diff --git a/Cargo.toml b/Cargo.toml index 9f039393..c97cccf9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,8 +19,9 @@ byte-slice-cast = "0.2.0" gst-plugin-version-helper = "0.1" [features] -default = ["interlaced-fields"] +default = ["interlaced-fields", "reference-timestamps"] interlaced-fields = ["gstreamer/v1_16", "gstreamer-video/v1_16"] +reference-timestamps = ["gstreamer/v1_14"] [lib] name = "gstndi" diff --git a/src/lib.rs b/src/lib.rs index 576978ab..c7ab76e2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -48,6 +48,16 @@ lazy_static! { let m = HashMap::new(); Mutex::new(m) }; + + #[cfg(feature = "reference-timestamps")] + static ref TIMECODE_CAPS: gst::Caps = { + gst::Caps::new_simple("timestamp/x-ndi-timecode", &[]) + }; + + #[cfg(feature = "reference-timestamps")] + static ref TIMESTAMP_CAPS: gst::Caps = { + gst::Caps::new_simple("timestamp/x-ndi-timestamp", &[]) + }; } static ID_RECEIVER: AtomicUsize = AtomicUsize::new(0); diff --git a/src/ndiaudiosrc.rs b/src/ndiaudiosrc.rs index 1c0ab758..cb879911 100644 --- a/src/ndiaudiosrc.rs +++ b/src/ndiaudiosrc.rs @@ -18,6 +18,10 @@ use ndisys; use stop_ndi; use HASHMAP_RECEIVERS; +#[cfg(feature = "reference-timestamps")] +use TIMECODE_CAPS; +#[cfg(feature = "reference-timestamps")] +use TIMESTAMP_CAPS; use byte_slice_cast::AsMutSliceOf; @@ -400,6 +404,24 @@ impl BaseSrcImpl for NdiAudioSrc { buffer.set_pts(pts); buffer.set_duration(duration); + #[cfg(feature = "reference-timestamps")] + { + gst::ReferenceTimestampMeta::add( + buffer, + &*TIMECODE_CAPS, + gst::ClockTime::from(audio_frame.timecode() as u64 * 100), + gst::CLOCK_TIME_NONE, + ); + if audio_frame.timestamp() != ndisys::NDIlib_recv_timestamp_undefined { + gst::ReferenceTimestampMeta::add( + buffer, + &*TIMESTAMP_CAPS, + gst::ClockTime::from(audio_frame.timestamp() as u64 * 100), + gst::CLOCK_TIME_NONE, + ); + } + } + audio_frame.copy_to_interleaved_16s( buffer .map_writable() diff --git a/src/ndivideosrc.rs b/src/ndivideosrc.rs index de1d24e8..daf2192d 100644 --- a/src/ndivideosrc.rs +++ b/src/ndivideosrc.rs @@ -21,6 +21,10 @@ use connect_ndi; use stop_ndi; use HASHMAP_RECEIVERS; +#[cfg(feature = "reference-timestamps")] +use TIMECODE_CAPS; +#[cfg(feature = "reference-timestamps")] +use TIMESTAMP_CAPS; #[derive(Debug, Clone)] struct Settings { @@ -497,6 +501,24 @@ impl BaseSrcImpl for NdiVideoSrc { buffer.set_pts(pts); buffer.set_duration(duration); + #[cfg(feature = "reference-timestamps")] + { + gst::ReferenceTimestampMeta::add( + buffer, + &*TIMECODE_CAPS, + gst::ClockTime::from(video_frame.timecode() as u64 * 100), + gst::CLOCK_TIME_NONE, + ); + if video_frame.timestamp() != ndisys::NDIlib_recv_timestamp_undefined { + gst::ReferenceTimestampMeta::add( + buffer, + &*TIMESTAMP_CAPS, + gst::ClockTime::from(video_frame.timestamp() as u64 * 100), + gst::CLOCK_TIME_NONE, + ); + } + } + #[cfg(feature = "interlaced-fields")] { match video_frame.frame_format_type() {