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