d7c8a9bcb77feb64db7717a2440f1f78351b7fca
[platform/core/api/player.git] / test / player_audio_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 <Ecore.h>
24
25 #ifdef PACKAGE
26 #undef PACKAGE
27 #endif
28 #define PACKAGE "player_audio_test"
29
30 #ifdef LOG_TAG
31 #undef LOG_TAG
32 #endif
33 #define LOG_TAG "PLAYER_AUDIO_TEST"
34
35 #define MAX_STRING_LEN  2048
36 #define PLAYER_AUDIO_TEST_DUMP_PATH_PREFIX   "/home/owner/dump_pcm_"
37 #define DEFAULT_HTTP_TIMEOUT -1
38
39 #include <system_info.h>
40 #include <stdlib.h>
41 typedef enum {
42         TIZEN_PROFILE_UNKNOWN = 0,
43         TIZEN_PROFILE_MOBILE = 0x1,
44         TIZEN_PROFILE_WEARABLE = 0x2,
45         TIZEN_PROFILE_TV = 0x4,
46         TIZEN_PROFILE_IVI = 0x8,
47         TIZEN_PROFILE_COMMON = 0x10,
48 } tizen_profile_t;
49
50 typedef struct {
51         int bandwidth;
52         int width;
53         int height;
54 } adaptive_variant_info_t;
55
56 static tizen_profile_t _get_tizen_profile()
57 {
58         char *profileName;
59         static tizen_profile_t profile = TIZEN_PROFILE_UNKNOWN;
60
61         if (__builtin_expect(profile != TIZEN_PROFILE_UNKNOWN, 1))
62                 return profile;
63
64         system_info_get_platform_string("http://tizen.org/feature/profile", &profileName);
65         switch (*profileName) {
66         case 'm':
67         case 'M':
68                 profile = TIZEN_PROFILE_MOBILE;
69                 break;
70         case 'w':
71         case 'W':
72                 profile = TIZEN_PROFILE_WEARABLE;
73                 break;
74         case 't':
75         case 'T':
76                 profile = TIZEN_PROFILE_TV;
77                 break;
78         case 'i':
79         case 'I':
80                 profile = TIZEN_PROFILE_IVI;
81                 break;
82         default: // common or unknown ==> ALL ARE COMMON.
83                 profile = TIZEN_PROFILE_COMMON;
84         }
85         free(profileName);
86
87         return profile;
88 }
89 #define TIZEN_TV  ((_get_tizen_profile()) == TIZEN_PROFILE_TV)
90
91 static gboolean g_memory_playback = FALSE;
92 static char g_uri[MAX_STRING_LEN];
93 static FILE *g_pcm_fd;
94
95 static gboolean is_es_push_mode = FALSE;
96 static pthread_t g_feed_audio_thread_id = 0;
97 static bool g_thread_end = FALSE;
98 static media_packet_h g_audio_pkt = NULL;
99 static media_format_h g_audio_fmt = NULL;
100
101 static int _save(unsigned char *src, int length);
102
103 #define DUMP_OUTBUF         1
104 #if DUMP_OUTBUF
105 FILE *fp_out1 = NULL;
106 FILE *fp_out2 = NULL;
107 #endif
108
109 enum {
110         CURRENT_STATUS_MAINMENU,
111         CURRENT_STATUS_HANDLE_NUM,
112         CURRENT_STATUS_FILENAME,
113         CURRENT_STATUS_VOLUME,
114         CURRENT_STATUS_SOUND_TYPE,
115         CURRENT_STATUS_SOUND_STREAM_INFO,
116         CURRENT_STATUS_MUTE,
117         CURRENT_STATUS_POSITION_TIME,
118         CURRENT_STATUS_LOOPING,
119         CURRENT_STATUS_AUDIO_EQUALIZER,
120         CURRENT_STATUS_PLAYBACK_RATE,
121         CURRENT_STATUS_STREAMING_PLAYBACK_RATE,
122         CURRENT_STATUS_NEXT_URI,
123         CURRENT_STATUS_GAPLESS,
124         CURRENT_STATUS_GET_TRACK_INFO,
125         CURRENT_STATUS_POSITION_ACCURATE,
126         CURRENT_STATUS_SET_MAX_BANDWIDTH_VARIANT,
127         CURRENT_STATUS_SET_MAX_WIDTH_VARIANT,
128         CURRENT_STATUS_SET_MAX_HEIGHT_VARIANT,
129 };
130
131 typedef struct {
132         int pos;
133         bool accurate;
134 } player_seek_pos_t;
135
136 #define MAX_HANDLE 20
137
138 static player_h g_player[MAX_HANDLE] = { 0, };
139 static player_seek_pos_t seek_info = {0};
140 int g_handle_num = 1;
141 int g_menu_state = CURRENT_STATUS_MAINMENU;
142 gboolean quit_pushing;
143 sound_stream_info_h g_stream_info_h = NULL;
144 static adaptive_variant_info_t max_limit = {-1, -1, -1};
145
146 static int app_create(void *data)
147 {
148         return 0;
149 }
150 static int app_terminate(void *data)
151 {
152         return 0;
153 }
154
155 struct appcore_ops ops = {
156         .create = app_create,
157         .terminate = app_terminate,
158 };
159
160 static void prepared_cb(void *user_data)
161 {
162         g_print("[Player_Audio_Test] prepared_cb!!!!\n");
163 }
164
165 static void _audio_frame_decoded_cb_ex(player_audio_raw_data_s * audio_raw_frame, void *user_data)
166 {
167         player_audio_raw_data_s *audio_raw = audio_raw_frame;
168
169         if (!audio_raw)
170                 return;
171
172         g_print("[Player_Audio_Test] decoded_cb_ex! channel: %d channel_mask: %llu\n", audio_raw->channel, audio_raw->channel_mask);
173
174 #if DUMP_OUTBUF
175         if (audio_raw->channel_mask == 1 && fp_out1)
176                 fwrite((guint8 *) audio_raw->data, 1, audio_raw->size, fp_out1);
177         else if (audio_raw->channel_mask == 2 && fp_out2)
178                 fwrite((guint8 *) audio_raw->data, 1, audio_raw->size, fp_out2);
179 #endif
180 }
181
182 static void progress_down_cb(player_pd_message_type_e type, void *user_data)
183 {
184         g_print("[Player_Audio_Test] progress_down_cb!!!! type : %d\n", type);
185 }
186
187 static void buffering_cb(int percent, void *user_data)
188 {
189         g_print("[Player_Audio_Test] buffering_cb!!!! percent : %d\n", percent);
190 }
191
192 static void seek_completed_cb(void *user_data)
193 {
194         g_print("[Player_Audio_Test] seek_completed_cb!!! \n");
195 }
196
197 static void completed_cb(void *user_data)
198 {
199         g_print("[Player_Audio_Test] completed_cb!!!!\n");
200 }
201
202 static void error_cb(int code, void *user_data)
203 {
204         g_print("[Player_Audio_Test] error_cb!!!! code : %d\n", code);
205 }
206
207 static void interrupted_cb(player_interrupted_code_e code, void *user_data)
208 {
209         g_print("[Player_Audio_Test] interrupted_cb!!!! code : %d\n", code);
210 }
211
212 static void video_changed_cb(int width, int height, int fps, int bit_rate, void *user_data)
213 {
214         g_print("[Player_Audio_Test] video_changed_cb!!!! %d x %d, %d, %d \n", width, height, fps, bit_rate);
215 }
216
217 #if 0
218 static void audio_frame_decoded_cb(unsigned char *data, unsigned int size, void *user_data)
219 {
220         int pos = 0;
221
222         if (data && g_pcm_fd)
223                 fwrite(data, 1, size, g_pcm_fd);
224         player_get_play_position(g_player[0], &pos);
225         g_print("[Player_Audio_Test] audio_frame_decoded_cb [size: %d] --- current pos : %d!!!!\n", size, pos);
226 }
227 #endif
228
229 static int _save(unsigned char *src, int length)
230 {
231         /* unlink(CAPTUERD_IMAGE_SAVE_PATH); */
232         FILE *fp;
233         char filename[256] = { 0, };
234         static int WRITE_COUNT = 0;
235         /* gchar *filename  = CAPTUERD_IMAGE_SAVE_PATH; */
236         snprintf(filename, 256, "/tmp/IMAGE_client%d", WRITE_COUNT);
237         WRITE_COUNT++;
238         fp = fopen(filename, "w+");
239         if (fp == NULL) {
240                 g_print("file open error!!\n");
241                 return FALSE;
242         } else {
243                 g_print("open success\n");
244                 if (fwrite(src, 1, length, fp) < 1) {
245                         g_print("file write error!!\n");
246                         fclose(fp);
247                         return FALSE;
248                 }
249                 g_print("write success(%s)\n", filename);
250                 fclose(fp);
251         }
252
253         return TRUE;
254 }
255
256 static void input_filename(char *filename)
257 {
258         int len = strlen(filename);
259         int i = 0;
260
261         if (len < 0 || len > MAX_STRING_LEN - 1)
262                 return;
263
264         for (i = 0; i < g_handle_num; i++) {
265                 if (g_player[i] != NULL) {
266                         player_unprepare(g_player[i]);
267                         player_destroy(g_player[i]);
268                 }
269                 g_player[i] = 0;
270
271                 if (player_create(&g_player[i]) != PLAYER_ERROR_NONE)
272                         g_print("player create is failed\n");
273         }
274         strncpy(g_uri, filename, len+1);
275
276 #if 0
277         /* ned(APPSRC_TEST) */
278         gchar uri[100];
279         gchar *ext;
280         gsize file_size;
281         GMappedFile *file;
282         GError *error = NULL;
283         guint8 *g_media_mem = NULL;
284
285         ext = filename;
286
287         file = g_mapped_file_new(ext, FALSE, &error);
288         file_size = g_mapped_file_get_length(file);
289         g_media_mem = (guint8 *) g_mapped_file_get_contents(file);
290
291         g_sprintf(uri, "mem://ext=%s,size=%d", ext ? ext : "", file_size);
292         g_print("[uri] = %s\n", uri);
293
294         mm_player_set_attribute(g_player[0], &g_err_name, "profile_uri", uri, strlen(uri), "profile_user_param", g_media_mem, file_size NULL);
295 #else
296         /* player_set_uri(g_player[0], filename); */
297 #endif
298         /* APPSRC_TEST */
299
300         int ret;
301         player_state_e state;
302         for (i = 0; i < g_handle_num; i++) {
303                 ret = player_get_state(g_player[i], &state);
304                 g_print("player_get_state returned [%d]\n", ret);
305                 g_print("1. After player_create() - Current State : %d \n", state);
306         }
307 }
308
309 /* use this API instead of player_set_uri */
310 static void player_set_memory_buffer_test()
311 {
312         GMappedFile *file;
313         gsize file_size;
314         guint8 *g_media_mem = NULL;
315
316         file = g_mapped_file_new(g_uri, FALSE, NULL);
317         file_size = g_mapped_file_get_length(file);
318         g_media_mem = (guint8 *) g_mapped_file_get_contents(file);
319
320         int ret = player_set_memory_buffer(g_player[0], (void *)g_media_mem, file_size);
321         g_print("player_set_memory_buffer ret : %d\n", ret);
322 }
323
324
325 int audio_packet_count = 0;
326 static void buffer_need_audio_data_cb(unsigned int size, void *user_data)
327 {
328         int real_read_len = 0;
329         char fname[128];
330         FILE *fp = NULL;
331         guint8 *buff_ptr = NULL;
332         void *src = NULL;
333
334         memset(fname, 0, 128);
335         audio_packet_count++;
336
337         if (audio_packet_count > 1000) {
338                 g_print("EOS.\n");
339                 /* player_submit_packet(g_player[0], NULL, 0, 0, 0); */
340                 player_push_media_stream(g_player[0], NULL);
341                 g_thread_end = TRUE;
342         }
343
344         /* snprintf(fname, 128, "/opt/storage/usb/test/audio_packet/packet_%d.dat", audio_packet_count); */
345         snprintf(fname, 128, "/home/developer/test/audio_packet/packet_%d.dat", audio_packet_count);
346
347         static guint64 audio_pts = 0;
348         guint64 audio_dur = 21333333;
349
350         fp = fopen(fname, "rb");
351         if (fp) {
352                 buff_ptr = (guint8 *) g_malloc0(1048576);
353                 if (!buff_ptr) {
354                         g_print("no free space\n");
355                         fclose(fp);
356                         fp = NULL;
357                         return;
358                 }
359                 real_read_len = fread(buff_ptr, 1, size, fp);
360                 fclose(fp);
361                 fp = NULL;
362
363                 g_print("\t audio need data - data size : %d, pts : %" G_GUINT64_FORMAT "\n", real_read_len, audio_pts);
364         }
365 #if 0
366         player_submit_packet(g_player[0], buff_ptr, real_read_len, (audio_pts / 1000000), 0);
367 #else
368         /* create media packet */
369         if (g_audio_pkt) {
370                 media_packet_destroy(g_audio_pkt);
371                 g_audio_pkt = NULL;
372         }
373         media_packet_create_alloc(g_audio_fmt, NULL, NULL, &g_audio_pkt);
374
375         g_print("packet = %p, src = %p\n", g_audio_pkt, src);
376
377         if (media_packet_get_buffer_data_ptr(g_audio_pkt, &src) != MEDIA_PACKET_ERROR_NONE)
378                 goto EXIT;
379
380         if (media_packet_set_pts(g_audio_pkt, (uint64_t) audio_pts) != MEDIA_PACKET_ERROR_NONE)
381                 goto EXIT;
382
383         if (media_packet_set_buffer_size(g_audio_pkt, (uint64_t) real_read_len) != MEDIA_PACKET_ERROR_NONE)
384                 goto EXIT;
385
386         memcpy(src, buff_ptr, real_read_len);
387
388         /* then, push it  */
389         player_push_media_stream(g_player[0], g_audio_pkt);
390 #endif
391
392         audio_pts += audio_dur;
393  EXIT:
394         if (buff_ptr) {
395                 g_free(buff_ptr);
396                 buff_ptr = NULL;
397         }
398 }
399
400 static void set_content_info(bool is_push_mode)
401 {
402         /* testcode for es buff src case, please input url as es_buff://123 or es_buff://push_mode */
403         /* 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}; */
404
405         /* create media format */
406         media_format_create(&g_audio_fmt);
407
408         /* Audio--aac--StarWars.mp4 */
409         media_format_set_audio_mime(g_audio_fmt, MEDIA_FORMAT_AAC);
410         media_format_set_audio_channel(g_audio_fmt, 2);
411         media_format_set_audio_samplerate(g_audio_fmt, 48000);
412         /* player_set_media_stream_info(g_player[0], PLAYER_STREAM_TYPE_AUDIO, g_audio_fmt); */
413 #if 0
414         /* audio--aac--StarWars.mp4 */
415         /* audio_info->mime = g_strdup("audio/mpeg"); */
416         /* audio_info->version = 2; */
417         /* audio_info->user_info = 0; *//* raw */
418 #endif
419
420 #ifdef _ES_PULL_
421         if (!is_push_mode) {
422                 player_set_buffer_need_audio_data_cb(g_player[0], buffer_need_audio_data_cb, (void *)g_player[0]);
423         }
424 #endif
425 }
426
427 static void feed_audio_data_thread_func(void *data)
428 {
429         while (!g_thread_end) {
430                 buffer_need_audio_data_cb(1048576, NULL);
431         }
432 }
433
434 static void _player_prepare(bool async)
435 {
436         int ret = FALSE;
437         int i = 0;
438         for (i = 0; i < g_handle_num; i++) {
439                 player_set_buffering_cb(g_player[i], buffering_cb, (void *)g_player[i]);
440                 player_set_completed_cb(g_player[i], completed_cb, (void *)g_player[i]);
441                 player_set_interrupted_cb(g_player[i], interrupted_cb, (void *)g_player[i]);
442                 player_set_error_cb(g_player[i], error_cb, (void *)g_player[i]);
443                 player_set_video_stream_changed_cb(g_player[0], video_changed_cb, (void *)g_player[0]);
444                 if (g_memory_playback)
445                         player_set_memory_buffer_test();
446                 else
447                         player_set_uri(g_player[i], g_uri);
448         }
449
450         if (strstr(g_uri, "es_buff://")) {
451                 is_es_push_mode = FALSE;
452                 audio_packet_count = 0;
453
454                 if (strstr(g_uri, "es_buff://push_mode")) {
455                         set_content_info(TRUE);
456                         async = TRUE;
457                         is_es_push_mode = TRUE;
458 #ifdef _ES_PULL_
459                 } else {
460                         set_content_info(FALSE);
461 #endif
462                 }
463         }
464
465         for (i = 0; i < g_handle_num; i++) {
466                 if (async)
467                         ret = player_prepare_async(g_player[i], prepared_cb, (void *)g_player[i]);
468                 else
469                         ret = player_prepare(g_player[i]);
470         }
471
472         if (ret != PLAYER_ERROR_NONE)
473                 g_print("prepare is failed (errno = %d) \n", ret);
474
475         player_state_e state;
476
477         for (i = 0; i < g_handle_num; i++) {
478                 ret = player_get_state(g_player[i], &state);
479                 g_print("After player_prepare() - Current State : %d \n", state);
480         }
481
482         if (is_es_push_mode)
483                 pthread_create(&g_feed_audio_thread_id, NULL, (void *)feed_audio_data_thread_func, NULL);
484
485 }
486
487 static void _player_unprepare()
488 {
489         int ret = FALSE;
490         int i = 0;
491         player_state_e state;
492
493         for (i = 0; i < g_handle_num; i++) {
494                 if (g_player[i] != NULL) {
495                         ret = player_unprepare(g_player[i]);
496                         if (ret != PLAYER_ERROR_NONE)
497                                 g_print("unprepare is failed (errno = %d) \n", ret);
498
499                         ret = player_unset_subtitle_updated_cb(g_player[i]);
500                         g_print("player_unset_subtitle_updated_cb [%d] ret %d\n", i, ret);
501
502                         ret = player_unset_buffering_cb(g_player[i]);
503                         g_print("player_unset_buffering_cb [%d] ret %d\n", i, ret);
504
505                         ret = player_unset_completed_cb(g_player[i]);
506                         g_print("player_unset_completed_cb [%d] ret %d\n", i, ret);
507
508                         ret = player_unset_interrupted_cb(g_player[i]);
509                         g_print("player_unset_interrupted_cb [%d] ret %d\n", i, ret);
510
511                         ret = player_unset_error_cb(g_player[i]);
512                         g_print("player_unset_error_cb [%d] ret %d\n", i, ret);
513                 }
514         }
515
516         for (i = 0; i < g_handle_num; i++) {
517                 ret = player_get_state(g_player[i], &state);
518                 g_print(" After player_unprepare() - Current State : %d \n", state);
519         }
520 }
521
522 static void _player_destroy()
523 {
524         int i = 0;
525
526         for (i = 0; i < g_handle_num; i++) {
527                 if (g_player[i] != NULL) {
528                         player_unprepare(g_player[i]);
529                         player_destroy(g_player[i]);
530                         g_player[i] = 0;
531                 }
532         }
533
534         if (g_stream_info_h) {
535                 sound_manager_destroy_stream_information(g_stream_info_h);
536                 g_stream_info_h = NULL;
537         }
538
539         if (g_audio_pkt)
540                 media_packet_destroy(g_audio_pkt);
541
542 #if DUMP_OUTBUF
543         if (fp_out1)
544                 fclose(fp_out1);
545         if (fp_out2)
546                 fclose(fp_out2);
547 #endif
548
549 }
550
551 static void _player_play()
552 {
553         int bRet = FALSE;
554         int i = 0;
555         for (i = 0; i < g_handle_num; i++) {
556                 bRet = player_start(g_player[i]);
557                 g_print("player_start returned [%d]", bRet);
558         }
559 }
560
561 static void _player_stop()
562 {
563         int bRet = FALSE;
564         int i = 0;
565
566         for (i = 0; i < g_handle_num; i++) {
567                 bRet = player_stop(g_player[i]);
568                 g_print("player_stop returned [%d]", bRet);
569         }
570
571         g_thread_end = TRUE;
572         if (g_feed_audio_thread_id) {
573                 pthread_join(g_feed_audio_thread_id, NULL);
574                 g_feed_audio_thread_id = 0;
575         }
576
577 }
578
579 static void _player_resume()
580 {
581         int bRet = FALSE;
582         int i = 0;
583
584         for (i = 0; i < g_handle_num; i++) {
585                 bRet = player_start(g_player[i]);
586                 g_print("player_start returned [%d]", bRet);
587         }
588 }
589
590 static void _player_pause()
591 {
592         int bRet = FALSE;
593         int i = 0;
594         for (i = 0; i < g_handle_num; i++) {
595                 bRet = player_pause(g_player[i]);
596                 g_print("player_pause returned [%d]", bRet);
597         }
598 }
599
600 static void _player_state()
601 {
602         player_state_e state;
603         player_get_state(g_player[0], &state);
604         g_print("                                                            ==> [Player_Audio_Test] Current Player State : %d\n", state);
605 }
606
607 static void _player_set_progressive_download()
608 {
609         player_set_progressive_download_path(g_player[0], "/home/owner/test.pd");
610         player_set_progressive_download_message_cb(g_player[0], progress_down_cb, (void *)g_player[0]);
611 }
612
613 static void _player_get_progressive_download_status()
614 {
615         int bRet = 0;
616         unsigned long curr = 0, total = 0;
617         bRet = player_get_progressive_download_status(g_player[0], &curr, &total);
618         g_print("player_get_progressive_download_status return[%d]           ==> [Player_Audio_Test] progressive download status : %lu/%lu\n", bRet, curr, total);
619 }
620
621 static void set_next_uri(char * uri)
622 {
623         if (TIZEN_TV) {
624                 g_print("not support at TV profile");
625                 return;
626         }
627
628         if (player_set_next_uri(g_player[0], uri) != PLAYER_ERROR_NONE)
629                 g_print("fail to set next uri");
630 }
631
632 static void get_next_uri()
633 {
634         char *uri;
635
636         if (TIZEN_TV) {
637                 g_print("not support at TV profile");
638                 return;
639         }
640
641         if (player_get_next_uri(g_player[0], &uri) != PLAYER_ERROR_NONE) {
642                 g_print("fail to get next uri");
643                 return;
644         }
645
646         if (uri != NULL) {
647                 g_print("next_uri = %s", uri);
648                 free(uri);
649         }
650 }
651
652 static void set_volume(float volume)
653 {
654         if (player_set_volume(g_player[0], volume, volume) != PLAYER_ERROR_NONE)
655                 g_print("failed to set volume\n");
656 }
657
658 static void get_volume(float *left, float *right)
659 {
660         player_get_volume(g_player[0], left, right);
661         g_print("                                                            ==> [Player_Audio_Test] volume - left : %f, right : %f\n", *left, *right);
662 }
663
664 static void set_mute(bool mute)
665 {
666         if (player_set_mute(g_player[0], mute) != PLAYER_ERROR_NONE)
667                 g_print("failed to set_mute\n");
668 }
669
670 static void get_mute(bool * mute)
671 {
672         player_is_muted(g_player[0], mute);
673         g_print("                                                            ==> [Player_Audio_Test] mute = %d\n", *mute);
674 }
675
676 static void set_sound_type(sound_type_e type)
677 {
678         if (player_set_sound_type(g_player[0], type) != PLAYER_ERROR_NONE)
679                 g_print("failed to set sound type(%d)\n", type);
680         else
681                 g_print("set sound type(%d) success", type);
682 }
683
684 void focus_callback(sound_stream_info_h stream_info,
685                                         sound_stream_focus_mask_e focus_mask,
686                                         sound_stream_focus_state_e focus_state,
687                                         sound_stream_focus_change_reason_e reason,
688                                         int sound_behavior,
689                                         const char *extra_info,
690                                         void *user_data)
691 {
692         g_print("FOCUS callback is called, reason(%d), extra_info(%s), userdata(%p)", reason, extra_info, user_data);
693         return;
694 }
695
696 static void set_sound_stream_info(int type)
697 {
698         sound_device_list_h device_list = NULL;
699         int ret = SOUND_MANAGER_ERROR_NONE;
700
701         if (g_stream_info_h) {
702                 g_print("stream information is already set, please destory handle and try again\n");
703                 return;
704         }
705         if (sound_manager_create_stream_information(type, focus_callback, g_player[0], &g_stream_info_h)) {
706                 g_print("failed to create stream_information()\n");
707                 return;
708         }
709         /* In case of MEDIA_EXTERNAL_ONLY, we need to set external device manually */
710         if (type == (int)SOUND_STREAM_TYPE_MEDIA_EXTERNAL_ONLY) {
711                 sound_device_h device = NULL;
712                 sound_device_type_e device_type;
713
714                 if ((ret = sound_manager_get_device_list(SOUND_DEVICE_ALL_MASK, &device_list))) {
715                         g_print("failed to sound_manager_get_device_list(), ret(0x%x)\n", ret);
716                         goto END;
717                 }
718                 while (!(ret = sound_manager_get_next_device(device_list, &device))) {
719                         if ((ret = sound_manager_get_device_type(device, &device_type))) {
720                                 g_print("failed to sound_manager_get_device_type(), ret(0x%x)\n", ret);
721                                 goto END;
722                         }
723                         if (device_type == SOUND_DEVICE_BLUETOOTH || device_type == SOUND_DEVICE_USB_AUDIO) {
724                                 if ((ret = sound_manager_add_device_for_stream_routing(g_stream_info_h, device))) {
725                                         g_print("failed to sound_manager_add_device_for_stream_routing(), ret(0x%x)\n", ret);
726                                         goto END;
727                                 }
728                                 if ((ret = sound_manager_apply_stream_routing(g_stream_info_h))) {
729                                         g_print("failed to sound_manager_apply_stream_routing(), ret(0x%x)\n", ret);
730                                         goto END;
731                                 }
732                                 break;
733                         }
734                 }
735                 if (ret != SOUND_MANAGER_ERROR_NONE) {
736                         g_print("failed to sound_manager_get_next_device(), ret(0x%x)\n", ret);
737                         goto END;
738                 }
739         }
740
741         if (player_set_sound_stream_info(g_player[0], g_stream_info_h) != PLAYER_ERROR_NONE)
742                 g_print("failed to set sound stream information(%p)\n", g_stream_info_h);
743         else
744                 g_print("set stream information(%p) success", g_stream_info_h);
745
746  END:
747         if (device_list)
748                 sound_manager_free_device_list(device_list);
749         return;
750 }
751
752 void variant_cb(int bandwidth, int width, int height, void *user_data)
753 {
754         g_print("                                                            ==> [Player_Audio_Test][b]%d, [w]%d, [h]%d\n", bandwidth, width, height);
755 }
756
757 static void get_variant_info()
758 {
759         player_foreach_adaptive_variant(g_player[0], (player_adaptive_variant_cb)variant_cb, g_player[0]);
760 }
761
762 static void get_variant_limit()
763 {
764         int bandwidth, width, height;
765         player_get_max_adaptive_variant_limit(g_player[0], &bandwidth, &width, &height);
766         g_print("                                                            ==> [Player_Audio_Test]get [b]%d, [w]%d, [h]%d\n", bandwidth, width, height);
767 }
768
769 static void set_variant_limit()
770 {
771         g_print("                                                            ==> [Player_Audio_Test]set [b]%d, [w]%d, [h]%d\n", max_limit.bandwidth, max_limit.width, max_limit.height);
772         player_set_max_adaptive_variant_limit(g_player[0], max_limit.bandwidth, max_limit.width, max_limit.height);
773 }
774
775 static void get_position()
776 {
777         int position = 0;
778         int ret;
779         ret = player_get_play_position(g_player[0], &position);
780         g_print("                                                            ==> [Player_Audio_Test] player_get_play_position()%d return : %d\n", ret, position);
781 }
782
783 static void set_position(int position, bool accurate)
784 {
785         if (player_set_play_position(g_player[0], position, accurate, seek_completed_cb, g_player[0]) != PLAYER_ERROR_NONE)
786                 g_print("failed to set position\n");
787 }
788
789 static void set_playback_rate(float rate, bool streaming)
790 {
791         if (streaming) {
792                 if (player_set_streaming_playback_rate(g_player[0], rate) != PLAYER_ERROR_NONE)
793                         g_print("failed to set streaming playback rate\n");
794         } else {
795                 if (player_set_playback_rate(g_player[0], rate) != PLAYER_ERROR_NONE)
796                         g_print("failed to set playback rate\n");
797         }
798 }
799
800 static void get_duration()
801 {
802         int duration = 0;
803         int ret;
804         ret = player_get_duration(g_player[0], &duration);
805         g_print("                                                            ==> [Player_Audio_Test] player_get_duration() return : %d\n", ret);
806         g_print("                                                            ==> [Player_Audio_Test] Duration: [%d ] msec\n", duration);
807 }
808
809 static void audio_frame_decoded_cb_ex(bool sync)
810 {
811         int ret;
812 #if DUMP_OUTBUF
813         fp_out1 = fopen("/tmp/out1.pcm", "wb");
814         fp_out2 = fopen("/tmp/out2.pcm", "wb");
815         if (!fp_out1 || !fp_out2) {
816                 g_print("File open error\n");
817                 return;
818         }
819 #endif
820
821         ret = player_set_pcm_extraction_mode(g_player[0], sync, _audio_frame_decoded_cb_ex, &ret);
822         g_print("                                                            ==> [Player_Audio_Test] player_set_audio_frame_decoded_cb_ex(sync:%d) ret:%d\n", sync, ret);
823
824         ret = player_set_pcm_spec(g_player[0], "F32LE", 44100, 2);
825         g_print("[Player_Audio_Test] set_pcm_spec return: %d\n", ret);
826 }
827
828 static void get_stream_info()
829 {
830         int w = 0;
831         int h = 0;
832
833         char *value = NULL;
834         player_get_content_info(g_player[0], PLAYER_CONTENT_INFO_ALBUM, &value);
835         g_print("                                                            ==> [Player_Audio_Test] PLAYER_CONTENT_INFO_ALBUM: [%s ] \n", value);
836         player_get_content_info(g_player[0], PLAYER_CONTENT_INFO_ARTIST, &value);
837         g_print("                                                            ==> [Player_Audio_Test] PLAYER_CONTENT_INFO_ARTIST: [%s ] \n", value);
838         player_get_content_info(g_player[0], PLAYER_CONTENT_INFO_AUTHOR, &value);
839         g_print("                                                            ==> [Player_Audio_Test] PLAYER_CONTENT_INFO_AUTHOR: [%s ] \n", value);
840         player_get_content_info(g_player[0], PLAYER_CONTENT_INFO_GENRE, &value);
841         g_print("                                                            ==> [Player_Audio_Test] PLAYER_CONTENT_INFO_GENRE: [%s ] \n", value);
842         player_get_content_info(g_player[0], PLAYER_CONTENT_INFO_TITLE, &value);
843         g_print("                                                            ==> [Player_Audio_Test] PLAYER_CONTENT_INFO_TITLE: [%s ] \n", value);
844         void *album;
845         int size;
846         player_get_album_art(g_player[0], &album, &size);
847         g_print("                                                            ==> [Player_Audio_Test] Album art : [ data : %p, size : %d ]\n", (unsigned int *)album, size);
848         _save(album, size);
849         if (value != NULL) {
850                 free(value);
851                 value = NULL;
852         }
853
854         int sample_rate;
855         int channel;
856         int bit_rate;
857         int fps, v_bit_rate;
858         player_get_audio_stream_info(g_player[0], &sample_rate, &channel, &bit_rate);
859         g_print("                                                            ==> [Player_Audio_Test] Sample Rate: [%d ] , Channel: [%d ] , Bit Rate: [%d ] \n", sample_rate, channel, bit_rate);
860
861         player_get_video_stream_info(g_player[0], &fps, &v_bit_rate);
862         g_print("                                                            ==> [Player_Audio_Test] fps: [%d ] , Bit Rate: [%d ] \n", fps, v_bit_rate);
863
864         char *audio_codec = NULL;
865         char *video_codec = NULL;
866         player_get_codec_info(g_player[0], &audio_codec, &video_codec);
867         if (audio_codec != NULL) {
868                 g_print("                                                            ==> [Player_Audio_Test] Audio Codec: [%s ] \n", audio_codec);
869                 free(audio_codec);
870                 audio_codec = NULL;
871         }
872         if (video_codec != NULL) {
873                 g_print("                                                            ==> [Player_Audio_Test] Video Codec: [%s ] \n", video_codec);
874                 free(video_codec);
875                 video_codec = NULL;
876         }
877         player_get_video_size(g_player[0], &w, &h);
878         g_print("                                                            ==> [Player_Audio_Test] Width: [%d ] , Height: [%d ] \n", w, h);
879 }
880
881 static void set_gapless(bool gapless)
882 {
883         int i = 0;
884
885         if (TIZEN_TV) {
886                 g_print("not support at TV profile");
887                 return;
888         }
889
890         for (i = 0; i < g_handle_num; i++) {
891                 if (player_set_gapless(g_player[i], gapless) != PLAYER_ERROR_NONE)
892                         g_print("failed to set_gapless\n");
893         }
894 }
895
896 static void set_looping(bool looping)
897 {
898         int i = 0;
899         for (i = 0; i < g_handle_num; i++) {
900                 if (player_set_looping(g_player[i], looping) != PLAYER_ERROR_NONE)
901                         g_print("failed to set_looping\n");
902         }
903 }
904
905 static void get_looping(bool * looping)
906 {
907         player_is_looping(g_player[0], looping);
908         g_print("                                                            ==> [Player_Audio_Test] looping = %d\n", *looping);
909 }
910
911 static void get_track_info(int index)
912 {
913         int count = 0, cur_index = 0;
914         int ret = 0;
915         char *lang_code = NULL;
916
917         if (index != PLAYER_STREAM_TYPE_AUDIO &&
918                 index != PLAYER_STREAM_TYPE_TEXT) {
919                 g_print("invalid stream type %d", index);
920                 return;
921         }
922
923         ret = player_get_track_count(g_player[0], index, &count);
924         if (ret != PLAYER_ERROR_NONE)
925                 g_print("player_get_track_count fail!!!!\n");
926         else if (count) {
927                 int idx = 0;
928                 player_get_current_track(g_player[0], index, &cur_index);
929                 g_print("total track: %d, curr track: %d\n", count, cur_index);
930
931                 for (idx = 0; idx < count; idx++) {
932                         player_get_track_language_code(g_player[0], index, idx, &lang_code);
933                         g_print("track info = [%d] %s\n", idx, lang_code);
934                 }
935         } else {
936                 g_print("no track\n");
937         }
938 }
939
940 static void decoding_audio()
941 {
942 #if 0
943         int ret;
944         char *suffix, *dump_path;
945         GDateTime *time = g_date_time_new_now_local();
946
947         suffix = g_date_time_format(time, "%Y%m%d_%H%M%S.pcm");
948         dump_path = g_strjoin(NULL, PLAYER_AUDIO_TEST_DUMP_PATH_PREFIX, suffix, NULL);
949         g_pcm_fd = fopen(dump_path, "w+");
950         g_free(dump_path);
951         g_free(suffix);
952         g_date_time_unref(time);
953         if (!g_pcm_fd)
954                 g_print("Can not create debug dump file");
955
956         ret = player_set_audio_frame_decoded_cb(g_player[0], 0, 0, audio_frame_decoded_cb, (void *)g_player[0]);
957         if (ret != PLAYER_ERROR_NONE)
958                 g_print("player_set_audio_frame_decoded_cb is failed (errno = %d) \n", ret);
959 #endif
960 }
961
962 static void set_audio_eq(int value)
963 {
964         bool available = FALSE;
965         int index, min = 0, max = 0;
966
967         if (value) {
968                 if (player_audio_effect_equalizer_is_available(g_player[0], &available) != PLAYER_ERROR_NONE)
969                         g_print("failed to player_audio_effect_equalizer_is_available\n");
970
971                 if (available) {
972                         if ((player_audio_effect_get_equalizer_bands_count(g_player[0], &index) != PLAYER_ERROR_NONE) ||
973                                 (player_audio_effect_get_equalizer_level_range(g_player[0], &min, &max) != PLAYER_ERROR_NONE) ||
974                                 (player_audio_effect_set_equalizer_band_level(g_player[0], index / 2, max) != PLAYER_ERROR_NONE))
975                                 g_print("failed to player_audio_effect_set_equalizer_band_level index %d, level %d\n", index / 2, max);
976                 }
977         }
978
979         else {
980                 if (player_audio_effect_equalizer_clear(g_player[0]) != PLAYER_ERROR_NONE)
981                         g_print("failed to player_audio_effect_equalizer_clear\n");
982         }
983
984 }
985
986 static void get_audio_eq()
987 {
988         int index, min, max, value;
989         player_audio_effect_get_equalizer_bands_count(g_player[0], &index);
990         g_print("                                                            ==> [Player_Audio_Test] eq bands count: [%d] \n", index);
991         player_audio_effect_get_equalizer_level_range(g_player[0], &min, &max);
992         g_print("                                                            ==> [Player_Audio_Test] eq bands range: [%d~%d] \n", min, max);
993         player_audio_effect_get_equalizer_band_level(g_player[0], index / 2, &value);
994         g_print("                                                            ==> [Player_Audio_Test] eq bands level: [%d] \n", value);
995         player_audio_effect_get_equalizer_band_frequency(g_player[0], 0, &value);
996         g_print("                                                            ==> [Player_Audio_Test] eq bands frequency: [%d] \n", value);
997         player_audio_effect_get_equalizer_band_frequency_range(g_player[0], 0, &value);
998         g_print("                                                            ==> [Player_Audio_Test] eq bands frequency range: [%d] \n", value);
999 }
1000
1001 void quit_program()
1002 {
1003
1004         if (g_pcm_fd)
1005                 fclose(g_pcm_fd);
1006
1007         if (g_player[0] != NULL || g_player[1] != NULL) {
1008                 _player_unprepare();
1009                 _player_destroy();
1010         }
1011         printf("call quit_program, but can not call elm_exit()..please Ctrl+c\n");
1012 #ifdef TIZEN_PLAYER_TEST_ENABLE_VIDEO
1013         elm_exit();
1014 #endif
1015         if (g_audio_fmt)
1016                 media_format_unref(g_audio_fmt);
1017 }
1018
1019 void play_with_ini(char *file_path)
1020 {
1021         input_filename(file_path);
1022         _player_play();
1023 }
1024
1025 void _interpret_main_menu(char *cmd)
1026 {
1027         int len = strlen(cmd);
1028         if (len == 1) {
1029                 if (strncmp(cmd, "a", 1) == 0) {
1030                         g_menu_state = CURRENT_STATUS_FILENAME;
1031                 } else if (strncmp(cmd, "b", 1) == 0) {
1032                         _player_play();
1033                 } else if (strncmp(cmd, "c", 1) == 0) {
1034                         _player_stop();
1035                 } else if (strncmp(cmd, "d", 1) == 0) {
1036                         _player_resume();
1037                 } else if (strncmp(cmd, "e", 1) == 0) {
1038                         _player_pause();
1039                 } else if (strncmp(cmd, "S", 1) == 0) {
1040                         _player_state();
1041                 } else if (strncmp(cmd, "f", 1) == 0) {
1042                         g_menu_state = CURRENT_STATUS_VOLUME;
1043                 } else if (strncmp(cmd, "g", 1) == 0) {
1044                         float left;
1045                         float right;
1046                         get_volume(&left, &right);
1047                 } else if (strncmp(cmd, "z", 1) == 0) {
1048                         g_menu_state = CURRENT_STATUS_SOUND_TYPE;
1049                 } else if (strncmp(cmd, "k", 1) == 0) {
1050                         g_menu_state = CURRENT_STATUS_SOUND_STREAM_INFO;
1051                 } else if (strncmp(cmd, "h", 1) == 0) {
1052                         g_menu_state = CURRENT_STATUS_MUTE;
1053                 } else if (strncmp(cmd, "i", 1) == 0) {
1054                         bool mute;
1055                         get_mute(&mute);
1056                 } else if (strncmp(cmd, "j", 1) == 0) {
1057                         g_menu_state = CURRENT_STATUS_POSITION_TIME;
1058                 } else if (strncmp(cmd, "l", 1) == 0) {
1059                         get_position();
1060                 } else if (strncmp(cmd, "m", 1) == 0) {
1061                         get_duration();
1062                 } else if (strncmp(cmd, "n", 1) == 0) {
1063                         get_stream_info();
1064                 } else if (strncmp(cmd, "o", 1) == 0) {
1065                         g_menu_state = CURRENT_STATUS_LOOPING;
1066                 } else if (strncmp(cmd, "p", 1) == 0) {
1067                         bool looping;
1068                         get_looping(&looping);
1069                 } else if (strncmp(cmd, "D", 1) == 0) {
1070                         decoding_audio();
1071                 } else if (strncmp(cmd, "q", 1) == 0) {
1072                         quit_pushing = TRUE;
1073                         quit_program();
1074                 } else if (strncmp(cmd, "E", 1) == 0) {
1075                         g_menu_state = CURRENT_STATUS_AUDIO_EQUALIZER;
1076                 } else if (strncmp(cmd, "H", 1) == 0) {
1077                         get_audio_eq();
1078                 } else {
1079                         g_print("unknown menu \n");
1080                 }
1081         } else if (len == 2) {
1082                 if (strncmp(cmd, "pr", 2) == 0) {
1083                         _player_prepare(FALSE);
1084                 } else if (strncmp(cmd, "pa", 2) == 0) {
1085                         _player_prepare(TRUE);
1086                 } else if (strncmp(cmd, "un", 2) == 0) {
1087                         _player_unprepare();
1088                 } else if (strncmp(cmd, "dt", 2) == 0) {
1089                         _player_destroy();
1090                 } else if (strncmp(cmd, "sp", 2) == 0) {
1091                         _player_set_progressive_download();
1092                 } else if (strncmp(cmd, "gp", 2) == 0) {
1093                         _player_get_progressive_download_status();
1094                 } else if (strncmp(cmd, "mp", 2) == 0) {
1095                         g_memory_playback = (g_memory_playback ? FALSE : TRUE);
1096                         g_print("memory playback = %d\n", g_memory_playback);
1097                 } else if (strncmp(cmd, "nb", 2) == 0) {
1098                         g_menu_state = CURRENT_STATUS_HANDLE_NUM;
1099                 } else if (strncmp(cmd, "tr", 2) == 0) {
1100                         g_menu_state = CURRENT_STATUS_PLAYBACK_RATE;
1101                 } else if (strncmp(cmd, "X3", 2) == 0) {
1102                         audio_frame_decoded_cb_ex(TRUE);
1103                 } else if (strncmp(cmd, "X4", 2) == 0) {
1104                         audio_frame_decoded_cb_ex(FALSE);
1105                 } else if (strncmp(cmd, "su", 2) == 0) {
1106                         g_menu_state = CURRENT_STATUS_NEXT_URI;
1107                 } else if (strncmp(cmd, "gu", 2) == 0) {
1108                         get_next_uri();
1109                 } else if (strncmp(cmd, "sg", 2) == 0) {
1110                         g_menu_state = CURRENT_STATUS_GAPLESS;
1111                 } else if (strncmp(cmd, "tl", 2) == 0) {
1112                         g_menu_state = CURRENT_STATUS_GET_TRACK_INFO;
1113                 } else if (strncmp(cmd, "vi", 2) == 0) {
1114                         get_variant_info();
1115                 } else if (strncmp(cmd, "vs", 2) == 0) {
1116                         g_menu_state = CURRENT_STATUS_SET_MAX_BANDWIDTH_VARIANT;
1117                 } else if (strncmp(cmd, "vg", 2) == 0) {
1118                         get_variant_limit();
1119                 } else {
1120                         g_print("unknown menu \n");
1121                 }
1122         } else {
1123                 if (strncmp(cmd, "trs", 3) == 0)
1124                         g_menu_state = CURRENT_STATUS_STREAMING_PLAYBACK_RATE;
1125                 else
1126                         g_print("unknown menu \n");
1127         }
1128 }
1129
1130 void display_sub_basic()
1131 {
1132         g_print("\n");
1133         g_print("=========================================================================================\n");
1134         g_print("                          Player Audio Test (press q to quit) \n");
1135         g_print("-----------------------------------------------------------------------------------------\n");
1136         g_print("[playback] a. Create\t");
1137         g_print("pr. Prepare  \t");
1138         g_print("pa. Prepare async \t");
1139         g_print("b. Play  \t");
1140         g_print("c. Stop  \t");
1141         g_print("d. Resume\t");
1142         g_print("e. Pause \t");
1143         g_print("un. Unprepare \t");
1144         g_print("dt. Destroy \n");
1145         g_print("[State] S. Player State \n");
1146         g_print("[ volume ] f. Set Volume\t");
1147         g_print("g. Get Volume\t");
1148         g_print("z. Set Sound type\t");
1149         g_print("k. Set Sound Stream Info.\n");
1150         g_print("[ mute ] h. Set Mute\t");
1151         g_print("i. Get Mute\n");
1152         g_print("[audio eq] E. Set Audio EQ\t");
1153         g_print("H. Get Audio EQ\n");
1154         g_print("[position] j. Set Position \t");
1155         g_print("l. Get Position\n");
1156         g_print("[trick] tr. set playback rate\n");
1157         g_print("[duration] m. Get Duration\n");
1158         g_print("[Stream Info] n. Get stream info (Video Size, codec, audio stream info, and tag info)\n");
1159         g_print("[Looping] o. Set Looping\t");
1160         g_print("p. Get Looping\n");
1161         g_print("[Track] tl. Get Track language info(single only)\n");
1162         g_print("[Variant] vi. Get Streaming Variant Info\t");
1163         g_print("vs. Set max limit of variant\t");
1164         g_print("vg. Get max limit of variant\n");
1165         g_print("[next uri] su. set next uri. \t");
1166         g_print("gu. get next uri. \t");
1167         g_print("sg. set gapless. \n");
1168         g_print("[audio_frame_decoded_cb_ex] X3. set audio_cb with sync\t");
1169         g_print("X4. set audio_cb with async \n");
1170         g_print("[etc] sp. Set Progressive Download\t");
1171         g_print("gp. Get Progressive Download status\t");
1172         g_print("mp. memory playback\n");
1173         g_print("\n");
1174         g_print("=========================================================================================\n");
1175 }
1176
1177 static void displaymenu()
1178 {
1179         if (g_menu_state == CURRENT_STATUS_MAINMENU) {
1180                 display_sub_basic();
1181         } else if (g_menu_state == CURRENT_STATUS_HANDLE_NUM) {
1182                 g_print("*** input number of handles.(recommended only for EVAS surface)\n");
1183         } else if (g_menu_state == CURRENT_STATUS_FILENAME) {
1184                 g_print("*** input mediapath.\n");
1185         } else if (g_menu_state == CURRENT_STATUS_VOLUME) {
1186                 g_print("*** input volume value.(0~1.0)\n");
1187         } else if (g_menu_state == CURRENT_STATUS_SOUND_TYPE) {
1188                 g_print("*** input sound type.(0:SYSTEM 1:NOTIFICATION 2:ALARM 3:RINGTONE 4:MEDIA 5:CALL 6:VOIP 7:FIXED)\n");
1189         } else if (g_menu_state == CURRENT_STATUS_SOUND_STREAM_INFO) {
1190                 g_print("*** input sound stream type.(0:MEDIA 1:SYSTEM 2:ALARM 3:NOTIFICATION 4:EMERGENCY 5:VOICE_INFORMATION 9:MEDIA_EXT_ONLY)\n");
1191         } else if (g_menu_state == CURRENT_STATUS_MUTE) {
1192                 g_print("*** input mute value.(0: Not Mute, 1: Mute) \n");
1193         } else if (g_menu_state == CURRENT_STATUS_POSITION_TIME) {
1194                 g_print("*** input position value(msec)\n");
1195         } else if (g_menu_state == CURRENT_STATUS_POSITION_ACCURATE) {
1196                 g_print("*** input accurate value(0/1)\n");
1197         } else if (g_menu_state == CURRENT_STATUS_LOOPING) {
1198                 g_print("*** input looping value.(0: Not Looping, 1: Looping) \n");
1199         } else if (g_menu_state == CURRENT_STATUS_AUDIO_EQUALIZER) {
1200                 g_print(" *** input audio eq value.(0: UNSET, 1: SET) \n");
1201         } else if (g_menu_state == CURRENT_STATUS_PLAYBACK_RATE || g_menu_state == CURRENT_STATUS_STREAMING_PLAYBACK_RATE) {
1202                 g_print(" *** input playback rate.(-5.0 ~ 5.0)\n");
1203         } else if (g_menu_state == CURRENT_STATUS_NEXT_URI) {
1204                 g_print("*** input next uri.\n");
1205         } else if (g_menu_state == CURRENT_STATUS_GAPLESS) {
1206                 g_print("*** input gapless value.(0:disable, 1: enable) \n");
1207         } else if (g_menu_state == CURRENT_STATUS_GET_TRACK_INFO) {
1208                 g_print("*** input stream type.(1:audio, 3:text) \n");
1209         } else if (g_menu_state == CURRENT_STATUS_SET_MAX_BANDWIDTH_VARIANT) {
1210                 g_print("*** set max bandwidth (default: -1) \n");
1211         } else if (g_menu_state == CURRENT_STATUS_SET_MAX_WIDTH_VARIANT) {
1212                 g_print("*** set max width (default: -1) \n");
1213         } else if (g_menu_state == CURRENT_STATUS_SET_MAX_HEIGHT_VARIANT) {
1214                 g_print("*** set max height (default: -1) \n");
1215         } else {
1216                 g_print("*** unknown status.\n");
1217                 quit_program();
1218         }
1219         g_print(" >>> ");
1220 }
1221
1222 gboolean timeout_menu_display(void *data)
1223 {
1224         displaymenu();
1225         return FALSE;
1226 }
1227
1228 gboolean timeout_quit_program(void *data)
1229 {
1230         quit_program();
1231         return FALSE;
1232 }
1233
1234 void reset_menu_state(void)
1235 {
1236         g_menu_state = CURRENT_STATUS_MAINMENU;
1237 }
1238
1239 static void interpret(char *cmd)
1240 {
1241         switch (g_menu_state) {
1242         case CURRENT_STATUS_MAINMENU:
1243                 {
1244                         _interpret_main_menu(cmd);
1245                 }
1246                 break;
1247         case CURRENT_STATUS_HANDLE_NUM:
1248                 {
1249                         int num_handle = atoi(cmd);
1250                         if (0 >= num_handle || num_handle > MAX_HANDLE)
1251                                 g_print("not supported this number for handles(%d)\n", num_handle);
1252                         else
1253                                 g_handle_num = num_handle;
1254
1255                         reset_menu_state();
1256                 }
1257                 break;
1258         case CURRENT_STATUS_FILENAME:
1259                 {
1260                         input_filename(cmd);
1261                         reset_menu_state();
1262                 }
1263                 break;
1264         case CURRENT_STATUS_VOLUME:
1265                 {
1266                         float level = atof(cmd);
1267                         set_volume(level);
1268                         reset_menu_state();
1269                 }
1270                 break;
1271         case CURRENT_STATUS_SOUND_TYPE:
1272                 {
1273                         int type = atoi(cmd);
1274                         set_sound_type(type);
1275                         reset_menu_state();
1276                 }
1277                 break;
1278         case CURRENT_STATUS_SOUND_STREAM_INFO:
1279                 {
1280                         int type = atoi(cmd);
1281                         set_sound_stream_info(type);
1282                         reset_menu_state();
1283                 }
1284                 break;
1285         case CURRENT_STATUS_MUTE:
1286                 {
1287                         int mute = atoi(cmd);
1288                         set_mute(mute);
1289                         reset_menu_state();
1290                 }
1291                 break;
1292         case CURRENT_STATUS_POSITION_TIME:
1293                 {
1294                         seek_info.pos = atoi(cmd);
1295                         g_menu_state = CURRENT_STATUS_POSITION_ACCURATE;
1296                 }
1297                 break;
1298         case CURRENT_STATUS_POSITION_ACCURATE:
1299                 {
1300                         seek_info.accurate = (atoi(cmd) != 0) ? (true) : (false);
1301                         set_position(seek_info.pos, seek_info.accurate);
1302                         reset_menu_state();
1303                 }
1304                 break;
1305         case CURRENT_STATUS_LOOPING:
1306                 {
1307                         int looping = atoi(cmd);
1308                         set_looping(looping);
1309                         reset_menu_state();
1310                 }
1311                 break;
1312         case CURRENT_STATUS_GAPLESS:
1313                 {
1314                         int gapless = atoi(cmd);
1315                         set_gapless(gapless);
1316                         reset_menu_state();
1317                 }
1318                 break;
1319         case CURRENT_STATUS_AUDIO_EQUALIZER:
1320                 {
1321                         int value = atoi(cmd);
1322                         set_audio_eq(value);
1323                         reset_menu_state();
1324                 }
1325                 break;
1326         case CURRENT_STATUS_PLAYBACK_RATE:
1327                 {
1328                         float rate = atof(cmd);
1329                         set_playback_rate(rate, FALSE);
1330                         reset_menu_state();
1331                 }
1332                 break;
1333         case CURRENT_STATUS_STREAMING_PLAYBACK_RATE:
1334                 {
1335                         float rate = atof(cmd);
1336                         set_playback_rate(rate, TRUE);
1337                         reset_menu_state();
1338                 }
1339                 break;
1340         case CURRENT_STATUS_NEXT_URI:
1341                 {
1342                         set_next_uri(cmd);
1343                         reset_menu_state();
1344                 }
1345                 break;
1346         case CURRENT_STATUS_GET_TRACK_INFO:
1347                 {
1348                         int index = atoi(cmd);
1349                         get_track_info(index);
1350                         reset_menu_state();
1351                 }
1352                 break;
1353         case CURRENT_STATUS_SET_MAX_BANDWIDTH_VARIANT:
1354                 {
1355                         int value = atoi(cmd);
1356                         max_limit.bandwidth = value;
1357                         g_menu_state = CURRENT_STATUS_SET_MAX_WIDTH_VARIANT;
1358                 }
1359                 break;
1360         case CURRENT_STATUS_SET_MAX_WIDTH_VARIANT:
1361                 {
1362                         int value = atoi(cmd);
1363                         max_limit.width = value;
1364                         g_menu_state = CURRENT_STATUS_SET_MAX_HEIGHT_VARIANT;
1365                 }
1366                 break;
1367         case CURRENT_STATUS_SET_MAX_HEIGHT_VARIANT:
1368                 {
1369                         int value = atoi(cmd);
1370                         max_limit.height = value;
1371                         set_variant_limit();
1372                         reset_menu_state();
1373                 }
1374                 break;
1375         }
1376
1377         g_timeout_add(100, timeout_menu_display, 0);
1378 }
1379
1380 gboolean input(GIOChannel * channel)
1381 {
1382         gchar buf[MAX_STRING_LEN];
1383         gsize read;
1384         GError *error = NULL;
1385
1386         g_io_channel_read_chars(channel, buf, MAX_STRING_LEN, &read, &error);
1387         buf[read] = '\0';
1388         g_strstrip(buf);
1389         interpret(buf);
1390
1391         return TRUE;
1392 }
1393
1394 int main(int argc, char *argv[])
1395 {
1396         GIOChannel *stdin_channel;
1397         stdin_channel = g_io_channel_unix_new(0);
1398         g_io_channel_set_flags(stdin_channel, G_IO_FLAG_NONBLOCK, NULL);
1399         g_io_add_watch(stdin_channel, G_IO_IN, (GIOFunc) input, NULL);
1400
1401         displaymenu();
1402         return appcore_efl_main(PACKAGE, &argc, &argv, &ops);
1403
1404 }