Add quick prepare menu for testing
[platform/core/multimedia/esplusplayer.git] / test / esplusplayer_test.c
index 0c82e28..38400a4 100644 (file)
@@ -22,6 +22,7 @@
 #include <glib.h>
 #include <dlog.h>
 #include <mediademuxer.h>
+#include <getopt.h>
 
 #include "esplusplayer_capi/esplusplayer_capi.h"
 #include "esplusplayer_capi/esplusplayer_internal.h"
@@ -95,6 +96,8 @@ typedef struct {
        stream_t streams[STREAM_MAX];
        media_format_h track_format[MAX_TRACK_COUNT];
        bool stop_thread;
+       int video_track_id;
+       int audio_track_id;
 } test_h;
 
 static appdata g_ad;
@@ -118,7 +121,7 @@ static test_h *g_test_h;
        } \
 }
 
-static char g_uri[MAX_STRING_LEN];
+static char *g_uri;
 static int g_menu_state = CURRENT_STATUS_MAINMENU;
 
 static void __deinit_test();
@@ -440,6 +443,9 @@ static void __init_test()
                g_cond_init(&g_test_h->streams[i].cond);
                g_test_h->streams[i].track_index = -1;
        }
+       g_test_h->audio_track_id = -1;
+       g_test_h->video_track_id = -1;
+
        __init_espp();
        __init_demux();
 }
@@ -481,7 +487,7 @@ static void __deinit_test()
        }
 
        g_free(g_test_h);
-       g_test_h = NULL;
+       g_free(g_uri);
 }
 
 static void __test_demuxer_get_track_info()
@@ -525,6 +531,8 @@ static void __test_demuxer_get_track_info()
                                g_test_h->track_format[track] = get_format;
                                media_format_ref(get_format);
                                g_test_h->streams[VIDEO_STREAM].format = get_format;
+                               if (g_test_h->video_track_id < 0)  /* keep the first track id for quick prepare */
+                                       g_test_h->video_track_id = track;
                        } else if (media_format_get_audio_info(get_format, &mime,
                                                        &channel, &samplerate, &bit, NULL) == MEDIA_FORMAT_ERROR_NONE) {
                                g_print("\t\t[audio_id(%d)]mime:%x, channel :%d, samplerate :%d, bit :%d\n",
@@ -535,6 +543,8 @@ static void __test_demuxer_get_track_info()
                                }
                                media_format_ref(get_format);
                                g_test_h->track_format[track] = get_format;
+                               if (g_test_h->audio_track_id < 0) /* keep the first track id for quick prepare */
+                                       g_test_h->audio_track_id = track;
                        } else if (media_format_get_text_info(get_format, &mime, &t_type) == MEDIA_FORMAT_ERROR_NONE) {
                                        g_print("media_format_get_text_info is success!\n");
                                        g_print("\t\t[media_format_get_text]mime:%x, type:%x\n", mime, t_type);
@@ -1282,10 +1292,71 @@ static void __test_enable_video_hole(bool value)
                g_print("                       => esplusplayer_enable_video_hole() success\n");
 }
 
+static void __test_quick_prepare()
+{
+       int ret = 0;
+
+       if (!g_uri) {
+               g_print("                       => failed, need uri with testsuite option\n");
+               return;
+       }
+
+       __init_test();
+
+       ret = esplusplayer_set_display(g_test_h->espp_h, ESPLUSPLAYER_DISPLAY_TYPE_OVERLAY, (void *)g_win_id);
+       if (ret != ESPLUSPLAYER_ERROR_TYPE_NONE) {
+               g_print("                       => failed to esplusplayer_set_display\n");
+               return;
+       }
+
+       if (mediademuxer_set_data_source(g_test_h->demux_h, g_uri) != MEDIADEMUXER_ERROR_NONE) {
+               g_print("                       => failed to mediademuxer_set_data_source()\n");
+               return;
+       }
+
+       if (mediademuxer_prepare(g_test_h->demux_h) != MEDIADEMUXER_ERROR_NONE) {
+               g_print("                       => failed to mediademuxer_prepare()\n");
+               return;
+       }
+
+       __test_demuxer_get_track_info();
+
+       if (g_test_h->video_track_id >= 0) {
+               g_test_h->streams[VIDEO_STREAM].format = g_test_h->track_format[g_test_h->video_track_id];
+               g_test_h->streams[VIDEO_STREAM].track_index = g_test_h->video_track_id;
+               if (mediademuxer_select_track(g_test_h->demux_h, g_test_h->video_track_id) != MEDIADEMUXER_ERROR_NONE) {
+                       g_print("                       => failed to mediademuxer_select_track() for video\n");
+                       return;
+               }
+       }
+
+       if (g_test_h->audio_track_id >= 0) {
+               g_test_h->streams[AUDIO_STREAM].format = g_test_h->track_format[g_test_h->audio_track_id];
+               g_test_h->streams[AUDIO_STREAM].track_index = g_test_h->audio_track_id;
+               if (mediademuxer_select_track(g_test_h->demux_h, g_test_h->audio_track_id) != MEDIADEMUXER_ERROR_NONE) {
+                       g_print("                       => failed to mediademuxer_select_track() for audio\n");
+                       return;
+               }
+       }
+
+       if (mediademuxer_start(g_test_h->demux_h) != MEDIADEMUXER_ERROR_NONE) {
+               g_print("                       => failed to mediademuxer_start()\n");
+               return;
+       }
+
+       if (g_test_h->video_track_id >= 0)
+               __test_set_video_stream_info();
+
+       if (g_test_h->audio_track_id >= 0)
+               __test_set_audio_stream_info();
+
+       __test_prepare_async();
+
+       g_print(" => input 'sp' -> 's' to start()\n");
+}
+
 static void __input_filename(char *filename)
 {
-       int len = 0;
-       gsize src_size = 0;
        int ret = TIZEN_ERROR_NONE;
 
        if (!filename)
@@ -1296,15 +1367,7 @@ static void __input_filename(char *filename)
                return;
        }
 
