26 #define DEFAULT_URI "aamps://tungsten.aaplimg.com/VOD/bipbop_adv_example_v2/master.m3u8"
27 #define DEFAULT_URI2 "aamp://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"
28 #define DEFAULT_VIDEO_RECT "0,0,1280,720"
30 #define PLAYBINTEST_NUMBER_OF_VID 1
31 #define PLAYBINTEST_MAX_NUMBER_OF_VID 2
33 GST_DEBUG_CATEGORY_STATIC (playbintest);
34 #define GST_CAT_DEFAULT playbintest
36 GstElement *playbin[PLAYBINTEST_NUMBER_OF_VID];
40 const char* playbin_names[PLAYBINTEST_MAX_NUMBER_OF_VID] = {
"playbin-0",
"playbin-1"};
41 const char* video_rectangle[PLAYBINTEST_MAX_NUMBER_OF_VID] = {
"0,0,640,360",
"640,0,640,360"};
42 gboolean g_print_states = FALSE;
44 #define PLAYBINFLAG_BUFFERING 0x00000100
46 static void info(
int idx = 0)
48 gint64 position=0, duration=0;
49 if (FALSE == gst_element_query_position(playbin[idx], GST_FORMAT_TIME, &position))
51 g_printerr(
"**PLAYBINTEST: gst_element_query_position failed\n");
54 if (FALSE == gst_element_query_duration(playbin[idx], GST_FORMAT_TIME, &duration))
56 g_printerr(
"*******PLAYBINTEST: ** gst_element_query_duration failed\n");
58 g_print(
"**PLAYBINTEST: Position:%" G_GINT64_FORMAT
" Duration:%" G_GINT64_FORMAT
"\n", position, duration);
62 static void setRate(gdouble rate,
int idx=0)
64 gint64 cur = GST_CLOCK_TIME_NONE;
66 if (!gst_element_query_position(playbin[idx], GST_FORMAT_TIME, &cur))
68 g_print(
"**PLAYBINTEST: query failed\n");
70 g_print(
"**PLAYBINTEST: setting rate %f\n", rate);
73 ret = gst_element_seek(playbin[idx], rate, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH,
74 GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE, GST_SEEK_TYPE_SET, cur);
78 ret = gst_element_seek(playbin[idx], rate, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH, GST_SEEK_TYPE_SET, cur,
79 GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE);
83 g_print(
"**PLAYBINTEST: seek failed\n");
87 g_print(
"**PLAYBINTEST: seek setrate success\n");
91 static void seek(
int seconds,
int idx=0)
93 gint64 cur = GST_SECOND*seconds;
95 if (!gst_element_seek(playbin[idx], 1.0, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH,
96 GST_SEEK_TYPE_SET, cur,
97 GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE))
99 g_print(
"**PLAYBINTEST: seek failed\n");
103 g_print(
"**PLAYBINTEST: seek success\n");
107 static void setPause(
bool pause,
int idx= 0)
110 GstStateChangeReturn ret;
111 GstState state = pause?GST_STATE_PAUSED:GST_STATE_PLAYING;
112 ret = gst_element_set_state(playbin[idx], state);
113 if (ret == GST_STATE_CHANGE_FAILURE)
115 g_printerr(
"gst_element_set_state failed\n");
119 static void stop(
int idx = 0)
121 GstStateChangeReturn ret;
122 ret = gst_element_set_state(playbin[idx], GST_STATE_NULL);
123 if (ret == GST_STATE_CHANGE_FAILURE)
125 g_printerr(
"gst_element_set_state failed\n");
129 static void changeChannel(
const char* uri,
int idx= 0)
133 g_object_set(playbin[idx],
"uri", uri, NULL);
137 static void stressTest(
int idx= 0)
140 g_print(
"**PLAYBINTEST: start stressTest\n");
143 changeChannel(uri[0], idx);
144 g_usleep(10*1000*1000);
145 changeChannel(uri[1], idx);
146 g_usleep(10*1000*1000);
148 g_print(
"\n\n**PLAYBINTEST: ChannelChange Count %d\n\n",count);
152 static void process_command(
char* cmd)
155 if (strcmp(cmd,
"info") == 0)
159 else if (strcmp(cmd,
"ff8") == 0)
163 else if (strcmp(cmd,
"ff16") == 0)
167 else if (strcmp(cmd,
"ff32") == 0)
171 else if (strcmp(cmd,
"ff") == 0)
175 else if (strcmp(cmd,
"rw32") == 0)
179 else if (strcmp(cmd,
"rw16") == 0)
183 else if (strcmp(cmd,
"rw8") == 0)
187 else if (strcmp(cmd,
"rw") == 0)
191 else if (strcmp(cmd,
"play") == 0)
195 else if (strcmp(cmd,
"pause") == 0)
199 else if (strcmp(cmd,
"1") == 0)
201 changeChannel(uri[1]);
203 else if (strcmp(cmd,
"0") == 0)
205 changeChannel(uri[0]);
207 else if (strcmp(cmd,
"stress") == 0)
211 else if (sscanf(cmd,
"seek %d", &value) == 1)
215 else if (strcmp(cmd,
"stop") == 0)
221 static void* ui_thread(
void * arg)
224 g_print(
"**PLAYBINTEST: start ui_thread\n");
225 while (fgets(cmd,
sizeof(cmd), stdin))
233 process_command(cmd);
235 g_print(
"**PLAYBINTEST: exit ui_thread\n");
239 static gboolean handle_bus_message(GstBus *bus, GstMessage *msg,
void* arg)
245 switch (GST_MESSAGE_TYPE(msg))
247 case GST_MESSAGE_EOS:
253 case GST_MESSAGE_ERROR:
255 gst_message_parse_error(msg, &error, &info);
256 g_printerr(
"**PLAYBINTEST: Error received from element %s: %s\n", GST_OBJECT_NAME(msg->src), error->message);
257 g_printerr(
"**PLAYBINTEST: Debugging information: %s\n", info ? info :
"none");
259 g_main_loop_quit(main_loop);
262 case GST_MESSAGE_STATE_CHANGED:
264 GstState old, now, pending;
265 gst_message_parse_state_changed(msg, &old, &now, &pending);
266 if (g_print_states || memcmp(GST_OBJECT_NAME(GST_MESSAGE_SRC(msg)),
"playbin", 7) == 0)
268 g_print(
"**PLAYBINTEST: element %s state change : %s -> %s . pending state %s\n", GST_ELEMENT_NAME(GST_MESSAGE_SRC(msg)),
269 gst_element_state_get_name(old), gst_element_state_get_name(now), gst_element_state_get_name(pending) );
271 GST_DEBUG_BIN_TO_DOT_FILE((GstBin *)playbin[0], GST_DEBUG_GRAPH_SHOW_ALL,
"playbintest");
273 if (now == GST_STATE_PLAYING && memcmp(GST_OBJECT_NAME(GST_MESSAGE_SRC(msg)),
"brcmvideosink", 13) == 0)
281 GstElement *pbin = GST_ELEMENT(GST_MESSAGE_SRC(msg));
284 while(GST_ELEMENT_PARENT(pbin))
286 pbin = GST_ELEMENT_PARENT(pbin);
288 const char * rect = DEFAULT_VIDEO_RECT;
290 if (PLAYBINTEST_NUMBER_OF_VID > 1 )
292 for (
int i=0; i< PLAYBINTEST_NUMBER_OF_VID; i++)
294 if (strcmp(GST_OBJECT_NAME(pbin), playbin_names[i]) == 0)
296 rect = video_rectangle[i];
302 g_print(
"*%s : setting rectangle to %s zorder to %d*\n", GST_OBJECT_NAME(pbin), rect, zorder);
303 g_object_set(GST_MESSAGE_SRC(msg),
"rectangle", rect, NULL);
304 g_object_set(GST_MESSAGE_SRC(msg),
"zorder", zorder, NULL);
308 g_printerr(
"%s:%d : pbin is null", __FUNCTION__, __LINE__);
313 case GST_MESSAGE_BUFFERING:
316 gst_message_parse_buffering(msg, &percent);
317 g_print(
"**PLAYBINTEST: eBuffering %d\n", percent);
318 #ifdef PLAYBINTEST_BUFFERING
321 else if(percent < 10)
326 case GST_MESSAGE_TAG:
329 g_print(
"Bus msg type: %s\n", gst_message_type_get_name(msg->type));
336 int main(
int argc,
char *argv[])
339 GstStateChangeReturn ret;
342 gst_init(&argc, &argv);
343 GST_DEBUG_CATEGORY_INIT (playbintest,
"playbin test", 0,
"Debug Category for Playbin Test");
345 GST_FIXME(
"Start\n");
349 uri[0] = g_strdup(argv[1]);
350 g_print(
"Using uri provided in command line : ");
354 uri[0] = DEFAULT_URI;
355 g_print(
"Using default uri : ");
359 uri[1] = g_strdup(argv[2]);
363 uri[1] = DEFAULT_URI2;
365 g_print(
"uri[0] %s uri[1] %s\n", uri[0], uri[1]);
367 if (NULL != g_getenv(
"PLAYBINTEST_DEBUG_STATES"))
369 g_print_states =
TRUE;
371 for(
int i = 0; i <PLAYBINTEST_NUMBER_OF_VID; i++)
373 playbin[i] = gst_element_factory_make(
"playbin", playbin_names[i]);
376 g_printerr(
"playbin couldn't be created.\n");
379 g_object_set(playbin[i],
"uri", uri[i], NULL);
381 g_object_get(playbin[i],
"flags", &flags, NULL);
382 flags |= 0x03 | 0x00000040;
383 #ifdef PLAYBINTEST_BUFFERING
384 flags |= PLAYBINFLAG_BUFFERING;
387 g_object_set(playbin[i],
"flags", flags, NULL);
389 #ifdef PLAYBINTEST_WESTEROSSINK
390 GstElement* west = gst_element_factory_make(
"westerossink", NULL);
393 g_printerr(
"westeros-sink couldn't be created.\n");
396 g_object_set(playbin[i],
"video-sink", west, NULL);
399 bus = gst_element_get_bus(playbin[i]);
400 gst_bus_add_watch(bus, (GstBusFunc) handle_bus_message, NULL);
402 #ifdef PLAYBINTEST_BUFFERING
403 ret = gst_element_set_state(playbin[i], GST_STATE_PAUSED);
405 GST_FIXME(
"Setting to Playing State\n");
406 ret = gst_element_set_state(playbin[i], GST_STATE_PLAYING);
407 GST_FIXME(
"Set to Playing State\n");
409 if (ret == GST_STATE_CHANGE_FAILURE)
411 g_printerr(
"Play failed\n");
412 gst_object_unref(playbin[i]);
416 if(0 != pthread_create(&uiThreadID, NULL, &ui_thread, NULL))
418 g_printerr(
"%s:%d: Error at pthread_create", __FUNCTION__, __LINE__);
420 main_loop = g_main_loop_new(NULL, FALSE);
421 g_main_loop_run(main_loop);
424 g_main_loop_unref(main_loop);
425 gst_object_unref(bus);
427 for(
int i = 0; i <PLAYBINTEST_NUMBER_OF_VID; i++)
429 gst_element_set_state(playbin[i], GST_STATE_NULL);
430 gst_object_unref(playbin[i]);