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 ---------------------------------------------------------------------------*/
44 __mmplayer_apply_attribute(MMHandleType handle, const char *attribute_name);
46 /*===========================================================================================
48 | FUNCTION DEFINITIONS |
50 ========================================================================================== */
53 _mmplayer_get_attribute(MMHandleType handle, char **err_attr_name, const char *attribute_name, va_list args_list)
55 int result = MM_ERROR_NONE;
56 MMHandleType attrs = 0;
58 /* NOTE : Don't need to check err_attr_name because it can be set NULL */
59 /* if it's not want to know it. */
60 MMPLAYER_RETURN_VAL_IF_FAIL(attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
61 MMPLAYER_RETURN_VAL_IF_FAIL(handle, MM_ERROR_COMMON_INVALID_ARGUMENT);
63 attrs = MM_PLAYER_GET_ATTRS(handle);
65 result = mm_attrs_get_valist(attrs, err_attr_name, attribute_name, args_list);
67 if (result != MM_ERROR_NONE)
68 LOGE("failed to get %s attribute", attribute_name);
74 _mmplayer_set_attribute(MMHandleType handle, char **err_attr_name, const char *attribute_name, va_list args_list)
76 int result = MM_ERROR_NONE;
77 MMHandleType attrs = 0;
79 /* NOTE : Don't need to check err_attr_name because it can be set NULL */
80 /* if it's not want to know it. */
81 MMPLAYER_RETURN_VAL_IF_FAIL(attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
82 MMPLAYER_RETURN_VAL_IF_FAIL(handle, MM_ERROR_COMMON_INVALID_ARGUMENT);
84 attrs = MM_PLAYER_GET_ATTRS(handle);
86 /* set attributes and commit them */
87 result = mm_attrs_set_valist(attrs, err_attr_name, attribute_name, args_list);
89 if (result != MM_ERROR_NONE) {
90 LOGE("failed to set %s attribute", attribute_name);
94 result = __mmplayer_apply_attribute(handle, attribute_name);
95 if (result != MM_ERROR_NONE) {
96 LOGE("failed to apply attributes");
104 _mmplayer_get_attributes_info(MMHandleType handle, const char *attribute_name, mmplayer_attrs_info_t *dst_info)
106 int result = MM_ERROR_NONE;
107 MMHandleType attrs = 0;
108 MMAttrsInfo src_info = {0, };
110 MMPLAYER_RETURN_VAL_IF_FAIL(attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
111 MMPLAYER_RETURN_VAL_IF_FAIL(dst_info, MM_ERROR_COMMON_INVALID_ARGUMENT);
112 MMPLAYER_RETURN_VAL_IF_FAIL(handle, MM_ERROR_COMMON_INVALID_ARGUMENT);
114 attrs = MM_PLAYER_GET_ATTRS(handle);
116 result = mm_attrs_get_info_by_name(attrs, attribute_name, &src_info);
118 if (result != MM_ERROR_NONE) {
119 LOGE("failed to get attribute info");
123 memset(dst_info, 0x00, sizeof(mmplayer_attrs_info_t));
125 dst_info->type = src_info.type;
126 dst_info->flag = src_info.flag;
127 dst_info->validity_type = src_info.validity_type;
129 switch (src_info.validity_type) {
130 case MM_ATTRS_VALID_TYPE_INT_ARRAY:
131 dst_info->int_array.array = src_info.int_array.array;
132 dst_info->int_array.count = src_info.int_array.count;
133 dst_info->int_array.d_val = src_info.int_array.dval;
136 case MM_ATTRS_VALID_TYPE_INT_RANGE:
137 dst_info->int_range.min = src_info.int_range.min;
138 dst_info->int_range.max = src_info.int_range.max;
139 dst_info->int_range.d_val = src_info.int_range.dval;
142 case MM_ATTRS_VALID_TYPE_DOUBLE_ARRAY:
143 dst_info->double_array.array = src_info.double_array.array;
144 dst_info->double_array.count = src_info.double_array.count;
145 dst_info->double_array.d_val = src_info.double_array.dval;
148 case MM_ATTRS_VALID_TYPE_DOUBLE_RANGE:
149 dst_info->double_range.min = src_info.double_range.min;
150 dst_info->double_range.max = src_info.double_range.max;
151 dst_info->double_range.d_val = src_info.double_range.dval;
162 __mmplayer_apply_attribute(MMHandleType handle, const char *attribute_name)
164 mmplayer_t *player = 0;
166 MMPLAYER_RETURN_VAL_IF_FAIL(handle, MM_ERROR_COMMON_INVALID_ARGUMENT);
167 MMPLAYER_RETURN_VAL_IF_FAIL(attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
169 player = MM_PLAYER_CAST(handle);
170 mmplayer_pipeline_info_t *pipeline = player->pipeline;
172 /* before preparing, just keep the attr value */
173 MMPLAYER_RETURN_VAL_IF_FAIL(pipeline && pipeline->mainbin, MM_ERROR_NONE);
175 if (g_strrstr(attribute_name, MM_PLAYER_PITCH_VALUE)) {
176 int pitch_control = 0;
177 double pitch_value = 0;
179 mm_attrs_multiple_get(player->attrs, NULL,
180 MM_PLAYER_PITCH_CONTROL, &pitch_control,
181 MM_PLAYER_PITCH_VALUE, &pitch_value,
184 if (!pitch_control || !pipeline->audiobin[MMPLAYER_A_PITCH].gst)
185 return MM_ERROR_PLAYER_NO_OP;
187 LOGD("set pitch value to %1.3f", pitch_value);
188 g_object_set(pipeline->audiobin[MMPLAYER_A_PITCH].gst, "pitch", (gdouble)pitch_value, NULL);
191 /* Currently, there are only display related implementation at below */
192 if (!pipeline->videobin ||
193 !pipeline->videobin[MMPLAYER_V_SINK].gst) {
195 * The attribute should be committed even though videobin is not created yet.
196 * So, true should be returned here.
197 * Otherwise, video can be diaplayed abnormal.
199 return MM_ERROR_NONE;
202 if (g_strrstr(attribute_name, "display")) {
203 char *param_name = NULL;
204 int str_len = strlen(attribute_name);
205 param_name = g_malloc0(str_len + 1);
207 LOGE("failed to alloc param_name");
208 return MM_ERROR_PLAYER_INTERNAL;
210 strncpy(param_name, attribute_name, str_len);
211 param_name[str_len] = '\0';
212 LOGD(" param_name: %s", param_name);
213 if (MM_ERROR_NONE != _mmplayer_update_video_param(player, param_name)) {
214 MMPLAYER_FREEIF(param_name);
215 LOGE("failed to update video param");
216 return MM_ERROR_PLAYER_INTERNAL;
218 MMPLAYER_FREEIF(param_name);
221 if (g_strrstr(attribute_name, MM_PLAYER_GAPLESS_MODE)) {
224 mm_attrs_get_int_by_name(player->attrs, "gapless_mode", &gapless);
226 LOGD("disable last-sample at videosink");
227 g_object_set(player->pipeline->videobin[MMPLAYER_V_SINK].gst, "enable-last-sample", FALSE, NULL);
231 if (g_strrstr(attribute_name, MM_PLAYER_ENABLE_VIDEO_DECODED_CB)) {
232 if (!player->set_mode.video_export) {
233 LOGE("there is no callback to export video");
234 return MM_ERROR_PLAYER_INTERNAL;
237 mm_attrs_get_int_by_name(player->attrs, "enable_video_decoded_cb", &enable);
238 g_object_set(player->pipeline->videobin[MMPLAYER_V_SINK].gst, "signal-handoffs", enable ? TRUE : FALSE, NULL);
241 return MM_ERROR_NONE;
245 _mmplayer_construct_attribute(MMHandleType handle)
247 int result = MM_ERROR_NONE;
249 MMHandleType attrs = 0;
250 int num_of_attrs = 0;
251 MMAttrsConstructInfo *base = NULL;
253 MMPLAYER_RETURN_VAL_IF_FAIL(handle, 0);
255 mmplayer_attrs_spec_t player_attrs[] = {
257 "profile_uri", // name
258 MM_ATTRS_TYPE_STRING, // type
259 MM_ATTRS_FLAG_RW, // flag
260 (void *)NULL, // default value
261 MM_ATTRS_VALID_TYPE_NONE, // validity type
262 0, // validity min value
263 0 // validity max value
266 "profile_user_param",
270 MM_ATTRS_VALID_TYPE_NONE,
275 "profile_play_count",
278 (void *)1, /* -1 : repeat continually */
279 MM_ATTRS_VALID_TYPE_INT_RANGE,
284 "profile_prepare_async",
288 MM_ATTRS_VALID_TYPE_INT_RANGE,
293 "streaming_user_agent",
294 MM_ATTRS_TYPE_STRING,
297 MM_ATTRS_VALID_TYPE_NONE,
303 MM_ATTRS_TYPE_STRING,
306 MM_ATTRS_VALID_TYPE_NONE,
312 MM_ATTRS_TYPE_STRING,
315 MM_ATTRS_VALID_TYPE_NONE,
324 MM_ATTRS_VALID_TYPE_INT_RANGE,
329 "content_max_bitrate",
333 MM_ATTRS_VALID_TYPE_INT_RANGE,
338 "content_video_found",
342 MM_ATTRS_VALID_TYPE_INT_RANGE,
347 "content_video_codec",
348 MM_ATTRS_TYPE_STRING,
351 MM_ATTRS_VALID_TYPE_NONE,
356 "content_video_bitrate",
360 MM_ATTRS_VALID_TYPE_INT_RANGE,
369 MM_ATTRS_VALID_TYPE_INT_RANGE,
374 "content_video_width",
378 MM_ATTRS_VALID_TYPE_INT_RANGE,
383 "content_video_height",
387 MM_ATTRS_VALID_TYPE_INT_RANGE,
392 "content_audio_codec",
393 MM_ATTRS_TYPE_STRING,
396 MM_ATTRS_VALID_TYPE_NONE,
401 "content_audio_bitrate",
405 MM_ATTRS_VALID_TYPE_INT_RANGE,
410 "content_audio_channels",
414 MM_ATTRS_VALID_TYPE_INT_RANGE,
419 "content_audio_samplerate",
423 MM_ATTRS_VALID_TYPE_INT_RANGE,
428 "content_audio_format",
429 MM_ATTRS_TYPE_STRING,
432 MM_ATTRS_VALID_TYPE_NONE,
437 "content_text_track_num",
441 MM_ATTRS_VALID_TYPE_INT_RANGE,
446 "current_text_track_index",
450 MM_ATTRS_VALID_TYPE_INT_RANGE,
456 MM_ATTRS_TYPE_STRING,
459 MM_ATTRS_VALID_TYPE_NONE,
465 MM_ATTRS_TYPE_STRING,
468 MM_ATTRS_VALID_TYPE_NONE,
474 MM_ATTRS_TYPE_STRING,
480 MM_ATTRS_TYPE_STRING,
483 MM_ATTRS_VALID_TYPE_NONE,
489 MM_ATTRS_TYPE_STRING,
492 MM_ATTRS_VALID_TYPE_NONE,
498 MM_ATTRS_TYPE_STRING,
501 MM_ATTRS_VALID_TYPE_NONE,
507 MM_ATTRS_TYPE_STRING,
510 MM_ATTRS_VALID_TYPE_NONE,
516 MM_ATTRS_TYPE_STRING,
519 MM_ATTRS_VALID_TYPE_NONE,
528 MM_ATTRS_VALID_TYPE_INT_RANGE,
537 MM_ATTRS_VALID_TYPE_NONE,
545 (void *)MM_DISPLAY_ROTATION_NONE,
546 MM_ATTRS_VALID_TYPE_INT_RANGE,
547 MM_DISPLAY_ROTATION_NONE,
548 MM_DISPLAY_ROTATION_270
555 MM_ATTRS_VALID_TYPE_INT_RANGE,
563 (void *)MM_DISPLAY_METHOD_LETTER_BOX,
564 MM_ATTRS_VALID_TYPE_INT_RANGE,
565 MM_DISPLAY_METHOD_LETTER_BOX,
566 MM_DISPLAY_METHOD_CUSTOM_ROI
573 MM_ATTRS_VALID_TYPE_NONE,
582 MM_ATTRS_VALID_TYPE_INT_RANGE,
591 MM_ATTRS_VALID_TYPE_INT_RANGE,
596 "display_win_roi_width",
600 MM_ATTRS_VALID_TYPE_INT_RANGE,
605 "display_win_roi_height",
609 MM_ATTRS_VALID_TYPE_INT_RANGE,
614 "display_surface_type",
617 (void *)MM_DISPLAY_SURFACE_NULL,
618 MM_ATTRS_VALID_TYPE_INT_RANGE,
619 MM_DISPLAY_SURFACE_OVERLAY,
620 MM_DISPLAY_SURFACE_NUM - 1
624 MM_ATTRS_TYPE_STRING,
627 MM_ATTRS_VALID_TYPE_NONE,
632 "sound_stream_index",
636 MM_ATTRS_VALID_TYPE_INT_RANGE,
641 "sound_latency_mode",
644 (void *)1, // 0: low latency, 1: middle latency 2: high latency
645 MM_ATTRS_VALID_TYPE_INT_RANGE,
650 "pcm_extraction_samplerate", // set samplerate for pcm extraction
654 MM_ATTRS_VALID_TYPE_INT_RANGE,
659 "pcm_extraction_channels", // set channels for pcm extraction
663 MM_ATTRS_VALID_TYPE_INT_RANGE,
672 MM_ATTRS_VALID_TYPE_INT_RANGE,
677 "content_video_orientation", // orientation of video content
678 MM_ATTRS_TYPE_STRING,
681 MM_ATTRS_VALID_TYPE_NONE,
687 MM_ATTRS_TYPE_STRING,
690 MM_ATTRS_VALID_TYPE_NONE,
699 MM_ATTRS_VALID_TYPE_INT_RANGE,
708 MM_ATTRS_VALID_TYPE_INT_RANGE,
713 "enable_video_decoded_cb",
717 MM_ATTRS_VALID_TYPE_INT_RANGE,
722 "content_video_is_spherical",
726 MM_ATTRS_VALID_TYPE_INT_RANGE,
734 (void *)MM_PLAYER_CODEC_TYPE_DEFAULT,
735 MM_ATTRS_VALID_TYPE_INT_RANGE,
736 MM_PLAYER_CODEC_TYPE_DEFAULT,
737 MM_PLAYER_CODEC_TYPE_SW
743 (void *)MM_PLAYER_CODEC_TYPE_DEFAULT,
744 MM_ATTRS_VALID_TYPE_INT_RANGE,
745 MM_PLAYER_CODEC_TYPE_DEFAULT,
746 MM_PLAYER_CODEC_TYPE_SW
749 "video_buffer_total_size",
752 (void *)DEFAULT_NUM_OF_V_OUT_BUFFER,
753 MM_ATTRS_VALID_TYPE_INT_RANGE,
758 "video_buffer_extra_size",
761 (void *)DEFAULT_NUM_OF_V_OUT_BUFFER,
762 MM_ATTRS_VALID_TYPE_INT_RANGE,
767 "prebuffer_ms", /* user setting */
770 (void *) MIN_BUFFERING_TIME,
771 MM_ATTRS_VALID_TYPE_INT_RANGE,
776 "rebuffer_ms", /* user setting */
779 (void *) MIN_BUFFERING_TIME,
780 MM_ATTRS_VALID_TYPE_INT_RANGE,
785 "audio_offload", /* MM_PLAYER_AUDIO_OFFLOAD */
789 MM_ATTRS_VALID_TYPE_INT_RANGE,
794 "pitch_control", /* MM_PLAYER_PITCH_CONTROL */
798 MM_ATTRS_VALID_TYPE_INT_RANGE,
803 "pitch_value", /* MM_PLAYER_PITCH_VALUE */
804 MM_ATTRS_TYPE_DOUBLE,
807 MM_ATTRS_VALID_TYPE_DOUBLE_RANGE,
813 num_of_attrs = ARRAY_SIZE(player_attrs);
815 base = g_try_new(MMAttrsConstructInfo, num_of_attrs);
817 LOGE("failed to alloc attrs constructor");
821 /* initialize values of attributes */
822 for (idx = 0; idx < num_of_attrs; idx++) {
823 base[idx].name = player_attrs[idx].name;
824 base[idx].value_type = player_attrs[idx].value_type;
825 base[idx].flags = player_attrs[idx].flags;
826 base[idx].default_value = player_attrs[idx].default_value;
829 result = mm_attrs_new(base, num_of_attrs, "mmplayer_attrs",
833 MMPLAYER_FREEIF(base);
836 LOGE("failed to create player attrs");
840 /* set validity type and range */
841 for (idx = 0; idx < num_of_attrs; idx++) {
842 switch (player_attrs[idx].valid_type) {
843 case MM_ATTRS_VALID_TYPE_INT_RANGE:
845 mm_attrs_set_valid_type(attrs, idx, MM_ATTRS_VALID_TYPE_INT_RANGE);
846 mm_attrs_set_valid_range(attrs, idx,
847 player_attrs[idx].value_min,
848 player_attrs[idx].value_max,
849 (int)(intptr_t)(player_attrs[idx].default_value));
853 case MM_ATTRS_VALID_TYPE_INT_ARRAY:
854 case MM_ATTRS_VALID_TYPE_DOUBLE_ARRAY:
855 case MM_ATTRS_VALID_TYPE_DOUBLE_RANGE:
862 if (mm_attrs_commit_all(attrs)) {
863 LOGE("failed to update attributes");
864 mm_attrs_free(attrs);
872 _mmplayer_deconstruct_attribute(MMHandleType handle) // @
874 mmplayer_t *player = MM_PLAYER_CAST(handle);
876 MMPLAYER_RETURN_VAL_IF_FAIL(player, FALSE);
879 mm_attrs_free(player->attrs);