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