4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: JongHyuk Choi <jhchoi.choi@samsung.com>, YeJin Cho <cho.yejin@samsung.com>,
7 * YoungHwan An <younghwan_.an@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
23 /*===========================================================================================
27 ========================================================================================== */
30 #include "mm_player_utils.h"
31 #include "mm_player_priv.h"
32 #include "mm_player_attrs.h"
34 /*===========================================================================================
36 | LOCAL DEFINITIONS AND DECLARATIONS FOR MODULE |
38 ========================================================================================== */
40 /*-----------------------------------------------------------------------
41 | LOCAL FUNCTION PROTOTYPES: |
42 -----------------------------------------------------------------------*/
43 static bool __mmplayer_commit_gapless_mode(MMHandleType handle, int attr_idx, const MMAttrsValue *value);
44 static bool __mmplayer_commit_enable_video_decoded_cb(MMHandleType handle, int attr_idx, const MMAttrsValue *value);
45 static bool __mmplayer_commit_audio_pitch_value(MMHandleType handle, int attr_idx, const MMAttrsValue *value);
47 /*-----------------------------------------------------------------------
48 | LOCAL VARIABLE DEFINITIONS for internal |
49 -----------------------------------------------------------------------*/
50 mmplayer_attrs_spec_t player_attrs[] = {
52 MMPLAYER_ATTRS_PROFILE_URI, /* ID */
53 (char *)"profile_uri", /* Name */
54 MM_ATTRS_TYPE_STRING, /* Value Type */
55 MM_ATTRS_FLAG_RW, /* Flag */
56 {(void *)NULL}, /* default value */
57 MM_ATTRS_VALID_TYPE_NONE, /* validity type */
58 {0}, /* validity min value */
59 {0}, /* validity max value */
60 NULL, /* Runtime setting function of the attribute */
63 MMPLAYER_ATTRS_PROFILE_USER_PARAM,
64 (char *)"profile_user_param",
68 MM_ATTRS_VALID_TYPE_NONE,
74 MMPLAYER_ATTRS_PROFILE_PLAY_COUNT,
75 (char *)"profile_play_count",
78 {(void *)1}, /* -1 : repeat continually */
79 MM_ATTRS_VALID_TYPE_INT_RANGE,
85 MMPLAYER_ATTRS_PROFILE_PREPARE_ASYNC,
86 (char *)"profile_prepare_async",
90 MM_ATTRS_VALID_TYPE_INT_RANGE,
96 MMPLAYER_ATTRS_STREAMING_USER_AGENT,
97 (char *)"streaming_user_agent",
101 MM_ATTRS_VALID_TYPE_NONE,
107 MMPLAYER_ATTRS_STREAMING_COOKIE,
108 (char *)"streaming_cookie",
109 MM_ATTRS_TYPE_STRING,
112 MM_ATTRS_VALID_TYPE_NONE,
118 MMPLAYER_ATTRS_SUBTITLE_URI,
119 (char *)"subtitle_uri",
120 MM_ATTRS_TYPE_STRING,
123 MM_ATTRS_VALID_TYPE_NONE,
129 MMPLAYER_ATTRS_CONTENT_BITRATE,
130 (char *)"content_bitrate",
134 MM_ATTRS_VALID_TYPE_INT_RANGE,
136 {.int_max = MMPLAYER_MAX_INT},
140 MMPLAYER_ATTRS_CONTENT_MAX_BITRATE,
141 (char *)"content_max_bitrate",
145 MM_ATTRS_VALID_TYPE_INT_RANGE,
147 {.int_max = MMPLAYER_MAX_INT},
151 MMPLAYER_ATTRS_CONTENT_VIDEO_FOUND,
152 (char *)"content_video_found",
156 MM_ATTRS_VALID_TYPE_INT_RANGE,
162 MMPLAYER_ATTRS_CONTENT_VIDEO_CODEC,
163 (char *)"content_video_codec",
164 MM_ATTRS_TYPE_STRING,
167 MM_ATTRS_VALID_TYPE_NONE,
173 MMPLAYER_ATTRS_CONTENT_VIDEO_BITRATE,
174 (char *)"content_video_bitrate",
178 MM_ATTRS_VALID_TYPE_INT_RANGE,
180 {.int_max = MMPLAYER_MAX_INT},
184 MMPLAYER_ATTRS_CONTENT_VIDEO_FPS,
185 (char *)"content_video_fps",
189 MM_ATTRS_VALID_TYPE_INT_RANGE,
191 {.int_max = MMPLAYER_MAX_INT},
195 MMPLAYER_ATTRS_CONTENT_VIDEO_WIDTH,
196 (char *)"content_video_width",
200 MM_ATTRS_VALID_TYPE_INT_RANGE,
202 {.int_max = MMPLAYER_MAX_INT},
206 MMPLAYER_ATTRS_CONTENT_VIDEO_HEIGHT,
207 (char *)"content_video_height",
211 MM_ATTRS_VALID_TYPE_INT_RANGE,
213 {.int_max = MMPLAYER_MAX_INT},
217 MMPLAYER_ATTRS_CONTENT_VIDEO_ORIENTATION,
218 (char *)"content_video_orientation", /* orientation of video content */
219 MM_ATTRS_TYPE_STRING,
222 MM_ATTRS_VALID_TYPE_NONE,
228 MMPLAYER_ATTRS_CONTENT_VIDEO_IS_SPHERICAL,
229 (char *)"content_video_is_spherical",
233 MM_ATTRS_VALID_TYPE_INT_RANGE,
235 {.int_max = MMPLAYER_MAX_INT},
239 MMPLAYER_ATTRS_CONTENT_AUDIO_CODEC,
240 (char *)"content_audio_codec",
241 MM_ATTRS_TYPE_STRING,
244 MM_ATTRS_VALID_TYPE_NONE,
250 MMPLAYER_ATTRS_CONTENT_AUDIO_BITRATE,
251 (char *)"content_audio_bitrate",
255 MM_ATTRS_VALID_TYPE_INT_RANGE,
257 {.int_max = MMPLAYER_MAX_INT},
261 MMPLAYER_ATTRS_CONTENT_AUDIO_CHANNELS,
262 (char *)"content_audio_channels",
266 MM_ATTRS_VALID_TYPE_INT_RANGE,
268 {.int_max = MMPLAYER_MAX_INT},
272 MMPLAYER_ATTRS_CONTENT_AUDIO_SAMPLERATE,
273 (char *)"content_audio_samplerate",
277 MM_ATTRS_VALID_TYPE_INT_RANGE,
279 {.int_max = MMPLAYER_MAX_INT},
283 MMPLAYER_ATTRS_CONTENT_AUDIO_FORMAT,
284 (char *)"content_audio_format",
285 MM_ATTRS_TYPE_STRING,
288 MM_ATTRS_VALID_TYPE_NONE,
294 MMPLAYER_ATTRS_CONTENT_TEXT_TRACK_NUM,
295 (char *)"content_text_track_num",
299 MM_ATTRS_VALID_TYPE_INT_RANGE,
301 {.int_max = MMPLAYER_MAX_INT},
305 MMPLAYER_ATTRS_CONTENT_TEXT_TRACK_INDEX,
306 (char *)"current_text_track_index",
310 MM_ATTRS_VALID_TYPE_INT_RANGE,
312 {.int_max = MMPLAYER_MAX_INT},
316 MMPLAYER_ATTRS_TAG_ARTIST,
317 (char *)"tag_artist",
318 MM_ATTRS_TYPE_STRING,
321 MM_ATTRS_VALID_TYPE_NONE,
327 MMPLAYER_ATTRS_TAG_TITLE,
329 MM_ATTRS_TYPE_STRING,
332 MM_ATTRS_VALID_TYPE_NONE,
338 MMPLAYER_ATTRS_TAG_ALBUM,
340 MM_ATTRS_TYPE_STRING,
343 MM_ATTRS_VALID_TYPE_NONE,
349 MMPLAYER_ATTRS_TAG_GENRE,
351 MM_ATTRS_TYPE_STRING,
354 MM_ATTRS_VALID_TYPE_NONE,
360 MMPLAYER_ATTRS_TAG_AUTHOR,
361 (char *)"tag_author",
362 MM_ATTRS_TYPE_STRING,
365 MM_ATTRS_VALID_TYPE_NONE,
371 MMPLAYER_ATTRS_TAG_COPYRIGHT,
372 (char *)"tag_copyright",
373 MM_ATTRS_TYPE_STRING,
376 MM_ATTRS_VALID_TYPE_NONE,
382 MMPLAYER_ATTRS_TAG_DATE,
384 MM_ATTRS_TYPE_STRING,
387 MM_ATTRS_VALID_TYPE_NONE,
393 MMPLAYER_ATTRS_TAG_DESCRIPTION,
394 (char *)"tag_description",
395 MM_ATTRS_TYPE_STRING,
398 MM_ATTRS_VALID_TYPE_NONE,
404 MMPLAYER_ATTRS_TAG_TRACK_NUM,
405 (char *)"tag_track_num",
409 MM_ATTRS_VALID_TYPE_INT_RANGE,
411 {.int_max = MMPLAYER_MAX_INT},
415 MMPLAYER_ATTRS_TAG_ALBUM_COVER,
416 (char *)"tag_album_cover",
420 MM_ATTRS_VALID_TYPE_NONE,
426 MMPLAYER_ATTRS_DISPLAY_ROTATION,
427 (char *)"display_rotation",
430 {(void *)MM_DISPLAY_ROTATION_NONE},
431 MM_ATTRS_VALID_TYPE_INT_RANGE,
432 {.int_min = MM_DISPLAY_ROTATION_NONE},
433 {.int_max = MM_DISPLAY_ROTATION_270},
437 MMPLAYER_ATTRS_DISPLAY_VISIBLE,
438 (char *)"display_visible",
442 MM_ATTRS_VALID_TYPE_INT_RANGE,
448 MMPLAYER_ATTRS_DISPLAY_METHOD,
449 (char *)"display_method",
452 {(void *)MM_DISPLAY_METHOD_LETTER_BOX},
453 MM_ATTRS_VALID_TYPE_INT_RANGE,
454 {.int_min = MM_DISPLAY_METHOD_LETTER_BOX},
455 {.int_max = MM_DISPLAY_METHOD_CUSTOM_ROI},
459 MMPLAYER_ATTRS_DISPLAY_OVERLAY,
460 (char *)"display_overlay",
464 MM_ATTRS_VALID_TYPE_INT_RANGE,
466 {.int_max = MMPLAYER_MAX_INT},
470 MMPLAYER_ATTRS_DISPLAY_WIN_ROI_X,
471 (char *)"display_win_roi_x",
475 MM_ATTRS_VALID_TYPE_INT_RANGE,
476 {.int_min = MMPLAYER_MIN_INT},
477 {.int_max = MMPLAYER_MAX_INT},
481 MMPLAYER_ATTRS_DISPLAY_WIN_ROI_Y,
482 (char *)"display_win_roi_y",
486 MM_ATTRS_VALID_TYPE_INT_RANGE,
487 {.int_min = MMPLAYER_MIN_INT},
488 {.int_max = MMPLAYER_MAX_INT},
492 MMPLAYER_ATTRS_DISPLAY_WIN_ROI_WIDTH,
493 (char *)"display_win_roi_width",
497 MM_ATTRS_VALID_TYPE_INT_RANGE,
499 {.int_max = MMPLAYER_MAX_INT},
503 MMPLAYER_ATTRS_DISPLAY_WIN_ROI_HEIGHT,
504 (char *)"display_win_roi_height",
508 MM_ATTRS_VALID_TYPE_INT_RANGE,
510 {.int_max = MMPLAYER_MAX_INT},
514 MMPLAYER_ATTRS_DISPLAY_SURFACE_TYPE,
515 (char *)"display_surface_type",
518 {(void *)MM_DISPLAY_SURFACE_NULL},
519 MM_ATTRS_VALID_TYPE_INT_RANGE,
520 {.int_min = MM_DISPLAY_SURFACE_OVERLAY},
521 {.int_max = MM_DISPLAY_SURFACE_NUM - 1},
525 MMPLAYER_ATTRS_SOUND_STREAM_TYPE,
526 (char *)"sound_stream_type",
527 MM_ATTRS_TYPE_STRING,
530 MM_ATTRS_VALID_TYPE_NONE,
536 MMPLAYER_ATTRS_SOUND_STREAM_INDEX,
537 (char *)"sound_stream_index",
541 MM_ATTRS_VALID_TYPE_INT_RANGE,
543 {.int_max = MMPLAYER_MAX_INT},
547 MMPLAYER_ATTRS_SOUND_LATENCY_MODE,
548 (char *)"sound_latency_mode",
551 {(void *)1}, /* 0: low latency, 1: middle latency 2: high latency */
552 MM_ATTRS_VALID_TYPE_INT_RANGE,
558 MMPLAYER_ATTRS_PCM_EXTRACTION_SAMPLERATE,
559 (char *)"pcm_extraction_samplerate", /* set samplerate for pcm extraction */
563 MM_ATTRS_VALID_TYPE_INT_RANGE,
565 {.int_max = MMPLAYER_MAX_INT},
569 MMPLAYER_ATTRS_PCM_EXTRACTION_CHANNELS,
570 (char *)"pcm_extraction_channels", /* set channels for pcm extraction */
574 MM_ATTRS_VALID_TYPE_INT_RANGE,
576 {.int_max = MMPLAYER_MAX_INT},
580 MMPLAYER_ATTRS_ACCURATE_SEEK,
581 (char *)"accurate_seek",
585 MM_ATTRS_VALID_TYPE_INT_RANGE,
591 MMPLAYER_ATTRS_PCM_EXTRACTION_FORMAT,
592 (char *)"pcm_extraction_format",
593 MM_ATTRS_TYPE_STRING,
596 MM_ATTRS_VALID_TYPE_NONE,
602 MMPLAYER_ATTRS_DRC_MODE,
607 MM_ATTRS_VALID_TYPE_INT_RANGE,
613 MMPLAYER_ATTRS_GAPLESS_MODE,
614 (char *)"gapless_mode",
618 MM_ATTRS_VALID_TYPE_INT_RANGE,
621 __mmplayer_commit_gapless_mode,
624 MMPLAYER_ATTRS_ENABLE_VIDEO_DECODED_CB,
625 (char *)"enable_video_decoded_cb",
629 MM_ATTRS_VALID_TYPE_INT_RANGE,
632 __mmplayer_commit_enable_video_decoded_cb,
635 MMPLAYER_ATTRS_VIDEO_CODEC_TYPE,
636 (char *)"video_codec_type",
639 {(void *)MM_PLAYER_CODEC_TYPE_DEFAULT},
640 MM_ATTRS_VALID_TYPE_INT_RANGE,
641 {.int_min = MM_PLAYER_CODEC_TYPE_DEFAULT},
642 {.int_max = MM_PLAYER_CODEC_TYPE_SW},
646 MMPLAYER_ATTRS_AUDIO_CODEC_TYPE,
647 (char *)"audio_codec_type",
650 {(void *)MM_PLAYER_CODEC_TYPE_DEFAULT},
651 MM_ATTRS_VALID_TYPE_INT_RANGE,
652 {.int_min = MM_PLAYER_CODEC_TYPE_DEFAULT},
653 {.int_max = MM_PLAYER_CODEC_TYPE_SW},
657 MMPLAYER_ATTRS_VIDEO_BUFFER_TOTAL_SIZE,
658 (char *)"video_buffer_total_size",
661 {(void *)DEFAULT_NUM_OF_V_OUT_BUFFER},
662 MM_ATTRS_VALID_TYPE_INT_RANGE,
663 {.int_min = MMPLAYER_MIN_INT},
664 {.int_max = MMPLAYER_MAX_INT},
668 MMPLAYER_ATTRS_VIDEO_BUFFER_EXTRA_SIZE,
669 (char *)"video_buffer_extra_size",
672 {(void *)DEFAULT_NUM_OF_V_OUT_BUFFER},
673 MM_ATTRS_VALID_TYPE_INT_RANGE,
674 {.int_min = MMPLAYER_MIN_INT},
675 {.int_max = MMPLAYER_MAX_INT},
679 MMPLAYER_ATTRS_PREBUFFER_MS,
680 (char *)"prebuffer_ms", /* user setting */
683 {(void *) MIN_BUFFERING_TIME},
684 MM_ATTRS_VALID_TYPE_INT_RANGE,
685 {.int_min = MIN_BUFFERING_TIME},
686 {.int_max = MMPLAYER_MAX_INT},
690 MMPLAYER_ATTRS_REBUFFER_MS,
691 (char *)"rebuffer_ms", /* user setting */
694 {(void *) MIN_BUFFERING_TIME},
695 MM_ATTRS_VALID_TYPE_INT_RANGE,
696 {.int_min = MIN_BUFFERING_TIME},
697 {.int_max = MMPLAYER_MAX_INT},
701 MMPLAYER_ATTRS_PITCH_CONTROL,
702 (char *)"pitch_control", /* MM_PLAYER_PITCH_CONTROL */
706 MM_ATTRS_VALID_TYPE_INT_RANGE,
712 MMPLAYER_ATTRS_PITCH_VALUE,
713 (char *)"pitch_value", /* MM_PLAYER_PITCH_VALUE */
714 MM_ATTRS_TYPE_DOUBLE,
716 {.value_double = 1.0},
717 MM_ATTRS_VALID_TYPE_DOUBLE_RANGE,
720 __mmplayer_commit_audio_pitch_value,
723 MMPLAYER_ATTRS_AUDIO_OFFLOAD,
724 (char *)"audio_offload", /* MM_PLAYER_AUDIO_OFFLOAD */
728 MM_ATTRS_VALID_TYPE_INT_RANGE,
734 MMPLAYER_ATTRS_AUDIO_OFFLOAD_FORMAT,
735 (char *)"audio_offload_format", /* MM_PLAYER_AUDIO_OFFLOAD_FORMAT, array of media_format_mimetype_e */
739 MM_ATTRS_VALID_TYPE_INT_ARRAY,
745 MMPLAYER_ATTRS_MEDIA_STREAM_INPUT_FORMAT, /* MM_PLAYER_MEDIA_STREAM_INPUT_FORMAT */
746 (char *)"media_stream_input_format",
750 MM_ATTRS_VALID_TYPE_INT_ARRAY,
757 /*===========================================================================================
759 | FUNCTION DEFINITIONS |
761 ========================================================================================== */
763 static bool __mmplayer_commit_enable_video_decoded_cb(MMHandleType handle, int attr_idx, const MMAttrsValue *value)
765 mmplayer_t *player = MM_PLAYER_CAST(handle);
766 mmplayer_gst_element_t *videobin = NULL;
769 MMPLAYER_RETURN_VAL_IF_FAIL(player && value, false);
771 if (!_mmplayer_is_videosink_ready(player, MM_DISPLAY_SURFACE_NUM)) {
772 LOGD("will be applied when videosink is ready");
776 if (!player->set_mode.video_export) {
777 LOGW("there is no callback for enabling");
781 videobin = player->pipeline->videobin;
783 LOGD("[update plugin][videosink] handoff %d", value->value.i_val);
785 g_object_set(videobin[MMPLAYER_V_SINK].gst,
786 "signal-handoffs", (value->value.i_val) ? TRUE : FALSE, NULL);
791 static bool __mmplayer_commit_gapless_mode(MMHandleType handle, int attr_idx, const MMAttrsValue *value)
793 mmplayer_t *player = MM_PLAYER_CAST(handle);
794 mmplayer_gst_element_t *videobin = NULL;
797 MMPLAYER_RETURN_VAL_IF_FAIL(player && value, false);
799 if (!_mmplayer_is_videosink_ready(player, MM_DISPLAY_SURFACE_NUM)) {
800 LOGD("will be applied when videosink is ready");
804 videobin = player->pipeline->videobin;
806 if (value->value.i_val > 0) {
807 LOGD("[update plugin][videosink] disable last sample for gapless");
808 g_object_set(videobin[MMPLAYER_V_SINK].gst, "enable-last-sample", FALSE, NULL);
814 static bool __mmplayer_commit_audio_pitch_value(MMHandleType handle, int attr_idx, const MMAttrsValue *value)
816 mmplayer_t *player = MM_PLAYER_CAST(handle);
817 mmplayer_pipeline_info_t *pipeline;
818 int pitch_control = 0;
821 MMPLAYER_RETURN_VAL_IF_FAIL(player && value, false);
822 MMPLAYER_RETURN_VAL_IF_FAIL(player->pipeline && player->pipeline->mainbin, true);
824 pipeline = player->pipeline;
825 mm_attrs_get_int_by_name(player->attrs, MM_PLAYER_PITCH_CONTROL, &pitch_control);
827 if (!pitch_control || !pipeline->audiobin[MMPLAYER_A_PITCH].gst) {
828 LOGW("audio pitch is disabled");
832 LOGD("[update plugin][pitch] value to %1.3f", value->value.d_val);
833 g_object_set(pipeline->audiobin[MMPLAYER_A_PITCH].gst, "pitch", (value->value.d_val), NULL);
838 static int __mmplayer_get_array_count(MMHandleType handle, int type)
840 mmplayer_t *player = (mmplayer_t *)handle;
845 if (type == KEYWORD_A_OFFLOAD_MEDIA_FORMAT) {
846 while (player->ini.audio_offload_media_format[i++][0])
848 } else if (type == KEYWORD_MEDIA_STREAM_IN_FORMAT) {
849 while (player->ini.media_stream_input_format[i++][0])
855 static media_format_mimetype_e __mmplayer_get_supported_format_mimetype(MMHandleType handle, int type, int i)
858 media_format_mimetype_e format = MEDIA_FORMAT_MAX;
860 mmplayer_t *player = (mmplayer_t *)handle;
862 if (type == KEYWORD_A_OFFLOAD_MEDIA_FORMAT) {
863 name = player->ini.audio_offload_media_format[i];
864 } else if (type == KEYWORD_MEDIA_STREAM_IN_FORMAT) {
865 name = player->ini.media_stream_input_format[i];
867 LOGE("invalid ini type");
871 if (!strcmp(name, "MP3"))
872 format = MEDIA_FORMAT_MP3;
873 else if (!strcmp(name, "AAC"))
874 format = MEDIA_FORMAT_AAC;
875 else if (!strcmp(name, "H264_SP"))
876 format = MEDIA_FORMAT_H264_SP;
877 else if (!strcmp(name, "H264_MP"))
878 format = MEDIA_FORMAT_H264_MP;
879 else if (!strcmp(name, "H264_HP"))
880 format = MEDIA_FORMAT_H264_HP;
881 else if (!strcmp(name, "PCM"))
882 format = MEDIA_FORMAT_PCM;
883 else if (!strcmp(name, "PCM_S16LE"))
884 format = MEDIA_FORMAT_PCM_S16LE;
885 else if (!strcmp(name, "PCM_S24LE"))
886 format = MEDIA_FORMAT_PCM_S24LE;
887 else if (!strcmp(name, "PCM_S32LE"))
888 format = MEDIA_FORMAT_PCM_S32LE;
889 else if (!strcmp(name, "PCM_S16BE"))
890 format = MEDIA_FORMAT_PCM_S16BE;
891 else if (!strcmp(name, "PCM_S24BE"))
892 format = MEDIA_FORMAT_PCM_S24BE;
893 else if (!strcmp(name, "PCM_S32BE"))
894 format = MEDIA_FORMAT_PCM_S32BE;
895 else if (!strcmp(name, "PCM_F32LE"))
896 format = MEDIA_FORMAT_PCM_F32LE;
897 else if (!strcmp(name, "PCM_F32BE"))
898 format = MEDIA_FORMAT_PCM_F32BE;
899 else if (!strcmp(name, "PCM_S16LE"))
900 format = MEDIA_FORMAT_PCM_U16LE;
901 else if (!strcmp(name, "PCM_U24LE"))
902 format = MEDIA_FORMAT_PCM_U24LE;
903 else if (!strcmp(name, "PCM_U32LE"))
904 format = MEDIA_FORMAT_PCM_U32LE;
905 else if (!strcmp(name, "PCM_U16BE"))
906 format = MEDIA_FORMAT_PCM_U16BE;
907 else if (!strcmp(name, "PCM_U24BE"))
908 format = MEDIA_FORMAT_PCM_U24BE;
909 else if (!strcmp(name, "PCM_U32BE"))
910 format = MEDIA_FORMAT_PCM_U32BE;
912 LOGE("FIXME: need to modify function to support more format");
915 LOGD("[%d type] supported format 0x%X(%s)", type, format, name);
920 static int __mmplayer_get_available_format(MMHandleType handle, int type, int **format)
928 MMPLAYER_RETURN_VAL_IF_FAIL(handle, -1);
930 count = __mmplayer_get_array_count(handle, type);
935 arr = (int *) g_malloc0(count * sizeof(int));
937 LOGE("malloc failed : %zu", count * sizeof(int));
941 for (i = 0 ; i < count ; i++) {
942 fmt = __mmplayer_get_supported_format_mimetype(handle, type, i);
943 if (fmt != MEDIA_FORMAT_MAX)
944 arr[total_count++] = fmt;
947 LOGD("[%d type] num of supported codec %d", type, total_count);
953 static int __mmplayer_set_ini_to_valid_info(MMHandleType handle)
958 /* supported format of audio offload */
959 total_count = __mmplayer_get_available_format(handle, KEYWORD_A_OFFLOAD_MEDIA_FORMAT, &format);
960 if (format && total_count > 0) {
961 player_attrs[MMPLAYER_ATTRS_AUDIO_OFFLOAD_FORMAT].validity_value_1.int_array = format;
962 player_attrs[MMPLAYER_ATTRS_AUDIO_OFFLOAD_FORMAT].validity_value_2.count = total_count;
965 /* supported format of media stream input */
966 total_count = __mmplayer_get_available_format(handle, KEYWORD_MEDIA_STREAM_IN_FORMAT, &format);
967 if (format && total_count > 0) {
968 player_attrs[MMPLAYER_ATTRS_MEDIA_STREAM_INPUT_FORMAT].validity_value_1.int_array = format;
969 player_attrs[MMPLAYER_ATTRS_MEDIA_STREAM_INPUT_FORMAT].validity_value_2.count = total_count;
972 return MM_ERROR_NONE;
975 static int __mmplayer_release_ini_info(void)
981 mem = (int *)(player_attrs[MMPLAYER_ATTRS_AUDIO_OFFLOAD_FORMAT].validity_value_1.int_array);
984 player_attrs[MMPLAYER_ATTRS_AUDIO_OFFLOAD_FORMAT].validity_value_1.int_array = NULL;
985 player_attrs[MMPLAYER_ATTRS_AUDIO_OFFLOAD_FORMAT].validity_value_2.count = 0;
988 mem = (int *)(player_attrs[MMPLAYER_ATTRS_MEDIA_STREAM_INPUT_FORMAT].validity_value_1.int_array);
991 player_attrs[MMPLAYER_ATTRS_MEDIA_STREAM_INPUT_FORMAT].validity_value_1.int_array = NULL;
992 player_attrs[MMPLAYER_ATTRS_MEDIA_STREAM_INPUT_FORMAT].validity_value_2.count = 0;
996 return MM_ERROR_NONE;
999 static void __mmplayer_print_attrs(const char *attr_name, const MMAttrsValue * value, const char *prefix)
1001 switch (value->type) {
1002 case MM_ATTRS_TYPE_INT:
1003 LOGD("[ %s : %s : %d ]", prefix, attr_name, value->value.i_val);
1005 case MM_ATTRS_TYPE_DOUBLE:
1006 LOGD("[ %s : %s : %f ]", prefix, attr_name, value->value.d_val);
1008 case MM_ATTRS_TYPE_STRING:
1009 LOGD("[ %s : %s : %s ]", prefix, attr_name, value->value.s_val);
1011 case MM_ATTRS_TYPE_DATA:
1012 LOGD("[ %s : %s : %p ]", prefix, attr_name, value->value.p_val);
1021 bool _mmplayer_commit_attribute(int attr_idx, const char *attr_name, const MMAttrsValue *value, void *user_data)
1024 mmplayer_t *player = MM_PLAYER_CAST(user_data);
1026 MMPLAYER_RETURN_VAL_IF_FAIL(player && (attr_idx >= 0) && attr_name && value, false);
1028 if (player_attrs[attr_idx].attr_commit) {
1029 __mmplayer_print_attrs(attr_name, value, "Dynamic");
1030 ret = player_attrs[attr_idx].attr_commit((MMHandleType)user_data, attr_idx, value);
1032 __mmplayer_print_attrs(attr_name, value, "Static");
1039 int _mmplayer_get_attribute(MMHandleType handle, char **err_attr_name, const char *attribute_name, va_list args_list)
1041 int result = MM_ERROR_NONE;
1042 MMHandleType attrs = NULL;
1044 /* NOTE : Don't need to check err_attr_name because it can be set NULL */
1045 /* if it's not want to know it. */
1046 MMPLAYER_RETURN_VAL_IF_FAIL(attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
1047 MMPLAYER_RETURN_VAL_IF_FAIL(handle, MM_ERROR_COMMON_INVALID_ARGUMENT);
1049 attrs = MM_PLAYER_GET_ATTRS(handle);
1051 result = mm_attrs_get_valist(attrs, err_attr_name, attribute_name, args_list);
1053 if (result != MM_ERROR_NONE)
1054 LOGE("failed to get %s attribute", attribute_name);
1059 int __mmplayer_apply_attribute(MMHandleType handle, const char *attribute_name)
1061 mmplayer_t *player = NULL;
1064 MMPLAYER_RETURN_VAL_IF_FAIL(handle, MM_ERROR_COMMON_INVALID_ARGUMENT);
1065 MMPLAYER_RETURN_VAL_IF_FAIL(attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
1067 player = MM_PLAYER_CAST(handle);
1069 /* apply display attr value to player handle */
1070 if (!g_strrstr(attribute_name, "display"))
1071 return MM_ERROR_NONE;
1073 if (!_mmplayer_is_videosink_ready(player, MM_DISPLAY_SURFACE_NUM)) {
1074 LOGD("will be applied when videosink is ready");
1075 return MM_ERROR_NONE;
1078 if (_mmplayer_update_video_overlay_param(player, attribute_name) != MM_ERROR_NONE) {
1079 LOGW("not supported video param %s", attribute_name);
1080 return MM_ERROR_NONE;
1083 return MM_ERROR_NONE;
1086 int _mmplayer_set_attribute(MMHandleType handle, char **err_attr_name, const char *attribute_name, va_list args_list)
1088 int result = MM_ERROR_NONE;
1089 MMHandleType attrs = NULL;
1091 /* NOTE : Don't need to check err_attr_name because it can be set NULL */
1092 /* if it's not want to know it. */
1093 MMPLAYER_RETURN_VAL_IF_FAIL(attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
1094 MMPLAYER_RETURN_VAL_IF_FAIL(handle, MM_ERROR_COMMON_INVALID_ARGUMENT);
1096 attrs = MM_PLAYER_GET_ATTRS(handle);
1098 /* set attributes and commit them */
1099 result = mm_attrs_set_valist(attrs, err_attr_name, attribute_name, args_list);
1100 if (result != MM_ERROR_NONE) {
1101 LOGE("failed to set %s attribute", attribute_name);
1105 /* Note: 'attr_commit' function is called before committing the new value to attr struct.
1106 so if there is a value to apply after committing, it should be added below function. */
1107 result = __mmplayer_apply_attribute(handle, attribute_name);
1108 if (result != MM_ERROR_NONE) {
1109 LOGE("failed to apply attributes");
1113 return MM_ERROR_NONE;
1116 int _mmplayer_get_attributes_info(MMHandleType handle, const char *attribute_name, mmplayer_attrs_info_t *dst_info)
1118 int result = MM_ERROR_NONE;
1119 MMHandleType attrs = NULL;
1120 MMAttrsInfo src_info = {0, };
1122 MMPLAYER_RETURN_VAL_IF_FAIL(attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
1123 MMPLAYER_RETURN_VAL_IF_FAIL(dst_info, MM_ERROR_COMMON_INVALID_ARGUMENT);
1124 MMPLAYER_RETURN_VAL_IF_FAIL(handle, MM_ERROR_COMMON_INVALID_ARGUMENT);
1126 attrs = MM_PLAYER_GET_ATTRS(handle);
1128 result = mm_attrs_get_info_by_name(attrs, attribute_name, &src_info);
1130 if (result != MM_ERROR_NONE) {
1131 LOGE("failed to get attribute info");
1135 memset(dst_info, 0x00, sizeof(mmplayer_attrs_info_t));
1137 dst_info->type = src_info.type;
1138 dst_info->flag = src_info.flag;
1139 dst_info->validity_type = src_info.validity_type;
1141 switch (src_info.validity_type) {
1142 case MM_ATTRS_VALID_TYPE_INT_ARRAY:
1143 dst_info->int_array.array = src_info.int_array.array;
1144 dst_info->int_array.count = src_info.int_array.count;
1145 dst_info->int_array.d_val = src_info.int_array.dval;
1148 case MM_ATTRS_VALID_TYPE_INT_RANGE:
1149 dst_info->int_range.min = src_info.int_range.min;
1150 dst_info->int_range.max = src_info.int_range.max;
1151 dst_info->int_range.d_val = src_info.int_range.dval;
1154 case MM_ATTRS_VALID_TYPE_DOUBLE_ARRAY:
1155 dst_info->double_array.array = src_info.double_array.array;
1156 dst_info->double_array.count = src_info.double_array.count;
1157 dst_info->double_array.d_val = src_info.double_array.dval;
1160 case MM_ATTRS_VALID_TYPE_DOUBLE_RANGE:
1161 dst_info->double_range.min = src_info.double_range.min;
1162 dst_info->double_range.max = src_info.double_range.max;
1163 dst_info->double_range.d_val = src_info.double_range.dval;
1173 MMHandleType _mmplayer_construct_attribute(MMHandleType handle)
1175 int result = MM_ERROR_NONE;
1177 MMHandleType attrs = NULL;
1178 int num_of_attrs = 0;
1179 MMAttrsConstructInfo *base = NULL;
1181 MMPLAYER_RETURN_VAL_IF_FAIL(handle, 0);
1183 num_of_attrs = ARRAY_SIZE(player_attrs);
1185 base = g_try_new(MMAttrsConstructInfo, num_of_attrs);
1187 LOGE("failed to alloc attrs constructor");
1191 /* initialize values of attributes */
1192 for (idx = 0; idx < num_of_attrs; idx++) {
1193 base[idx].name = player_attrs[idx].name;
1194 base[idx].value_type = player_attrs[idx].value_type;
1195 base[idx].flags = player_attrs[idx].flags;
1196 base[idx].default_value = player_attrs[idx].default_value.value_void; /* FIXME: need to consider the double data type */
1199 result = mm_attrs_new(base, num_of_attrs, "mmplayer_attrs",
1200 _mmplayer_commit_attribute, (void *)handle, &attrs);
1203 MMPLAYER_FREEIF(base);
1206 LOGE("failed to create player attrs");
1210 __mmplayer_set_ini_to_valid_info(handle);
1212 /* set validity type and range */
1213 for (idx = 0; idx < num_of_attrs; idx++) {
1214 mm_attrs_set_valid_type(attrs, idx, player_attrs[idx].valid_type);
1215 switch (player_attrs[idx].valid_type) {
1216 case MM_ATTRS_VALID_TYPE_INT_RANGE:
1217 mm_attrs_set_valid_range(attrs, idx,
1218 player_attrs[idx].validity_value_1.int_min,
1219 player_attrs[idx].validity_value_2.int_max,
1220 player_attrs[idx].default_value.value_int);
1222 case MM_ATTRS_VALID_TYPE_INT_ARRAY:
1223 if (player_attrs[idx].validity_value_1.int_array &&
1224 player_attrs[idx].validity_value_2.count > 0)
1225 mm_attrs_set_valid_array(attrs, idx,
1226 (const int *)(player_attrs[idx].validity_value_1.int_array),
1227 player_attrs[idx].validity_value_2.count,
1228 player_attrs[idx].default_value.value_int);
1230 case MM_ATTRS_VALID_TYPE_DOUBLE_RANGE:
1231 mm_attrs_set_valid_double_range(attrs, idx,
1232 player_attrs[idx].validity_value_1.double_min,
1233 player_attrs[idx].validity_value_2.double_max,
1234 player_attrs[idx].default_value.value_double);
1236 case MM_ATTRS_VALID_TYPE_DOUBLE_ARRAY:
1237 LOGW("FIXME: need to set range value if required.");
1238 case MM_ATTRS_VALID_TYPE_NONE:
1239 case MM_ATTRS_VALID_TYPE_INVALID:
1246 if (mm_attrs_commit_all(attrs)) {
1247 LOGE("failed to update attributes");
1248 mm_attrs_free(attrs);
1252 __mmplayer_release_ini_info();
1257 bool _mmplayer_deconstruct_attribute(MMHandleType handle)
1259 mmplayer_t *player = MM_PLAYER_CAST(handle);
1261 MMPLAYER_RETURN_VAL_IF_FAIL(player, false);
1263 if (player->attrs) {
1264 mm_attrs_free(player->attrs);
1265 player->attrs = NULL;