[0.3.129][test] set subtitle cb
[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 #define USE_EVENT_HANDLER
17
18 #include <player.h>
19 #include <player_internal.h>
20 #include <sound_manager.h>
21 #include <pthread.h>
22 #include <glib.h>
23 #include <dlfcn.h>
24 #include <appcore-efl.h>
25 #include <Elementary.h>
26 #include <Ecore.h>
27 #include <stdio.h>
28 #include <string.h>
29 #ifdef _ACTIVATE_EOM_
30 #include <eom.h>
31 #endif
32
33 #ifdef USE_EVENT_HANDLER
34 #include <mm_navevent_handler.h>
35 #endif
36
37 #ifdef PACKAGE
38 #undef PACKAGE
39 #endif
40 #define PACKAGE "player_test"
41
42 #ifdef LOG_TAG
43 #undef LOG_TAG
44 #endif
45 #define LOG_TAG "PLAYER_TEST"
46
47 #define MAX_STRING_LEN  2048
48 #define PLAYER_TEST_DUMP_PATH_PREFIX   "/home/owner/dump_pcm_"
49 #define DEFAULT_HTTP_TIMEOUT -1
50
51 #include <system_info.h>
52 #include <stdlib.h>
53 typedef enum {
54         TIZEN_PROFILE_UNKNOWN = 0,
55         TIZEN_PROFILE_MOBILE = 0x1,
56         TIZEN_PROFILE_WEARABLE = 0x2,
57         TIZEN_PROFILE_TV = 0x4,
58         TIZEN_PROFILE_IVI = 0x8,
59         TIZEN_PROFILE_COMMON = 0x10,
60 } tizen_profile_e;
61
62 typedef struct {
63         uint64_t mask;
64         FILE *fp_out;
65 } audio_pcm_dump_t;
66
67 #ifdef USE_EVENT_HANDLER
68 static void event_handler_cb(enum libinput_event_type ev_t, int x, int y, void *data, float e[3]);
69 static void event_handler_set_dov_fov();
70 static void event_handler_set_window_parameters();
71 mm_navevent_handler_h event_handler;
72 mm_navevent_handler_size_s image_size;
73 #endif
74
75 static tizen_profile_e _get_tizen_profile()
76 {
77         char *profileName;
78         static tizen_profile_e profile = TIZEN_PROFILE_UNKNOWN;
79
80         if (__builtin_expect(profile != TIZEN_PROFILE_UNKNOWN, 1))
81                 return profile;
82
83         system_info_get_platform_string("http://tizen.org/feature/profile", &profileName);
84         switch (*profileName) {
85         case 'm':
86         case 'M':
87                 profile = TIZEN_PROFILE_MOBILE;
88                 break;
89         case 'w':
90         case 'W':
91                 profile = TIZEN_PROFILE_WEARABLE;
92                 break;
93         case 't':
94         case 'T':
95                 profile = TIZEN_PROFILE_TV;
96                 break;
97         case 'i':
98         case 'I':
99                 profile = TIZEN_PROFILE_IVI;
100                 break;
101         default: // common or unknown ==> ALL ARE COMMON.
102                 profile = TIZEN_PROFILE_COMMON;
103         }
104         free(profileName);
105
106         return profile;
107 }
108 #define TIZEN_TV  ((_get_tizen_profile()) == TIZEN_PROFILE_TV)
109
110 static gboolean g_memory_playback = FALSE;
111 static char g_uri[MAX_STRING_LEN];
112 static char g_subtitle_uri[MAX_STRING_LEN];
113 static FILE *g_pcm_fd;
114
115 static gboolean is_es_push_mode = FALSE;
116 static pthread_t g_feed_video_thread_id = 0;
117 static bool g_thread_end = FALSE;
118 static media_packet_h g_audio_pkt = NULL;
119 static media_format_h g_audio_fmt = NULL;
120
121 static media_packet_h g_video_pkt = NULL;
122 static media_format_h g_video_fmt = NULL;
123
124 static int _save(unsigned char *src, int length);
125
126 #define DUMP_OUTBUF         1
127 #if DUMP_OUTBUF
128 FILE *fp_out1 = NULL;
129 FILE *fp_out2 = NULL;
130 GList *audio_dump_list = NULL;
131 #endif
132
133 enum {
134         CURRENT_STATUS_MAINMENU,
135         CURRENT_STATUS_HANDLE_NUM,
136         CURRENT_STATUS_FILENAME,
137         CURRENT_STATUS_VOLUME,
138         CURRENT_STATUS_SOUND_STREAM_INFO,
139         CURRENT_STATUS_MUTE,
140         CURRENT_STATUS_POSITION_TIME,
141         CURRENT_STATUS_LOOPING,
142         CURRENT_STATUS_DISPLAY_SURFACE_CHANGE,
143         CURRENT_STATUS_EXPORT_VIDEO_FRAME,
144         CURRENT_STATUS_DISPLAY_MODE,
145         CURRENT_STATUS_DISPLAY_DST_ROI_AREA,
146         CURRENT_STATUS_DISPLAY_ROTATION,
147         CURRENT_STATUS_DISPLAY_VISIBLE,
148         CURRENT_STATUS_SUBTITLE_FILENAME,
149         CURRENT_STATUS_AUDIO_EQUALIZER,
150         CURRENT_STATUS_PLAYBACK_RATE,
151         CURRENT_STATUS_STREAMING_PLAYBACK_RATE,
152         CURRENT_STATUS_LATENCY,
153         CURRENT_STATUS_SET_TRACK_TYPE,
154         CURRENT_STATUS_SET_TRACK_INDEX,
155         CURRENT_STATUS_NEXT_URI,
156         CURRENT_STATUS_GAPLESS,
157         CURRENT_STATUS_GET_TRACK_INFO,
158         CURRENT_STATUS_POSITION_ACCURATE,
159         CURRENT_STATUS_SET_MAX_BANDWIDTH_VARIANT,
160         CURRENT_STATUS_SET_MAX_WIDTH_VARIANT,
161         CURRENT_STATUS_SET_MAX_HEIGHT_VARIANT,
162         CURRENT_STATUS_SET_AUDIO_ONLY,
163         CURRENT_STATUS_SET_PRE_BUFFERING_SIZE,
164         CURRENT_STATUS_SET_RE_BUFFERING_SIZE,
165         CURRENT_STATUS_VIDEO360_SET_ENABLE,
166         CURRENT_STATUS_VIDEO360_SET_DOV,
167         CURRENT_STATUS_VIDEO360_SET_DOV1,
168         CURRENT_STATUS_VIDEO360_SET_FOV,
169         CURRENT_STATUS_VIDEO360_SET_FOV1,
170         CURRENT_STATUS_VIDEO360_SET_ZOOM,
171         CURRENT_STATUS_VIDEO360_SET_ZOOM_WITH_FOV,
172         CURRENT_STATUS_VIDEO360_SET_ZOOM_WITH_FOV1,
173         CURRENT_STATUS_VIDEO360_SET_ZOOM_WITH_FOV2,
174         CURRENT_STATUS_SET_VIDEO_CODEC_TYPE,
175         CURRENT_STATUS_SET_AUDIO_CODEC_TYPE,
176         CURRENT_STATUS_GET_CODEC_TYPE,
177         CURRENT_STATUS_REPLAYGAIN_ENABLE,
178         CURRENT_STATUS_AUDIO_OFFLOAD,
179         CURRENT_STATUS_PITCH_CONTROL,
180         CURRENT_STATUS_PITCH_VALUE,
181         CURRENT_STATUS_EXPORT_PCM_OPTION,
182         CURRENT_STATUS_EXPORT_PCM_CH,
183         CURRENT_STATUS_EXPORT_PCM_RATE,
184         CURRENT_STATUS_EXPORT_PCM_MIME,
185 };
186
187 #define MAX_HANDLE 20
188
189 /* for video display */
190 static Evas_Object *g_win_id;
191 #ifdef _ACTIVATE_EOM_
192 static Evas_Object *g_external_win_id;
193 #endif
194 static Evas_Object *selected_win_id;
195 static Evas_Object *g_eo[MAX_HANDLE] = { 0, };
196
197 static int g_current_surface_type = -1;
198
199 typedef struct {
200         Evas_Object *win;
201         Evas_Object *layout_main;       /* layout widget based on EDJ */
202         /* add more variables here */
203 #ifdef _ACTIVATE_EOM_
204         int hdmi_output_id;
205 #endif
206 } appdata;
207
208 static appdata ad;
209 static player_h g_player[MAX_HANDLE] = { 0, };
210
211 int g_handle_num = 1;
212 int g_menu_state = CURRENT_STATUS_MAINMENU;
213 gboolean quit_pushing;
214 sound_stream_info_h g_stream_info_h = NULL;
215
216 static void win_del(void *data, Evas_Object *obj, void *event)
217 {
218         elm_exit();
219 }
220
221 static Evas_Object *create_win(const char *name)
222 {
223         Evas_Object *eo = NULL;
224         int w = 0;
225         int h = 0;
226
227         g_print("[%s][%d] name=%s\n", __func__, __LINE__, name);
228
229         eo = elm_win_add(NULL, name, ELM_WIN_BASIC);
230         if (eo) {
231                 elm_win_title_set(eo, name);
232                 elm_win_borderless_set(eo, EINA_TRUE);
233                 evas_object_smart_callback_add(eo, "delete,request", win_del, NULL);
234                 elm_win_screen_size_get(eo, NULL, NULL, &w, &h);
235                 g_print("window size :%d,%d", w, h);
236                 evas_object_resize(eo, w, h);
237                 elm_win_autodel_set(eo, EINA_TRUE);
238                 elm_win_alpha_set(eo, EINA_TRUE);
239         }
240         return eo;
241 }
242
243 static Evas_Object *create_image_object(Evas_Object *eo_parent)
244 {
245         if (!eo_parent)
246                 return NULL;
247
248         Evas *evas = evas_object_evas_get(eo_parent);
249         Evas_Object *eo = NULL;
250
251         eo = evas_object_image_add(evas);
252
253         return eo;
254 }
255
256 void create_render_rect_and_bg(Evas_Object *win)
257 {
258         if (!win) {
259                 g_print("no win");
260                 return;
261         }
262         Evas_Object *bg, *rect;
263
264         bg = elm_bg_add(win);
265         elm_win_resize_object_add(win, bg);
266         evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
267         evas_object_show(bg);
268
269         rect = evas_object_rectangle_add(evas_object_evas_get(win));
270         if (!rect) {
271                 g_print("no rect");
272                 return;
273         }
274         evas_object_color_set(rect, 0, 0, 0, 0);
275         evas_object_render_op_set(rect, EVAS_RENDER_COPY);
276
277         elm_win_resize_object_add(win, rect);
278         evas_object_size_hint_weight_set(rect, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
279         evas_object_show(rect);
280         evas_object_show(win);
281 }
282
283 #ifdef _ACTIVATE_EOM_
284 int eom_get_output_id(const char *output_name)
285 {
286         eom_output_id *output_ids = NULL;
287         eom_output_id output_id = 0;
288         eom_output_type_e output_type = EOM_OUTPUT_TYPE_UNKNOWN;
289         int id_cnt = 0;
290         int i;
291
292         /* get output_ids */
293         output_ids = eom_get_eom_output_ids(&id_cnt);
294         if (id_cnt == 0) {
295                 g_print("[eom] no external outuputs supported\n");
296                 return 0;
297         }
298
299         /* find output ids interested */
300         for (i = 0; i < id_cnt; i++) {
301                 eom_get_output_type(output_ids[i], &output_type);
302                 if (!strncmp(output_name, "HDMI", 4)) {
303                         if (output_type == EOM_OUTPUT_TYPE_HDMIA || output_type == EOM_OUTPUT_TYPE_HDMIB) {
304                                 output_id = output_ids[i];
305                                 break;
306                         }
307                 } else if (!strncmp(output_name, "Virtual", 4)) {
308                         if (output_type == EOM_OUTPUT_TYPE_VIRTUAL) {
309                                 output_id = output_ids[i];
310                                 break;
311                         }
312                 }
313         }
314
315         if (output_ids)
316                 free(output_ids);
317
318         return output_id;
319 }
320
321 static void eom_notify_cb_output_add(eom_output_id output_id, void *user_data)
322 {
323         appdata *info = (appdata *)user_data;
324
325         if (info->hdmi_output_id != output_id) {
326                 g_print("[eom] OUTPUT ADDED. SKIP. my output ID is %d\n", info->hdmi_output_id);
327                 return;
328         }
329         g_print("[eom] output(%d) connected\n", output_id);
330         /* it is for external window */
331         if (!g_external_win_id) {
332                 g_external_win_id = elm_win_add(NULL, "External", ELM_WIN_BASIC);
333                 if (eom_set_output_window(info->hdmi_output_id, g_external_win_id) == EOM_ERROR_NONE) {
334                         create_render_rect_and_bg(g_external_win_id);
335                         g_print("[eom] create external window\n");
336                 } else {
337                         evas_object_del(g_external_win_id);
338                         g_external_win_id = NULL;
339                         g_print("[eom] create external window fail\n");
340                 }
341         }
342 }
343
344 static void eom_notify_cb_output_remove(eom_output_id output_id, void *user_data)
345 {
346         appdata *info = (appdata *)user_data;
347         player_state_e state;
348
349         if (info->hdmi_output_id != output_id) {
350                 g_print("[eom] OUTPUT REMOVED. SKIP. my output ID is %d\n", info->hdmi_output_id);
351                 return;
352         }
353         g_print("[eom] output(%d) disconnected\n", output_id);
354
355         if (selected_win_id == g_external_win_id && g_player[0]) {
356                 player_get_state(g_player[0], &state);
357                 if (state >= PLAYER_STATE_READY) {
358                         if (!g_win_id) {
359                                 g_win_id = create_win(PACKAGE);
360                                 if (g_win_id == NULL)
361                                         return;
362                                 g_print("create win_id %p\n", g_win_id);
363                                 create_render_rect_and_bg(g_win_id);
364                                 elm_win_activate(g_win_id);
365                                 evas_object_show(g_win_id);
366                         }
367                         player_set_display(g_player[0], PLAYER_DISPLAY_TYPE_OVERLAY, GET_DISPLAY(g_win_id));
368                 }
369         }
370
371         /* it is for external window */
372         if (g_external_win_id) {
373                 evas_object_del(g_external_win_id);
374                 g_external_win_id = NULL;
375         }
376         selected_win_id = g_win_id;
377 }
378
379 static void eom_notify_cb_mode_changed(eom_output_id output_id, void *user_data)
380 {
381         appdata *info = (appdata *)user_data;
382         eom_output_mode_e mode = EOM_OUTPUT_MODE_NONE;
383
384         if (info->hdmi_output_id != output_id) {
385                 g_print("[eom] MODE CHANGED. SKIP. my output ID is %d\n", info->hdmi_output_id);
386                 return;
387         }
388
389         eom_get_output_mode(output_id, &mode);
390         g_print("[eom] output(%d) mode changed(%d)\n", output_id, mode);
391 }
392
393 static void eom_notify_cb_attribute_changed(eom_output_id output_id, void *user_data)
394 {
395         appdata *info = (appdata *)user_data;
396
397         eom_output_attribute_e attribute = EOM_OUTPUT_ATTRIBUTE_NONE;
398         eom_output_attribute_state_e state = EOM_OUTPUT_ATTRIBUTE_STATE_NONE;
399
400         if (info->hdmi_output_id != output_id) {
401                 g_print("[eom] ATTR CHANGED. SKIP. my output ID is %d\n", info->hdmi_output_id);
402                 return;
403         }
404
405         eom_get_output_attribute(output_id, &attribute);
406         eom_get_output_attribute_state(output_id, &state);
407
408         g_print("[eom] output(%d) attribute changed(%d, %d)\n", output_id, attribute, state);
409         if (state == EOM_OUTPUT_ATTRIBUTE_STATE_ACTIVE) {
410                 g_print("[eom] active\n");
411                 if (!g_external_win_id) {
412                         g_external_win_id = elm_win_add(NULL, "External", ELM_WIN_BASIC);
413                         if (eom_set_output_window(info->hdmi_output_id, g_external_win_id) == EOM_ERROR_NONE) {
414                                 create_render_rect_and_bg(g_external_win_id);
415                                 g_print("[eom] create external window\n");
416                         } else {
417                                 evas_object_del(g_external_win_id);
418                                 g_external_win_id = NULL;
419                                 g_print("[eom] create external window fail\n");
420                         }
421                 }
422                 selected_win_id = g_external_win_id;
423                 /* play video on external window */
424                 if (g_player[0])
425                         player_set_display(g_player[0], PLAYER_DISPLAY_TYPE_OVERLAY, GET_DISPLAY(selected_win_id));
426         } else if (state == EOM_OUTPUT_ATTRIBUTE_STATE_INACTIVE) {
427                 g_print("[eom] inactive\n");
428                 if (!g_win_id) {
429                         g_win_id = create_win(PACKAGE);
430                         if (g_win_id == NULL)
431                                 return;
432                         g_print("create win_id %p\n", g_win_id);
433                         create_render_rect_and_bg(g_win_id);
434                         elm_win_activate(g_win_id);
435                         evas_object_show(g_win_id);
436                 }
437                 selected_win_id = g_win_id;
438                 if (g_player[0])
439                         player_set_display(g_player[0], PLAYER_DISPLAY_TYPE_OVERLAY, GET_DISPLAY(selected_win_id));
440
441                 if (g_external_win_id) {
442                         evas_object_del(g_external_win_id);
443                         g_external_win_id = NULL;
444                 }
445         } else if (state == EOM_OUTPUT_ATTRIBUTE_STATE_LOST) {
446                 g_print("[eom] lost\n");
447                 if (!g_win_id) {
448                         g_win_id = create_win(PACKAGE);
449                         if (g_win_id == NULL)
450                                 return;
451                         g_print("create win_id %p\n", g_win_id);
452                         create_render_rect_and_bg(g_win_id);
453                         elm_win_activate(g_win_id);
454                         evas_object_show(g_win_id);
455                 }
456                 selected_win_id = g_win_id;
457
458                 if (g_player[0])
459                         player_set_display(g_player[0], PLAYER_DISPLAY_TYPE_OVERLAY, GET_DISPLAY(selected_win_id));
460
461                 if (g_external_win_id) {
462                         evas_object_del(g_external_win_id);
463                         g_external_win_id = NULL;
464                 }
465
466                 eom_unset_output_added_cb(eom_notify_cb_output_add);
467                 eom_unset_output_removed_cb(eom_notify_cb_output_remove);
468                 eom_unset_mode_changed_cb(eom_notify_cb_mode_changed);
469                 eom_unset_attribute_changed_cb(eom_notify_cb_attribute_changed);
470
471                 eom_deinit();
472         }
473 }
474 #endif
475 static int app_create(void *data)
476 {
477         appdata *ad = data;
478         Evas_Object *win = NULL;
479 #ifdef _ACTIVATE_EOM_
480         eom_output_mode_e output_mode = EOM_OUTPUT_MODE_NONE;
481 #endif
482
483         /* use gl backend */
484         elm_config_accel_preference_set("opengl");
485
486         /* create window */
487         win = create_win(PACKAGE);
488         if (win == NULL)
489                 return -1;
490         ad->win = win;
491         g_win_id = win;
492         selected_win_id = g_win_id;
493         create_render_rect_and_bg(ad->win);
494         /* Create evas image object for EVAS surface */
495         g_eo[0] = create_image_object(ad->win);
496         evas_object_image_size_set(g_eo[0], 500, 500);
497         evas_object_image_fill_set(g_eo[0], 0, 0, 500, 500);
498         evas_object_resize(g_eo[0], 500, 500);
499
500         elm_win_activate(win);
501         evas_object_show(win);
502 #ifdef _ACTIVATE_EOM_
503         /* check external device */
504         eom_init();
505         ad->hdmi_output_id = eom_get_output_id("HDMI");
506         if (ad->hdmi_output_id == 0) {
507                 g_print("[eom] error : HDMI output id is NULL.\n");
508                 return 0;
509         }
510
511         g_print("eom_set_output_attribute EOM_OUTPUT_ATTRIBUTE_NORMAL(id:%d)\n", ad->hdmi_output_id);
512         if (eom_set_output_attribute(ad->hdmi_output_id, EOM_OUTPUT_ATTRIBUTE_NORMAL) != EOM_ERROR_NONE) {
513                 g_print("attribute set fail. cannot use external output\n");
514                 eom_deinit();
515         }
516
517         eom_get_output_mode(ad->hdmi_output_id, &output_mode);
518         if (output_mode != EOM_OUTPUT_MODE_NONE) {
519                 g_external_win_id = elm_win_add(NULL, "External", ELM_WIN_BASIC);
520                 if (eom_set_output_window(ad->hdmi_output_id, g_external_win_id) == EOM_ERROR_NONE) {
521                         create_render_rect_and_bg(g_external_win_id);
522                         g_print("[eom] create external window\n");
523                 } else {
524                         evas_object_del(g_external_win_id);
525                         g_external_win_id = NULL;
526                         g_print("[eom] create external window fail\n");
527                 }
528                 selected_win_id = g_external_win_id;
529         }
530
531         /* set callback for detecting external device */
532         eom_set_output_added_cb(eom_notify_cb_output_add, ad);
533         eom_set_output_removed_cb(eom_notify_cb_output_remove, ad);
534         eom_set_mode_changed_cb(eom_notify_cb_mode_changed, ad);
535         eom_set_attribute_changed_cb(eom_notify_cb_attribute_changed, ad);
536 #endif
537
538 #ifdef USE_EVENT_HANDLER
539         if (mm_navevent_handler_create(&event_handler,
540                         MM_NAVEVENT_HANDLER_DEVICE_TYPE_TOUCH) != MM_NAVEVENT_HANDLER_ERROR_NONE) {
541                 g_print ("Error during handler creation\n");
542                 return -1;
543         }
544
545         if (mm_navevent_handler_set_cb(event_handler, event_handler_cb, NULL) !=
546                         MM_NAVEVENT_HANDLER_ERROR_NONE) {
547                 g_print ("Error during callback set\n");
548                 return -1;
549         }
550 #endif
551
552         return 0;
553 }
554
555 static int app_terminate(void *data)
556 {
557         appdata *ad = data;
558         int i = 0;
559
560 #ifdef USE_EVENT_HANDLER
561         mm_navevent_handler_destroy(event_handler);
562 #endif
563
564         for (i = 0; i < MAX_HANDLE; i++) {
565                 if (g_eo[i]) {
566                         evas_object_del(g_eo[i]);
567                         g_eo[i] = NULL;
568                 }
569         }
570         if (g_win_id) {
571                 evas_object_del(g_win_id);
572                 g_win_id = NULL;
573         }
574 #ifdef _ACTIVATE_EOM_
575         if (g_external_win_id) {
576                 evas_object_del(g_external_win_id);
577                 g_external_win_id = NULL;
578         }
579 #endif
580         ad->win = NULL;
581         selected_win_id = NULL;
582 #ifdef _ACTIVATE_EOM_
583         eom_unset_output_added_cb(eom_notify_cb_output_add);
584         eom_unset_output_removed_cb(eom_notify_cb_output_remove);
585         eom_unset_mode_changed_cb(eom_notify_cb_mode_changed);
586         eom_unset_attribute_changed_cb(eom_notify_cb_attribute_changed);
587
588         eom_deinit();
589 #endif
590         return 0;
591 }
592
593 struct appcore_ops ops = {
594         .create = app_create,
595         .terminate = app_terminate,
596 };
597
598 static void prepared_cb(void *user_data)
599 {
600         g_print("[Player_Test] prepared_cb!!!!\n");
601 }
602
603 static void buffering_cb(int percent, void *user_data)
604 {
605         g_print("[Player_Test] buffering_cb!!!! percent : %d\n", percent);
606 }
607
608 static void seek_completed_cb(void *user_data)
609 {
610         g_print("[Player_Test] seek_completed_cb!!! \n");
611 }
612
613 static void completed_cb(void *user_data)
614 {
615         g_print("[Player_Test] completed_cb!!!!\n");
616 }
617
618 static void error_cb(int code, void *user_data)
619 {
620         g_print("[Player_Test] error_cb!!!! code : %d\n", code);
621 }
622
623 static void interrupted_cb(player_interrupted_code_e code, void *user_data)
624 {
625         g_print("[Player_Test] interrupted_cb!!!! code : %d\n", code);
626 }
627
628 static void video_changed_cb(int width, int height, int fps, int bit_rate, void *user_data)
629 {
630         g_print("[Player_Test] video_changed_cb!!!! %d x %d, %d, %d \n", width, height, fps, bit_rate);
631
632 #ifdef USE_EVENT_HANDLER
633         image_size.width = width;
634         image_size.height = height;
635         event_handler_set_window_parameters();
636 #endif
637 }
638
639 #if 0
640 static void audio_frame_decoded_cb(unsigned char *data, unsigned int size, void *user_data)
641 {
642         int pos = 0;
643
644         if (data && g_pcm_fd)
645                 fwrite(data, 1, size, g_pcm_fd);
646         player_get_play_position(g_player[0], &pos);
647         g_print("[Player_Test] audio_frame_decoded_cb [size: %d] --- current pos : %d!!!!\n", size, pos);
648 }
649 #endif
650
651 static void subtitle_updated_cb(unsigned long duration, char *text, void *user_data)
652 {
653         g_print("[Player_Test] subtitle_updated_cb!!!! [%ld] %s\n", duration, text);
654 }
655
656 static void video_captured_cb(unsigned char *data, int width, int height, unsigned int size, void *user_data)
657 {
658         g_print("[Player_Test] video_captured_cb!!!! width: %d, height : %d, size : %d \n", width, height, size);
659         _save(data, size);
660 }
661
662 static int _save(unsigned char *src, int length)
663 {
664         /* unlink(CAPTUERD_IMAGE_SAVE_PATH); */
665         FILE *fp;
666         char filename[256] = { 0, };
667         static int WRITE_COUNT = 0;
668         /* gchar *filename  = CAPTUERD_IMAGE_SAVE_PATH; */
669         snprintf(filename, 256, "/tmp/IMAGE_client%d", WRITE_COUNT);
670         WRITE_COUNT++;
671         fp = fopen(filename, "w+");
672         if (fp == NULL) {
673                 g_print("file open error!!\n");
674                 return FALSE;
675         } else {
676                 g_print("open success\n");
677                 if (fwrite(src, 1, length, fp) < 1) {
678                         g_print("file write error!!\n");
679                         fclose(fp);
680                         return FALSE;
681                 }
682                 g_print("write success(%s)\n", filename);
683                 fclose(fp);
684         }
685
686         return TRUE;
687 }
688 #ifdef NO_USE_CODE
689 static void reset_display()
690 {
691         int i = 0;
692
693         /* delete evas window, if it is */
694         for (i = 0; i < MAX_HANDLE; i++) {
695                 if (g_eo[i]) {
696                         evas_object_del(g_eo[i]);
697                         g_eo[i] = NULL;
698                 }
699         }
700 }
701 #endif
702 static void input_filename(char *filename)
703 {
704         int len = 0;
705         gsize src_size = 0;
706         int i = 0;
707
708         if (!filename)
709                 return;
710
711         len = strlen(filename);
712         if (len < 0 || len > MAX_STRING_LEN - 1)
713                 return;
714
715         for (i = 0; i < g_handle_num; i++) {
716                 if (g_player[i] != NULL) {
717                         player_unprepare(g_player[i]);
718                         player_destroy(g_player[i]);
719                 }
720                 g_player[i] = 0;
721
722                 if (player_create(&g_player[i]) != PLAYER_ERROR_NONE)
723                         g_print("player create is failed\n");
724         }
725
726         src_size = g_strlcpy(g_uri, filename, MAX_STRING_LEN);
727         if (src_size != len)
728                 return;
729
730 #if 0
731         /* ned(APPSRC_TEST) */
732         gchar uri[100];
733         gchar *ext;
734         gsize file_size;
735         GMappedFile *file;
736         GError *error = NULL;
737         guint8 *g_media_mem = NULL;
738
739         ext = filename;
740
741         file = g_mapped_file_new(ext, FALSE, &error);
742         file_size = g_mapped_file_get_length(file);
743         g_media_mem = (guint8 *)g_mapped_file_get_contents(file);
744
745         g_sprintf(uri, "mem://ext=%s,size=%d", ext ? ext : "", file_size);
746         g_print("[uri] = %s\n", uri);
747
748         mm_player_set_attribute(g_player[0], &g_err_name, "profile_uri", uri, strlen(uri), "profile_user_param", g_media_mem, file_size NULL);
749 #else
750         /* player_set_uri(g_player[0], filename); */
751 #endif
752         /* APPSRC_TEST */
753
754         int ret;
755         player_state_e state;
756         for (i = 0; i < g_handle_num; i++) {
757                 ret = player_get_state(g_player[i], &state);
758                 g_print("player_get_state returned [%d]\n", ret);
759                 g_print("1. After player_create() - Current State : %d \n", state);
760         }
761 }
762
763 /* use this API instead of player_set_uri */
764 static void player_set_memory_buffer_test()
765 {
766         GMappedFile *file;
767         gsize file_size;
768         guint8 *g_media_mem = NULL;
769
770         file = g_mapped_file_new(g_uri, FALSE, NULL);
771         file_size = g_mapped_file_get_length(file);
772         g_media_mem = (guint8 *)g_mapped_file_get_contents(file);
773
774         int ret = player_set_memory_buffer(g_player[0], (void *)g_media_mem, file_size);
775         g_print("player_set_memory_buffer ret : %d\n", ret);
776 }
777
778 int video_packet_count = 0;
779
780 static void buffer_need_video_data_cb(unsigned int size, void *user_data)
781 {
782         int real_read_len = 0;
783         char fname[128];
784         char fptsname[128];
785         static guint64 pts = 0L;
786
787         FILE *fp = NULL;
788         guint8 *buff_ptr = NULL;
789         void *src = NULL;
790
791         memset(fname, 0, 128);
792         memset(fptsname, 0, 128);
793
794         video_packet_count++;
795
796         if (video_packet_count > 1000) {
797                 g_print("EOS.\n");
798
799                 /* player_submit_packet(g_player[0], NULL, 0, 0, 1); */
800                 player_push_media_stream(g_player[0], NULL);
801                 g_thread_end = TRUE;
802         }
803
804         /* snprintf(fname, 128, "/opt/storage/usb/test/packet/packet_%d.dat", video_packet_count); */
805         /* snprintf(fptsname, 128, "/opt/storage/usb/test/packet/gstpts_%d.dat", video_packet_count); */
806         snprintf(fname, 128, "/home/developer/test/packet/packet_%d.dat", video_packet_count);
807         snprintf(fptsname, 128, "/home/developer/test/packet/gstpts_%d.dat", video_packet_count);
808
809         fp = fopen(fptsname, "rb");
810         if (fp) {
811                 int pts_len = 0;
812                 pts_len = fread(&pts, 1, sizeof(guint64), fp);
813                 if (pts_len != sizeof(guint64))
814                         g_print("Warning, pts value can be wrong.\n");
815                 fclose(fp);
816                 fp = NULL;
817         }
818
819         fp = fopen(fname, "rb");
820         if (fp) {
821                 buff_ptr = (guint8 *)g_malloc0(1048576);
822                 if (!buff_ptr) {
823                         g_print("no free space\n");
824                         fclose(fp);
825                         fp = NULL;
826                         return;
827                 }
828                 real_read_len = fread(buff_ptr, 1, size, fp);
829                 fclose(fp);
830                 fp = NULL;
831         }
832         g_print("video need data - data size : %d, pts : %" G_GUINT64_FORMAT "\n", real_read_len, pts);
833 #if 0
834         player_submit_packet(g_player[0], buff_ptr, real_read_len, (pts / 1000000), 1);
835 #else
836         /* create media packet */
837         if (g_video_pkt) {
838                 media_packet_destroy(g_video_pkt);
839                 g_video_pkt = NULL;
840         }
841
842         if (media_packet_create_alloc(g_video_fmt, NULL, NULL, &g_video_pkt) != MEDIA_PACKET_ERROR_NONE) {
843                 g_print("media_packet_create_alloc failed\n");
844                 goto EXIT;
845         }
846
847         g_print("packet = %p, src = %p\n", g_video_pkt, src);
848
849         if (media_packet_get_buffer_data_ptr(g_video_pkt, &src) != MEDIA_PACKET_ERROR_NONE)
850                 goto EXIT;
851
852         if (media_packet_set_pts(g_video_pkt, (uint64_t)pts) != MEDIA_PACKET_ERROR_NONE)
853                 goto EXIT;
854
855         if (media_packet_set_buffer_size(g_video_pkt, (uint64_t)real_read_len) != MEDIA_PACKET_ERROR_NONE)
856                 goto EXIT;
857
858         memcpy(src, buff_ptr, real_read_len);
859
860         /* then, push it  */
861         player_push_media_stream(g_player[0], g_video_pkt);
862 #endif
863
864 EXIT:
865         g_free(buff_ptr);
866 }
867
868 int audio_packet_count = 0;
869 static void buffer_need_audio_data_cb(unsigned int size, void *user_data)
870 {
871         int real_read_len = 0;
872         char fname[128];
873         FILE *fp = NULL;
874         guint8 *buff_ptr = NULL;
875         void *src = NULL;
876
877         memset(fname, 0, 128);
878         audio_packet_count++;
879
880         if (audio_packet_count > 1000) {
881                 g_print("EOS.\n");
882                 /* player_submit_packet(g_player[0], NULL, 0, 0, 0); */
883                 player_push_media_stream(g_player[0], NULL);
884                 g_thread_end = TRUE;
885         }
886
887         /* snprintf(fname, 128, "/opt/storage/usb/test/audio_packet/packet_%d.dat", audio_packet_count); */
888         snprintf(fname, 128, "/home/developer/test/audio_packet/packet_%d.dat", audio_packet_count);
889
890         static guint64 audio_pts = 0;
891         guint64 audio_dur = 21333333;
892
893         fp = fopen(fname, "rb");
894         if (fp) {
895                 buff_ptr = (guint8 *)g_malloc0(1048576);
896                 if (!buff_ptr) {
897                         g_print("no free space\n");
898                         fclose(fp);
899                         fp = NULL;
900                         return;
901                 }
902                 real_read_len = fread(buff_ptr, 1, size, fp);
903                 fclose(fp);
904                 fp = NULL;
905
906                 g_print("\t audio need data - data size : %d, pts : %" G_GUINT64_FORMAT "\n", real_read_len, audio_pts);
907         }
908 #if 0
909         player_submit_packet(g_player[0], buff_ptr, real_read_len, (audio_pts / 1000000), 0);
910 #else
911         /* create media packet */
912         if (g_audio_pkt) {
913                 media_packet_destroy(g_audio_pkt);
914                 g_audio_pkt = NULL;
915         }
916
917         if (media_packet_create_alloc(g_audio_fmt, NULL, NULL, &g_audio_pkt) != MEDIA_PACKET_ERROR_NONE) {
918                 g_print("media_packet_create_alloc failed\n");
919                 goto EXIT;
920         }
921
922         g_print("packet = %p, src = %p\n", g_audio_pkt, src);
923
924         if (media_packet_get_buffer_data_ptr(g_audio_pkt, &src) != MEDIA_PACKET_ERROR_NONE)
925                 goto EXIT;
926
927         if (media_packet_set_pts(g_audio_pkt, (uint64_t)audio_pts) != MEDIA_PACKET_ERROR_NONE)
928                 goto EXIT;
929
930         if (media_packet_set_buffer_size(g_audio_pkt, (uint64_t)real_read_len) != MEDIA_PACKET_ERROR_NONE)
931                 goto EXIT;
932
933         memcpy(src, buff_ptr, real_read_len);
934
935         /* then, push it  */
936         player_push_media_stream(g_player[0], g_audio_pkt);
937 #endif
938
939         audio_pts += audio_dur;
940
941 EXIT:
942         g_free(buff_ptr);
943 }
944
945 static void set_content_info(bool is_push_mode)
946 {
947         /* testcode for es buff src case, please input url as es_buff://123 or es_buff://push_mode */
948         /* 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}; */
949
950         /* create media format */
951         media_format_create(&g_audio_fmt);
952         media_format_create(&g_video_fmt);
953
954         /* Video */
955         /* configure media format  for video and set to player */
956         media_format_set_video_mime(g_video_fmt, MEDIA_FORMAT_MPEG4_SP);
957         media_format_set_video_width(g_video_fmt, 640);
958         media_format_set_video_height(g_video_fmt, 272);
959         /* player_set_media_stream_info(g_player[0], PLAYER_STREAM_TYPE_VIDEO, g_video_fmt); */
960
961         /* Audio--aac--StarWars.mp4 */
962         media_format_set_audio_mime(g_audio_fmt, MEDIA_FORMAT_AAC);
963         media_format_set_audio_channel(g_audio_fmt, 2);
964         media_format_set_audio_samplerate(g_audio_fmt, 48000);
965         /* player_set_media_stream_info(g_player[0], PLAYER_STREAM_TYPE_AUDIO, g_audio_fmt); */
966 #if 0
967         /* video_info->mime = g_strdup("video/mpeg"); *//* CODEC_ID_MPEG4VIDEO */
968         video_info->width = 640;
969         video_info->height = 272;
970         video_info->version = 4;
971         video_info->framerate_den = 100;
972         video_info->framerate_num = 2997;
973
974         video_info->extradata_size = 45;
975         video_info->codec_extradata = codec_data;
976         player_set_video_stream_info(g_player[0], video_info);
977
978         /* audio--aac--StarWars.mp4 */
979         /* audio_info->mime = g_strdup("audio/mpeg"); */
980         /* audio_info->version = 2; */
981         /* audio_info->user_info = 0; *//* raw */
982 #endif
983
984 #ifdef _ES_PULL_
985         if (!is_push_mode) {
986                 player_set_buffer_need_video_data_cb(g_player[0], buffer_need_video_data_cb, (void *)g_player[0]);
987                 player_set_buffer_need_audio_data_cb(g_player[0], buffer_need_audio_data_cb, (void *)g_player[0]);
988         }
989 #endif
990 }
991
992 static void feed_video_data_thread_func(void *data)
993 {
994         while (!g_thread_end) {
995                 buffer_need_video_data_cb(1048576, NULL);
996                 buffer_need_audio_data_cb(1048576, NULL);
997         }
998 }
999
1000 static void _player_prepare(bool async)
1001 {
1002         int ret = FALSE;
1003         int slen = strlen(g_subtitle_uri);
1004
1005         if (slen > 0 && slen < MAX_STRING_LEN) {
1006                 g_print("0. set subtile path() (size : %d) - %s  \n", slen, g_subtitle_uri);
1007                 player_set_subtitle_path(g_player[0], g_subtitle_uri);
1008         }
1009         player_set_subtitle_updated_cb(g_player[0], subtitle_updated_cb, (void *)g_player[0]);
1010         if (g_current_surface_type == -1) {
1011                 g_print("You must set display surface type before setting prepare.\n");
1012                 return;
1013         }
1014
1015         if (g_current_surface_type == PLAYER_DISPLAY_TYPE_OVERLAY) {
1016                 player_set_buffering_cb(g_player[0], buffering_cb, (void *)g_player[0]);
1017                 player_set_completed_cb(g_player[0], completed_cb, (void *)g_player[0]);
1018                 player_set_interrupted_cb(g_player[0], interrupted_cb, (void *)g_player[0]);
1019                 player_set_error_cb(g_player[0], error_cb, (void *)g_player[0]);
1020                 player_set_video_stream_changed_cb(g_player[0], video_changed_cb, (void *)g_player[0]);
1021                 if (g_memory_playback)
1022                         player_set_memory_buffer_test();
1023                 else
1024                         player_set_uri(g_player[0], g_uri);
1025         } else {
1026                 int i = 0;
1027                 for (i = 0; i < g_handle_num; i++) {
1028                         player_set_buffering_cb(g_player[i], buffering_cb, (void *)g_player[i]);
1029                         player_set_completed_cb(g_player[i], completed_cb, (void *)g_player[i]);
1030                         player_set_interrupted_cb(g_player[i], interrupted_cb, (void *)g_player[i]);
1031                         player_set_error_cb(g_player[i], error_cb, (void *)g_player[i]);
1032                         player_set_video_stream_changed_cb(g_player[0], video_changed_cb, (void *)g_player[0]);
1033                         if (g_memory_playback)
1034                                 player_set_memory_buffer_test();
1035                         else
1036                                 player_set_uri(g_player[i], g_uri);
1037                 }
1038         }
1039
1040         if (strstr(g_uri, "es_buff://")) {
1041                 is_es_push_mode = FALSE;
1042                 video_packet_count = 0;
1043                 audio_packet_count = 0;
1044
1045                 if (strstr(g_uri, "es_buff://push_mode")) {
1046                         set_content_info(TRUE);
1047                         async = TRUE;
1048                         is_es_push_mode = TRUE;
1049 #ifdef _ES_PULL_
1050                 } else {
1051                         set_content_info(FALSE);
1052 #endif
1053                 }
1054         }
1055
1056         if (g_current_surface_type == PLAYER_DISPLAY_TYPE_OVERLAY) {
1057                 if (async)
1058                         ret = player_prepare_async(g_player[0], prepared_cb, (void *)g_player[0]);
1059                 else
1060                         ret = player_prepare(g_player[0]);
1061         } else {
1062                 int i = 0;
1063                 for (i = 0; i < g_handle_num; i++) {
1064                         if (async)
1065                                 ret = player_prepare_async(g_player[i], prepared_cb, (void *)g_player[i]);
1066                         else
1067                                 ret = player_prepare(g_player[i]);
1068                 }
1069         }
1070
1071         if (ret != PLAYER_ERROR_NONE)
1072                 g_print("prepare is failed (errno = %d) \n", ret);
1073
1074         player_state_e state;
1075         if (g_current_surface_type == PLAYER_DISPLAY_TYPE_OVERLAY) {
1076                 ret = player_get_state(g_player[0], &state);
1077                 g_print("After player_prepare() - Current State : %d \n", state);
1078         } else {
1079                 int i = 0;
1080                 for (i = 0; i < g_handle_num; i++) {
1081                         ret = player_get_state(g_player[i], &state);
1082                         g_print("After player_prepare() - Current State : %d \n", state);
1083                 }
1084         }
1085
1086         if (is_es_push_mode)
1087                 pthread_create(&g_feed_video_thread_id, NULL, (void *)feed_video_data_thread_func, NULL);
1088
1089 #ifdef USE_EVENT_HANDLER
1090         event_handler_set_dov_fov();
1091 #endif
1092 }
1093
1094 static void _player_unprepare()
1095 {
1096         int ret = FALSE;
1097         int i = 0;
1098         if (g_current_surface_type == PLAYER_DISPLAY_TYPE_OVERLAY) {
1099                 ret = player_unprepare(g_player[0]);
1100                 if (ret != PLAYER_ERROR_NONE)
1101                         g_print("unprepare is failed (errno = %d) \n", ret);
1102
1103                 ret = player_unset_subtitle_updated_cb(g_player[0]);
1104                 g_print("player_unset_subtitle_updated_cb ret %d\n", ret);
1105
1106                 ret = player_unset_buffering_cb(g_player[0]);
1107                 g_print("player_unset_buffering_cb ret %d\n", ret);
1108
1109                 ret = player_unset_completed_cb(g_player[0]);
1110                 g_print("player_unset_completed_cb ret %d\n", ret);
1111
1112                 ret = player_unset_interrupted_cb(g_player[0]);
1113                 g_print("player_unset_interrupted_cb ret %d\n", ret);
1114
1115                 ret = player_unset_error_cb(g_player[0]);
1116                 g_print("player_unset_error_cb ret %d\n", ret);
1117         } else {
1118                 for (i = 0; i < g_handle_num; i++) {
1119                         if (g_player[i] != NULL) {
1120                                 ret = player_unprepare(g_player[i]);
1121                                 if (ret != PLAYER_ERROR_NONE)
1122                                         g_print("unprepare is failed (errno = %d) \n", ret);
1123
1124                                 ret = player_unset_subtitle_updated_cb(g_player[i]);
1125                                 g_print("player_unset_subtitle_updated_cb [%d] ret %d\n", i, ret);
1126
1127                                 ret = player_unset_buffering_cb(g_player[i]);
1128                                 g_print("player_unset_buffering_cb [%d] ret %d\n", i, ret);
1129
1130                                 ret = player_unset_completed_cb(g_player[i]);
1131                                 g_print("player_unset_completed_cb [%d] ret %d\n", i, ret);
1132
1133                                 ret = player_unset_interrupted_cb(g_player[i]);
1134                                 g_print("player_unset_interrupted_cb [%d] ret %d\n", i, ret);
1135
1136                                 ret = player_unset_error_cb(g_player[i]);
1137                                 g_print("player_unset_error_cb [%d] ret %d\n", i, ret);
1138                         }
1139                 }
1140         }
1141
1142         memset(g_subtitle_uri, 0, sizeof(g_subtitle_uri));
1143         player_state_e state;
1144         if (g_current_surface_type == PLAYER_DISPLAY_TYPE_OVERLAY) {
1145                 ret = player_get_state(g_player[0], &state);
1146                 g_print(" After player_unprepare() - Current State : %d \n", state);
1147         } else {
1148                 for (i = 0; i < g_handle_num; i++) {
1149                         ret = player_get_state(g_player[i], &state);
1150                         g_print(" After player_unprepare() - Current State : %d \n", state);
1151                 }
1152         }
1153 }
1154
1155 static void _player_destroy()
1156 {
1157         int i = 0;
1158
1159         if (g_current_surface_type == PLAYER_DISPLAY_TYPE_OVERLAY) {
1160                 player_destroy(g_player[0]);
1161                 g_player[0] = 0;
1162         } else {
1163                 for (i = 0; i < g_handle_num; i++) {
1164                         if (g_player[i] != NULL) {
1165                                 player_unprepare(g_player[i]);
1166                                 player_destroy(g_player[i]);
1167                                 g_player[i] = 0;
1168                         }
1169                 }
1170         }
1171
1172         if (g_stream_info_h) {
1173                 sound_manager_destroy_stream_information(g_stream_info_h);
1174                 g_stream_info_h = NULL;
1175         }
1176
1177         if (g_video_pkt)
1178                 media_packet_destroy(g_video_pkt);
1179
1180         if (g_audio_pkt)
1181                 media_packet_destroy(g_audio_pkt);
1182
1183 #if DUMP_OUTBUF
1184         GList *list = NULL;
1185         audio_pcm_dump_t *a_data = NULL;
1186
1187         list = audio_dump_list;
1188         while(list) {
1189                 a_data = (audio_pcm_dump_t *)list->data;
1190                 list = g_list_next(list);
1191                 if (a_data && a_data->fp_out)
1192                                 fclose(a_data->fp_out);
1193                 g_free(a_data);
1194         }
1195         g_list_free(audio_dump_list);
1196         audio_dump_list = NULL;
1197
1198         if (fp_out1)
1199                 fclose(fp_out1);
1200         if (fp_out2)
1201                 fclose(fp_out2);
1202 #endif
1203
1204 }
1205
1206 static void _player_play()
1207 {
1208         int bRet = FALSE;
1209         int i = 0;
1210         if (g_current_surface_type == PLAYER_DISPLAY_TYPE_OVERLAY) {
1211 #ifdef _ACTIVATE_EOM_
1212                 /* for checking external display.... */
1213                 player_set_display(g_player[0], g_current_surface_type, GET_DISPLAY(selected_win_id));
1214 #endif
1215                 bRet = player_start(g_player[0]);
1216                 g_print("player_start returned [%d]", bRet);
1217         } else {
1218                 for (i = 0; i < g_handle_num; i++) {
1219                         bRet = player_start(g_player[i]);
1220                         g_print("player_start returned [%d]", bRet);
1221                 }
1222         }
1223 }
1224
1225 static void _player_stop()
1226 {
1227         int bRet = FALSE;
1228         int i = 0;
1229         if (g_current_surface_type == PLAYER_DISPLAY_TYPE_OVERLAY) {
1230                 bRet = player_stop(g_player[0]);
1231                 g_print("player_stop returned [%d]", bRet);
1232         } else {
1233                 for (i = 0; i < g_handle_num; i++) {
1234                         bRet = player_stop(g_player[i]);
1235                         g_print("player_stop returned [%d]", bRet);
1236                 }
1237         }
1238
1239         g_thread_end = TRUE;
1240         if (g_feed_video_thread_id) {
1241                 pthread_join(g_feed_video_thread_id, NULL);
1242                 g_feed_video_thread_id = 0;
1243         }
1244
1245 }
1246
1247 static void _player_resume()
1248 {
1249         int bRet = FALSE;
1250         int i = 0;
1251         if (g_current_surface_type == PLAYER_DISPLAY_TYPE_OVERLAY) {
1252 #ifdef _ACTIVATE_EOM_
1253                 /* for checking external display.... */
1254                 player_set_display(g_player[0], PLAYER_DISPLAY_TYPE_OVERLAY, GET_DISPLAY(selected_win_id));
1255 #endif
1256                 bRet = player_start(g_player[0]);
1257                 g_print("player_start returned [%d]", bRet);
1258         } else {
1259                 for (i = 0; i < g_handle_num; i++) {
1260                         bRet = player_start(g_player[i]);
1261                         g_print("player_start returned [%d]", bRet);
1262                 }
1263         }
1264 }
1265
1266 static void _player_pause()
1267 {
1268         int bRet = FALSE;
1269         int i = 0;
1270         if (g_current_surface_type == PLAYER_DISPLAY_TYPE_OVERLAY) {
1271                 bRet = player_pause(g_player[0]);
1272                 g_print("player_pause returned [%d]", bRet);
1273         } else {
1274                 for (i = 0; i < g_handle_num; i++) {
1275                         bRet = player_pause(g_player[i]);
1276                         g_print("player_pause returned [%d]", bRet);
1277                 }
1278         }
1279 }
1280
1281 static void _player_state()
1282 {
1283         player_state_e state;
1284         player_get_state(g_player[0], &state);
1285         g_print("                                                            ==> [Player_Test] Current Player State : %d\n", state);
1286 }
1287
1288 static void _player_enable_tsurf_pool(void)
1289 {
1290         bool enabled = FALSE;
1291
1292         if (TIZEN_TV) {
1293                 g_print("not support at TV profile");
1294                 return;
1295         }
1296
1297         player_is_enabled_tsurf_pool(g_player[0], &enabled);
1298
1299         g_print("tbm surface pool will be %s", (enabled) ? "disabled" : "enabled");
1300         player_enable_tsurf_pool(g_player[0], !enabled);
1301 }
1302
1303 static void set_next_uri(char *uri)
1304 {
1305         if (TIZEN_TV) {
1306                 g_print("not support at TV profile");
1307                 return;
1308         }
1309
1310         if (player_set_next_uri(g_player[0], uri) != PLAYER_ERROR_NONE)
1311                 g_print("fail to set next uri");
1312 }
1313
1314 static void get_next_uri()
1315 {
1316         char *uri;
1317
1318         if (TIZEN_TV) {
1319                 g_print("not support at TV profile");
1320                 return;
1321         }
1322
1323         if (player_get_next_uri(g_player[0], &uri) != PLAYER_ERROR_NONE) {
1324                 g_print("fail to get next uri");
1325                 return;
1326         }
1327
1328         if (uri != NULL) {
1329                 g_print("next_uri = %s", uri);
1330                 free(uri);
1331         }
1332 }
1333
1334 static void set_volume(float volume)
1335 {
1336         if (player_set_volume(g_player[0], volume, volume) != PLAYER_ERROR_NONE)
1337                 g_print("failed to set volume\n");
1338 }
1339
1340 static void get_volume(float *left, float *right)
1341 {
1342         player_get_volume(g_player[0], left, right);
1343         g_print("                                                            ==> [Player_Test] volume - left : %f, right : %f\n", *left, *right);
1344 }
1345
1346 static void set_mute(bool mute)
1347 {
1348         if (player_set_mute(g_player[0], mute) != PLAYER_ERROR_NONE)
1349                 g_print("failed to set_mute\n");
1350 }
1351
1352 static void get_mute(bool *mute)
1353 {
1354         player_is_muted(g_player[0], mute);
1355         g_print("                                                            ==> [Player_Test] mute = %d\n", *mute);
1356 }
1357
1358 void focus_callback(sound_stream_info_h stream_info,
1359                                         sound_stream_focus_mask_e focus_mask,
1360                                         sound_stream_focus_state_e focus_state,
1361                                         sound_stream_focus_change_reason_e reason,
1362                                         int sound_behavior,
1363                                         const char *extra_info,
1364                                         void *user_data)
1365 {
1366         g_print("FOCUS callback is called, reason(%d), extra_info(%s), userdata(%p)", reason, extra_info, user_data);
1367         return;
1368 }
1369
1370 static void set_sound_stream_info(int type)
1371 {
1372         sound_device_list_h device_list = NULL;
1373         int ret = SOUND_MANAGER_ERROR_NONE;
1374
1375         if (g_stream_info_h) {
1376                 g_print("stream information is already set, please destory handle and try again\n");
1377                 return;
1378         }
1379         if (sound_manager_create_stream_information(type, focus_callback, g_player[0], &g_stream_info_h)) {
1380                 g_print("failed to create stream_information()\n");
1381                 return;
1382         }
1383         /* In case of MEDIA_EXTERNAL_ONLY, we need to set external device manually */
1384         if (type == (int)SOUND_STREAM_TYPE_MEDIA_EXTERNAL_ONLY) {
1385                 sound_device_h device = NULL;
1386                 sound_device_type_e device_type;
1387
1388                 if ((ret = sound_manager_get_device_list(SOUND_DEVICE_ALL_MASK, &device_list))) {
1389                         g_print("failed to sound_manager_get_device_list(), ret(0x%x)\n", ret);
1390                         goto END;
1391                 }
1392                 while (!(ret = sound_manager_get_next_device(device_list, &device))) {
1393                         if ((ret = sound_manager_get_device_type(device, &device_type))) {
1394                                 g_print("failed to sound_manager_get_device_type(), ret(0x%x)\n", ret);
1395                                 goto END;
1396                         }
1397                         if (device_type == SOUND_DEVICE_BLUETOOTH_MEDIA || device_type == SOUND_DEVICE_USB_AUDIO) {
1398                                 if ((ret = sound_manager_add_device_for_stream_routing(g_stream_info_h, device))) {
1399                                         g_print("failed to sound_manager_add_device_for_stream_routing(), ret(0x%x)\n", ret);
1400                                         goto END;
1401                                 }
1402                                 if ((ret = sound_manager_apply_stream_routing(g_stream_info_h))) {
1403                                         g_print("failed to sound_manager_apply_stream_routing(), ret(0x%x)\n", ret);
1404                                         goto END;
1405                                 }
1406                                 break;
1407                         }
1408                 }
1409                 if (ret != SOUND_MANAGER_ERROR_NONE) {
1410                         g_print("failed to sound_manager_get_next_device(), ret(0x%x)\n", ret);
1411                         goto END;
1412                 }
1413         }
1414
1415         if (player_set_sound_stream_info(g_player[0], g_stream_info_h) != PLAYER_ERROR_NONE)
1416                 g_print("failed to set sound stream information(%p)\n", g_stream_info_h);
1417         else
1418                 g_print("set stream information(%p) success", g_stream_info_h);
1419
1420 END:
1421         if (device_list)
1422                 sound_manager_free_device_list(device_list);
1423         return;
1424 }
1425
1426 void variant_cb(int bandwidth, int width, int height, void *user_data)
1427 {
1428         g_print("                                                            ==> [Player_Test][b]%d, [w]%d, [h]%d\n", bandwidth, width, height);
1429 }
1430
1431 static void get_variant_info()
1432 {
1433         player_foreach_adaptive_variant(g_player[0], (player_adaptive_variant_cb)variant_cb, g_player[0]);
1434 }
1435
1436 static void get_variant_limit()
1437 {
1438         int bandwidth, width, height;
1439         player_get_max_adaptive_variant_limit(g_player[0], &bandwidth, &width, &height);
1440         g_print("                                                            ==> [Player_Test]get [b]%d, [w]%d, [h]%d\n", bandwidth, width, height);
1441 }
1442
1443 static void set_variant_limit(int bandwidth, int width, int height)
1444 {
1445         g_print("                                                            ==> [Player_Test]set [b]%d, [w]%d, [h]%d\n", bandwidth, width, height);
1446         player_set_max_adaptive_variant_limit(g_player[0], bandwidth, width, height);
1447 }
1448
1449 static void set_buffer_size(int prebuffer, int rebuffer)
1450 {
1451         int ret = 0;
1452         int buffer_ms = 0, rebuffer_ms = 0;
1453
1454         ret = player_get_streaming_buffering_time(g_player[0], &buffer_ms, &rebuffer_ms);
1455         if (ret != PLAYER_ERROR_NONE)
1456                 g_print("failed to get buffering time. 0x%X\n", ret);
1457         else
1458                 g_print("current buffer size %d ms / %d ms\n", buffer_ms, rebuffer_ms);
1459
1460         ret = player_set_streaming_buffering_time(g_player[0], prebuffer, rebuffer);
1461         if (ret != PLAYER_ERROR_NONE)
1462                 g_print("failed to set buffering time. 0x%X\n", ret);
1463         else
1464                 g_print("new buffer size %d ms / %d ms\n", prebuffer, rebuffer);
1465 }
1466
1467 static void get_buffering_position()
1468 {
1469         int ret;
1470         int start = 0, end = 0;
1471         ret = player_get_streaming_download_progress(g_player[0], &start, &end);
1472         g_print("                                                            ==> [Player_Test] buffering pos ()%d return : %d ~ %d\n", ret, start, end);
1473 }
1474
1475 static void get_position()
1476 {
1477         int position = 0;
1478         int ret;
1479         ret = player_get_play_position(g_player[0], &position);
1480         g_print("                                                            ==> [Player_Test] player_get_play_position()%d return : %d\n", ret, position);
1481 }
1482
1483 static void set_position(int position, bool accurate)
1484 {
1485         if (player_set_play_position(g_player[0], position, accurate, seek_completed_cb, g_player[0]) != PLAYER_ERROR_NONE)
1486                 g_print("failed to set position\n");
1487 }
1488
1489 static void set_playback_rate(float rate, bool streaming)
1490 {
1491         if (streaming) {
1492                 if (player_set_streaming_playback_rate(g_player[0], rate) != PLAYER_ERROR_NONE)
1493                         g_print("failed to set streaming playback rate\n");
1494         } else {
1495                 if (player_set_playback_rate(g_player[0], rate) != PLAYER_ERROR_NONE)
1496                         g_print("failed to set playback rate\n");
1497         }
1498 }
1499
1500 static void get_duration()
1501 {
1502         int duration = 0;
1503         int ret;
1504         ret = player_get_duration(g_player[0], &duration);
1505         g_print("                                                            ==> [Player_Test] player_get_duration() return : %d\n", ret);
1506         g_print("                                                            ==> [Player_Test] Duration: [%d ] msec\n", duration);
1507 }
1508
1509 static void set_video_codec_type(int codec_type)
1510 {
1511         int ret;
1512
1513         ret = player_set_video_codec_type_ex(g_player[0], codec_type);
1514         g_print("                                                            ==> [Player_Test] video codec type (%d) return: %d\n", codec_type, ret);
1515
1516 }
1517
1518 static void set_audio_codec_type(int codec_type)
1519 {
1520         int ret;
1521
1522         ret = player_set_audio_codec_type(g_player[0], codec_type);
1523         g_print("                                                            ==> [Player_Test] audio codec type (%d) return: %d\n", codec_type, ret);
1524
1525 }
1526
1527 static void get_codec_type(int stream_type)
1528 {
1529         int ret;
1530         int type = 0;
1531
1532         if (stream_type == 1) {
1533                 player_video_codec_type_ex_e vtype = PLAYER_VIDEO_CODEC_TYPE_EX_DEFAULT;
1534                 ret = player_get_video_codec_type_ex(g_player[0], &vtype);
1535                 type = vtype;
1536         } else {
1537                 player_codec_type_e atype = PLAYER_CODEC_TYPE_SW;
1538                 ret = player_get_audio_codec_type(g_player[0], &atype);
1539                 type = atype;
1540         }
1541         g_print("                                                            ==> [Player_Test] Codec type: [%d][ret 0x%X]\n", type, ret);
1542 }
1543
1544 static void get_stream_info()
1545 {
1546         int w = 0;
1547         int h = 0;
1548
1549         char *value = NULL;
1550         player_get_content_info(g_player[0], PLAYER_CONTENT_INFO_ALBUM, &value);
1551         g_print("                                                            ==> [Player_Test] PLAYER_CONTENT_INFO_ALBUM: [%s ] \n", value);
1552         player_get_content_info(g_player[0], PLAYER_CONTENT_INFO_ARTIST, &value);
1553         g_print("                                                            ==> [Player_Test] PLAYER_CONTENT_INFO_ARTIST: [%s ] \n", value);
1554         player_get_content_info(g_player[0], PLAYER_CONTENT_INFO_AUTHOR, &value);
1555         g_print("                                                            ==> [Player_Test] PLAYER_CONTENT_INFO_AUTHOR: [%s ] \n", value);
1556         player_get_content_info(g_player[0], PLAYER_CONTENT_INFO_GENRE, &value);
1557         g_print("                                                            ==> [Player_Test] PLAYER_CONTENT_INFO_GENRE: [%s ] \n", value);
1558         player_get_content_info(g_player[0], PLAYER_CONTENT_INFO_TITLE, &value);
1559         g_print("                                                            ==> [Player_Test] PLAYER_CONTENT_INFO_TITLE: [%s ] \n", value);
1560         void *album;
1561         int size;
1562         player_get_album_art(g_player[0], &album, &size);
1563         g_print("                                                            ==> [Player_Test] Album art : [ data : %p, size : %d ]\n", (unsigned int *)album, size);
1564         _save(album, size);
1565         if (value != NULL) {
1566                 free(value);
1567                 value = NULL;
1568         }
1569
1570         int sample_rate;
1571         int channel;
1572         int bit_rate;
1573         int fps, v_bit_rate;
1574         player_get_audio_stream_info(g_player[0], &sample_rate, &channel, &bit_rate);
1575         g_print("                                                            ==> [Player_Test] Sample Rate: [%d ] , Channel: [%d ] , Bit Rate: [%d ] \n", sample_rate, channel, bit_rate);
1576
1577         player_get_video_stream_info(g_player[0], &fps, &v_bit_rate);
1578         g_print("                                                            ==> [Player_Test] fps: [%d ] , Bit Rate: [%d ] \n", fps, v_bit_rate);
1579
1580         char *audio_codec = NULL;
1581         char *video_codec = NULL;
1582         player_get_codec_info(g_player[0], &audio_codec, &video_codec);
1583         if (audio_codec != NULL) {
1584                 g_print("                                                            ==> [Player_Test] Audio Codec: [%s ] \n", audio_codec);
1585                 free(audio_codec);
1586                 audio_codec = NULL;
1587         }
1588         if (video_codec != NULL) {
1589                 g_print("                                                            ==> [Player_Test] Video Codec: [%s ] \n", video_codec);
1590                 free(video_codec);
1591                 video_codec = NULL;
1592         }
1593         player_get_video_size(g_player[0], &w, &h);
1594         g_print("                                                            ==> [Player_Test] Width: [%d ] , Height: [%d ] \n", w, h);
1595 }
1596
1597 static void set_gapless(bool gapless)
1598 {
1599         if (TIZEN_TV) {
1600                 g_print("not support at TV profile");
1601                 return;
1602         }
1603
1604         if (g_current_surface_type == PLAYER_DISPLAY_TYPE_OVERLAY) {
1605                 if (player_set_gapless(g_player[0], gapless) != PLAYER_ERROR_NONE)
1606                         g_print("failed set_gapless\n");
1607         } else {
1608                 int i = 0;
1609                 for (i = 0; i < g_handle_num; i++) {
1610                         if (player_set_gapless(g_player[i], gapless) != PLAYER_ERROR_NONE)
1611                                 g_print("failed to set_gapless\n");
1612                 }
1613         }
1614 }
1615
1616 static void set_looping(bool looping)
1617 {
1618         if (g_current_surface_type == PLAYER_DISPLAY_TYPE_OVERLAY) {
1619                 if (player_set_looping(g_player[0], looping) != PLAYER_ERROR_NONE)
1620                         g_print("failed to set_looping\n");
1621         } else {
1622                 int i = 0;
1623                 for (i = 0; i < g_handle_num; i++) {
1624                         if (player_set_looping(g_player[i], looping) != PLAYER_ERROR_NONE)
1625                                 g_print("failed to set_looping\n");
1626                 }
1627         }
1628 }
1629
1630 static void get_looping(bool *looping)
1631 {
1632         player_is_looping(g_player[0], looping);
1633         g_print("                                                            ==> [Player_Test] looping = %d\n", *looping);
1634 }
1635
1636 void _video_decoded_cb(media_packet_h packet, void *user_data)
1637 {
1638         media_packet_destroy(packet);
1639 }
1640
1641 static void set_video_frame_decoded_cb(void)
1642 {
1643         player_set_media_packet_video_frame_decoded_cb(g_player[0], _video_decoded_cb, g_player[0]);
1644 }
1645
1646 void _audio_decoded_cb(media_packet_h packet, void *user_data)
1647 {
1648         int mime, channel, rate;
1649         uint64_t channel_mask;
1650         uint64_t size;
1651         void *pkt_data;
1652
1653         if (!packet) {
1654                 g_print("invalid packet param");
1655                 return;
1656         }
1657
1658         media_packet_get_format(packet, &g_audio_fmt);
1659         media_format_get_audio_info(g_audio_fmt, (media_format_mimetype_e *)&mime, &channel, &rate, NULL, NULL);
1660         media_format_get_audio_channel_mask(g_audio_fmt, &channel_mask);
1661         media_packet_get_buffer_data_ptr(packet, &pkt_data);
1662         media_packet_get_buffer_size(packet, &size);
1663
1664         g_print("[ received ] channel: %d size: %"G_GUINT64_FORMAT", mask %"G_GUINT64_FORMAT"\n", channel, size, channel_mask);
1665
1666 #if DUMP_OUTBUF
1667         GList *list = NULL;
1668         audio_pcm_dump_t *a_data = NULL;
1669         FILE *fp_dump = NULL;
1670         char file_path[32];
1671
1672         list = audio_dump_list;
1673         while(list) {
1674                 a_data = (audio_pcm_dump_t *)list->data;
1675                 list = g_list_next(list);
1676
1677                 if (a_data && a_data->mask == channel_mask) {
1678                         fp_dump = a_data->fp_out;
1679                         break;
1680                 }
1681         }
1682
1683         a_data = NULL;
1684         if (!fp_dump) {
1685                 a_data = g_try_malloc(sizeof(audio_pcm_dump_t));
1686                 if (a_data == NULL) {
1687                         g_print("failed to malloc");
1688                         goto EXIT;
1689                 }
1690
1691                 snprintf(file_path, 32, "/tmp/out%"G_GUINT64_FORMAT".pcm", channel_mask);
1692
1693                 a_data->mask = channel_mask;
1694                 a_data->fp_out = fopen(file_path, "wb");
1695                 if (!a_data->fp_out) {
1696                         g_free(a_data);
1697                         g_print("[ERROR] failed to open file\n");
1698                         goto EXIT;
1699                 }
1700
1701                 audio_dump_list = g_list_append(audio_dump_list, a_data);
1702                 fp_dump = a_data->fp_out;
1703         }
1704
1705         fwrite((guint8 *)pkt_data, 1, size, fp_dump);
1706 #endif
1707
1708 EXIT:
1709         media_packet_destroy(packet);
1710 }
1711
1712 static media_format_mimetype_e __convert_audio_pcm_str_to_media_format_mime(char *audio_pcm_str)
1713 {
1714         int len = strlen("S16LE");
1715         if (!audio_pcm_str) {
1716                 g_print("audio pcm str is NULL\n");
1717                 return MEDIA_FORMAT_MAX;
1718         }
1719
1720         if (!strncasecmp(audio_pcm_str, "S16LE", len))
1721                 return MEDIA_FORMAT_PCM_S16LE;
1722         else if (!strncasecmp(audio_pcm_str, "S24LE", len))
1723                 return MEDIA_FORMAT_PCM_S24LE;
1724         else if (!strncasecmp(audio_pcm_str, "S32LE", len))
1725                 return MEDIA_FORMAT_PCM_S32LE;
1726         else if (!strncasecmp(audio_pcm_str, "S16BE", len))
1727                 return MEDIA_FORMAT_PCM_S16BE;
1728         else if (!strncasecmp(audio_pcm_str, "S24BE", len))
1729                 return MEDIA_FORMAT_PCM_S24BE;
1730         else if (!strncasecmp(audio_pcm_str, "S32BE", len))
1731                 return MEDIA_FORMAT_PCM_S32BE;
1732         else if (!strncasecmp(audio_pcm_str, "F32LE", len))
1733                 return MEDIA_FORMAT_PCM_F32LE;
1734         else if (!strncasecmp(audio_pcm_str, "F32BE", len))
1735                 return MEDIA_FORMAT_PCM_F32BE;
1736         else if (!strncasecmp(audio_pcm_str, "U16LE", len))
1737                 return MEDIA_FORMAT_PCM_U16LE;
1738         else if (!strncasecmp(audio_pcm_str, "U24LE", len))
1739                 return MEDIA_FORMAT_PCM_U24LE;
1740         else if (!strncasecmp(audio_pcm_str, "U32LE", len))
1741                 return MEDIA_FORMAT_PCM_U32LE;
1742         else if (!strncasecmp(audio_pcm_str, "U16BE", len))
1743                 return MEDIA_FORMAT_PCM_U16BE;
1744         else if (!strncasecmp(audio_pcm_str, "U24BE", len))
1745                 return MEDIA_FORMAT_PCM_U24BE;
1746         else if (!strncasecmp(audio_pcm_str, "U32BE", len))
1747                 return MEDIA_FORMAT_PCM_U32BE;
1748         else {
1749                 g_print("Not supported audio pcm format str : %s\n", audio_pcm_str);
1750                 return MEDIA_FORMAT_MAX;
1751         }
1752 }
1753
1754 static void set_audio_frame_decoded_cb(player_audio_extract_option_e opt, char* mime, int ch, int rate)
1755 {
1756         media_format_mimetype_e type = __convert_audio_pcm_str_to_media_format_mime(mime);
1757
1758         if (type == MEDIA_FORMAT_MAX) {
1759                 g_print("failed to convert the mime : %s\n", mime);
1760                 return;
1761         }
1762
1763         media_format_create(&g_audio_fmt);
1764         media_format_set_audio_mime(g_audio_fmt, type);
1765         media_format_set_audio_channel(g_audio_fmt, ch);
1766         media_format_set_audio_samplerate(g_audio_fmt, rate);
1767
1768         g_print("==========> [Player_Test] option = 0x%X, %s(%d), %d, %d\n", opt, mime, type, ch, rate);
1769         player_set_media_packet_audio_frame_decoded_cb(g_player[0], g_audio_fmt, opt, _audio_decoded_cb, g_player[0]);
1770
1771         media_format_unref(g_audio_fmt);
1772         g_audio_fmt = NULL;
1773 }
1774
1775 static void change_surface(int option)
1776 {
1777         player_display_type_e surface_type = 0;
1778         int ret = PLAYER_ERROR_NONE;
1779 #ifdef _ACTIVATE_EOM_
1780         int hdmi_output_id;
1781         eom_output_mode_e output_mode;
1782 #endif
1783         switch (option) {
1784         case 0:
1785                 /* X surface */
1786                 surface_type = PLAYER_DISPLAY_TYPE_OVERLAY;
1787                 g_print("change surface type to X\n");
1788                 break;
1789 #ifdef TIZEN_FEATURE_EVAS_RENDERER
1790         case 1:
1791                 /* EVAS surface */
1792                 surface_type = PLAYER_DISPLAY_TYPE_EVAS;
1793                 g_print("change surface type to EVAS\n");
1794                 break;
1795 #endif
1796         case 2:
1797                 g_print("change surface type to NONE\n");
1798                 surface_type = g_current_surface_type = PLAYER_DISPLAY_TYPE_NONE;
1799                 player_set_display(g_player[0], PLAYER_DISPLAY_TYPE_NONE, NULL);
1800                 break;
1801         default:
1802                 g_print("invalid surface type\n");
1803                 return;
1804         }
1805
1806         player_state_e player_state = PLAYER_STATE_NONE;
1807         ret = player_get_state(g_player[0], &player_state);
1808         if (ret)
1809                 g_print("failed to player_get_state(), ret(0x%x)\n", ret);
1810 #ifdef NO_USE_CODE
1811         reset_display();
1812 #endif
1813         if (surface_type == PLAYER_DISPLAY_TYPE_OVERLAY) {
1814 #ifdef _ACTIVATE_EOM_
1815                 hdmi_output_id = eom_get_output_id("HDMI");
1816                 if (hdmi_output_id == 0)
1817                         g_print("[eom] error : HDMI output id is NULL.\n");
1818
1819                 eom_get_output_mode(hdmi_output_id, &output_mode);
1820                 if (output_mode == EOM_OUTPUT_MODE_NONE) {
1821 #endif
1822                         if (!g_win_id) {
1823                                 g_win_id = create_win(PACKAGE);
1824                                 if (g_win_id == NULL)
1825                                         return;
1826                                 g_print("create win_id %p\n", g_win_id);
1827                                 create_render_rect_and_bg(g_win_id);
1828                                 elm_win_activate(g_win_id);
1829                                 evas_object_show(g_win_id);
1830                                 g_win_id = selected_win_id;
1831                         }
1832 #ifdef _ACTIVATE_EOM_
1833                 } else {
1834                         /* for external */
1835                 }
1836 #endif
1837                 ret = player_set_display(g_player[0], surface_type, GET_DISPLAY(selected_win_id));
1838         } else {
1839                 if (!g_win_id) {
1840                         g_win_id = create_win(PACKAGE);
1841                         if (g_win_id == NULL)
1842                                 return;
1843                         g_print("create win_id %p\n", g_win_id);
1844                         create_render_rect_and_bg(g_win_id);
1845                         elm_win_activate(g_win_id);
1846                         evas_object_show(g_win_id);
1847                 }
1848                 if (surface_type == PLAYER_DISPLAY_TYPE_EVAS) {
1849                         /* surface type is PLAYER_DISPLAY_TYPE_NONE */
1850                         int i = 0;
1851                         for (i = 0; i < g_handle_num; i++) {
1852                                 /* Create evas image object for EVAS surface */
1853                                 if (!g_eo[i]) {
1854                                         g_eo[i] = create_image_object(g_win_id);
1855                                         g_print("create eo[%d] %p\n", i, g_eo[i]);
1856                                         evas_object_image_size_set(g_eo[i], 500, 500);
1857                                         evas_object_image_fill_set(g_eo[i], 0, 0, 500, 500);
1858                                         evas_object_resize(g_eo[i], 500, 500);
1859                                         evas_object_move(g_eo[i], i * 20, i * 20);
1860                                 }
1861                                 ret = player_set_display(g_player[i], surface_type, g_eo[i]);
1862
1863                         }
1864                 } else {
1865                         g_print("surface type is PLAYER_DISPLAY_TYPE_NONE\n");
1866                 }
1867         }
1868         if (ret) {
1869                 g_print("failed to set display, surface_type(%d)\n", surface_type);
1870                 return;
1871         }
1872         g_current_surface_type = surface_type;
1873         return;
1874 }
1875
1876 static void set_display_mode(int mode)
1877 {
1878         if (player_set_display_mode(g_player[0], mode) != PLAYER_ERROR_NONE)
1879                 g_print("failed to player_set_display_mode\n");
1880 }
1881
1882 static void get_display_mode()
1883 {
1884         player_display_mode_e mode;
1885         player_get_display_mode(g_player[0], &mode);
1886         g_print("                                                            ==> [Player_Test] Display mode: [%d ] \n", mode);
1887 }
1888
1889 static void set_display_roi_area(int x, int y, int width, int height)
1890 {
1891         player_set_display_roi_area(g_player[0], x, y, width, height);
1892         g_print("                                                            ==> [Player_Test] Display roi area: [x(%d) y(%d) width(%d) height(%d)] \n", x, y, width, height);
1893 }
1894
1895 static void set_display_rotation(int rotation)
1896 {
1897         if (player_set_display_rotation(g_player[0], rotation) != PLAYER_ERROR_NONE)
1898                 g_print("failed to set_display_rotation\n");
1899 #ifdef USE_EVENT_HANDLER
1900         event_handler_set_window_parameters();
1901 #endif
1902 }
1903
1904 static void get_display_rotation()
1905 {
1906         player_display_rotation_e rotation = 0;
1907         player_get_display_rotation(g_player[0], &rotation);
1908         g_print("                                                            ==> [Player_Test] Video Overlay Display rotation: [%d ] \n", rotation);
1909 }
1910
1911 static void set_display_visible(bool visible)
1912 {
1913         if (player_set_display_visible(g_player[0], visible) != PLAYER_ERROR_NONE)
1914                 g_print("failed to player_set_x11_display_visible\n");
1915 }
1916
1917 static void get_display_visible(bool *visible)
1918 {
1919         player_is_display_visible(g_player[0], visible);
1920         g_print("                                                            ==> [Player_Test] Video Overlay Display Visible = %d\n", *visible);
1921 }
1922
1923 static void input_subtitle_filename(char *subtitle_filename)
1924 {
1925         int len = strlen(subtitle_filename);
1926         gsize src_size = 0;
1927
1928         if (len < 1 || len > MAX_STRING_LEN - 1)
1929                 return;
1930
1931         src_size = g_strlcpy(g_subtitle_uri, subtitle_filename, MAX_STRING_LEN);
1932         if (src_size != len)
1933                 return;
1934
1935         g_print("subtitle uri is set to %s\n", g_subtitle_uri);
1936         player_set_subtitle_path(g_player[0], g_subtitle_uri);
1937         player_set_subtitle_updated_cb(g_player[0], subtitle_updated_cb, (void *)g_player[0]);
1938 }
1939
1940 static void set_track(int type, int index)
1941 {
1942         char *lang_code = NULL;
1943
1944         if (player_select_track(g_player[0], type, index) != PLAYER_ERROR_NONE)
1945                 g_print("player_select_track failed\n");
1946
1947         if (player_get_track_language_code(g_player[0], type, index, &lang_code) == PLAYER_ERROR_NONE) {
1948                 g_print("selected track lang code %s\n", lang_code);
1949                 free(lang_code);
1950         }
1951 }
1952
1953 static void get_track_info(int index)
1954 {
1955         int count = 0, cur_index = 0;
1956         int ret = 0;
1957         char *lang_code = NULL;
1958
1959         if (index != PLAYER_STREAM_TYPE_AUDIO &&
1960                 index != PLAYER_STREAM_TYPE_TEXT) {
1961                 g_print("invalid stream type %d", index);
1962                 return;
1963         }
1964
1965         ret = player_get_track_count(g_player[0], index, &count);
1966         if (ret != PLAYER_ERROR_NONE) {
1967                 g_print("player_get_track_count fail!!!!\n");
1968         } else if (count) {
1969                 int idx = 0;
1970                 player_get_current_track(g_player[0], index, &cur_index);
1971                 g_print("total track: %d, curr track: %d\n", count, cur_index);
1972
1973                 for (idx = 0; idx < count; idx++) {
1974                         player_get_track_language_code(g_player[0], index, idx, &lang_code);
1975                         g_print("track info = [%d] %s\n", idx, lang_code);
1976                 }
1977         } else {
1978                 g_print("no track\n");
1979         }
1980 }
1981
1982 static void capture_video()
1983 {
1984         if (player_capture_video(g_player[0], video_captured_cb, NULL) != PLAYER_ERROR_NONE)
1985                 g_print("failed to player_capture_video\n");
1986 }
1987
1988 static void set_audio_only(int val)
1989 {
1990         int ret = PLAYER_ERROR_NONE;
1991         bool audio_only = false;
1992         ret = player_is_audio_only(g_player[0], &audio_only);
1993         if (ret != PLAYER_ERROR_NONE)
1994                 g_print("failed to get current setting. 0x%X\n", ret);
1995         else
1996                 g_print("current audio only mode : %s\n", (audio_only) ? "enabled" : "disabled");
1997         g_print("new audio only mode : %s\n", (val != 0) ? "enabled" : "disabled");
1998
1999         if (val != 0)
2000                 ret = player_set_audio_only(g_player[0], true);
2001         else
2002                 ret = player_set_audio_only(g_player[0], false);
2003         g_print("finished 0x%X\n", ret);
2004 }
2005
2006 static void decoding_audio()
2007 {
2008 #if 0
2009         int ret;
2010         char *suffix, *dump_path;
2011         GDateTime *time = g_date_time_new_now_local();
2012
2013         suffix = g_date_time_format(time, "%Y%m%d_%H%M%S.pcm");
2014         dump_path = g_strjoin(NULL, PLAYER_TEST_DUMP_PATH_PREFIX, suffix, NULL);
2015         g_pcm_fd = fopen(dump_path, "w+");
2016         g_free(dump_path);
2017         g_free(suffix);
2018         g_date_time_unref(time);
2019         if (!g_pcm_fd)
2020                 g_print("Can not create debug dump file");
2021
2022         ret = player_set_audio_frame_decoded_cb(g_player[0], 0, 0, audio_frame_decoded_cb, (void *)g_player[0]);
2023         if (ret != PLAYER_ERROR_NONE)
2024                 g_print("player_set_audio_frame_decoded_cb is failed (errno = %d) \n", ret);
2025 #endif
2026 }
2027
2028 static void set_audio_eq(int value)
2029 {
2030         bool available = FALSE;
2031         int index, min = 0, max = 0;
2032
2033         if (value) {
2034                 if (player_audio_effect_equalizer_is_available(g_player[0], &available) != PLAYER_ERROR_NONE)
2035                         g_print("failed to player_audio_effect_equalizer_is_available\n");
2036
2037                 if (available) {
2038                         if ((player_audio_effect_get_equalizer_bands_count(g_player[0], &index) != PLAYER_ERROR_NONE) ||
2039                                 (player_audio_effect_get_equalizer_level_range(g_player[0], &min, &max) != PLAYER_ERROR_NONE) ||
2040                                 (player_audio_effect_set_equalizer_band_level(g_player[0], index / 2, max) != PLAYER_ERROR_NONE))
2041                                 g_print("failed to player_audio_effect_set_equalizer_band_level index %d, level %d\n", index / 2, max);
2042                 }
2043         } else {
2044                 if (player_audio_effect_equalizer_clear(g_player[0]) != PLAYER_ERROR_NONE)
2045                         g_print("failed to player_audio_effect_equalizer_clear\n");
2046         }
2047
2048 }
2049
2050 static void get_audio_eq()
2051 {
2052         int index, min, max, value;
2053         player_audio_effect_get_equalizer_bands_count(g_player[0], &index);
2054         g_print("                                                            ==> [Player_Test] eq bands count: [%d] \n", index);
2055         player_audio_effect_get_equalizer_level_range(g_player[0], &min, &max);
2056         g_print("                                                            ==> [Player_Test] eq bands range: [%d~%d] \n", min, max);
2057         player_audio_effect_get_equalizer_band_level(g_player[0], index / 2, &value);
2058         g_print("                                                            ==> [Player_Test] eq bands level: [%d] \n", value);
2059         player_audio_effect_get_equalizer_band_frequency(g_player[0], 0, &value);
2060         g_print("                                                            ==> [Player_Test] eq bands frequency: [%d] \n", value);
2061         player_audio_effect_get_equalizer_band_frequency_range(g_player[0], 0, &value);
2062         g_print("                                                            ==> [Player_Test] eq bands frequency range: [%d] \n", value);
2063 }
2064
2065 static void set_latency(int value)
2066 {
2067         int ret = PLAYER_ERROR_NONE;
2068
2069         if ((ret = player_set_audio_latency_mode(g_player[0], value)))
2070                 g_print("failed to player_set_audio_latency_mode, ret(0x%x)\n", ret);
2071 }
2072
2073 static void video360_is_spherical(void)
2074 {
2075         bool spherical;
2076
2077         if (player_360_is_content_spherical(g_player[0], &spherical) != PLAYER_ERROR_NONE)
2078                 g_print("failed to get content spherical info\n");
2079         else
2080                 g_print("                                                          ==> [Player_Test] Video 360 content = %s\n", spherical ? "spherical" : "---");
2081
2082 }
2083
2084 static void video360_set_enable(bool enable)
2085 {
2086         bool enabled = false;
2087
2088 #ifdef USE_EVENT_HANDLER
2089         event_handler_set_dov_fov();
2090 #endif
2091
2092         if (player_360_set_enabled(g_player[0], enable) != PLAYER_ERROR_NONE)
2093                 g_print("failed to %s video 360 mode\n", enable ? "enable" : "disable");
2094
2095         if (player_360_is_enabled(g_player[0], &enabled) != PLAYER_ERROR_NONE)
2096                 g_print("failed to get video 360 mode status\n");
2097         else
2098                 g_print("                                                          ==> [Player_Test] Video 360 mode = %s\n", enabled ? "enabled" : "disabled");
2099 }
2100
2101 static void video360_get_fov()
2102 {
2103         int hfov, vfov;
2104
2105         if (player_360_get_field_of_view(g_player[0], &hfov, &vfov) != PLAYER_ERROR_NONE)
2106                 g_print("failed to get video 360 field of view\n");
2107         else
2108                 g_print("                                                          ==> [Player_Test] Video 360 FOV = %dx%d deg.\n", hfov, vfov);
2109 }
2110
2111 static void video360_set_fov(int hfov, int vfov)
2112 {
2113 #ifdef USE_EVENT_HANDLER
2114         mm_navevent_handler_size_s fov;
2115
2116         fov.width = hfov;
2117         fov.height = vfov;
2118         mm_navevent_handler_set_fov_size(event_handler, fov);
2119 #endif
2120         if (player_360_set_field_of_view(g_player[0], hfov, vfov) != PLAYER_ERROR_NONE)
2121                 g_print("failed to set video 360 field of view\n");
2122
2123         video360_get_fov();
2124 }
2125
2126 static void video360_get_dov()
2127 {
2128         float yaw, pitch;
2129
2130         if (player_360_get_direction_of_view(g_player[0], &yaw, &pitch) != PLAYER_ERROR_NONE)
2131                 g_print("failed to get video 360 direction of view\n");
2132         else
2133                 g_print("                                                          ==> [Player_Test] Video 360 DOV yaw = %d, pitch = %d deg.\n", (int)(yaw * 180.0f / M_PI), (int)(pitch * 180.0f / M_PI));
2134 }
2135
2136 static void video360_set_dov(int yaw_deg, int pitch_deg)
2137 {
2138         float angles[3];
2139
2140         angles[0] = M_PI * yaw_deg / 180.0f;
2141         angles[1] = M_PI * pitch_deg / 180.0f;
2142         angles[2] = 0;
2143
2144 #ifdef USE_EVENT_HANDLER
2145         mm_navevent_handler_set_angles(event_handler, angles);
2146 #endif
2147
2148         if (player_360_set_direction_of_view(g_player[0], angles[0], angles[1]) != PLAYER_ERROR_NONE)
2149                 g_print("failed to set video 360 direction of view\n");
2150
2151         video360_get_dov();
2152 }
2153
2154 static void video360_get_zoom()
2155 {
2156         float zoom;
2157
2158         if (player_360_get_zoom(g_player[0], &zoom) != PLAYER_ERROR_NONE)
2159                 g_print("failed to get video 360 zoom\n");
2160         else
2161                 g_print("                                                          ==> [Player_Test] Video 360 zoom = %f\n", zoom);
2162 }
2163
2164 static void video360_set_zoom(float zoom)
2165 {
2166         if (player_360_set_zoom(g_player[0], zoom) != PLAYER_ERROR_NONE)
2167                 g_print("failed to set video 360 zoom\n");
2168
2169         video360_get_zoom();
2170 }
2171
2172 static void video360_set_zoom_with_fov(float zoom, int hfov, int vfov)
2173 {
2174 #ifdef USE_EVENT_HANDLER
2175         mm_navevent_handler_size_s fov;
2176
2177         fov.width = hfov;
2178         fov.height = vfov;
2179         mm_navevent_handler_set_fov_size(event_handler, fov);
2180 #endif
2181         if (player_360_set_zoom_with_field_of_view(g_player[0], zoom, hfov, vfov) != PLAYER_ERROR_NONE)
2182                 g_print("failed to set video 360 zoom with field of view\n");
2183
2184         video360_get_fov();
2185         video360_get_zoom();
2186 }
2187
2188 static void set_replaygain_enabled(bool enabled)
2189 {
2190         if (player_set_replaygain_enabled(g_player[0], enabled) != PLAYER_ERROR_NONE)
2191                 g_print("failed to set_replaygain_enabled\n");
2192 }
2193
2194 static void is_replaygain_enabled(bool *enable)
2195 {
2196         player_is_replaygain_enabled(g_player[0], enable);
2197         g_print("                                                            ==> [Player_Test] replaygain = %d\n", *enable);
2198 }
2199
2200 static bool _supported_media_format_cb(media_format_mimetype_e format, void *user_data)
2201 {
2202         g_print("- supported format mimetype 0x%X\n", format);
2203         return true;
2204 }
2205
2206 static void set_audio_offload_enabled(bool enabled)
2207 {
2208         bool is_enabled = false;
2209
2210         player_audio_offload_is_enabled(g_player[0], &is_enabled);
2211         g_print("[Player_Test] offload setting %d -> %d\n", is_enabled, enabled);
2212
2213         player_audio_offload_foreach_supported_format(g_player[0], _supported_media_format_cb, (void *)g_player[0]);
2214
2215         if (player_audio_offload_set_enabled(g_player[0], enabled) != PLAYER_ERROR_NONE)
2216                 g_print("failed to set audio offload\n");
2217 }
2218
2219 static void pitch_set_enabled(bool enabled)
2220 {
2221         bool is_enabled = false;
2222         player_audio_pitch_is_enabled(g_player[0], &is_enabled);
2223
2224         g_print("pitch enabled %d -> %d \n", is_enabled, enabled);
2225         if (player_audio_pitch_set_enabled(g_player[0], enabled) != PLAYER_ERROR_NONE)
2226                 g_print("failed to pitch_set_enabled\n");
2227 }
2228
2229 static void pitch_set_value(float level)
2230 {
2231         float curr = 0.0;
2232         player_audio_pitch_get_value(g_player[0], &curr);
2233
2234         g_print("pitch level %1.3f -> %1.3f \n", curr, level);
2235         if (player_audio_pitch_set_value(g_player[0], level) != PLAYER_ERROR_NONE)
2236                 g_print("failed to set pitch value\n");
2237 }
2238
2239 #ifdef USE_EVENT_HANDLER
2240 static void event_handler_cb(enum libinput_event_type ev_t, int x, int y, void *data, float e[3])
2241 {
2242         if (ev_t == LIBINPUT_EVENT_TOUCH_MOTION)
2243                 if (player_360_set_direction_of_view(g_player[0], e[0], e[1]) != PLAYER_ERROR_NONE)
2244                         g_print("Event handler callback: failed to set direction of view\n");
2245 }
2246
2247 static void event_handler_set_dov_fov()
2248 {
2249         float angles[3];
2250         mm_navevent_handler_size_s fov;
2251
2252         if (player_360_get_direction_of_view(g_player[0], &angles[0], &angles[1]) != PLAYER_ERROR_NONE) {
2253                 g_print("Failed to get video360 direction of view\n");
2254                 return;
2255         }
2256         if (player_360_get_field_of_view(g_player[0], &fov.width, &fov.height) != PLAYER_ERROR_NONE) {
2257                 g_print("Failed to get video360 field of view\n");
2258                 return;
2259         }
2260         mm_navevent_handler_set_angles(event_handler, angles);
2261         mm_navevent_handler_set_fov_size(event_handler, fov);
2262 }
2263
2264 static void event_handler_set_window_parameters()
2265 {
2266         player_display_rotation_e window_orientation;
2267         mm_navevent_handler_size_s window_size;
2268         float image_ratio;
2269
2270         player_get_display_rotation(g_player[0], &window_orientation);
2271         elm_win_screen_size_get(selected_win_id, NULL, NULL, &window_size.width, &window_size.height);
2272
2273         image_ratio = (float)image_size.width / (float)image_size.height;
2274
2275         if (window_orientation == PLAYER_DISPLAY_ROTATION_NONE ||
2276                         window_orientation == PLAYER_DISPLAY_ROTATION_180) {
2277                 window_size.height = (int)((float)window_size.width / image_ratio);
2278         } else {
2279                 window_size.height = window_size.width;
2280                 window_size.width = (int)((float)window_size.width * image_ratio);
2281         }
2282
2283         mm_navevent_handler_set_window_parameters(event_handler,
2284                         (mm_navevent_handler_orientation_e)window_orientation, window_size);
2285 }
2286 #endif
2287
2288 void quit_program()
2289 {
2290
2291         if (g_pcm_fd)
2292                 fclose(g_pcm_fd);
2293
2294         if (g_player[0] != NULL || g_player[1] != NULL) {
2295                 _player_unprepare();
2296                 _player_destroy();
2297         }
2298
2299         elm_exit();
2300
2301         if (g_audio_fmt)
2302                 media_format_unref(g_audio_fmt);
2303
2304         if (g_video_fmt)
2305                 media_format_unref(g_video_fmt);
2306 }
2307
2308 void play_with_ini(char *file_path)
2309 {
2310         input_filename(file_path);
2311         _player_play();
2312 }
2313
2314 void _interpret_main_menu(char *cmd)
2315 {
2316         int len = strlen(cmd);
2317         if (len == 1) {
2318                 if (strncmp(cmd, "a", 1) == 0) {
2319                         g_menu_state = CURRENT_STATUS_FILENAME;
2320                 } else if (strncmp(cmd, "b", 1) == 0) {
2321                         _player_play();
2322                 } else if (strncmp(cmd, "c", 1) == 0) {
2323                         _player_stop();
2324                 } else if (strncmp(cmd, "d", 1) == 0) {
2325                         _player_resume();
2326                 } else if (strncmp(cmd, "e", 1) == 0) {
2327                         _player_pause();
2328                 } else if (strncmp(cmd, "S", 1) == 0) {
2329                         _player_state();
2330                 } else if (strncmp(cmd, "f", 1) == 0) {
2331                         g_menu_state = CURRENT_STATUS_VOLUME;
2332                 } else if (strncmp(cmd, "g", 1) == 0) {
2333                         float left;
2334                         float right;
2335                         get_volume(&left, &right);
2336                 } else if (strncmp(cmd, "k", 1) == 0) {
2337                         g_menu_state = CURRENT_STATUS_SOUND_STREAM_INFO;
2338                 } else if (strncmp(cmd, "h", 1) == 0) {
2339                         g_menu_state = CURRENT_STATUS_MUTE;
2340                 } else if (strncmp(cmd, "i", 1) == 0) {
2341                         bool mute;
2342                         get_mute(&mute);
2343                 } else if (strncmp(cmd, "j", 1) == 0) {
2344                         g_menu_state = CURRENT_STATUS_POSITION_TIME;
2345                 } else if (strncmp(cmd, "l", 1) == 0) {
2346                         get_position();
2347                 } else if (strncmp(cmd, "m", 1) == 0) {
2348                         get_duration();
2349                 } else if (strncmp(cmd, "n", 1) == 0) {
2350                         get_stream_info();
2351                 } else if (strncmp(cmd, "o", 1) == 0) {
2352                         g_menu_state = CURRENT_STATUS_LOOPING;
2353                 } else if (strncmp(cmd, "p", 1) == 0) {
2354                         bool looping;
2355                         get_looping(&looping);
2356                 } else if (strncmp(cmd, "r", 1) == 0) {
2357                         g_menu_state = CURRENT_STATUS_DISPLAY_MODE;
2358                 } else if (strncmp(cmd, "s", 1) == 0) {
2359                         get_display_mode();
2360                 } else if (strncmp(cmd, "t", 1) == 0) {
2361                         g_menu_state = CURRENT_STATUS_DISPLAY_ROTATION;
2362                 } else if (strncmp(cmd, "u", 1) == 0) {
2363                         get_display_rotation();
2364                 } else if (strncmp(cmd, "v", 1) == 0) {
2365                         g_menu_state = CURRENT_STATUS_DISPLAY_VISIBLE;
2366                 } else if (strncmp(cmd, "w", 1) == 0) {
2367                         bool visible;
2368                         get_display_visible(&visible);
2369                 } else if (strncmp(cmd, "A", 1) == 0) {
2370                         g_menu_state = CURRENT_STATUS_SUBTITLE_FILENAME;
2371                 } else if (strncmp(cmd, "C", 1) == 0) {
2372                         capture_video();
2373                 } else if (strncmp(cmd, "D", 1) == 0) {
2374                         decoding_audio();
2375                 } else if (strncmp(cmd, "q", 1) == 0) {
2376                         quit_pushing = TRUE;
2377                         quit_program();
2378                 } else if (strncmp(cmd, "E", 1) == 0) {
2379                         g_menu_state = CURRENT_STATUS_AUDIO_EQUALIZER;
2380                 } else if (strncmp(cmd, "H", 1) == 0) {
2381                         get_audio_eq();
2382                 } else {
2383                         g_print("unknown menu \n");
2384                 }
2385         } else if (len == 2) {
2386                 if (strncmp(cmd, "pr", 2) == 0) {
2387                         /* sync */
2388                         if (g_current_surface_type == -1) {
2389                                 g_print("You must set display surface type before setting prepare. please 'pr' after setting display surface type.\n");
2390                                 g_menu_state = CURRENT_STATUS_DISPLAY_SURFACE_CHANGE;
2391                         } else
2392                                 _player_prepare(FALSE);
2393                 } else if (strncmp(cmd, "pa", 2) == 0) {
2394                         /* async */
2395                         if (g_current_surface_type == -1) {
2396                                 g_print("You must set display surface type before setting prepare. please 'pr' after setting display surface type.\n");
2397                                 g_menu_state = CURRENT_STATUS_DISPLAY_SURFACE_CHANGE;
2398                         } else {
2399                                 _player_prepare(TRUE);
2400                         }
2401                 } else if (strncmp(cmd, "un", 2) == 0) {
2402                         _player_unprepare();
2403                 } else if (strncmp(cmd, "dt", 2) == 0) {
2404                         _player_destroy();
2405                 } else if (strncmp(cmd, "mp", 2) == 0) {
2406                         g_memory_playback = (g_memory_playback ? FALSE : TRUE);
2407                         g_print("memory playback = %d\n", g_memory_playback);
2408                 } else if (strncmp(cmd, "ds", 2) == 0) {
2409                         g_menu_state = CURRENT_STATUS_DISPLAY_SURFACE_CHANGE;
2410                 } else if (strncmp(cmd, "dr", 2) == 0) {
2411                         g_menu_state = CURRENT_STATUS_DISPLAY_DST_ROI_AREA;
2412                 } else if (strncmp(cmd, "nb", 2) == 0) {
2413                         g_menu_state = CURRENT_STATUS_HANDLE_NUM;
2414                 } else if (strncmp(cmd, "tr", 2) == 0) {
2415                         g_menu_state = CURRENT_STATUS_PLAYBACK_RATE;
2416                 } else if (strncmp(cmd, "lt", 2) == 0) {
2417                         g_menu_state = CURRENT_STATUS_LATENCY;
2418                 } else if (strncmp(cmd, "X5", 2) == 0) {
2419                         g_menu_state = CURRENT_STATUS_EXPORT_PCM_OPTION;
2420                 } else if (strncmp(cmd, "ep", 2) == 0) {
2421                         _player_enable_tsurf_pool();
2422                 } else if (strncmp(cmd, "su", 2) == 0) {
2423                         g_menu_state = CURRENT_STATUS_NEXT_URI;
2424                 } else if (strncmp(cmd, "gu", 2) == 0) {
2425                         get_next_uri();
2426                 } else if (strncmp(cmd, "sg", 2) == 0) {
2427                         g_menu_state = CURRENT_STATUS_GAPLESS;
2428                 } else if (strncmp(cmd, "tg", 2) == 0) {
2429                         g_menu_state = CURRENT_STATUS_GET_TRACK_INFO;
2430                 } else if (strncmp(cmd, "ts", 2) == 0) {
2431                         g_menu_state = CURRENT_STATUS_SET_TRACK_TYPE;
2432                 } else if (strncmp(cmd, "vi", 2) == 0) {
2433                         get_variant_info();
2434                 } else if (strncmp(cmd, "vs", 2) == 0) {
2435                         g_menu_state = CURRENT_STATUS_SET_MAX_BANDWIDTH_VARIANT;
2436                 } else if (strncmp(cmd, "vg", 2) == 0) {
2437                         get_variant_limit();
2438                 } else if (strncmp(cmd, "ao", 2) == 0) {
2439                         g_menu_state = CURRENT_STATUS_SET_AUDIO_ONLY;
2440                 } else if (strncmp(cmd, "bf", 2) == 0) {
2441                         g_menu_state = CURRENT_STATUS_SET_PRE_BUFFERING_SIZE;
2442                 } else if (strncmp(cmd, "C1", 2) == 0) {
2443                         g_menu_state = CURRENT_STATUS_SET_VIDEO_CODEC_TYPE;
2444                 } else if (strncmp(cmd, "C2", 2) == 0) {
2445                         g_menu_state = CURRENT_STATUS_SET_AUDIO_CODEC_TYPE;
2446                 } else if (strncmp(cmd, "C3", 2) == 0) {
2447                         g_menu_state = CURRENT_STATUS_GET_CODEC_TYPE;
2448                 } else if (!strncmp(cmd, "si", 2)) {
2449                         video360_is_spherical();
2450                 } else if (!strncmp(cmd, "se", 2)) {
2451                         g_menu_state = CURRENT_STATUS_VIDEO360_SET_ENABLE;
2452                 } else if (!strncmp(cmd, "sd", 2)) {
2453                         g_menu_state = CURRENT_STATUS_VIDEO360_SET_DOV;
2454                 } else if (!strncmp(cmd, "sf", 2)) {
2455                         g_menu_state = CURRENT_STATUS_VIDEO360_SET_FOV;
2456                 } else if (!strncmp(cmd, "sz", 2)) {
2457                         g_menu_state = CURRENT_STATUS_VIDEO360_SET_ZOOM;
2458                 } else if (strncmp(cmd, "lb", 2) == 0) {
2459                         get_buffering_position();
2460                 } else if (strncmp(cmd, "ol", 2) == 0) {
2461                         g_menu_state = CURRENT_STATUS_AUDIO_OFFLOAD;
2462                 } else if (strncmp(cmd, "pc", 2) == 0) {
2463                         g_menu_state = CURRENT_STATUS_PITCH_CONTROL;
2464                 } else if (strncmp(cmd, "pv", 2) == 0) {
2465                         g_menu_state = CURRENT_STATUS_PITCH_VALUE;
2466                 } else {
2467                         g_print("unknown menu \n");
2468                 }
2469         } else if (len == 3) {
2470                 if (strncmp(cmd, "trs", 3) == 0) {
2471                         g_menu_state = CURRENT_STATUS_STREAMING_PLAYBACK_RATE;
2472                 } else if (strncmp(cmd, "rgs", 3) == 0) {
2473                         g_menu_state = CURRENT_STATUS_REPLAYGAIN_ENABLE;
2474                 } else if (strncmp(cmd, "rgg", 3) == 0) {
2475                         bool enable;
2476                         is_replaygain_enabled(&enable);
2477                 } else if (!strncmp(cmd, "szz", 3)) {
2478                         g_menu_state = CURRENT_STATUS_VIDEO360_SET_ZOOM_WITH_FOV;
2479                 } else {
2480                         g_print("unknown menu \n");
2481                 }
2482         } else {
2483                 g_print("unknown menu \n");
2484         }
2485 }
2486
2487 void display_sub_basic()
2488 {
2489         g_print("\n");
2490         g_print("=========================================================================================\n");
2491         g_print("                          Player Test (press q to quit) \n");
2492         g_print("-----------------------------------------------------------------------------------------\n");
2493         g_print("[playback] a. Create\t");
2494         g_print("pr. Prepare  \t");
2495         g_print("pa. Prepare async \t");
2496         g_print("b. Play  \t");
2497         g_print("c. Stop  \t");
2498         g_print("d. Resume\t");
2499         g_print("e. Pause \t");
2500         g_print("un. Unprepare \t");
2501         g_print("dt. Destroy \n");
2502         g_print("[State] S. Player State \n");
2503         g_print("[ volume ] f. Set Volume\t");
2504         g_print("g. Get Volume\t");
2505         g_print("k. Set Sound Stream Info.\n");
2506         g_print("[ mute ] h. Set Mute\t");
2507         g_print("i. Get Mute\n");
2508         g_print("[audio eq] E. Set Audio EQ\t");
2509         g_print("H. Get Audio EQ\n");
2510         g_print("[position] j. Set Position \t");
2511         g_print("l. Get Position\t");
2512         g_print("lb. Get buffering position\n");
2513         g_print("[trick] tr. set playback rate\n");
2514         g_print("[latency] lt. Set latency\n");
2515         g_print("[duration] m. Get Duration\n");
2516         g_print("[Stream Info] n. Get stream info (Video Size, codec, audio stream info, and tag info)\n");
2517         g_print("[Looping] o. Set Looping\t");
2518         g_print("p. Get Looping\n");
2519         g_print("[display] v. Set display visible\t");
2520         g_print("w. Get display visible\n");
2521         g_print("[display] ds. Change display surface type\n");
2522         g_print("[display] dr. set display roi area\n");
2523         g_print("[overlay display] r. Set display mode\t");
2524         g_print("s. Get display mode\n");
2525         g_print("[overlay display] t. Set display Rotation\n");
2526         g_print("[Variant] vi. Get Streaming Variant Info\t");
2527         g_print("vs. Set max limit of variant\t");
2528         g_print("vg. Get max limit of variant\n");
2529         g_print("[audio only] ao. set audio only\n");
2530         g_print("[subtitle] A. Set(or change) subtitle path\n");
2531         g_print("[Track] tg. Get Track info\n");
2532         g_print("[Track] ts. Set track\n");
2533         g_print("[Video Capture] C. Capture \n");
2534         g_print("[Video Codec] C1. Set codec type (1:HW, 2:SW)\t");
2535         g_print("C2. Get codec type\n");
2536         g_print("[next uri] su. set next uri. \t");
2537         g_print("gu. get next uri. \t");
2538         g_print("sg. set gapless. \n");
2539         g_print("[audio_frame_decoded_cb] X5. set audio decoded cb\n");
2540         g_print("[video_frame_decoded_cb] ep. enable tbm surface pool\n");
2541         g_print("[buffering] bf. set new buffering size\n");
2542         g_print("[Video 360] si. check spherical info\t");
2543         g_print("se. Set Enable\n");
2544         g_print("[Video 360] sd. Set Direction Of View\t");
2545         g_print("sf. Set Field Of View\n");
2546         g_print("[Video 360] sz. Set Zoom\t\t");
2547         g_print("szz. Set Zoom with FOV\n");
2548         g_print("[Replaygain] rgs. Set Replaygain\t\t");
2549         g_print("rgg. Get replaygain\n");
2550         g_print("[Offload] ol. Set audio offload\n");
2551         g_print("[pitch] pc. enable pitch control\t");
2552         g_print("pv. Set pitch value\n");
2553         g_print("[etc] sp. Set Progressive Download\t");
2554         g_print("gp. Get Progressive Download status\t");
2555         g_print("mp. memory playback\n");
2556         g_print("\n");
2557         g_print("=========================================================================================\n");
2558 }
2559
2560 static void displaymenu()
2561 {
2562         if (g_menu_state == CURRENT_STATUS_MAINMENU) {
2563                 display_sub_basic();
2564         } else if (g_menu_state == CURRENT_STATUS_HANDLE_NUM) {
2565                 g_print("*** input number of handles.(recommended only for EVAS surface)\n");
2566         } else if (g_menu_state == CURRENT_STATUS_FILENAME) {
2567                 g_print("*** input mediapath.\n");
2568         } else if (g_menu_state == CURRENT_STATUS_VOLUME) {
2569                 g_print("*** input volume value.(0~1.0)\n");
2570         } else if (g_menu_state == CURRENT_STATUS_SOUND_STREAM_INFO) {
2571                 g_print("*** input sound stream type.(0:MEDIA 1:SYSTEM 2:ALARM 3:NOTIFICATION 4:EMERGENCY 5:VOICE_INFORMATION 9:MEDIA_EXT_ONLY)\n");
2572         } else if (g_menu_state == CURRENT_STATUS_MUTE) {
2573                 g_print("*** input mute value.(0: Not Mute, 1: Mute) \n");
2574         } else if (g_menu_state == CURRENT_STATUS_POSITION_TIME) {
2575                 g_print("*** input position value(msec)\n");
2576         } else if (g_menu_state == CURRENT_STATUS_POSITION_ACCURATE) {
2577                 g_print("*** input accurate value(0/1)\n");
2578         } else if (g_menu_state == CURRENT_STATUS_LOOPING) {
2579                 g_print("*** input looping value.(0: Not Looping, 1: Looping) \n");
2580         } else if (g_menu_state == CURRENT_STATUS_DISPLAY_SURFACE_CHANGE) {
2581                 g_print("*** input display surface type.(0: Wayland surface, 1: EVAS surface, 2: No use surface (e.g: audio playback)) \n");
2582         } else if (g_menu_state == CURRENT_STATUS_EXPORT_VIDEO_FRAME) {
2583                 g_print("*** set video_decoded_cb (0: none, 1: set cb) \n");
2584         } else if (g_menu_state == CURRENT_STATUS_DISPLAY_MODE) {
2585                 g_print("*** input display mode value.(0: LETTER BOX, 1: ORIGIN SIZE, 2: FULL_SCREEN, 3: CROPPED_FULL, 4: ORIGIN_OR_LETTER, 5:ROI) \n");
2586         } else if (g_menu_state == CURRENT_STATUS_DISPLAY_DST_ROI_AREA) {
2587                 g_print("*** input display roi value sequentially.(x, y, w, h)\n");
2588         } else if (g_menu_state == CURRENT_STATUS_DISPLAY_ROTATION) {
2589                 g_print("*** input display rotation value.(0: NONE, 1: 90, 2: 180, 3: 270, 4:F LIP_HORZ, 5: FLIP_VERT ) \n");
2590         } else if (g_menu_state == CURRENT_STATUS_DISPLAY_VISIBLE) {
2591                 g_print("*** input display visible value.(0: HIDE, 1: SHOW) \n");
2592         } else if (g_menu_state == CURRENT_STATUS_SUBTITLE_FILENAME) {
2593                 g_print(" *** input  subtitle file path.\n");
2594         } else if (g_menu_state == CURRENT_STATUS_AUDIO_EQUALIZER) {
2595                 g_print(" *** input audio eq value.(0: UNSET, 1: SET) \n");
2596         } else if (g_menu_state == CURRENT_STATUS_PLAYBACK_RATE || g_menu_state == CURRENT_STATUS_STREAMING_PLAYBACK_RATE) {
2597                 g_print(" *** input playback rate.(-5.0 ~ 5.0)\n");
2598         } else if (g_menu_state == CURRENT_STATUS_LATENCY) {
2599                 g_print(" *** input latency.(0: Low, 1: Mid, 2: High)\n");
2600         } else if (g_menu_state == CURRENT_STATUS_SET_TRACK_TYPE) {
2601                 g_print(" *** input track type.(1:audio, 3:text)\n");
2602         } else if (g_menu_state == CURRENT_STATUS_SET_TRACK_INDEX) {
2603                 g_print(" *** input track index\n");
2604         } else if (g_menu_state == CURRENT_STATUS_NEXT_URI) {
2605                 g_print("*** input next uri.\n");
2606         } else if (g_menu_state == CURRENT_STATUS_GAPLESS) {
2607                 g_print("*** input gapless value.(0:disable, 1: enable) \n");
2608         } else if (g_menu_state == CURRENT_STATUS_GET_TRACK_INFO) {
2609                 g_print("*** input track type.(1:audio, 3:text) \n");
2610         } else if (g_menu_state == CURRENT_STATUS_SET_MAX_BANDWIDTH_VARIANT) {
2611                 g_print("*** set max bandwidth (default: -1) \n");
2612         } else if (g_menu_state == CURRENT_STATUS_SET_MAX_WIDTH_VARIANT) {
2613                 g_print("*** set max width (default: -1) \n");
2614         } else if (g_menu_state == CURRENT_STATUS_SET_MAX_HEIGHT_VARIANT) {
2615                 g_print("*** set max height (default: -1) \n");
2616         } else if (g_menu_state == CURRENT_STATUS_SET_AUDIO_ONLY) {
2617                 g_print("*** set audio only mode (0:disable, 1:enable) \n");
2618         } else if (g_menu_state == CURRENT_STATUS_SET_PRE_BUFFERING_SIZE) {
2619                 g_print("*** set pre buffering size (ms) \n");
2620         } else if (g_menu_state == CURRENT_STATUS_SET_RE_BUFFERING_SIZE) {
2621                 g_print("*** set re buffering size (ms) \n");
2622         } else if (g_menu_state == CURRENT_STATUS_VIDEO360_SET_ENABLE) {
2623                 g_print("*** input video 360 status (0: disabled (full panorama), 1: enabled)\n");
2624         } else if (g_menu_state == CURRENT_STATUS_VIDEO360_SET_DOV) {
2625                 g_print("*** input direction of view yaw angle (+/- 180 deg.)\n");
2626         } else if (g_menu_state == CURRENT_STATUS_VIDEO360_SET_DOV1) {
2627                 g_print("*** input direction of view pitch angle (+/- 90 deg.)\n");
2628         } else if (g_menu_state == CURRENT_STATUS_VIDEO360_SET_FOV) {
2629                 g_print("*** input horizontal field of view angle (1~360 deg.)\n");
2630         } else if (g_menu_state == CURRENT_STATUS_VIDEO360_SET_FOV1) {
2631                 g_print("*** input vertical field of view angle (1~180 deg.)\n");
2632         } else if (g_menu_state == CURRENT_STATUS_VIDEO360_SET_ZOOM) {
2633                 g_print("*** input zoom factor.(1.0~10.0, where 1.0 - no zoom, actual image) \n");
2634         } else if (g_menu_state == CURRENT_STATUS_VIDEO360_SET_ZOOM_WITH_FOV) {
2635                 g_print("*** input zoom factor.(1.0~10.0, where 1.0 - no zoom, actual image) \n");
2636         } else if (g_menu_state == CURRENT_STATUS_VIDEO360_SET_ZOOM_WITH_FOV1) {
2637                 g_print("*** input horizontal field of view angle (1~360 deg.)\n");
2638         } else if (g_menu_state == CURRENT_STATUS_VIDEO360_SET_ZOOM_WITH_FOV2) {
2639                 g_print("*** input vertical field of view angle (1~180 deg.)\n");
2640         } else if (g_menu_state == CURRENT_STATUS_SET_VIDEO_CODEC_TYPE) {
2641                 g_print("*** set video codec type (0: HW, 1: SW) \n");
2642         } else if (g_menu_state == CURRENT_STATUS_SET_AUDIO_CODEC_TYPE) {
2643                 g_print("*** set audio codec type (0: HW, 1: SW) \n");
2644         } else if (g_menu_state == CURRENT_STATUS_GET_CODEC_TYPE) {
2645                 g_print("*** stream type (1: video, 2: audio) \n");
2646         } else if (g_menu_state == CURRENT_STATUS_REPLAYGAIN_ENABLE) {
2647                 g_print("*** input replaygain value.(0:disable, 1: enable) \n");
2648         } else if (g_menu_state == CURRENT_STATUS_AUDIO_OFFLOAD) {
2649                 g_print("*** input audio offload value.(0:disable, 1: enable) \n");
2650         } else if (g_menu_state == CURRENT_STATUS_PITCH_CONTROL) {
2651                 g_print("*** input pitch control value.(0:disable, 1: enable) \n");
2652         } else if (g_menu_state == CURRENT_STATUS_PITCH_VALUE) {
2653                 g_print("*** input pitch value.(0.5 ~ 2) \n");
2654         } else if (g_menu_state == CURRENT_STATUS_EXPORT_PCM_OPTION) {
2655                 g_print("*** set option (0~3) \n");
2656         } else if (g_menu_state == CURRENT_STATUS_EXPORT_PCM_CH) {
2657                 g_print("*** set pcm channel (e.g. 2)\n");
2658         } else if (g_menu_state == CURRENT_STATUS_EXPORT_PCM_RATE) {
2659                 g_print("*** set pcm samplerate (e.g. 44100)\n");
2660         } else if (g_menu_state == CURRENT_STATUS_EXPORT_PCM_MIME) {
2661                 g_print("*** set pcm mime (e.g. S16LE) \n");
2662         } else {
2663                 g_print("*** unknown status.\n");
2664                 quit_program();
2665         }
2666         g_print(" >>> ");
2667 }
2668
2669 gboolean timeout_menu_display(void *data)
2670 {
2671         displaymenu();
2672         return FALSE;
2673 }
2674
2675 gboolean timeout_quit_program(void *data)
2676 {
2677         quit_program();
2678         return FALSE;
2679 }
2680
2681 void reset_menu_state(void)
2682 {
2683         g_menu_state = CURRENT_STATUS_MAINMENU;
2684 }
2685
2686 static void interpret(char *cmd)
2687 {
2688         static int value1 = 0, value2 = 0, value3 = 0;
2689         static float fval = 0.0;
2690
2691         switch (g_menu_state) {
2692         case CURRENT_STATUS_MAINMENU:
2693                 {
2694                         _interpret_main_menu(cmd);
2695                 }
2696                 break;
2697         case CURRENT_STATUS_HANDLE_NUM:
2698                 {
2699                         value1 = atoi(cmd);
2700                         if (0 >= value1 || value1 > MAX_HANDLE)
2701                                 g_print("not supported this number for handles(%d)\n", value1);
2702                         else
2703                                 g_handle_num = value1;
2704
2705                         reset_menu_state();
2706                 }
2707                 break;
2708         case CURRENT_STATUS_FILENAME:
2709                 {
2710                         input_filename(cmd);
2711                         reset_menu_state();
2712                 }
2713                 break;
2714         case CURRENT_STATUS_VOLUME:
2715                 {
2716                         fval = atof(cmd);
2717                         set_volume(fval);
2718                         reset_menu_state();
2719                 }
2720                 break;
2721         case CURRENT_STATUS_SOUND_STREAM_INFO:
2722                 {
2723                         value1 = atoi(cmd);
2724                         set_sound_stream_info(value1);
2725                         reset_menu_state();
2726                 }
2727                 break;
2728         case CURRENT_STATUS_MUTE:
2729                 {
2730                         value1 = atoi(cmd);
2731                         set_mute(value1);
2732                         reset_menu_state();
2733                 }
2734                 break;
2735         case CURRENT_STATUS_POSITION_TIME:
2736                 {
2737                         value1 = atoi(cmd);
2738                         g_menu_state = CURRENT_STATUS_POSITION_ACCURATE;
2739                 }
2740                 break;
2741         case CURRENT_STATUS_POSITION_ACCURATE:
2742                 {
2743                         set_position(value1, ((atoi(cmd) != 0) ? (true) : (false)));
2744                         reset_menu_state();
2745                 }
2746                 break;
2747         case CURRENT_STATUS_LOOPING:
2748                 {
2749                         value1 = atoi(cmd);
2750                         set_looping(value1);
2751                         reset_menu_state();
2752                 }
2753                 break;
2754         case CURRENT_STATUS_GAPLESS:
2755                 {
2756                         value1 = atoi(cmd);
2757                         set_gapless(value1);
2758                         reset_menu_state();
2759                 }
2760                 break;
2761         case CURRENT_STATUS_DISPLAY_SURFACE_CHANGE:
2762                 {
2763                         value1 = atoi(cmd);
2764                         change_surface(value1);
2765                         if (value1 == 2) { /* null display type */
2766                                 g_menu_state = CURRENT_STATUS_EXPORT_VIDEO_FRAME;
2767                                 break;
2768                         }
2769                         reset_menu_state();
2770                 }
2771                 break;
2772         case CURRENT_STATUS_EXPORT_VIDEO_FRAME:
2773                 {
2774                         value2 = atoi(cmd);
2775                         if (value2 != 0)
2776                                 set_video_frame_decoded_cb();
2777                         reset_menu_state();
2778                 } break;
2779         case CURRENT_STATUS_DISPLAY_MODE:
2780                 {
2781                         value1 = atoi(cmd);
2782                         set_display_mode(value1);
2783                         reset_menu_state();
2784                 }
2785                 break;
2786         case CURRENT_STATUS_DISPLAY_DST_ROI_AREA:
2787                 {
2788                         value1 = atoi(cmd);
2789                         static int x = 0;
2790                         static int y = 0;
2791                         static int w = 0;
2792                         static int h = 0;
2793                         static int cnt = 0;
2794
2795                         switch (cnt) {
2796                         case 0:
2797                                 x = value1;
2798                                 cnt++;
2799                                 break;
2800                         case 1:
2801                                 y = value1;
2802                                 cnt++;
2803                                 break;
2804                         case 2:
2805                                 w = value1;
2806                                 cnt++;
2807                                 break;
2808                         case 3:
2809                                 cnt = 0;
2810                                 h = value1;
2811                                 set_display_roi_area(x, y, w, h);
2812                                 x = y = w = h = 0;
2813                                 reset_menu_state();
2814                                 break;
2815                         default:
2816                                 break;
2817                         }
2818                 }
2819                 break;
2820         case CURRENT_STATUS_DISPLAY_ROTATION:
2821                 {
2822                         value1 = atoi(cmd);
2823                         set_display_rotation(value1);
2824                         reset_menu_state();
2825                 }
2826                 break;
2827         case CURRENT_STATUS_DISPLAY_VISIBLE:
2828                 {
2829                         value1 = atoi(cmd);
2830                         set_display_visible(value1);
2831                         reset_menu_state();
2832                 }
2833                 break;
2834         case CURRENT_STATUS_SUBTITLE_FILENAME:
2835                 {
2836                         input_subtitle_filename(cmd);
2837                         reset_menu_state();
2838                 }
2839                 break;
2840         case CURRENT_STATUS_AUDIO_EQUALIZER:
2841                 {
2842                         value1 = atoi(cmd);
2843                         set_audio_eq(value1);
2844                         reset_menu_state();
2845                 }
2846                 break;
2847         case CURRENT_STATUS_PLAYBACK_RATE:
2848                 {
2849                         fval = atof(cmd);
2850                         set_playback_rate(fval, FALSE);
2851                         reset_menu_state();
2852                 }
2853                 break;
2854         case CURRENT_STATUS_STREAMING_PLAYBACK_RATE:
2855                 {
2856                         fval = atof(cmd);
2857                         set_playback_rate(fval, TRUE);
2858                         reset_menu_state();
2859                 }
2860                 break;
2861         case CURRENT_STATUS_LATENCY:
2862                 {
2863                         int value = atoi(cmd);
2864                         set_latency(value);
2865                         reset_menu_state();
2866                 }
2867                 break;
2868         case CURRENT_STATUS_SET_TRACK_TYPE:
2869                 {
2870                         value1 = atoi(cmd);
2871                         get_track_info(value1);
2872
2873                         g_menu_state = CURRENT_STATUS_SET_TRACK_INDEX;
2874                 }
2875                 break;
2876         case CURRENT_STATUS_SET_TRACK_INDEX:
2877                 {
2878                         value2 = atoi(cmd);
2879                         set_track(value1, value2);
2880                         reset_menu_state();
2881                 }
2882                 break;
2883         case CURRENT_STATUS_NEXT_URI:
2884                 {
2885                         set_next_uri(cmd);
2886                         reset_menu_state();
2887                 }
2888                 break;
2889         case CURRENT_STATUS_GET_TRACK_INFO:
2890                 {
2891                         value1 = atoi(cmd);
2892                         get_track_info(value1);
2893                         reset_menu_state();
2894                 }
2895                 break;
2896         case CURRENT_STATUS_SET_MAX_BANDWIDTH_VARIANT:
2897                 {
2898                         value1 = atoi(cmd);
2899                         g_menu_state = CURRENT_STATUS_SET_MAX_WIDTH_VARIANT;
2900                 }
2901                 break;
2902         case CURRENT_STATUS_SET_MAX_WIDTH_VARIANT:
2903                 {
2904                         value2 = atoi(cmd);
2905                         g_menu_state = CURRENT_STATUS_SET_MAX_HEIGHT_VARIANT;
2906                 }
2907                 break;
2908         case CURRENT_STATUS_SET_MAX_HEIGHT_VARIANT:
2909                 {
2910                         value3 = atoi(cmd);
2911                         set_variant_limit(value1, value2, value3);
2912                         reset_menu_state();
2913                 }
2914                 break;
2915         case CURRENT_STATUS_SET_AUDIO_ONLY:
2916                 {
2917                         value1 = atoi(cmd);
2918                         set_audio_only(value1);
2919                         reset_menu_state();
2920                 }
2921                 break;
2922         case CURRENT_STATUS_SET_PRE_BUFFERING_SIZE:
2923                 {
2924                         value1 = atoi(cmd);
2925                         g_menu_state = CURRENT_STATUS_SET_RE_BUFFERING_SIZE;
2926                 }
2927                 break;
2928         case CURRENT_STATUS_SET_RE_BUFFERING_SIZE:
2929                 {
2930                         value2 = atoi(cmd);
2931                         set_buffer_size(value1, value2);
2932                         reset_menu_state();
2933                 }
2934                 break;
2935         case CURRENT_STATUS_VIDEO360_SET_ENABLE:
2936                 {
2937                         value1 = atoi(cmd);
2938                         video360_set_enable(value1);
2939                         reset_menu_state();
2940                 }
2941                 break;
2942         case CURRENT_STATUS_VIDEO360_SET_DOV:
2943                 {
2944                         value1 = atoi(cmd);
2945                         g_menu_state = CURRENT_STATUS_VIDEO360_SET_DOV1;
2946                 }
2947                 break;
2948         case CURRENT_STATUS_VIDEO360_SET_DOV1:
2949                 {
2950                         value2 = atoi(cmd);
2951                         video360_set_dov(value1, value2);
2952                         reset_menu_state();
2953                 }
2954                 break;
2955         case CURRENT_STATUS_VIDEO360_SET_FOV:
2956                 {
2957                         value1 = atoi(cmd);
2958                         g_menu_state = CURRENT_STATUS_VIDEO360_SET_FOV1;
2959                 }
2960                 break;
2961         case CURRENT_STATUS_VIDEO360_SET_FOV1:
2962                 {
2963                         value2 = atoi(cmd);
2964                         video360_set_fov(value1, value2);
2965                         reset_menu_state();
2966                 }
2967                 break;
2968         case CURRENT_STATUS_VIDEO360_SET_ZOOM:
2969                 {
2970                         fval = atof(cmd);
2971                         video360_set_zoom(fval);
2972                         reset_menu_state();
2973                 }
2974                 break;
2975         case CURRENT_STATUS_VIDEO360_SET_ZOOM_WITH_FOV:
2976                 {
2977                         fval = atof(cmd);
2978                         g_menu_state = CURRENT_STATUS_VIDEO360_SET_ZOOM_WITH_FOV1;
2979                 }
2980                 break;
2981         case CURRENT_STATUS_VIDEO360_SET_ZOOM_WITH_FOV1:
2982                 {
2983                         value1 = atoi(cmd);
2984                         g_menu_state = CURRENT_STATUS_VIDEO360_SET_ZOOM_WITH_FOV2;
2985                 }
2986                 break;
2987         case CURRENT_STATUS_VIDEO360_SET_ZOOM_WITH_FOV2:
2988                 {
2989                         value2 = atoi(cmd);
2990                         video360_set_zoom_with_fov(fval, value1, value2);
2991                         reset_menu_state();
2992                 }
2993                 break;
2994         case CURRENT_STATUS_SET_VIDEO_CODEC_TYPE:
2995                 {
2996                         value1 = atoi(cmd);
2997                         set_video_codec_type(value1);
2998                         reset_menu_state();
2999                 }
3000                 break;
3001         case CURRENT_STATUS_SET_AUDIO_CODEC_TYPE:
3002                 {
3003                         value1 = atoi(cmd);
3004                         set_audio_codec_type(value1);
3005                         reset_menu_state();
3006                 }
3007                 break;
3008         case CURRENT_STATUS_GET_CODEC_TYPE:
3009                 {
3010                         value1 = atoi(cmd);
3011                         get_codec_type(value1);
3012                         reset_menu_state();
3013                 }
3014                 break;
3015         case CURRENT_STATUS_REPLAYGAIN_ENABLE:
3016                 {
3017                         value1 = atoi(cmd);
3018                         set_replaygain_enabled(value1);
3019                         reset_menu_state();
3020                 }
3021                 break;
3022         case CURRENT_STATUS_AUDIO_OFFLOAD:
3023                 {
3024                         value1 = atoi(cmd);
3025                         set_audio_offload_enabled(value1);
3026                         reset_menu_state();
3027                 }
3028                 break;
3029         case CURRENT_STATUS_PITCH_CONTROL:
3030                 {
3031                         value1 = atoi(cmd);
3032                         pitch_set_enabled(value1);
3033                         reset_menu_state();
3034                 }
3035                 break;
3036         case CURRENT_STATUS_PITCH_VALUE:
3037                 {
3038                         fval = atof(cmd);
3039                         pitch_set_value(fval);
3040                         reset_menu_state();
3041                 }
3042                 break;
3043         case CURRENT_STATUS_EXPORT_PCM_OPTION:
3044                 {
3045                         value1 = atoi(cmd);
3046                         g_menu_state = CURRENT_STATUS_EXPORT_PCM_CH;
3047                 }
3048                 break;
3049         case CURRENT_STATUS_EXPORT_PCM_CH:
3050                 {
3051                         value2 = atoi(cmd);
3052                         g_menu_state = CURRENT_STATUS_EXPORT_PCM_RATE;
3053                 }
3054                 break;
3055         case CURRENT_STATUS_EXPORT_PCM_RATE:
3056                 {
3057                         value3 = atoi(cmd);
3058                         g_menu_state = CURRENT_STATUS_EXPORT_PCM_MIME;
3059                 }
3060                 break;
3061         case CURRENT_STATUS_EXPORT_PCM_MIME:
3062                 {
3063                         set_audio_frame_decoded_cb((player_audio_extract_option_e)value1, cmd, value2, value3);
3064                         reset_menu_state();
3065                 }
3066                 break;
3067         }
3068
3069         g_timeout_add(100, timeout_menu_display, 0);
3070 }
3071
3072 gboolean input(GIOChannel *channel)
3073 {
3074         gchar buf[MAX_STRING_LEN];
3075         gsize read;
3076         GError *error = NULL;
3077
3078         g_io_channel_read_chars(channel, buf, MAX_STRING_LEN, &read, &error);
3079         buf[read] = '\0';
3080         g_strstrip(buf);
3081         interpret(buf);
3082
3083         return TRUE;
3084 }
3085
3086 int main(int argc, char *argv[])
3087 {
3088         GIOChannel *stdin_channel;
3089         stdin_channel = g_io_channel_unix_new(0);
3090         g_io_channel_set_flags(stdin_channel, G_IO_FLAG_NONBLOCK, NULL);
3091         g_io_add_watch(stdin_channel, G_IO_IN, (GIOFunc)input, NULL);
3092
3093         displaymenu();
3094         memset(&ad, 0x0, sizeof(appdata));
3095         ops.data = &ad;
3096
3097         return appcore_efl_main(PACKAGE, &argc, &argv, &ops);
3098 }