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