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