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.
17 #include <player_internal.h>
18 #include <sound_manager.h>
22 #include <appcore-efl.h>
28 #define PACKAGE "player_audio_test"
33 #define LOG_TAG "PLAYER_AUDIO_TEST"
35 #define MAX_STRING_LEN 2048
36 #define PLAYER_AUDIO_TEST_DUMP_PATH_PREFIX "/home/owner/dump_pcm_"
37 #define DEFAULT_HTTP_TIMEOUT -1
39 #include <system_info.h>
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,
54 } adaptive_variant_info_t;
56 static tizen_profile_t _get_tizen_profile()
59 static tizen_profile_t profile = TIZEN_PROFILE_UNKNOWN;
61 if (__builtin_expect(profile != TIZEN_PROFILE_UNKNOWN, 1))
64 system_info_get_platform_string("http://tizen.org/feature/profile", &profileName);
65 switch (*profileName) {
68 profile = TIZEN_PROFILE_MOBILE;
72 profile = TIZEN_PROFILE_WEARABLE;
76 profile = TIZEN_PROFILE_TV;
80 profile = TIZEN_PROFILE_IVI;
82 default: // common or unknown ==> ALL ARE COMMON.
83 profile = TIZEN_PROFILE_COMMON;
89 #define TIZEN_TV ((_get_tizen_profile()) == TIZEN_PROFILE_TV)
91 static gboolean g_memory_playback = FALSE;
92 static char g_uri[MAX_STRING_LEN];
93 static FILE *g_pcm_fd;
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;
101 static int _save(unsigned char *src, int length);
103 #define DUMP_OUTBUF 1
105 FILE *fp_out1 = NULL;
106 FILE *fp_out2 = NULL;
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,
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,
136 #define MAX_HANDLE 20
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};
146 static int app_create(void *data)
150 static int app_terminate(void *data)
155 struct appcore_ops ops = {
156 .create = app_create,
157 .terminate = app_terminate,
160 static void prepared_cb(void *user_data)
162 g_print("[Player_Audio_Test] prepared_cb!!!!\n");
165 static void _audio_frame_decoded_cb_ex(player_audio_raw_data_s * audio_raw_frame, void *user_data)
167 player_audio_raw_data_s *audio_raw = audio_raw_frame;
172 g_print("[Player_Audio_Test] decoded_cb_ex! channel: %d channel_mask: %llu\n", audio_raw->channel, audio_raw->channel_mask);
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);
182 static void progress_down_cb(player_pd_message_type_e type, void *user_data)
184 g_print("[Player_Audio_Test] progress_down_cb!!!! type : %d\n", type);
187 static void buffering_cb(int percent, void *user_data)
189 g_print("[Player_Audio_Test] buffering_cb!!!! percent : %d\n", percent);
192 static void seek_completed_cb(void *user_data)
194 g_print("[Player_Audio_Test] seek_completed_cb!!! \n");
197 static void completed_cb(void *user_data)
199 g_print("[Player_Audio_Test] completed_cb!!!!\n");
202 static void error_cb(int code, void *user_data)
204 g_print("[Player_Audio_Test] error_cb!!!! code : %d\n", code);
207 static void interrupted_cb(player_interrupted_code_e code, void *user_data)
209 g_print("[Player_Audio_Test] interrupted_cb!!!! code : %d\n", code);
212 static void video_changed_cb(int width, int height, int fps, int bit_rate, void *user_data)
214 g_print("[Player_Audio_Test] video_changed_cb!!!! %d x %d, %d, %d \n", width, height, fps, bit_rate);
218 static void audio_frame_decoded_cb(unsigned char *data, unsigned int size, void *user_data)
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);
229 static int _save(unsigned char *src, int length)
231 /* unlink(CAPTUERD_IMAGE_SAVE_PATH); */
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);
238 fp = fopen(filename, "w+");
240 g_print("file open error!!\n");
243 g_print("open success\n");
244 if (fwrite(src, 1, length, fp) < 1) {
245 g_print("file write error!!\n");
249 g_print("write success(%s)\n", filename);
256 static void input_filename(char *filename)
258 int len = strlen(filename);
261 if (len < 0 || len > MAX_STRING_LEN - 1)
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]);
271 if (player_create(&g_player[i]) != PLAYER_ERROR_NONE)
272 g_print("player create is failed\n");
274 strncpy(g_uri, filename, len+1);
277 /* ned(APPSRC_TEST) */
282 GError *error = NULL;
283 guint8 *g_media_mem = NULL;
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);
291 g_sprintf(uri, "mem://ext=%s,size=%d", ext ? ext : "", file_size);
292 g_print("[uri] = %s\n", uri);
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);
296 /* player_set_uri(g_player[0], filename); */
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);
309 /* use this API instead of player_set_uri */
310 static void player_set_memory_buffer_test()
314 guint8 *g_media_mem = NULL;
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);
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);
325 int audio_packet_count = 0;
326 static void buffer_need_audio_data_cb(unsigned int size, void *user_data)
328 int real_read_len = 0;
331 guint8 *buff_ptr = NULL;
334 memset(fname, 0, 128);
335 audio_packet_count++;
337 if (audio_packet_count > 1000) {
339 /* player_submit_packet(g_player[0], NULL, 0, 0, 0); */
340 player_push_media_stream(g_player[0], NULL);
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);
347 static guint64 audio_pts = 0;
348 guint64 audio_dur = 21333333;
350 fp = fopen(fname, "rb");
352 buff_ptr = (guint8 *) g_malloc0(1048576);
354 g_print("no free space\n");
359 real_read_len = fread(buff_ptr, 1, size, fp);
363 g_print("\t audio need data - data size : %d, pts : %" G_GUINT64_FORMAT "\n", real_read_len, audio_pts);
366 player_submit_packet(g_player[0], buff_ptr, real_read_len, (audio_pts / 1000000), 0);
368 /* create media packet */
370 media_packet_destroy(g_audio_pkt);
373 media_packet_create_alloc(g_audio_fmt, NULL, NULL, &g_audio_pkt);
375 g_print("packet = %p, src = %p\n", g_audio_pkt, src);
377 if (media_packet_get_buffer_data_ptr(g_audio_pkt, &src) != MEDIA_PACKET_ERROR_NONE)
380 if (media_packet_set_pts(g_audio_pkt, (uint64_t) audio_pts) != MEDIA_PACKET_ERROR_NONE)
383 if (media_packet_set_buffer_size(g_audio_pkt, (uint64_t) real_read_len) != MEDIA_PACKET_ERROR_NONE)
386 memcpy(src, buff_ptr, real_read_len);
389 player_push_media_stream(g_player[0], g_audio_pkt);
392 audio_pts += audio_dur;
400 static void set_content_info(bool is_push_mode)
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}; */
405 /* create media format */
406 media_format_create(&g_audio_fmt);
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); */
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 */
422 player_set_buffer_need_audio_data_cb(g_player[0], buffer_need_audio_data_cb, (void *)g_player[0]);
427 static void feed_audio_data_thread_func(void *data)
429 while (!g_thread_end) {
430 buffer_need_audio_data_cb(1048576, NULL);
434 static void _player_prepare(bool async)
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();
447 player_set_uri(g_player[i], g_uri);
450 if (strstr(g_uri, "es_buff://")) {
451 is_es_push_mode = FALSE;
452 audio_packet_count = 0;
454 if (strstr(g_uri, "es_buff://push_mode")) {
455 set_content_info(TRUE);
457 is_es_push_mode = TRUE;
460 set_content_info(FALSE);
465 for (i = 0; i < g_handle_num; i++) {
467 ret = player_prepare_async(g_player[i], prepared_cb, (void *)g_player[i]);
469 ret = player_prepare(g_player[i]);
472 if (ret != PLAYER_ERROR_NONE)
473 g_print("prepare is failed (errno = %d) \n", ret);
475 player_state_e state;
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);
483 pthread_create(&g_feed_audio_thread_id, NULL, (void *)feed_audio_data_thread_func, NULL);
487 static void _player_unprepare()
491 player_state_e state;
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);
499 ret = player_unset_subtitle_updated_cb(g_player[i]);
500 g_print("player_unset_subtitle_updated_cb [%d] ret %d\n", i, ret);
502 ret = player_unset_buffering_cb(g_player[i]);
503 g_print("player_unset_buffering_cb [%d] ret %d\n", i, ret);
505 ret = player_unset_completed_cb(g_player[i]);
506 g_print("player_unset_completed_cb [%d] ret %d\n", i, ret);
508 ret = player_unset_interrupted_cb(g_player[i]);
509 g_print("player_unset_interrupted_cb [%d] ret %d\n", i, ret);
511 ret = player_unset_error_cb(g_player[i]);
512 g_print("player_unset_error_cb [%d] ret %d\n", i, ret);
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);
522 static void _player_destroy()
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]);
534 if (g_stream_info_h) {
535 sound_manager_destroy_stream_information(g_stream_info_h);
536 g_stream_info_h = NULL;
540 media_packet_destroy(g_audio_pkt);
551 static void _player_play()
555 for (i = 0; i < g_handle_num; i++) {
556 bRet = player_start(g_player[i]);
557 g_print("player_start returned [%d]", bRet);
561 static void _player_stop()
566 for (i = 0; i < g_handle_num; i++) {
567 bRet = player_stop(g_player[i]);
568 g_print("player_stop returned [%d]", bRet);
572 if (g_feed_audio_thread_id) {
573 pthread_join(g_feed_audio_thread_id, NULL);
574 g_feed_audio_thread_id = 0;
579 static void _player_resume()
584 for (i = 0; i < g_handle_num; i++) {
585 bRet = player_start(g_player[i]);
586 g_print("player_start returned [%d]", bRet);
590 static void _player_pause()
594 for (i = 0; i < g_handle_num; i++) {
595 bRet = player_pause(g_player[i]);
596 g_print("player_pause returned [%d]", bRet);
600 static void _player_state()
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);
607 static void _player_set_progressive_download()
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]);
613 static void _player_get_progressive_download_status()
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);
621 static void set_next_uri(char * uri)
624 g_print("not support at TV profile");
628 if (player_set_next_uri(g_player[0], uri) != PLAYER_ERROR_NONE)
629 g_print("fail to set next uri");
632 static void get_next_uri()
637 g_print("not support at TV profile");
641 if (player_get_next_uri(g_player[0], &uri) != PLAYER_ERROR_NONE) {
642 g_print("fail to get next uri");
647 g_print("next_uri = %s", uri);
652 static void set_volume(float volume)
654 if (player_set_volume(g_player[0], volume, volume) != PLAYER_ERROR_NONE)
655 g_print("failed to set volume\n");
658 static void get_volume(float *left, float *right)
660 player_get_volume(g_player[0], left, right);
661 g_print(" ==> [Player_Audio_Test] volume - left : %f, right : %f\n", *left, *right);
664 static void set_mute(bool mute)
666 if (player_set_mute(g_player[0], mute) != PLAYER_ERROR_NONE)
667 g_print("failed to set_mute\n");
670 static void get_mute(bool * mute)
672 player_is_muted(g_player[0], mute);
673 g_print(" ==> [Player_Audio_Test] mute = %d\n", *mute);
676 static void set_sound_type(sound_type_e type)
678 if (player_set_sound_type(g_player[0], type) != PLAYER_ERROR_NONE)
679 g_print("failed to set sound type(%d)\n", type);
681 g_print("set sound type(%d) success", type);
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,
689 const char *extra_info,
692 g_print("FOCUS callback is called, reason(%d), extra_info(%s), userdata(%p)", reason, extra_info, user_data);
696 static void set_sound_stream_info(int type)
698 sound_device_list_h device_list = NULL;
699 int ret = SOUND_MANAGER_ERROR_NONE;
701 if (g_stream_info_h) {
702 g_print("stream information is already set, please destory handle and try again\n");
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");
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;
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);
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);
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);
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);
735 if (ret != SOUND_MANAGER_ERROR_NONE) {
736 g_print("failed to sound_manager_get_next_device(), ret(0x%x)\n", ret);
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);
744 g_print("set stream information(%p) success", g_stream_info_h);
748 sound_manager_free_device_list(device_list);
752 void variant_cb(int bandwidth, int width, int height, void *user_data)
754 g_print(" ==> [Player_Audio_Test][b]%d, [w]%d, [h]%d\n", bandwidth, width, height);
757 static void get_variant_info()
759 player_foreach_adaptive_variant(g_player[0], (player_adaptive_variant_cb)variant_cb, g_player[0]);
762 static void get_variant_limit()
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);
769 static void set_variant_limit()
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);
775 static void get_position()
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);
783 static void set_position(int position, bool accurate)
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");
789 static void set_playback_rate(float rate, bool 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");
795 if (player_set_playback_rate(g_player[0], rate) != PLAYER_ERROR_NONE)
796 g_print("failed to set playback rate\n");
800 static void get_duration()
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);
809 static void audio_frame_decoded_cb_ex(bool sync)
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");
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);
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);
828 static void get_stream_info()
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);
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);
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);
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);
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);
872 if (video_codec != NULL) {
873 g_print(" ==> [Player_Audio_Test] Video Codec: [%s ] \n", video_codec);
877 player_get_video_size(g_player[0], &w, &h);
878 g_print(" ==> [Player_Audio_Test] Width: [%d ] , Height: [%d ] \n", w, h);
881 static void set_gapless(bool gapless)
886 g_print("not support at TV profile");
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");
896 static void set_looping(bool looping)
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");
905 static void get_looping(bool * looping)
907 player_is_looping(g_player[0], looping);
908 g_print(" ==> [Player_Audio_Test] looping = %d\n", *looping);
911 static void get_track_info(int index)
913 int count = 0, cur_index = 0;
915 char *lang_code = NULL;
917 if (index != PLAYER_STREAM_TYPE_AUDIO &&
918 index != PLAYER_STREAM_TYPE_TEXT) {
919 g_print("invalid stream type %d", index);
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");
928 player_get_current_track(g_player[0], index, &cur_index);
929 g_print("total track: %d, curr track: %d\n", count, cur_index);
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);
936 g_print("no track\n");
940 static void decoding_audio()
944 char *suffix, *dump_path;
945 GDateTime *time = g_date_time_new_now_local();
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+");
952 g_date_time_unref(time);
954 g_print("Can not create debug dump file");
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);
962 static void set_audio_eq(int value)
964 bool available = FALSE;
965 int index, min = 0, max = 0;
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");
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);
980 if (player_audio_effect_equalizer_clear(g_player[0]) != PLAYER_ERROR_NONE)
981 g_print("failed to player_audio_effect_equalizer_clear\n");
986 static void get_audio_eq()
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);
1007 if (g_player[0] != NULL || g_player[1] != NULL) {
1008 _player_unprepare();
1011 printf("call quit_program, but can not call elm_exit()..please Ctrl+c\n");
1012 #ifdef TIZEN_PLAYER_TEST_ENABLE_VIDEO
1016 media_format_unref(g_audio_fmt);
1019 void play_with_ini(char *file_path)
1021 input_filename(file_path);
1025 void _interpret_main_menu(char *cmd)
1027 int len = strlen(cmd);
1029 if (strncmp(cmd, "a", 1) == 0) {
1030 g_menu_state = CURRENT_STATUS_FILENAME;
1031 } else if (strncmp(cmd, "b", 1) == 0) {
1033 } else if (strncmp(cmd, "c", 1) == 0) {
1035 } else if (strncmp(cmd, "d", 1) == 0) {
1037 } else if (strncmp(cmd, "e", 1) == 0) {
1039 } else if (strncmp(cmd, "S", 1) == 0) {
1041 } else if (strncmp(cmd, "f", 1) == 0) {
1042 g_menu_state = CURRENT_STATUS_VOLUME;
1043 } else if (strncmp(cmd, "g", 1) == 0) {
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) {
1056 } else if (strncmp(cmd, "j", 1) == 0) {
1057 g_menu_state = CURRENT_STATUS_POSITION_TIME;
1058 } else if (strncmp(cmd, "l", 1) == 0) {
1060 } else if (strncmp(cmd, "m", 1) == 0) {
1062 } else if (strncmp(cmd, "n", 1) == 0) {
1064 } else if (strncmp(cmd, "o", 1) == 0) {
1065 g_menu_state = CURRENT_STATUS_LOOPING;
1066 } else if (strncmp(cmd, "p", 1) == 0) {
1068 get_looping(&looping);
1069 } else if (strncmp(cmd, "D", 1) == 0) {
1071 } else if (strncmp(cmd, "q", 1) == 0) {
1072 quit_pushing = TRUE;
1074 } else if (strncmp(cmd, "E", 1) == 0) {
1075 g_menu_state = CURRENT_STATUS_AUDIO_EQUALIZER;
1076 } else if (strncmp(cmd, "H", 1) == 0) {
1079 g_print("unknown menu \n");
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) {
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) {
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) {
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();
1120 g_print("unknown menu \n");
1123 if (strncmp(cmd, "trs", 3) == 0)
1124 g_menu_state = CURRENT_STATUS_STREAMING_PLAYBACK_RATE;
1126 g_print("unknown menu \n");
1130 void display_sub_basic()
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");
1174 g_print("=========================================================================================\n");
1177 static void displaymenu()
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");
1216 g_print("*** unknown status.\n");
1222 gboolean timeout_menu_display(void *data)
1228 gboolean timeout_quit_program(void *data)
1234 void reset_menu_state(void)
1236 g_menu_state = CURRENT_STATUS_MAINMENU;
1239 static void interpret(char *cmd)
1241 switch (g_menu_state) {
1242 case CURRENT_STATUS_MAINMENU:
1244 _interpret_main_menu(cmd);
1247 case CURRENT_STATUS_HANDLE_NUM:
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);
1253 g_handle_num = num_handle;
1258 case CURRENT_STATUS_FILENAME:
1260 input_filename(cmd);
1264 case CURRENT_STATUS_VOLUME:
1266 float level = atof(cmd);
1271 case CURRENT_STATUS_SOUND_TYPE:
1273 int type = atoi(cmd);
1274 set_sound_type(type);
1278 case CURRENT_STATUS_SOUND_STREAM_INFO:
1280 int type = atoi(cmd);
1281 set_sound_stream_info(type);
1285 case CURRENT_STATUS_MUTE:
1287 int mute = atoi(cmd);
1292 case CURRENT_STATUS_POSITION_TIME:
1294 seek_info.pos = atoi(cmd);
1295 g_menu_state = CURRENT_STATUS_POSITION_ACCURATE;
1298 case CURRENT_STATUS_POSITION_ACCURATE:
1300 seek_info.accurate = (atoi(cmd) != 0) ? (true) : (false);
1301 set_position(seek_info.pos, seek_info.accurate);
1305 case CURRENT_STATUS_LOOPING:
1307 int looping = atoi(cmd);
1308 set_looping(looping);
1312 case CURRENT_STATUS_GAPLESS:
1314 int gapless = atoi(cmd);
1315 set_gapless(gapless);
1319 case CURRENT_STATUS_AUDIO_EQUALIZER:
1321 int value = atoi(cmd);
1322 set_audio_eq(value);
1326 case CURRENT_STATUS_PLAYBACK_RATE:
1328 float rate = atof(cmd);
1329 set_playback_rate(rate, FALSE);
1333 case CURRENT_STATUS_STREAMING_PLAYBACK_RATE:
1335 float rate = atof(cmd);
1336 set_playback_rate(rate, TRUE);
1340 case CURRENT_STATUS_NEXT_URI:
1346 case CURRENT_STATUS_GET_TRACK_INFO:
1348 int index = atoi(cmd);
1349 get_track_info(index);
1353 case CURRENT_STATUS_SET_MAX_BANDWIDTH_VARIANT:
1355 int value = atoi(cmd);
1356 max_limit.bandwidth = value;
1357 g_menu_state = CURRENT_STATUS_SET_MAX_WIDTH_VARIANT;
1360 case CURRENT_STATUS_SET_MAX_WIDTH_VARIANT:
1362 int value = atoi(cmd);
1363 max_limit.width = value;
1364 g_menu_state = CURRENT_STATUS_SET_MAX_HEIGHT_VARIANT;
1367 case CURRENT_STATUS_SET_MAX_HEIGHT_VARIANT:
1369 int value = atoi(cmd);
1370 max_limit.height = value;
1371 set_variant_limit();
1377 g_timeout_add(100, timeout_menu_display, 0);
1380 gboolean input(GIOChannel * channel)
1382 gchar buf[MAX_STRING_LEN];
1384 GError *error = NULL;
1386 g_io_channel_read_chars(channel, buf, MAX_STRING_LEN, &read, &error);
1394 int main(int argc, char *argv[])
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);
1402 return appcore_efl_main(PACKAGE, &argc, &argv, &ops);