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