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
19 #include <gst/controller/gstcontroller.h>
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");
35 print_buffer_ts (GstPad * pad, GstProbeType type, gpointer type_data,
38 GstBuffer *buffer = type_data;
40 GST_DEBUG_OBJECT (pad, " ts: %" GST_TIME_FORMAT,
41 GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer)));
47 main (gint argc, gchar ** argv)
50 GstElement *src, *mix = NULL, *sink;
53 GstInterpolationControlSource *csource1, *csource2;
56 GstClockReturn wait_ret;
58 GstEvent *pos_seek, *rate_seek1, *rate_seek2;
63 gboolean use_adder = FALSE;
64 gboolean use_flush = FALSE;
65 gboolean be_quiet = FALSE;
67 gst_init (&argc, &argv);
68 gst_controller_init (&argc, &argv);
72 for (arg = 0; arg < argc; arg++) {
73 if (!strcmp (argv[arg], "-a"))
75 else if (!strcmp (argv[arg], "-f"))
77 else if (!strcmp (argv[arg], "-q"))
83 bin = gst_pipeline_new ("pipeline");
84 clock = gst_pipeline_get_clock (GST_PIPELINE (bin));
85 src = gst_element_factory_make ("audiotestsrc", NULL);
87 GST_WARNING ("need audiotestsrc from gst-plugins-base");
91 mix = gst_element_factory_make ("adder", NULL);
93 GST_WARNING ("need adder from gst-plugins-base");
97 sink = gst_element_factory_make ((be_quiet ? "fakesink" : "autoaudiosink"),
100 GST_WARNING ("need autoaudiosink from gst-plugins-base");
105 gst_bin_add_many (GST_BIN (bin), src, mix, sink, NULL);
106 if (!gst_element_link_many (src, mix, sink, NULL)) {
107 GST_WARNING ("can't link elements");
111 gst_bin_add_many (GST_BIN (bin), src, sink, NULL);
112 if (!gst_element_link_many (src, sink, NULL)) {
113 GST_WARNING ("can't link elements");
118 /* use 10 buffers per second */
119 g_object_set (src, "samplesperbuffer", 44100 / 10, NULL);
122 g_object_set (sink, "sync", TRUE, NULL);
125 src_pad = gst_element_get_static_pad (src, "src");
126 gst_pad_add_probe (src_pad, GST_PROBE_TYPE_BUFFER, print_buffer_ts, NULL,
128 gst_object_unref (src_pad);
130 /* add a controller to the source */
131 if (!(ctrl = gst_controller_new (G_OBJECT (src), "freq", "volume", NULL))) {
132 GST_WARNING ("can't control source element");
136 csource1 = gst_interpolation_control_source_new ();
137 csource2 = gst_interpolation_control_source_new ();
139 gst_controller_set_control_source (ctrl, "volume",
140 GST_CONTROL_SOURCE (csource1));
141 gst_controller_set_control_source (ctrl, "freq",
142 GST_CONTROL_SOURCE (csource2));
144 /* Set interpolation mode */
146 gst_interpolation_control_source_set_interpolation_mode (csource1,
147 GST_INTERPOLATE_LINEAR);
148 gst_interpolation_control_source_set_interpolation_mode (csource2,
149 GST_INTERPOLATE_LINEAR);
151 /* set control values */
152 g_value_init (&vol, G_TYPE_DOUBLE);
153 g_value_set_double (&vol, 0.0);
154 gst_interpolation_control_source_set (csource1, 0 * GST_SECOND, &vol);
155 g_value_set_double (&vol, 1.0);
156 gst_interpolation_control_source_set (csource1, 5 * GST_SECOND, &vol);
158 g_object_unref (csource1);
160 g_value_set_double (&vol, 220.0);
161 gst_interpolation_control_source_set (csource2, 0 * GST_SECOND, &vol);
162 g_value_set_double (&vol, 3520.0);
163 gst_interpolation_control_source_set (csource2, 2 * GST_SECOND, &vol);
164 g_value_set_double (&vol, 440.0);
165 gst_interpolation_control_source_set (csource2, 6 * GST_SECOND, &vol);
167 g_object_unref (csource2);
170 flags = use_flush ? GST_SEEK_FLAG_FLUSH : GST_SEEK_FLAG_NONE;
171 pos_seek = gst_event_new_seek (1.0, GST_FORMAT_TIME, flags,
172 GST_SEEK_TYPE_SET, 3 * GST_SECOND,
173 GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE);
174 rate_seek1 = gst_event_new_seek (0.5, GST_FORMAT_TIME, flags,
175 GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE,
176 GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE);
177 rate_seek2 = gst_event_new_seek (-1.0, GST_FORMAT_TIME, flags,
178 GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE,
179 GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE);
181 /* prepare queries */
182 pos = gst_query_new_position (GST_FORMAT_TIME);
186 if (gst_element_set_state (bin, GST_STATE_PAUSED) != GST_STATE_CHANGE_FAILURE) {
188 /* run for 5 seconds */
190 gst_clock_new_single_shot_id (clock,
191 gst_clock_get_time (clock) + (5 * GST_SECOND));
193 if (gst_element_set_state (bin,
194 GST_STATE_PLAYING) != GST_STATE_CHANGE_FAILURE) {
195 check_position (bin, pos, "start");
196 if ((wait_ret = gst_clock_id_wait (clock_id, NULL)) != GST_CLOCK_OK) {
197 GST_WARNING ("clock_id_wait returned: %d", wait_ret);
200 gst_clock_id_unref (clock_id);
202 check_position (bin, pos, "before seek to new pos");
204 /* seek to 3:00 sec (back 2 sec) */
205 if (!gst_element_send_event (sink, pos_seek)) {
206 GST_WARNING ("element failed to seek to new position");
209 check_position (bin, pos, "after seek to new pos");
211 /* run for 2 seconds */
213 gst_clock_new_single_shot_id (clock,
214 gst_clock_get_time (clock) + (2 * GST_SECOND));
215 if ((wait_ret = gst_clock_id_wait (clock_id, NULL)) != GST_CLOCK_OK) {
216 GST_WARNING ("clock_id_wait returned: %d", wait_ret);
218 gst_clock_id_unref (clock_id);
220 check_position (bin, pos, "before slow down rate change");
222 /* change playback rate to 0.5 */
223 if (!gst_element_send_event (sink, rate_seek1)) {
224 GST_WARNING ("element failed to change playback rate");
227 check_position (bin, pos, "after slow down rate change");
229 /* run for 4 seconds */
231 gst_clock_new_single_shot_id (clock,
232 gst_clock_get_time (clock) + (4 * GST_SECOND));
233 if ((wait_ret = gst_clock_id_wait (clock_id, NULL)) != GST_CLOCK_OK) {
234 GST_WARNING ("clock_id_wait returned: %d", wait_ret);
236 gst_clock_id_unref (clock_id);
238 check_position (bin, pos, "before reverse rate change");
240 /* change playback rate to -1.0 */
241 if (!gst_element_send_event (sink, rate_seek2)) {
242 GST_WARNING ("element failed to change playback rate");
245 check_position (bin, pos, "after reverse rate change");
247 /* run for 7 seconds */
249 gst_clock_new_single_shot_id (clock,
250 gst_clock_get_time (clock) + (7 * GST_SECOND));
251 if ((wait_ret = gst_clock_id_wait (clock_id, NULL)) != GST_CLOCK_OK) {
252 GST_WARNING ("clock_id_wait returned: %d", wait_ret);
254 gst_clock_id_unref (clock_id);
256 check_position (bin, pos, "done");
258 gst_element_set_state (bin, GST_STATE_NULL);
262 gst_query_unref (pos);
263 g_object_unref (G_OBJECT (ctrl));
264 gst_object_unref (G_OBJECT (clock));
265 gst_object_unref (G_OBJECT (bin));