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