diff --git a/ChangeLog b/ChangeLog index b6429843b6..82520601c6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2005-11-21 Thomas Vander Stichele + + * check/Makefile.am: + * gst-libs/gst/audio/audio.c: (gst_audio_duration_from_pad_buffer): + * gst-libs/gst/audio/audio.h: + add a method that returns a proper GstClockTime + 2005-11-21 Tim-Philipp Müller * gst-libs/gst/interfaces/xoverlay.c: (gst_x_overlay_base_init), diff --git a/check/Makefile.am b/check/Makefile.am index 0975bdbbf7..48a4a19b27 100644 --- a/check/Makefile.am +++ b/check/Makefile.am @@ -31,6 +31,7 @@ check_PROGRAMS = \ elements/audioconvert \ elements/audioresample \ elements/volume \ + generic/states \ pipelines/simple_launch_lines \ clocks/selection \ $(check_vorbis) @@ -38,12 +39,11 @@ check_PROGRAMS = \ # tests to fix leaks in VALGRIND_TO_FIX = \ elements/audioresample \ + generic/states \ pipelines/simple_launch_lines # these tests don't even pass -# generic/states: elements need state fixin' before this can be added -noinst_PROGRAMS = \ - generic/states +noinst_PROGRAMS = AM_CFLAGS = $(GST_OBJ_CFLAGS) $(GST_CHECK_CFLAGS) $(CHECK_CFLAGS) LDADD = $(GST_OBJ_LIBS) $(GST_CHECK_LIBS) $(CHECK_LIBS) diff --git a/gst-libs/gst/audio/audio.c b/gst-libs/gst/audio/audio.c index f82337a5da..1e145dada7 100644 --- a/gst-libs/gst/audio/audio.c +++ b/gst-libs/gst/audio/audio.c @@ -147,6 +147,49 @@ gst_audio_length (GstPad * pad, GstBuffer * buf) return length; } +double +gst_audio_duration_from_pad_buffer (GstPad * pad, GstBuffer * buf) +{ +/* calculate length in nanoseconds + * of audio buffer buf + * based on capabilities of pad + */ + + long bytes = 0; + int width = 0; + int channels = 0; + int rate = 0; + + GstClockTime length; + + const GstCaps *caps = NULL; + GstStructure *structure; + + g_assert (GST_IS_BUFFER (buf)); + /* get caps of pad */ + caps = GST_PAD_CAPS (pad); + if (caps == NULL) { + /* ERROR: could not get caps of pad */ + g_warning ("gstaudio: could not get caps of pad %s:%s\n", + GST_ELEMENT_NAME (gst_pad_get_parent (pad)), GST_PAD_NAME (pad)); + length = GST_CLOCK_TIME_NONE; + } else { + structure = gst_caps_get_structure (caps, 0); + bytes = GST_BUFFER_SIZE (buf); + gst_structure_get_int (structure, "width", &width); + gst_structure_get_int (structure, "channels", &channels); + gst_structure_get_int (structure, "rate", &rate); + + g_assert (bytes != 0); + g_assert (width != 0); + g_assert (channels != 0); + g_assert (rate != 0); + length = (bytes * 8.0 * GST_SECOND) / (rate * channels * width); + } + /* g_print ("DEBUG: audio: returning length of %f\n", length); */ + return length; +} + long gst_audio_highest_sample_value (GstPad * pad) /* calculate highest possible sample value diff --git a/gst-libs/gst/audio/audio.h b/gst-libs/gst/audio/audio.h index 3821c82e5c..189de51fde 100644 --- a/gst-libs/gst/audio/audio.h +++ b/gst-libs/gst/audio/audio.h @@ -110,6 +110,8 @@ long gst_audio_frame_rate (GstPad *pad); /* calculate length in seconds of audio buffer buf based on caps of pad */ double gst_audio_length (GstPad* pad, GstBuffer* buf); +double gst_audio_duration_from_pad_buffer (GstPad * pad, GstBuffer * buf); + /* calculate highest possible sample value based on capabilities of pad */ long gst_audio_highest_sample_value (GstPad* pad); diff --git a/tests/check/Makefile.am b/tests/check/Makefile.am index 0975bdbbf7..48a4a19b27 100644 --- a/tests/check/Makefile.am +++ b/tests/check/Makefile.am @@ -31,6 +31,7 @@ check_PROGRAMS = \ elements/audioconvert \ elements/audioresample \ elements/volume \ + generic/states \ pipelines/simple_launch_lines \ clocks/selection \ $(check_vorbis) @@ -38,12 +39,11 @@ check_PROGRAMS = \ # tests to fix leaks in VALGRIND_TO_FIX = \ elements/audioresample \ + generic/states \ pipelines/simple_launch_lines # these tests don't even pass -# generic/states: elements need state fixin' before this can be added -noinst_PROGRAMS = \ - generic/states +noinst_PROGRAMS = AM_CFLAGS = $(GST_OBJ_CFLAGS) $(GST_CHECK_CFLAGS) $(CHECK_CFLAGS) LDADD = $(GST_OBJ_LIBS) $(GST_CHECK_LIBS) $(CHECK_LIBS)