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>
23 #include <Elementary.h>
25 #include <Ecore_Wayland.h>
33 #define PACKAGE "player_test"
38 #define LOG_TAG "PLAYER_TEST"
40 #define MAX_STRING_LEN 2048
41 #define MMTS_SAMPLELIST_INI_DEFAULT_PATH "/opt/etc/mmts_filelist.ini"
42 #define PLAYER_TEST_DUMP_PATH_PREFIX "/home/owner/content/dump_pcm_"
43 #define INI_SAMPLE_LIST_MAX 9
44 #define DEFAULT_HTTP_TIMEOUT -1
46 static gboolean g_memory_playback = FALSE;
47 static char g_uri[MAX_STRING_LEN];
48 static char g_subtitle_uri[MAX_STRING_LEN];
49 static FILE *g_pcm_fd;
51 static gboolean is_es_push_mode = FALSE;
52 static pthread_t g_feed_video_thread_id = 0;
53 static bool g_thread_end = FALSE;
54 static media_packet_h g_audio_pkt = NULL;
55 static media_format_h g_audio_fmt = NULL;
57 static media_packet_h g_video_pkt = NULL;
58 static media_format_h g_video_fmt = NULL;
60 static int _save(unsigned char *src, int length);
69 CURRENT_STATUS_MAINMENU,
70 CURRENT_STATUS_HANDLE_NUM,
71 CURRENT_STATUS_FILENAME,
72 CURRENT_STATUS_VOLUME,
73 CURRENT_STATUS_SOUND_TYPE,
74 CURRENT_STATUS_SOUND_STREAM_INFO,
76 CURRENT_STATUS_POSITION_TIME,
77 CURRENT_STATUS_LOOPING,
78 CURRENT_STATUS_DISPLAY_SURFACE_CHANGE,
79 CURRENT_STATUS_DISPLAY_MODE,
80 CURRENT_STATUS_DISPLAY_ROTATION,
81 CURRENT_STATUS_DISPLAY_VISIBLE,
82 CURRENT_STATUS_SUBTITLE_FILENAME,
83 CURRENT_STATUS_AUDIO_EQUALIZER,
84 CURRENT_STATUS_PLAYBACK_RATE,
85 CURRENT_STATUS_STREAMING_PLAYBACK_RATE,
86 CURRENT_STATUS_SWITCH_SUBTITLE,
87 CURRENT_STATUS_NEXT_URI,
92 /* for video display */
93 static Evas_Object *g_win_id;
95 static Evas_Object *g_external_win_id;
97 static Evas_Object *selected_win_id;
98 static Evas_Object *g_eo[MAX_HANDLE] = { 0, };
100 static int g_current_surface_type = PLAYER_DISPLAY_TYPE_OVERLAY;
104 Evas_Object *layout_main; /* layout widget based on EDJ */
105 /* add more variables here */
106 #ifdef _ACTIVATE_EOM_
112 static player_h g_player[MAX_HANDLE] = { 0, };
114 int g_handle_num = 1;
115 int g_menu_state = CURRENT_STATUS_MAINMENU;
116 char g_file_list[9][256];
117 gboolean quit_pushing;
118 sound_stream_info_h g_stream_info_h = NULL;
120 static void win_del(void *data, Evas_Object * obj, void *event)
125 static Evas_Object *create_win(const char *name)
127 Evas_Object *eo = NULL;
131 g_print("[%s][%d] name=%s\n", __func__, __LINE__, name);
133 eo = elm_win_add(NULL, name, ELM_WIN_BASIC);
135 elm_win_title_set(eo, name);
136 elm_win_borderless_set(eo, EINA_TRUE);
137 evas_object_smart_callback_add(eo, "delete,request", win_del, NULL);
138 elm_win_screen_size_get(eo, NULL, NULL, &w, &h);
139 g_print("window size :%d,%d", w, h);
140 evas_object_resize(eo, w, h);
141 elm_win_autodel_set(eo, EINA_TRUE);
142 elm_win_alpha_set(eo, EINA_TRUE);
147 static Evas_Object *create_image_object(Evas_Object * eo_parent)
152 Evas *evas = evas_object_evas_get(eo_parent);
153 Evas_Object *eo = NULL;
155 eo = evas_object_image_add(evas);
160 void create_render_rect_and_bg(Evas_Object * win)
166 Evas_Object *bg, *rect;
168 bg = elm_bg_add(win);
169 elm_win_resize_object_add(win, bg);
170 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
171 evas_object_show(bg);
173 rect = evas_object_rectangle_add(evas_object_evas_get(win));
178 evas_object_color_set(rect, 0, 0, 0, 0);
179 evas_object_render_op_set(rect, EVAS_RENDER_COPY);
181 elm_win_resize_object_add(win, rect);
182 evas_object_size_hint_weight_set(rect, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
183 evas_object_show(rect);
184 evas_object_show(win);
187 #ifdef _ACTIVATE_EOM_
188 int eom_get_output_id(const char *output_name)
190 eom_output_id *output_ids = NULL;
191 eom_output_id output_id = 0;
192 eom_output_type_e output_type = EOM_OUTPUT_TYPE_UNKNOWN;
197 output_ids = eom_get_eom_output_ids(&id_cnt);
199 g_print("[eom] no external outuputs supported\n");
203 /* find output ids interested */
204 for (i = 0; i < id_cnt; i++) {
205 eom_get_output_type(output_ids[i], &output_type);
206 if (!strncmp(output_name, "HDMI", 4)) {
207 if (output_type == EOM_OUTPUT_TYPE_HDMIA || output_type == EOM_OUTPUT_TYPE_HDMIB) {
208 output_id = output_ids[i];
211 } else if (!strncmp(output_name, "Virtual", 4)) {
212 if (output_type == EOM_OUTPUT_TYPE_VIRTUAL) {
213 output_id = output_ids[i];
225 static void eom_notify_cb_output_add(eom_output_id output_id, void *user_data)
227 appdata *info = (appdata *) user_data;
229 if (info->hdmi_output_id != output_id) {
230 g_print("[eom] OUTPUT ADDED. SKIP. my output ID is %d\n", info->hdmi_output_id);
233 g_print("[eom] output(%d) connected\n", output_id);
234 /* it is for external window */
235 if (!g_external_win_id) {
236 g_external_win_id = elm_win_add(NULL, "External", ELM_WIN_BASIC);
237 if (eom_set_output_window(info->hdmi_output_id, g_external_win_id) == EOM_ERROR_NONE) {
238 create_render_rect_and_bg(g_external_win_id);
239 g_print("[eom] create external window\n");
241 evas_object_del(g_external_win_id);
242 g_external_win_id = NULL;
243 g_print("[eom] create external window fail\n");
248 static void eom_notify_cb_output_remove(eom_output_id output_id, void *user_data)
250 appdata *info = (appdata *) user_data;
251 player_state_e state;
253 if (info->hdmi_output_id != output_id) {
254 g_print("[eom] OUTPUT REMOVED. SKIP. my output ID is %d\n", info->hdmi_output_id);
257 g_print("[eom] output(%d) disconnected\n", output_id);
259 if (selected_win_id == g_external_win_id && g_player[0]) {
260 player_get_state(g_player[0], &state);
261 if (state >= PLAYER_STATE_READY) {
263 g_win_id = create_win(PACKAGE);
264 if (g_win_id == NULL)
266 g_print("create win_id %p\n", g_win_id);
267 create_render_rect_and_bg(g_win_id);
268 elm_win_activate(g_win_id);
269 evas_object_show(g_win_id);
271 player_set_display(g_player[0], PLAYER_DISPLAY_TYPE_OVERLAY, GET_DISPLAY(g_win_id));
275 /* it is for external window */
276 if (g_external_win_id) {
277 evas_object_del(g_external_win_id);
278 g_external_win_id = NULL;
280 selected_win_id = g_win_id;
283 static void eom_notify_cb_mode_changed(eom_output_id output_id, void *user_data)
285 appdata *info = (appdata *) user_data;
286 eom_output_mode_e mode = EOM_OUTPUT_MODE_NONE;
288 if (info->hdmi_output_id != output_id) {
289 g_print("[eom] MODE CHANGED. SKIP. my output ID is %d\n", info->hdmi_output_id);
293 eom_get_output_mode(output_id, &mode);
294 g_print("[eom] output(%d) mode changed(%d)\n", output_id, mode);
297 static void eom_notify_cb_attribute_changed(eom_output_id output_id, void *user_data)
299 appdata *info = (appdata *) user_data;
301 eom_output_attribute_e attribute = EOM_OUTPUT_ATTRIBUTE_NONE;
302 eom_output_attribute_state_e state = EOM_OUTPUT_ATTRIBUTE_STATE_NONE;
304 if (info->hdmi_output_id != output_id) {
305 g_print("[eom] ATTR CHANGED. SKIP. my output ID is %d\n", info->hdmi_output_id);
309 eom_get_output_attribute(output_id, &attribute);
310 eom_get_output_attribute_state(output_id, &state);
312 g_print("[eom] output(%d) attribute changed(%d, %d)\n", output_id, attribute, state);
313 if (state == EOM_OUTPUT_ATTRIBUTE_STATE_ACTIVE) {
314 g_print("[eom] active\n");
315 if (!g_external_win_id) {
316 g_external_win_id = elm_win_add(NULL, "External", ELM_WIN_BASIC);
317 if (eom_set_output_window(info->hdmi_output_id, g_external_win_id) == EOM_ERROR_NONE) {
318 create_render_rect_and_bg(g_external_win_id);
319 g_print("[eom] create external window\n");
321 evas_object_del(g_external_win_id);
322 g_external_win_id = NULL;
323 g_print("[eom] create external window fail\n");
326 selected_win_id = g_external_win_id;
327 /* play video on external window */
329 player_set_display(g_player[0], PLAYER_DISPLAY_TYPE_OVERLAY, GET_DISPLAY(selected_win_id));
330 } else if (state == EOM_OUTPUT_ATTRIBUTE_STATE_INACTIVE) {
331 g_print("[eom] inactive\n");
333 g_win_id = create_win(PACKAGE);
334 if (g_win_id == NULL)
336 g_print("create win_id %p\n", g_win_id);
337 create_render_rect_and_bg(g_win_id);
338 elm_win_activate(g_win_id);
339 evas_object_show(g_win_id);
341 selected_win_id = g_win_id;
343 player_set_display(g_player[0], PLAYER_DISPLAY_TYPE_OVERLAY, GET_DISPLAY(selected_win_id));
345 if (g_external_win_id) {
346 evas_object_del(g_external_win_id);
347 g_external_win_id = NULL;
349 } else if (state == EOM_OUTPUT_ATTRIBUTE_STATE_LOST) {
350 g_print("[eom] lost\n");
352 g_win_id = create_win(PACKAGE);
353 if (g_win_id == NULL)
355 g_print("create win_id %p\n", g_win_id);
356 create_render_rect_and_bg(g_win_id);
357 elm_win_activate(g_win_id);
358 evas_object_show(g_win_id);
360 selected_win_id = g_win_id;
363 player_set_display(g_player[0], PLAYER_DISPLAY_TYPE_OVERLAY, GET_DISPLAY(selected_win_id));
365 if (g_external_win_id) {
366 evas_object_del(g_external_win_id);
367 g_external_win_id = NULL;
370 eom_unset_output_added_cb(eom_notify_cb_output_add);
371 eom_unset_output_removed_cb(eom_notify_cb_output_remove);
372 eom_unset_mode_changed_cb(eom_notify_cb_mode_changed);
373 eom_unset_attribute_changed_cb(eom_notify_cb_attribute_changed);
379 static int app_create(void *data)
382 Evas_Object *win = NULL;
383 #ifdef _ACTIVATE_EOM_
384 eom_output_mode_e output_mode = EOM_OUTPUT_MODE_NONE;
387 elm_config_accel_preference_set("opengl");
390 win = create_win(PACKAGE);
395 selected_win_id = g_win_id;
396 create_render_rect_and_bg(ad->win);
397 /* Create evas image object for EVAS surface */
398 g_eo[0] = create_image_object(ad->win);
399 evas_object_image_size_set(g_eo[0], 500, 500);
400 evas_object_image_fill_set(g_eo[0], 0, 0, 500, 500);
401 evas_object_resize(g_eo[0], 500, 500);
403 elm_win_activate(win);
404 evas_object_show(win);
405 #ifdef _ACTIVATE_EOM_
406 /* check external device */
408 ad->hdmi_output_id = eom_get_output_id("HDMI");
409 if (ad->hdmi_output_id == 0) {
410 g_print("[eom] error : HDMI output id is NULL.\n");
414 g_print("eom_set_output_attribute EOM_OUTPUT_ATTRIBUTE_NORMAL(id:%d)\n", ad->hdmi_output_id);
415 if (eom_set_output_attribute(ad->hdmi_output_id, EOM_OUTPUT_ATTRIBUTE_NORMAL) != EOM_ERROR_NONE) {
416 g_print("attribute set fail. cannot use external output\n");
420 eom_get_output_mode(ad->hdmi_output_id, &output_mode);
421 if (output_mode != EOM_OUTPUT_MODE_NONE) {
422 g_external_win_id = elm_win_add(NULL, "External", ELM_WIN_BASIC);
423 if (eom_set_output_window(ad->hdmi_output_id, g_external_win_id) == EOM_ERROR_NONE) {
424 create_render_rect_and_bg(g_external_win_id);
425 g_print("[eom] create external window\n");
427 evas_object_del(g_external_win_id);
428 g_external_win_id = NULL;
429 g_print("[eom] create external window fail\n");
431 selected_win_id = g_external_win_id;
434 /* set callback for detecting external device */
435 eom_set_output_added_cb(eom_notify_cb_output_add, ad);
436 eom_set_output_removed_cb(eom_notify_cb_output_remove, ad);
437 eom_set_mode_changed_cb(eom_notify_cb_mode_changed, ad);
438 eom_set_attribute_changed_cb(eom_notify_cb_attribute_changed, ad);
443 static int app_terminate(void *data)
448 for (i = 0; i < MAX_HANDLE; i++) {
450 evas_object_del(g_eo[i]);
455 evas_object_del(g_win_id);
458 #ifdef _ACTIVATE_EOM_
459 if (g_external_win_id) {
460 evas_object_del(g_external_win_id);
461 g_external_win_id = NULL;
465 selected_win_id = NULL;
466 #ifdef _ACTIVATE_EOM_
467 eom_unset_output_added_cb(eom_notify_cb_output_add);
468 eom_unset_output_removed_cb(eom_notify_cb_output_remove);
469 eom_unset_mode_changed_cb(eom_notify_cb_mode_changed);
470 eom_unset_attribute_changed_cb(eom_notify_cb_attribute_changed);
477 struct appcore_ops ops = {
478 .create = app_create,
479 .terminate = app_terminate,
482 static void prepared_cb(void *user_data)
484 g_print("[Player_Test] prepared_cb!!!!\n");
487 static void _audio_frame_decoded_cb_ex(player_audio_raw_data_s * audio_raw_frame, void *user_data)
489 player_audio_raw_data_s *audio_raw = audio_raw_frame;
494 g_print("[Player_Test] decoded_cb_ex! channel: %d channel_mask: %llu\n", audio_raw->channel, audio_raw->channel_mask);
497 if (audio_raw->channel_mask == 1 && fp_out1)
498 fwrite((guint8 *) audio_raw->data, 1, audio_raw->size, fp_out1);
499 else if (audio_raw->channel_mask == 2 && fp_out2)
500 fwrite((guint8 *) audio_raw->data, 1, audio_raw->size, fp_out2);
504 static void progress_down_cb(player_pd_message_type_e type, void *user_data)
506 g_print("[Player_Test] progress_down_cb!!!! type : %d\n", type);
509 static void buffering_cb(int percent, void *user_data)
511 g_print("[Player_Test] buffering_cb!!!! percent : %d\n", percent);
514 static void seek_completed_cb(void *user_data)
516 g_print("[Player_Test] seek_completed_cb!!! \n");
519 static void completed_cb(void *user_data)
521 g_print("[Player_Test] completed_cb!!!!\n");
524 static void error_cb(int code, void *user_data)
526 g_print("[Player_Test] error_cb!!!! code : %d\n", code);
529 static void interrupted_cb(player_interrupted_code_e code, void *user_data)
531 g_print("[Player_Test] interrupted_cb!!!! code : %d\n", code);
535 static void audio_frame_decoded_cb(unsigned char *data, unsigned int size, void *user_data)
539 if (data && g_pcm_fd)
540 fwrite(data, 1, size, g_pcm_fd);
541 player_get_play_position(g_player[0], &pos);
542 g_print("[Player_Test] audio_frame_decoded_cb [size: %d] --- current pos : %d!!!!\n", size, pos);
546 static void subtitle_updated_cb(unsigned long duration, char *text, void *user_data)
548 g_print("[Player_Test] subtitle_updated_cb!!!! [%ld] %s\n", duration, text);
551 static void video_captured_cb(unsigned char *data, int width, int height, unsigned int size, void *user_data)
553 g_print("[Player_Test] video_captured_cb!!!! width: %d, height : %d, size : %d \n", width, height, size);
557 static int _save(unsigned char *src, int length)
559 /* unlink(CAPTUERD_IMAGE_SAVE_PATH); */
561 char filename[256] = { 0, };
562 static int WRITE_COUNT = 0;
563 /* gchar *filename = CAPTUERD_IMAGE_SAVE_PATH; */
564 snprintf(filename, 256, "/tmp/IMAGE_client%d", WRITE_COUNT);
566 fp = fopen(filename, "w+");
568 g_print("file open error!!\n");
571 g_print("open success\n");
572 if (fwrite(src, 1, length, fp) < 1) {
573 g_print("file write error!!\n");
577 g_print("write success(%s)\n", filename);
584 static void reset_display()
588 /* delete evas window, if it is */
589 for (i = 0; i < MAX_HANDLE; i++) {
591 evas_object_del(g_eo[i]);
597 static void input_filename(char *filename)
599 int len = strlen(filename);
602 if (len < 0 || len > MAX_STRING_LEN - 1)
605 for (i = 0; i < g_handle_num; i++) {
606 if (g_player[i] != NULL) {
607 player_unprepare(g_player[i]);
608 player_destroy(g_player[i]);
612 if (player_create(&g_player[i]) != PLAYER_ERROR_NONE)
613 g_print("player create is failed\n");
616 strncpy(g_uri, filename, len);
620 /* ned(APPSRC_TEST) */
625 GError *error = NULL;
626 guint8 *g_media_mem = NULL;
630 file = g_mapped_file_new(ext, FALSE, &error);
631 file_size = g_mapped_file_get_length(file);
632 g_media_mem = (guint8 *) g_mapped_file_get_contents(file);
634 g_sprintf(uri, "mem://ext=%s,size=%d", ext ? ext : "", file_size);
635 g_print("[uri] = %s\n", uri);
637 mm_player_set_attribute(g_player[0], &g_err_name, "profile_uri", uri, strlen(uri), "profile_user_param", g_media_mem, file_size NULL);
639 /* player_set_uri(g_player[0], filename); */
644 player_state_e state;
645 for (i = 0; i < g_handle_num; i++) {
646 ret = player_get_state(g_player[i], &state);
647 g_print("player_get_state returned [%d]\n", ret);
648 g_print("1. After player_create() - Current State : %d \n", state);
652 /* use this API instead of player_set_uri */
653 static void player_set_memory_buffer_test()
657 guint8 *g_media_mem = NULL;
659 file = g_mapped_file_new(g_uri, FALSE, NULL);
660 file_size = g_mapped_file_get_length(file);
661 g_media_mem = (guint8 *) g_mapped_file_get_contents(file);
663 int ret = player_set_memory_buffer(g_player[0], (void *)g_media_mem, file_size);
664 g_print("player_set_memory_buffer ret : %d\n", ret);
667 int video_packet_count = 0;
669 static void buffer_need_video_data_cb(unsigned int size, void *user_data)
671 int real_read_len = 0;
674 static guint64 pts = 0L;
677 guint8 *buff_ptr = NULL;
680 memset(fname, 0, 128);
681 memset(fptsname, 0, 128);
683 video_packet_count++;
685 if (video_packet_count > 1000) {
688 /* player_submit_packet(g_player[0], NULL, 0, 0, 1); */
689 player_push_media_stream(g_player[0], NULL);
693 /* snprintf(fname, 128, "/opt/storage/usb/test/packet/packet_%d.dat", video_packet_count); */
694 /* snprintf(fptsname, 128, "/opt/storage/usb/test/packet/gstpts_%d.dat", video_packet_count); */
695 snprintf(fname, 128, "/home/developer/test/packet/packet_%d.dat", video_packet_count);
696 snprintf(fptsname, 128, "/home/developer/test/packet/gstpts_%d.dat", video_packet_count);
698 fp = fopen(fptsname, "rb");
701 pts_len = fread(&pts, 1, sizeof(guint64), fp);
702 if (pts_len != sizeof(guint64))
703 g_print("Warning, pts value can be wrong.\n");
708 fp = fopen(fname, "rb");
710 buff_ptr = (guint8 *) g_malloc0(1048576);
712 g_print("no free space\n");
717 real_read_len = fread(buff_ptr, 1, size, fp);
721 g_print("video need data - data size : %d, pts : %" G_GUINT64_FORMAT "\n", real_read_len, pts);
723 player_submit_packet(g_player[0], buff_ptr, real_read_len, (pts / 1000000), 1);
725 /* create media packet */
727 media_packet_destroy(g_video_pkt);
731 media_packet_create_alloc(g_video_fmt, NULL, NULL, &g_video_pkt);
733 g_print("packet = %p, src = %p\n", g_video_pkt, src);
735 if (media_packet_get_buffer_data_ptr(g_video_pkt, &src) != MEDIA_PACKET_ERROR_NONE)
738 if (media_packet_set_pts(g_video_pkt, (uint64_t) pts) != MEDIA_PACKET_ERROR_NONE)
741 if (media_packet_set_buffer_size(g_video_pkt, (uint64_t) real_read_len) != MEDIA_PACKET_ERROR_NONE)
744 memcpy(src, buff_ptr, real_read_len);
747 player_push_media_stream(g_player[0], g_video_pkt);
757 int audio_packet_count = 0;
758 static void buffer_need_audio_data_cb(unsigned int size, void *user_data)
760 int real_read_len = 0;
763 guint8 *buff_ptr = NULL;
766 memset(fname, 0, 128);
767 audio_packet_count++;
769 if (audio_packet_count > 1000) {
771 /* player_submit_packet(g_player[0], NULL, 0, 0, 0); */
772 player_push_media_stream(g_player[0], NULL);
776 /* snprintf(fname, 128, "/opt/storage/usb/test/audio_packet/packet_%d.dat", audio_packet_count); */
777 snprintf(fname, 128, "/home/developer/test/audio_packet/packet_%d.dat", audio_packet_count);
779 static guint64 audio_pts = 0;
780 guint64 audio_dur = 21333333;
782 fp = fopen(fname, "rb");
784 buff_ptr = (guint8 *) g_malloc0(1048576);
786 g_print("no free space\n");
791 real_read_len = fread(buff_ptr, 1, size, fp);
795 g_print("\t audio need data - data size : %d, pts : %" G_GUINT64_FORMAT "\n", real_read_len, audio_pts);
798 player_submit_packet(g_player[0], buff_ptr, real_read_len, (audio_pts / 1000000), 0);
800 /* create media packet */
802 media_packet_destroy(g_audio_pkt);
805 media_packet_create_alloc(g_audio_fmt, NULL, NULL, &g_audio_pkt);
807 g_print("packet = %p, src = %p\n", g_audio_pkt, src);
809 if (media_packet_get_buffer_data_ptr(g_audio_pkt, &src) != MEDIA_PACKET_ERROR_NONE)
812 if (media_packet_set_pts(g_audio_pkt, (uint64_t) audio_pts) != MEDIA_PACKET_ERROR_NONE)
815 if (media_packet_set_buffer_size(g_audio_pkt, (uint64_t) real_read_len) != MEDIA_PACKET_ERROR_NONE)
818 memcpy(src, buff_ptr, real_read_len);
821 player_push_media_stream(g_player[0], g_audio_pkt);
824 audio_pts += audio_dur;
832 static void set_content_info(bool is_push_mode)
834 /* testcode for es buff src case, please input url as es_buff://123 or es_buff://push_mode */
835 /* 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}; */
837 /* create media format */
838 media_format_create(&g_audio_fmt);
839 media_format_create(&g_video_fmt);
842 /* configure media format for video and set to player */
843 media_format_set_video_mime(g_video_fmt, MEDIA_FORMAT_MPEG4_SP);
844 media_format_set_video_width(g_video_fmt, 640);
845 media_format_set_video_height(g_video_fmt, 272);
846 /* player_set_media_stream_info(g_player[0], PLAYER_STREAM_TYPE_VIDEO, g_video_fmt); */
848 /* Audio--aac--StarWars.mp4 */
849 media_format_set_audio_mime(g_audio_fmt, MEDIA_FORMAT_AAC);
850 media_format_set_audio_channel(g_audio_fmt, 2);
851 media_format_set_audio_samplerate(g_audio_fmt, 48000);
852 /* player_set_media_stream_info(g_player[0], PLAYER_STREAM_TYPE_AUDIO, g_audio_fmt); */
854 /* video_info->mime = g_strdup("video/mpeg"); *//* CODEC_ID_MPEG4VIDEO */
855 video_info->width = 640;
856 video_info->height = 272;
857 video_info->version = 4;
858 video_info->framerate_den = 100;
859 video_info->framerate_num = 2997;
861 video_info->extradata_size = 45;
862 video_info->codec_extradata = codec_data;
863 player_set_video_stream_info(g_player[0], video_info);
865 /* audio--aac--StarWars.mp4 */
866 /* audio_info->mime = g_strdup("audio/mpeg"); */
867 /* audio_info->version = 2; */
868 /* audio_info->user_info = 0; *//* raw */
873 player_set_buffer_need_video_data_cb(g_player[0], buffer_need_video_data_cb, (void *)g_player[0]);
874 player_set_buffer_need_audio_data_cb(g_player[0], buffer_need_audio_data_cb, (void *)g_player[0]);
879 static void feed_video_data_thread_func(void *data)
881 while (!g_thread_end) {
882 buffer_need_video_data_cb(1048576, NULL);
883 buffer_need_audio_data_cb(1048576, NULL);
887 static void _player_prepare(bool async)
890 int slen = strlen(g_subtitle_uri);
892 if (slen > 0 && slen < MAX_STRING_LEN) {
893 g_print("0. set subtile path() (size : %d) - %s \n", slen, g_subtitle_uri);
894 player_set_subtitle_path(g_player[0], g_subtitle_uri);
895 player_set_subtitle_updated_cb(g_player[0], subtitle_updated_cb, (void *)g_player[0]);
897 if (g_current_surface_type == PLAYER_DISPLAY_TYPE_OVERLAY) {
898 player_set_display(g_player[0], g_current_surface_type, GET_DISPLAY(selected_win_id));
899 player_set_buffering_cb(g_player[0], buffering_cb, (void *)g_player[0]);
900 player_set_completed_cb(g_player[0], completed_cb, (void *)g_player[0]);
901 player_set_interrupted_cb(g_player[0], interrupted_cb, (void *)g_player[0]);
902 player_set_error_cb(g_player[0], error_cb, (void *)g_player[0]);
903 if (g_memory_playback)
904 player_set_memory_buffer_test();
906 player_set_uri(g_player[0], g_uri);
909 for (i = 0; i < g_handle_num; i++) {
910 player_set_display(g_player[i], g_current_surface_type, g_eo[i]);
911 player_set_buffering_cb(g_player[i], buffering_cb, (void *)g_player[i]);
912 player_set_completed_cb(g_player[i], completed_cb, (void *)g_player[i]);
913 player_set_interrupted_cb(g_player[i], interrupted_cb, (void *)g_player[i]);
914 player_set_error_cb(g_player[i], error_cb, (void *)g_player[i]);
915 if (g_memory_playback)
916 player_set_memory_buffer_test();
918 player_set_uri(g_player[i], g_uri);
922 if (strstr(g_uri, "es_buff://")) {
923 is_es_push_mode = FALSE;
924 video_packet_count = 0;
925 audio_packet_count = 0;
927 if (strstr(g_uri, "es_buff://push_mode")) {
928 set_content_info(TRUE);
930 is_es_push_mode = TRUE;
933 set_content_info(FALSE);
938 if (g_current_surface_type == PLAYER_DISPLAY_TYPE_OVERLAY) {
940 ret = player_prepare_async(g_player[0], prepared_cb, (void *)g_player[0]);
942 ret = player_prepare(g_player[0]);
945 for (i = 0; i < g_handle_num; i++) {
947 ret = player_prepare_async(g_player[i], prepared_cb, (void *)g_player[i]);
949 ret = player_prepare(g_player[i]);
953 if (ret != PLAYER_ERROR_NONE)
954 g_print("prepare is failed (errno = %d) \n", ret);
956 player_state_e state;
957 if (g_current_surface_type == PLAYER_DISPLAY_TYPE_OVERLAY) {
958 ret = player_get_state(g_player[0], &state);
959 g_print("After player_prepare() - Current State : %d \n", state);
962 for (i = 0; i < g_handle_num; i++) {
963 ret = player_get_state(g_player[i], &state);
964 g_print("After player_prepare() - Current State : %d \n", state);
969 pthread_create(&g_feed_video_thread_id, NULL, (void *)feed_video_data_thread_func, NULL);
973 static void _player_unprepare()
977 if (g_current_surface_type == PLAYER_DISPLAY_TYPE_OVERLAY) {
978 ret = player_unprepare(g_player[0]);
979 if (ret != PLAYER_ERROR_NONE)
980 g_print("unprepare is failed (errno = %d) \n", ret);
982 ret = player_unset_subtitle_updated_cb(g_player[0]);
983 g_print("player_unset_subtitle_updated_cb ret %d\n", ret);
985 ret = player_unset_buffering_cb(g_player[0]);
986 g_print("player_unset_buffering_cb ret %d\n", ret);
988 ret = player_unset_completed_cb(g_player[0]);
989 g_print("player_unset_completed_cb ret %d\n", ret);
991 ret = player_unset_interrupted_cb(g_player[0]);
992 g_print("player_unset_interrupted_cb ret %d\n", ret);
994 ret = player_unset_error_cb(g_player[0]);
995 g_print("player_unset_error_cb ret %d\n", ret);
997 for (i = 0; i < g_handle_num; i++) {
998 if (g_player[i] != NULL) {
999 ret = player_unprepare(g_player[i]);
1000 if (ret != PLAYER_ERROR_NONE)
1001 g_print("unprepare is failed (errno = %d) \n", ret);
1003 ret = player_unset_subtitle_updated_cb(g_player[i]);
1004 g_print("player_unset_subtitle_updated_cb [%d] ret %d\n", i, ret);
1006 ret = player_unset_buffering_cb(g_player[i]);
1007 g_print("player_unset_buffering_cb [%d] ret %d\n", i, ret);
1009 ret = player_unset_completed_cb(g_player[i]);
1010 g_print("player_unset_completed_cb [%d] ret %d\n", i, ret);
1012 ret = player_unset_interrupted_cb(g_player[i]);
1013 g_print("player_unset_interrupted_cb [%d] ret %d\n", i, ret);
1015 ret = player_unset_error_cb(g_player[i]);
1016 g_print("player_unset_error_cb [%d] ret %d\n", i, ret);
1020 /* attention! surface(evas) -> unprepare -> surface(evas) : evas object will disappear. */
1022 memset(g_subtitle_uri, 0, sizeof(g_subtitle_uri));
1023 player_state_e state;
1024 if (g_current_surface_type == PLAYER_DISPLAY_TYPE_OVERLAY) {
1025 ret = player_get_state(g_player[0], &state);
1026 g_print(" After player_unprepare() - Current State : %d \n", state);
1028 for (i = 0; i < g_handle_num; i++) {
1029 ret = player_get_state(g_player[i], &state);
1030 g_print(" After player_unprepare() - Current State : %d \n", state);
1035 static void _player_destroy()
1039 if (g_current_surface_type == PLAYER_DISPLAY_TYPE_OVERLAY) {
1040 player_unprepare(g_player[0]);
1041 for (i = 0; i < g_handle_num; i++) {
1042 player_destroy(g_player[i]);
1046 for (i = 0; i < g_handle_num; i++) {
1047 if (g_player[i] != NULL) {
1048 player_unprepare(g_player[i]);
1049 player_destroy(g_player[i]);
1055 if (g_stream_info_h) {
1056 sound_manager_destroy_stream_information(g_stream_info_h);
1057 g_stream_info_h = NULL;
1061 media_packet_destroy(g_video_pkt);
1064 media_packet_destroy(g_audio_pkt);
1075 static void _player_play()
1079 if (g_current_surface_type == PLAYER_DISPLAY_TYPE_OVERLAY) {
1080 #ifdef _ACTIVATE_EOM_
1081 /* for checking external display.... */
1082 player_set_display(g_player[0], g_current_surface_type, GET_DISPLAY(selected_win_id));
1084 bRet = player_start(g_player[0]);
1085 g_print("player_start returned [%d]", bRet);
1087 for (i = 0; i < g_handle_num; i++) {
1088 bRet = player_start(g_player[i]);
1089 g_print("player_start returned [%d]", bRet);
1094 static void _player_stop()
1098 if (g_current_surface_type == PLAYER_DISPLAY_TYPE_OVERLAY) {
1099 bRet = player_stop(g_player[0]);
1100 g_print("player_stop returned [%d]", bRet);
1102 for (i = 0; i < g_handle_num; i++) {
1103 bRet = player_stop(g_player[i]);
1104 g_print("player_stop returned [%d]", bRet);
1108 g_thread_end = TRUE;
1109 if (g_feed_video_thread_id) {
1110 pthread_join(g_feed_video_thread_id, NULL);
1111 g_feed_video_thread_id = 0;
1116 static void _player_resume()
1120 if (g_current_surface_type == PLAYER_DISPLAY_TYPE_OVERLAY) {
1121 #ifdef _ACTIVATE_EOM_
1122 /* for checking external display.... */
1123 player_set_display(g_player[0], PLAYER_DISPLAY_TYPE_OVERLAY, GET_DISPLAY(selected_win_id));
1125 bRet = player_start(g_player[0]);
1126 g_print("player_start returned [%d]", bRet);
1128 for (i = 0; i < g_handle_num; i++) {
1129 bRet = player_start(g_player[i]);
1130 g_print("player_start returned [%d]", bRet);
1135 static void _player_pause()
1139 if (g_current_surface_type == PLAYER_DISPLAY_TYPE_OVERLAY) {
1140 bRet = player_pause(g_player[0]);
1141 g_print("player_pause returned [%d]", bRet);
1143 for (i = 0; i < g_handle_num; i++) {
1144 bRet = player_pause(g_player[i]);
1145 g_print("player_pause returned [%d]", bRet);
1150 static void _player_state()
1152 player_state_e state;
1153 player_get_state(g_player[0], &state);
1154 g_print(" ==> [Player_Test] Current Player State : %d\n", state);
1157 static void _player_set_progressive_download()
1159 player_set_progressive_download_path(g_player[0], "/home/owner/test.pd");
1160 player_set_progressive_download_message_cb(g_player[0], progress_down_cb, (void *)g_player[0]);
1163 static void _player_get_progressive_download_status()
1166 unsigned long curr, total;
1167 bRet = player_get_progressive_download_status(g_player[0], &curr, &total);
1168 g_print("player_get_progressive_download_status return[%d] ==> [Player_Test] progressive download status : %lu/%lu\n", bRet, curr, total);
1171 static void set_next_uri(char * uri)
1174 player_set_gapless(g_player[0], TRUE);
1175 if (player_set_next_uri(g_player[0], uri) != PLAYER_ERROR_NONE)
1176 g_print("fail to set next uri");
1178 g_print("not support at TV profile");
1182 static void get_next_uri()
1186 if (player_get_next_uri(g_player[0], &uri) != PLAYER_ERROR_NONE) {
1187 g_print("fail to get next uri");
1192 g_print("next_uri = %s", uri);
1196 g_print("not support at TV profile");
1200 static void set_volume(float volume)
1202 if (player_set_volume(g_player[0], volume, volume) != PLAYER_ERROR_NONE)
1203 g_print("failed to set volume\n");
1206 static void get_volume(float *left, float *right)
1208 player_get_volume(g_player[0], left, right);
1209 g_print(" ==> [Player_Test] volume - left : %f, right : %f\n", *left, *right);
1212 static void set_mute(bool mute)
1214 if (player_set_mute(g_player[0], mute) != PLAYER_ERROR_NONE)
1215 g_print("failed to set_mute\n");
1218 static void get_mute(bool * mute)
1220 player_is_muted(g_player[0], mute);
1221 g_print(" ==> [Player_Test] mute = %d\n", *mute);
1224 static void set_sound_type(sound_type_e type)
1226 if (player_set_sound_type(g_player[0], type) != PLAYER_ERROR_NONE)
1227 g_print("failed to set sound type(%d)\n", type);
1229 g_print("set sound type(%d) success", type);
1232 void focus_callback(sound_stream_info_h stream_info, sound_stream_focus_change_reason_e reason, const char *extra_info, void *user_data)
1234 g_print("FOCUS callback is called, reason(%d), extra_info(%s), userdata(%p)", reason, extra_info, user_data);
1238 static void set_sound_stream_info(int type)
1240 sound_device_list_h device_list = NULL;
1241 int ret = SOUND_MANAGER_ERROR_NONE;
1243 if (g_stream_info_h) {
1244 g_print("stream information is already set, please destory handle and try again\n");
1247 if (sound_manager_create_stream_information(type, focus_callback, g_player[0], &g_stream_info_h)) {
1248 g_print("failed to create stream_information()\n");
1251 /* In case of MEDIA_EXTERNAL_ONLY, we need to set external device manually */
1252 if (type == (int)SOUND_STREAM_TYPE_MEDIA_EXTERNAL_ONLY) {
1253 sound_device_h device = NULL;
1254 sound_device_type_e device_type;
1256 if ((ret = sound_manager_get_current_device_list(SOUND_DEVICE_ALL_MASK, &device_list))) {
1257 g_print("failed to sound_manager_get_current_device_list(), ret(0x%x)\n", ret);
1260 while (!(ret = sound_manager_get_next_device(device_list, &device))) {
1261 if ((ret = sound_manager_get_device_type(device, &device_type))) {
1262 g_print("failed to sound_manager_get_device_type(), ret(0x%x)\n", ret);
1265 if (device_type == SOUND_DEVICE_BLUETOOTH || device_type == SOUND_DEVICE_USB_AUDIO) {
1266 if ((ret = sound_manager_add_device_for_stream_routing(g_stream_info_h, device))) {
1267 g_print("failed to sound_manager_add_device_for_stream_routing(), ret(0x%x)\n", ret);
1270 if ((ret = sound_manager_apply_stream_routing(g_stream_info_h))) {
1271 g_print("failed to sound_manager_apply_stream_routing(), ret(0x%x)\n", ret);
1277 if (ret != SOUND_MANAGER_ERROR_NONE) {
1278 g_print("failed to sound_manager_get_next_device(), ret(0x%x)\n", ret);
1283 if (player_set_audio_policy_info(g_player[0], g_stream_info_h) != PLAYER_ERROR_NONE)
1284 g_print("failed to set sound stream information(%p)\n", g_stream_info_h);
1286 g_print("set stream information(%p) success", g_stream_info_h);
1290 sound_manager_free_device_list(device_list);
1294 static void get_position()
1298 ret = player_get_play_position(g_player[0], &position);
1299 g_print(" ==> [Player_Test] player_get_play_position()%d return : %d\n", ret, position);
1302 static void set_position(int position)
1304 if (player_set_play_position(g_player[0], position, TRUE, seek_completed_cb, g_player[0]) != PLAYER_ERROR_NONE)
1305 g_print("failed to set position\n");
1308 static void set_playback_rate(float rate, bool streaming)
1311 if (player_set_streaming_playback_rate(g_player[0], rate) != PLAYER_ERROR_NONE)
1312 g_print("failed to set streaming playback rate\n");
1314 if (player_set_playback_rate(g_player[0], rate) != PLAYER_ERROR_NONE)
1315 g_print("failed to set playback rate\n");
1319 static void get_duration()
1323 ret = player_get_duration(g_player[0], &duration);
1324 g_print(" ==> [Player_Test] player_get_duration() return : %d\n", ret);
1325 g_print(" ==> [Player_Test] Duration: [%d ] msec\n", duration);
1328 static void audio_frame_decoded_cb_ex(bool sync)
1332 fp_out1 = fopen("/tmp/out1.pcm", "wb");
1333 fp_out2 = fopen("/tmp/out2.pcm", "wb");
1334 if (!fp_out1 || !fp_out2) {
1335 g_print("File open error\n");
1340 ret = player_set_pcm_extraction_mode(g_player[0], sync, _audio_frame_decoded_cb_ex, &ret);
1341 g_print(" ==> [Player_Test] player_set_audio_frame_decoded_cb_ex(sync:%d) ret:%d\n", sync, ret);
1343 ret = player_set_pcm_spec(g_player[0], "F32LE", 44100, 2);
1344 g_print("[Player_Test] set_pcm_spec return: %d\n", ret);
1347 static void get_stream_info()
1353 player_get_content_info(g_player[0], PLAYER_CONTENT_INFO_ALBUM, &value);
1354 g_print(" ==> [Player_Test] PLAYER_CONTENT_INFO_ALBUM: [%s ] \n", value);
1355 player_get_content_info(g_player[0], PLAYER_CONTENT_INFO_ARTIST, &value);
1356 g_print(" ==> [Player_Test] PLAYER_CONTENT_INFO_ARTIST: [%s ] \n", value);
1357 player_get_content_info(g_player[0], PLAYER_CONTENT_INFO_AUTHOR, &value);
1358 g_print(" ==> [Player_Test] PLAYER_CONTENT_INFO_AUTHOR: [%s ] \n", value);
1359 player_get_content_info(g_player[0], PLAYER_CONTENT_INFO_GENRE, &value);
1360 g_print(" ==> [Player_Test] PLAYER_CONTENT_INFO_GENRE: [%s ] \n", value);
1361 player_get_content_info(g_player[0], PLAYER_CONTENT_INFO_TITLE, &value);
1362 g_print(" ==> [Player_Test] PLAYER_CONTENT_INFO_TITLE: [%s ] \n", value);
1365 player_get_album_art(g_player[0], &album, &size);
1366 g_print(" ==> [Player_Test] Album art : [ data : %p, size : %d ]\n", (unsigned int *)album, size);
1368 if (value != NULL) {
1376 int fps, v_bit_rate;
1377 player_get_audio_stream_info(g_player[0], &sample_rate, &channel, &bit_rate);
1378 g_print(" ==> [Player_Test] Sample Rate: [%d ] , Channel: [%d ] , Bit Rate: [%d ] \n", sample_rate, channel, bit_rate);
1380 player_get_video_stream_info(g_player[0], &fps, &v_bit_rate);
1381 g_print(" ==> [Player_Test] fps: [%d ] , Bit Rate: [%d ] \n", fps, v_bit_rate);
1383 char *audio_codec = NULL;
1384 char *video_codec = NULL;
1385 player_get_codec_info(g_player[0], &audio_codec, &video_codec);
1386 if (audio_codec != NULL) {
1387 g_print(" ==> [Player_Test] Audio Codec: [%s ] \n", audio_codec);
1391 if (video_codec != NULL) {
1392 g_print(" ==> [Player_Test] Video Codec: [%s ] \n", video_codec);
1396 player_get_video_size(g_player[0], &w, &h);
1397 g_print(" ==> [Player_Test] Width: [%d ] , Height: [%d ] \n", w, h);
1400 static void set_looping(bool looping)
1402 if (g_current_surface_type == PLAYER_DISPLAY_TYPE_OVERLAY) {
1403 if (player_set_looping(g_player[0], looping) != PLAYER_ERROR_NONE)
1404 g_print("failed to set_looping\n");
1407 for (i = 0; i < g_handle_num; i++) {
1408 if (player_set_looping(g_player[i], looping) != PLAYER_ERROR_NONE)
1409 g_print("failed to set_looping\n");
1414 static void get_looping(bool * looping)
1416 player_is_looping(g_player[0], looping);
1417 g_print(" ==> [Player_Test] looping = %d\n", *looping);
1420 static void change_surface(int option)
1422 player_display_type_e surface_type = 0;
1423 int ret = PLAYER_ERROR_NONE;
1424 #ifdef _ACTIVATE_EOM_
1426 eom_output_mode_e output_mode;
1431 surface_type = PLAYER_DISPLAY_TYPE_OVERLAY;
1432 g_print("change surface type to X\n");
1434 #ifdef EVAS_RENDERER_SUPPORT
1437 surface_type = PLAYER_DISPLAY_TYPE_EVAS;
1438 g_print("change surface type to EVAS\n");
1442 g_print("change surface type to NONE\n");
1443 surface_type = g_current_surface_type = PLAYER_DISPLAY_TYPE_NONE;
1444 player_set_display(g_player[0], PLAYER_DISPLAY_TYPE_NONE, NULL);
1447 g_print("invalid surface type\n");
1451 if (surface_type == g_current_surface_type) {
1452 g_print("same with the previous surface type(%d)\n", g_current_surface_type);
1455 player_state_e player_state = PLAYER_STATE_NONE;
1456 ret = player_get_state(g_player[0], &player_state);
1458 g_print("failed to player_get_state(), ret(0x%x)\n", ret);
1462 if (surface_type == PLAYER_DISPLAY_TYPE_OVERLAY) {
1463 #ifdef _ACTIVATE_EOM_
1464 hdmi_output_id = eom_get_output_id("HDMI");
1465 if (hdmi_output_id == 0)
1466 g_print("[eom] error : HDMI output id is NULL.\n");
1468 eom_get_output_mode(hdmi_output_id, &output_mode);
1469 if (output_mode == EOM_OUTPUT_MODE_NONE) {
1472 g_win_id = create_win(PACKAGE);
1473 if (g_win_id == NULL)
1475 g_print("create win_id %p\n", g_win_id);
1476 create_render_rect_and_bg(g_win_id);
1477 elm_win_activate(g_win_id);
1478 evas_object_show(g_win_id);
1479 g_win_id = selected_win_id;
1481 #ifdef _ACTIVATE_EOM_
1486 ret = player_set_display(g_player[0], surface_type, GET_DISPLAY(selected_win_id));
1489 g_win_id = create_win(PACKAGE);
1490 if (g_win_id == NULL)
1492 g_print("create win_id %p\n", g_win_id);
1493 create_render_rect_and_bg(g_win_id);
1494 elm_win_activate(g_win_id);
1495 evas_object_show(g_win_id);
1498 for (i = 0; i < g_handle_num; i++) {
1499 /* Create evas image object for EVAS surface */
1501 g_eo[i] = create_image_object(g_win_id);
1502 g_print("create eo[%d] %p\n", i, g_eo[i]);
1503 evas_object_image_size_set(g_eo[i], 500, 500);
1504 evas_object_image_fill_set(g_eo[i], 0, 0, 500, 500);
1505 evas_object_resize(g_eo[i], 500, 500);
1506 evas_object_move(g_eo[i], i * 20, i * 20);
1508 ret = player_set_display(g_player[i], surface_type, g_eo[i]);
1513 g_print("failed to set display, surface_type(%d)\n", surface_type);
1516 g_current_surface_type = surface_type;
1521 static void set_display_mode(int mode)
1523 if (player_set_display_mode(g_player[0], mode) != PLAYER_ERROR_NONE)
1524 g_print("failed to player_set_display_mode\n");
1527 static void get_display_mode()
1529 player_display_mode_e mode;
1530 player_get_display_mode(g_player[0], &mode);
1531 g_print(" ==> [Player_Test] Display mode: [%d ] \n", mode);
1534 static void set_display_rotation(int rotation)
1536 if (player_set_display_rotation(g_player[0], rotation) != PLAYER_ERROR_NONE)
1537 g_print("failed to set_display_rotation\n");
1540 static void get_display_rotation()
1542 player_display_rotation_e rotation = 0;
1543 player_get_display_rotation(g_player[0], &rotation);
1544 g_print(" ==> [Player_Test] Video Overlay Display rotation: [%d ] \n", rotation);
1547 static void set_display_visible(bool visible)
1549 if (player_set_display_visible(g_player[0], visible) != PLAYER_ERROR_NONE)
1550 g_print("failed to player_set_x11_display_visible\n");
1553 static void get_display_visible(bool * visible)
1555 player_is_display_visible(g_player[0], visible);
1556 g_print(" ==> [Player_Test] Video Overlay Display Visible = %d\n", *visible);
1559 static void input_subtitle_filename(char *subtitle_filename)
1561 int len = strlen(subtitle_filename);
1563 if (len < 1 || len > MAX_STRING_LEN)
1566 strncpy(g_subtitle_uri, subtitle_filename, len);
1567 g_print("subtitle uri is set to %s\n", g_subtitle_uri);
1568 player_set_subtitle_path(g_player[0], g_subtitle_uri);
1571 static void switch_subtitle(int index)
1573 char *lang_code = NULL;
1574 if (player_select_track(g_player[0], PLAYER_STREAM_TYPE_TEXT, index) != PLAYER_ERROR_NONE)
1575 g_print("player_select_track failed\n");
1577 if (player_get_track_language_code(g_player[0], PLAYER_STREAM_TYPE_TEXT, index, &lang_code) == PLAYER_ERROR_NONE) {
1578 g_print("selected track code %s\n", lang_code);
1583 static void capture_video()
1585 if (player_capture_video(g_player[0], video_captured_cb, NULL) != PLAYER_ERROR_NONE)
1586 g_print("failed to player_capture_video\n");
1589 static void decoding_audio()
1593 char *suffix, *dump_path;
1594 GDateTime *time = g_date_time_new_now_local();
1596 suffix = g_date_time_format(time, "%Y%m%d_%H%M%S.pcm");
1597 dump_path = g_strjoin(NULL, PLAYER_TEST_DUMP_PATH_PREFIX, suffix, NULL);
1598 g_pcm_fd = fopen(dump_path, "w+");
1601 g_date_time_unref(time);
1603 g_print("Can not create debug dump file");
1605 ret = player_set_audio_frame_decoded_cb(g_player[0], 0, 0, audio_frame_decoded_cb, (void *)g_player[0]);
1606 if (ret != PLAYER_ERROR_NONE)
1607 g_print("player_set_audio_frame_decoded_cb is failed (errno = %d) \n", ret);
1611 static void set_audio_eq(int value)
1613 bool available = FALSE;
1614 int index, min, max;
1617 if (player_audio_effect_equalizer_is_available(g_player[0], &available) != PLAYER_ERROR_NONE)
1618 g_print("failed to player_audio_effect_equalizer_is_available\n");
1621 if ((player_audio_effect_get_equalizer_bands_count(g_player[0], &index) != PLAYER_ERROR_NONE) ||
1622 (player_audio_effect_get_equalizer_level_range(g_player[0], &min, &max) != PLAYER_ERROR_NONE) ||
1623 (player_audio_effect_set_equalizer_band_level(g_player[0], index / 2, max) != PLAYER_ERROR_NONE))
1624 g_print("failed to player_audio_effect_set_equalizer_band_level index %d, level %d\n", index / 2, max);
1629 if (player_audio_effect_equalizer_clear(g_player[0]) != PLAYER_ERROR_NONE)
1630 g_print("failed to player_audio_effect_equalizer_clear\n");
1635 static void get_audio_eq()
1637 int index, min, max, value;
1638 player_audio_effect_get_equalizer_bands_count(g_player[0], &index);
1639 g_print(" ==> [Player_Test] eq bands count: [%d] \n", index);
1640 player_audio_effect_get_equalizer_level_range(g_player[0], &min, &max);
1641 g_print(" ==> [Player_Test] eq bands range: [%d~%d] \n", min, max);
1642 player_audio_effect_get_equalizer_band_level(g_player[0], index / 2, &value);
1643 g_print(" ==> [Player_Test] eq bands level: [%d] \n", value);
1644 player_audio_effect_get_equalizer_band_frequency(g_player[0], 0, &value);
1645 g_print(" ==> [Player_Test] eq bands frequency: [%d] \n", value);
1646 player_audio_effect_get_equalizer_band_frequency_range(g_player[0], 0, &value);
1647 g_print(" ==> [Player_Test] eq bands frequency range: [%d] \n", value);
1657 for (i = 0; i < g_handle_num; i++) {
1658 if (g_player[i] != NULL) {
1659 player_unprepare(g_player[i]);
1660 player_destroy(g_player[i]);
1667 media_format_unref(g_audio_fmt);
1670 media_format_unref(g_video_fmt);
1673 void play_with_ini(char *file_path)
1675 input_filename(file_path);
1679 void _interpret_main_menu(char *cmd)
1681 int len = strlen(cmd);
1683 if (strncmp(cmd, "a", 1) == 0) {
1684 g_menu_state = CURRENT_STATUS_FILENAME;
1685 } else if (strncmp(cmd, "1", 1) == 0) {
1686 play_with_ini(g_file_list[0]);
1687 } else if (strncmp(cmd, "2", 1) == 0) {
1688 play_with_ini(g_file_list[1]);
1689 } else if (strncmp(cmd, "3", 1) == 0) {
1690 play_with_ini(g_file_list[2]);
1691 } else if (strncmp(cmd, "4", 1) == 0) {
1692 play_with_ini(g_file_list[3]);
1693 } else if (strncmp(cmd, "5", 1) == 0) {
1694 play_with_ini(g_file_list[4]);
1695 } else if (strncmp(cmd, "6", 1) == 0) {
1696 play_with_ini(g_file_list[5]);
1697 } else if (strncmp(cmd, "7", 1) == 0) {
1698 play_with_ini(g_file_list[6]);
1699 } else if (strncmp(cmd, "8", 1) == 0) {
1700 play_with_ini(g_file_list[7]);
1701 } else if (strncmp(cmd, "9", 1) == 0) {
1702 play_with_ini(g_file_list[8]);
1703 } else if (strncmp(cmd, "b", 1) == 0) {
1705 } else if (strncmp(cmd, "c", 1) == 0) {
1707 } else if (strncmp(cmd, "d", 1) == 0) {
1709 } else if (strncmp(cmd, "e", 1) == 0) {
1711 } else if (strncmp(cmd, "S", 1) == 0) {
1713 } else if (strncmp(cmd, "f", 1) == 0) {
1714 g_menu_state = CURRENT_STATUS_VOLUME;
1715 } else if (strncmp(cmd, "g", 1) == 0) {
1718 get_volume(&left, &right);
1719 } else if (strncmp(cmd, "z", 1) == 0) {
1720 g_menu_state = CURRENT_STATUS_SOUND_TYPE;
1721 } else if (strncmp(cmd, "k", 1) == 0) {
1722 g_menu_state = CURRENT_STATUS_SOUND_STREAM_INFO;
1723 } else if (strncmp(cmd, "h", 1) == 0) {
1724 g_menu_state = CURRENT_STATUS_MUTE;
1725 } else if (strncmp(cmd, "i", 1) == 0) {
1728 } else if (strncmp(cmd, "j", 1) == 0) {
1729 g_menu_state = CURRENT_STATUS_POSITION_TIME;
1730 } else if (strncmp(cmd, "l", 1) == 0) {
1732 } else if (strncmp(cmd, "m", 1) == 0) {
1734 } else if (strncmp(cmd, "n", 1) == 0) {
1736 } else if (strncmp(cmd, "o", 1) == 0) {
1737 g_menu_state = CURRENT_STATUS_LOOPING;
1738 } else if (strncmp(cmd, "p", 1) == 0) {
1740 get_looping(&looping);
1741 } else if (strncmp(cmd, "r", 1) == 0) {
1742 g_menu_state = CURRENT_STATUS_DISPLAY_MODE;
1743 } else if (strncmp(cmd, "s", 1) == 0) {
1745 } else if (strncmp(cmd, "t", 1) == 0) {
1746 g_menu_state = CURRENT_STATUS_DISPLAY_ROTATION;
1747 } else if (strncmp(cmd, "u", 1) == 0) {
1748 get_display_rotation();
1749 } else if (strncmp(cmd, "v", 1) == 0) {
1750 g_menu_state = CURRENT_STATUS_DISPLAY_VISIBLE;
1751 } else if (strncmp(cmd, "w", 1) == 0) {
1753 get_display_visible(&visible);
1754 } else if (strncmp(cmd, "A", 1) == 0) {
1755 g_menu_state = CURRENT_STATUS_SUBTITLE_FILENAME;
1756 } else if (strncmp(cmd, "C", 1) == 0) {
1758 } else if (strncmp(cmd, "D", 1) == 0) {
1760 } else if (strncmp(cmd, "q", 1) == 0) {
1761 quit_pushing = TRUE;
1763 } else if (strncmp(cmd, "E", 1) == 0) {
1764 g_menu_state = CURRENT_STATUS_AUDIO_EQUALIZER;
1765 } else if (strncmp(cmd, "H", 1) == 0) {
1768 g_print("unknown menu \n");
1770 } else if (len == 2) {
1771 if (strncmp(cmd, "pr", 2) == 0) {
1773 _player_prepare(FALSE);
1774 } else if (strncmp(cmd, "pa", 2) == 0) {
1776 _player_prepare(TRUE);
1777 } else if (strncmp(cmd, "un", 2) == 0) {
1778 _player_unprepare();
1779 } else if (strncmp(cmd, "dt", 2) == 0) {
1781 } else if (strncmp(cmd, "sp", 2) == 0) {
1782 _player_set_progressive_download();
1783 } else if (strncmp(cmd, "gp", 2) == 0) {
1784 _player_get_progressive_download_status();
1785 } else if (strncmp(cmd, "mp", 2) == 0) {
1786 g_memory_playback = (g_memory_playback ? FALSE : TRUE);
1787 g_print("memory playback = %d\n", g_memory_playback);
1788 } else if (strncmp(cmd, "ds", 2) == 0) {
1789 g_menu_state = CURRENT_STATUS_DISPLAY_SURFACE_CHANGE;
1790 } else if (strncmp(cmd, "nb", 2) == 0) {
1791 g_menu_state = CURRENT_STATUS_HANDLE_NUM;
1792 } else if (strncmp(cmd, "tr", 2) == 0) {
1793 g_menu_state = CURRENT_STATUS_PLAYBACK_RATE;
1794 } else if (strncmp(cmd, "ss", 2) == 0) {
1795 g_menu_state = CURRENT_STATUS_SWITCH_SUBTITLE;
1796 } else if (strncmp(cmd, "X3", 2) == 0) {
1797 audio_frame_decoded_cb_ex(TRUE);
1798 } else if (strncmp(cmd, "X4", 2) == 0) {
1799 audio_frame_decoded_cb_ex(FALSE);
1800 } else if (strncmp(cmd, "su", 2) == 0) {
1801 g_menu_state = CURRENT_STATUS_NEXT_URI;
1802 } else if (strncmp(cmd, "gu", 2) == 0) {
1805 g_print("unknown menu \n");
1808 if (strncmp(cmd, "trs", 3) == 0)
1809 g_menu_state = CURRENT_STATUS_STREAMING_PLAYBACK_RATE;
1811 g_print("unknown menu \n");
1815 void display_sub_basic()
1819 g_print("=========================================================================================\n");
1820 g_print(" Player Test (press q to quit) \n");
1821 g_print("-----------------------------------------------------------------------------------------\n");
1822 g_print("*. Sample List in [%s] \t", MMTS_SAMPLELIST_INI_DEFAULT_PATH);
1823 g_print("nb. num. of handles \n");
1824 for (idx = 1; idx <= INI_SAMPLE_LIST_MAX; idx++) {
1825 if (strlen(g_file_list[idx - 1]) > 0)
1826 g_print("%d. Play [%s]\n", idx, g_file_list[idx - 1]);
1828 g_print("-----------------------------------------------------------------------------------------\n");
1829 g_print("[playback] a. Create\t");
1830 g_print("pr. Prepare \t");
1831 g_print("pa. Prepare async \t");
1832 g_print("b. Play \t");
1833 g_print("c. Stop \t");
1834 g_print("d. Resume\t");
1835 g_print("e. Pause \t");
1836 g_print("un. Unprepare \t");
1837 g_print("dt. Destroy \n");
1838 g_print("[State] S. Player State \n");
1839 g_print("[ volume ] f. Set Volume\t");
1840 g_print("g. Get Volume\t");
1841 g_print("z. Set Sound type\t");
1842 g_print("k. Set Sound Stream Info.\t");
1843 g_print("[ mute ] h. Set Mute\t");
1844 g_print("i. Get Mute\n");
1845 g_print("[audio eq] E. Set Audio EQ\t");
1846 g_print("H. Get Audio EQ\n");
1847 g_print("[position] j. Set Position \t");
1848 g_print("l. Get Position\n");
1849 g_print("[trick] tr. set playback rate\n");
1850 g_print("[duration] m. Get Duration\n");
1851 g_print("[Stream Info] n. Get stream info (Video Size, codec, audio stream info, and tag info)\n");
1852 g_print("[Looping] o. Set Looping\t");
1853 g_print("p. Get Looping\n");
1854 g_print("[display] v. Set display visible\t");
1855 g_print("w. Get display visible\n");
1856 g_print("[display] ds. Change display surface type\n");
1857 g_print("[overlay display] r. Set display mode\t");
1858 g_print("s. Get display mode\n");
1859 g_print("[overlay display] t. Set display Rotation\t");
1860 g_print("[Track] tl. Get Track language info(single only)\n");
1861 g_print("[subtitle] A. Set(or change) subtitle path\n");
1862 g_print("[subtitle] ss. Select(or change) subtitle track\n");
1863 g_print("[Video Capture] C. Capture \n");
1864 g_print("[next uri] su. set next uri. \t");
1865 g_print("gu. get next uri. \t");
1866 g_print("[etc] sp. Set Progressive Download\t");
1867 g_print("gp. Get Progressive Download status\n");
1868 g_print("mp. memory playback\n");
1869 g_print("[audio_frame_decoded_cb_ex] X3. set audio_cb with sync\t");
1870 g_print("X4. set audio_cb with async \n");
1872 g_print("=========================================================================================\n");
1875 static void displaymenu()
1877 if (g_menu_state == CURRENT_STATUS_MAINMENU) {
1878 display_sub_basic();
1879 } else if (g_menu_state == CURRENT_STATUS_HANDLE_NUM) {
1880 g_print("*** input number of handles.(recommended only for EVAS surface)\n");
1881 } else if (g_menu_state == CURRENT_STATUS_FILENAME) {
1882 g_print("*** input mediapath.\n");
1883 } else if (g_menu_state == CURRENT_STATUS_VOLUME) {
1884 g_print("*** input volume value.(0~1.0)\n");
1885 } else if (g_menu_state == CURRENT_STATUS_SOUND_TYPE) {
1886 g_print("*** input sound type.(0:SYSTEM 1:NOTIFICATION 2:ALARM 3:RINGTONE 4:MEDIA 5:CALL 6:VOIP 7:FIXED)\n");
1887 } else if (g_menu_state == CURRENT_STATUS_SOUND_STREAM_INFO) {
1888 g_print("*** input sound stream type.(0:MEDIA 1:SYSTEM 2:ALARM 3:NOTIFICATION 4:EMERGENCY 5:VOICE_INFORMATION 9:MEDIA_EXT_ONLY)\n");
1889 } else if (g_menu_state == CURRENT_STATUS_MUTE) {
1890 g_print("*** input mute value.(0: Not Mute, 1: Mute) \n");
1891 } else if (g_menu_state == CURRENT_STATUS_POSITION_TIME) {
1892 g_print("*** input position value(msec)\n");
1893 } else if (g_menu_state == CURRENT_STATUS_LOOPING) {
1894 g_print("*** input looping value.(0: Not Looping, 1: Looping) \n");
1895 } else if (g_menu_state == CURRENT_STATUS_DISPLAY_SURFACE_CHANGE) {
1896 g_print("*** input display surface type.(0: X surface, 1: EVAS surface) \n");
1897 } else if (g_menu_state == CURRENT_STATUS_DISPLAY_MODE) {
1898 g_print("*** input display mode value.(0: LETTER BOX, 1: ORIGIN SIZE, 2: FULL_SCREEN, 3: CROPPED_FULL, 4: ORIGIN_OR_LETTER) \n");
1899 } else if (g_menu_state == CURRENT_STATUS_DISPLAY_ROTATION) {
1900 g_print("*** input display rotation value.(0: NONE, 1: 90, 2: 180, 3: 270, 4:F LIP_HORZ, 5: FLIP_VERT ) \n");
1901 } else if (g_menu_state == CURRENT_STATUS_DISPLAY_VISIBLE) {
1902 g_print("*** input display visible value.(0: HIDE, 1: SHOW) \n");
1903 } else if (g_menu_state == CURRENT_STATUS_SUBTITLE_FILENAME) {
1904 g_print(" *** input subtitle file path.\n");
1905 } else if (g_menu_state == CURRENT_STATUS_AUDIO_EQUALIZER) {
1906 g_print(" *** input audio eq value.(0: UNSET, 1: SET) \n");
1907 } else if (g_menu_state == CURRENT_STATUS_PLAYBACK_RATE || g_menu_state == CURRENT_STATUS_STREAMING_PLAYBACK_RATE) {
1908 g_print(" *** input playback rate.(-5.0 ~ 5.0)\n");
1909 } else if (g_menu_state == CURRENT_STATUS_SWITCH_SUBTITLE) {
1910 int count = 0, cur_index = 0;
1913 ret = player_get_track_count(g_player[0], PLAYER_STREAM_TYPE_TEXT, &count);
1914 if (ret != PLAYER_ERROR_NONE)
1915 g_print("player_get_track_count fail!!!!\n");
1917 g_print("Total subtitle tracks = %d \n", count);
1918 player_get_current_track(g_player[0], PLAYER_STREAM_TYPE_TEXT, &cur_index);
1919 g_print("Current index = %d \n", cur_index);
1920 g_print(" *** input correct index 0 to %d\n:", (count - 1));
1922 g_print("no track\n");
1923 } else if (g_menu_state == CURRENT_STATUS_NEXT_URI) {
1924 g_print("*** input next uri.\n");
1926 g_print("*** unknown status.\n");
1932 gboolean timeout_menu_display(void *data)
1938 gboolean timeout_quit_program(void *data)
1944 void reset_menu_state(void)
1946 g_menu_state = CURRENT_STATUS_MAINMENU;
1949 static void interpret(char *cmd)
1951 switch (g_menu_state) {
1952 case CURRENT_STATUS_MAINMENU:
1954 _interpret_main_menu(cmd);
1957 case CURRENT_STATUS_HANDLE_NUM:
1959 int num_handle = atoi(cmd);
1960 if (0 >= num_handle || num_handle > MAX_HANDLE)
1961 g_print("not supported this number for handles(%d)\n", num_handle);
1963 g_handle_num = num_handle;
1968 case CURRENT_STATUS_FILENAME:
1970 input_filename(cmd);
1974 case CURRENT_STATUS_VOLUME:
1976 float level = atof(cmd);
1981 case CURRENT_STATUS_SOUND_TYPE:
1983 int type = atoi(cmd);
1984 set_sound_type(type);
1988 case CURRENT_STATUS_SOUND_STREAM_INFO:
1990 int type = atoi(cmd);
1991 set_sound_stream_info(type);
1995 case CURRENT_STATUS_MUTE:
1997 int mute = atoi(cmd);
2002 case CURRENT_STATUS_POSITION_TIME:
2004 long position = atol(cmd);
2005 set_position(position);
2009 case CURRENT_STATUS_LOOPING:
2011 int looping = atoi(cmd);
2012 set_looping(looping);
2016 case CURRENT_STATUS_DISPLAY_SURFACE_CHANGE:
2018 int type = atoi(cmd);
2019 change_surface(type);
2023 case CURRENT_STATUS_DISPLAY_MODE:
2025 int mode = atoi(cmd);
2026 set_display_mode(mode);
2030 case CURRENT_STATUS_DISPLAY_ROTATION:
2032 int rotation = atoi(cmd);
2033 set_display_rotation(rotation);
2037 case CURRENT_STATUS_DISPLAY_VISIBLE:
2039 int visible = atoi(cmd);
2040 set_display_visible(visible);
2044 case CURRENT_STATUS_SUBTITLE_FILENAME:
2046 input_subtitle_filename(cmd);
2050 case CURRENT_STATUS_AUDIO_EQUALIZER:
2052 int value = atoi(cmd);
2053 set_audio_eq(value);
2057 case CURRENT_STATUS_PLAYBACK_RATE:
2059 float rate = atof(cmd);
2060 set_playback_rate(rate, FALSE);
2064 case CURRENT_STATUS_STREAMING_PLAYBACK_RATE:
2066 float rate = atof(cmd);
2067 set_playback_rate(rate, TRUE);
2071 case CURRENT_STATUS_SWITCH_SUBTITLE:
2073 int index = atoi(cmd);
2074 switch_subtitle(index);
2078 case CURRENT_STATUS_NEXT_URI:
2086 g_timeout_add(100, timeout_menu_display, 0);
2089 gboolean input(GIOChannel * channel)
2091 gchar buf[MAX_STRING_LEN];
2093 GError *error = NULL;
2095 g_io_channel_read_chars(channel, buf, MAX_STRING_LEN, &read, &error);
2103 int main(int argc, char *argv[])
2105 GIOChannel *stdin_channel;
2106 stdin_channel = g_io_channel_unix_new(0);
2107 g_io_channel_set_flags(stdin_channel, G_IO_FLAG_NONBLOCK, NULL);
2108 g_io_add_watch(stdin_channel, G_IO_IN, (GIOFunc) input, NULL);
2111 memset(&ad, 0x0, sizeof(appdata));
2114 return appcore_efl_main(PACKAGE, &argc, &argv, &ops);