From d813fa568151341f11a1f9238d69b5da5dfd4045 Mon Sep 17 00:00:00 2001 From: Daniel Vilar Date: Mon, 23 Apr 2018 14:12:41 +0200 Subject: [PATCH] Try to add video data to a buffer --- gst-plugin-ndi/src/ndisrc.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/gst-plugin-ndi/src/ndisrc.rs b/gst-plugin-ndi/src/ndisrc.rs index a7358576..e8b38621 100644 --- a/gst-plugin-ndi/src/ndisrc.rs +++ b/gst-plugin-ndi/src/ndisrc.rs @@ -663,6 +663,9 @@ impl BaseSrcImpl for NdiSrc { let audio_frame: NDIlib_audio_frame_v2_t = Default::default(); let metadata_frame: NDIlib_metadata_frame_t = Default::default(); + //TODO Solo hacemos el buffer cuando tengamos un frame de video + let mut frame = false; + while !frame{ let frame_type = NDIlib_recv_capture_v2( pNDI_recv, &video_frame, @@ -674,7 +677,7 @@ impl BaseSrcImpl for NdiSrc { match frame_type { NDIlib_frame_type_e::NDIlib_frame_type_video => { println!("Tengo video {:?}", video_frame); - + frame = true; } NDIlib_frame_type_e::NDIlib_frame_type_audio => { println!("Tengo audio {:?}", audio_frame); @@ -700,6 +703,7 @@ impl BaseSrcImpl for NdiSrc { } _ => println!("Tengo {:?}", frame_type), } + } // } @@ -727,6 +731,16 @@ impl BaseSrcImpl for NdiSrc { gst::Buffer::with_size(200 * 400).unwrap(); { let buffer = buffer.get_mut().unwrap(); + let pts: gst::ClockTime = (video_frame.timestamp as u64).into(); + let duration: gst::ClockTime = (334624).into(); + buffer.set_pts(pts); + buffer.set_duration(duration); + // Map the buffer writable and create the actual samples + let mut map = buffer.map_writable().unwrap(); + let mut data = map.as_slice(); + //data = &mut video_frame.p_data; + let a = CStr::from_ptr(video_frame.p_data); + data = a.to_bytes(); // // Calculate the current timestamp (PTS) and the next one, // // and calculate the duration from the difference instead of