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