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,
735 /*===========================================================================================
737 | FUNCTION DEFINITIONS |
739 ========================================================================================== */
741 static bool __mmplayer_commit_enable_video_decoded_cb(MMHandleType handle, int attr_idx, const MMAttrsValue *value)
743 mmplayer_t *player = MM_PLAYER_CAST(handle);
744 mmplayer_gst_element_t *videobin = NULL;
747 MMPLAYER_RETURN_VAL_IF_FAIL(player && value, false);
749 if (!_mmplayer_is_videosink_ready(player, MM_DISPLAY_SURFACE_NUM)) {
750 LOGD("will be applied when videosink is ready");
754 if (!player->set_mode.video_export) {
755 LOGW("there is no callback for enabling");
759 videobin = player->pipeline->videobin;
761 LOGD("[update plugin][videosink] handoff %d", value->value.i_val);
763 g_object_set(videobin[MMPLAYER_V_SINK].gst,
764 "signal-handoffs", (value->value.i_val) ? TRUE : FALSE, NULL);
769 static bool __mmplayer_commit_gapless_mode(MMHandleType handle, int attr_idx, const MMAttrsValue *value)
771 mmplayer_t *player = MM_PLAYER_CAST(handle);
772 mmplayer_gst_element_t *videobin = NULL;
775 MMPLAYER_RETURN_VAL_IF_FAIL(player && value, false);
777 if (!_mmplayer_is_videosink_ready(player, MM_DISPLAY_SURFACE_NUM)) {
778 LOGD("will be applied when videosink is ready");
782 videobin = player->pipeline->videobin;
784 if (value->value.i_val > 0) {
785 LOGD("[update plugin][videosink] disable last sample for gapless");
786 g_object_set(videobin[MMPLAYER_V_SINK].gst, "enable-last-sample", FALSE, NULL);
792 static bool __mmplayer_commit_audio_pitch_value(MMHandleType handle, int attr_idx, const MMAttrsValue *value)
794 mmplayer_t *player = MM_PLAYER_CAST(handle);
795 mmplayer_pipeline_info_t *pipeline;
796 int pitch_control = 0;
799 MMPLAYER_RETURN_VAL_IF_FAIL(player && value, false);
800 MMPLAYER_RETURN_VAL_IF_FAIL(player->pipeline && player->pipeline->mainbin, true);
802 pipeline = player->pipeline;
803 mm_attrs_get_int_by_name(player->attrs, MM_PLAYER_PITCH_CONTROL, &pitch_control);
805 if (!pitch_control || !pipeline->audiobin[MMPLAYER_A_PITCH].gst) {
806 LOGW("audio pitch is disabled");
810 LOGD("[update plugin][pitch] value to %1.3f", value->value.d_val);
811 g_object_set(pipeline->audiobin[MMPLAYER_A_PITCH].gst, "pitch", (value->value.d_val), NULL);
816 static void __mmplayer_print_attrs(const char *attr_name, const MMAttrsValue * value, const char *prefix)
818 switch (value->type) {
819 case MM_ATTRS_TYPE_INT:
820 LOGD("[ %s : %s : %d ]", prefix, attr_name, value->value.i_val);
822 case MM_ATTRS_TYPE_DOUBLE:
823 LOGD("[ %s : %s : %f ]", prefix, attr_name, value->value.d_val);
825 case MM_ATTRS_TYPE_STRING:
826 LOGD("[ %s : %s : %s ]", prefix, attr_name, value->value.s_val);
828 case MM_ATTRS_TYPE_DATA:
829 LOGD("[ %s : %s : %p ]", prefix, attr_name, value->value.p_val);
838 bool _mmplayer_commit_attribute(int attr_idx, const char *attr_name, const MMAttrsValue *value, void *user_data)
841 mmplayer_t *player = MM_PLAYER_CAST(user_data);
843 MMPLAYER_RETURN_VAL_IF_FAIL(player && (attr_idx >= 0) && attr_name && value, false);
845 if (player_attrs[attr_idx].attr_commit) {
846 __mmplayer_print_attrs(attr_name, value, "Dynamic");
847 ret = player_attrs[attr_idx].attr_commit((MMHandleType)user_data, attr_idx, value);
849 __mmplayer_print_attrs(attr_name, value, "Static");
856 int _mmplayer_get_attribute(MMHandleType handle, char **err_attr_name, const char *attribute_name, va_list args_list)
858 int result = MM_ERROR_NONE;
859 MMHandleType attrs = NULL;
861 /* NOTE : Don't need to check err_attr_name because it can be set NULL */
862 /* if it's not want to know it. */
863 MMPLAYER_RETURN_VAL_IF_FAIL(attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
864 MMPLAYER_RETURN_VAL_IF_FAIL(handle, MM_ERROR_COMMON_INVALID_ARGUMENT);
866 attrs = MM_PLAYER_GET_ATTRS(handle);
868 result = mm_attrs_get_valist(attrs, err_attr_name, attribute_name, args_list);
870 if (result != MM_ERROR_NONE)
871 LOGE("failed to get %s attribute", attribute_name);
876 int __mmplayer_apply_attribute(MMHandleType handle, const char *attribute_name)
878 mmplayer_t *player = NULL;
881 MMPLAYER_RETURN_VAL_IF_FAIL(handle, MM_ERROR_COMMON_INVALID_ARGUMENT);
882 MMPLAYER_RETURN_VAL_IF_FAIL(attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
884 player = MM_PLAYER_CAST(handle);
886 /* apply display attr value to player handle */
887 if (!g_strrstr(attribute_name, "display"))
888 return MM_ERROR_NONE;
890 if (!_mmplayer_is_videosink_ready(player, MM_DISPLAY_SURFACE_NUM)) {
891 LOGD("will be applied when videosink is ready");
892 return MM_ERROR_NONE;
895 if (_mmplayer_update_video_overlay_param(player, attribute_name) != MM_ERROR_NONE) {
896 LOGW("not supported video param %s", attribute_name);
897 return MM_ERROR_NONE;
900 return MM_ERROR_NONE;
903 int _mmplayer_set_attribute(MMHandleType handle, char **err_attr_name, const char *attribute_name, va_list args_list)
905 int result = MM_ERROR_NONE;
906 MMHandleType attrs = NULL;
908 /* NOTE : Don't need to check err_attr_name because it can be set NULL */
909 /* if it's not want to know it. */
910 MMPLAYER_RETURN_VAL_IF_FAIL(attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
911 MMPLAYER_RETURN_VAL_IF_FAIL(handle, MM_ERROR_COMMON_INVALID_ARGUMENT);
913 attrs = MM_PLAYER_GET_ATTRS(handle);
915 /* set attributes and commit them */
916 result = mm_attrs_set_valist(attrs, err_attr_name, attribute_name, args_list);
917 if (result != MM_ERROR_NONE) {
918 LOGE("failed to set %s attribute", attribute_name);
922 /* Note: 'attr_commit' function is called before committing the new value to attr struct.
923 so if there is a value to apply after committing, it should be added below function. */
924 result = __mmplayer_apply_attribute(handle, attribute_name);
925 if (result != MM_ERROR_NONE) {
926 LOGE("failed to apply attributes");
930 return MM_ERROR_NONE;
933 int _mmplayer_get_attributes_info(MMHandleType handle, const char *attribute_name, mmplayer_attrs_info_t *dst_info)
935 int result = MM_ERROR_NONE;
936 MMHandleType attrs = NULL;
937 MMAttrsInfo src_info = {0, };
939 MMPLAYER_RETURN_VAL_IF_FAIL(attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
940 MMPLAYER_RETURN_VAL_IF_FAIL(dst_info, MM_ERROR_COMMON_INVALID_ARGUMENT);
941 MMPLAYER_RETURN_VAL_IF_FAIL(handle, MM_ERROR_COMMON_INVALID_ARGUMENT);
943 attrs = MM_PLAYER_GET_ATTRS(handle);
945 result = mm_attrs_get_info_by_name(attrs, attribute_name, &src_info);
947 if (result != MM_ERROR_NONE) {
948 LOGE("failed to get attribute info");
952 memset(dst_info, 0x00, sizeof(mmplayer_attrs_info_t));
954 dst_info->type = src_info.type;
955 dst_info->flag = src_info.flag;
956 dst_info->validity_type = src_info.validity_type;
958 switch (src_info.validity_type) {
959 case MM_ATTRS_VALID_TYPE_INT_ARRAY:
960 dst_info->int_array.array = src_info.int_array.array;
961 dst_info->int_array.count = src_info.int_array.count;
962 dst_info->int_array.d_val = src_info.int_array.dval;
965 case MM_ATTRS_VALID_TYPE_INT_RANGE:
966 dst_info->int_range.min = src_info.int_range.min;
967 dst_info->int_range.max = src_info.int_range.max;
968 dst_info->int_range.d_val = src_info.int_range.dval;
971 case MM_ATTRS_VALID_TYPE_DOUBLE_ARRAY:
972 dst_info->double_array.array = src_info.double_array.array;
973 dst_info->double_array.count = src_info.double_array.count;
974 dst_info->double_array.d_val = src_info.double_array.dval;
977 case MM_ATTRS_VALID_TYPE_DOUBLE_RANGE:
978 dst_info->double_range.min = src_info.double_range.min;
979 dst_info->double_range.max = src_info.double_range.max;
980 dst_info->double_range.d_val = src_info.double_range.dval;
990 MMHandleType _mmplayer_construct_attribute(MMHandleType handle)
992 int result = MM_ERROR_NONE;
994 MMHandleType attrs = NULL;
995 int num_of_attrs = 0;
996 MMAttrsConstructInfo *base = NULL;
998 MMPLAYER_RETURN_VAL_IF_FAIL(handle, 0);
1000 num_of_attrs = ARRAY_SIZE(player_attrs);
1002 base = g_try_new(MMAttrsConstructInfo, num_of_attrs);
1004 LOGE("failed to alloc attrs constructor");
1008 /* initialize values of attributes */
1009 for (idx = 0; idx < num_of_attrs; idx++) {
1010 base[idx].name = player_attrs[idx].name;
1011 base[idx].value_type = player_attrs[idx].value_type;
1012 base[idx].flags = player_attrs[idx].flags;
1013 base[idx].default_value = player_attrs[idx].default_value.value_void; /* FIXME: need to consider the double data type */
1016 result = mm_attrs_new(base, num_of_attrs, "mmplayer_attrs",
1017 _mmplayer_commit_attribute, (void *)handle, &attrs);
1020 MMPLAYER_FREEIF(base);
1023 LOGE("failed to create player attrs");
1027 /* set validity type and range */
1028 for (idx = 0; idx < num_of_attrs; idx++) {
1029 mm_attrs_set_valid_type(attrs, idx, player_attrs[idx].valid_type);
1030 switch (player_attrs[idx].valid_type) {
1031 case MM_ATTRS_VALID_TYPE_INT_RANGE:
1032 mm_attrs_set_valid_range(attrs, idx,
1033 player_attrs[idx].validity_value_1.int_min,
1034 player_attrs[idx].validity_value_2.int_max,
1035 player_attrs[idx].default_value.value_int);
1037 case MM_ATTRS_VALID_TYPE_INT_ARRAY:
1038 if (player_attrs[idx].validity_value_1.int_array &&
1039 player_attrs[idx].validity_value_2.count > 0)
1040 mm_attrs_set_valid_array(attrs, idx,
1041 (const int *)(player_attrs[idx].validity_value_1.int_array),
1042 player_attrs[idx].validity_value_2.count,
1043 player_attrs[idx].default_value.value_int);
1045 case MM_ATTRS_VALID_TYPE_DOUBLE_RANGE:
1046 mm_attrs_set_valid_double_range(attrs, idx,
1047 player_attrs[idx].validity_value_1.double_min,
1048 player_attrs[idx].validity_value_2.double_max,
1049 player_attrs[idx].default_value.value_double);
1051 case MM_ATTRS_VALID_TYPE_DOUBLE_ARRAY:
1052 LOGW("FIXME: need to set range value if required.");
1053 case MM_ATTRS_VALID_TYPE_NONE:
1054 case MM_ATTRS_VALID_TYPE_INVALID:
1061 if (mm_attrs_commit_all(attrs)) {
1062 LOGE("failed to update attributes");
1063 mm_attrs_free(attrs);
1070 bool _mmplayer_deconstruct_attribute(MMHandleType handle)
1072 mmplayer_t *player = MM_PLAYER_CAST(handle);
1074 MMPLAYER_RETURN_VAL_IF_FAIL(player, false);
1076 if (player->attrs) {
1077 mm_attrs_free(player->attrs);
1078 player->attrs = NULL;