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