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