4 * Copyright(c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: JongHyuk Choi <jhchoi.choi@samsung.com>, heechul jeon <heechul.jeon@samsung.co>,
7 * YoungHwan An <younghwan_.an@samsung.com>, Eunhae Choi <eunhae1.choi@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 ========================================================================================== */
29 #include "mm_player_es.h"
30 #include "mm_player_utils.h"
31 #include "mm_player_internal.h"
33 #include <gst/app/gstappsrc.h>
35 /*---------------------------------------------------------------------------
36 | LOCAL VARIABLE DEFINITIONS for internal |
37 ---------------------------------------------------------------------------*/
38 #define DEFAULT_FRAMERATE_NUM 30
39 #define DEFAULT_FRAMERATE_DEN 1
40 #define DEFAULT_VIDEO_FRAME_DURATION 33 /* ms */
41 #define PLAYER_DATA_PUSH_WAIT_COUNT 10
42 #define PLAYER_STATE_CHECK_INTERVAL (100*1000)
44 /*---------------------------------------------------------------------------
45 | LOCAL FUNCTION PROTOTYPES: |
46 ---------------------------------------------------------------------------*/
47 static int __parse_media_format(MMPlayerVideoStreamInfo * video, MMPlayerAudioStreamInfo * audio, media_format_h format);
48 static int __convert_media_format_video_mime_to_str(MMPlayerVideoStreamInfo * video, media_format_mimetype_e mime);
49 static int __convert_media_format_audio_mime_to_str(MMPlayerAudioStreamInfo * audio, media_format_mimetype_e mime);
51 /*===========================================================================================
53 | FUNCTION DEFINITIONS |
55 ========================================================================================== */
58 __convert_media_format_video_mime_to_str(MMPlayerVideoStreamInfo * video,
59 media_format_mimetype_e mime)
61 MMPLAYER_RETURN_VAL_IF_FAIL(video, MM_ERROR_INVALID_ARGUMENT);
64 case MEDIA_FORMAT_MPEG4_SP:
65 video->mime = g_strdup("video/mpeg");
68 case MEDIA_FORMAT_H264_SP:
69 case MEDIA_FORMAT_H264_MP:
70 case MEDIA_FORMAT_H264_HP:
71 video->mime = g_strdup("video/x-h264");
74 video->mime = g_strdup("unknown");
82 __convert_media_format_audio_mime_to_str(MMPlayerAudioStreamInfo * audio,
83 media_format_mimetype_e mime)
85 MMPLAYER_RETURN_VAL_IF_FAIL(audio, MM_ERROR_INVALID_ARGUMENT);
88 case MEDIA_FORMAT_AAC:
89 audio->mime = g_strdup("audio/mpeg");
93 audio->mime = g_strdup("unknown");
101 __parse_media_format(MMPlayerVideoStreamInfo * video,
102 MMPlayerAudioStreamInfo * audio, media_format_h format)
105 media_format_mimetype_e mime;
110 if (media_format_get_audio_info(format, &mime, &channel, &samplerate, NULL,
111 &avg_bps) != MEDIA_FORMAT_ERROR_NONE) {
112 LOGE("media_format_get_audio_info failed");
113 return MM_ERROR_PLAYER_INTERNAL;
116 __convert_media_format_audio_mime_to_str(audio, mime);
117 audio->sample_rate = samplerate;
118 audio->channels = channel;
119 //video->user_info = ;
123 media_format_mimetype_e mime;
129 if (media_format_get_video_info(format, &mime, &width, &height, &avg_bps,
130 NULL) != MEDIA_FORMAT_ERROR_NONE) {
131 LOGE("media_format_get_video_info failed");
132 return MM_ERROR_PLAYER_INTERNAL;
135 if (media_format_get_video_frame_rate(format, &frame_rate))
136 LOGW("failed to get video frame rate, will be set 30.");
138 LOGD("frame_rate %d", frame_rate);
140 __convert_media_format_video_mime_to_str(video, mime);
142 video->width = width;
143 video->height = height;
144 video->framerate_num = (frame_rate > 0) ? (frame_rate) : (DEFAULT_FRAMERATE_NUM);
145 video->framerate_den = DEFAULT_FRAMERATE_DEN;
148 return MM_ERROR_NONE;
152 __mmplayer_update_video_info(MMHandleType hplayer, media_format_h fmt)
154 mm_player_t *player = (mm_player_t *) hplayer;
155 gboolean ret = FALSE;
156 GstStructure *str = NULL;
157 media_format_mimetype_e mimetype = 0;
158 gint cur_width = 0, width = 0;
159 gint cur_height = 0, height = 0;
163 MMPLAYER_RETURN_VAL_IF_FAIL(player && player->v_stream_caps, FALSE);
164 MMPLAYER_RETURN_VAL_IF_FAIL(fmt, FALSE);
166 if (MMPLAYER_CURRENT_STATE(player) != MM_PLAYER_STATE_PAUSED &&
167 MMPLAYER_CURRENT_STATE(player) != MM_PLAYER_STATE_PLAYING) {
168 LOGW("skip update video info, state: %s", MMPLAYER_STATE_GET_NAME(MMPLAYER_CURRENT_STATE(player)));
172 str = gst_caps_get_structure(player->v_stream_caps, 0);
174 LOGE("failed to get caps info");
178 if (!gst_structure_get_int(str, "width", &cur_width))
179 LOGD("missing 'width' field in video caps");
181 if (!gst_structure_get_int(str, "height", &cur_height))
182 LOGD("missing 'height' field in video caps");
184 media_format_get_video_info(fmt, &mimetype, &width, &height, NULL, NULL);
185 if ((cur_width != width) || (cur_height != height)) {
186 LOGW("resolution is changed %dx%d -> %dx%d",
187 cur_width, cur_height, width, height);
188 _mmplayer_set_video_info(hplayer, fmt);
198 _mmplayer_set_media_stream_buffer_status_cb(MMHandleType hplayer,
199 MMPlayerStreamType type,
200 mm_player_media_stream_buffer_status_callback callback,
203 mm_player_t *player = (mm_player_t *) hplayer;
207 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
209 MMPLAYER_MEDIA_STREAM_CALLBACK_LOCK(player);
211 if (player->media_stream_buffer_status_cb[type]) {
213 LOGD("[type:%s] will be clear", MMPLAYER_STREAM_TYPE_GET_NAME(type));
215 LOGD("[type:%s] will be overwritten", MMPLAYER_STREAM_TYPE_GET_NAME(type));
218 player->media_stream_buffer_status_cb[type] = callback;
219 player->buffer_cb_user_param[type] = user_param;
221 LOGD("player handle %p, type %s, callback %p",
222 player, MMPLAYER_STREAM_TYPE_GET_NAME(type), player->media_stream_buffer_status_cb[type]);
223 MMPLAYER_MEDIA_STREAM_CALLBACK_UNLOCK(player);
227 return MM_ERROR_NONE;
231 _mmplayer_set_media_stream_seek_data_cb(MMHandleType hplayer,
232 MMPlayerStreamType type,
233 mm_player_media_stream_seek_data_callback callback,
236 mm_player_t *player = (mm_player_t *) hplayer;
240 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
242 MMPLAYER_MEDIA_STREAM_CALLBACK_LOCK(player);
244 if (player->media_stream_seek_data_cb[type]) {
246 LOGD("[type:%s] will be clear", MMPLAYER_STREAM_TYPE_GET_NAME(type));
248 LOGD("[type:%s] will be overwritten", MMPLAYER_STREAM_TYPE_GET_NAME(type));
251 player->media_stream_seek_data_cb[type] = callback;
252 player->seek_cb_user_param[type] = user_param;
254 LOGD("player handle %p, type %s, callback %p",
255 player, MMPLAYER_STREAM_TYPE_GET_NAME(type), player->media_stream_seek_data_cb[type]);
256 MMPLAYER_MEDIA_STREAM_CALLBACK_UNLOCK(player);
260 return MM_ERROR_NONE;
264 __mmplayer_get_source_element(mm_player_t *player, MMPlayerStreamType type)
266 enum MainElementID elemId = MMPLAYER_M_NUM;
268 if (player && player->pipeline && player->pipeline->mainbin) {
269 /* get elem according to the stream type */
270 if (type == MM_PLAYER_STREAM_TYPE_AUDIO) {
271 if (player->pipeline->mainbin[MMPLAYER_M_2ND_SRC].gst)
272 elemId = MMPLAYER_M_2ND_SRC;
273 else if (g_strrstr(GST_ELEMENT_NAME(player->pipeline->mainbin[MMPLAYER_M_SRC].gst), "audio_appsrc"))
274 elemId = MMPLAYER_M_SRC;
275 } else if (type == MM_PLAYER_STREAM_TYPE_VIDEO) {
276 elemId = MMPLAYER_M_SRC;
277 } else if (type == MM_PLAYER_STREAM_TYPE_TEXT) {
278 elemId = MMPLAYER_M_SUBSRC;
281 if (elemId != MMPLAYER_M_NUM)
282 return player->pipeline->mainbin[elemId].gst;
289 _mmplayer_set_media_stream_max_size(MMHandleType hplayer, MMPlayerStreamType type, guint64 max_size)
291 mm_player_t *player = (mm_player_t *) hplayer;
292 GstElement *element = NULL;
295 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
297 if ((type < MM_PLAYER_STREAM_TYPE_AUDIO) ||
298 (type > MM_PLAYER_STREAM_TYPE_TEXT) ||
300 LOGE("Invalid param type:%d, max_size:%"G_GUINT64_FORMAT, type, max_size);
301 return MM_ERROR_INVALID_ARGUMENT;
304 LOGD("type:%s, max_size %"G_GUINT64_FORMAT, MMPLAYER_STREAM_TYPE_GET_NAME(type), max_size);
306 if ((element = __mmplayer_get_source_element(player, type))) {
307 LOGD("update max_size of %s", GST_ELEMENT_NAME(element));
308 g_object_set(G_OBJECT(element), "max-bytes", max_size, NULL);
311 player->media_stream_buffer_max_size[type] = max_size;
314 return MM_ERROR_NONE;
318 _mmplayer_get_media_stream_max_size(MMHandleType hplayer, MMPlayerStreamType type, guint64 *max_size)
320 mm_player_t *player = (mm_player_t *) hplayer;
324 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
325 MMPLAYER_RETURN_VAL_IF_FAIL(max_size, MM_ERROR_INVALID_ARGUMENT);
327 *max_size = player->media_stream_buffer_max_size[type];
331 return MM_ERROR_NONE;
335 _mmplayer_set_media_stream_min_percent(MMHandleType hplayer, MMPlayerStreamType type, guint min_percent)
337 mm_player_t *player = (mm_player_t *) hplayer;
338 GstElement *element = NULL;
342 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
344 if ((type < MM_PLAYER_STREAM_TYPE_AUDIO) || (type > MM_PLAYER_STREAM_TYPE_TEXT)) {
345 LOGE("Invalid param type:%d", type);
346 return MM_ERROR_INVALID_ARGUMENT;
349 LOGD("type:%s, min_per %u", MMPLAYER_STREAM_TYPE_GET_NAME(type), min_percent);
351 if ((element = __mmplayer_get_source_element(player, type))) {
352 LOGD("update min_per of %s", GST_ELEMENT_NAME(element));
353 g_object_set(G_OBJECT(element), "min-percent", min_percent, NULL);
356 player->media_stream_buffer_min_percent[type] = min_percent;
359 return MM_ERROR_NONE;
363 _mmplayer_get_media_stream_min_percent(MMHandleType hplayer, MMPlayerStreamType type, guint *min_percent)
365 mm_player_t *player = (mm_player_t *) hplayer;
369 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
370 MMPLAYER_RETURN_VAL_IF_FAIL(min_percent, MM_ERROR_INVALID_ARGUMENT);
372 *min_percent = player->media_stream_buffer_min_percent[type];
376 return MM_ERROR_NONE;
380 __mmplayer_check_buffer_level(mm_player_t *player, GstElement* element, MMPlayerStreamType type)
382 guint64 current_level_bytes = 0;
383 guint64 max_bytes = 0;
384 guint current_level_per = 0;
387 MMPLAYER_RETURN_VAL_IF_FAIL(player && element, MM_ERROR_PLAYER_NOT_INITIALIZED);
389 if (player->media_stream_buffer_max_size[type] > 0)
390 max_bytes = player->media_stream_buffer_max_size[type];
392 g_object_get(G_OBJECT(element), "max-bytes", &max_bytes, NULL);
394 if (max_bytes == 0) {
395 LOGW("buffer max size is zero");
396 return MM_ERROR_NONE;
399 g_object_get(G_OBJECT(element), "current-level-bytes", ¤t_level_bytes, NULL);
401 if (max_bytes <= current_level_bytes) {
402 LOGE("no available buffer space, type: %s, max %"G_GUINT64_FORMAT", curr %"G_GUINT64_FORMAT,
403 MMPLAYER_STREAM_TYPE_GET_NAME(type), max_bytes, current_level_bytes);
404 return MM_ERROR_PLAYER_BUFFER_SPACE;
407 if (MMPLAYER_CURRENT_STATE(player) != MM_PLAYER_STATE_PLAYING) {
408 MMPLAYER_MEDIA_STREAM_CALLBACK_LOCK(player);
409 if (!player->media_stream_buffer_status_cb[type]) {
410 MMPLAYER_MEDIA_STREAM_CALLBACK_UNLOCK(player);
411 return MM_ERROR_NONE;
414 current_level_per = (guint)(gst_util_guint64_to_gdouble(current_level_bytes)/gst_util_guint64_to_gdouble(max_bytes)*100);
416 LOGD("type: %s, min_per %u, curr_per %u max %"G_GUINT64_FORMAT" cur %"G_GUINT64_FORMAT,
417 MMPLAYER_STREAM_TYPE_GET_NAME(type), player->media_stream_buffer_min_percent[type],
419 player->media_stream_buffer_max_size[type],
420 current_level_bytes);
422 if (current_level_per < player->media_stream_buffer_min_percent[type])
423 player->media_stream_buffer_status_cb[type](type, MM_PLAYER_MEDIA_STREAM_BUFFER_UNDERRUN, current_level_bytes, player->buffer_cb_user_param[type]);
425 MMPLAYER_MEDIA_STREAM_CALLBACK_UNLOCK(player);
429 return MM_ERROR_NONE;
433 _mmplayer_submit_packet(MMHandleType hplayer, media_packet_h packet)
435 int ret = MM_ERROR_NONE;
436 GstBuffer *_buffer = NULL;
437 mm_player_t *player = (mm_player_t *) hplayer;
440 GstElement* element = NULL;
441 MMPlayerStreamType streamtype = MM_PLAYER_STREAM_TYPE_AUDIO;
442 media_format_h fmt = NULL;
446 MMPLAYER_RETURN_VAL_IF_FAIL(packet, MM_ERROR_INVALID_ARGUMENT);
447 MMPLAYER_RETURN_VAL_IF_FAIL(player &&
449 player->pipeline->mainbin &&
450 player->pipeline->mainbin[MMPLAYER_M_SRC].gst,
451 MM_ERROR_PLAYER_NOT_INITIALIZED);
453 /* get stream type if audio or video */
454 media_packet_is_audio(packet, &flag);
456 streamtype = MM_PLAYER_STREAM_TYPE_AUDIO;
458 media_packet_is_video(packet, &flag);
460 streamtype = MM_PLAYER_STREAM_TYPE_VIDEO;
462 streamtype = MM_PLAYER_STREAM_TYPE_TEXT;
465 element = __mmplayer_get_source_element(player, streamtype);
467 LOGE("there is no source element of type %d", streamtype);
468 ret = MM_ERROR_PLAYER_INTERNAL;
472 /* check buffer level */
473 ret = __mmplayer_check_buffer_level(player, element, streamtype);
474 if (ret != MM_ERROR_NONE)
478 if (media_packet_get_buffer_data_ptr(packet, (void **) &buf) != MEDIA_PACKET_ERROR_NONE) {
479 LOGE("failed to get buffer data ptr");
480 ret = MM_ERROR_PLAYER_INTERNAL;
484 if (media_packet_get_buffer_size(packet, &size) != MEDIA_PACKET_ERROR_NONE) {
485 LOGE("failed to get buffer size");
486 ret = MM_ERROR_PLAYER_INTERNAL;
490 if (buf != NULL && size > 0) {
491 GstMapInfo buff_info = GST_MAP_INFO_INIT;
493 uint64_t duration = 0;
497 _buffer = gst_buffer_new_and_alloc(size);
500 LOGE("failed to allocate memory for push buffer\n");
501 ret = MM_ERROR_PLAYER_NO_FREE_SPACE;
505 if (gst_buffer_map(_buffer, &buff_info, GST_MAP_READWRITE)) {
506 memcpy(buff_info.data, buf, size);
507 buff_info.size = size;
509 gst_buffer_unmap(_buffer, &buff_info);
512 /* wait till the pipeline is ready to get data, if not some data is missed */
513 while ((GST_STATE(element) < GST_STATE_PAUSED) && (wait_cnt < PLAYER_DATA_PUSH_WAIT_COUNT)) {
514 LOGW("wait to update source state : %d, %d", player->state, GST_STATE(element));
515 usleep(PLAYER_STATE_CHECK_INTERVAL);
519 if (wait_cnt == PLAYER_DATA_PUSH_WAIT_COUNT) {
520 LOGE("source is not ready %d", GST_STATE(element));
521 ret = MM_ERROR_PLAYER_INTERNAL;
525 if (streamtype == MM_PLAYER_STREAM_TYPE_VIDEO) {
526 /* get format to check video format */
527 media_packet_get_format(packet, &fmt);
529 if (__mmplayer_update_video_info(hplayer, fmt)) {
530 LOGD("update video caps");
531 g_object_set(G_OBJECT(player->pipeline->mainbin[MMPLAYER_M_SRC].gst),
532 "caps", player->v_stream_caps, NULL);
534 media_format_unref(fmt);
538 if (media_packet_get_duration(packet, &duration) != MEDIA_PACKET_ERROR_NONE) {
539 LOGW("failed to get duration info");
540 /* keep push without error handling */
544 duration = DEFAULT_VIDEO_FRAME_DURATION * GST_MSECOND;
546 GST_BUFFER_DURATION(_buffer) = (GstClockTime)duration;
550 if (media_packet_get_pts(packet, &pts) != MEDIA_PACKET_ERROR_NONE) {
551 LOGE("failed to get pts info");
552 ret = MM_ERROR_PLAYER_INTERNAL;
555 GST_BUFFER_PTS(_buffer) = (GstClockTime)pts;
557 if (MMPLAYER_CURRENT_STATE(player) != MM_PLAYER_STATE_PLAYING) {
558 /* the pushed pts should be lager than current position if it is not in playing state. */
559 LOGD("type:%s, curr pos: %"G_GINT64_FORMAT", pushed pts:%"G_GINT64_FORMAT", size:%"G_GUINT64_FORMAT,
560 MMPLAYER_STREAM_TYPE_GET_NAME(streamtype), player->last_position, (GstClockTime)pts, (guint64)size);
563 gst_app_src_push_buffer(GST_APP_SRC(element), _buffer);
565 LOGW("There is no data to push : buf %p, size %"G_GUINT64_FORMAT, buf, (guint64)size);
569 if (media_packet_is_end_of_stream(packet, &is_eos) != MEDIA_PACKET_ERROR_NONE) {
570 LOGE("failed to get eos info");
571 return MM_ERROR_PLAYER_INTERNAL;
575 LOGW("we got eos of stream type(%s)", MMPLAYER_STREAM_TYPE_GET_NAME(streamtype));
576 g_signal_emit_by_name(element, "end-of-stream", &ret);
582 gst_buffer_unref(_buffer);
587 __mmplayer_video_caps_new(MMHandleType hplayer, MMPlayerVideoStreamInfo * video,
588 const char *fieldname, ...)
591 GstCaps *caps = NULL;
592 GstStructure *structure = NULL;
594 mm_player_t *player = MM_PLAYER_CAST(hplayer);
597 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
598 MMPLAYER_RETURN_VAL_IF_FAIL(video, MM_ERROR_PLAYER_NOT_INITIALIZED);
600 LOGD("width=%d height=%d framerate num=%d, den=%d",
601 video->width, video->height, video->framerate_num, video->framerate_den);
603 caps = gst_caps_new_simple(video->mime,
604 "width", G_TYPE_INT, video->width,
605 "height", G_TYPE_INT, video->height,
606 "framerate", GST_TYPE_FRACTION, video->framerate_num, video->framerate_den, NULL);
608 for (cap_size = 0; cap_size < gst_caps_get_size(caps); cap_size++) {
609 va_start(var_args, fieldname);
610 structure = gst_caps_get_structure(caps, cap_size);
611 gst_structure_set_valist(structure, fieldname, var_args);
615 if (video->extradata_size) {
616 GstBuffer *buf = NULL;
617 GstMapInfo buff_info = GST_MAP_INFO_INIT;
619 buf = gst_buffer_new_and_alloc(video->extradata_size);
621 if (gst_buffer_map(buf, &buff_info, GST_MAP_READ)) {
622 memcpy(buff_info.data, video->codec_extradata, video->extradata_size);
623 buff_info.size = video->extradata_size;
624 gst_buffer_unmap(buf, &buff_info);
627 gst_caps_set_simple(caps, "codec_data", GST_TYPE_BUFFER, buf, NULL);
628 gst_buffer_unref(buf);
631 if (player->v_stream_caps) {
632 LOGW("caps will be updated ");
634 gst_caps_unref(player->v_stream_caps);
635 player->v_stream_caps = NULL;
638 player->v_stream_caps = gst_caps_copy(caps);
639 MMPLAYER_LOG_GST_CAPS_TYPE(player->v_stream_caps);
640 gst_caps_unref(caps);
644 return MM_ERROR_NONE;
648 __mmplayer_set_uri_type(mm_player_t *player)
652 player->profile.uri_type = MM_PLAYER_URI_TYPE_MS_BUFF;
653 player->es_player_push_mode = TRUE;
660 _mmplayer_set_video_info(MMHandleType hplayer, media_format_h format)
662 mm_player_t *player = MM_PLAYER_CAST(hplayer);
663 MMPlayerVideoStreamInfo video = { 0, };
664 int ret = MM_ERROR_NONE;
665 gboolean drc = FALSE;
669 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
671 __mmplayer_set_uri_type(player);
673 ret = __parse_media_format(&video, NULL, format);
674 if (ret != MM_ERROR_NONE)
677 mm_attrs_get_int_by_name(player->attrs, MM_PLAYER_DRC_MODE, &drc);
679 if (strstr(video.mime, "video/mpeg")) {
680 __mmplayer_video_caps_new(hplayer, &video,
681 "mpegversion", G_TYPE_INT, video.version,
682 "systemstream", G_TYPE_BOOLEAN, FALSE,
683 "adaptive-streaming", G_TYPE_BOOLEAN, drc, NULL);
684 } else if (strstr(video.mime, "video/x-h264")) {
686 if (info.colordepth) {
687 __mmplayer_video_caps_new(hplayer, &info,
688 "colordepth", G_TYPE_INT, info.colordepth, NULL);
692 __mmplayer_video_caps_new(hplayer, &video,
693 "stream-format", G_TYPE_STRING, "byte-stream",
694 "alignment", G_TYPE_STRING, "au",
695 "adaptive-streaming", G_TYPE_BOOLEAN, drc, NULL);
699 else if (strstr(info->mime, "video/x-wmv")) {
700 __mmplayer_video_caps_new(hplayer, &info,
701 "wmvversion", G_TYPE_INT, info.version, NULL);
702 } else if (strstr(info.mime, "video/x-pn-realvideo")) {
703 __mmplayer_video_caps_new(hplayer, &info,
704 "rmversion", G_TYPE_INT, info.version, NULL);
705 } else if (strstr(info.mime, "video/x-msmpeg")) {
706 __mmplayer_video_caps_new(hplayer, &info,
707 "msmpegversion", G_TYPE_INT, info.version, NULL);
708 } else if (strstr(info.mime, "video/x-h265")) {
710 __mmplayer_video_caps_new(hplayer, &info,
711 "colordepth", G_TYPE_INT, info.colordepth, NULL);
713 __mmplayer_video_caps_new(hplayer, &info, NULL);
715 __mmplayer_video_caps_new(hplayer, &info, NULL);
717 g_free((char *) video.mime);
721 return MM_ERROR_NONE;
725 _mmplayer_set_audio_info(MMHandleType hplayer, media_format_h format)
727 mm_player_t *player = MM_PLAYER_CAST(hplayer);
728 GstCaps *caps = NULL;
729 MMPlayerAudioStreamInfo audio = { 0, };
730 int ret = MM_ERROR_NONE;
734 MMPLAYER_RETURN_VAL_IF_FAIL(hplayer, MM_ERROR_PLAYER_NOT_INITIALIZED);
736 __mmplayer_set_uri_type(player);
738 ret = __parse_media_format(NULL, &audio, format);
739 if (ret != MM_ERROR_NONE)
742 audio.user_info = 0; //test
744 LOGD("set audio player[%p] version=%d rate=%d channel=%d",
745 player, audio.version, audio.sample_rate, audio.channels);
747 if (strstr(audio.mime, "audio/mpeg")) {
748 if (audio.version == 1) { // mp3
749 caps = gst_caps_new_simple("audio/mpeg",
750 "channels", G_TYPE_INT, audio.channels,
751 "rate", G_TYPE_INT, audio.sample_rate,
752 "mpegversion", G_TYPE_INT, audio.version,
753 "layer", G_TYPE_INT, audio.user_info, NULL);
755 gchar *stream_format = NULL;
757 if (audio.user_info == 0)
758 stream_format = g_strdup("raw");
759 else if (audio.user_info == 1)
760 stream_format = g_strdup("adts");
761 else if (audio.user_info == 2)
762 stream_format = g_strdup("adif");
764 caps = gst_caps_new_simple("audio/mpeg",
765 "channels", G_TYPE_INT, audio.channels,
766 "rate", G_TYPE_INT, audio.sample_rate,
767 "mpegversion", G_TYPE_INT, audio.version,
768 "stream-format", G_TYPE_STRING, stream_format, NULL);
770 g_free(stream_format);
771 stream_format = NULL;
775 else if (strstr(audio.mime, "audio/x-raw-int")) {
776 caps = gst_caps_new_simple("audio/x-raw-int",
777 "width", G_TYPE_INT, audio.width,
778 "depth", G_TYPE_INT, audio.depth,
779 "endianness", G_TYPE_INT, audio.endianness,
780 "signed", G_TYPE_BOOLEAN, audio.signedness,
781 "channels", G_TYPE_INT, audio.channels,
782 "rate", G_TYPE_INT, audio.sample_rate, NULL);
784 caps = gst_caps_new_simple(audio.mime,
785 "channels", G_TYPE_INT, audio.channels,
786 "rate", G_TYPE_INT, audio.sample_rate, NULL);
790 if (audio.extradata_size && audio.codec_extradata) {
791 GstBuffer *buf = NULL;
792 GstMapInfo buff_info = GST_MAP_INFO_INIT;
794 buf = gst_buffer_new_and_alloc(audio.extradata_size);
796 if (gst_buffer_map(buf, &buff_info, GST_MAP_READ)) {
797 memcpy(buff_info.data, audio.codec_extradata, audio.extradata_size);
798 gst_buffer_unmap(buf, &buff_info);
801 gst_caps_set_simple(caps, "codec_data", GST_TYPE_BUFFER, buf, NULL);
802 gst_buffer_unref(buf);
803 g_free((char *) audio.codec_extradata);
806 g_free((char *) audio.mime);
808 player->a_stream_caps = gst_caps_copy(caps);
809 gst_caps_unref(caps);
813 return MM_ERROR_NONE;
817 _mmplayer_set_subtitle_info(MMHandleType hplayer,
818 MMPlayerSubtitleStreamInfo * subtitle)
821 mm_player_t *player = MM_PLAYER_CAST(hplayer);
822 GstCaps *caps = NULL;
826 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
827 MMPLAYER_RETURN_VAL_IF_FAIL(info, MM_ERROR_PLAYER_NOT_INITIALIZED);
829 LOGD("set subtitle player[%p] info [%p]", player, info);
832 caps = gst_caps_new_simple(info->mime, NULL, NULL); // TO CHECK
836 if (strstr(info->mime, "application/x-xsub")) {
837 gst_caps_set_simple(caps, "codec_tag", G_TYPE_UINT, info->codec_tag, NULL);
838 } else if (strstr(info->mime, "application/x-smpte-text")) {
840 gst_caps_set_simple(caps, "ttml_priv_data", G_TYPE_POINTER,
841 info->context, NULL);
845 player->s_stream_caps = gst_caps_copy(caps);
847 gst_caps_unref(caps);
852 return MM_ERROR_NONE;
856 _mmplayer_set_media_stream_dynamic_resolution(MMHandleType hplayer, bool drc)
858 mm_player_t *player = MM_PLAYER_CAST(hplayer);
859 int ret = MM_ERROR_NONE;
863 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
865 mm_attrs_set_int_by_name(player->attrs, MM_PLAYER_DRC_MODE, (int)drc);
866 if (player->v_stream_caps) {
867 gst_caps_set_simple(player->v_stream_caps,
868 "adaptive-streaming", G_TYPE_BOOLEAN, drc, NULL);
869 MMPLAYER_LOG_GST_CAPS_TYPE(player->v_stream_caps);