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