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