tests: port some more to 1.0

This commit is contained in:
Mark Nauwelaerts 2012-04-10 17:24:05 +02:00
parent 06ac28eb81
commit a1dc042bd8
4 changed files with 71 additions and 85 deletions

View file

@ -233,7 +233,7 @@ GST_START_TEST (test_audio_pad)
"could not set to playing");
/* corresponds to I420 buffer for the size mentioned in the caps */
inbuffer = gst_buffer_new ();
inbuffer = gst_buffer_new_and_alloc (sizeof (mp2_data));
gst_buffer_fill (inbuffer, 0, mp2_data, sizeof (mp2_data));
caps = gst_caps_from_string (AUDIO_CAPS_STRING);
gst_pad_set_caps (mysrcpad, caps);

View file

@ -24,6 +24,18 @@
#include <gst/check/gstcheck.h>
#if G_BYTE_ORDER == G_BIG_ENDIAN
#define AFORMAT "S16BE"
#else
#define AFORMAT "S16LE"
#endif
#define AUDIO_CAPS_STRING "audio/x-raw, " \
"format = (string) " AFORMAT ", "\
"layout = (string) interleaved, " \
"rate = (int) 48000, " \
"channels = (int) 1 "
static const guint8 opus_ogg_id_header[19] = {
0x4f, 0x70, 0x75, 0x73, 0x48, 0x65, 0x61, 0x64, 0x00, 0x02, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00
@ -60,8 +72,8 @@ setup_opusdec (void)
GST_DEBUG ("setup_opusdec");
opusdec = gst_check_setup_element ("opusdec");
mydecsrcpad = gst_check_setup_src_pad (opusdec, &srctemplate, NULL);
mydecsinkpad = gst_check_setup_sink_pad (opusdec, &sinktemplate, NULL);
mydecsrcpad = gst_check_setup_src_pad (opusdec, &srctemplate);
mydecsinkpad = gst_check_setup_sink_pad (opusdec, &sinktemplate);
gst_pad_set_active (mydecsrcpad, TRUE);
gst_pad_set_active (mydecsinkpad, TRUE);
@ -88,8 +100,8 @@ setup_opusenc (void)
GST_DEBUG ("setup_opusenc");
opusenc = gst_check_setup_element ("opusenc");
myencsrcpad = gst_check_setup_src_pad (opusenc, &srctemplate, NULL);
myencsinkpad = gst_check_setup_sink_pad (opusenc, &sinktemplate, NULL);
myencsrcpad = gst_check_setup_src_pad (opusenc, &srctemplate);
myencsinkpad = gst_check_setup_sink_pad (opusenc, &sinktemplate);
gst_pad_set_active (myencsrcpad, TRUE);
gst_pad_set_active (myencsinkpad, TRUE);
@ -121,7 +133,7 @@ check_buffers (guint expected)
for (i = 0; i < num_buffers; ++i) {
outbuffer = GST_BUFFER (buffers->data);
fail_if (outbuffer == NULL);
fail_if (GST_BUFFER_SIZE (outbuffer) == 0);
fail_if (gst_buffer_get_size (outbuffer) == 0);
buffers = g_list_remove (buffers, outbuffer);
@ -142,7 +154,7 @@ GST_START_TEST (test_opus_id_header)
"could not set to playing");
inbuffer = gst_buffer_new_and_alloc (sizeof (opus_ogg_id_header));
memcpy (GST_BUFFER_DATA (inbuffer), opus_ogg_id_header,
gst_buffer_fill (inbuffer, 0, opus_ogg_id_header,
sizeof (opus_ogg_id_header));
ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
gst_buffer_ref (inbuffer);
@ -208,8 +220,6 @@ GST_START_TEST (test_opus_encode_samples)
GstElement *opusenc;
GstBuffer *inbuffer;
GstCaps *caps;
guint16 *samples;
unsigned int n;
opusenc = setup_opusenc ();
@ -218,19 +228,15 @@ GST_START_TEST (test_opus_encode_samples)
"could not set to playing");
inbuffer = gst_buffer_new_and_alloc (nsamples * 2);
samples = (guint16 *) GST_BUFFER_DATA (inbuffer);
for (n = 0; n < nsamples; ++n) {
samples[n] = 0;
}
gst_buffer_memset (inbuffer, 0, 0, nsamples * 2);
GST_BUFFER_TIMESTAMP (inbuffer) = GST_BUFFER_OFFSET (inbuffer) = 0;
GST_BUFFER_DURATION (inbuffer) = GST_CLOCK_TIME_NONE;
ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
caps =
gst_caps_from_string ("audio/x-raw,format=S16LE,rate=48000,channels=1");
caps = gst_caps_from_string (AUDIO_CAPS_STRING);
fail_unless (caps != NULL);
gst_buffer_set_caps (inbuffer, caps);
gst_pad_set_caps (myencsrcpad, caps);
gst_caps_unref (caps);
gst_buffer_ref (inbuffer);
@ -264,8 +270,7 @@ GST_START_TEST (test_opus_encode_properties)
GstElement *opusenc;
GstBuffer *inbuffer;
GstCaps *caps;
guint16 *samples;
unsigned int n, step;
unsigned int step;
static const struct
{
const char *param;
@ -299,22 +304,19 @@ GST_START_TEST (test_opus_encode_properties)
GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
"could not set to playing");
caps =
gst_caps_from_string ("audio/x-raw,format=S16LE,rate=48000,channels=1");
caps = gst_caps_from_string (AUDIO_CAPS_STRING);
fail_unless (caps != NULL);
gst_pad_set_caps (myencsrcpad, caps);
for (step = 0; step < steps; ++step) {
inbuffer = gst_buffer_new_and_alloc (nsamples * 2);
samples = (guint16 *) GST_BUFFER_DATA (inbuffer);
for (n = 0; n < nsamples; ++n) {
samples[n] = 0;
}
gst_buffer_memset (inbuffer, 0, 0, nsamples * 2);
GST_BUFFER_TIMESTAMP (inbuffer) = GST_BUFFER_OFFSET (inbuffer) = 0;
GST_BUFFER_DURATION (inbuffer) = GST_CLOCK_TIME_NONE;
ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
gst_buffer_set_caps (inbuffer, caps);
gst_buffer_ref (inbuffer);
/* pushing gives away my reference ... */

View file

@ -23,20 +23,19 @@
#include <unistd.h>
#include <gst/check/gstcheck.h>
#include <gst/audio/multichannel.h>
#include <gst/audio/audio.h>
/* 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 */
static GstPad *mysrcpad, *mysinkpad;
#define AUDIO_CAPS_STRING "audio/x-raw-int, " \
#define AUDIO_CAPS_STRING "audio/x-raw, " \
"format = (string) " GST_AUDIO_NE (S16) ", "\
"layout = (string) interleaved, " \
"rate = (int) 48000, " \
"channels = (int) 2, " \
"width = (int) 16, " \
"depth = (int) 16, " \
"signed = (boolean) true, " \
"endianness = (int) BYTE_ORDER "
"channel-mask = (bitmask) 3"
#define AAC_RAW_CAPS_STRING "audio/mpeg, " \
"mpegversion = (int) 4, " \
@ -75,12 +74,12 @@ setup_voaacenc (gboolean adts)
GST_DEBUG ("setup_voaacenc");
voaacenc = gst_check_setup_element ("voaacenc");
mysrcpad = gst_check_setup_src_pad (voaacenc, &srctemplate, NULL);
mysrcpad = gst_check_setup_src_pad (voaacenc, &srctemplate);
if (adts)
mysinkpad = gst_check_setup_sink_pad (voaacenc, &sinktemplate_adts, NULL);
mysinkpad = gst_check_setup_sink_pad (voaacenc, &sinktemplate_adts);
else
mysinkpad = gst_check_setup_sink_pad (voaacenc, &sinktemplate_raw, NULL);
mysinkpad = gst_check_setup_sink_pad (voaacenc, &sinktemplate_raw);
gst_pad_set_active (mysrcpad, TRUE);
gst_pad_set_active (mysinkpad, TRUE);
@ -101,28 +100,6 @@ cleanup_voaacenc (GstElement * voaacenc)
gst_check_teardown_element (voaacenc);
}
static void
set_channel_positions (GstCaps * caps, int channels,
GstAudioChannelPosition * channelpositions)
{
GValue chanpos = { 0 };
GValue pos = { 0 };
GstStructure *structure = gst_caps_get_structure (caps, 0);
int c;
g_value_init (&chanpos, GST_TYPE_ARRAY);
g_value_init (&pos, GST_TYPE_AUDIO_CHANNEL_POSITION);
for (c = 0; c < channels; c++) {
g_value_set_enum (&pos, channelpositions[c]);
gst_value_array_append_value (&chanpos, &pos);
}
g_value_unset (&pos);
gst_structure_set_value (structure, "channel-positions", &chanpos);
g_value_unset (&chanpos);
}
static void
do_test (gboolean adts)
{
@ -131,10 +108,6 @@ do_test (gboolean adts)
GstCaps *caps;
gint i, num_buffers;
const gint nbuffers = 10;
GstAudioChannelPosition channel_position_layout[2] =
{ GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT
};
voaacenc = setup_voaacenc (adts);
fail_unless (gst_element_set_state (voaacenc,
@ -144,12 +117,10 @@ do_test (gboolean adts)
/* corresponds to audio buffer mentioned in the caps */
inbuffer = gst_buffer_new_and_alloc (1024 * nbuffers * 2 * 2);
/* makes valgrind's memcheck happier */
memset (GST_BUFFER_DATA (inbuffer), 0, GST_BUFFER_SIZE (inbuffer));
gst_buffer_memset (inbuffer, 0, 0, 1024 * nbuffers * 2 * 2);
caps = gst_caps_from_string (AUDIO_CAPS_STRING);
set_channel_positions (caps, 2, channel_position_layout);
gst_buffer_set_caps (inbuffer, caps);
gst_pad_set_caps (mysrcpad, caps);
gst_caps_unref (caps);
GST_BUFFER_TIMESTAMP (inbuffer) = 0;
ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
@ -163,14 +134,17 @@ do_test (gboolean adts)
/* clean up buffers */
for (i = 0; i < num_buffers; ++i) {
gint size, header = 0, id;
gint header = 0, id;
GstMapInfo map;
gsize size;
guint8 *data;
outbuffer = GST_BUFFER (buffers->data);
fail_if (outbuffer == NULL);
data = GST_BUFFER_DATA (outbuffer);
size = GST_BUFFER_SIZE (outbuffer);
gst_buffer_map (outbuffer, &map, GST_MAP_READ);
data = map.data;
size = map.size;
if (adts) {
gboolean protection;
@ -206,8 +180,9 @@ do_test (gboolean adts)
const GValue *value;
GstBuffer *buf;
gint k;
GstMapInfo cmap;
caps = gst_buffer_get_caps (outbuffer);
caps = gst_pad_get_current_caps (mysinkpad);
fail_if (caps == NULL);
s = gst_caps_get_structure (caps, 0);
fail_if (s == NULL);
@ -215,10 +190,10 @@ do_test (gboolean adts)
fail_if (value == NULL);
buf = gst_value_get_buffer (value);
fail_if (buf == NULL);
data = GST_BUFFER_DATA (buf);
size = GST_BUFFER_SIZE (buf);
fail_if (size < 2);
k = GST_READ_UINT16_BE (data);
gst_buffer_map (buf, &cmap, GST_MAP_READ);
fail_if (cmap.size < 2);
k = GST_READ_UINT16_BE (cmap.data);
gst_buffer_unmap (buf, &cmap);
/* profile, rate, channels */
fail_unless ((k & 0xFFF8) == ((0x02 << 11) | (0x3 << 7) | (0x02 << 3)));
gst_caps_unref (caps);
@ -229,6 +204,7 @@ do_test (gboolean adts)
id = data[header] & (0x7 << 5);
/* allow all but ID_END or ID_LFE */
fail_if (id == 7 || id == 3);
gst_buffer_unmap (outbuffer, &map);
buffers = g_list_remove (buffers, outbuffer);

View file

@ -29,13 +29,18 @@
* get_peer, and then remove references in every test function */
static GstPad *mysrcpad, *mysinkpad;
#define AUDIO_CAPS_STRING "audio/x-raw-int, " \
#if G_BYTE_ORDER == G_BIG_ENDIAN
#define AFORMAT "S16BE"
#else
#define AFORMAT "S16LE"
#endif
#define AUDIO_CAPS_STRING "audio/x-raw, " \
"format = (string) " AFORMAT ", "\
"layout = (string) interleaved, " \
"rate = (int) 16000, " \
"channels = (int) 1, " \
"width = (int) 16, " \
"depth = (int) 16, " \
"signed = (boolean) true, " \
"endianness = (int) BYTE_ORDER "
"channels = (int) 1 "
#define AMRWB_CAPS_STRING "audio/AMR-WB"
@ -61,8 +66,8 @@ setup_voamrwbenc (void)
voamrwbenc = gst_check_setup_element ("voamrwbenc");
/* ensure mode as expected */
g_object_set (voamrwbenc, "band-mode", 0, NULL);
mysrcpad = gst_check_setup_src_pad (voamrwbenc, &srctemplate, NULL);
mysinkpad = gst_check_setup_sink_pad (voamrwbenc, &sinktemplate, NULL);
mysrcpad = gst_check_setup_src_pad (voamrwbenc, &srctemplate);
mysinkpad = gst_check_setup_sink_pad (voamrwbenc, &sinktemplate);
gst_pad_set_active (mysrcpad, TRUE);
gst_pad_set_active (mysinkpad, TRUE);
@ -99,10 +104,10 @@ do_test (void)
/* corresponds to audio buffer mentioned in the caps */
inbuffer = gst_buffer_new_and_alloc (320 * nbuffers * 2);
/* makes valgrind's memcheck happier */
memset (GST_BUFFER_DATA (inbuffer), 0, GST_BUFFER_SIZE (inbuffer));
gst_buffer_memset (inbuffer, 0, 0, 1024 * nbuffers * 2 * 2);
caps = gst_caps_from_string (AUDIO_CAPS_STRING);
gst_buffer_set_caps (inbuffer, caps);
gst_pad_set_caps (mysrcpad, caps);
gst_caps_unref (caps);
GST_BUFFER_TIMESTAMP (inbuffer) = 0;
ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
@ -116,15 +121,17 @@ do_test (void)
/* clean up buffers */
for (i = 0; i < num_buffers; ++i) {
gint size;
GstMapInfo map;
gsize size;
guint8 *data;
GstClockTime time, dur;
outbuffer = GST_BUFFER (buffers->data);
fail_if (outbuffer == NULL);
data = GST_BUFFER_DATA (outbuffer);
size = GST_BUFFER_SIZE (outbuffer);
gst_buffer_map (outbuffer, &map, GST_MAP_READ);
data = map.data;
size = map.size;
/* at least for mode 0 */
fail_unless (size == 18);
@ -135,6 +142,7 @@ do_test (void)
dur = GST_BUFFER_DURATION (outbuffer);
fail_unless (time == 20 * GST_MSECOND * i);
fail_unless (dur == 20 * GST_MSECOND);
gst_buffer_unmap (outbuffer, &map);
buffers = g_list_remove (buffers, outbuffer);