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