2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <system_info.h>
23 #include <sound_manager.h>
26 #include "player_internal.h"
31 #define PACKAGE "player_audio_test"
36 #define LOG_TAG "PLAYER_AUDIO_TEST"
38 #define MAX_STRING_LEN 2048
39 #define PLAYER_AUDIO_TEST_DUMP_PATH_PREFIX "/home/owner/dump_pcm_"
40 #define DEFAULT_HTTP_TIMEOUT -1
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,
56 } adaptive_variant_info_t;
58 static tizen_profile_t _get_tizen_profile()
61 static tizen_profile_t profile = TIZEN_PROFILE_UNKNOWN;
63 if (__builtin_expect(profile != TIZEN_PROFILE_UNKNOWN, 1))
66 system_info_get_platform_string("http://tizen.org/feature/profile", &profileName);
67 switch (*profileName) {
70 profile = TIZEN_PROFILE_MOBILE;
74 profile = TIZEN_PROFILE_WEARABLE;
78 profile = TIZEN_PROFILE_TV;
82 profile = TIZEN_PROFILE_IVI;
84 default: // common or unknown ==> ALL ARE COMMON.
85 profile = TIZEN_PROFILE_COMMON;
91 #define TIZEN_TV ((_get_tizen_profile()) == TIZEN_PROFILE_TV)
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;
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;
104 static int _save(unsigned char *src, int length);
106 #define DUMP_OUTBUF 1
108 FILE *fp_out1 = NULL;
109 FILE *fp_out2 = NULL;
113 CURRENT_STATUS_MAINMENU,
114 CURRENT_STATUS_HANDLE_NUM,
115 CURRENT_STATUS_FILENAME,
116 CURRENT_STATUS_VOLUME,
117 CURRENT_STATUS_SOUND_STREAM_INFO,
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,
139 #define MAX_HANDLE 20
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};
148 static void prepared_cb(void *user_data)
150 g_print("[Player_Audio_Test] prepared_cb!!!!\n");
153 static void buffering_cb(int percent, void *user_data)
155 g_print("[Player_Audio_Test] buffering_cb!!!! percent : %d\n", percent);
158 static void seek_completed_cb(void *user_data)
160 g_print("[Player_Audio_Test] seek_completed_cb!!! \n");
163 static void completed_cb(void *user_data)
165 g_print("[Player_Audio_Test] completed_cb!!!!\n");
168 static void error_cb(int code, void *user_data)
170 g_print("[Player_Audio_Test] error_cb!!!! code : %d\n", code);
173 static void interrupted_cb(player_interrupted_code_e code, void *user_data)
175 g_print("[Player_Audio_Test] interrupted_cb!!!! code : %d\n", code);
178 static void video_changed_cb(int width, int height, int fps, int bit_rate, void *user_data)
180 g_print("[Player_Audio_Test] video_changed_cb!!!! %d x %d, %d, %d \n", width, height, fps, bit_rate);
184 static void audio_frame_decoded_cb(unsigned char *data, unsigned int size, void *user_data)
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);
195 static int _save(unsigned char *src, int length)
197 /* unlink(CAPTUERD_IMAGE_SAVE_PATH); */
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);
204 fp = fopen(filename, "w+");
206 g_print("file open error!!\n");
209 g_print("open success\n");
210 if (fwrite(src, 1, length, fp) < 1) {
211 g_print("file write error!!\n");
215 g_print("write success(%s)\n", filename);
222 static void input_filename(char *filename)
230 len = strlen(filename);
231 if (len < 0 || len > MAX_STRING_LEN - 1)
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]);
241 if (player_create(&g_player[i]) != PLAYER_ERROR_NONE)
242 g_print("player create is failed\n");
245 g_strlcpy(g_uri, filename, MAX_STRING_LEN);
248 /* ned(APPSRC_TEST) */
253 GError *error = NULL;
254 guint8 *g_media_mem = NULL;
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);
262 g_sprintf(uri, "mem://ext=%s,size=%d", ext ? ext : "", file_size);
263 g_print("[uri] = %s\n", uri);
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);
267 /* player_set_uri(g_player[0], filename); */
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);
280 /* use this API instead of player_set_uri */
281 static void player_set_memory_buffer_test()
284 guint8 *g_media_mem = NULL;
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);
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);
295 int audio_packet_count = 0;
296 static void buffer_need_audio_data_cb(unsigned int size, void *user_data)
298 int real_read_len = 0;
301 guint8 *buff_ptr = NULL;
304 memset(fname, 0, 128);
305 audio_packet_count++;
307 if (audio_packet_count > 1000) {
309 /* player_submit_packet(g_player[0], NULL, 0, 0, 0); */
310 player_push_media_stream(g_player[0], NULL);
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);
317 static guint64 audio_pts = 0;
318 guint64 audio_dur = 21333333;
320 fp = fopen(fname, "rb");
322 buff_ptr = (guint8 *)g_malloc0(1048576);
324 g_print("no free space\n");
329 real_read_len = fread(buff_ptr, 1, size, fp);
333 g_print("\t audio need data - data size : %d, pts : %" G_GUINT64_FORMAT "\n", real_read_len, audio_pts);
336 player_submit_packet(g_player[0], buff_ptr, real_read_len, (audio_pts / 1000000), 0);
338 /* create media packet */
340 media_packet_destroy(g_audio_pkt);
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");
349 g_print("packet = %p, src = %p\n", g_audio_pkt, src);
351 if (media_packet_get_buffer_data_ptr(g_audio_pkt, &src) != MEDIA_PACKET_ERROR_NONE)
354 if (media_packet_set_pts(g_audio_pkt, (uint64_t)audio_pts) != MEDIA_PACKET_ERROR_NONE)
357 if (media_packet_set_buffer_size(g_audio_pkt, (uint64_t)real_read_len) != MEDIA_PACKET_ERROR_NONE)
360 memcpy(src, buff_ptr, real_read_len);
363 player_push_media_stream(g_player[0], g_audio_pkt);
366 audio_pts += audio_dur;
372 static void set_content_info(bool is_push_mode)
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}; */
377 /* create media format */
378 media_format_create(&g_audio_fmt);
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); */
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 */
394 player_set_buffer_need_audio_data_cb(g_player[0], buffer_need_audio_data_cb, (void *)g_player[0]);
398 static void feed_audio_data_thread_func(void *data)
400 while (!g_thread_end)
401 buffer_need_audio_data_cb(1048576, NULL);
404 static void _player_prepare(bool async)
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();
417 player_set_uri(g_player[i], g_uri);
420 if (strstr(g_uri, "es_buff://")) {
421 is_es_push_mode = FALSE;
422 audio_packet_count = 0;
424 if (strstr(g_uri, "es_buff://push_mode")) {
425 set_content_info(TRUE);
427 is_es_push_mode = TRUE;
430 set_content_info(FALSE);
435 for (i = 0; i < g_handle_num; i++) {
437 ret = player_prepare_async(g_player[i], prepared_cb, (void *)g_player[i]);
439 ret = player_prepare(g_player[i]);
442 if (ret != PLAYER_ERROR_NONE)
443 g_print("prepare is failed (errno = %d) \n", ret);
445 player_state_e state;
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);
453 pthread_create(&g_feed_audio_thread_id, NULL, (void *)feed_audio_data_thread_func, NULL);
457 static void _player_unprepare()
461 player_state_e state;
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);
469 ret = player_unset_subtitle_updated_cb(g_player[i]);
470 g_print("player_unset_subtitle_updated_cb [%d] ret %d\n", i, ret);
472 ret = player_unset_buffering_cb(g_player[i]);
473 g_print("player_unset_buffering_cb [%d] ret %d\n", i, ret);
475 ret = player_unset_completed_cb(g_player[i]);
476 g_print("player_unset_completed_cb [%d] ret %d\n", i, ret);
478 ret = player_unset_interrupted_cb(g_player[i]);
479 g_print("player_unset_interrupted_cb [%d] ret %d\n", i, ret);
481 ret = player_unset_error_cb(g_player[i]);
482 g_print("player_unset_error_cb [%d] ret %d\n", i, ret);
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);
492 static void _player_destroy()
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]);
504 if (g_stream_info_h) {
505 sound_manager_destroy_stream_information(g_stream_info_h);
506 g_stream_info_h = NULL;
510 media_packet_destroy(g_audio_pkt);
520 g_mapped_file_unref(g_file);
526 static void _player_play()
530 for (i = 0; i < g_handle_num; i++) {
531 bRet = player_start(g_player[i]);
532 g_print("player_start returned [%d]", bRet);
536 static void _player_stop()
541 for (i = 0; i < g_handle_num; i++) {
542 bRet = player_stop(g_player[i]);
543 g_print("player_stop returned [%d]", bRet);
547 if (g_feed_audio_thread_id) {
548 pthread_join(g_feed_audio_thread_id, NULL);
549 g_feed_audio_thread_id = 0;
554 static void _player_resume()
559 for (i = 0; i < g_handle_num; i++) {
560 bRet = player_start(g_player[i]);
561 g_print("player_start returned [%d]", bRet);
565 static void _player_pause()
569 for (i = 0; i < g_handle_num; i++) {
570 bRet = player_pause(g_player[i]);
571 g_print("player_pause returned [%d]", bRet);
575 static void _player_state()
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);
582 static void set_next_uri(char *uri)
585 g_print("not support at TV profile");
589 if (player_set_next_uri(g_player[0], uri) != PLAYER_ERROR_NONE)
590 g_print("fail to set next uri");
593 static void get_next_uri()
598 g_print("not support at TV profile");
602 if (player_get_next_uri(g_player[0], &uri) != PLAYER_ERROR_NONE) {
603 g_print("fail to get next uri");
608 g_print("next_uri = %s", uri);
613 static void set_volume(float volume)
615 if (player_set_volume(g_player[0], volume, volume) != PLAYER_ERROR_NONE)
616 g_print("failed to set volume\n");
619 static void get_volume(float *left, float *right)
621 player_get_volume(g_player[0], left, right);
622 g_print(" ==> [Player_Audio_Test] volume - left : %f, right : %f\n", *left, *right);
625 static void set_mute(bool mute)
627 if (player_set_mute(g_player[0], mute) != PLAYER_ERROR_NONE)
628 g_print("failed to set_mute\n");
631 static void get_mute(bool *mute)
633 player_is_muted(g_player[0], mute);
634 g_print(" ==> [Player_Audio_Test] mute = %d\n", *mute);
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,
642 const char *extra_info,
645 g_print("FOCUS callback is called, reason(%d), extra_info(%s), userdata(%p)", reason, extra_info, user_data);
649 static void set_sound_stream_info(int type)
651 sound_device_list_h device_list = NULL;
652 int ret = SOUND_MANAGER_ERROR_NONE;
654 if (g_stream_info_h) {
655 g_print("stream information is already set, please destroy handle and try again\n");
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");
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;
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);
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);
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);
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);
688 if (ret != SOUND_MANAGER_ERROR_NONE) {
689 g_print("failed to sound_manager_get_next_device(), ret(0x%x)\n", ret);
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);
697 g_print("set stream information(%p) success", g_stream_info_h);
701 sound_manager_free_device_list(device_list);
705 void variant_cb(int bandwidth, int width, int height, void *user_data)
707 g_print(" ==> [Player_Audio_Test][b]%d, [w]%d, [h]%d\n", bandwidth, width, height);
710 static void get_variant_info()
712 player_foreach_adaptive_variant(g_player[0], (player_adaptive_variant_cb)variant_cb, g_player[0]);
715 static void get_variant_limit()
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);
722 static void set_variant_limit()
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);
728 static void get_position()
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);
736 static void set_position(int position, bool accurate)
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");
742 static void set_playback_rate(float rate, bool 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");
748 if (player_set_playback_rate(g_player[0], rate) != PLAYER_ERROR_NONE)
749 g_print("failed to set playback rate\n");
753 static void get_duration()
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);
762 static void get_stream_info()
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);
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);
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);
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);
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);
806 if (video_codec != NULL) {
807 g_print(" ==> [Player_Audio_Test] Video Codec: [%s ] \n", video_codec);
811 player_get_video_size(g_player[0], &w, &h);
812 g_print(" ==> [Player_Audio_Test] Width: [%d ] , Height: [%d ] \n", w, h);
815 static void set_gapless(bool gapless)
820 g_print("not support at TV profile");
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");
830 static void set_looping(bool looping)
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");
839 static void get_looping(bool *looping)
841 player_is_looping(g_player[0], looping);
842 g_print(" ==> [Player_Audio_Test] looping = %d\n", *looping);
845 static void get_track_info(int index)
847 int count = 0, cur_index = 0;
849 char *lang_code = NULL;
851 if (index != PLAYER_STREAM_TYPE_AUDIO &&
852 index != PLAYER_STREAM_TYPE_TEXT) {
853 g_print("invalid stream type %d", index);
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");
862 player_get_current_track(g_player[0], index, &cur_index);
863 g_print("total track: %d, curr track: %d\n", count, cur_index);
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);
870 g_print("no track\n");
874 static void decoding_audio()
878 char *suffix, *dump_path;
879 GDateTime *time = g_date_time_new_now_local();
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+");
886 g_date_time_unref(time);
888 g_print("Can not create debug dump file");
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);
896 static void set_audio_eq(int value)
898 bool available = FALSE;
899 int index, min = 0, max = 0;
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");
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);
914 if (player_audio_effect_equalizer_clear(g_player[0]) != PLAYER_ERROR_NONE)
915 g_print("failed to player_audio_effect_equalizer_clear\n");
920 static void get_audio_eq()
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);
935 static void set_latency(int value)
937 int ret = PLAYER_ERROR_NONE;
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);
948 if (g_player[0] != NULL || g_player[1] != NULL) {
954 media_format_unref(g_audio_fmt);
959 void play_with_ini(char *file_path)
961 input_filename(file_path);
965 void _interpret_main_menu(char *cmd)
967 int len = strlen(cmd);
969 if (strncmp(cmd, "a", 1) == 0) {
970 g_menu_state = CURRENT_STATUS_FILENAME;
971 } else if (strncmp(cmd, "b", 1) == 0) {
973 } else if (strncmp(cmd, "c", 1) == 0) {
975 } else if (strncmp(cmd, "d", 1) == 0) {
977 } else if (strncmp(cmd, "e", 1) == 0) {
979 } else if (strncmp(cmd, "S", 1) == 0) {
981 } else if (strncmp(cmd, "f", 1) == 0) {
982 g_menu_state = CURRENT_STATUS_VOLUME;
983 } else if (strncmp(cmd, "g", 1) == 0) {
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) {
994 } else if (strncmp(cmd, "j", 1) == 0) {
995 g_menu_state = CURRENT_STATUS_POSITION_TIME;
996 } else if (strncmp(cmd, "l", 1) == 0) {
998 } else if (strncmp(cmd, "m", 1) == 0) {
1000 } else if (strncmp(cmd, "n", 1) == 0) {
1002 } else if (strncmp(cmd, "o", 1) == 0) {
1003 g_menu_state = CURRENT_STATUS_LOOPING;
1004 } else if (strncmp(cmd, "p", 1) == 0) {
1006 get_looping(&looping);
1007 } else if (strncmp(cmd, "D", 1) == 0) {
1009 } else if (strncmp(cmd, "q", 1) == 0) {
1011 } else if (strncmp(cmd, "E", 1) == 0) {
1012 g_menu_state = CURRENT_STATUS_AUDIO_EQUALIZER;
1013 } else if (strncmp(cmd, "H", 1) == 0) {
1016 g_print("unknown menu \n");
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) {
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) {
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) {
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();
1051 g_print("unknown menu \n");
1054 if (strncmp(cmd, "trs", 3) == 0)
1055 g_menu_state = CURRENT_STATUS_STREAMING_PLAYBACK_RATE;
1057 g_print("unknown menu \n");
1061 void display_sub_basic()
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");
1103 g_print("=========================================================================================\n");
1106 static void displaymenu()
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");
1145 g_print("*** unknown status.\n");
1151 gboolean timeout_menu_display(void *data)
1157 gboolean timeout_quit_program(void *data)
1163 void reset_menu_state(void)
1165 g_menu_state = CURRENT_STATUS_MAINMENU;
1168 static void interpret(char *cmd)
1170 switch (g_menu_state) {
1171 case CURRENT_STATUS_MAINMENU:
1173 _interpret_main_menu(cmd);
1176 case CURRENT_STATUS_HANDLE_NUM:
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);
1182 g_handle_num = num_handle;
1187 case CURRENT_STATUS_FILENAME:
1189 input_filename(cmd);
1193 case CURRENT_STATUS_VOLUME:
1195 float level = atof(cmd);
1200 case CURRENT_STATUS_SOUND_STREAM_INFO:
1202 int type = atoi(cmd);
1203 set_sound_stream_info(type);
1207 case CURRENT_STATUS_MUTE:
1209 int mute = atoi(cmd);
1214 case CURRENT_STATUS_POSITION_TIME:
1216 seek_info.pos = atoi(cmd);
1217 g_menu_state = CURRENT_STATUS_POSITION_ACCURATE;
1220 case CURRENT_STATUS_POSITION_ACCURATE:
1222 seek_info.accurate = (atoi(cmd) != 0) ? (true) : (false);
1223 set_position(seek_info.pos, seek_info.accurate);
1227 case CURRENT_STATUS_LOOPING:
1229 int looping = atoi(cmd);
1230 set_looping(looping);
1234 case CURRENT_STATUS_GAPLESS:
1236 int gapless = atoi(cmd);
1237 set_gapless(gapless);
1241 case CURRENT_STATUS_AUDIO_EQUALIZER:
1243 int value = atoi(cmd);
1244 set_audio_eq(value);
1248 case CURRENT_STATUS_PLAYBACK_RATE:
1250 float rate = atof(cmd);
1251 set_playback_rate(rate, FALSE);
1255 case CURRENT_STATUS_STREAMING_PLAYBACK_RATE:
1257 float rate = atof(cmd);
1258 set_playback_rate(rate, TRUE);
1262 case CURRENT_STATUS_LATENCY:
1264 int value = atoi(cmd);
1269 case CURRENT_STATUS_NEXT_URI:
1275 case CURRENT_STATUS_GET_TRACK_INFO:
1277 int index = atoi(cmd);
1278 get_track_info(index);
1282 case CURRENT_STATUS_SET_MAX_BANDWIDTH_VARIANT:
1284 int value = atoi(cmd);
1285 max_limit.bandwidth = value;
1286 g_menu_state = CURRENT_STATUS_SET_MAX_WIDTH_VARIANT;
1289 case CURRENT_STATUS_SET_MAX_WIDTH_VARIANT:
1291 int value = atoi(cmd);
1292 max_limit.width = value;
1293 g_menu_state = CURRENT_STATUS_SET_MAX_HEIGHT_VARIANT;
1296 case CURRENT_STATUS_SET_MAX_HEIGHT_VARIANT:
1298 int value = atoi(cmd);
1299 max_limit.height = value;
1300 set_variant_limit();
1306 g_timeout_add(100, timeout_menu_display, 0);
1309 gboolean input(GIOChannel *channel)
1311 gchar buf[MAX_STRING_LEN];
1314 memset(buf, 0, MAX_STRING_LEN);
1315 cnt = read(0, (void *)buf, MAX_STRING_LEN);
1316 if (cnt == 0) return TRUE;
1324 int main(int argc, char *argv[])
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);
1334 g_main_loop_run(loop);
1336 g_print("exit player_audio_test\n");
1337 g_main_loop_unref(loop);