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