4 * Builds a pipeline with two audiotestsources mixed with adder. Assigns
5 * controller patterns to the audio generators and test various trick modes.
7 * There are currently several issues:
8 * - adder only work with flushing seeks
9 * - there is a gap of almost 4 seconds before backwards playback
10 * - it is "waiting for free space"
11 * - using sync=false on the sink does not help (but has some other weird effects)
12 * - using fakesink shows same behaviour
14 * GST_DEBUG_NO_COLOR=1 GST_DEBUG="*:2,default:3,*sink*:4,*ring*:4,*pulse*:5" ./audio-trickplay 2>log.txt
15 * GST_DEBUG_NO_COLOR=1 GST_DEBUG="*:2,default:3,*sink*:4,*ring*:4,*pulse*:5" ./audio-trickplay -a -f 2>log-af.txt
20 #include <gst/controller/gstinterpolationcontrolsource.h>
23 check_position (GstElement * elem, GstQuery * pos, const gchar * info)
25 if (gst_element_query (elem, pos)) {
27 gst_query_parse_position (pos, NULL, &play_pos);
28 GST_INFO ("pos : %" GST_TIME_FORMAT " %s", GST_TIME_ARGS (play_pos), info);
30 GST_WARNING ("position query failed");
34 static GstPadProbeReturn
35 print_buffer_ts (GstPad * pad, GstPadProbeInfo * info, gpointer user_data)
37 GstBuffer *buffer = GST_PAD_PROBE_INFO_BUFFER (info);
39 GST_DEBUG_OBJECT (pad, " ts: %" GST_TIME_FORMAT,
40 GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer)));
42 return GST_PAD_PROBE_OK;
46 main (gint argc, gchar ** argv)
49 GstElement *src, *mix = NULL, *sink;
51 GstInterpolationControlSource *csource1, *csource2;
54 GstClockReturn wait_ret;
56 GstEvent *pos_seek, *rate_seek1, *rate_seek2;
61 gboolean use_adder = FALSE;
62 gboolean use_flush = FALSE;
63 gboolean be_quiet = FALSE;
65 gst_init (&argc, &argv);
69 for (arg = 0; arg < argc; arg++) {
70 if (!strcmp (argv[arg], "-a"))
72 else if (!strcmp (argv[arg], "-f"))
74 else if (!strcmp (argv[arg], "-q"))
80 bin = gst_pipeline_new ("pipeline");
81 clock = gst_pipeline_get_clock (GST_PIPELINE (bin));
82 src = gst_element_factory_make ("audiotestsrc", NULL);
84 GST_WARNING ("need audiotestsrc from gst-plugins-base");
88 mix = gst_element_factory_make ("adder", NULL);
90 GST_WARNING ("need adder from gst-plugins-base");
94 sink = gst_element_factory_make ((be_quiet ? "fakesink" : "autoaudiosink"),
97 GST_WARNING ("need autoaudiosink from gst-plugins-base");
102 gst_bin_add_many (GST_BIN (bin), src, mix, sink, NULL);
103 if (!gst_element_link_many (src, mix, sink, NULL)) {
104 GST_WARNING ("can't link elements");
108 gst_bin_add_many (GST_BIN (bin), src, sink, NULL);
109 if (!gst_element_link_many (src, sink, NULL)) {
110 GST_WARNING ("can't link elements");
115 /* use 10 buffers per second */
116 g_object_set (src, "samplesperbuffer", 44100 / 10, NULL);
119 g_object_set (sink, "sync", TRUE, NULL);
122 src_pad = gst_element_get_static_pad (src, "src");
123 gst_pad_add_probe (src_pad, GST_PAD_PROBE_TYPE_BUFFER, print_buffer_ts, NULL,
125 gst_object_unref (src_pad);
127 csource1 = gst_interpolation_control_source_new ();
128 csource2 = gst_interpolation_control_source_new ();
130 gst_object_set_control_source (GST_OBJECT (src), "volume",
131 GST_CONTROL_SOURCE (csource1));
132 gst_object_set_control_source (GST_OBJECT (src), "freq",
133 GST_CONTROL_SOURCE (csource2));
135 /* Set interpolation mode */
137 gst_interpolation_control_source_set_interpolation_mode (csource1,
138 GST_INTERPOLATE_LINEAR);
139 gst_interpolation_control_source_set_interpolation_mode (csource2,
140 GST_INTERPOLATE_LINEAR);
142 /* set control values */
143 g_value_init (&vol, G_TYPE_DOUBLE);
144 g_value_set_double (&vol, 0.0);
145 gst_interpolation_control_source_set (csource1, 0 * GST_SECOND, &vol);
146 g_value_set_double (&vol, 1.0);
147 gst_interpolation_control_source_set (csource1, 5 * GST_SECOND, &vol);
149 g_object_unref (csource1);
151 g_value_set_double (&vol, 220.0);
152 gst_interpolation_control_source_set (csource2, 0 * GST_SECOND, &vol);
153 g_value_set_double (&vol, 3520.0);
154 gst_interpolation_control_source_set (csource2, 2 * GST_SECOND, &vol);
155 g_value_set_double (&vol, 440.0);
156 gst_interpolation_control_source_set (csource2, 6 * GST_SECOND, &vol);
158 g_object_unref (csource2);
161 flags = use_flush ? GST_SEEK_FLAG_FLUSH : GST_SEEK_FLAG_NONE;
162 pos_seek = gst_event_new_seek (1.0, GST_FORMAT_TIME, flags,
163 GST_SEEK_TYPE_SET, 3 * GST_SECOND,
164 GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE);
165 rate_seek1 = gst_event_new_seek (0.5, GST_FORMAT_TIME, flags,
166 GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE,
167 GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE);
168 rate_seek2 = gst_event_new_seek (-1.0, GST_FORMAT_TIME, flags,
169 GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE,
170 GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE);
172 /* prepare queries */
173 pos = gst_query_new_position (GST_FORMAT_TIME);
177 if (gst_element_set_state (bin, GST_STATE_PAUSED) != GST_STATE_CHANGE_FAILURE) {
179 /* run for 5 seconds */
181 gst_clock_new_single_shot_id (clock,
182 gst_clock_get_time (clock) + (5 * GST_SECOND));
184 if (gst_element_set_state (bin,
185 GST_STATE_PLAYING) != GST_STATE_CHANGE_FAILURE) {
186 check_position (bin, pos, "start");
187 if ((wait_ret = gst_clock_id_wait (clock_id, NULL)) != GST_CLOCK_OK) {
188 GST_WARNING ("clock_id_wait returned: %d", wait_ret);
191 gst_clock_id_unref (clock_id);
193 check_position (bin, pos, "before seek to new pos");
195 /* seek to 3:00 sec (back 2 sec) */
196 if (!gst_element_send_event (sink, pos_seek)) {
197 GST_WARNING ("element failed to seek to new position");
200 check_position (bin, pos, "after seek to new pos");
202 /* run for 2 seconds */
204 gst_clock_new_single_shot_id (clock,
205 gst_clock_get_time (clock) + (2 * GST_SECOND));
206 if ((wait_ret = gst_clock_id_wait (clock_id, NULL)) != GST_CLOCK_OK) {
207 GST_WARNING ("clock_id_wait returned: %d", wait_ret);
209 gst_clock_id_unref (clock_id);
211 check_position (bin, pos, "before slow down rate change");
213 /* change playback rate to 0.5 */
214 if (!gst_element_send_event (sink, rate_seek1)) {
215 GST_WARNING ("element failed to change playback rate");
218 check_position (bin, pos, "after slow down rate change");
220 /* run for 4 seconds */
222 gst_clock_new_single_shot_id (clock,
223 gst_clock_get_time (clock) + (4 * GST_SECOND));
224 if ((wait_ret = gst_clock_id_wait (clock_id, NULL)) != GST_CLOCK_OK) {
225 GST_WARNING ("clock_id_wait returned: %d", wait_ret);
227 gst_clock_id_unref (clock_id);
229 check_position (bin, pos, "before reverse rate change");
231 /* change playback rate to -1.0 */
232 if (!gst_element_send_event (sink, rate_seek2)) {
233 GST_WARNING ("element failed to change playback rate");
236 check_position (bin, pos, "after reverse rate change");
238 /* run for 7 seconds */
240 gst_clock_new_single_shot_id (clock,
241 gst_clock_get_time (clock) + (7 * GST_SECOND));
242 if ((wait_ret = gst_clock_id_wait (clock_id, NULL)) != GST_CLOCK_OK) {
243 GST_WARNING ("clock_id_wait returned: %d", wait_ret);
245 gst_clock_id_unref (clock_id);
247 check_position (bin, pos, "done");
249 gst_element_set_state (bin, GST_STATE_NULL);
253 gst_query_unref (pos);
254 gst_object_unref (G_OBJECT (clock));
255 gst_object_unref (G_OBJECT (bin));