Use same start_pts for audio and video in the same ndi receiver

This commit is contained in:
Daniel Vilar 2018-08-20 16:59:12 +02:00
parent 3b4ae6c00e
commit 4338068b3c
3 changed files with 18 additions and 17 deletions

View file

@ -52,6 +52,7 @@ struct ndi_receiver_info{
audio: bool,
ndi_instance: NdiInstance,
id: i8,
timestamp: u64,
}
lazy_static! {
@ -193,7 +194,7 @@ fn connect_ndi(cat: gst::DebugCategory , element: &BaseSrc, ip: String, stream
NDIlib_recv_send_metadata(pNDI_recv, &enable_hw_accel);
receivers.insert(id_receiver, ndi_receiver_info{stream_name: source_name.clone(), ip: source_ip.clone(), video:video, audio: audio, ndi_instance: NdiInstance{recv: pNDI_recv}, id: id_receiver});
receivers.insert(id_receiver, ndi_receiver_info{stream_name: source_name.clone(), ip: source_ip.clone(), video:video, audio: audio, ndi_instance: NdiInstance{recv: pNDI_recv}, id: id_receiver, timestamp: 0});
// let start = SystemTime::now();
// let since_the_epoch = start.duration_since(UNIX_EPOCH)

View file

@ -73,7 +73,6 @@ impl Default for State {
}
struct TimestampData{
pts: u64,
offset: u64,
}
@ -102,7 +101,6 @@ impl NdiAudioSrc {
settings: Mutex::new(Default::default()),
state: Mutex::new(Default::default()),
timestamp_data: Mutex::new(TimestampData{
pts: 0,
offset: 0,
}),
})
@ -327,14 +325,13 @@ impl NdiAudioSrc {
fn fixate(&self, element: &BaseSrc, caps: gst::Caps) -> gst::Caps {
//We need to set the correct caps resolution and framerate
unsafe{
let receivers = hashmap_receivers.lock().unwrap();
let mut receivers = hashmap_receivers.lock().unwrap();
let settings = self.settings.lock().unwrap();
let recv = &receivers.get(&settings.id_receiver).unwrap().ndi_instance;
let receiver = receivers.get_mut(&settings.id_receiver).unwrap();
let recv = &receiver.ndi_instance;
let pNDI_recv = recv.recv;
let mut timestamp_data = self.timestamp_data.lock().unwrap();
let audio_frame: NDIlib_audio_frame_v2_t = Default::default();
let mut frame_type: NDIlib_frame_type_e = NDIlib_frame_type_e::NDIlib_frame_type_none;
@ -342,7 +339,9 @@ impl NdiAudioSrc {
frame_type = NDIlib_recv_capture_v2(pNDI_recv, ptr::null(), &audio_frame, ptr::null(), 1000);
}
timestamp_data.pts = audio_frame.timecode as u64;
if receiver.timestamp >= audio_frame.timecode as u64 || receiver.timestamp == 0{
receiver.timestamp = audio_frame.timecode as u64;
}
let mut caps = gst::Caps::truncate(caps);
{
@ -391,7 +390,8 @@ impl NdiAudioSrc {
let audio_frame: NDIlib_audio_frame_v2_t = Default::default();
NDIlib_recv_capture_v2(pNDI_recv, ptr::null(), &audio_frame, ptr::null(), 1000,);
pts = (audio_frame.timecode as u64) - timestamp_data.pts;
let time = &receivers.get(&_settings.id_receiver).unwrap().timestamp;
pts = audio_frame.timecode as u64- time;
let buff_size = ((audio_frame.channel_stride_in_bytes)) as usize;
let mut buffer = gst::Buffer::with_size(buff_size).unwrap();

View file

@ -74,7 +74,6 @@ impl Default for State {
}
struct TimestampData{
pts: u64,
offset: u64,
}
@ -103,7 +102,6 @@ impl NdiVideoSrc {
settings: Mutex::new(Default::default()),
state: Mutex::new(Default::default()),
timestamp_data: Mutex::new(TimestampData{
pts: 0,
offset: 0,
}),
})
@ -334,14 +332,13 @@ impl NdiVideoSrc {
fn fixate(&self, element: &BaseSrc, caps: gst::Caps) -> gst::Caps {
//We need to set the correct caps resolution and framerate
unsafe{
let receivers = hashmap_receivers.lock().unwrap();
let mut receivers = hashmap_receivers.lock().unwrap();
let settings = self.settings.lock().unwrap();
let recv = &receivers.get(&settings.id_receiver).unwrap().ndi_instance;
let receiver = receivers.get_mut(&settings.id_receiver).unwrap();
let recv = &receiver.ndi_instance;
let pNDI_recv = recv.recv;
let mut timestamp_data = self.timestamp_data.lock().unwrap();
let video_frame: NDIlib_video_frame_v2_t = Default::default();
let mut frame_type: NDIlib_frame_type_e = NDIlib_frame_type_e::NDIlib_frame_type_none;
@ -350,7 +347,9 @@ impl NdiVideoSrc {
}
//TODO Check that this is working
timestamp_data.pts = video_frame.timecode as u64;
if receiver.timestamp >= video_frame.timecode as u64 || receiver.timestamp == 0{
receiver.timestamp = video_frame.timecode as u64;
}
let mut caps = gst::Caps::truncate(caps);
{
@ -399,7 +398,8 @@ impl NdiVideoSrc {
let video_frame: NDIlib_video_frame_v2_t = Default::default();
NDIlib_recv_capture_v2(pNDI_recv, &video_frame, ptr::null(), ptr::null(), 1000,);
pts = (video_frame.timecode as u64) - timestamp_data.pts;
let time = &receivers.get(&_settings.id_receiver).unwrap().timestamp;
pts = video_frame.timecode as u64 - time;
let buff_size = (video_frame.yres * video_frame.line_stride_in_bytes) as usize;
//println!("{:?}", buff_size);