2005-08-25 15:44:58 +00:00
|
|
|
/* GStreamer
|
|
|
|
*
|
2009-01-23 11:31:06 +00:00
|
|
|
* unit test for audioresample, based on the audioresample unit test
|
2005-08-25 15:44:58 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) <2005> Thomas Vander Stichele <thomas at apestaart dot org>
|
2006-06-16 15:43:23 +00:00
|
|
|
* Copyright (C) <2006> Tim-Philipp Müller <tim at centricular net>
|
2005-08-25 15:44:58 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include <gst/check/gstcheck.h>
|
|
|
|
|
2009-01-23 11:31:06 +00:00
|
|
|
#include <gst/audio/audio.h>
|
|
|
|
|
2011-08-12 11:07:32 +00:00
|
|
|
#include <gst/fft/gstfft.h>
|
|
|
|
#include <gst/fft/gstffts16.h>
|
|
|
|
#include <gst/fft/gstffts32.h>
|
|
|
|
#include <gst/fft/gstfftf32.h>
|
|
|
|
#include <gst/fft/gstfftf64.h>
|
|
|
|
|
2005-08-25 15:44:58 +00:00
|
|
|
/* For ease of programming we use globals to keep refs for our floating
|
|
|
|
* src and sink pads we create; otherwise we always have to do get_pad,
|
|
|
|
* get_peer, and then remove references in every test function */
|
Correct all relevant warnings found by the sparse semantic code analyzer. This include marking several symbols static...
Original commit message from CVS:
* ext/alsa/gstalsamixertrack.c: (gst_alsa_mixer_track_get_type):
* ext/alsa/gstalsasink.c: (set_hwparams):
* ext/alsa/gstalsasrc.c: (set_hwparams):
* ext/gio/gstgio.c: (gst_gio_uri_handler_get_uri):
* ext/ogg/gstoggmux.h:
* ext/ogg/gstogmparse.c:
* gst-libs/gst/audio/audio.c:
* gst-libs/gst/fft/kiss_fft_f64.c: (kiss_fft_f64_alloc):
* gst-libs/gst/pbutils/missing-plugins.c:
(gst_missing_uri_sink_message_new),
(gst_missing_element_message_new),
(gst_missing_decoder_message_new),
(gst_missing_encoder_message_new):
* gst-libs/gst/rtp/gstbasertppayload.c:
* gst-libs/gst/rtp/gstrtcpbuffer.c:
(gst_rtcp_packet_bye_get_reason):
* gst/audioconvert/gstaudioconvert.c:
* gst/audioresample/gstaudioresample.c:
* gst/ffmpegcolorspace/imgconvert.c:
* gst/playback/test.c: (gen_video_element), (gen_audio_element):
* gst/typefind/gsttypefindfunctions.c:
* gst/videoscale/vs_4tap.c:
* gst/videoscale/vs_4tap.h:
* sys/v4l/gstv4lelement.c:
* sys/v4l/gstv4lsrc.c: (gst_v4lsrc_get_any_caps):
* sys/v4l/v4l_calls.c:
* sys/v4l/v4lsrc_calls.c: (gst_v4lsrc_capture_init),
(gst_v4lsrc_try_capture):
* sys/ximage/ximagesink.c: (gst_ximagesink_check_xshm_calls),
(gst_ximagesink_ximage_new):
* sys/xvimage/xvimagesink.c: (gst_xvimagesink_check_xshm_calls),
(gst_xvimagesink_xvimage_new):
* tests/check/elements/audioconvert.c:
* tests/check/elements/audioresample.c:
(fail_unless_perfect_stream):
* tests/check/elements/audiotestsrc.c: (setup_audiotestsrc):
* tests/check/elements/decodebin.c:
* tests/check/elements/gdpdepay.c: (setup_gdpdepay),
(setup_gdpdepay_streamheader):
* tests/check/elements/gdppay.c: (setup_gdppay), (GST_START_TEST),
(setup_gdppay_streamheader):
* tests/check/elements/gnomevfssink.c: (setup_gnomevfssink):
* tests/check/elements/multifdsink.c: (setup_multifdsink):
* tests/check/elements/textoverlay.c:
* tests/check/elements/videorate.c: (setup_videorate):
* tests/check/elements/videotestsrc.c: (setup_videotestsrc):
* tests/check/elements/volume.c: (setup_volume):
* tests/check/elements/vorbisdec.c: (setup_vorbisdec):
* tests/check/elements/vorbistag.c:
* tests/check/generic/clock-selection.c:
* tests/check/generic/states.c: (setup), (teardown):
* tests/check/libs/cddabasesrc.c:
* tests/check/libs/video.c:
* tests/check/pipelines/gio.c:
* tests/check/pipelines/oggmux.c:
* tests/check/pipelines/simple-launch-lines.c:
(simple_launch_lines_suite):
* tests/check/pipelines/streamheader.c:
* tests/check/pipelines/theoraenc.c:
* tests/check/pipelines/vorbisdec.c:
* tests/check/pipelines/vorbisenc.c:
* tests/examples/seek/scrubby.c:
* tests/examples/seek/seek.c: (query_positions_elems),
(query_positions_pads):
* tests/icles/stress-xoverlay.c: (myclock):
Correct all relevant warnings found by the sparse semantic code
analyzer. This include marking several symbols static, using
NULL instead of 0 for pointers and using "foo (void)" instead
of "foo ()" for declarations.
* win32/common/libgstrtp.def:
Add gst_rtp_buffer_set_extension_data to the symbol definition file.
2008-03-03 06:04:31 +00:00
|
|
|
static GstPad *mysrcpad, *mysinkpad;
|
2005-08-25 15:44:58 +00:00
|
|
|
|
2009-01-23 11:31:06 +00:00
|
|
|
#define RESAMPLE_CAPS_FLOAT \
|
|
|
|
"audio/x-raw-float, " \
|
|
|
|
"channels = (int) [ 1, MAX ], " \
|
|
|
|
"rate = (int) [ 1, MAX ], " \
|
|
|
|
"endianness = (int) BYTE_ORDER, " \
|
|
|
|
"width = (int) { 32, 64 }"
|
2005-08-25 15:44:58 +00:00
|
|
|
|
2009-01-23 11:31:06 +00:00
|
|
|
#define RESAMPLE_CAPS_INT \
|
2005-12-06 19:42:02 +00:00
|
|
|
"audio/x-raw-int, " \
|
|
|
|
"channels = (int) [ 1, MAX ], " \
|
|
|
|
"rate = (int) [ 1, MAX ], " \
|
|
|
|
"endianness = (int) BYTE_ORDER, " \
|
2011-08-12 11:07:32 +00:00
|
|
|
"width = (int) { 16, 32 }, " \
|
|
|
|
"depth = (int) { 16, 32 }, " \
|
2005-08-25 15:44:58 +00:00
|
|
|
"signed = (bool) TRUE"
|
|
|
|
|
2009-01-23 11:31:06 +00:00
|
|
|
#define RESAMPLE_CAPS_TEMPLATE_STRING \
|
|
|
|
RESAMPLE_CAPS_FLOAT " ; " \
|
|
|
|
RESAMPLE_CAPS_INT
|
|
|
|
|
2005-08-25 15:44:58 +00:00
|
|
|
static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS (RESAMPLE_CAPS_TEMPLATE_STRING)
|
|
|
|
);
|
|
|
|
static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS (RESAMPLE_CAPS_TEMPLATE_STRING)
|
|
|
|
);
|
|
|
|
|
Correct all relevant warnings found by the sparse semantic code analyzer. This include marking several symbols static...
Original commit message from CVS:
* ext/alsa/gstalsamixertrack.c: (gst_alsa_mixer_track_get_type):
* ext/alsa/gstalsasink.c: (set_hwparams):
* ext/alsa/gstalsasrc.c: (set_hwparams):
* ext/gio/gstgio.c: (gst_gio_uri_handler_get_uri):
* ext/ogg/gstoggmux.h:
* ext/ogg/gstogmparse.c:
* gst-libs/gst/audio/audio.c:
* gst-libs/gst/fft/kiss_fft_f64.c: (kiss_fft_f64_alloc):
* gst-libs/gst/pbutils/missing-plugins.c:
(gst_missing_uri_sink_message_new),
(gst_missing_element_message_new),
(gst_missing_decoder_message_new),
(gst_missing_encoder_message_new):
* gst-libs/gst/rtp/gstbasertppayload.c:
* gst-libs/gst/rtp/gstrtcpbuffer.c:
(gst_rtcp_packet_bye_get_reason):
* gst/audioconvert/gstaudioconvert.c:
* gst/audioresample/gstaudioresample.c:
* gst/ffmpegcolorspace/imgconvert.c:
* gst/playback/test.c: (gen_video_element), (gen_audio_element):
* gst/typefind/gsttypefindfunctions.c:
* gst/videoscale/vs_4tap.c:
* gst/videoscale/vs_4tap.h:
* sys/v4l/gstv4lelement.c:
* sys/v4l/gstv4lsrc.c: (gst_v4lsrc_get_any_caps):
* sys/v4l/v4l_calls.c:
* sys/v4l/v4lsrc_calls.c: (gst_v4lsrc_capture_init),
(gst_v4lsrc_try_capture):
* sys/ximage/ximagesink.c: (gst_ximagesink_check_xshm_calls),
(gst_ximagesink_ximage_new):
* sys/xvimage/xvimagesink.c: (gst_xvimagesink_check_xshm_calls),
(gst_xvimagesink_xvimage_new):
* tests/check/elements/audioconvert.c:
* tests/check/elements/audioresample.c:
(fail_unless_perfect_stream):
* tests/check/elements/audiotestsrc.c: (setup_audiotestsrc):
* tests/check/elements/decodebin.c:
* tests/check/elements/gdpdepay.c: (setup_gdpdepay),
(setup_gdpdepay_streamheader):
* tests/check/elements/gdppay.c: (setup_gdppay), (GST_START_TEST),
(setup_gdppay_streamheader):
* tests/check/elements/gnomevfssink.c: (setup_gnomevfssink):
* tests/check/elements/multifdsink.c: (setup_multifdsink):
* tests/check/elements/textoverlay.c:
* tests/check/elements/videorate.c: (setup_videorate):
* tests/check/elements/videotestsrc.c: (setup_videotestsrc):
* tests/check/elements/volume.c: (setup_volume):
* tests/check/elements/vorbisdec.c: (setup_vorbisdec):
* tests/check/elements/vorbistag.c:
* tests/check/generic/clock-selection.c:
* tests/check/generic/states.c: (setup), (teardown):
* tests/check/libs/cddabasesrc.c:
* tests/check/libs/video.c:
* tests/check/pipelines/gio.c:
* tests/check/pipelines/oggmux.c:
* tests/check/pipelines/simple-launch-lines.c:
(simple_launch_lines_suite):
* tests/check/pipelines/streamheader.c:
* tests/check/pipelines/theoraenc.c:
* tests/check/pipelines/vorbisdec.c:
* tests/check/pipelines/vorbisenc.c:
* tests/examples/seek/scrubby.c:
* tests/examples/seek/seek.c: (query_positions_elems),
(query_positions_pads):
* tests/icles/stress-xoverlay.c: (myclock):
Correct all relevant warnings found by the sparse semantic code
analyzer. This include marking several symbols static, using
NULL instead of 0 for pointers and using "foo (void)" instead
of "foo ()" for declarations.
* win32/common/libgstrtp.def:
Add gst_rtp_buffer_set_extension_data to the symbol definition file.
2008-03-03 06:04:31 +00:00
|
|
|
static GstElement *
|
2009-01-23 11:31:06 +00:00
|
|
|
setup_audioresample (int channels, int inrate, int outrate, int width,
|
|
|
|
gboolean fp)
|
2005-08-25 15:44:58 +00:00
|
|
|
{
|
|
|
|
GstElement *audioresample;
|
|
|
|
GstCaps *caps;
|
|
|
|
GstStructure *structure;
|
|
|
|
|
|
|
|
GST_DEBUG ("setup_audioresample");
|
|
|
|
audioresample = gst_check_setup_element ("audioresample");
|
|
|
|
|
2009-01-23 11:31:06 +00:00
|
|
|
if (fp)
|
|
|
|
caps = gst_caps_from_string (RESAMPLE_CAPS_FLOAT);
|
|
|
|
else
|
|
|
|
caps = gst_caps_from_string (RESAMPLE_CAPS_INT);
|
2005-08-25 15:44:58 +00:00
|
|
|
structure = gst_caps_get_structure (caps, 0);
|
2005-08-25 16:19:39 +00:00
|
|
|
gst_structure_set (structure, "channels", G_TYPE_INT, channels,
|
2009-01-23 11:31:06 +00:00
|
|
|
"rate", G_TYPE_INT, inrate, "width", G_TYPE_INT, width, NULL);
|
|
|
|
if (!fp)
|
|
|
|
gst_structure_set (structure, "depth", G_TYPE_INT, width, NULL);
|
2005-08-25 15:44:58 +00:00
|
|
|
fail_unless (gst_caps_is_fixed (caps));
|
|
|
|
|
2006-06-16 15:17:44 +00:00
|
|
|
fail_unless (gst_element_set_state (audioresample,
|
|
|
|
GST_STATE_PAUSED) == GST_STATE_CHANGE_SUCCESS,
|
|
|
|
"could not set to paused");
|
|
|
|
|
2005-08-25 15:44:58 +00:00
|
|
|
mysrcpad = gst_check_setup_src_pad (audioresample, &srctemplate, caps);
|
2008-09-01 16:05:45 +00:00
|
|
|
gst_pad_set_caps (mysrcpad, caps);
|
2005-08-25 15:44:58 +00:00
|
|
|
gst_caps_unref (caps);
|
|
|
|
|
2009-01-23 11:31:06 +00:00
|
|
|
if (fp)
|
|
|
|
caps = gst_caps_from_string (RESAMPLE_CAPS_FLOAT);
|
|
|
|
else
|
|
|
|
caps = gst_caps_from_string (RESAMPLE_CAPS_INT);
|
2005-08-25 15:44:58 +00:00
|
|
|
structure = gst_caps_get_structure (caps, 0);
|
2005-08-25 16:19:39 +00:00
|
|
|
gst_structure_set (structure, "channels", G_TYPE_INT, channels,
|
2009-01-23 11:31:06 +00:00
|
|
|
"rate", G_TYPE_INT, outrate, "width", G_TYPE_INT, width, NULL);
|
|
|
|
if (!fp)
|
|
|
|
gst_structure_set (structure, "depth", G_TYPE_INT, width, NULL);
|
2005-08-25 15:44:58 +00:00
|
|
|
fail_unless (gst_caps_is_fixed (caps));
|
|
|
|
|
|
|
|
mysinkpad = gst_check_setup_sink_pad (audioresample, &sinktemplate, caps);
|
|
|
|
/* this installs a getcaps func that will always return the caps we set
|
|
|
|
* later */
|
2008-09-01 16:05:45 +00:00
|
|
|
gst_pad_set_caps (mysinkpad, caps);
|
2005-08-25 15:44:58 +00:00
|
|
|
gst_pad_use_fixed_caps (mysinkpad);
|
2008-09-01 16:05:45 +00:00
|
|
|
|
2005-08-30 19:54:35 +00:00
|
|
|
gst_pad_set_active (mysinkpad, TRUE);
|
2008-09-01 16:05:45 +00:00
|
|
|
gst_pad_set_active (mysrcpad, TRUE);
|
2005-08-25 15:44:58 +00:00
|
|
|
|
2009-01-23 11:31:06 +00:00
|
|
|
gst_caps_unref (caps);
|
|
|
|
|
2005-08-25 15:44:58 +00:00
|
|
|
return audioresample;
|
|
|
|
}
|
|
|
|
|
Correct all relevant warnings found by the sparse semantic code analyzer. This include marking several symbols static...
Original commit message from CVS:
* ext/alsa/gstalsamixertrack.c: (gst_alsa_mixer_track_get_type):
* ext/alsa/gstalsasink.c: (set_hwparams):
* ext/alsa/gstalsasrc.c: (set_hwparams):
* ext/gio/gstgio.c: (gst_gio_uri_handler_get_uri):
* ext/ogg/gstoggmux.h:
* ext/ogg/gstogmparse.c:
* gst-libs/gst/audio/audio.c:
* gst-libs/gst/fft/kiss_fft_f64.c: (kiss_fft_f64_alloc):
* gst-libs/gst/pbutils/missing-plugins.c:
(gst_missing_uri_sink_message_new),
(gst_missing_element_message_new),
(gst_missing_decoder_message_new),
(gst_missing_encoder_message_new):
* gst-libs/gst/rtp/gstbasertppayload.c:
* gst-libs/gst/rtp/gstrtcpbuffer.c:
(gst_rtcp_packet_bye_get_reason):
* gst/audioconvert/gstaudioconvert.c:
* gst/audioresample/gstaudioresample.c:
* gst/ffmpegcolorspace/imgconvert.c:
* gst/playback/test.c: (gen_video_element), (gen_audio_element):
* gst/typefind/gsttypefindfunctions.c:
* gst/videoscale/vs_4tap.c:
* gst/videoscale/vs_4tap.h:
* sys/v4l/gstv4lelement.c:
* sys/v4l/gstv4lsrc.c: (gst_v4lsrc_get_any_caps):
* sys/v4l/v4l_calls.c:
* sys/v4l/v4lsrc_calls.c: (gst_v4lsrc_capture_init),
(gst_v4lsrc_try_capture):
* sys/ximage/ximagesink.c: (gst_ximagesink_check_xshm_calls),
(gst_ximagesink_ximage_new):
* sys/xvimage/xvimagesink.c: (gst_xvimagesink_check_xshm_calls),
(gst_xvimagesink_xvimage_new):
* tests/check/elements/audioconvert.c:
* tests/check/elements/audioresample.c:
(fail_unless_perfect_stream):
* tests/check/elements/audiotestsrc.c: (setup_audiotestsrc):
* tests/check/elements/decodebin.c:
* tests/check/elements/gdpdepay.c: (setup_gdpdepay),
(setup_gdpdepay_streamheader):
* tests/check/elements/gdppay.c: (setup_gdppay), (GST_START_TEST),
(setup_gdppay_streamheader):
* tests/check/elements/gnomevfssink.c: (setup_gnomevfssink):
* tests/check/elements/multifdsink.c: (setup_multifdsink):
* tests/check/elements/textoverlay.c:
* tests/check/elements/videorate.c: (setup_videorate):
* tests/check/elements/videotestsrc.c: (setup_videotestsrc):
* tests/check/elements/volume.c: (setup_volume):
* tests/check/elements/vorbisdec.c: (setup_vorbisdec):
* tests/check/elements/vorbistag.c:
* tests/check/generic/clock-selection.c:
* tests/check/generic/states.c: (setup), (teardown):
* tests/check/libs/cddabasesrc.c:
* tests/check/libs/video.c:
* tests/check/pipelines/gio.c:
* tests/check/pipelines/oggmux.c:
* tests/check/pipelines/simple-launch-lines.c:
(simple_launch_lines_suite):
* tests/check/pipelines/streamheader.c:
* tests/check/pipelines/theoraenc.c:
* tests/check/pipelines/vorbisdec.c:
* tests/check/pipelines/vorbisenc.c:
* tests/examples/seek/scrubby.c:
* tests/examples/seek/seek.c: (query_positions_elems),
(query_positions_pads):
* tests/icles/stress-xoverlay.c: (myclock):
Correct all relevant warnings found by the sparse semantic code
analyzer. This include marking several symbols static, using
NULL instead of 0 for pointers and using "foo (void)" instead
of "foo ()" for declarations.
* win32/common/libgstrtp.def:
Add gst_rtp_buffer_set_extension_data to the symbol definition file.
2008-03-03 06:04:31 +00:00
|
|
|
static void
|
2005-08-25 15:44:58 +00:00
|
|
|
cleanup_audioresample (GstElement * audioresample)
|
|
|
|
{
|
|
|
|
GST_DEBUG ("cleanup_audioresample");
|
|
|
|
|
2006-06-16 15:17:44 +00:00
|
|
|
fail_unless (gst_element_set_state (audioresample,
|
|
|
|
GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to NULL");
|
|
|
|
|
2006-12-21 08:12:26 +00:00
|
|
|
gst_pad_set_active (mysrcpad, FALSE);
|
|
|
|
gst_pad_set_active (mysinkpad, FALSE);
|
2005-08-25 15:44:58 +00:00
|
|
|
gst_check_teardown_src_pad (audioresample);
|
|
|
|
gst_check_teardown_sink_pad (audioresample);
|
|
|
|
gst_check_teardown_element (audioresample);
|
2009-09-11 20:44:18 +00:00
|
|
|
gst_check_drop_buffers ();
|
2005-08-25 15:44:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
Correct all relevant warnings found by the sparse semantic code analyzer. This include marking several symbols static...
Original commit message from CVS:
* ext/alsa/gstalsamixertrack.c: (gst_alsa_mixer_track_get_type):
* ext/alsa/gstalsasink.c: (set_hwparams):
* ext/alsa/gstalsasrc.c: (set_hwparams):
* ext/gio/gstgio.c: (gst_gio_uri_handler_get_uri):
* ext/ogg/gstoggmux.h:
* ext/ogg/gstogmparse.c:
* gst-libs/gst/audio/audio.c:
* gst-libs/gst/fft/kiss_fft_f64.c: (kiss_fft_f64_alloc):
* gst-libs/gst/pbutils/missing-plugins.c:
(gst_missing_uri_sink_message_new),
(gst_missing_element_message_new),
(gst_missing_decoder_message_new),
(gst_missing_encoder_message_new):
* gst-libs/gst/rtp/gstbasertppayload.c:
* gst-libs/gst/rtp/gstrtcpbuffer.c:
(gst_rtcp_packet_bye_get_reason):
* gst/audioconvert/gstaudioconvert.c:
* gst/audioresample/gstaudioresample.c:
* gst/ffmpegcolorspace/imgconvert.c:
* gst/playback/test.c: (gen_video_element), (gen_audio_element):
* gst/typefind/gsttypefindfunctions.c:
* gst/videoscale/vs_4tap.c:
* gst/videoscale/vs_4tap.h:
* sys/v4l/gstv4lelement.c:
* sys/v4l/gstv4lsrc.c: (gst_v4lsrc_get_any_caps):
* sys/v4l/v4l_calls.c:
* sys/v4l/v4lsrc_calls.c: (gst_v4lsrc_capture_init),
(gst_v4lsrc_try_capture):
* sys/ximage/ximagesink.c: (gst_ximagesink_check_xshm_calls),
(gst_ximagesink_ximage_new):
* sys/xvimage/xvimagesink.c: (gst_xvimagesink_check_xshm_calls),
(gst_xvimagesink_xvimage_new):
* tests/check/elements/audioconvert.c:
* tests/check/elements/audioresample.c:
(fail_unless_perfect_stream):
* tests/check/elements/audiotestsrc.c: (setup_audiotestsrc):
* tests/check/elements/decodebin.c:
* tests/check/elements/gdpdepay.c: (setup_gdpdepay),
(setup_gdpdepay_streamheader):
* tests/check/elements/gdppay.c: (setup_gdppay), (GST_START_TEST),
(setup_gdppay_streamheader):
* tests/check/elements/gnomevfssink.c: (setup_gnomevfssink):
* tests/check/elements/multifdsink.c: (setup_multifdsink):
* tests/check/elements/textoverlay.c:
* tests/check/elements/videorate.c: (setup_videorate):
* tests/check/elements/videotestsrc.c: (setup_videotestsrc):
* tests/check/elements/volume.c: (setup_volume):
* tests/check/elements/vorbisdec.c: (setup_vorbisdec):
* tests/check/elements/vorbistag.c:
* tests/check/generic/clock-selection.c:
* tests/check/generic/states.c: (setup), (teardown):
* tests/check/libs/cddabasesrc.c:
* tests/check/libs/video.c:
* tests/check/pipelines/gio.c:
* tests/check/pipelines/oggmux.c:
* tests/check/pipelines/simple-launch-lines.c:
(simple_launch_lines_suite):
* tests/check/pipelines/streamheader.c:
* tests/check/pipelines/theoraenc.c:
* tests/check/pipelines/vorbisdec.c:
* tests/check/pipelines/vorbisenc.c:
* tests/examples/seek/scrubby.c:
* tests/examples/seek/seek.c: (query_positions_elems),
(query_positions_pads):
* tests/icles/stress-xoverlay.c: (myclock):
Correct all relevant warnings found by the sparse semantic code
analyzer. This include marking several symbols static, using
NULL instead of 0 for pointers and using "foo (void)" instead
of "foo ()" for declarations.
* win32/common/libgstrtp.def:
Add gst_rtp_buffer_set_extension_data to the symbol definition file.
2008-03-03 06:04:31 +00:00
|
|
|
fail_unless_perfect_stream (void)
|
2005-08-25 15:44:58 +00:00
|
|
|
{
|
|
|
|
guint64 timestamp = 0L, duration = 0L;
|
|
|
|
guint64 offset = 0L, offset_end = 0L;
|
|
|
|
|
|
|
|
GList *l;
|
|
|
|
GstBuffer *buffer;
|
|
|
|
|
|
|
|
for (l = buffers; l; l = l->next) {
|
|
|
|
buffer = GST_BUFFER (l->data);
|
|
|
|
ASSERT_BUFFER_REFCOUNT (buffer, "buffer", 1);
|
|
|
|
GST_DEBUG ("buffer timestamp %" G_GUINT64_FORMAT ", duration %"
|
2008-09-01 16:05:45 +00:00
|
|
|
G_GUINT64_FORMAT " offset %" G_GUINT64_FORMAT " offset_end %"
|
|
|
|
G_GUINT64_FORMAT,
|
|
|
|
GST_BUFFER_TIMESTAMP (buffer),
|
|
|
|
GST_BUFFER_DURATION (buffer),
|
|
|
|
GST_BUFFER_OFFSET (buffer), GST_BUFFER_OFFSET_END (buffer));
|
2005-08-25 15:44:58 +00:00
|
|
|
|
|
|
|
fail_unless_equals_uint64 (timestamp, GST_BUFFER_TIMESTAMP (buffer));
|
|
|
|
fail_unless_equals_uint64 (offset, GST_BUFFER_OFFSET (buffer));
|
|
|
|
duration = GST_BUFFER_DURATION (buffer);
|
|
|
|
offset_end = GST_BUFFER_OFFSET_END (buffer);
|
|
|
|
|
|
|
|
timestamp += duration;
|
|
|
|
offset = offset_end;
|
2005-08-25 16:19:39 +00:00
|
|
|
gst_buffer_unref (buffer);
|
2005-08-25 15:44:58 +00:00
|
|
|
}
|
2005-08-25 16:19:39 +00:00
|
|
|
g_list_free (buffers);
|
|
|
|
buffers = NULL;
|
2005-08-25 15:44:58 +00:00
|
|
|
}
|
|
|
|
|
2007-03-14 17:16:30 +00:00
|
|
|
/* this tests that the output is a perfect stream if the input is */
|
2005-08-25 15:44:58 +00:00
|
|
|
static void
|
|
|
|
test_perfect_stream_instance (int inrate, int outrate, int samples,
|
|
|
|
int numbuffers)
|
|
|
|
{
|
|
|
|
GstElement *audioresample;
|
|
|
|
GstBuffer *inbuffer, *outbuffer;
|
|
|
|
GstCaps *caps;
|
2008-09-01 16:05:45 +00:00
|
|
|
guint64 offset = 0;
|
2005-08-25 15:44:58 +00:00
|
|
|
|
|
|
|
int i, j;
|
|
|
|
gint16 *p;
|
|
|
|
|
2009-01-23 11:31:06 +00:00
|
|
|
audioresample = setup_audioresample (2, inrate, outrate, 16, FALSE);
|
2005-08-25 15:44:58 +00:00
|
|
|
caps = gst_pad_get_negotiated_caps (mysrcpad);
|
|
|
|
fail_unless (gst_caps_is_fixed (caps));
|
|
|
|
|
|
|
|
fail_unless (gst_element_set_state (audioresample,
|
2005-09-02 15:43:18 +00:00
|
|
|
GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
|
|
|
|
"could not set to playing");
|
2005-08-25 15:44:58 +00:00
|
|
|
|
|
|
|
for (j = 1; j <= numbuffers; ++j) {
|
|
|
|
|
|
|
|
inbuffer = gst_buffer_new_and_alloc (samples * 4);
|
2009-01-23 11:31:06 +00:00
|
|
|
GST_BUFFER_DURATION (inbuffer) = GST_FRAMES_TO_CLOCK_TIME (samples, inrate);
|
2005-08-25 15:44:58 +00:00
|
|
|
GST_BUFFER_TIMESTAMP (inbuffer) = GST_BUFFER_DURATION (inbuffer) * (j - 1);
|
2008-09-01 16:05:45 +00:00
|
|
|
GST_BUFFER_OFFSET (inbuffer) = offset;
|
|
|
|
offset += samples;
|
|
|
|
GST_BUFFER_OFFSET_END (inbuffer) = offset;
|
2005-08-25 15:44:58 +00:00
|
|
|
|
|
|
|
gst_buffer_set_caps (inbuffer, caps);
|
|
|
|
|
|
|
|
p = (gint16 *) GST_BUFFER_DATA (inbuffer);
|
|
|
|
|
|
|
|
/* create a 16 bit signed ramp */
|
|
|
|
for (i = 0; i < samples; ++i) {
|
|
|
|
*p = -32767 + i * (65535 / samples);
|
|
|
|
++p;
|
|
|
|
*p = -32767 + i * (65535 / samples);
|
|
|
|
++p;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* pushing gives away my reference ... */
|
|
|
|
fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
|
|
|
|
/* ... but it ends up being collected on the global buffer list */
|
2005-08-25 16:19:39 +00:00
|
|
|
fail_unless_equals_int (g_list_length (buffers), j);
|
2005-08-25 15:44:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME: we should make audioresample handle eos by flushing out the last
|
|
|
|
* samples, which will give us one more, small, buffer */
|
|
|
|
fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
|
|
|
|
ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 1);
|
|
|
|
|
|
|
|
fail_unless_perfect_stream ();
|
|
|
|
|
|
|
|
/* cleanup */
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
cleanup_audioresample (audioresample);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* make sure that outgoing buffers are contiguous in timestamp/duration and
|
|
|
|
* offset/offsetend
|
|
|
|
*/
|
|
|
|
GST_START_TEST (test_perfect_stream)
|
|
|
|
{
|
2005-08-25 16:19:39 +00:00
|
|
|
/* integral scalings */
|
|
|
|
test_perfect_stream_instance (48000, 24000, 500, 20);
|
|
|
|
test_perfect_stream_instance (48000, 12000, 500, 20);
|
|
|
|
test_perfect_stream_instance (12000, 24000, 500, 20);
|
|
|
|
test_perfect_stream_instance (12000, 48000, 500, 20);
|
|
|
|
|
|
|
|
/* non-integral scalings */
|
|
|
|
test_perfect_stream_instance (44100, 8000, 500, 20);
|
|
|
|
test_perfect_stream_instance (8000, 44100, 500, 20);
|
|
|
|
|
|
|
|
/* wacky scalings */
|
|
|
|
test_perfect_stream_instance (12345, 54321, 500, 20);
|
|
|
|
test_perfect_stream_instance (101, 99, 500, 20);
|
2005-08-25 15:44:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
2007-03-14 17:16:30 +00:00
|
|
|
/* this tests that the output is a correct discontinuous stream
|
|
|
|
* if the input is; ie input drops in time come out the same way */
|
|
|
|
static void
|
|
|
|
test_discont_stream_instance (int inrate, int outrate, int samples,
|
|
|
|
int numbuffers)
|
|
|
|
{
|
|
|
|
GstElement *audioresample;
|
|
|
|
GstBuffer *inbuffer, *outbuffer;
|
|
|
|
GstCaps *caps;
|
|
|
|
GstClockTime ints;
|
|
|
|
|
|
|
|
int i, j;
|
|
|
|
gint16 *p;
|
|
|
|
|
2008-09-01 16:05:45 +00:00
|
|
|
GST_DEBUG ("inrate:%d outrate:%d samples:%d numbuffers:%d",
|
|
|
|
inrate, outrate, samples, numbuffers);
|
|
|
|
|
2009-01-23 11:31:06 +00:00
|
|
|
audioresample = setup_audioresample (2, inrate, outrate, 16, FALSE);
|
2007-03-14 17:16:30 +00:00
|
|
|
caps = gst_pad_get_negotiated_caps (mysrcpad);
|
|
|
|
fail_unless (gst_caps_is_fixed (caps));
|
|
|
|
|
|
|
|
fail_unless (gst_element_set_state (audioresample,
|
|
|
|
GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
|
|
|
|
"could not set to playing");
|
|
|
|
|
|
|
|
for (j = 1; j <= numbuffers; ++j) {
|
|
|
|
|
|
|
|
inbuffer = gst_buffer_new_and_alloc (samples * 4);
|
|
|
|
GST_BUFFER_DURATION (inbuffer) = samples * GST_SECOND / inrate;
|
|
|
|
/* "drop" half the buffers */
|
|
|
|
ints = GST_BUFFER_DURATION (inbuffer) * 2 * (j - 1);
|
|
|
|
GST_BUFFER_TIMESTAMP (inbuffer) = ints;
|
|
|
|
GST_BUFFER_OFFSET (inbuffer) = (j - 1) * 2 * samples;
|
|
|
|
GST_BUFFER_OFFSET_END (inbuffer) = j * 2 * samples + samples;
|
|
|
|
|
|
|
|
gst_buffer_set_caps (inbuffer, caps);
|
|
|
|
|
|
|
|
p = (gint16 *) GST_BUFFER_DATA (inbuffer);
|
|
|
|
|
|
|
|
/* create a 16 bit signed ramp */
|
|
|
|
for (i = 0; i < samples; ++i) {
|
|
|
|
*p = -32767 + i * (65535 / samples);
|
|
|
|
++p;
|
|
|
|
*p = -32767 + i * (65535 / samples);
|
|
|
|
++p;
|
|
|
|
}
|
|
|
|
|
2008-09-01 16:05:45 +00:00
|
|
|
GST_DEBUG ("Sending Buffer time:%" G_GUINT64_FORMAT " duration:%"
|
|
|
|
G_GINT64_FORMAT " discont:%d offset:%" G_GUINT64_FORMAT " offset_end:%"
|
|
|
|
G_GUINT64_FORMAT, GST_BUFFER_TIMESTAMP (inbuffer),
|
|
|
|
GST_BUFFER_DURATION (inbuffer), GST_BUFFER_IS_DISCONT (inbuffer),
|
|
|
|
GST_BUFFER_OFFSET (inbuffer), GST_BUFFER_OFFSET_END (inbuffer));
|
2007-03-14 17:16:30 +00:00
|
|
|
/* pushing gives away my reference ... */
|
|
|
|
fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
|
|
|
|
|
|
|
|
/* check if the timestamp of the pushed buffer matches the incoming one */
|
|
|
|
outbuffer = g_list_nth_data (buffers, g_list_length (buffers) - 1);
|
|
|
|
fail_if (outbuffer == NULL);
|
|
|
|
fail_unless_equals_uint64 (ints, GST_BUFFER_TIMESTAMP (outbuffer));
|
2008-09-01 16:05:45 +00:00
|
|
|
GST_DEBUG ("Got Buffer time:%" G_GUINT64_FORMAT " duration:%"
|
|
|
|
G_GINT64_FORMAT " discont:%d offset:%" G_GUINT64_FORMAT " offset_end:%"
|
|
|
|
G_GUINT64_FORMAT, GST_BUFFER_TIMESTAMP (outbuffer),
|
|
|
|
GST_BUFFER_DURATION (outbuffer), GST_BUFFER_IS_DISCONT (outbuffer),
|
|
|
|
GST_BUFFER_OFFSET (outbuffer), GST_BUFFER_OFFSET_END (outbuffer));
|
2007-03-14 17:16:30 +00:00
|
|
|
if (j > 1) {
|
|
|
|
fail_unless (GST_BUFFER_IS_DISCONT (outbuffer),
|
2008-09-01 16:05:45 +00:00
|
|
|
"expected discont for buffer #%d", j);
|
2007-03-14 17:16:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* cleanup */
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
cleanup_audioresample (audioresample);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_START_TEST (test_discont_stream)
|
|
|
|
{
|
|
|
|
/* integral scalings */
|
2010-12-13 12:04:40 +00:00
|
|
|
test_discont_stream_instance (48000, 24000, 5000, 20);
|
|
|
|
test_discont_stream_instance (48000, 12000, 5000, 20);
|
|
|
|
test_discont_stream_instance (12000, 24000, 5000, 20);
|
|
|
|
test_discont_stream_instance (12000, 48000, 5000, 20);
|
2007-03-14 17:16:30 +00:00
|
|
|
|
|
|
|
/* non-integral scalings */
|
2010-12-13 12:04:40 +00:00
|
|
|
test_discont_stream_instance (44100, 8000, 5000, 20);
|
|
|
|
test_discont_stream_instance (8000, 44100, 5000, 20);
|
2007-03-14 17:16:30 +00:00
|
|
|
|
|
|
|
/* wacky scalings */
|
2010-12-13 12:04:40 +00:00
|
|
|
test_discont_stream_instance (12345, 54321, 5000, 20);
|
|
|
|
test_discont_stream_instance (101, 99, 5000, 20);
|
2007-03-14 17:16:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-06-16 15:43:23 +00:00
|
|
|
GST_START_TEST (test_reuse)
|
|
|
|
{
|
|
|
|
GstElement *audioresample;
|
|
|
|
GstEvent *newseg;
|
|
|
|
GstBuffer *inbuffer;
|
|
|
|
GstCaps *caps;
|
|
|
|
|
2009-01-23 11:31:06 +00:00
|
|
|
audioresample = setup_audioresample (1, 9343, 48000, 16, FALSE);
|
2006-06-16 15:43:23 +00:00
|
|
|
caps = gst_pad_get_negotiated_caps (mysrcpad);
|
|
|
|
fail_unless (gst_caps_is_fixed (caps));
|
|
|
|
|
|
|
|
fail_unless (gst_element_set_state (audioresample,
|
|
|
|
GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
|
|
|
|
"could not set to playing");
|
|
|
|
|
|
|
|
newseg = gst_event_new_new_segment (FALSE, 1.0, GST_FORMAT_TIME, 0, -1, 0);
|
|
|
|
fail_unless (gst_pad_push_event (mysrcpad, newseg) != FALSE);
|
|
|
|
|
|
|
|
inbuffer = gst_buffer_new_and_alloc (9343 * 4);
|
|
|
|
memset (GST_BUFFER_DATA (inbuffer), 0, GST_BUFFER_SIZE (inbuffer));
|
|
|
|
GST_BUFFER_DURATION (inbuffer) = GST_SECOND;
|
|
|
|
GST_BUFFER_TIMESTAMP (inbuffer) = 0;
|
|
|
|
GST_BUFFER_OFFSET (inbuffer) = 0;
|
|
|
|
gst_buffer_set_caps (inbuffer, caps);
|
|
|
|
|
|
|
|
/* pushing gives away my reference ... */
|
|
|
|
fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
|
|
|
|
|
|
|
|
/* ... but it ends up being collected on the global buffer list */
|
|
|
|
fail_unless_equals_int (g_list_length (buffers), 1);
|
|
|
|
|
|
|
|
/* now reset and try again ... */
|
|
|
|
fail_unless (gst_element_set_state (audioresample,
|
|
|
|
GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to NULL");
|
|
|
|
|
|
|
|
fail_unless (gst_element_set_state (audioresample,
|
|
|
|
GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
|
|
|
|
"could not set to playing");
|
|
|
|
|
|
|
|
newseg = gst_event_new_new_segment (FALSE, 1.0, GST_FORMAT_TIME, 0, -1, 0);
|
|
|
|
fail_unless (gst_pad_push_event (mysrcpad, newseg) != FALSE);
|
|
|
|
|
|
|
|
inbuffer = gst_buffer_new_and_alloc (9343 * 4);
|
|
|
|
memset (GST_BUFFER_DATA (inbuffer), 0, GST_BUFFER_SIZE (inbuffer));
|
|
|
|
GST_BUFFER_DURATION (inbuffer) = GST_SECOND;
|
|
|
|
GST_BUFFER_TIMESTAMP (inbuffer) = 0;
|
|
|
|
GST_BUFFER_OFFSET (inbuffer) = 0;
|
|
|
|
gst_buffer_set_caps (inbuffer, caps);
|
|
|
|
|
|
|
|
fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
|
|
|
|
|
|
|
|
/* ... it also ends up being collected on the global buffer list. If we
|
|
|
|
* now have more than 2 buffers, then audioresample probably didn't clean
|
|
|
|
* up its internal buffer properly and tried to push the remaining samples
|
|
|
|
* when it got the second NEWSEGMENT event */
|
|
|
|
fail_unless_equals_int (g_list_length (buffers), 2);
|
|
|
|
|
|
|
|
cleanup_audioresample (audioresample);
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
2007-04-21 13:54:39 +00:00
|
|
|
GST_START_TEST (test_shutdown)
|
|
|
|
{
|
|
|
|
GstElement *pipeline, *src, *cf1, *ar, *cf2, *sink;
|
|
|
|
GstCaps *caps;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
/* create pipeline, force audioresample to actually resample */
|
|
|
|
pipeline = gst_pipeline_new (NULL);
|
|
|
|
|
|
|
|
src = gst_check_setup_element ("audiotestsrc");
|
|
|
|
cf1 = gst_check_setup_element ("capsfilter");
|
|
|
|
ar = gst_check_setup_element ("audioresample");
|
|
|
|
cf2 = gst_check_setup_element ("capsfilter");
|
|
|
|
g_object_set (cf2, "name", "capsfilter2", NULL);
|
|
|
|
sink = gst_check_setup_element ("fakesink");
|
|
|
|
|
|
|
|
caps =
|
|
|
|
gst_caps_new_simple ("audio/x-raw-int", "rate", G_TYPE_INT, 11025, NULL);
|
|
|
|
g_object_set (cf1, "caps", caps, NULL);
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
|
|
|
|
caps =
|
|
|
|
gst_caps_new_simple ("audio/x-raw-int", "rate", G_TYPE_INT, 48000, NULL);
|
|
|
|
g_object_set (cf2, "caps", caps, NULL);
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
|
|
|
|
/* don't want to sync against the clock, the more throughput the better */
|
|
|
|
g_object_set (src, "is-live", FALSE, NULL);
|
|
|
|
g_object_set (sink, "sync", FALSE, NULL);
|
|
|
|
|
|
|
|
gst_bin_add_many (GST_BIN (pipeline), src, cf1, ar, cf2, sink, NULL);
|
|
|
|
fail_if (!gst_element_link_many (src, cf1, ar, cf2, sink, NULL));
|
|
|
|
|
|
|
|
/* now, wait until pipeline is running and then shut it down again; repeat */
|
|
|
|
for (i = 0; i < 20; ++i) {
|
|
|
|
gst_element_set_state (pipeline, GST_STATE_PAUSED);
|
|
|
|
gst_element_get_state (pipeline, NULL, NULL, -1);
|
|
|
|
gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
|
|
|
g_usleep (100);
|
|
|
|
gst_element_set_state (pipeline, GST_STATE_NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_object_unref (pipeline);
|
|
|
|
}
|
|
|
|
|
2008-05-08 06:20:42 +00:00
|
|
|
GST_END_TEST;
|
|
|
|
|
|
|
|
static GstFlowReturn
|
2008-05-13 10:59:49 +00:00
|
|
|
live_switch_alloc_only_48000 (GstPad * pad, guint64 offset,
|
|
|
|
guint size, GstCaps * caps, GstBuffer ** buf)
|
2008-05-08 06:20:42 +00:00
|
|
|
{
|
|
|
|
GstStructure *structure;
|
|
|
|
gint rate;
|
2008-05-13 10:59:49 +00:00
|
|
|
gint channels;
|
|
|
|
GstCaps *desired;
|
2008-05-08 06:20:42 +00:00
|
|
|
|
|
|
|
structure = gst_caps_get_structure (caps, 0);
|
|
|
|
fail_unless (gst_structure_get_int (structure, "rate", &rate));
|
2008-05-13 10:59:49 +00:00
|
|
|
fail_unless (gst_structure_get_int (structure, "channels", &channels));
|
2008-05-08 06:20:42 +00:00
|
|
|
|
2008-05-13 10:59:49 +00:00
|
|
|
if (rate < 48000)
|
2008-05-08 06:20:42 +00:00
|
|
|
return GST_FLOW_NOT_NEGOTIATED;
|
|
|
|
|
2008-05-13 10:59:49 +00:00
|
|
|
desired = gst_caps_copy (caps);
|
|
|
|
gst_caps_set_simple (desired, "rate", G_TYPE_INT, 48000, NULL);
|
|
|
|
|
|
|
|
*buf = gst_buffer_new_and_alloc (channels * 48000);
|
|
|
|
gst_buffer_set_caps (*buf, desired);
|
|
|
|
gst_caps_unref (desired);
|
|
|
|
|
2008-05-08 06:20:42 +00:00
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
|
2008-05-13 10:59:49 +00:00
|
|
|
static GstCaps *
|
|
|
|
live_switch_get_sink_caps (GstPad * pad)
|
2008-05-08 06:20:42 +00:00
|
|
|
{
|
2008-05-13 10:59:49 +00:00
|
|
|
GstCaps *result;
|
2008-05-08 06:20:42 +00:00
|
|
|
|
2008-05-13 10:59:49 +00:00
|
|
|
result = gst_caps_copy (GST_PAD_CAPS (pad));
|
2008-05-08 06:20:42 +00:00
|
|
|
|
2008-05-13 10:59:49 +00:00
|
|
|
gst_caps_set_simple (result,
|
|
|
|
"rate", GST_TYPE_INT_RANGE, 48000, G_MAXINT, NULL);
|
2008-05-08 06:20:42 +00:00
|
|
|
|
2008-05-13 10:59:49 +00:00
|
|
|
return result;
|
|
|
|
}
|
2008-05-08 06:20:42 +00:00
|
|
|
|
2008-05-13 10:59:49 +00:00
|
|
|
static void
|
|
|
|
live_switch_push (int rate, GstCaps * caps)
|
|
|
|
{
|
|
|
|
GstBuffer *inbuffer;
|
|
|
|
GstCaps *desired;
|
|
|
|
GList *l;
|
2008-05-08 06:20:42 +00:00
|
|
|
|
2008-05-13 10:59:49 +00:00
|
|
|
desired = gst_caps_copy (caps);
|
|
|
|
gst_caps_set_simple (desired, "rate", G_TYPE_INT, rate, NULL);
|
2009-01-23 11:31:06 +00:00
|
|
|
gst_pad_set_caps (mysrcpad, desired);
|
2008-05-08 06:20:42 +00:00
|
|
|
|
|
|
|
fail_unless (gst_pad_alloc_buffer_and_set_caps (mysrcpad,
|
2008-05-13 10:59:49 +00:00
|
|
|
GST_BUFFER_OFFSET_NONE, rate * 4, desired, &inbuffer) == GST_FLOW_OK);
|
|
|
|
|
|
|
|
/* When the basetransform hits the non-configured case it always
|
|
|
|
* returns a buffer with exactly the same caps as we requested so the actual
|
|
|
|
* renegotiation (if needed) will be done in the _chain*/
|
|
|
|
fail_unless (inbuffer != NULL);
|
2009-01-23 11:31:06 +00:00
|
|
|
GST_DEBUG ("desired: %" GST_PTR_FORMAT ".... got: %" GST_PTR_FORMAT,
|
|
|
|
desired, GST_BUFFER_CAPS (inbuffer));
|
2008-05-13 10:59:49 +00:00
|
|
|
fail_unless (gst_caps_is_equal (desired, GST_BUFFER_CAPS (inbuffer)));
|
2008-05-08 06:20:42 +00:00
|
|
|
|
|
|
|
memset (GST_BUFFER_DATA (inbuffer), 0, GST_BUFFER_SIZE (inbuffer));
|
|
|
|
GST_BUFFER_DURATION (inbuffer) = GST_SECOND;
|
|
|
|
GST_BUFFER_TIMESTAMP (inbuffer) = 0;
|
|
|
|
GST_BUFFER_OFFSET (inbuffer) = 0;
|
|
|
|
|
|
|
|
/* pushing gives away my reference ... */
|
|
|
|
fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
|
|
|
|
|
|
|
|
/* ... but it ends up being collected on the global buffer list */
|
|
|
|
fail_unless_equals_int (g_list_length (buffers), 1);
|
|
|
|
|
|
|
|
for (l = buffers; l; l = l->next) {
|
|
|
|
GstBuffer *buffer = GST_BUFFER (l->data);
|
|
|
|
|
|
|
|
gst_buffer_unref (buffer);
|
|
|
|
}
|
2008-05-13 10:59:49 +00:00
|
|
|
|
2008-05-08 06:20:42 +00:00
|
|
|
g_list_free (buffers);
|
|
|
|
buffers = NULL;
|
2008-05-13 10:59:49 +00:00
|
|
|
|
|
|
|
gst_caps_unref (desired);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_START_TEST (test_live_switch)
|
|
|
|
{
|
|
|
|
GstElement *audioresample;
|
|
|
|
GstEvent *newseg;
|
|
|
|
GstCaps *caps;
|
|
|
|
|
2009-01-23 11:31:06 +00:00
|
|
|
audioresample = setup_audioresample (4, 48000, 48000, 16, FALSE);
|
2008-05-13 10:59:49 +00:00
|
|
|
|
|
|
|
/* Let the sinkpad act like something that can only handle things of
|
|
|
|
* rate 48000- and can only allocate buffers for that rate, but if someone
|
|
|
|
* tries to get a buffer with a rate higher then 48000 tries to renegotiate
|
|
|
|
* */
|
|
|
|
gst_pad_set_bufferalloc_function (mysinkpad, live_switch_alloc_only_48000);
|
|
|
|
gst_pad_set_getcaps_function (mysinkpad, live_switch_get_sink_caps);
|
|
|
|
|
2009-01-23 11:31:06 +00:00
|
|
|
gst_pad_use_fixed_caps (mysrcpad);
|
|
|
|
|
2008-05-13 10:59:49 +00:00
|
|
|
caps = gst_pad_get_negotiated_caps (mysrcpad);
|
|
|
|
fail_unless (gst_caps_is_fixed (caps));
|
|
|
|
|
|
|
|
fail_unless (gst_element_set_state (audioresample,
|
|
|
|
GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
|
|
|
|
"could not set to playing");
|
|
|
|
|
|
|
|
newseg = gst_event_new_new_segment (FALSE, 1.0, GST_FORMAT_TIME, 0, -1, 0);
|
|
|
|
fail_unless (gst_pad_push_event (mysrcpad, newseg) != FALSE);
|
|
|
|
|
|
|
|
/* downstream can provide the requested rate, a buffer alloc will be passed
|
|
|
|
* on */
|
|
|
|
live_switch_push (48000, caps);
|
|
|
|
|
|
|
|
/* Downstream can never accept this rate, buffer alloc isn't passed on */
|
|
|
|
live_switch_push (40000, caps);
|
|
|
|
|
|
|
|
/* Downstream can provide the requested rate but will re-negotiate */
|
|
|
|
live_switch_push (50000, caps);
|
|
|
|
|
|
|
|
cleanup_audioresample (audioresample);
|
2008-05-08 06:20:42 +00:00
|
|
|
gst_caps_unref (caps);
|
|
|
|
}
|
|
|
|
|
2009-01-23 11:31:06 +00:00
|
|
|
GST_END_TEST;
|
|
|
|
|
|
|
|
#ifndef GST_DISABLE_PARSE
|
|
|
|
|
|
|
|
static GMainLoop *loop;
|
|
|
|
static gint messages = 0;
|
|
|
|
|
|
|
|
static void
|
|
|
|
element_message_cb (GstBus * bus, GstMessage * message, gpointer user_data)
|
|
|
|
{
|
|
|
|
gchar *s;
|
|
|
|
|
|
|
|
s = gst_structure_to_string (gst_message_get_structure (message));
|
|
|
|
GST_DEBUG ("Received message: %s", s);
|
|
|
|
g_free (s);
|
|
|
|
|
|
|
|
messages++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
eos_message_cb (GstBus * bus, GstMessage * message, gpointer user_data)
|
|
|
|
{
|
|
|
|
GST_DEBUG ("Received eos");
|
|
|
|
g_main_loop_quit (loop);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_pipeline (gint width, gboolean fp, gint inrate, gint outrate, gint quality)
|
|
|
|
{
|
|
|
|
GstElement *pipeline;
|
|
|
|
GstBus *bus;
|
|
|
|
GError *error = NULL;
|
|
|
|
gchar *pipe_str;
|
|
|
|
|
|
|
|
pipe_str =
|
|
|
|
g_strdup_printf
|
|
|
|
("audiotestsrc num-buffers=10 ! audioconvert ! audio/x-raw-%s,rate=%d,width=%d,channels=2 ! audioresample quality=%d ! audio/x-raw-%s,rate=%d,width=%d ! identity check-imperfect-timestamp=TRUE ! fakesink",
|
|
|
|
(fp) ? "float" : "int", inrate, width, quality, (fp) ? "float" : "int",
|
|
|
|
outrate, width);
|
|
|
|
|
|
|
|
pipeline = gst_parse_launch (pipe_str, &error);
|
|
|
|
fail_unless (pipeline != NULL, "Error parsing pipeline: %s",
|
|
|
|
error ? error->message : "(invalid error)");
|
|
|
|
g_free (pipe_str);
|
|
|
|
|
|
|
|
bus = gst_element_get_bus (pipeline);
|
|
|
|
fail_if (bus == NULL);
|
|
|
|
gst_bus_add_signal_watch (bus);
|
|
|
|
g_signal_connect (bus, "message::element", (GCallback) element_message_cb,
|
|
|
|
NULL);
|
|
|
|
g_signal_connect (bus, "message::eos", (GCallback) eos_message_cb, NULL);
|
|
|
|
|
|
|
|
gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
|
|
|
|
|
|
|
/* run until we receive EOS */
|
|
|
|
loop = g_main_loop_new (NULL, FALSE);
|
|
|
|
|
|
|
|
g_main_loop_run (loop);
|
|
|
|
|
|
|
|
g_main_loop_unref (loop);
|
|
|
|
loop = NULL;
|
|
|
|
|
|
|
|
gst_element_set_state (pipeline, GST_STATE_NULL);
|
|
|
|
|
|
|
|
fail_if (messages > 0, "Received imperfect timestamp messages");
|
|
|
|
gst_object_unref (pipeline);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_START_TEST (test_pipelines)
|
|
|
|
{
|
|
|
|
gint quality;
|
|
|
|
|
|
|
|
/* Test qualities 0, 5 and 10 */
|
|
|
|
for (quality = 0; quality < 11; quality += 5) {
|
2009-08-21 08:02:05 +00:00
|
|
|
GST_DEBUG ("Checking with quality %d", quality);
|
|
|
|
|
2009-01-23 11:31:06 +00:00
|
|
|
test_pipeline (8, FALSE, 44100, 48000, quality);
|
|
|
|
test_pipeline (8, FALSE, 48000, 44100, quality);
|
|
|
|
|
|
|
|
test_pipeline (16, FALSE, 44100, 48000, quality);
|
|
|
|
test_pipeline (16, FALSE, 48000, 44100, quality);
|
|
|
|
|
|
|
|
test_pipeline (24, FALSE, 44100, 48000, quality);
|
|
|
|
test_pipeline (24, FALSE, 48000, 44100, quality);
|
|
|
|
|
|
|
|
test_pipeline (32, FALSE, 44100, 48000, quality);
|
|
|
|
test_pipeline (32, FALSE, 48000, 44100, quality);
|
|
|
|
|
|
|
|
test_pipeline (32, TRUE, 44100, 48000, quality);
|
|
|
|
test_pipeline (32, TRUE, 48000, 44100, quality);
|
|
|
|
|
|
|
|
test_pipeline (64, TRUE, 44100, 48000, quality);
|
|
|
|
test_pipeline (64, TRUE, 48000, 44100, quality);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
2009-04-01 14:15:57 +00:00
|
|
|
|
|
|
|
GST_START_TEST (test_preference_passthrough)
|
|
|
|
{
|
|
|
|
GstStateChangeReturn ret;
|
|
|
|
GstElement *pipeline, *src;
|
|
|
|
GstStructure *s;
|
|
|
|
GstMessage *msg;
|
|
|
|
GstCaps *caps;
|
|
|
|
GstPad *pad;
|
|
|
|
GstBus *bus;
|
|
|
|
GError *error = NULL;
|
|
|
|
gint rate = 0;
|
|
|
|
|
|
|
|
pipeline = gst_parse_launch ("audiotestsrc num-buffers=1 name=src ! "
|
|
|
|
"audioresample ! audio/x-raw-int,channels=1,width=16,depth=16,"
|
2009-05-12 22:51:08 +00:00
|
|
|
"endianness=BYTE_ORDER,signed=true,rate=8000 ! "
|
2009-04-01 14:15:57 +00:00
|
|
|
"fakesink can-activate-pull=false", &error);
|
|
|
|
fail_unless (pipeline != NULL, "Error parsing pipeline: %s",
|
|
|
|
error ? error->message : "(invalid error)");
|
|
|
|
|
|
|
|
ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
|
|
|
fail_unless_equals_int (ret, GST_STATE_CHANGE_ASYNC);
|
|
|
|
|
|
|
|
/* run until we receive EOS */
|
|
|
|
bus = gst_element_get_bus (pipeline);
|
|
|
|
fail_if (bus == NULL);
|
|
|
|
msg = gst_bus_timed_pop_filtered (bus, -1, GST_MESSAGE_EOS);
|
|
|
|
gst_message_unref (msg);
|
|
|
|
gst_object_unref (bus);
|
|
|
|
|
|
|
|
src = gst_bin_get_by_name (GST_BIN (pipeline), "src");
|
|
|
|
fail_unless (src != NULL);
|
|
|
|
pad = gst_element_get_static_pad (src, "src");
|
|
|
|
fail_unless (pad != NULL);
|
|
|
|
caps = gst_pad_get_negotiated_caps (pad);
|
|
|
|
GST_LOG ("negotiated audiotestsrc caps: %" GST_PTR_FORMAT, caps);
|
|
|
|
fail_unless (caps != NULL);
|
|
|
|
s = gst_caps_get_structure (caps, 0);
|
|
|
|
fail_unless (gst_structure_get_int (s, "rate", &rate));
|
|
|
|
/* there's no need to resample, audiotestsrc supports any rate, so make
|
|
|
|
* sure audioresample provided upstream with the right caps to negotiate
|
|
|
|
* this correctly */
|
|
|
|
fail_unless_equals_int (rate, 8000);
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
gst_object_unref (pad);
|
|
|
|
gst_object_unref (src);
|
|
|
|
|
|
|
|
gst_element_set_state (pipeline, GST_STATE_NULL);
|
|
|
|
gst_object_unref (pipeline);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
2009-01-23 11:31:06 +00:00
|
|
|
#endif
|
|
|
|
|
2009-08-21 09:51:47 +00:00
|
|
|
static void
|
|
|
|
_message_cb (GstBus * bus, GstMessage * message, gpointer user_data)
|
|
|
|
{
|
|
|
|
GMainLoop *loop = user_data;
|
|
|
|
|
|
|
|
switch (GST_MESSAGE_TYPE (message)) {
|
|
|
|
case GST_MESSAGE_ERROR:
|
|
|
|
case GST_MESSAGE_WARNING:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
break;
|
|
|
|
case GST_MESSAGE_EOS:
|
|
|
|
g_main_loop_quit (loop);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
guint64 latency;
|
|
|
|
GstClockTime in_ts;
|
|
|
|
|
|
|
|
GstClockTime next_out_ts;
|
|
|
|
guint64 next_out_off;
|
|
|
|
|
|
|
|
guint64 in_buffer_count, out_buffer_count;
|
|
|
|
} TimestampDriftCtx;
|
|
|
|
|
2010-03-11 12:32:14 +00:00
|
|
|
static void
|
2009-08-21 09:51:47 +00:00
|
|
|
fakesink_handoff_cb (GstElement * object, GstBuffer * buffer, GstPad * pad,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
TimestampDriftCtx *ctx = user_data;
|
|
|
|
|
|
|
|
ctx->out_buffer_count++;
|
|
|
|
if (ctx->latency == GST_CLOCK_TIME_NONE) {
|
|
|
|
ctx->latency = 1000 - GST_BUFFER_SIZE (buffer) / 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if we have a perfectly timestampped stream */
|
|
|
|
if (ctx->next_out_ts != GST_CLOCK_TIME_NONE)
|
|
|
|
fail_unless (ctx->next_out_ts == GST_BUFFER_TIMESTAMP (buffer),
|
|
|
|
"expected timestamp %" GST_TIME_FORMAT " got timestamp %"
|
|
|
|
GST_TIME_FORMAT, GST_TIME_ARGS (ctx->next_out_ts),
|
|
|
|
GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer)));
|
|
|
|
|
|
|
|
/* Check if we have a perfectly offsetted stream */
|
|
|
|
fail_unless (GST_BUFFER_OFFSET_END (buffer) ==
|
|
|
|
GST_BUFFER_OFFSET (buffer) + GST_BUFFER_SIZE (buffer) / 8,
|
|
|
|
"expected offset end %" G_GUINT64_FORMAT " got offset end %"
|
|
|
|
G_GUINT64_FORMAT,
|
|
|
|
GST_BUFFER_OFFSET (buffer) + GST_BUFFER_SIZE (buffer) / 8,
|
|
|
|
GST_BUFFER_OFFSET_END (buffer));
|
|
|
|
if (ctx->next_out_off != GST_BUFFER_OFFSET_NONE) {
|
|
|
|
fail_unless (GST_BUFFER_OFFSET (buffer) == ctx->next_out_off,
|
|
|
|
"expected offset %" G_GUINT64_FORMAT " got offset %" G_GUINT64_FORMAT,
|
|
|
|
ctx->next_out_off, GST_BUFFER_OFFSET (buffer));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ctx->in_buffer_count != ctx->out_buffer_count) {
|
2009-09-11 20:44:18 +00:00
|
|
|
GST_INFO ("timestamp %" GST_TIME_FORMAT,
|
2009-08-21 09:51:47 +00:00
|
|
|
GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer)));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ctx->in_ts != GST_CLOCK_TIME_NONE && ctx->in_buffer_count > 1
|
|
|
|
&& ctx->in_buffer_count == ctx->out_buffer_count) {
|
|
|
|
fail_unless (GST_BUFFER_TIMESTAMP (buffer) ==
|
|
|
|
ctx->in_ts - gst_util_uint64_scale_round (ctx->latency, GST_SECOND,
|
|
|
|
4096),
|
|
|
|
"expected output timestamp %" GST_TIME_FORMAT " (%" G_GUINT64_FORMAT
|
|
|
|
") got output timestamp %" GST_TIME_FORMAT " (%" G_GUINT64_FORMAT ")",
|
|
|
|
GST_TIME_ARGS (ctx->in_ts - gst_util_uint64_scale_round (ctx->latency,
|
|
|
|
GST_SECOND, 4096)),
|
|
|
|
ctx->in_ts - gst_util_uint64_scale_round (ctx->latency, GST_SECOND,
|
|
|
|
4096), GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer)),
|
|
|
|
GST_BUFFER_TIMESTAMP (buffer));
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx->next_out_ts =
|
|
|
|
GST_BUFFER_TIMESTAMP (buffer) + GST_BUFFER_DURATION (buffer);
|
|
|
|
ctx->next_out_off = GST_BUFFER_OFFSET_END (buffer);
|
|
|
|
}
|
|
|
|
|
2010-03-11 12:32:14 +00:00
|
|
|
static void
|
2009-08-21 09:51:47 +00:00
|
|
|
identity_handoff_cb (GstElement * object, GstBuffer * buffer,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
TimestampDriftCtx *ctx = user_data;
|
|
|
|
|
|
|
|
ctx->in_ts = GST_BUFFER_TIMESTAMP (buffer);
|
|
|
|
ctx->in_buffer_count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_START_TEST (test_timestamp_drift)
|
|
|
|
{
|
|
|
|
TimestampDriftCtx ctx =
|
|
|
|
{ GST_CLOCK_TIME_NONE, GST_CLOCK_TIME_NONE, GST_CLOCK_TIME_NONE,
|
|
|
|
GST_BUFFER_OFFSET_NONE, 0, 0
|
|
|
|
};
|
|
|
|
GstElement *pipeline;
|
|
|
|
GstElement *audiotestsrc, *capsfilter1, *identity, *audioresample,
|
|
|
|
*capsfilter2, *fakesink;
|
|
|
|
GstBus *bus;
|
|
|
|
GMainLoop *loop;
|
|
|
|
GstCaps *caps;
|
|
|
|
|
|
|
|
pipeline = gst_pipeline_new ("pipeline");
|
|
|
|
fail_unless (pipeline != NULL);
|
|
|
|
|
|
|
|
audiotestsrc = gst_element_factory_make ("audiotestsrc", "src");
|
|
|
|
fail_unless (audiotestsrc != NULL);
|
|
|
|
g_object_set (G_OBJECT (audiotestsrc), "num-buffers", 10000,
|
|
|
|
"samplesperbuffer", 4000, NULL);
|
|
|
|
|
|
|
|
capsfilter1 = gst_element_factory_make ("capsfilter", "capsfilter1");
|
|
|
|
fail_unless (capsfilter1 != NULL);
|
|
|
|
caps =
|
|
|
|
gst_caps_from_string
|
|
|
|
("audio/x-raw-float, channels=1, width=64, rate=16384");
|
|
|
|
g_object_set (G_OBJECT (capsfilter1), "caps", caps, NULL);
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
|
|
|
|
identity = gst_element_factory_make ("identity", "identity");
|
|
|
|
fail_unless (identity != NULL);
|
|
|
|
g_object_set (G_OBJECT (identity), "sync", FALSE, "signal-handoffs", TRUE,
|
|
|
|
NULL);
|
|
|
|
g_signal_connect (identity, "handoff", (GCallback) identity_handoff_cb, &ctx);
|
|
|
|
|
|
|
|
audioresample = gst_element_factory_make ("audioresample", "resample");
|
|
|
|
fail_unless (audioresample != NULL);
|
|
|
|
capsfilter2 = gst_element_factory_make ("capsfilter", "capsfilter2");
|
|
|
|
fail_unless (capsfilter2 != NULL);
|
|
|
|
caps =
|
|
|
|
gst_caps_from_string
|
|
|
|
("audio/x-raw-float, channels=1, width=64, rate=4096");
|
|
|
|
g_object_set (G_OBJECT (capsfilter2), "caps", caps, NULL);
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
|
|
|
|
fakesink = gst_element_factory_make ("fakesink", "sink");
|
|
|
|
fail_unless (fakesink != NULL);
|
|
|
|
g_object_set (G_OBJECT (fakesink), "sync", FALSE, "async", FALSE,
|
|
|
|
"signal-handoffs", TRUE, NULL);
|
|
|
|
g_signal_connect (fakesink, "handoff", (GCallback) fakesink_handoff_cb, &ctx);
|
|
|
|
|
|
|
|
|
|
|
|
gst_bin_add_many (GST_BIN (pipeline), audiotestsrc, capsfilter1, identity,
|
|
|
|
audioresample, capsfilter2, fakesink, NULL);
|
|
|
|
fail_unless (gst_element_link_many (audiotestsrc, capsfilter1, identity,
|
|
|
|
audioresample, capsfilter2, fakesink, NULL));
|
|
|
|
|
|
|
|
loop = g_main_loop_new (NULL, FALSE);
|
|
|
|
|
|
|
|
bus = gst_element_get_bus (pipeline);
|
|
|
|
gst_bus_add_signal_watch (bus);
|
|
|
|
g_signal_connect (bus, "message", (GCallback) _message_cb, loop);
|
|
|
|
|
|
|
|
fail_unless (gst_element_set_state (pipeline,
|
|
|
|
GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS);
|
|
|
|
g_main_loop_run (loop);
|
|
|
|
|
|
|
|
fail_unless (gst_element_set_state (pipeline,
|
|
|
|
GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS);
|
|
|
|
g_main_loop_unref (loop);
|
|
|
|
gst_object_unref (pipeline);
|
|
|
|
|
|
|
|
} GST_END_TEST;
|
|
|
|
|
2011-08-12 11:07:32 +00:00
|
|
|
#define FFT_HELPERS(type,ffttag,ffttag2,scale); \
|
|
|
|
static gdouble magnitude##ffttag (const GstFFT##ffttag##Complex *c) \
|
|
|
|
{ \
|
|
|
|
gdouble mag = (gdouble) c->r * (gdouble) c->r; \
|
|
|
|
mag += (gdouble) c->i * (gdouble) c->i; \
|
|
|
|
mag /= scale * scale; \
|
|
|
|
mag = 10.0 * log10 (mag); \
|
|
|
|
return mag; \
|
|
|
|
} \
|
|
|
|
static gdouble find_main_frequency_spot_##ffttag (const GstFFT##ffttag##Complex *v, \
|
|
|
|
int elements) \
|
|
|
|
{ \
|
|
|
|
int i; \
|
|
|
|
gdouble maxmag = -9999; \
|
|
|
|
int maxidx = 0; \
|
|
|
|
for (i=0; i<elements; ++i) { \
|
|
|
|
gdouble mag = magnitude##ffttag (v+i); \
|
|
|
|
if (mag > maxmag) { \
|
|
|
|
maxmag = mag; \
|
|
|
|
maxidx = i; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
return maxidx / (gdouble) elements; \
|
|
|
|
} \
|
|
|
|
static gboolean is_zero_except_##ffttag (const GstFFT##ffttag##Complex *v, int elements, \
|
|
|
|
gdouble spot) \
|
|
|
|
{ \
|
|
|
|
int i; \
|
|
|
|
for (i=0; i<elements; ++i) { \
|
|
|
|
gdouble pos = i / (gdouble) elements; \
|
|
|
|
gdouble mag = magnitude##ffttag (v+i); \
|
|
|
|
if (fabs (pos - spot) > 0.01) { \
|
|
|
|
if (mag > -55.0) { \
|
|
|
|
return FALSE; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
return TRUE; \
|
|
|
|
} \
|
|
|
|
static void compare_ffts_##ffttag (const GstBuffer *inbuffer, const GstBuffer *outbuffer) \
|
|
|
|
{ \
|
|
|
|
int insamples = GST_BUFFER_SIZE (inbuffer) / sizeof(type) & ~1; \
|
|
|
|
int outsamples = GST_BUFFER_SIZE (outbuffer) / sizeof(type) & ~1; \
|
|
|
|
gdouble inspot, outspot; \
|
|
|
|
\
|
|
|
|
GstFFT##ffttag *inctx = gst_fft_##ffttag2##_new (insamples, FALSE); \
|
|
|
|
GstFFT##ffttag##Complex *in = g_new (GstFFT##ffttag##Complex, insamples / 2 + 1); \
|
|
|
|
GstFFT##ffttag *outctx = gst_fft_##ffttag2##_new (outsamples, FALSE); \
|
|
|
|
GstFFT##ffttag##Complex *out = g_new (GstFFT##ffttag##Complex, outsamples / 2 + 1); \
|
|
|
|
\
|
|
|
|
gst_fft_##ffttag2##_window (inctx, (type*)GST_BUFFER_DATA (inbuffer), \
|
|
|
|
GST_FFT_WINDOW_HAMMING); \
|
|
|
|
gst_fft_##ffttag2##_fft (inctx, (type*)GST_BUFFER_DATA (inbuffer), in); \
|
|
|
|
gst_fft_##ffttag2##_window (outctx, (type*)GST_BUFFER_DATA (outbuffer), \
|
|
|
|
GST_FFT_WINDOW_HAMMING); \
|
|
|
|
gst_fft_##ffttag2##_fft (outctx, (type*)GST_BUFFER_DATA (outbuffer), out); \
|
|
|
|
\
|
|
|
|
inspot = find_main_frequency_spot_##ffttag (in, insamples / 2 + 1); \
|
|
|
|
outspot = find_main_frequency_spot_##ffttag (out, outsamples / 2 + 1); \
|
|
|
|
GST_LOG ("Spots are %.3f and %.3f", inspot, outspot); \
|
|
|
|
fail_unless (fabs (outspot - inspot) < 0.05); \
|
|
|
|
fail_unless (is_zero_except_##ffttag (in, insamples / 2 + 1, inspot)); \
|
|
|
|
fail_unless (is_zero_except_##ffttag (out, outsamples / 2 + 1, outspot)); \
|
|
|
|
\
|
|
|
|
gst_fft_##ffttag2##_free (inctx); \
|
|
|
|
gst_fft_##ffttag2##_free (outctx); \
|
|
|
|
g_free (in); \
|
|
|
|
g_free (out); \
|
|
|
|
}
|
|
|
|
FFT_HELPERS (float, F32, f32, 2048.0f);
|
|
|
|
FFT_HELPERS (double, F64, f64, 2048.0);
|
|
|
|
FFT_HELPERS (gint16, S16, s16, 32767.0);
|
|
|
|
FFT_HELPERS (gint32, S32, s32, 2147483647.0);
|
|
|
|
|
|
|
|
#define FILL_BUFFER(type, desc, value); \
|
|
|
|
static void init_##type##_##desc (GstBuffer *buffer) \
|
|
|
|
{ \
|
|
|
|
type *ptr = (type *) GST_BUFFER_DATA (buffer); \
|
|
|
|
int i, nsamples = GST_BUFFER_SIZE (buffer) / sizeof (type); \
|
|
|
|
for (i = 0; i < nsamples; ++i) { \
|
|
|
|
*ptr++ = value; \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
FILL_BUFFER (float, silence, 0.0f);
|
|
|
|
FILL_BUFFER (double, silence, 0.0);
|
|
|
|
FILL_BUFFER (gint16, silence, 0);
|
|
|
|
FILL_BUFFER (gint32, silence, 0);
|
|
|
|
FILL_BUFFER (float, sine, sinf (i * 0.01f));
|
|
|
|
FILL_BUFFER (float, sine2, sinf (i * 1.8f));
|
|
|
|
FILL_BUFFER (double, sine, sin (i * 0.01));
|
|
|
|
FILL_BUFFER (double, sine2, sin (i * 1.8));
|
|
|
|
FILL_BUFFER (gint16, sine, (gint16) (32767 * sinf (i * 0.01f)));
|
|
|
|
FILL_BUFFER (gint16, sine2, (gint16) (32767 * sinf (i * 1.8f)));
|
|
|
|
FILL_BUFFER (gint32, sine, (gint32) (2147483647 * sinf (i * 0.01f)));
|
|
|
|
FILL_BUFFER (gint32, sine2, (gint32) (2147483647 * sinf (i * 1.8f)));
|
|
|
|
|
|
|
|
static void
|
|
|
|
run_fft_pipeline (int inrate, int outrate, int quality, int width, gboolean fp,
|
|
|
|
void (*init) (GstBuffer *),
|
|
|
|
void (*compare_ffts) (const GstBuffer *, const GstBuffer *))
|
|
|
|
{
|
|
|
|
GstElement *audioresample;
|
|
|
|
GstBuffer *inbuffer, *outbuffer;
|
|
|
|
GstCaps *caps;
|
|
|
|
const int nsamples = 2048;
|
|
|
|
|
|
|
|
audioresample = setup_audioresample (1, inrate, outrate, width, fp);
|
|
|
|
fail_unless (audioresample != NULL);
|
|
|
|
g_object_set (audioresample, "quality", quality, NULL);
|
|
|
|
caps = gst_pad_get_negotiated_caps (mysrcpad);
|
|
|
|
fail_unless (gst_caps_is_fixed (caps));
|
|
|
|
|
|
|
|
fail_unless (gst_element_set_state (audioresample,
|
|
|
|
GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
|
|
|
|
"could not set to playing");
|
|
|
|
|
|
|
|
inbuffer = gst_buffer_new_and_alloc (nsamples * width / 8);
|
|
|
|
GST_BUFFER_DURATION (inbuffer) = GST_FRAMES_TO_CLOCK_TIME (nsamples, inrate);
|
|
|
|
GST_BUFFER_TIMESTAMP (inbuffer) = 0;
|
|
|
|
gst_buffer_set_caps (inbuffer, caps);
|
|
|
|
gst_buffer_ref (inbuffer);
|
|
|
|
|
|
|
|
(*init) (inbuffer);
|
|
|
|
|
|
|
|
/* pushing gives away my reference ... */
|
|
|
|
fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
|
|
|
|
/* ... but it ends up being collected on the global buffer list */
|
|
|
|
fail_unless_equals_int (g_list_length (buffers), 1);
|
|
|
|
/* retrieve out buffer */
|
|
|
|
fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
|
|
|
|
|
|
|
|
fail_unless (gst_element_set_state (audioresample,
|
|
|
|
GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null");
|
|
|
|
|
|
|
|
(*compare_ffts) (inbuffer, outbuffer);
|
|
|
|
|
|
|
|
/* cleanup */
|
|
|
|
gst_buffer_unref (inbuffer);
|
|
|
|
cleanup_audioresample (audioresample);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_START_TEST (test_fft)
|
|
|
|
{
|
|
|
|
int quality;
|
|
|
|
size_t f0, f1;
|
|
|
|
static const int frequencies[] =
|
|
|
|
{ 8000, 16000, 44100, 48000, 128000, 12345, 54321 };
|
|
|
|
|
|
|
|
/* audioresample uses a mixed float/double code path for floats with quality>8, make sure we test it */
|
|
|
|
for (quality = 0; quality <= 10; quality += 5) {
|
|
|
|
for (f0 = 0; f0 < G_N_ELEMENTS (frequencies); ++f0) {
|
|
|
|
for (f1 = 0; f1 < G_N_ELEMENTS (frequencies); ++f1) {
|
|
|
|
run_fft_pipeline (frequencies[f0], frequencies[f0], quality, 32, TRUE,
|
|
|
|
&init_float_silence, &compare_ffts_F32);
|
|
|
|
run_fft_pipeline (frequencies[f0], frequencies[f0], quality, 32, TRUE,
|
|
|
|
&init_float_sine, &compare_ffts_F32);
|
|
|
|
run_fft_pipeline (frequencies[f0], frequencies[f0], quality, 32, TRUE,
|
|
|
|
&init_float_sine2, &compare_ffts_F32);
|
|
|
|
run_fft_pipeline (frequencies[f0], frequencies[f0], quality, 64, TRUE,
|
|
|
|
&init_double_silence, &compare_ffts_F64);
|
|
|
|
run_fft_pipeline (frequencies[f0], frequencies[f0], quality, 64, TRUE,
|
|
|
|
&init_double_sine, &compare_ffts_F64);
|
|
|
|
run_fft_pipeline (frequencies[f0], frequencies[f0], quality, 64, TRUE,
|
|
|
|
&init_double_sine2, &compare_ffts_F64);
|
|
|
|
run_fft_pipeline (frequencies[f0], frequencies[f0], quality, 16, FALSE,
|
|
|
|
&init_gint16_silence, &compare_ffts_S16);
|
|
|
|
run_fft_pipeline (frequencies[f0], frequencies[f0], quality, 16, FALSE,
|
|
|
|
&init_gint16_sine, &compare_ffts_S16);
|
|
|
|
run_fft_pipeline (frequencies[f0], frequencies[f0], quality, 16, FALSE,
|
|
|
|
&init_gint16_sine2, &compare_ffts_S16);
|
|
|
|
run_fft_pipeline (frequencies[f0], frequencies[f0], quality, 32, FALSE,
|
|
|
|
&init_gint32_silence, &compare_ffts_S32);
|
|
|
|
run_fft_pipeline (frequencies[f0], frequencies[f0], quality, 32, FALSE,
|
|
|
|
&init_gint32_sine, &compare_ffts_S32);
|
|
|
|
run_fft_pipeline (frequencies[f0], frequencies[f0], quality, 32, FALSE,
|
|
|
|
&init_gint32_sine2, &compare_ffts_S32);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
2009-01-23 11:31:06 +00:00
|
|
|
static Suite *
|
2005-08-25 15:44:58 +00:00
|
|
|
audioresample_suite (void)
|
|
|
|
{
|
|
|
|
Suite *s = suite_create ("audioresample");
|
|
|
|
TCase *tc_chain = tcase_create ("general");
|
|
|
|
|
|
|
|
suite_add_tcase (s, tc_chain);
|
|
|
|
tcase_add_test (tc_chain, test_perfect_stream);
|
2007-03-14 17:16:30 +00:00
|
|
|
tcase_add_test (tc_chain, test_discont_stream);
|
2006-06-16 15:43:23 +00:00
|
|
|
tcase_add_test (tc_chain, test_reuse);
|
2007-04-21 13:54:39 +00:00
|
|
|
tcase_add_test (tc_chain, test_shutdown);
|
2008-05-08 06:20:42 +00:00
|
|
|
tcase_add_test (tc_chain, test_live_switch);
|
2009-08-21 09:51:47 +00:00
|
|
|
tcase_add_test (tc_chain, test_timestamp_drift);
|
2011-08-12 11:07:32 +00:00
|
|
|
tcase_add_test (tc_chain, test_fft);
|
2005-08-25 15:44:58 +00:00
|
|
|
|
2009-01-23 11:31:06 +00:00
|
|
|
#ifndef GST_DISABLE_PARSE
|
|
|
|
tcase_set_timeout (tc_chain, 360);
|
|
|
|
tcase_add_test (tc_chain, test_pipelines);
|
2009-04-01 14:15:57 +00:00
|
|
|
tcase_add_test (tc_chain, test_preference_passthrough);
|
2009-01-23 11:31:06 +00:00
|
|
|
#endif
|
|
|
|
|
2005-08-25 15:44:58 +00:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2007-04-21 13:54:39 +00:00
|
|
|
GST_CHECK_MAIN (audioresample);
|