diff --git a/tests/old/testsuite/alsa/Makefile.am b/tests/old/testsuite/alsa/Makefile.am index e00f26b002..6e3b78723b 100644 --- a/tests/old/testsuite/alsa/Makefile.am +++ b/tests/old/testsuite/alsa/Makefile.am @@ -1,11 +1,14 @@ -testprogs = formats +testprogs = formats state TESTS = $(testprogs) check_PROGRAMS = $(testprogs) formats_SOURCES = formats.c sinesrc.c sinesrc.h +state_SOURCES = state.c sinesrc.c sinesrc.h # we have nothing but apps here, we can do this safely LIBS = $(GST_LIBS) AM_CFLAGS = $(GST_CFLAGS) + +noinst_HEADERS = sinesrc.h diff --git a/tests/old/testsuite/alsa/formats.c b/tests/old/testsuite/alsa/formats.c index 845887c1c0..93ed4e295d 100644 --- a/tests/old/testsuite/alsa/formats.c +++ b/tests/old/testsuite/alsa/formats.c @@ -1,6 +1,8 @@ /* * Copyright (C) 2003 Benjamin Otte * + * formats.c: Tests the different formats on alsasink + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public * License as published by the Free Software Foundation; either @@ -25,7 +27,7 @@ gint endianness = G_LITTLE_ENDIAN; gint depth = 8; gint width = 8; -#define NUMBER_OF_INT_TESTS 16 +#define NUMBER_OF_INT_TESTS 28 #define NUMBER_OF_FLOAT_TESTS 2 #define NUMBER_OF_LAW_TESTS 2 @@ -164,7 +166,7 @@ main (gint argc, gchar *argv[]) g_print ("\n" "This test will test the various formats ALSA and GStreamer support.\n" "You will hear a short sine tone on your default ALSA soundcard for every\n" - "format tested. They should all sound the same.\n" + "format tested. They should all sound the same (incl. volume).\n" "\n"); create_pipeline (); diff --git a/tests/old/testsuite/alsa/sinesrc.c b/tests/old/testsuite/alsa/sinesrc.c index 4ee01f341d..7e2cf3a013 100644 --- a/tests/old/testsuite/alsa/sinesrc.c +++ b/tests/old/testsuite/alsa/sinesrc.c @@ -18,8 +18,9 @@ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include #include "sinesrc.h" +#include +#include /* memcpy */ #define SAMPLES_PER_WAVE 200 @@ -56,6 +57,7 @@ static void sinesrc_init (SineSrc *src); static void sinesrc_class_init (SineSrcClass *klass); static GstBuffer * sinesrc_get (GstPad *pad); +static GstElementStateReturn sinesrc_change_state (GstElement *element); GType @@ -78,6 +80,10 @@ sinesrc_get_type (void) static void sinesrc_class_init (SineSrcClass *klass) { + GstElementClass *element_class = GST_ELEMENT_CLASS (klass); + + element_class->change_state = sinesrc_change_state; + parent_class = g_type_class_ref (GST_TYPE_ELEMENT); } @@ -222,8 +228,47 @@ sinesrc_get (GstPad *pad) POPULATE (guint16, GUINT16_TO_BE, GUINT16_TO_LE) break; case 24: - /* mom, can I have gint24 plz? */ - g_assert_not_reached (); + if (src->sign) { + gpointer p; + gint32 val = (gint32) int_value; + switch (src->endianness) { + case G_LITTLE_ENDIAN: + val = GINT32_TO_LE (val); + break; + case G_BIG_ENDIAN: + val = GINT32_TO_BE (val); + break; + default: + g_assert_not_reached (); + }; + p = &val; + if (src->endianness == G_BIG_ENDIAN) + p++; + for (j = 0; j < src->channels; j++) { + memcpy (data, p, 3); + data += 3; + } + } else { + gpointer p; + guint32 val = (guint32) int_value; + switch (src->endianness) { + case G_LITTLE_ENDIAN: + val = GUINT32_TO_LE (val); + break; + case G_BIG_ENDIAN: + val = GUINT32_TO_BE (val); + break; + default: + g_assert_not_reached (); + }; + p = &val; + if (src->endianness == G_BIG_ENDIAN) + p++; + for (j = 0; j < src->channels; j++) { + memcpy (data, p, 3); + data += 3; + } + } break; case 32: if (src->sign) @@ -278,3 +323,31 @@ sinesrc_set_pre_get_func (SineSrc *src, PreGetFunc func) { src->pre_get_func = func; } +static GstElementStateReturn +sinesrc_change_state (GstElement *element) +{ + SineSrc *sinesrc; + + g_return_val_if_fail (element != NULL, FALSE); + sinesrc = SINESRC (element); + + switch (GST_STATE_TRANSITION (element)) { + case GST_STATE_NULL_TO_READY: + case GST_STATE_READY_TO_PAUSED: + case GST_STATE_PAUSED_TO_PLAYING: + case GST_STATE_PLAYING_TO_PAUSED: + break; + case GST_STATE_PAUSED_TO_READY: + sinesrc->newcaps = TRUE; + break; + case GST_STATE_READY_TO_NULL: + break; + default: + g_assert_not_reached(); + } + + if (GST_ELEMENT_CLASS (parent_class)->change_state) + return GST_ELEMENT_CLASS (parent_class)->change_state (element); + + return GST_STATE_SUCCESS; +} diff --git a/tests/old/testsuite/alsa/state.c b/tests/old/testsuite/alsa/state.c new file mode 100644 index 0000000000..db92f7ea8d --- /dev/null +++ b/tests/old/testsuite/alsa/state.c @@ -0,0 +1,105 @@ +/* + * Copyright (C) 2003 Benjamin Otte + * + * state.c: Tests alsasink for state changes + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU 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 + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include "sinesrc.h" + +GstElement *pipeline; + +static void +set_state (GstElementState state) +{ + GstElementState old_state = gst_element_get_state (pipeline); + + g_print ("Setting state from %s to %s...", gst_element_state_get_name (old_state), gst_element_state_get_name (state)); + + if (!gst_element_set_state (pipeline, state)) { + g_print (" ERROR\n"); + exit (-1); + } + + if (state == GST_STATE_PLAYING) { + gint i; + g_print (" DONE - iterating a bit..."); + for (i = 0; i < 400; i++) { + if (!gst_bin_iterate (GST_BIN (pipeline))) { + g_print (" ERROR in iteration %d\n", i); + exit (-2); + } + } + } + g_print (" DONE\n"); +} + +static void +create_pipeline (void) +{ + GstElement *src; + SineSrc *sinesrc; + GstElement *alsasink; + + pipeline = gst_pipeline_new ("pipeline"); + src = sinesrc_new (); + alsasink = gst_element_factory_make ("alsasink", "alsasink"); + + gst_bin_add_many (GST_BIN (pipeline), src, alsasink, NULL); + gst_element_link (src, alsasink); + + /* prepare our sinesrc */ + sinesrc = (SineSrc *) src; + sinesrc->newcaps = TRUE; + sinesrc->type = SINE_SRC_INT; + sinesrc->sign = TRUE; + sinesrc->endianness = G_BYTE_ORDER; + sinesrc->depth = 16; + sinesrc->width = 16; +} +gint +main (gint argc, gchar *argv[]) +{ + gst_init (&argc, &argv); + + g_print ("\n" + "This test will check if state changes work on the alsasink.\n" + "You will hear some short sine tones on your default ALSA soundcard,\n" + "but they are not important in this test.\n" + "\n"); + create_pipeline (); + + /* simulate some state changes here */ + set_state (GST_STATE_READY); + set_state (GST_STATE_NULL); + set_state (GST_STATE_READY); + set_state (GST_STATE_NULL); + set_state (GST_STATE_PAUSED); + set_state (GST_STATE_NULL); + set_state (GST_STATE_PLAYING); + set_state (GST_STATE_PAUSED); + set_state (GST_STATE_PLAYING); + set_state (GST_STATE_READY); + set_state (GST_STATE_PLAYING); + set_state (GST_STATE_NULL); + set_state (GST_STATE_PLAYING); + + g_print ("The alsa plugin mastered another test.\n"); + + gst_object_unref (GST_OBJECT (pipeline)); + + return 0; +} diff --git a/testsuite/alsa/Makefile.am b/testsuite/alsa/Makefile.am index e00f26b002..6e3b78723b 100644 --- a/testsuite/alsa/Makefile.am +++ b/testsuite/alsa/Makefile.am @@ -1,11 +1,14 @@ -testprogs = formats +testprogs = formats state TESTS = $(testprogs) check_PROGRAMS = $(testprogs) formats_SOURCES = formats.c sinesrc.c sinesrc.h +state_SOURCES = state.c sinesrc.c sinesrc.h # we have nothing but apps here, we can do this safely LIBS = $(GST_LIBS) AM_CFLAGS = $(GST_CFLAGS) + +noinst_HEADERS = sinesrc.h diff --git a/testsuite/alsa/formats.c b/testsuite/alsa/formats.c index 845887c1c0..93ed4e295d 100644 --- a/testsuite/alsa/formats.c +++ b/testsuite/alsa/formats.c @@ -1,6 +1,8 @@ /* * Copyright (C) 2003 Benjamin Otte * + * formats.c: Tests the different formats on alsasink + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public * License as published by the Free Software Foundation; either @@ -25,7 +27,7 @@ gint endianness = G_LITTLE_ENDIAN; gint depth = 8; gint width = 8; -#define NUMBER_OF_INT_TESTS 16 +#define NUMBER_OF_INT_TESTS 28 #define NUMBER_OF_FLOAT_TESTS 2 #define NUMBER_OF_LAW_TESTS 2 @@ -164,7 +166,7 @@ main (gint argc, gchar *argv[]) g_print ("\n" "This test will test the various formats ALSA and GStreamer support.\n" "You will hear a short sine tone on your default ALSA soundcard for every\n" - "format tested. They should all sound the same.\n" + "format tested. They should all sound the same (incl. volume).\n" "\n"); create_pipeline (); diff --git a/testsuite/alsa/sinesrc.c b/testsuite/alsa/sinesrc.c index 4ee01f341d..7e2cf3a013 100644 --- a/testsuite/alsa/sinesrc.c +++ b/testsuite/alsa/sinesrc.c @@ -18,8 +18,9 @@ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include #include "sinesrc.h" +#include +#include /* memcpy */ #define SAMPLES_PER_WAVE 200 @@ -56,6 +57,7 @@ static void sinesrc_init (SineSrc *src); static void sinesrc_class_init (SineSrcClass *klass); static GstBuffer * sinesrc_get (GstPad *pad); +static GstElementStateReturn sinesrc_change_state (GstElement *element); GType @@ -78,6 +80,10 @@ sinesrc_get_type (void) static void sinesrc_class_init (SineSrcClass *klass) { + GstElementClass *element_class = GST_ELEMENT_CLASS (klass); + + element_class->change_state = sinesrc_change_state; + parent_class = g_type_class_ref (GST_TYPE_ELEMENT); } @@ -222,8 +228,47 @@ sinesrc_get (GstPad *pad) POPULATE (guint16, GUINT16_TO_BE, GUINT16_TO_LE) break; case 24: - /* mom, can I have gint24 plz? */ - g_assert_not_reached (); + if (src->sign) { + gpointer p; + gint32 val = (gint32) int_value; + switch (src->endianness) { + case G_LITTLE_ENDIAN: + val = GINT32_TO_LE (val); + break; + case G_BIG_ENDIAN: + val = GINT32_TO_BE (val); + break; + default: + g_assert_not_reached (); + }; + p = &val; + if (src->endianness == G_BIG_ENDIAN) + p++; + for (j = 0; j < src->channels; j++) { + memcpy (data, p, 3); + data += 3; + } + } else { + gpointer p; + guint32 val = (guint32) int_value; + switch (src->endianness) { + case G_LITTLE_ENDIAN: + val = GUINT32_TO_LE (val); + break; + case G_BIG_ENDIAN: + val = GUINT32_TO_BE (val); + break; + default: + g_assert_not_reached (); + }; + p = &val; + if (src->endianness == G_BIG_ENDIAN) + p++; + for (j = 0; j < src->channels; j++) { + memcpy (data, p, 3); + data += 3; + } + } break; case 32: if (src->sign) @@ -278,3 +323,31 @@ sinesrc_set_pre_get_func (SineSrc *src, PreGetFunc func) { src->pre_get_func = func; } +static GstElementStateReturn +sinesrc_change_state (GstElement *element) +{ + SineSrc *sinesrc; + + g_return_val_if_fail (element != NULL, FALSE); + sinesrc = SINESRC (element); + + switch (GST_STATE_TRANSITION (element)) { + case GST_STATE_NULL_TO_READY: + case GST_STATE_READY_TO_PAUSED: + case GST_STATE_PAUSED_TO_PLAYING: + case GST_STATE_PLAYING_TO_PAUSED: + break; + case GST_STATE_PAUSED_TO_READY: + sinesrc->newcaps = TRUE; + break; + case GST_STATE_READY_TO_NULL: + break; + default: + g_assert_not_reached(); + } + + if (GST_ELEMENT_CLASS (parent_class)->change_state) + return GST_ELEMENT_CLASS (parent_class)->change_state (element); + + return GST_STATE_SUCCESS; +} diff --git a/testsuite/alsa/state.c b/testsuite/alsa/state.c new file mode 100644 index 0000000000..db92f7ea8d --- /dev/null +++ b/testsuite/alsa/state.c @@ -0,0 +1,105 @@ +/* + * Copyright (C) 2003 Benjamin Otte + * + * state.c: Tests alsasink for state changes + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU 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 + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include "sinesrc.h" + +GstElement *pipeline; + +static void +set_state (GstElementState state) +{ + GstElementState old_state = gst_element_get_state (pipeline); + + g_print ("Setting state from %s to %s...", gst_element_state_get_name (old_state), gst_element_state_get_name (state)); + + if (!gst_element_set_state (pipeline, state)) { + g_print (" ERROR\n"); + exit (-1); + } + + if (state == GST_STATE_PLAYING) { + gint i; + g_print (" DONE - iterating a bit..."); + for (i = 0; i < 400; i++) { + if (!gst_bin_iterate (GST_BIN (pipeline))) { + g_print (" ERROR in iteration %d\n", i); + exit (-2); + } + } + } + g_print (" DONE\n"); +} + +static void +create_pipeline (void) +{ + GstElement *src; + SineSrc *sinesrc; + GstElement *alsasink; + + pipeline = gst_pipeline_new ("pipeline"); + src = sinesrc_new (); + alsasink = gst_element_factory_make ("alsasink", "alsasink"); + + gst_bin_add_many (GST_BIN (pipeline), src, alsasink, NULL); + gst_element_link (src, alsasink); + + /* prepare our sinesrc */ + sinesrc = (SineSrc *) src; + sinesrc->newcaps = TRUE; + sinesrc->type = SINE_SRC_INT; + sinesrc->sign = TRUE; + sinesrc->endianness = G_BYTE_ORDER; + sinesrc->depth = 16; + sinesrc->width = 16; +} +gint +main (gint argc, gchar *argv[]) +{ + gst_init (&argc, &argv); + + g_print ("\n" + "This test will check if state changes work on the alsasink.\n" + "You will hear some short sine tones on your default ALSA soundcard,\n" + "but they are not important in this test.\n" + "\n"); + create_pipeline (); + + /* simulate some state changes here */ + set_state (GST_STATE_READY); + set_state (GST_STATE_NULL); + set_state (GST_STATE_READY); + set_state (GST_STATE_NULL); + set_state (GST_STATE_PAUSED); + set_state (GST_STATE_NULL); + set_state (GST_STATE_PLAYING); + set_state (GST_STATE_PAUSED); + set_state (GST_STATE_PLAYING); + set_state (GST_STATE_READY); + set_state (GST_STATE_PLAYING); + set_state (GST_STATE_NULL); + set_state (GST_STATE_PLAYING); + + g_print ("The alsa plugin mastered another test.\n"); + + gst_object_unref (GST_OBJECT (pipeline)); + + return 0; +}