mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-24 02:31:03 +00:00
tests: fix audioresample test
This commit is contained in:
parent
8c894ce8b4
commit
48b190c7be
1 changed files with 57 additions and 70 deletions
|
@ -39,43 +39,32 @@
|
||||||
static GstPad *mysrcpad, *mysinkpad;
|
static GstPad *mysrcpad, *mysinkpad;
|
||||||
|
|
||||||
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
||||||
#define FORMATS_F "{ F32LE, F64LE }"
|
#define FORMATS "{ F32LE, F64LE, S16LE, S32LE }"
|
||||||
#define FORMATS_I "{ S16LE, S32LE }"
|
|
||||||
#else
|
#else
|
||||||
#define FORMATS_F "{ F32BE, F64BE }"
|
#define FORMATS "{ F32BE, F64BE, S16BE, S32BE }"
|
||||||
#define FORMATS_I "{ S16BE, S32BE }"
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define RESAMPLE_CAPS_FLOAT \
|
#define RESAMPLE_CAPS \
|
||||||
"audio/x-raw, " \
|
"audio/x-raw, " \
|
||||||
"formats = (string) "FORMATS_F", " \
|
"format = (string) "FORMATS", " \
|
||||||
"channels = (int) [ 1, MAX ], " \
|
"channels = (int) [ 1, MAX ], " \
|
||||||
"rate = (int) [ 1, MAX ]"
|
"rate = (int) [ 1, MAX ], " \
|
||||||
|
"layout = (string) interleaved"
|
||||||
#define RESAMPLE_CAPS_INT \
|
|
||||||
"audio/x-raw, " \
|
|
||||||
"formats = (string) "FORMATS_I", " \
|
|
||||||
"channels = (int) [ 1, MAX ], " \
|
|
||||||
"rate = (int) [ 1, MAX ]"
|
|
||||||
|
|
||||||
#define RESAMPLE_CAPS_TEMPLATE_STRING \
|
|
||||||
RESAMPLE_CAPS_FLOAT " ; " \
|
|
||||||
RESAMPLE_CAPS_INT
|
|
||||||
|
|
||||||
static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
|
static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
|
||||||
GST_PAD_SINK,
|
GST_PAD_SINK,
|
||||||
GST_PAD_ALWAYS,
|
GST_PAD_ALWAYS,
|
||||||
GST_STATIC_CAPS (RESAMPLE_CAPS_TEMPLATE_STRING)
|
GST_STATIC_CAPS (RESAMPLE_CAPS)
|
||||||
);
|
);
|
||||||
static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
|
static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
|
||||||
GST_PAD_SRC,
|
GST_PAD_SRC,
|
||||||
GST_PAD_ALWAYS,
|
GST_PAD_ALWAYS,
|
||||||
GST_STATIC_CAPS (RESAMPLE_CAPS_TEMPLATE_STRING)
|
GST_STATIC_CAPS (RESAMPLE_CAPS)
|
||||||
);
|
);
|
||||||
|
|
||||||
static GstElement *
|
static GstElement *
|
||||||
setup_audioresample (int channels, int inrate, int outrate, int width,
|
setup_audioresample (int channels, guint64 mask, int inrate, int outrate,
|
||||||
gboolean fp)
|
const gchar * format)
|
||||||
{
|
{
|
||||||
GstElement *audioresample;
|
GstElement *audioresample;
|
||||||
GstCaps *caps;
|
GstCaps *caps;
|
||||||
|
@ -84,15 +73,11 @@ setup_audioresample (int channels, int inrate, int outrate, int width,
|
||||||
GST_DEBUG ("setup_audioresample");
|
GST_DEBUG ("setup_audioresample");
|
||||||
audioresample = gst_check_setup_element ("audioresample");
|
audioresample = gst_check_setup_element ("audioresample");
|
||||||
|
|
||||||
if (fp)
|
caps = gst_caps_from_string (RESAMPLE_CAPS);
|
||||||
caps = gst_caps_from_string (RESAMPLE_CAPS_FLOAT);
|
|
||||||
else
|
|
||||||
caps = gst_caps_from_string (RESAMPLE_CAPS_INT);
|
|
||||||
structure = gst_caps_get_structure (caps, 0);
|
structure = gst_caps_get_structure (caps, 0);
|
||||||
gst_structure_set (structure, "channels", G_TYPE_INT, channels,
|
gst_structure_set (structure, "channels", G_TYPE_INT, channels,
|
||||||
"rate", G_TYPE_INT, inrate, "width", G_TYPE_INT, width, NULL);
|
"rate", G_TYPE_INT, inrate, "format", G_TYPE_STRING, format,
|
||||||
if (!fp)
|
"channel-mask", GST_TYPE_BITMASK, mask, NULL);
|
||||||
gst_structure_set (structure, "depth", G_TYPE_INT, width, NULL);
|
|
||||||
fail_unless (gst_caps_is_fixed (caps));
|
fail_unless (gst_caps_is_fixed (caps));
|
||||||
|
|
||||||
fail_unless (gst_element_set_state (audioresample,
|
fail_unless (gst_element_set_state (audioresample,
|
||||||
|
@ -100,28 +85,23 @@ setup_audioresample (int channels, int inrate, int outrate, int width,
|
||||||
"could not set to paused");
|
"could not set to paused");
|
||||||
|
|
||||||
mysrcpad = gst_check_setup_src_pad (audioresample, &srctemplate);
|
mysrcpad = gst_check_setup_src_pad (audioresample, &srctemplate);
|
||||||
|
gst_pad_set_active (mysrcpad, TRUE);
|
||||||
gst_pad_set_caps (mysrcpad, caps);
|
gst_pad_set_caps (mysrcpad, caps);
|
||||||
gst_caps_unref (caps);
|
gst_caps_unref (caps);
|
||||||
|
|
||||||
if (fp)
|
caps = gst_caps_from_string (RESAMPLE_CAPS);
|
||||||
caps = gst_caps_from_string (RESAMPLE_CAPS_FLOAT);
|
|
||||||
else
|
|
||||||
caps = gst_caps_from_string (RESAMPLE_CAPS_INT);
|
|
||||||
structure = gst_caps_get_structure (caps, 0);
|
structure = gst_caps_get_structure (caps, 0);
|
||||||
gst_structure_set (structure, "channels", G_TYPE_INT, channels,
|
gst_structure_set (structure, "channels", G_TYPE_INT, channels,
|
||||||
"rate", G_TYPE_INT, outrate, "width", G_TYPE_INT, width, NULL);
|
"rate", G_TYPE_INT, outrate, "format", G_TYPE_STRING, format, NULL);
|
||||||
if (!fp)
|
|
||||||
gst_structure_set (structure, "depth", G_TYPE_INT, width, NULL);
|
|
||||||
fail_unless (gst_caps_is_fixed (caps));
|
fail_unless (gst_caps_is_fixed (caps));
|
||||||
|
|
||||||
mysinkpad = gst_check_setup_sink_pad (audioresample, &sinktemplate);
|
mysinkpad = gst_check_setup_sink_pad (audioresample, &sinktemplate);
|
||||||
|
gst_pad_set_active (mysinkpad, TRUE);
|
||||||
/* this installs a getcaps func that will always return the caps we set
|
/* this installs a getcaps func that will always return the caps we set
|
||||||
* later */
|
* later */
|
||||||
gst_pad_set_caps (mysinkpad, caps);
|
gst_pad_set_caps (mysinkpad, caps);
|
||||||
gst_pad_use_fixed_caps (mysinkpad);
|
gst_pad_use_fixed_caps (mysinkpad);
|
||||||
|
|
||||||
gst_pad_set_active (mysinkpad, TRUE);
|
|
||||||
gst_pad_set_active (mysrcpad, TRUE);
|
|
||||||
|
|
||||||
gst_caps_unref (caps);
|
gst_caps_unref (caps);
|
||||||
|
|
||||||
|
@ -189,7 +169,8 @@ test_perfect_stream_instance (int inrate, int outrate, int samples,
|
||||||
GstMapInfo map;
|
GstMapInfo map;
|
||||||
gint16 *p;
|
gint16 *p;
|
||||||
|
|
||||||
audioresample = setup_audioresample (2, inrate, outrate, 16, FALSE);
|
audioresample =
|
||||||
|
setup_audioresample (2, 0x3, inrate, outrate, GST_AUDIO_NE (S16));
|
||||||
caps = gst_pad_get_current_caps (mysrcpad);
|
caps = gst_pad_get_current_caps (mysrcpad);
|
||||||
fail_unless (gst_caps_is_fixed (caps));
|
fail_unless (gst_caps_is_fixed (caps));
|
||||||
|
|
||||||
|
@ -277,7 +258,8 @@ test_discont_stream_instance (int inrate, int outrate, int samples,
|
||||||
GST_DEBUG ("inrate:%d outrate:%d samples:%d numbuffers:%d",
|
GST_DEBUG ("inrate:%d outrate:%d samples:%d numbuffers:%d",
|
||||||
inrate, outrate, samples, numbuffers);
|
inrate, outrate, samples, numbuffers);
|
||||||
|
|
||||||
audioresample = setup_audioresample (2, inrate, outrate, 16, FALSE);
|
audioresample =
|
||||||
|
setup_audioresample (2, 3, inrate, outrate, GST_AUDIO_NE (S16));
|
||||||
caps = gst_pad_get_current_caps (mysrcpad);
|
caps = gst_pad_get_current_caps (mysrcpad);
|
||||||
fail_unless (gst_caps_is_fixed (caps));
|
fail_unless (gst_caps_is_fixed (caps));
|
||||||
|
|
||||||
|
@ -363,7 +345,7 @@ GST_START_TEST (test_reuse)
|
||||||
GstCaps *caps;
|
GstCaps *caps;
|
||||||
GstSegment segment;
|
GstSegment segment;
|
||||||
|
|
||||||
audioresample = setup_audioresample (1, 9343, 48000, 16, FALSE);
|
audioresample = setup_audioresample (1, 0, 9343, 48000, GST_AUDIO_NE (S16));
|
||||||
caps = gst_pad_get_current_caps (mysrcpad);
|
caps = gst_pad_get_current_caps (mysrcpad);
|
||||||
fail_unless (gst_caps_is_fixed (caps));
|
fail_unless (gst_caps_is_fixed (caps));
|
||||||
|
|
||||||
|
@ -551,7 +533,8 @@ GST_START_TEST (test_live_switch)
|
||||||
GstCaps *caps;
|
GstCaps *caps;
|
||||||
GstSegment segment;
|
GstSegment segment;
|
||||||
|
|
||||||
audioresample = setup_audioresample (4, 48000, 48000, 16, FALSE);
|
audioresample =
|
||||||
|
setup_audioresample (4, 0xf, 48000, 48000, GST_AUDIO_NE (S16));
|
||||||
|
|
||||||
/* Let the sinkpad act like something that can only handle things of
|
/* 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
|
* rate 48000- and can only allocate buffers for that rate, but if someone
|
||||||
|
@ -1000,6 +983,7 @@ FFT_HELPERS (gint32, S32, s32, 2147483647.0);
|
||||||
for (i = 0; i < nsamples; ++i) { \
|
for (i = 0; i < nsamples; ++i) { \
|
||||||
*ptr++ = value; \
|
*ptr++ = value; \
|
||||||
} \
|
} \
|
||||||
|
gst_buffer_unmap (buffer, &map); \
|
||||||
}
|
}
|
||||||
|
|
||||||
FILL_BUFFER (float, silence, 0.0f);
|
FILL_BUFFER (float, silence, 0.0f);
|
||||||
|
@ -1016,15 +1000,16 @@ FILL_BUFFER (gint32, sine, (gint32) (2147483647 * sinf (i * 0.01f)));
|
||||||
FILL_BUFFER (gint32, sine2, (gint32) (2147483647 * sinf (i * 1.8f)));
|
FILL_BUFFER (gint32, sine2, (gint32) (2147483647 * sinf (i * 1.8f)));
|
||||||
|
|
||||||
static void
|
static void
|
||||||
run_fft_pipeline (int inrate, int outrate, int quality, int width, gboolean fp,
|
run_fft_pipeline (int inrate, int outrate, int quality, int width,
|
||||||
void (*init) (GstBuffer *), void (*compare_ffts) (GstBuffer *, GstBuffer *))
|
const gchar * format, void (*init) (GstBuffer *),
|
||||||
|
void (*compare_ffts) (GstBuffer *, GstBuffer *))
|
||||||
{
|
{
|
||||||
GstElement *audioresample;
|
GstElement *audioresample;
|
||||||
GstBuffer *inbuffer, *outbuffer;
|
GstBuffer *inbuffer, *outbuffer;
|
||||||
GstCaps *caps;
|
GstCaps *caps;
|
||||||
const int nsamples = 2048;
|
const int nsamples = 2048;
|
||||||
|
|
||||||
audioresample = setup_audioresample (1, inrate, outrate, width, fp);
|
audioresample = setup_audioresample (1, 0, inrate, outrate, format);
|
||||||
fail_unless (audioresample != NULL);
|
fail_unless (audioresample != NULL);
|
||||||
g_object_set (audioresample, "quality", quality, NULL);
|
g_object_set (audioresample, "quality", quality, NULL);
|
||||||
caps = gst_pad_get_current_caps (mysrcpad);
|
caps = gst_pad_get_current_caps (mysrcpad);
|
||||||
|
@ -1038,10 +1023,10 @@ run_fft_pipeline (int inrate, int outrate, int quality, int width, gboolean fp,
|
||||||
GST_BUFFER_DURATION (inbuffer) = GST_FRAMES_TO_CLOCK_TIME (nsamples, inrate);
|
GST_BUFFER_DURATION (inbuffer) = GST_FRAMES_TO_CLOCK_TIME (nsamples, inrate);
|
||||||
GST_BUFFER_TIMESTAMP (inbuffer) = 0;
|
GST_BUFFER_TIMESTAMP (inbuffer) = 0;
|
||||||
gst_pad_set_caps (mysrcpad, caps);
|
gst_pad_set_caps (mysrcpad, caps);
|
||||||
gst_buffer_ref (inbuffer);
|
|
||||||
|
|
||||||
(*init) (inbuffer);
|
(*init) (inbuffer);
|
||||||
|
|
||||||
|
gst_buffer_ref (inbuffer);
|
||||||
/* pushing gives away my reference ... */
|
/* pushing gives away my reference ... */
|
||||||
fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
|
fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
|
||||||
/* ... but it ends up being collected on the global buffer list */
|
/* ... but it ends up being collected on the global buffer list */
|
||||||
|
@ -1052,10 +1037,12 @@ run_fft_pipeline (int inrate, int outrate, int quality, int width, gboolean fp,
|
||||||
fail_unless (gst_element_set_state (audioresample,
|
fail_unless (gst_element_set_state (audioresample,
|
||||||
GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null");
|
GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null");
|
||||||
|
|
||||||
|
if (inbuffer == outbuffer)
|
||||||
|
gst_buffer_unref (inbuffer);
|
||||||
|
|
||||||
(*compare_ffts) (inbuffer, outbuffer);
|
(*compare_ffts) (inbuffer, outbuffer);
|
||||||
|
|
||||||
/* cleanup */
|
/* cleanup */
|
||||||
gst_buffer_unref (inbuffer);
|
|
||||||
gst_caps_unref (caps);
|
gst_caps_unref (caps);
|
||||||
cleanup_audioresample (audioresample);
|
cleanup_audioresample (audioresample);
|
||||||
}
|
}
|
||||||
|
@ -1071,30 +1058,30 @@ GST_START_TEST (test_fft)
|
||||||
for (quality = 0; quality <= 10; quality += 5) {
|
for (quality = 0; quality <= 10; quality += 5) {
|
||||||
for (f0 = 0; f0 < G_N_ELEMENTS (frequencies); ++f0) {
|
for (f0 = 0; f0 < G_N_ELEMENTS (frequencies); ++f0) {
|
||||||
for (f1 = 0; f1 < G_N_ELEMENTS (frequencies); ++f1) {
|
for (f1 = 0; f1 < G_N_ELEMENTS (frequencies); ++f1) {
|
||||||
run_fft_pipeline (frequencies[f0], frequencies[f0], quality, 32, TRUE,
|
run_fft_pipeline (frequencies[f0], frequencies[f0], quality, 32,
|
||||||
&init_float_silence, &compare_ffts_F32);
|
GST_AUDIO_NE (F32), &init_float_silence, &compare_ffts_F32);
|
||||||
run_fft_pipeline (frequencies[f0], frequencies[f0], quality, 32, TRUE,
|
run_fft_pipeline (frequencies[f0], frequencies[f0], quality, 32,
|
||||||
&init_float_sine, &compare_ffts_F32);
|
GST_AUDIO_NE (F32), &init_float_sine, &compare_ffts_F32);
|
||||||
run_fft_pipeline (frequencies[f0], frequencies[f0], quality, 32, TRUE,
|
run_fft_pipeline (frequencies[f0], frequencies[f0], quality, 32,
|
||||||
&init_float_sine2, &compare_ffts_F32);
|
GST_AUDIO_NE (F32), &init_float_sine2, &compare_ffts_F32);
|
||||||
run_fft_pipeline (frequencies[f0], frequencies[f0], quality, 64, TRUE,
|
run_fft_pipeline (frequencies[f0], frequencies[f0], quality, 64,
|
||||||
&init_double_silence, &compare_ffts_F64);
|
GST_AUDIO_NE (F64), &init_double_silence, &compare_ffts_F64);
|
||||||
run_fft_pipeline (frequencies[f0], frequencies[f0], quality, 64, TRUE,
|
run_fft_pipeline (frequencies[f0], frequencies[f0], quality, 64,
|
||||||
&init_double_sine, &compare_ffts_F64);
|
GST_AUDIO_NE (F64), &init_double_sine, &compare_ffts_F64);
|
||||||
run_fft_pipeline (frequencies[f0], frequencies[f0], quality, 64, TRUE,
|
run_fft_pipeline (frequencies[f0], frequencies[f0], quality, 64,
|
||||||
&init_double_sine2, &compare_ffts_F64);
|
GST_AUDIO_NE (F64), &init_double_sine2, &compare_ffts_F64);
|
||||||
run_fft_pipeline (frequencies[f0], frequencies[f0], quality, 16, FALSE,
|
run_fft_pipeline (frequencies[f0], frequencies[f0], quality, 16,
|
||||||
&init_gint16_silence, &compare_ffts_S16);
|
GST_AUDIO_NE (S16), &init_gint16_silence, &compare_ffts_S16);
|
||||||
run_fft_pipeline (frequencies[f0], frequencies[f0], quality, 16, FALSE,
|
run_fft_pipeline (frequencies[f0], frequencies[f0], quality, 16,
|
||||||
&init_gint16_sine, &compare_ffts_S16);
|
GST_AUDIO_NE (S16), &init_gint16_sine, &compare_ffts_S16);
|
||||||
run_fft_pipeline (frequencies[f0], frequencies[f0], quality, 16, FALSE,
|
run_fft_pipeline (frequencies[f0], frequencies[f0], quality, 16,
|
||||||
&init_gint16_sine2, &compare_ffts_S16);
|
GST_AUDIO_NE (S16), &init_gint16_sine2, &compare_ffts_S16);
|
||||||
run_fft_pipeline (frequencies[f0], frequencies[f0], quality, 32, FALSE,
|
run_fft_pipeline (frequencies[f0], frequencies[f0], quality, 32,
|
||||||
&init_gint32_silence, &compare_ffts_S32);
|
GST_AUDIO_NE (S32), &init_gint32_silence, &compare_ffts_S32);
|
||||||
run_fft_pipeline (frequencies[f0], frequencies[f0], quality, 32, FALSE,
|
run_fft_pipeline (frequencies[f0], frequencies[f0], quality, 32,
|
||||||
&init_gint32_sine, &compare_ffts_S32);
|
GST_AUDIO_NE (S32), &init_gint32_sine, &compare_ffts_S32);
|
||||||
run_fft_pipeline (frequencies[f0], frequencies[f0], quality, 32, FALSE,
|
run_fft_pipeline (frequencies[f0], frequencies[f0], quality, 32,
|
||||||
&init_gint32_sine2, &compare_ffts_S32);
|
GST_AUDIO_NE (S32), &init_gint32_sine2, &compare_ffts_S32);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue