Added gst-plugins-base-subtitles0.10-0.10.34 for Meego Harmattan 1.2
[mafwsubrenderer] / gst-plugins-base-subtitles0.10 / tests / old / testsuite / alsa / state.c
1 /*
2  * Copyright (C) 2003 Benjamin Otte <in7y118@public.uni-hamburg.de>
3  *
4  * state.c: Tests alsasink for state changes
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public
17  * License along with this library; if not, write to the Free
18  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  */
20
21 #include "sinesrc.h"
22
23 GstElement *pipeline;
24
25 static void
26 set_state (GstState state)
27 {
28   GstState old_state = gst_element_get_state (pipeline);
29
30   g_print ("Setting state from %s to %s...",
31       gst_element_state_get_name (old_state),
32       gst_element_state_get_name (state));
33
34   if (!gst_element_set_state (pipeline, state)) {
35     g_print (" ERROR\n");
36     exit (-1);
37   }
38
39   if (state == GST_STATE_PLAYING) {
40     gint i;
41
42     g_print (" DONE - iterating a bit...");
43     for (i = 0; i < 400; i++) {
44       if (!gst_bin_iterate (GST_BIN (pipeline))) {
45         g_print (" ERROR in iteration %d\n", i);
46         exit (-2);
47       }
48     }
49   }
50   g_print (" DONE\n");
51 }
52
53 static void
54 create_pipeline (void)
55 {
56   GstElement *src;
57   SineSrc *sinesrc;
58   GstElement *alsasink;
59
60   pipeline = gst_pipeline_new ("pipeline");
61   src = sinesrc_new ();
62   alsasink = gst_element_factory_make ("alsasink", "alsasink");
63
64   gst_bin_add_many (GST_BIN (pipeline), src, alsasink, NULL);
65   gst_element_link (src, alsasink);
66
67   /* prepare our sinesrc */
68   sinesrc = (SineSrc *) src;
69   sinesrc->newcaps = TRUE;
70   sinesrc->type = SINE_SRC_INT;
71   sinesrc->sign = TRUE;
72   sinesrc->endianness = G_BYTE_ORDER;
73   sinesrc->depth = 16;
74   sinesrc->width = 16;
75 }
76
77 gint
78 main (gint argc, gchar * argv[])
79 {
80   gst_init (&argc, &argv);
81
82   g_print ("\n"
83       "This test will check if state changes work on the alsasink.\n"
84       "You will hear some short sine tones on your default ALSA soundcard,\n"
85       "but they are not important in this test.\n" "\n");
86   create_pipeline ();
87
88   /* simulate some state changes here */
89   set_state (GST_STATE_READY);
90   set_state (GST_STATE_NULL);
91   set_state (GST_STATE_READY);
92   set_state (GST_STATE_NULL);
93   set_state (GST_STATE_PAUSED);
94   set_state (GST_STATE_NULL);
95   set_state (GST_STATE_PLAYING);
96   set_state (GST_STATE_PAUSED);
97   set_state (GST_STATE_PLAYING);
98   set_state (GST_STATE_READY);
99   set_state (GST_STATE_PLAYING);
100   set_state (GST_STATE_NULL);
101   set_state (GST_STATE_PLAYING);
102
103   g_print ("The alsa plugin mastered another test.\n");
104
105   gst_object_unref (pipeline);
106
107   return 0;
108 }