-       len = strlen(filename);
-       if (len < 0 || len > MAX_STRING_LEN - 1)
-               return;
-
-       src_size = g_strlcpy(g_uri, filename, MAX_STRING_LEN);
-       if (src_size != len)
-               return;
-
-       ret = mediademuxer_set_data_source(g_test_h->demux_h, g_uri);
+       ret = mediademuxer_set_data_source(g_test_h->demux_h, filename);
        if (ret != MEDIADEMUXER_ERROR_NONE)
                g_print("                       => failed to mediademuxer_set_data_source()\n");
 }
@@ -1373,6 +1436,8 @@ static void __interpret_main_menu(char *cmd)
                        g_menu_state = CURRENT_STATUS_ENABLE_VIDEO_HOLE;
                } else if (strncmp(cmd, "sr", 2) == 0) {
                        g_menu_state = CURRENT_STATUS_SET_RENDER_TIME_OFFSET;
+               } else if (strncmp(cmd, "qp", 2) == 0) {
+                       __test_quick_prepare();
                } else {
                        g_print("unknown menu \n");
                }
@@ -1399,7 +1464,9 @@ static void __display_sub_basic()
        g_print("=========================================================================================\n");
        g_print("                ESPlusplayer Test with mediademuxer (press q to quit) \n");
        g_print("-----------------------------------------------------------------------------------------\n");
-       g_print("c -> ds -> a -> prd (select track) -> sa / sv \n  -> pa -> sp -> (got prepare async done cb) -> s\n");
+       g_print("1. c -> ds -> a -> prd (select track) -> sa / sv \n\t-> pa -> sp -> (__espp_prepare_async_done_cb) \n\t-> s\n");
+       g_print("2. quick prepare with overlay and first audio/video track \n");
+       g_print("\tqp -> (__espp_ready_to_prepare_cb) \n\t-> sp -> (__espp_prepare_async_done_cb) \n\t-> s\n");
        g_print("-----------------------------------------------------------------------------------------\n");
        g_print("[playback] c.Create\t");
        g_print("a.Input media path\t");
@@ -1416,6 +1483,7 @@ static void __display_sub_basic()
        g_print("d.Resume\t");
        g_print("e.Pause\t\t");
        g_print("dt.Destroy\n");
+       g_print("qp.quick prepare\n");
        g_print("[seek] j.Seek\t\t");
        g_print("[trick] tr.set playback rate\n");
        g_print("[State] S.Get state\n");
@@ -1773,6 +1841,14 @@ static gboolean input(GIOChannel *channel, GIOCondition condition, gpointer data
        return TRUE;
 }
 
+static void print_usage()
+{
+       g_print("Usage : ");
+       g_print("esplusplayer_test [option]\n\n"
+               "  -u, --uri                       uri\n"
+               "  -h, --help                      help\n");
+}
+
 int main(int argc, char *argv[])
 {
        GIOChannel *stdin_channel;
@@ -1780,9 +1856,35 @@ int main(int argc, char *argv[])
        g_io_channel_set_flags(stdin_channel, G_IO_FLAG_NONBLOCK, NULL);
        g_io_add_watch(stdin_channel, G_IO_IN, (GIOFunc)input, NULL);
 
-       __displaymenu();
        memset(&g_ad, 0x0, sizeof(appdata));
+
+       while (1) {
+               int opt;
+               int opt_idx = 0;
+
+               static struct option long_options[] = {
+                       { "uri", required_argument, 0, 'u' },
+                       { "help", no_argument, 0, 'h' },
+                       { 0, 0, 0, 0 }
+               };
+
+               if ((opt = getopt_long(argc, argv, "u:h", long_options, &opt_idx)) == -1)
+                       break;
+
+               switch (opt) {
+               case 'u':
+                       g_free(g_uri);
+                       g_uri = g_strdup(optarg);
+                       break;
+               case 'h':
+               default:
+                       print_usage();
+                       return 0;
+               }
+       }
+
        ops.data = &g_ad;
+       __displaymenu();
 
        return appcore_efl_main(PACKAGE, &argc, &argv, &ops);
 }