diff --git a/docs/libs/gst-plugins-base-libs-sections.txt b/docs/libs/gst-plugins-base-libs-sections.txt index 1e3190e3b7..1816082abf 100644 --- a/docs/libs/gst-plugins-base-libs-sections.txt +++ b/docs/libs/gst-plugins-base-libs-sections.txt @@ -250,6 +250,8 @@ gst_audio_stream_align_copy gst_audio_stream_align_free gst_audio_stream_align_mark_discont gst_audio_stream_align_process +gst_audio_stream_align_get_samples_since_discont +gst_audio_stream_align_get_timestamp_at_discont gst_audio_stream_align_get_alignment_threshold gst_audio_stream_align_set_alignment_threshold gst_audio_stream_align_get_discont_wait diff --git a/gst-libs/gst/audio/gstaudiostreamalign.c b/gst-libs/gst/audio/gstaudiostreamalign.c index a2ac2fcefa..0f32490de9 100644 --- a/gst-libs/gst/audio/gstaudiostreamalign.c +++ b/gst-libs/gst/audio/gstaudiostreamalign.c @@ -50,6 +50,8 @@ struct _GstAudioStreamAlign /* counter to keep track of timestamps */ guint64 next_offset; + GstClockTime timestamp_at_discont; + guint64 samples_since_discont; /* Last time we noticed a discont */ GstClockTime discont_time; @@ -90,6 +92,8 @@ gst_audio_stream_align_new (gint rate, GstClockTime alignment_threshold, align->alignment_threshold = alignment_threshold; align->discont_wait = discont_wait; + align->timestamp_at_discont = GST_CLOCK_TIME_NONE; + align->samples_since_discont = 0; gst_audio_stream_align_mark_discont (align); return align; @@ -264,6 +268,44 @@ gst_audio_stream_align_mark_discont (GstAudioStreamAlign * align) align->discont_time = GST_CLOCK_TIME_NONE; } +/** + * gst_audio_stream_align_get_timestamp_at_discont: + * @align: a #GstAudioStreamAlign + * + * Timestamp that was passed when a discontinuity was detected, i.e. the first + * timestamp after the discontinuity. + * + * Returns: The last timestamp at when a discontinuity was detected + * + * Since: 1.14 + */ +GstClockTime +gst_audio_stream_align_get_timestamp_at_discont (GstAudioStreamAlign * align) +{ + g_return_val_if_fail (align != NULL, GST_CLOCK_TIME_NONE); + + return align->timestamp_at_discont; +} + +/** + * gst_audio_stream_align_get_samples_since_discont: + * @align: a #GstAudioStreamAlign + * + * Returns the number of samples that were processed since the last + * discontinuity was detected. + * + * Returns: The number of samples processed since the last discontinuity. + * + * Since: 1.14 + */ +guint64 +gst_audio_stream_align_get_samples_since_discont (GstAudioStreamAlign * align) +{ + g_return_val_if_fail (align != NULL, 0); + + return align->samples_since_discont; +} + /** * gst_audio_stream_align_process: * @align: a #GstAudioStreamAlign @@ -363,6 +405,8 @@ gst_audio_stream_align_process (GstAudioStreamAlign * align, G_GUINT64_FORMAT ", got %" G_GUINT64_FORMAT, align->next_offset, start_offset); align->next_offset = align->rate > 0 ? end_offset : start_offset; + align->timestamp_at_discont = start_time; + align->samples_since_discont = 0; /* Got a discont and adjusted, reset the discont_time marker */ align->discont_time = GST_CLOCK_TIME_NONE; @@ -399,6 +443,8 @@ gst_audio_stream_align_process (GstAudioStreamAlign * align, } } + align->samples_since_discont += n_samples; + if (out_timestamp) *out_timestamp = timestamp; if (out_duration) diff --git a/gst-libs/gst/audio/gstaudiostreamalign.h b/gst-libs/gst/audio/gstaudiostreamalign.h index 541c06d0ca..acbf46fb34 100644 --- a/gst-libs/gst/audio/gstaudiostreamalign.h +++ b/gst-libs/gst/audio/gstaudiostreamalign.h @@ -29,46 +29,52 @@ typedef struct _GstAudioStreamAlign GstAudioStreamAlign; GST_EXPORT -GType gst_audio_stream_align_get_type (void); +GType gst_audio_stream_align_get_type (void); GST_EXPORT -GstAudioStreamAlign * gst_audio_stream_align_new (gint rate, - GstClockTime alignment_threshold, - GstClockTime discont_wait); +GstAudioStreamAlign * gst_audio_stream_align_new (gint rate, + GstClockTime alignment_threshold, + GstClockTime discont_wait); GST_EXPORT -GstAudioStreamAlign * gst_audio_stream_align_copy (const GstAudioStreamAlign * align); +GstAudioStreamAlign * gst_audio_stream_align_copy (const GstAudioStreamAlign * align); GST_EXPORT -void gst_audio_stream_align_free (GstAudioStreamAlign * align); +void gst_audio_stream_align_free (GstAudioStreamAlign * align); GST_EXPORT -void gst_audio_stream_align_set_rate (GstAudioStreamAlign * align, - gint rate); +void gst_audio_stream_align_set_rate (GstAudioStreamAlign * align, + gint rate); GST_EXPORT -gint gst_audio_stream_align_get_rate (GstAudioStreamAlign * align); +gint gst_audio_stream_align_get_rate (GstAudioStreamAlign * align); GST_EXPORT -void gst_audio_stream_align_set_alignment_threshold (GstAudioStreamAlign * align, - GstClockTime alignment_threshold); +void gst_audio_stream_align_set_alignment_threshold (GstAudioStreamAlign * align, + GstClockTime alignment_threshold); GST_EXPORT -GstClockTime gst_audio_stream_align_get_alignment_threshold (GstAudioStreamAlign * align); +GstClockTime gst_audio_stream_align_get_alignment_threshold (GstAudioStreamAlign * align); GST_EXPORT -void gst_audio_stream_align_set_discont_wait (GstAudioStreamAlign * align, - GstClockTime discont_wait); +void gst_audio_stream_align_set_discont_wait (GstAudioStreamAlign * align, + GstClockTime discont_wait); GST_EXPORT -GstClockTime gst_audio_stream_align_get_discont_wait (GstAudioStreamAlign * align); +GstClockTime gst_audio_stream_align_get_discont_wait (GstAudioStreamAlign * align); GST_EXPORT -void gst_audio_stream_align_mark_discont (GstAudioStreamAlign * align); +void gst_audio_stream_align_mark_discont (GstAudioStreamAlign * align); GST_EXPORT -gboolean gst_audio_stream_align_process (GstAudioStreamAlign * align, - gboolean discont, - GstClockTime timestamp, - guint n_samples, - GstClockTime *out_timestamp, - GstClockTime *out_duration, - guint64 *out_sample_position); +GstClockTime gst_audio_stream_align_get_timestamp_at_discont (GstAudioStreamAlign * align); + +GST_EXPORT +guint64 gst_audio_stream_align_get_samples_since_discont (GstAudioStreamAlign * align); + +GST_EXPORT +gboolean gst_audio_stream_align_process (GstAudioStreamAlign * align, + gboolean discont, + GstClockTime timestamp, + guint n_samples, + GstClockTime *out_timestamp, + GstClockTime *out_duration, + guint64 *out_sample_position); #endif /* __GST_AUDIO_STREAM_ALIGN_H__ */ diff --git a/win32/common/libgstaudio.def b/win32/common/libgstaudio.def index 9a47e43dda..829cf19f5f 100644 --- a/win32/common/libgstaudio.def +++ b/win32/common/libgstaudio.def @@ -214,6 +214,8 @@ EXPORTS gst_audio_stream_align_get_alignment_threshold gst_audio_stream_align_get_discont_wait gst_audio_stream_align_get_rate + gst_audio_stream_align_get_samples_since_discont + gst_audio_stream_align_get_timestamp_at_discont gst_audio_stream_align_get_type gst_audio_stream_align_mark_discont gst_audio_stream_align_new