add test case for SOUND_STREAM_TYPE_MEDIA_EXTERNAL_ONLY in player_test
[platform/core/api/player.git] / test / player_test.c
1 /*
2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 #include <player.h>
17 #include <player_internal.h>
18 #include <sound_manager.h>
19 #include <pthread.h>
20 #include <glib.h>
21 #include <dlfcn.h>
22 #include <appcore-efl.h>
23 #include <Elementary.h>
24 #ifdef HAVE_X11
25 #include <Ecore_X.h>
26 #endif
27 #ifdef HAVE_WAYLAND
28 #include <Ecore.h>
29 #include <Ecore_Wayland.h>
30 #endif
31 #ifdef _ACTIVATE_EOM_
32 #include <eom.h>
33 #endif
34
35 #ifdef PACKAGE
36 #undef PACKAGE
37 #endif
38 #define PACKAGE "player_test"
39
40 #ifdef LOG_TAG
41 #undef LOG_TAG
42 #endif
43 #define LOG_TAG "PLAYER_TEST"
44
45 #define MAX_STRING_LEN  2048
46 #define MMTS_SAMPLELIST_INI_DEFAULT_PATH "/opt/etc/mmts_filelist.ini"
47 #define PLAYER_TEST_DUMP_PATH_PREFIX   "/home/owner/content/dump_pcm_"
48 #define INI_SAMPLE_LIST_MAX 9
49 #define DEFAULT_HTTP_TIMEOUT -1
50
51 static gboolean g_memory_playback = FALSE;
52 static char g_uri[MAX_STRING_LEN];
53 static char g_subtitle_uri[MAX_STRING_LEN];
54 static FILE *g_pcm_fd;
55
56 static gboolean is_es_push_mode = FALSE;
57 static pthread_t g_feed_video_thread_id = 0;
58 static bool g_thread_end = FALSE;
59 static media_packet_h g_audio_pkt = NULL;
60 static media_format_h g_audio_fmt = NULL;
61
62 static media_packet_h g_video_pkt = NULL;
63 static media_format_h g_video_fmt = NULL;
64
65 static int _save(unsigned char *src, int length);
66
67 #define DUMP_OUTBUF         1
68 #if DUMP_OUTBUF
69 FILE *fp_out1 = NULL;
70 FILE *fp_out2 = NULL;
71 #endif
72
73 enum {
74         CURRENT_STATUS_MAINMENU,
75         CURRENT_STATUS_HANDLE_NUM,
76         CURRENT_STATUS_FILENAME,
77         CURRENT_STATUS_VOLUME,
78         CURRENT_STATUS_SOUND_TYPE,
79         CURRENT_STATUS_SOUND_STREAM_INFO,
80         CURRENT_STATUS_MUTE,
81         CURRENT_STATUS_POSITION_TIME,
82         CURRENT_STATUS_LOOPING,
83         CURRENT_STATUS_DISPLAY_SURFACE_CHANGE,
84         CURRENT_STATUS_DISPLAY_MODE,
85         CURRENT_STATUS_DISPLAY_ROTATION,
86         CURRENT_STATUS_DISPLAY_VISIBLE,
87         CURRENT_STATUS_DISPLAY_ROI_MODE,
88         CURRENT_STATUS_DISPLAY_DST_ROI,
89         CURRENT_STATUS_DISPLAY_SRC_CROP,
90         CURRENT_STATUS_SUBTITLE_FILENAME,
91         CURRENT_STATUS_AUDIO_EQUALIZER,
92         CURRENT_STATUS_PLAYBACK_RATE,
93         CURRENT_STATUS_STREAMING_PLAYBACK_RATE,
94         CURRENT_STATUS_SWITCH_SUBTITLE,
95 };
96
97 #define MAX_HANDLE 20
98
99 /* for video display */
100 static Evas_Object *g_xid;
101 #ifdef _ACTIVATE_EOM_
102 static Evas_Object *g_external_xid;
103 #endif
104 static Evas_Object *selected_xid;
105 static Evas_Object *g_eo[MAX_HANDLE] = {0, };
106
107 static int g_current_surface_type = PLAYER_DISPLAY_TYPE_OVERLAY;
108
109 typedef struct {
110         Evas_Object *win;
111         Evas_Object *layout_main;       /* layout widget based on EDJ */
112 #ifdef HAVE_X11
113         Ecore_X_Window xid;
114 #elif HAVE_WAYLAND
115         unsigned int xid;
116 #endif
117         /* add more variables here */
118 #ifdef _ACTIVATE_EOM_
119         int hdmi_output_id;
120 #endif
121 } appdata;
122
123 static appdata ad;
124 static player_h g_player[MAX_HANDLE] = {0, };
125
126 int g_handle_num = 1;
127 int g_menu_state = CURRENT_STATUS_MAINMENU;
128 char g_file_list[9][256];
129 gboolean quit_pushing;
130 sound_stream_info_h g_stream_info_h = NULL;
131
132 static void win_del(void *data, Evas_Object *obj, void *event)
133 {
134         elm_exit();
135 }
136
137 static Evas_Object *create_win(const char *name)
138 {
139         Evas_Object *eo = NULL;
140         int w = 0;
141         int h = 0;
142
143         g_print("[%s][%d] name=%s\n", __func__, __LINE__, name);
144
145         eo = elm_win_add(NULL, name, ELM_WIN_BASIC);
146         if (eo) {
147                 elm_win_title_set(eo, name);
148                 elm_win_borderless_set(eo, EINA_TRUE);
149                 evas_object_smart_callback_add(eo, "delete,request", win_del, NULL);
150                 elm_win_screen_size_get(eo, NULL, NULL, &w, &h);
151                 g_print("window size :%d,%d", w, h);
152                 evas_object_resize(eo, w, h);
153                 elm_win_autodel_set(eo, EINA_TRUE);
154 #ifdef HAVE_WAYLAND
155                 elm_win_alpha_set(eo, EINA_TRUE);
156 #endif
157         }
158         return eo;
159 }
160
161 static Evas_Object *create_image_object(Evas_Object *eo_parent)
162 {
163         if (!eo_parent)
164                 return NULL;
165
166         Evas *evas = evas_object_evas_get(eo_parent);
167         Evas_Object *eo = NULL;
168
169         eo = evas_object_image_add(evas);
170
171         return eo;
172 }
173
174 void create_render_rect_and_bg(Evas_Object *win)
175 {
176         if (!win) {
177                 g_print("no win");
178                 return;
179         }
180         Evas_Object *bg, *rect;
181
182         bg = elm_bg_add(win);
183         elm_win_resize_object_add(win, bg);
184         evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
185         evas_object_show(bg);
186
187         rect = evas_object_rectangle_add(evas_object_evas_get(win));
188         if (!rect) {
189                 g_print("no rect");
190                 return;
191         }
192         evas_object_color_set(rect, 0, 0, 0, 0);
193         evas_object_render_op_set(rect, EVAS_RENDER_COPY);
194
195         elm_win_resize_object_add(win, rect);
196         evas_object_size_hint_weight_set(rect, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
197         evas_object_show(rect);
198         evas_object_show(win);
199 }
200 #ifdef _ACTIVATE_EOM_
201 int eom_get_output_id(const char *output_name)
202 {
203         eom_output_id *output_ids = NULL;
204         eom_output_id output_id = 0;
205         eom_output_type_e output_type = EOM_OUTPUT_TYPE_UNKNOWN;
206         int id_cnt = 0;
207         int i;
208
209         /* get output_ids */
210         output_ids = eom_get_eom_output_ids(&id_cnt);
211         if (id_cnt == 0) {
212                 g_print("[eom] no external outuputs supported\n");
213                 return 0;
214         }
215
216         /* find output ids interested */
217         for (i = 0; i < id_cnt; i++) {
218                 eom_get_output_type(output_ids[i], &output_type);
219                 if (!strncmp(output_name, "HDMI", 4)) {
220                         if (output_type == EOM_OUTPUT_TYPE_HDMIA || output_type == EOM_OUTPUT_TYPE_HDMIB) {
221                                 output_id = output_ids[i];
222                                 break;
223                         }
224                 } else if (!strncmp(output_name, "Virtual", 4)) {
225                         if (output_type == EOM_OUTPUT_TYPE_VIRTUAL) {
226                                 output_id = output_ids[i];
227                                 break;
228                         }
229                 }
230         }
231
232         if (output_ids)
233                 free(output_ids);
234
235         return output_id;
236 }
237
238 static void eom_notify_cb_output_add(eom_output_id output_id, void *user_data)
239 {
240         appdata *info = (appdata *)user_data;
241
242         if (info->hdmi_output_id != output_id) {
243                 g_print("[eom] OUTPUT ADDED. SKIP. my output ID is %d\n", info->hdmi_output_id);
244                 return;
245         }
246         g_print("[eom] output(%d) connected\n", output_id);
247         /* it is for external window */
248         if (!g_external_xid) {
249                 g_external_xid = elm_win_add(NULL, "External", ELM_WIN_BASIC);
250                 if (eom_set_output_window(info->hdmi_output_id, g_external_xid) == EOM_ERROR_NONE) {
251                         create_render_rect_and_bg(g_external_xid);
252                         g_print("[eom] create external window\n");
253                 } else {
254                         evas_object_del(g_external_xid);
255                         g_external_xid = NULL;
256                         g_print("[eom] create external window fail\n");
257                 }
258         }
259 }
260
261 static void eom_notify_cb_output_remove(eom_output_id output_id, void *user_data)
262 {
263         appdata *info = (appdata *)user_data;
264         player_state_e state;
265
266         if (info->hdmi_output_id != output_id) {
267                 g_print("[eom] OUTPUT REMOVED. SKIP. my output ID is %d\n", info->hdmi_output_id);
268                 return;
269         }
270         g_print("[eom] output(%d) disconnected\n", output_id);
271
272         if (selected_xid == g_external_xid && g_player[0]) {
273                 player_get_state(g_player[0], &state);
274                 if (state >= PLAYER_STATE_READY) {
275                         if (!g_xid) {
276                                 g_xid = create_win(PACKAGE);
277                                 if (g_xid == NULL)
278                                         return;
279                                 g_print("create xid %p\n", g_xid);
280                                 create_render_rect_and_bg(g_xid);
281                                 elm_win_activate(g_xid);
282                                 evas_object_show(g_xid);
283                         }
284                         player_set_display(g_player[0], PLAYER_DISPLAY_TYPE_OVERLAY, GET_DISPLAY(g_xid));
285                 }
286         }
287
288         /* it is for external window */
289         if (g_external_xid) {
290                 evas_object_del(g_external_xid);
291                 g_external_xid = NULL;
292         }
293         selected_xid = g_xid;
294 }
295
296 static void eom_notify_cb_mode_changed(eom_output_id output_id, void *user_data)
297 {
298         appdata *info = (appdata *)user_data;
299         eom_output_mode_e mode = EOM_OUTPUT_MODE_NONE;
300
301         if (info->hdmi_output_id != output_id) {
302                 g_print("[eom] MODE CHANGED. SKIP. my output ID is %d\n", info->hdmi_output_id);
303                 return;
304         }
305
306         eom_get_output_mode(output_id, &mode);
307         g_print("[eom] output(%d) mode changed(%d)\n", output_id, mode);
308 }
309
310 static void eom_notify_cb_attribute_changed(eom_output_id output_id, void *user_data)
311 {
312         appdata *info = (appdata *)user_data;
313
314         eom_output_attribute_e attribute = EOM_OUTPUT_ATTRIBUTE_NONE;
315         eom_output_attribute_state_e state = EOM_OUTPUT_ATTRIBUTE_STATE_NONE;
316
317         if (info->hdmi_output_id != output_id) {
318                 g_print("[eom] ATTR CHANGED. SKIP. my output ID is %d\n", info->hdmi_output_id);
319                 return;
320         }
321
322         eom_get_output_attribute(output_id, &attribute);
323         eom_get_output_attribute_state(output_id, &state);
324
325         g_print("[eom] output(%d) attribute changed(%d, %d)\n", output_id, attribute, state);
326         if (state == EOM_OUTPUT_ATTRIBUTE_STATE_ACTIVE) {
327                 g_print("[eom] active\n");
328                 if (!g_external_xid) {
329                         g_external_xid = elm_win_add(NULL, "External", ELM_WIN_BASIC);
330                         if (eom_set_output_window(info->hdmi_output_id, g_external_xid) == EOM_ERROR_NONE) {
331                                 create_render_rect_and_bg(g_external_xid);
332                                 g_print("[eom] create external window\n");
333                         } else {
334                                 evas_object_del(g_external_xid);
335                                 g_external_xid = NULL;
336                                 g_print("[eom] create external window fail\n");
337                         }
338                 }
339                 selected_xid = g_external_xid;
340                 /* play video on external window */
341                 if (g_player[0])
342                         player_set_display(g_player[0], PLAYER_DISPLAY_TYPE_OVERLAY, GET_DISPLAY(selected_xid));
343         } else if (state == EOM_OUTPUT_ATTRIBUTE_STATE_INACTIVE) {
344                 g_print("[eom] inactive\n");
345                 if (!g_xid) {
346                         g_xid = create_win(PACKAGE);
347                         if (g_xid == NULL)
348                                 return;
349                         g_print("create xid %p\n", g_xid);
350                         create_render_rect_and_bg(g_xid);
351                         elm_win_activate(g_xid);
352                         evas_object_show(g_xid);
353                 }
354                 selected_xid = g_xid;
355                 if (g_player[0])
356                         player_set_display(g_player[0], PLAYER_DISPLAY_TYPE_OVERLAY, GET_DISPLAY(selected_xid));
357
358                 if (g_external_xid) {
359                         evas_object_del(g_external_xid);
360                         g_external_xid = NULL;
361                 }
362         } else if (state == EOM_OUTPUT_ATTRIBUTE_STATE_LOST) {
363                 g_print("[eom] lost\n");
364                 if (!g_xid) {
365                         g_xid = create_win(PACKAGE);
366                         if (g_xid == NULL)
367                                 return;
368                         g_print("create xid %p\n", g_xid);
369                         create_render_rect_and_bg(g_xid);
370                         elm_win_activate(g_xid);
371                         evas_object_show(g_xid);
372                 }
373                 selected_xid = g_xid;
374
375                 if (g_player[0])
376                         player_set_display(g_player[0], PLAYER_DISPLAY_TYPE_OVERLAY, GET_DISPLAY(selected_xid));
377
378                 if (g_external_xid) {
379                         evas_object_del(g_external_xid);
380                         g_external_xid = NULL;
381                 }
382
383                 eom_unset_output_added_cb(eom_notify_cb_output_add);
384                 eom_unset_output_removed_cb(eom_notify_cb_output_remove);
385                 eom_unset_mode_changed_cb(eom_notify_cb_mode_changed);
386                 eom_unset_attribute_changed_cb(eom_notify_cb_attribute_changed);
387
388                 eom_deinit();
389         }
390 }
391 #endif
392 static int app_create(void *data)
393 {
394         appdata *ad = data;
395         Evas_Object *win = NULL;
396 #ifdef _ACTIVATE_EOM_
397         eom_output_mode_e output_mode = EOM_OUTPUT_MODE_NONE;
398 #endif
399         /* use gl backend */
400         elm_config_preferred_engine_set("3d");
401
402         /* create window */
403         win = create_win(PACKAGE);
404         if (win == NULL)
405                 return -1;
406         ad->win = win;
407         g_xid = win;
408         selected_xid = g_xid;
409         create_render_rect_and_bg(ad->win);
410         /* Create evas image object for EVAS surface */
411         g_eo[0] = create_image_object(ad->win);
412         evas_object_image_size_set(g_eo[0], 500, 500);
413         evas_object_image_fill_set(g_eo[0], 0, 0, 500, 500);
414         evas_object_resize(g_eo[0], 500, 500);
415
416         elm_win_activate(win);
417         evas_object_show(win);
418 #ifdef _ACTIVATE_EOM_
419         /* check external device */
420         eom_init();
421         ad->hdmi_output_id = eom_get_output_id("HDMI");
422         if (ad->hdmi_output_id == 0) {
423                 g_print("[eom] error : HDMI output id is NULL.\n");
424                 return 0;
425         }
426
427         g_print("eom_set_output_attribute EOM_OUTPUT_ATTRIBUTE_NORMAL(id:%d)\n", ad->hdmi_output_id);
428         if (eom_set_output_attribute(ad->hdmi_output_id, EOM_OUTPUT_ATTRIBUTE_NORMAL) != EOM_ERROR_NONE) {
429                 g_print("attribute set fail. cannot use external output\n");
430                 eom_deinit();
431         }
432
433         eom_get_output_mode(ad->hdmi_output_id, &output_mode);
434         if (output_mode != EOM_OUTPUT_MODE_NONE) {
435                 g_external_xid = elm_win_add(NULL, "External", ELM_WIN_BASIC);
436                 if (eom_set_output_window(ad->hdmi_output_id, g_external_xid) == EOM_ERROR_NONE) {
437                         create_render_rect_and_bg(g_external_xid);
438                         g_print("[eom] create external window\n");
439                 } else {
440                         evas_object_del(g_external_xid);
441                         g_external_xid = NULL;
442                         g_print("[eom] create external window fail\n");
443                 }
444                 selected_xid = g_external_xid;
445         }
446
447         /* set callback for detecting external device */
448         eom_set_output_added_cb(eom_notify_cb_output_add, ad);
449         eom_set_output_removed_cb(eom_notify_cb_output_remove, ad);
450         eom_set_mode_changed_cb(eom_notify_cb_mode_changed, ad);
451         eom_set_attribute_changed_cb(eom_notify_cb_attribute_changed, ad);
452 #endif
453         return 0;
454 }
455
456 static int app_terminate(void *data)
457 {
458         appdata *ad = data;
459         int i = 0;
460
461         for (i = 0; i < MAX_HANDLE; i++) {
462                 if (g_eo[i]) {
463                         evas_object_del(g_eo[i]);
464                         g_eo[i] = NULL;
465                 }
466         }
467         if (g_xid) {
468                 evas_object_del(g_xid);
469                 g_xid = NULL;
470         }
471 #ifdef _ACTIVATE_EOM_
472         if (g_external_xid) {
473                 evas_object_del(g_external_xid);
474                 g_external_xid = NULL;
475         }
476 #endif
477         ad->win = NULL;
478         selected_xid = NULL;
479 #ifdef _ACTIVATE_EOM_
480         eom_unset_output_added_cb(eom_notify_cb_output_add);
481         eom_unset_output_removed_cb(eom_notify_cb_output_remove);
482         eom_unset_mode_changed_cb(eom_notify_cb_mode_changed);
483         eom_unset_attribute_changed_cb(eom_notify_cb_attribute_changed);
484
485         eom_deinit();
486 #endif
487         return 0;
488 }
489
490 struct appcore_ops ops = {
491         .create = app_create,
492         .terminate = app_terminate,
493 };
494
495 static void prepared_cb(void *user_data)
496 {
497         g_print("[Player_Test] prepared_cb!!!!\n");
498 }
499
500 static void _audio_frame_decoded_cb_ex(player_audio_raw_data_s *audio_raw_frame, void *user_data)
501 {
502         player_audio_raw_data_s *audio_raw = audio_raw_frame;
503
504         if (!audio_raw)
505                 return;
506
507         g_print("[Player_Test] decoded_cb_ex! channel: %d channel_mask: %llu\n", audio_raw->channel, audio_raw->channel_mask);
508
509 #ifdef DUMP_OUTBUF
510         if (audio_raw->channel_mask == 1 && fp_out1)
511                 fwrite((guint8 *)audio_raw->data, 1, audio_raw->size, fp_out1);
512         else if (audio_raw->channel_mask == 2 && fp_out2)
513                 fwrite((guint8 *)audio_raw->data, 1, audio_raw->size, fp_out2);
514 #endif
515 }
516
517 static void progress_down_cb(player_pd_message_type_e type, void *user_data)
518 {
519         g_print("[Player_Test] progress_down_cb!!!! type : %d\n", type);
520 }
521
522 static void buffering_cb(int percent, void *user_data)
523 {
524         g_print("[Player_Test] buffering_cb!!!! percent : %d\n", percent);
525 }
526
527 static void seek_completed_cb(void *user_data)
528 {
529         g_print("[Player_Test] seek_completed_cb!!! \n");
530 }
531
532 static void completed_cb(void *user_data)
533 {
534         g_print("[Player_Test] completed_cb!!!!\n");
535 }
536
537 static void error_cb(int code, void *user_data)
538 {
539         g_print("[Player_Test] error_cb!!!! code : %d\n", code);
540 }
541
542 static void interrupted_cb(player_interrupted_code_e code, void *user_data)
543 {
544         g_print("[Player_Test] interrupted_cb!!!! code : %d\n", code);
545 }
546
547 #if 0
548 static void audio_frame_decoded_cb(unsigned char *data, unsigned int size, void *user_data)
549 {
550         int pos = 0;
551
552         if (data && g_pcm_fd)
553                 fwrite(data, 1, size, g_pcm_fd);
554         player_get_play_position(g_player[0], &pos);
555         g_print("[Player_Test] audio_frame_decoded_cb [size: %d] --- current pos : %d!!!!\n", size, pos);
556 }
557 #endif
558
559 static void subtitle_updated_cb(unsigned long duration, char *text, void *user_data)
560 {
561         g_print("[Player_Test] subtitle_updated_cb!!!! [%ld] %s\n", duration, text);
562 }
563
564 static void video_captured_cb(unsigned char *data, int width, int height, unsigned int size, void *user_data)
565 {
566         g_print("[Player_Test] video_captured_cb!!!! width: %d, height : %d, size : %d \n", width, height, size);
567         _save(data, size);
568 }
569
570 static int _save(unsigned char *src, int length)
571 {
572         /* unlink(CAPTUERD_IMAGE_SAVE_PATH); */
573         FILE *fp;
574         char filename[256] = {0, };
575         static int WRITE_COUNT = 0;
576         /* gchar *filename  = CAPTUERD_IMAGE_SAVE_PATH; */
577         snprintf(filename, 256, "/tmp/IMAGE_client%d", WRITE_COUNT);
578         WRITE_COUNT++;
579         fp = fopen(filename, "w+");
580         if (fp == NULL) {
581                 g_print("file open error!!\n");
582                 return FALSE;
583         } else {
584                 g_print("open success\n");
585                 if (fwrite(src, 1, length, fp) < 1) {
586                         g_print("file write error!!\n");
587                         fclose(fp);
588                         return FALSE;
589                 }
590                 g_print("write success(%s)\n", filename);
591                 fclose(fp);
592         }
593
594         return TRUE;
595 }
596
597 static void reset_display()
598 {
599         int i = 0;
600
601         /* delete evas window, if it is */
602         for (i = 0; i < MAX_HANDLE; i++) {
603                 if (g_eo[i]) {
604                         evas_object_del(g_eo[i]);
605                         g_eo[i] = NULL;
606                 }
607         }
608 }
609
610 static void input_filename(char *filename)
611 {
612         int len = strlen(filename);
613         int i = 0;
614
615         if (len < 0 || len > MAX_STRING_LEN - 1)
616                 return;
617
618         for (i = 0; i < g_handle_num; i++) {
619                 if (g_player[i] != NULL) {
620                         player_unprepare(g_player[i]);
621                         player_destroy(g_player[i]);
622                 }
623                 g_player[i] = 0;
624
625                 if (player_create(&g_player[i]) != PLAYER_ERROR_NONE)
626                         g_print("player create is failed\n");
627         }
628
629         strncpy(g_uri, filename, len);
630         g_uri[len] = '\0';
631
632 #if 0
633         /* ned(APPSRC_TEST) */
634         gchar uri[100];
635         gchar *ext;
636         gsize file_size;
637         GMappedFile *file;
638         GError *error = NULL;
639         guint8 *g_media_mem = NULL;
640
641         ext = filename;
642
643         file = g_mapped_file_new(ext, FALSE, &error);
644         file_size = g_mapped_file_get_length(file);
645         g_media_mem = (guint8 *) g_mapped_file_get_contents(file);
646
647         g_sprintf(uri, "mem://ext=%s,size=%d", ext ? ext : "", file_size);
648         g_print("[uri] = %s\n", uri);
649
650         mm_player_set_attribute(g_player[0], &g_err_name, "profile_uri", uri, strlen(uri), "profile_user_param", g_media_mem, file_size NULL);
651 #else
652         /* player_set_uri(g_player[0], filename); */
653 #endif
654         /* APPSRC_TEST */
655
656         int ret;
657         player_state_e state;
658         for (i = 0; i < g_handle_num; i++) {
659                 ret = player_get_state(g_player[i], &state);
660                 g_print("player_get_state returned [%d]\n", ret);
661                 g_print("1. After player_create() - Current State : %d \n", state);
662         }
663 }
664
665 /* use this API instead of player_set_uri */
666 static void player_set_memory_buffer_test()
667 {
668         GMappedFile *file;
669         gsize file_size;
670         guint8 *g_media_mem = NULL;
671
672         file = g_mapped_file_new(g_uri, FALSE, NULL);
673         file_size = g_mapped_file_get_length(file);
674         g_media_mem = (guint8 *)g_mapped_file_get_contents(file);
675
676         int ret = player_set_memory_buffer(g_player[0], (void *)g_media_mem, file_size);
677         g_print("player_set_memory_buffer ret : %d\n", ret);
678 }
679
680 int video_packet_count = 0;
681
682 static void buffer_need_video_data_cb(unsigned int size, void *user_data)
683 {
684         int real_read_len = 0;
685         char fname[128];
686         char fptsname[128];
687         static guint64 pts = 0L;
688
689         FILE *fp = NULL;
690         guint8 *buff_ptr = NULL;
691         void *src = NULL;
692
693         memset(fname, 0, 128);
694         memset(fptsname, 0, 128);
695
696         video_packet_count++;
697
698         if (video_packet_count > 1000) {
699                 g_print("EOS.\n");
700
701                 /* player_submit_packet(g_player[0], NULL, 0, 0, 1); */
702                 player_push_media_stream(g_player[0], NULL);
703                 g_thread_end = TRUE;
704         }
705
706         /* snprintf(fname, 128, "/opt/storage/usb/test/packet/packet_%d.dat", video_packet_count); */
707         /* snprintf(fptsname, 128, "/opt/storage/usb/test/packet/gstpts_%d.dat", video_packet_count); */
708         snprintf(fname, 128, "/home/developer/test/packet/packet_%d.dat", video_packet_count);
709         snprintf(fptsname, 128, "/home/developer/test/packet/gstpts_%d.dat", video_packet_count);
710
711         fp = fopen(fptsname, "rb");
712         if (fp) {
713                 int pts_len = 0;
714                 pts_len = fread(&pts, 1, sizeof(guint64), fp);
715                 if (pts_len != sizeof(guint64))
716                         g_print("Warning, pts value can be wrong.\n");
717                 fclose(fp);
718                 fp = NULL;
719         }
720
721         fp = fopen(fname, "rb");
722         if (fp) {
723                 buff_ptr = (guint8 *)g_malloc0(1048576);
724                 if (!buff_ptr) {
725                         g_print("no free space\n");
726                         fclose(fp);
727                         fp = NULL;
728                         return;
729                 }
730                 real_read_len = fread(buff_ptr, 1, size, fp);
731                 fclose(fp);
732                 fp = NULL;
733         }
734         g_print("video need data - data size : %d, pts : %" G_GUINT64_FORMAT "\n", real_read_len, pts);
735 #if 0
736         player_submit_packet(g_player[0], buff_ptr, real_read_len, (pts / 1000000), 1);
737 #else
738         /* create media packet */
739         if (g_video_pkt) {
740                 media_packet_destroy(g_video_pkt);
741                 g_video_pkt = NULL;
742         }
743
744         media_packet_create_alloc(g_video_fmt, NULL, NULL, &g_video_pkt);
745
746         g_print("packet = %p, src = %p\n", g_video_pkt, src);
747
748         if (media_packet_get_buffer_data_ptr(g_video_pkt, &src) != MEDIA_PACKET_ERROR_NONE)
749                 goto EXIT;
750
751         if (media_packet_set_pts(g_video_pkt, (uint64_t)pts) != MEDIA_PACKET_ERROR_NONE)
752                 goto EXIT;
753
754         if (media_packet_set_buffer_size(g_video_pkt, (uint64_t)real_read_len) != MEDIA_PACKET_ERROR_NONE)
755                 goto EXIT;
756
757         memcpy(src, buff_ptr, real_read_len);
758
759         /* then, push it  */
760         player_push_media_stream(g_player[0], g_video_pkt);
761 #endif
762
763 EXIT:
764         if (buff_ptr) {
765                 g_free(buff_ptr);
766                 buff_ptr = NULL;
767         }
768 }
769
770 int audio_packet_count = 0;
771 static void buffer_need_audio_data_cb(unsigned int size, void *user_data)
772 {
773         int real_read_len = 0;
774         char fname[128];
775         FILE *fp = NULL;
776         guint8 *buff_ptr = NULL;
777         void *src = NULL;
778
779         memset(fname, 0, 128);
780         audio_packet_count++;
781
782         if (audio_packet_count > 1000) {
783                 g_print("EOS.\n");
784                 /* player_submit_packet(g_player[0], NULL, 0, 0, 0); */
785                 player_push_media_stream(g_player[0], NULL);
786                 g_thread_end = TRUE;
787         }
788
789         /* snprintf(fname, 128, "/opt/storage/usb/test/audio_packet/packet_%d.dat", audio_packet_count); */
790         snprintf(fname, 128, "/home/developer/test/audio_packet/packet_%d.dat", audio_packet_count);
791
792         static guint64 audio_pts = 0;
793         guint64 audio_dur = 21333333;
794
795         fp = fopen(fname, "rb");
796         if (fp) {
797                 buff_ptr = (guint8 *)g_malloc0(1048576);
798                 if (!buff_ptr) {
799                         g_print("no free space\n");
800                         fclose(fp);
801                         fp = NULL;
802                         return;
803                 }
804                 real_read_len = fread(buff_ptr, 1, size, fp);
805                 fclose(fp);
806                 fp = NULL;
807
808                 g_print("\t audio need data - data size : %d, pts : %" G_GUINT64_FORMAT "\n", real_read_len, audio_pts);
809         }
810 #if 0
811         player_submit_packet(g_player[0], buff_ptr, real_read_len, (audio_pts / 1000000), 0);
812 #else
813         /* create media packet */
814         if (g_audio_pkt) {
815                 media_packet_destroy(g_audio_pkt);
816                 g_audio_pkt = NULL;
817         }
818         media_packet_create_alloc(g_audio_fmt, NULL, NULL, &g_audio_pkt);
819
820         g_print("packet = %p, src = %p\n", g_audio_pkt, src);
821
822         if (media_packet_get_buffer_data_ptr(g_audio_pkt, &src) != MEDIA_PACKET_ERROR_NONE)
823                 goto EXIT;
824
825         if (media_packet_set_pts(g_audio_pkt, (uint64_t)audio_pts) != MEDIA_PACKET_ERROR_NONE)
826                 goto EXIT;
827
828         if (media_packet_set_buffer_size(g_audio_pkt, (uint64_t)real_read_len) != MEDIA_PACKET_ERROR_NONE)
829                 goto EXIT;
830
831         memcpy(src, buff_ptr, real_read_len);
832
833         /* then, push it  */
834         player_push_media_stream(g_player[0], g_audio_pkt);
835 #endif
836
837         audio_pts += audio_dur;
838 EXIT:
839         if (buff_ptr) {
840                 g_free(buff_ptr);
841                 buff_ptr = NULL;
842         }
843 }
844
845 static void set_content_info(bool is_push_mode)
846 {
847         /* testcode for es buff src case, please input url as es_buff://123 or es_buff://push_mode */
848         /* unsigned char codec_data[45] =  {0x0,0x0,0x1,0xb0,0x1,0x0,0x0,0x1,0xb5,0x89,0x13,0x0,0x0,0x1,0x0,0x0,0x0,0x1,0x20,0x0,0xc4,0x8d,0x88,0x5d,0xad,0x14,0x4,0x22,0x14,0x43,0x0,0x0,0x1,0xb2,0x4c,0x61,0x76,0x63,0x35,0x31,0x2e,0x34,0x30,0x2e,0x34}; */
849
850         /* create media format */
851         media_format_create(&g_audio_fmt);
852         media_format_create(&g_video_fmt);
853
854         /* Video */
855         /* configure media format  for video and set to player */
856         media_format_set_video_mime(g_video_fmt, MEDIA_FORMAT_MPEG4_SP);
857         media_format_set_video_width(g_video_fmt, 640);
858         media_format_set_video_height(g_video_fmt, 272);
859         /* player_set_media_stream_info(g_player[0], PLAYER_STREAM_TYPE_VIDEO, g_video_fmt); */
860
861         /* Audio--aac--StarWars.mp4 */
862         media_format_set_audio_mime(g_audio_fmt, MEDIA_FORMAT_AAC);
863         media_format_set_audio_channel(g_audio_fmt, 2);
864         media_format_set_audio_samplerate(g_audio_fmt, 48000);
865         /* player_set_media_stream_info(g_player[0], PLAYER_STREAM_TYPE_AUDIO, g_audio_fmt); */
866 #if 0
867         /* video_info->mime = g_strdup("video/mpeg"); */ /* CODEC_ID_MPEG4VIDEO */
868         video_info->width = 640;
869         video_info->height = 272;
870         video_info->version = 4;
871         video_info->framerate_den = 100;
872         video_info->framerate_num = 2997;
873
874         video_info->extradata_size = 45;
875         video_info->codec_extradata = codec_data;
876         player_set_video_stream_info(g_player[0], video_info);
877
878         /* audio--aac--StarWars.mp4 */
879         /* audio_info->mime = g_strdup("audio/mpeg"); */
880         /* audio_info->version = 2; */
881         /* audio_info->user_info = 0; */ /* raw */
882 #endif
883
884 #ifdef _ES_PULL_
885         if (!is_push_mode) {
886                 player_set_buffer_need_video_data_cb(g_player[0], buffer_need_video_data_cb, (void *)g_player[0]);
887                 player_set_buffer_need_audio_data_cb(g_player[0], buffer_need_audio_data_cb, (void *)g_player[0]);
888         }
889 #endif
890 }
891
892 static void feed_video_data_thread_func(void *data)
893 {
894         while (!g_thread_end) {
895                 buffer_need_video_data_cb(1048576, NULL);
896                 buffer_need_audio_data_cb(1048576, NULL);
897         }
898 }
899
900 static void _player_prepare(bool async)
901 {
902         int ret = FALSE;
903         int slen = strlen(g_subtitle_uri);
904
905         if (slen > 0 && slen < MAX_STRING_LEN) {
906                 g_print("0. set subtile path() (size : %d) - %s  \n", slen, g_subtitle_uri);
907                 player_set_subtitle_path(g_player[0], g_subtitle_uri);
908                 player_set_subtitle_updated_cb(g_player[0], subtitle_updated_cb, (void *)g_player[0]);
909         }
910         if (g_current_surface_type == PLAYER_DISPLAY_TYPE_OVERLAY) {
911                 player_set_display(g_player[0], g_current_surface_type, GET_DISPLAY(selected_xid));
912                 player_set_buffering_cb(g_player[0], buffering_cb, (void *)g_player[0]);
913                 player_set_completed_cb(g_player[0], completed_cb, (void *)g_player[0]);
914                 player_set_interrupted_cb(g_player[0], interrupted_cb, (void *)g_player[0]);
915                 player_set_error_cb(g_player[0], error_cb, (void *)g_player[0]);
916                 if (g_memory_playback)
917                         player_set_memory_buffer_test();
918                 else
919                         player_set_uri(g_player[0], g_uri);
920         } else {
921                 int i = 0;
922                 for (i = 0; i < g_handle_num; i++) {
923                         player_set_display(g_player[i], g_current_surface_type, g_eo[i]);
924                         player_set_buffering_cb(g_player[i], buffering_cb, (void *)g_player[i]);
925                         player_set_completed_cb(g_player[i], completed_cb, (void *)g_player[i]);
926                         player_set_interrupted_cb(g_player[i], interrupted_cb, (void *)g_player[i]);
927                         player_set_error_cb(g_player[i], error_cb, (void *)g_player[i]);
928                         if (g_memory_playback)
929                                 player_set_memory_buffer_test();
930                         else
931                                 player_set_uri(g_player[i], g_uri);
932                 }
933         }
934
935         if (strstr(g_uri, "es_buff://")) {
936                 is_es_push_mode = FALSE;
937                 video_packet_count = 0;
938                 audio_packet_count = 0;
939
940                 if (strstr(g_uri, "es_buff://push_mode")) {
941                         set_content_info(TRUE);
942                         async = TRUE;
943                         is_es_push_mode = TRUE;
944 #ifdef _ES_PULL_
945                 } else {
946                         set_content_info(FALSE);
947 #endif
948                 }
949         }
950
951         if (g_current_surface_type == PLAYER_DISPLAY_TYPE_OVERLAY) {
952                 if (async)
953                         ret = player_prepare_async(g_player[0], prepared_cb, (void *)g_player[0]);
954                 else
955                         ret = player_prepare(g_player[0]);
956         } else {
957                 int i = 0;
958                 for (i = 0; i < g_handle_num; i++) {
959                         if (async)
960                                 ret = player_prepare_async(g_player[i], prepared_cb, (void *)g_player[i]);
961                         else
962                                 ret = player_prepare(g_player[i]);
963                 }
964         }
965
966         if (ret != PLAYER_ERROR_NONE)
967                 g_print("prepare is failed (errno = %d) \n", ret);
968
969         player_state_e state;
970         if (g_current_surface_type == PLAYER_DISPLAY_TYPE_OVERLAY) {
971                 ret = player_get_state(g_player[0], &state);
972                 g_print("After player_prepare() - Current State : %d \n", state);
973         } else {
974                 int i = 0;
975                 for (i = 0; i < g_handle_num; i++) {
976                         ret = player_get_state(g_player[i], &state);
977                         g_print("After player_prepare() - Current State : %d \n", state);
978                 }
979         }
980
981         if (is_es_push_mode)
982                 pthread_create(&g_feed_video_thread_id, NULL, (void *)feed_video_data_thread_func, NULL);
983
984 }
985
986 static void _player_unprepare()
987 {
988         int ret = FALSE;
989         int i = 0;
990         if (g_current_surface_type == PLAYER_DISPLAY_TYPE_OVERLAY) {
991                 ret = player_unprepare(g_player[0]);
992                 if (ret != PLAYER_ERROR_NONE)
993                         g_print("unprepare is failed (errno = %d) \n", ret);
994
995                 ret = player_unset_subtitle_updated_cb(g_player[0]);
996                 g_print("player_unset_subtitle_updated_cb ret %d\n", ret);
997
998                 ret = player_unset_buffering_cb(g_player[0]);
999                 g_print("player_unset_buffering_cb ret %d\n", ret);
1000
1001                 ret = player_unset_completed_cb(g_player[0]);
1002                 g_print("player_unset_completed_cb ret %d\n", ret);
1003
1004                 ret = player_unset_interrupted_cb(g_player[0]);
1005                 g_print("player_unset_interrupted_cb ret %d\n", ret);
1006
1007                 ret = player_unset_error_cb(g_player[0]);
1008                 g_print("player_unset_error_cb ret %d\n", ret);
1009         } else {
1010                 for (i = 0; i < g_handle_num; i++) {
1011                         if (g_player[i] != NULL) {
1012                                 ret = player_unprepare(g_player[i]);
1013                                 if (ret != PLAYER_ERROR_NONE)
1014                                         g_print("unprepare is failed (errno = %d) \n", ret);
1015
1016                                 ret = player_unset_subtitle_updated_cb(g_player[i]);
1017                                 g_print("player_unset_subtitle_updated_cb [%d] ret %d\n", i, ret);
1018
1019                                 ret = player_unset_buffering_cb(g_player[i]);
1020                                 g_print("player_unset_buffering_cb [%d] ret %d\n", i, ret);
1021
1022                                 ret = player_unset_completed_cb(g_player[i]);
1023                                 g_print("player_unset_completed_cb [%d] ret %d\n", i, ret);
1024
1025                                 ret = player_unset_interrupted_cb(g_player[i]);
1026                                 g_print("player_unset_interrupted_cb [%d] ret %d\n", i, ret);
1027
1028                                 ret = player_unset_error_cb(g_player[i]);
1029                                 g_print("player_unset_error_cb [%d] ret %d\n", i, ret);
1030                         }
1031                 }
1032         }
1033         /* attention! surface(evas) -> unprepare -> surface(evas) : evas object will disappear. */
1034         reset_display();
1035         memset(g_subtitle_uri, 0, sizeof(g_subtitle_uri));
1036         player_state_e state;
1037         if (g_current_surface_type == PLAYER_DISPLAY_TYPE_OVERLAY) {
1038                 ret = player_get_state(g_player[0], &state);
1039                 g_print(" After player_unprepare() - Current State : %d \n", state);
1040         } else {
1041                 for (i = 0; i < g_handle_num; i++) {
1042                         ret = player_get_state(g_player[i], &state);
1043                         g_print(" After player_unprepare() - Current State : %d \n", state);
1044                 }
1045         }
1046 }
1047
1048 static void _player_destroy()
1049 {
1050         int i = 0;
1051
1052         if (g_current_surface_type == PLAYER_DISPLAY_TYPE_OVERLAY) {
1053                 player_unprepare(g_player[0]);
1054                 for (i = 0; i < g_handle_num; i++) {
1055                         player_destroy(g_player[i]);
1056                         g_player[i] = 0;
1057                 }
1058         } else {
1059                 for (i = 0; i < g_handle_num; i++) {
1060                         if (g_player[i] != NULL) {
1061                                 player_unprepare(g_player[i]);
1062                                 player_destroy(g_player[i]);
1063                                 g_player[i] = 0;
1064                         }
1065                 }
1066         }
1067
1068         if (g_stream_info_h) {
1069                 sound_manager_destroy_stream_information(g_stream_info_h);
1070                 g_stream_info_h = NULL;
1071         }
1072
1073         if (g_video_pkt)
1074                 media_packet_destroy(g_video_pkt);
1075
1076         if (g_audio_pkt)
1077                 media_packet_destroy(g_audio_pkt);
1078
1079 #if DUMP_OUTBUF
1080         if (fp_out1)
1081                 fclose(fp_out1);
1082         if (fp_out2)
1083                 fclose(fp_out2);
1084 #endif
1085
1086 }
1087
1088 static void _player_play()
1089 {
1090         int bRet = FALSE;
1091         int i = 0;
1092         if (g_current_surface_type == PLAYER_DISPLAY_TYPE_OVERLAY) {
1093 #ifdef _ACTIVATE_EOM_
1094                 /* for checking external display.... */
1095                 player_set_display(g_player[0], g_current_surface_type, GET_DISPLAY(selected_xid));
1096 #endif
1097                 bRet = player_start(g_player[0]);
1098                 g_print("player_start returned [%d]", bRet);
1099         } else {
1100                 for (i = 0; i < g_handle_num; i++) {
1101                         bRet = player_start(g_player[i]);
1102                         g_print("player_start returned [%d]", bRet);
1103                 }
1104         }
1105 }
1106
1107 static void _player_stop()
1108 {
1109         int bRet = FALSE;
1110         int i = 0;
1111         if (g_current_surface_type == PLAYER_DISPLAY_TYPE_OVERLAY) {
1112                 bRet = player_stop(g_player[0]);
1113                 g_print("player_stop returned [%d]", bRet);
1114         } else {
1115                 for (i = 0; i < g_handle_num; i++) {
1116                         bRet = player_stop(g_player[i]);
1117                         g_print("player_stop returned [%d]", bRet);
1118                 }
1119         }
1120
1121         g_thread_end = TRUE;
1122         if (g_feed_video_thread_id) {
1123                 pthread_join(g_feed_video_thread_id, NULL);
1124                 g_feed_video_thread_id = 0;
1125         }
1126
1127 }
1128
1129 static void _player_resume()
1130 {
1131         int bRet = FALSE;
1132         int i = 0;
1133         if (g_current_surface_type == PLAYER_DISPLAY_TYPE_OVERLAY) {
1134 #ifdef _ACTIVATE_EOM_
1135                 /* for checking external display.... */
1136                 player_set_display(g_player[0], PLAYER_DISPLAY_TYPE_OVERLAY, GET_DISPLAY(selected_xid));
1137 #endif
1138                 bRet = player_start(g_player[0]);
1139                 g_print("player_start returned [%d]", bRet);
1140         } else {
1141                 for (i = 0; i < g_handle_num; i++) {
1142                         bRet = player_start(g_player[i]);
1143                         g_print("player_start returned [%d]", bRet);
1144                 }
1145         }
1146 }
1147
1148 static void _player_pause()
1149 {
1150         int bRet = FALSE;
1151         int i = 0;
1152         if (g_current_surface_type == PLAYER_DISPLAY_TYPE_OVERLAY) {
1153                 bRet = player_pause(g_player[0]);
1154                 g_print("player_pause returned [%d]", bRet);
1155         } else {
1156                 for (i = 0; i < g_handle_num; i++) {
1157                         bRet = player_pause(g_player[i]);
1158                         g_print("player_pause returned [%d]", bRet);
1159                 }
1160         }
1161 }
1162
1163 static void _player_state()
1164 {
1165         player_state_e state;
1166         player_get_state(g_player[0], &state);
1167         g_print("                                                            ==> [Player_Test] Current Player State : %d\n", state);
1168 }
1169
1170 static void _player_set_progressive_download()
1171 {
1172         player_set_progressive_download_path(g_player[0], "/home/owner/test.pd");
1173         player_set_progressive_download_message_cb(g_player[0], progress_down_cb, (void *)g_player[0]);
1174 }
1175
1176 static void _player_get_progressive_download_status()
1177 {
1178         int bRet;
1179         unsigned long curr, total;
1180         bRet = player_get_progressive_download_status(g_player[0], &curr, &total);
1181         g_print("player_get_progressive_download_status return[%d]           ==> [Player_Test] progressive download status : %lu/%lu\n", bRet, curr, total);
1182 }
1183
1184 static void set_volume(float volume)
1185 {
1186         if (player_set_volume(g_player[0], volume, volume) != PLAYER_ERROR_NONE)
1187                 g_print("failed to set volume\n");
1188 }
1189
1190 static void get_volume(float *left, float *right)
1191 {
1192         player_get_volume(g_player[0], left, right);
1193         g_print("                                                            ==> [Player_Test] volume - left : %f, right : %f\n", *left, *right);
1194 }
1195
1196 static void set_mute(bool mute)
1197 {
1198         if (player_set_mute(g_player[0], mute) != PLAYER_ERROR_NONE)
1199                 g_print("failed to set_mute\n");
1200 }
1201
1202 static void get_mute(bool * mute)
1203 {
1204         player_is_muted(g_player[0], mute);
1205         g_print("                                                            ==> [Player_Test] mute = %d\n", *mute);
1206 }
1207
1208 static void set_sound_type(sound_type_e type)
1209 {
1210         if (player_set_sound_type(g_player[0], type) != PLAYER_ERROR_NONE)
1211                 g_print("failed to set sound type(%d)\n", type);
1212         else
1213                 g_print("set sound type(%d) success", type);
1214 }
1215
1216 void focus_callback(sound_stream_info_h stream_info, sound_stream_focus_change_reason_e reason, const char *extra_info, void *user_data)
1217 {
1218         g_print("FOCUS callback is called, reason(%d), extra_info(%s), userdata(%p)", reason, extra_info, user_data);
1219         return;
1220 }
1221
1222 static void set_sound_stream_info(int type)
1223 {
1224         sound_device_list_h device_list = NULL;
1225         int ret = SOUND_MANAGER_ERROR_NONE;
1226
1227         if (g_stream_info_h) {
1228                 g_print("stream information is already set, please destory handle and try again\n");
1229                 return;
1230         }
1231         if (sound_manager_create_stream_information(type, focus_callback, g_player[0], &g_stream_info_h)) {
1232                 g_print("failed to create stream_information()\n");
1233                 return;
1234         }
1235         /* In case of MEDIA_EXTERNAL_ONLY, we need to set external device manually */
1236         if (type == (int)SOUND_STREAM_TYPE_MEDIA_EXTERNAL_ONLY) {
1237                 sound_device_h device = NULL;
1238                 sound_device_type_e device_type;
1239
1240                 if ((ret = sound_manager_get_current_device_list(SOUND_DEVICE_ALL_MASK, &device_list))) {
1241                         g_print("failed to sound_manager_get_current_device_list(), ret(0x%x)\n", ret);
1242                         return;
1243                 }
1244                 while (!(ret = sound_manager_get_next_device(device_list, &device))) {
1245                         if ((ret = sound_manager_get_device_type (device, &device_type))) {
1246                                 g_print("failed to sound_manager_get_device_type(), ret(0x%x)\n", ret);
1247                                 goto END;
1248                         }
1249                         if (device_type == SOUND_DEVICE_BLUETOOTH || device_type == SOUND_DEVICE_USB_AUDIO) {
1250                                 if ((ret = sound_manager_add_device_for_stream_routing (g_stream_info_h, device))) {
1251                                         g_print("failed to sound_manager_add_device_for_stream_routing(), ret(0x%x)\n", ret);
1252                                         goto END;
1253                                 }
1254                                 if ((ret = sound_manager_apply_stream_routing (g_stream_info_h))) {
1255                                         g_print("failed to sound_manager_apply_stream_routing(), ret(0x%x)\n", ret);
1256                                         goto END;
1257                                 }
1258                                 break;
1259                         }
1260                 }
1261                 if (ret != SOUND_MANAGER_ERROR_NONE) {
1262                         g_print("failed to sound_manager_get_next_device(), ret(0x%x)\n", ret);
1263                         goto END;
1264                 }
1265         }
1266
1267         if (player_set_audio_policy_info(g_player[0], g_stream_info_h) != PLAYER_ERROR_NONE)
1268                 g_print("failed to set sound stream information(%p)\n", g_stream_info_h);
1269         else
1270                 g_print("set stream information(%p) success", g_stream_info_h);
1271
1272 END:
1273         if (device_list)
1274                 sound_manager_free_device_list(device_list);
1275         return;
1276 }
1277
1278 static void get_position()
1279 {
1280         int position = 0;
1281         int ret;
1282         ret = player_get_play_position(g_player[0], &position);
1283         g_print("                                                            ==> [Player_Test] player_get_play_position()%d return : %d\n", ret, position);
1284 }
1285
1286 static void set_position(int position)
1287 {
1288         if (player_set_play_position(g_player[0], position, TRUE, seek_completed_cb, g_player[0]) != PLAYER_ERROR_NONE)
1289                 g_print("failed to set position\n");
1290 }
1291
1292 static void set_playback_rate(float rate, bool streaming)
1293 {
1294         if (streaming) {
1295                 if (player_set_streaming_playback_rate(g_player[0], rate) != PLAYER_ERROR_NONE)
1296                         g_print("failed to set streaming playback rate\n");
1297         } else {
1298                 if (player_set_playback_rate(g_player[0], rate) != PLAYER_ERROR_NONE)
1299                         g_print("failed to set playback rate\n");
1300         }
1301 }
1302
1303 static void get_duration()
1304 {
1305         int duration = 0;
1306         int ret;
1307         ret = player_get_duration(g_player[0], &duration);
1308         g_print("                                                            ==> [Player_Test] player_get_duration() return : %d\n", ret);
1309         g_print("                                                            ==> [Player_Test] Duration: [%d ] msec\n", duration);
1310 }
1311
1312 static void audio_frame_decoded_cb_ex()
1313 {
1314         int ret;
1315
1316 #if DUMP_OUTBUF
1317         fp_out1 = fopen("/home/owner/content/out1.pcm", "wb");
1318         fp_out2 = fopen("/home/owner/content/out2.pcm", "wb");
1319         if (!fp_out1 || !fp_out2) {
1320                 g_print("File open error\n");
1321                 return;
1322         }
1323 #endif
1324
1325         ret = player_set_pcm_extraction_mode(g_player[0], false, _audio_frame_decoded_cb_ex, &ret);
1326         g_print("                                                            ==> [Player_Test] player_set_audio_frame_decoded_cb_ex return: %d\n", ret);
1327 }
1328
1329 static void set_pcm_spec()
1330 {
1331         int ret = 0;
1332
1333         ret = player_set_pcm_spec(g_player[0], "F32LE", 44100, 2);
1334         g_print("[Player_Test] set_pcm_spec return: %d\n", ret);
1335 }
1336
1337 static void get_stream_info()
1338 {
1339         int w = 0;
1340         int h = 0;
1341
1342         char *value = NULL;
1343         player_get_content_info(g_player[0], PLAYER_CONTENT_INFO_ALBUM, &value);
1344         g_print("                                                            ==> [Player_Test] PLAYER_CONTENT_INFO_ALBUM: [%s ] \n", value);
1345         player_get_content_info(g_player[0], PLAYER_CONTENT_INFO_ARTIST, &value);
1346         g_print("                                                            ==> [Player_Test] PLAYER_CONTENT_INFO_ARTIST: [%s ] \n", value);
1347         player_get_content_info(g_player[0], PLAYER_CONTENT_INFO_AUTHOR, &value);
1348         g_print("                                                            ==> [Player_Test] PLAYER_CONTENT_INFO_AUTHOR: [%s ] \n", value);
1349         player_get_content_info(g_player[0], PLAYER_CONTENT_INFO_GENRE, &value);
1350         g_print("                                                            ==> [Player_Test] PLAYER_CONTENT_INFO_GENRE: [%s ] \n", value);
1351         player_get_content_info(g_player[0], PLAYER_CONTENT_INFO_TITLE, &value);
1352         g_print("                                                            ==> [Player_Test] PLAYER_CONTENT_INFO_TITLE: [%s ] \n", value);
1353         void *album;
1354         int size;
1355         player_get_album_art(g_player[0], &album, &size);
1356         g_print("                                                            ==> [Player_Test] Album art : [ data : %p, size : %d ]\n", (unsigned int *)album, size);
1357         _save(album, size);
1358         if (value != NULL) {
1359                 free(value);
1360                 value = NULL;
1361         }
1362
1363         int sample_rate;
1364         int channel;
1365         int bit_rate;
1366         int fps, v_bit_rate;
1367         player_get_audio_stream_info(g_player[0], &sample_rate, &channel, &bit_rate);
1368         g_print("                                                            ==> [Player_Test] Sample Rate: [%d ] , Channel: [%d ] , Bit Rate: [%d ] \n", sample_rate, channel, bit_rate);
1369
1370         player_get_video_stream_info(g_player[0], &fps, &v_bit_rate);
1371         g_print("                                                            ==> [Player_Test] fps: [%d ] , Bit Rate: [%d ] \n", fps, v_bit_rate);
1372
1373         char *audio_codec = NULL;
1374         char *video_codec = NULL;
1375         player_get_codec_info(g_player[0], &audio_codec, &video_codec);
1376         if (audio_codec != NULL) {
1377                 g_print("                                                            ==> [Player_Test] Audio Codec: [%s ] \n", audio_codec);
1378                 free(audio_codec);
1379                 audio_codec = NULL;
1380         }
1381         if (video_codec != NULL) {
1382                 g_print("                                                            ==> [Player_Test] Video Codec: [%s ] \n", video_codec);
1383                 free(video_codec);
1384                 video_codec = NULL;
1385         }
1386         player_get_video_size(g_player[0], &w, &h);
1387         g_print("                                                            ==> [Player_Test] Width: [%d ] , Height: [%d ] \n", w, h);
1388 }
1389
1390 static void set_looping(bool looping)
1391 {
1392         if (g_current_surface_type == PLAYER_DISPLAY_TYPE_OVERLAY) {
1393                 if (player_set_looping(g_player[0], looping) != PLAYER_ERROR_NONE)
1394                         g_print("failed to set_looping\n");
1395         } else {
1396                 int i = 0;
1397                 for (i = 0; i < g_handle_num; i++) {
1398                         if (player_set_looping(g_player[i], looping) != PLAYER_ERROR_NONE)
1399                                 g_print("failed to set_looping\n");
1400                 }
1401         }
1402 }
1403
1404 static void get_looping(bool *looping)
1405 {
1406         player_is_looping(g_player[0], looping);
1407         g_print("                                                            ==> [Player_Test] looping = %d\n", *looping);
1408 }
1409
1410 static void change_surface(int option)
1411 {
1412         player_display_type_e surface_type = 0;
1413         int ret = PLAYER_ERROR_NONE;
1414 #ifdef _ACTIVATE_EOM_
1415         int hdmi_output_id;
1416         eom_output_mode_e output_mode;
1417 #endif
1418         switch (option) {
1419         case 0:
1420                 /* X surface */
1421                 surface_type = PLAYER_DISPLAY_TYPE_OVERLAY;
1422                 g_print("change surface type to X\n");
1423                 break;
1424 #ifdef TIZEN_MOBILE
1425         case 1:
1426                 /* EVAS surface */
1427                 surface_type = PLAYER_DISPLAY_TYPE_EVAS;
1428                 g_print("change surface type to EVAS\n");
1429                 break;
1430 #endif
1431         case 2:
1432                 g_print("change surface type to NONE\n");
1433                 player_set_display(g_player[0], PLAYER_DISPLAY_TYPE_NONE, NULL);
1434                 break;
1435         default:
1436                 g_print("invalid surface type\n");
1437                 return;
1438         }
1439
1440         if (surface_type == g_current_surface_type) {
1441                 g_print("same with the previous surface type(%d)\n", g_current_surface_type);
1442                 return;
1443         } else {
1444                 player_state_e player_state = PLAYER_STATE_NONE;
1445                 ret = player_get_state(g_player[0], &player_state);
1446                 if (ret)
1447                         g_print("failed to player_get_state(), ret(0x%x)\n", ret);
1448
1449                 reset_display();
1450
1451                 if (surface_type == PLAYER_DISPLAY_TYPE_OVERLAY) {
1452 #ifdef _ACTIVATE_EOM_
1453                         hdmi_output_id = eom_get_output_id("HDMI");
1454                         if (hdmi_output_id == 0)
1455                                 g_print("[eom] error : HDMI output id is NULL.\n");
1456
1457                         eom_get_output_mode(hdmi_output_id, &output_mode);
1458                         if (output_mode == EOM_OUTPUT_MODE_NONE) {
1459 #endif
1460                                 if (!g_xid) {
1461                                         g_xid = create_win(PACKAGE);
1462                                         if (g_xid == NULL)
1463                                                 return;
1464                                         g_print("create xid %p\n", g_xid);
1465                                         create_render_rect_and_bg(g_xid);
1466                                         elm_win_activate(g_xid);
1467                                         evas_object_show(g_xid);
1468                                         g_xid = selected_xid;
1469                                 }
1470 #ifdef _ACTIVATE_EOM_
1471                         } else {
1472                                 /* for external */
1473                         }
1474 #endif
1475                         ret = player_set_display(g_player[0], surface_type, GET_DISPLAY(selected_xid));
1476                 } else {
1477                         if (!g_xid) {
1478                                 g_xid = create_win(PACKAGE);
1479                                 if (g_xid == NULL)
1480                                         return;
1481                                 g_print("create xid %p\n", g_xid);
1482                                 create_render_rect_and_bg(g_xid);
1483                                 elm_win_activate(g_xid);
1484                                 evas_object_show(g_xid);
1485                         }
1486                         int i = 0;
1487                         for (i = 0; i < g_handle_num; i++) {
1488                                 /* Create evas image object for EVAS surface */
1489                                 if (!g_eo[i]) {
1490                                         g_eo[i] = create_image_object(g_xid);
1491                                         g_print("create eo[%d] %p\n", i, g_eo[i]);
1492                                         evas_object_image_size_set(g_eo[i], 500, 500);
1493                                         evas_object_image_fill_set(g_eo[i], 0, 0, 500, 500);
1494                                         evas_object_resize(g_eo[i], 500, 500);
1495                                         evas_object_move(g_eo[i], i * 20, i * 20);
1496                                 }
1497                                 ret = player_set_display(g_player[i], surface_type, g_eo[i]);
1498
1499                         }
1500                 }
1501                 if (ret) {
1502                         g_print("failed to set display, surface_type(%d)\n", surface_type);
1503                         return;
1504                 }
1505                 g_current_surface_type = surface_type;
1506         }
1507         return;
1508 }
1509
1510 static void set_display_mode(int mode)
1511 {
1512         if (player_set_display_mode(g_player[0], mode) != PLAYER_ERROR_NONE)
1513                 g_print("failed to player_set_display_mode\n");
1514 }
1515
1516 static void get_display_mode()
1517 {
1518         player_display_mode_e mode;
1519         player_get_display_mode(g_player[0], &mode);
1520         g_print("                                                            ==> [Player_Test] Display mode: [%d ] \n", mode);
1521 }
1522
1523 static void set_display_rotation(int rotation)
1524 {
1525         if (player_set_display_rotation(g_player[0], rotation) != PLAYER_ERROR_NONE)
1526                 g_print("failed to set_display_rotation\n");
1527 }
1528
1529 static void get_display_rotation()
1530 {
1531         player_display_rotation_e rotation = 0;
1532         player_get_display_rotation(g_player[0], &rotation);
1533         g_print("                                                            ==> [Player_Test] X11 Display rotation: [%d ] \n", rotation);
1534 }
1535
1536 static void set_display_visible(bool visible)
1537 {
1538         if (player_set_display_visible(g_player[0], visible) != PLAYER_ERROR_NONE)
1539                 g_print("failed to player_set_x11_display_visible\n");
1540 }
1541
1542 static void get_display_visible(bool *visible)
1543 {
1544         player_is_display_visible(g_player[0], visible);
1545         g_print("                                                            ==> [Player_Test] X11 Display Visible = %d\n", *visible);
1546 }
1547
1548 static void set_display_dst_roi(int x, int y, int w, int h)
1549 {
1550 #if 0
1551         if (player_set_x11_display_dst_roi(g_player[0], x, y, w, h) != PLAYER_ERROR_NONE)
1552                 g_print("failed to player_set_x11_display_dst_roi\n");
1553         else
1554                 g_print("                                                            ==> [Player_Test] set X11 Display DST ROI (x:%d, y:%d, w:%d, h:%d)\n", x, y, w, h);
1555 #endif
1556 }
1557
1558 static void get_display_dst_roi()
1559 {
1560 #if 0
1561         int x = 0;
1562         int y = 0;
1563         int w = 0;
1564         int h = 0;
1565
1566         if (player_get_x11_display_dst_roi(g_player[0], &x, &y, &w, &h) != PLAYER_ERROR_NONE)
1567                 g_print("failed to player_get_x11_display_dst_roi\n");
1568         else
1569                 g_print("                                                            ==> [Player_Test] got X11 Display DST ROI (x:%d, y:%d, w:%d, h:%d)\n", x, y, w, h);
1570 #endif
1571 }
1572
1573 static void set_display_roi_mode(int mode)
1574 {
1575 #if 0
1576         if (player_set_x11_display_roi_mode(g_player[0], (player_display_roi_mode_e) mode) != PLAYER_ERROR_NONE)
1577                 g_print("failed to player_set_x11_display_roi_mode\n");
1578         else
1579                 g_print("                                                            ==> [Player_Test] set X11 Display ROI mode (%d)\n", mode);
1580 #endif
1581 }
1582
1583 static void get_display_roi_mode()
1584 {
1585 #if 0
1586         player_display_roi_mode_e mode;
1587         if (player_get_x11_display_roi_mode(g_player[0], &mode) != PLAYER_ERROR_NONE)
1588                 g_print("failed to player_get_x11_display_roi_mode\n");
1589         else
1590                 g_print("                                                            ==> [Player_Test] got X11 Display ROI mode (%d)\n", mode);
1591 #endif
1592 }
1593
1594 static void set_display_src_crop(int x, int y, int w, int h)
1595 {
1596 #if 0
1597         if (player_set_x11_display_src_crop(g_player[0], x, y, w, h) != PLAYER_ERROR_NONE)
1598                 g_print("failed to player_set_x11_display_src_crop\n");
1599         else
1600                 g_print("                                                            ==> [Player_Test] set X11 Display SRC CROP (x:%d, y:%d, w:%d, h:%d)\n", x, y, w, h);
1601 #endif
1602 }
1603
1604 static void get_display_src_crop()
1605 {
1606 #if 0
1607         int x = 0;
1608         int y = 0;
1609         int w = 0;
1610         int h = 0;
1611
1612         if (player_get_x11_display_src_crop(g_player[0], &x, &y, &w, &h) != PLAYER_ERROR_NONE)
1613                 g_print("failed to player_get_x11_display_src_crop\n");
1614         else
1615                 g_print("                                                            ==> [Player_Test] got X11 Display SRC CROP (x:%d, y:%d, w:%d, h:%d)\n", x, y, w, h);
1616 #endif
1617 }
1618
1619 static void input_subtitle_filename(char *subtitle_filename)
1620 {
1621         int len = strlen(subtitle_filename);
1622
1623         if (len < 1 || len > MAX_STRING_LEN)
1624                 return;
1625
1626         strncpy(g_subtitle_uri, subtitle_filename, len);
1627         g_print("subtitle uri is set to %s\n", g_subtitle_uri);
1628         player_set_subtitle_path(g_player[0], g_subtitle_uri);
1629 }
1630
1631 static void switch_subtitle(int index)
1632 {
1633         char *lang_code = NULL;
1634         if (player_select_track(g_player[0], PLAYER_STREAM_TYPE_TEXT, index) != PLAYER_ERROR_NONE)
1635                 g_print("player_select_track failed\n");
1636
1637         if (player_get_track_language_code(g_player[0], PLAYER_STREAM_TYPE_TEXT, index, &lang_code) == PLAYER_ERROR_NONE) {
1638                 g_print("selected track code %s\n", lang_code);
1639                 free(lang_code);
1640         }
1641 }
1642
1643 static void capture_video()
1644 {
1645         if (player_capture_video(g_player[0], video_captured_cb, NULL) != PLAYER_ERROR_NONE)
1646                 g_print("failed to player_capture_video\n");
1647 }
1648
1649 static void decoding_audio()
1650 {
1651 #if 0
1652         int ret;
1653         char *suffix, *dump_path;
1654         GDateTime *time = g_date_time_new_now_local();
1655
1656         suffix = g_date_time_format(time, "%Y%m%d_%H%M%S.pcm");
1657         dump_path = g_strjoin(NULL, PLAYER_TEST_DUMP_PATH_PREFIX, suffix, NULL);
1658         g_pcm_fd = fopen(dump_path, "w+");
1659         g_free(dump_path);
1660         g_free(suffix);
1661         g_date_time_unref(time);
1662         if (!g_pcm_fd)
1663                 g_print("Can not create debug dump file");
1664
1665         ret = player_set_audio_frame_decoded_cb(g_player[0], 0, 0, audio_frame_decoded_cb, (void *)g_player[0]);
1666         if (ret != PLAYER_ERROR_NONE)
1667                 g_print("player_set_audio_frame_decoded_cb is failed (errno = %d) \n", ret);
1668 #endif
1669 }
1670
1671 static void set_audio_eq(int value)
1672 {
1673         bool available = FALSE;
1674         int index, min, max;
1675
1676         if (value) {
1677                 if (player_audio_effect_equalizer_is_available(g_player[0], &available) != PLAYER_ERROR_NONE)
1678                         g_print("failed to player_audio_effect_equalizer_is_available\n");
1679
1680                 if (available) {
1681                         if ((player_audio_effect_get_equalizer_bands_count(g_player[0], &index) != PLAYER_ERROR_NONE) ||
1682                                 (player_audio_effect_get_equalizer_level_range(g_player[0], &min, &max) != PLAYER_ERROR_NONE) ||
1683                                 (player_audio_effect_set_equalizer_band_level(g_player[0], index / 2, max) != PLAYER_ERROR_NONE))
1684                                 g_print("failed to player_audio_effect_set_equalizer_band_level index %d, level %d\n", index / 2, max);
1685                 }
1686         }
1687
1688         else {
1689                 if (player_audio_effect_equalizer_clear(g_player[0]) != PLAYER_ERROR_NONE)
1690                         g_print("failed to player_audio_effect_equalizer_clear\n");
1691         }
1692
1693 }
1694
1695 static void get_audio_eq()
1696 {
1697         int index, min, max, value;
1698         player_audio_effect_get_equalizer_bands_count(g_player[0], &index);
1699         g_print("                                                            ==> [Player_Test] eq bands count: [%d] \n", index);
1700         player_audio_effect_get_equalizer_level_range(g_player[0], &min, &max);
1701         g_print("                                                            ==> [Player_Test] eq bands range: [%d~%d] \n", min, max);
1702         player_audio_effect_get_equalizer_band_level(g_player[0], index / 2, &value);
1703         g_print("                                                            ==> [Player_Test] eq bands level: [%d] \n", value);
1704         player_audio_effect_get_equalizer_band_frequency(g_player[0], 0, &value);
1705         g_print("                                                            ==> [Player_Test] eq bands frequency: [%d] \n", value);
1706         player_audio_effect_get_equalizer_band_frequency_range(g_player[0], 0, &value);
1707         g_print("                                                            ==> [Player_Test] eq bands frequency range: [%d] \n", value);
1708 }
1709
1710 void quit_program()
1711 {
1712         int i = 0;
1713
1714         if (g_pcm_fd)
1715                 fclose(g_pcm_fd);
1716
1717         for (i = 0; i < g_handle_num; i++) {
1718                 if (g_player[i] != NULL) {
1719                         player_unprepare(g_player[i]);
1720                         player_destroy(g_player[i]);
1721                         g_player[i] = 0;
1722                 }
1723         }
1724         elm_exit();
1725
1726         if (g_audio_fmt)
1727                 media_format_unref(g_audio_fmt);
1728
1729         if (g_video_fmt)
1730                 media_format_unref(g_video_fmt);
1731 }
1732
1733 void play_with_ini(char *file_path)
1734 {
1735         input_filename(file_path);
1736         _player_play();
1737 }
1738
1739 void _interpret_main_menu(char *cmd)
1740 {
1741         int len = strlen(cmd);
1742         if (len == 1) {
1743                 if (strncmp(cmd, "a", 1) == 0) {
1744                         g_menu_state = CURRENT_STATUS_FILENAME;
1745                 } else if (strncmp(cmd, "1", 1) == 0) {
1746                         play_with_ini(g_file_list[0]);
1747                 } else if (strncmp(cmd, "2", 1) == 0) {
1748                         play_with_ini(g_file_list[1]);
1749                 } else if (strncmp(cmd, "3", 1) == 0) {
1750                         play_with_ini(g_file_list[2]);
1751                 } else if (strncmp(cmd, "4", 1) == 0) {
1752                         play_with_ini(g_file_list[3]);
1753                 } else if (strncmp(cmd, "5", 1) == 0) {
1754                         play_with_ini(g_file_list[4]);
1755                 } else if (strncmp(cmd, "6", 1) == 0) {
1756                         play_with_ini(g_file_list[5]);
1757                 } else if (strncmp(cmd, "7", 1) == 0) {
1758                         play_with_ini(g_file_list[6]);
1759                 } else if (strncmp(cmd, "8", 1) == 0) {
1760                         play_with_ini(g_file_list[7]);
1761                 } else if (strncmp(cmd, "9", 1) == 0) {
1762                         play_with_ini(g_file_list[8]);
1763                 } else if (strncmp(cmd, "b", 1) == 0) {
1764                         _player_play();
1765                 } else if (strncmp(cmd, "c", 1) == 0) {
1766                         _player_stop();
1767                 } else if (strncmp(cmd, "d", 1) == 0) {
1768                         _player_resume();
1769                 } else if (strncmp(cmd, "e", 1) == 0) {
1770                         _player_pause();
1771                 } else if (strncmp(cmd, "S", 1) == 0) {
1772                         _player_state();
1773                 } else if (strncmp(cmd, "f", 1) == 0) {
1774                         g_menu_state = CURRENT_STATUS_VOLUME;
1775                 } else if (strncmp(cmd, "g", 1) == 0) {
1776                         float left;
1777                         float right;
1778                         get_volume(&left, &right);
1779                 } else if (strncmp(cmd, "z", 1) == 0) {
1780                         g_menu_state = CURRENT_STATUS_SOUND_TYPE;
1781                 } else if (strncmp(cmd, "k", 1) == 0) {
1782                         g_menu_state = CURRENT_STATUS_SOUND_STREAM_INFO;
1783                 } else if (strncmp(cmd, "h", 1) == 0) {
1784                         g_menu_state = CURRENT_STATUS_MUTE;
1785                 } else if (strncmp(cmd, "i", 1) == 0) {
1786                         bool mute;
1787                         get_mute(&mute);
1788                 } else if (strncmp(cmd, "j", 1) == 0) {
1789                         g_menu_state = CURRENT_STATUS_POSITION_TIME;
1790                 } else if (strncmp(cmd, "l", 1) == 0) {
1791                         get_position();
1792                 } else if (strncmp(cmd, "m", 1) == 0) {
1793                         get_duration();
1794                 } else if (strncmp(cmd, "n", 1) == 0) {
1795                         get_stream_info();
1796                 } else if (strncmp(cmd, "o", 1) == 0) {
1797                         g_menu_state = CURRENT_STATUS_LOOPING;
1798                 } else if (strncmp(cmd, "p", 1) == 0) {
1799                         bool looping;
1800                         get_looping(&looping);
1801                 } else if (strncmp(cmd, "r", 1) == 0) {
1802                         g_menu_state = CURRENT_STATUS_DISPLAY_MODE;
1803                 } else if (strncmp(cmd, "s", 1) == 0) {
1804                         get_display_mode();
1805                 } else if (strncmp(cmd, "t", 1) == 0) {
1806                         g_menu_state = CURRENT_STATUS_DISPLAY_ROTATION;
1807                 } else if (strncmp(cmd, "u", 1) == 0) {
1808                         get_display_rotation();
1809                 } else if (strncmp(cmd, "v", 1) == 0) {
1810                         g_menu_state = CURRENT_STATUS_DISPLAY_VISIBLE;
1811                 } else if (strncmp(cmd, "w", 1) == 0) {
1812                         bool visible;
1813                         get_display_visible(&visible);
1814                 } else if (strncmp(cmd, "x", 1) == 0) {
1815                         g_menu_state = CURRENT_STATUS_DISPLAY_DST_ROI;
1816                 } else if (strncmp(cmd, "y", 1) == 0) {
1817                         get_display_dst_roi();
1818                 } else if (strncmp(cmd, "M", 1) == 0) {
1819                         g_menu_state = CURRENT_STATUS_DISPLAY_ROI_MODE;
1820                 } else if (strncmp(cmd, "N", 1) == 0) {
1821                         get_display_roi_mode();
1822                 } else if (strncmp(cmd, "F", 1) == 0) {
1823                         g_menu_state = CURRENT_STATUS_DISPLAY_SRC_CROP;
1824                 } else if (strncmp(cmd, "G", 1) == 0) {
1825                         get_display_src_crop();
1826                 } else if (strncmp(cmd, "A", 1) == 0) {
1827                         g_menu_state = CURRENT_STATUS_SUBTITLE_FILENAME;
1828                 } else if (strncmp(cmd, "C", 1) == 0) {
1829                         capture_video();
1830                 } else if (strncmp(cmd, "D", 1) == 0) {
1831                         decoding_audio();
1832                 } else if (strncmp(cmd, "q", 1) == 0) {
1833                         quit_pushing = TRUE;
1834                         quit_program();
1835                 } else if (strncmp(cmd, "E", 1) == 0) {
1836                         g_menu_state = CURRENT_STATUS_AUDIO_EQUALIZER;
1837                 } else if (strncmp(cmd, "H", 1) == 0) {
1838                         get_audio_eq();
1839                 } else {
1840                         g_print("unknown menu \n");
1841                 }
1842         } else if (len == 2) {
1843                 if (strncmp(cmd, "pr", 2) == 0) {
1844                         /* sync */
1845                         _player_prepare(FALSE);
1846                 } else if (strncmp(cmd, "pa", 2) == 0) {
1847                         /* async */
1848                         _player_prepare(TRUE);
1849                 } else if (strncmp(cmd, "un", 2) == 0) {
1850                         _player_unprepare();
1851                 } else if (strncmp(cmd, "dt", 2) == 0) {
1852                         _player_destroy();
1853                 } else if (strncmp(cmd, "sp", 2) == 0) {
1854                         _player_set_progressive_download();
1855                 } else if (strncmp(cmd, "gp", 2) == 0) {
1856                         _player_get_progressive_download_status();
1857                 } else if (strncmp(cmd, "mp", 2) == 0) {
1858                         g_memory_playback = (g_memory_playback ? FALSE : TRUE);
1859                         g_print("memory playback = %d\n", g_memory_playback);
1860                 } else if (strncmp(cmd, "ds", 2) == 0) {
1861                         g_menu_state = CURRENT_STATUS_DISPLAY_SURFACE_CHANGE;
1862                 } else if (strncmp(cmd, "nb", 2) == 0) {
1863                         g_menu_state = CURRENT_STATUS_HANDLE_NUM;
1864                 } else if (strncmp(cmd, "tr", 2) == 0) {
1865                         g_menu_state = CURRENT_STATUS_PLAYBACK_RATE;
1866                 } else if (strncmp(cmd, "ss", 2) == 0) {
1867                         g_menu_state = CURRENT_STATUS_SWITCH_SUBTITLE;
1868                 } else if (strncmp(cmd, "X3", 2) == 0) {
1869                         audio_frame_decoded_cb_ex();
1870                 } else if (strncmp(cmd, "X4", 2) == 0) {
1871                         set_pcm_spec();
1872                 } else {
1873                         g_print("unknown menu \n");
1874                 }
1875         } else {
1876                 if (strncmp(cmd, "trs", 3) == 0)
1877                         g_menu_state = CURRENT_STATUS_STREAMING_PLAYBACK_RATE;
1878                 else
1879                         g_print("unknown menu \n");
1880         }
1881 }
1882
1883 void display_sub_basic()
1884 {
1885         int idx;
1886         g_print("\n");
1887         g_print("=========================================================================================\n");
1888         g_print("                          Player Test (press q to quit) \n");
1889         g_print("-----------------------------------------------------------------------------------------\n");
1890         g_print("*. Sample List in [%s]      \t", MMTS_SAMPLELIST_INI_DEFAULT_PATH);
1891         g_print("nb. num. of handles \n");
1892         for (idx = 1; idx <= INI_SAMPLE_LIST_MAX; idx++) {
1893                 if (strlen(g_file_list[idx - 1]) > 0)
1894                         g_print("%d. Play [%s]\n", idx, g_file_list[idx - 1]);
1895         }
1896         g_print("-----------------------------------------------------------------------------------------\n");
1897         g_print("[playback] a. Create\t");
1898         g_print("pr. Prepare  \t");
1899         g_print("pa. Prepare async \t");
1900         g_print("b. Play  \t");
1901         g_print("c. Stop  \t");
1902         g_print("d. Resume\t");
1903         g_print("e. Pause \t");
1904         g_print("un. Unprepare \t");
1905         g_print("dt. Destroy \n");
1906         g_print("[State] S. Player State \n");
1907         g_print("[ volume ] f. Set Volume\t");
1908         g_print("g. Get Volume\t");
1909         g_print("z. Set Sound type\t");
1910         g_print("k. Set Sound Stream Info.\t");
1911         g_print("[ mute ] h. Set Mute\t");
1912         g_print("i. Get Mute\n");
1913         g_print("[audio eq] E. Set Audio EQ\t");
1914         g_print("H. Get Audio EQ\n");
1915         g_print("[position] j. Set Position \t");
1916         g_print("l. Get Position\n");
1917         g_print("[trick] tr. set playback rate\n");
1918         g_print("[duration] m. Get Duration\n");
1919         g_print("[Stream Info] n. Get stream info (Video Size, codec, audio stream info, and tag info)\n");
1920         g_print("[Looping] o. Set Looping\t");
1921         g_print("p. Get Looping\n");
1922         g_print("[display] v. Set display visible\t");
1923         g_print("w. Get display visible\n");
1924         g_print("[display] ds. Change display surface type\n");
1925         g_print("[x display] r. Set display mode\t");
1926         g_print("s. Get display mode\n");
1927         g_print("[x display] t. Set display Rotation\t");
1928         g_print("[Track] tl. Get Track language info(single only)\n");
1929         g_print("[subtitle] A. Set(or change) subtitle path\n");
1930         g_print("[subtitle] ss. Select(or change) subtitle track\n");
1931         g_print("[Video Capture] C. Capture \n");
1932         g_print("[etc] sp. Set Progressive Download\t");
1933         g_print("gp. Get Progressive Download status\n");
1934         g_print("mp. memory playback\n");
1935         g_print("[audio_frame_decoded_cb_ex] X3. (input) set audio_frame_decoded_cb_ex callback \n");
1936         g_print("\n");
1937         g_print("=========================================================================================\n");
1938 }
1939
1940 static void displaymenu()
1941 {
1942         if (g_menu_state == CURRENT_STATUS_MAINMENU) {
1943                 display_sub_basic();
1944         } else if (g_menu_state == CURRENT_STATUS_HANDLE_NUM) {
1945                 g_print("*** input number of handles.(recommended only for EVAS surface)\n");
1946         } else if (g_menu_state == CURRENT_STATUS_FILENAME) {
1947                 g_print("*** input mediapath.\n");
1948         } else if (g_menu_state == CURRENT_STATUS_VOLUME) {
1949                 g_print("*** input volume value.(0~1.0)\n");
1950         } else if (g_menu_state == CURRENT_STATUS_SOUND_TYPE) {
1951                 g_print("*** input sound type.(0:SYSTEM 1:NOTIFICATION 2:ALARM 3:RINGTONE 4:MEDIA 5:CALL 6:VOIP 7:FIXED)\n");
1952         } else if (g_menu_state == CURRENT_STATUS_SOUND_STREAM_INFO) {
1953                 g_print("*** input sound stream type.(0:MEDIA 1:SYSTEM 2:ALARM 3:NOTIFICATION 4:EMERGENCY 5:VOICE_INFORMATION 9:MEDIA_EXT_ONLY)\n");
1954         } else if (g_menu_state == CURRENT_STATUS_MUTE) {
1955                 g_print("*** input mute value.(0: Not Mute, 1: Mute) \n");
1956         } else if (g_menu_state == CURRENT_STATUS_POSITION_TIME) {
1957                 g_print("*** input position value(msec)\n");
1958         } else if (g_menu_state == CURRENT_STATUS_LOOPING) {
1959                 g_print("*** input looping value.(0: Not Looping, 1: Looping) \n");
1960         } else if (g_menu_state == CURRENT_STATUS_DISPLAY_SURFACE_CHANGE) {
1961                 g_print("*** input display surface type.(0: X surface, 1: EVAS surface) \n");
1962         } else if (g_menu_state == CURRENT_STATUS_DISPLAY_MODE) {
1963                 g_print("*** input display mode value.(0: LETTER BOX, 1: ORIGIN SIZE, 2: FULL_SCREEN, 3: CROPPED_FULL, 4: ORIGIN_OR_LETTER, 5: ROI) \n");
1964         } else if (g_menu_state == CURRENT_STATUS_DISPLAY_ROTATION) {
1965                 g_print("*** input display rotation value.(0: NONE, 1: 90, 2: 180, 3: 270, 4:F LIP_HORZ, 5: FLIP_VERT ) \n");
1966         } else if (g_menu_state == CURRENT_STATUS_DISPLAY_VISIBLE) {
1967                 g_print("*** input display visible value.(0: HIDE, 1: SHOW) \n");
1968         } else if (g_menu_state == CURRENT_STATUS_DISPLAY_ROI_MODE) {
1969                 g_print("*** input display roi mode.(0: FULL_SCREEN, 1: LETTER BOX)\n");
1970         } else if (g_menu_state == CURRENT_STATUS_DISPLAY_DST_ROI) {
1971                 g_print("*** input display roi value sequentially.(x, y, w, h)\n");
1972         } else if (g_menu_state == CURRENT_STATUS_DISPLAY_SRC_CROP) {
1973                 g_print("*** input display source crop value sequentially.(x, y, w, h)\n");
1974         } else if (g_menu_state == CURRENT_STATUS_SUBTITLE_FILENAME) {
1975                 g_print(" *** input  subtitle file path.\n");
1976         } else if (g_menu_state == CURRENT_STATUS_AUDIO_EQUALIZER) {
1977                 g_print(" *** input audio eq value.(0: UNSET, 1: SET) \n");
1978         } else if (g_menu_state == CURRENT_STATUS_PLAYBACK_RATE || g_menu_state == CURRENT_STATUS_STREAMING_PLAYBACK_RATE) {
1979                 g_print(" *** input playback rate.(-5.0 ~ 5.0)\n");
1980         } else if (g_menu_state == CURRENT_STATUS_SWITCH_SUBTITLE) {
1981                 int count = 0, cur_index = 0;
1982                 int ret = 0;
1983
1984                 ret = player_get_track_count(g_player[0], PLAYER_STREAM_TYPE_TEXT, &count);
1985                 if (ret != PLAYER_ERROR_NONE)
1986                         g_print("player_get_track_count fail!!!!\n");
1987                 else if (count) {
1988                         g_print("Total subtitle tracks = %d \n", count);
1989                         player_get_current_track(g_player[0], PLAYER_STREAM_TYPE_TEXT, &cur_index);
1990                         g_print("Current index = %d \n", cur_index);
1991                         g_print(" *** input correct index 0 to %d\n:", (count - 1));
1992                 } else
1993                         g_print("no track\n");
1994         } else {
1995                 g_print("*** unknown status.\n");
1996                 quit_program();
1997         }
1998         g_print(" >>> ");
1999 }
2000
2001 gboolean timeout_menu_display(void *data)
2002 {
2003         displaymenu();
2004         return FALSE;
2005 }
2006
2007 gboolean timeout_quit_program(void *data)
2008 {
2009         quit_program();
2010         return FALSE;
2011 }
2012
2013 void reset_menu_state(void)
2014 {
2015         g_menu_state = CURRENT_STATUS_MAINMENU;
2016 }
2017
2018 static void interpret(char *cmd)
2019 {
2020         switch (g_menu_state) {
2021         case CURRENT_STATUS_MAINMENU:
2022                 {
2023                         _interpret_main_menu(cmd);
2024                 }
2025                 break;
2026         case CURRENT_STATUS_HANDLE_NUM:
2027                 {
2028                         int num_handle = atoi(cmd);
2029                         if (0 >= num_handle || num_handle > MAX_HANDLE)
2030                                 g_print("not supported this number for handles(%d)\n", num_handle);
2031                         else
2032                                 g_handle_num = num_handle;
2033
2034                         reset_menu_state();
2035                 }
2036                 break;
2037         case CURRENT_STATUS_FILENAME:
2038                 {
2039                         input_filename(cmd);
2040                         reset_menu_state();
2041                 }
2042                 break;
2043         case CURRENT_STATUS_VOLUME:
2044                 {
2045                         float level = atof(cmd);
2046                         set_volume(level);
2047                         reset_menu_state();
2048                 }
2049                 break;
2050         case CURRENT_STATUS_SOUND_TYPE:
2051                 {
2052                         int type = atoi(cmd);
2053                         set_sound_type(type);
2054                         reset_menu_state();
2055                 }
2056                 break;
2057         case CURRENT_STATUS_SOUND_STREAM_INFO:
2058                 {
2059                         int type = atoi(cmd);
2060                         set_sound_stream_info(type);
2061                         reset_menu_state();
2062                 }
2063                 break;
2064         case CURRENT_STATUS_MUTE:
2065                 {
2066                         int mute = atoi(cmd);
2067                         set_mute(mute);
2068                         reset_menu_state();
2069                 }
2070                 break;
2071         case CURRENT_STATUS_POSITION_TIME:
2072                 {
2073                         long position = atol(cmd);
2074                         set_position(position);
2075                         reset_menu_state();
2076                 }
2077                 break;
2078         case CURRENT_STATUS_LOOPING:
2079                 {
2080                         int looping = atoi(cmd);
2081                         set_looping(looping);
2082                         reset_menu_state();
2083                 }
2084                 break;
2085         case CURRENT_STATUS_DISPLAY_SURFACE_CHANGE:
2086                 {
2087                         int type = atoi(cmd);
2088                         change_surface(type);
2089                         reset_menu_state();
2090                 }
2091                 break;
2092         case CURRENT_STATUS_DISPLAY_MODE:
2093                 {
2094                         int mode = atoi(cmd);
2095                         set_display_mode(mode);
2096                         reset_menu_state();
2097                 }
2098                 break;
2099         case CURRENT_STATUS_DISPLAY_ROTATION:
2100                 {
2101                         int rotation = atoi(cmd);
2102                         set_display_rotation(rotation);
2103                         reset_menu_state();
2104                 }
2105                 break;
2106         case CURRENT_STATUS_DISPLAY_VISIBLE:
2107                 {
2108                         int visible = atoi(cmd);
2109                         set_display_visible(visible);
2110                         reset_menu_state();
2111                 }
2112                 break;
2113         case CURRENT_STATUS_DISPLAY_DST_ROI:
2114                 {
2115                         int value = atoi(cmd);
2116                         static int roi_x = 0;
2117                         static int roi_y = 0;
2118                         static int roi_w = 0;
2119                         static int roi_h = 0;
2120                         static int cnt = 0;
2121                         switch (cnt) {
2122                         case 0:
2123                                 roi_x = value;
2124                                 cnt++;
2125                                 break;
2126                         case 1:
2127                                 roi_y = value;
2128                                 cnt++;
2129                                 break;
2130                         case 2:
2131                                 roi_w = value;
2132                                 cnt++;
2133                                 break;
2134                         case 3:
2135                                 cnt = 0;
2136                                 roi_h = value;
2137                                 set_display_dst_roi(roi_x, roi_y, roi_w, roi_h);
2138                                 roi_x = roi_y = roi_w = roi_h = 0;
2139                                 reset_menu_state();
2140                                 break;
2141                         default:
2142                                 break;
2143                         }
2144                 }
2145                 break;
2146         case CURRENT_STATUS_DISPLAY_SRC_CROP:
2147                 {
2148                         int value = atoi(cmd);
2149                         static int crop_x = 0;
2150                         static int crop_y = 0;
2151                         static int crop_w = 0;
2152                         static int crop_h = 0;
2153                         static int crop_cnt = 0;
2154                         switch (crop_cnt) {
2155                         case 0:
2156                                 crop_x = value;
2157                                 crop_cnt++;
2158                                 break;
2159                         case 1:
2160                                 crop_y = value;
2161                                 crop_cnt++;
2162                                 break;
2163                         case 2:
2164                                 crop_w = value;
2165                                 crop_cnt++;
2166                                 break;
2167                         case 3:
2168                                 crop_cnt = 0;
2169                                 crop_h = value;
2170                                 set_display_src_crop(crop_x, crop_y, crop_w, crop_h);
2171                                 crop_x = crop_y = crop_w = crop_h = 0;
2172                                 reset_menu_state();
2173                                 break;
2174                         default:
2175                                 break;
2176                         }
2177                 }
2178                 break;
2179         case CURRENT_STATUS_DISPLAY_ROI_MODE:
2180                 {
2181                         int value = atoi(cmd);
2182                         set_display_roi_mode(value);
2183                         reset_menu_state();
2184                 }
2185                 break;
2186         case CURRENT_STATUS_SUBTITLE_FILENAME:
2187                 {
2188                         input_subtitle_filename(cmd);
2189                         reset_menu_state();
2190                 }
2191                 break;
2192         case CURRENT_STATUS_AUDIO_EQUALIZER:
2193                 {
2194                         int value = atoi(cmd);
2195                         set_audio_eq(value);
2196                         reset_menu_state();
2197                 }
2198                 break;
2199         case CURRENT_STATUS_PLAYBACK_RATE:
2200                 {
2201                         float rate = atof(cmd);
2202                         set_playback_rate(rate, FALSE);
2203                         reset_menu_state();
2204                 }
2205                 break;
2206         case CURRENT_STATUS_STREAMING_PLAYBACK_RATE:
2207                 {
2208                         float rate = atof(cmd);
2209                         set_playback_rate(rate, TRUE);
2210                         reset_menu_state();
2211                 }
2212                 break;
2213         case CURRENT_STATUS_SWITCH_SUBTITLE:
2214                 {
2215                         int index = atoi(cmd);
2216                         switch_subtitle(index);
2217                         reset_menu_state();
2218                 }
2219                 break;
2220         }
2221         g_timeout_add(100, timeout_menu_display, 0);
2222 }
2223
2224 gboolean input(GIOChannel *channel)
2225 {
2226         gchar buf[MAX_STRING_LEN];
2227         gsize read;
2228         GError *error = NULL;
2229
2230         g_io_channel_read_chars(channel, buf, MAX_STRING_LEN, &read, &error);
2231         buf[read] = '\0';
2232         g_strstrip(buf);
2233         interpret(buf);
2234
2235         return TRUE;
2236 }
2237
2238 int main(int argc, char *argv[])
2239 {
2240         GIOChannel *stdin_channel;
2241         stdin_channel = g_io_channel_unix_new(0);
2242         g_io_channel_set_flags(stdin_channel, G_IO_FLAG_NONBLOCK, NULL);
2243         g_io_add_watch(stdin_channel, G_IO_IN, (GIOFunc)input, NULL);
2244
2245         displaymenu();
2246         memset(&ad, 0x0, sizeof(appdata));
2247         ops.data = &ad;
2248
2249         return appcore_efl_main(PACKAGE, &argc, &argv, &ops);
2250 }