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