#include <dlog.h>
#include "mm_player_es.h"
#include "mm_player_utils.h"
-#include "mm_player_internal.h"
#include <gst/app/gstappsrc.h>
/*---------------------------------------------------------------------------
| LOCAL FUNCTION PROTOTYPES: |
---------------------------------------------------------------------------*/
-static int __parse_media_format(mmplayer_video_stream_info_t *video, mmplayer_audio_stream_info_t *audio, media_format_h format);
-static int __convert_media_format_video_mime_to_str(mmplayer_video_stream_info_t *video, media_format_mimetype_e mime);
-static int __convert_media_format_audio_mime_to_str(mmplayer_audio_stream_info_t *audio, media_format_mimetype_e mime);
static gboolean __mm_player_is_codec_data_changed(mmplayer_t *player, media_packet_h packet, mmplayer_stream_type_e streamtype);
/*===========================================================================================
LOGE("media_format_get_audio_info failed");
return MM_ERROR_PLAYER_INTERNAL;
}
-
+ if (mime & MEDIA_FORMAT_AAC) {
+ bool is_adts = false;
+ media_format_get_audio_aac_type (format, &is_adts);
+ if (is_adts)
+ audio->user_info = 1;
+ else
+ audio->user_info = 2;
+ }
+ /* FIXME : Check other mime type (now support AAC only) */
__convert_media_format_audio_mime_to_str(audio, mime);
audio->sample_rate = samplerate;
audio->channels = channel;
- //video->user_info = ;
}
if (video) {
}
static gboolean
-__mmplayer_update_video_info(MMHandleType hplayer, media_format_h fmt)
+__mmplayer_is_video_info_changed (MMHandleType hplayer, media_format_h fmt)
{
mmplayer_t *player = (mmplayer_t *)hplayer;
gboolean ret = FALSE;
return ret;
}
-int
-_mmplayer_set_media_stream_buffer_status_cb(MMHandleType hplayer,
- mmplayer_stream_type_e type,
- mm_player_media_stream_buffer_status_callback callback,
- void *user_param)
+static gboolean
+__mmplayer_is_audio_info_changed (MMHandleType hplayer, media_format_h fmt)
{
mmplayer_t *player = (mmplayer_t *)hplayer;
+ gboolean ret = FALSE;
+ GstStructure *str = NULL;
+ media_format_mimetype_e mimetype = 0;
+ gint cur_samplerate = 0, samplerate = 0;
+ gint cur_channel = 0, channel = 0;
MMPLAYER_FENTER();
- MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
-
- MMPLAYER_MEDIA_STREAM_CALLBACK_LOCK(player);
+ MMPLAYER_RETURN_VAL_IF_FAIL(player && player->a_stream_caps, FALSE);
+ MMPLAYER_RETURN_VAL_IF_FAIL(fmt, FALSE);
- if (player->media_stream_buffer_status_cb[type]) {
- if (!callback)
- LOGD("[type:%s] will be clear", MMPLAYER_STREAM_TYPE_GET_NAME(type));
- else
- LOGD("[type:%s] will be overwritten", MMPLAYER_STREAM_TYPE_GET_NAME(type));
+ if (MMPLAYER_CURRENT_STATE(player) != MM_PLAYER_STATE_PAUSED &&
+ MMPLAYER_CURRENT_STATE(player) != MM_PLAYER_STATE_PLAYING) {
+ LOGW("skip update audio info, state: %s", MMPLAYER_STATE_GET_NAME(MMPLAYER_CURRENT_STATE(player)));
+ return FALSE;
}
- player->media_stream_buffer_status_cb[type] = callback;
- player->buffer_cb_user_param[type] = user_param;
-
- LOGD("player handle %p, type %s, callback %p",
- player, MMPLAYER_STREAM_TYPE_GET_NAME(type), player->media_stream_buffer_status_cb[type]);
- MMPLAYER_MEDIA_STREAM_CALLBACK_UNLOCK(player);
-
- MMPLAYER_FLEAVE();
-
- return MM_ERROR_NONE;
-}
-
-int
-_mmplayer_set_media_stream_seek_data_cb(MMHandleType hplayer,
- mmplayer_stream_type_e type,
- mm_player_media_stream_seek_data_callback callback,
- void *user_param)
-{
- mmplayer_t *player = (mmplayer_t *)hplayer;
+ str = gst_caps_get_structure(player->a_stream_caps, 0);
+ if (!str) {
+ LOGE("failed to get caps info");
+ return FALSE;
+ }
- MMPLAYER_FENTER();
+ if (!gst_structure_get_int(str, "channels", &cur_channel))
+ LOGD("missing 'channel' field in audio caps");
- MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+ if (!gst_structure_get_int(str, "rate", &cur_samplerate))
+ LOGD("missing 'rate' field in audio caps");
- MMPLAYER_MEDIA_STREAM_CALLBACK_LOCK(player);
-
- if (player->media_stream_seek_data_cb[type]) {
- if (!callback)
- LOGD("[type:%s] will be clear", MMPLAYER_STREAM_TYPE_GET_NAME(type));
- else
- LOGD("[type:%s] will be overwritten", MMPLAYER_STREAM_TYPE_GET_NAME(type));
+ media_format_get_audio_info(fmt, &mimetype, &channel, &samplerate, NULL, NULL);
+ if ((cur_channel != channel) || (cur_samplerate != samplerate)) {
+ LOGW("audio info change channel(%d), samplerate(%d) -> %d, %d",
+ cur_channel, cur_samplerate, channel, samplerate);
+ _mmplayer_set_audio_info(hplayer, fmt);
+ ret = TRUE;
}
- player->media_stream_seek_data_cb[type] = callback;
- player->seek_cb_user_param[type] = user_param;
-
- LOGD("player handle %p, type %s, callback %p",
- player, MMPLAYER_STREAM_TYPE_GET_NAME(type), player->media_stream_seek_data_cb[type]);
- MMPLAYER_MEDIA_STREAM_CALLBACK_UNLOCK(player);
-
MMPLAYER_FLEAVE();
-
- return MM_ERROR_NONE;
+ return ret;
}
static GstElement *
MMPLAYER_FENTER();
MMPLAYER_RETURN_VAL_IF_FAIL(player && element, MM_ERROR_PLAYER_NOT_INITIALIZED);
+ MMPLAYER_RETURN_VAL_IF_FAIL(((type == MM_PLAYER_STREAM_TYPE_AUDIO) || (type == MM_PLAYER_STREAM_TYPE_VIDEO)), MM_ERROR_INVALID_ARGUMENT);
if (player->media_stream_buffer_max_size[type] > 0)
max_bytes = player->media_stream_buffer_max_size[type];
}
if (MMPLAYER_CURRENT_STATE(player) != MM_PLAYER_STATE_PLAYING) {
- MMPLAYER_MEDIA_STREAM_CALLBACK_LOCK(player);
- if (!player->media_stream_buffer_status_cb[type]) {
- MMPLAYER_MEDIA_STREAM_CALLBACK_UNLOCK(player);
- return MM_ERROR_NONE;
- }
-
current_level_per = (guint)(gst_util_guint64_to_gdouble(current_level_bytes) / gst_util_guint64_to_gdouble(max_bytes) * 100);
LOGD("type: %s, min_per %u, curr_per %u max %"G_GUINT64_FORMAT" cur %"G_GUINT64_FORMAT,
player->media_stream_buffer_max_size[type],
current_level_bytes);
- if (current_level_per < player->media_stream_buffer_min_percent[type])
- player->media_stream_buffer_status_cb[type](type, MM_PLAYER_MEDIA_STREAM_BUFFER_UNDERRUN, current_level_bytes, player->buffer_cb_user_param[type]);
+ if (current_level_per < player->media_stream_buffer_min_percent[type]) {
+ MMMessageParamType msg_param = {0,};
+
+ msg_param.union_type = MM_MSG_UNION_BUFFER_STATUS;
+ msg_param.buffer_status.stream_type = type;
+ msg_param.buffer_status.status = MM_PLAYER_MEDIA_STREAM_BUFFER_UNDERRUN;
+ msg_param.buffer_status.bytes = current_level_bytes;
- MMPLAYER_MEDIA_STREAM_CALLBACK_UNLOCK(player);
+ MMPLAYER_POST_MSG(player, MM_MESSAGE_PUSH_BUFFER_STATUS, &msg_param);
+ }
}
MMPLAYER_FLEAVE();
media_format_h fmt = NULL;
bool flag = false;
bool is_eos = false;
- gboolean need_update_caps = false;
+ gboolean need_update_caps = FALSE;
MMPLAYER_RETURN_VAL_IF_FAIL(packet, MM_ERROR_INVALID_ARGUMENT);
MMPLAYER_RETURN_VAL_IF_FAIL(player &&
- player->pipeline &&
- player->pipeline->mainbin &&
- player->pipeline->mainbin[MMPLAYER_M_SRC].gst,
- MM_ERROR_PLAYER_NOT_INITIALIZED);
+ player->pipeline &&
+ player->pipeline->mainbin &&
+ player->pipeline->mainbin[MMPLAYER_M_SRC].gst,
+ MM_ERROR_PLAYER_NOT_INITIALIZED);
/* get stream type if audio or video */
media_packet_is_audio(packet, &flag);
streamtype = MM_PLAYER_STREAM_TYPE_TEXT;
}
- need_update_caps = __mm_player_is_codec_data_changed(player, packet, streamtype);
-
element = __mmplayer_get_source_element(player, streamtype);
if (!element) {
LOGE("there is no source element of type %d", streamtype);
/* get format to check video format */
media_packet_get_format(packet, &fmt);
if (fmt) {
- need_update_caps |= __mmplayer_update_video_info(hplayer, fmt);
+ need_update_caps |= __mmplayer_is_video_info_changed (hplayer, fmt);
media_format_unref(fmt);
}
+ need_update_caps |= __mm_player_is_codec_data_changed(player, packet, streamtype);
if (need_update_caps)
g_object_set(G_OBJECT(player->pipeline->mainbin[MMPLAYER_M_SRC].gst),
duration = DEFAULT_VIDEO_FRAME_DURATION * GST_MSECOND;
GST_BUFFER_DURATION(_buffer) = (GstClockTime)duration;
- } else if ((streamtype == MM_PLAYER_STREAM_TYPE_AUDIO) && need_update_caps) {
- LOGD("update audio caps");
- g_object_set(G_OBJECT(player->pipeline->mainbin[MMPLAYER_M_SRC].gst),
- "caps", player->a_stream_caps, NULL);
+ } else if (streamtype == MM_PLAYER_STREAM_TYPE_AUDIO) {
+ media_packet_get_format(packet, &fmt);
+ if (fmt) {
+ need_update_caps |= __mmplayer_is_audio_info_changed (hplayer, fmt);
+ media_format_unref(fmt);
+ }
+ need_update_caps |= __mm_player_is_codec_data_changed(player, packet, streamtype);
+
+ if (need_update_caps) {
+ LOGD("update audio caps");
+ g_object_set(G_OBJECT(player->pipeline->mainbin[MMPLAYER_M_SRC].gst),
+ "caps", player->a_stream_caps, NULL);
+ }
}
/* get pts */
"systemstream", G_TYPE_BOOLEAN, FALSE,
"adaptive-streaming", G_TYPE_BOOLEAN, drc, NULL);
} else if (strstr(video.mime, "video/x-h264")) {
- /*
- if (info.colordepth) {
- __mmplayer_video_caps_new(hplayer, &info,
- "colordepth", G_TYPE_INT, info.colordepth, NULL);
- } else
- */
- {
- __mmplayer_video_caps_new(hplayer, &video,
+ __mmplayer_video_caps_new(hplayer, &video,
"stream-format", G_TYPE_STRING, "byte-stream",
"alignment", G_TYPE_STRING, "au",
"adaptive-streaming", G_TYPE_BOOLEAN, drc, NULL);
- }
}
-#if 0
- else if (strstr(info->mime, "video/x-wmv")) {
- __mmplayer_video_caps_new(hplayer, &info,
- "wmvversion", G_TYPE_INT, info.version, NULL);
- } else if (strstr(info.mime, "video/x-pn-realvideo")) {
- __mmplayer_video_caps_new(hplayer, &info,
- "rmversion", G_TYPE_INT, info.version, NULL);
- } else if (strstr(info.mime, "video/x-msmpeg")) {
- __mmplayer_video_caps_new(hplayer, &info,
- "msmpegversion", G_TYPE_INT, info.version, NULL);
- } else if (strstr(info.mime, "video/x-h265")) {
- if (info.colordepth)
- __mmplayer_video_caps_new(hplayer, &info,
- "colordepth", G_TYPE_INT, info.colordepth, NULL);
- else
- __mmplayer_video_caps_new(hplayer, &info, NULL);
- } else
- __mmplayer_video_caps_new(hplayer, &info, NULL);
-#endif
g_free((char *)video.mime);
MMPLAYER_FLEAVE();
if (ret != MM_ERROR_NONE)
return ret;
- audio.user_info = 0; //test
LOGD("set audio player[%p] version=%d rate=%d channel=%d",
player, audio.version, audio.sample_rate, audio.channels);
if (strstr(audio.mime, "audio/mpeg")) {
- if (audio.version == 1) { // mp3
- caps = gst_caps_new_simple("audio/mpeg",
- "channels", G_TYPE_INT, audio.channels,
- "rate", G_TYPE_INT, audio.sample_rate,
- "mpegversion", G_TYPE_INT, audio.version,
- "layer", G_TYPE_INT, audio.user_info, NULL);
- } else { // aac
+ if (audio.version == 2) { // aac
gchar *stream_format = NULL;
if (audio.user_info == 0)
MMPLAYER_FREEIF(stream_format);
stream_format = NULL;
+ } else if (audio.version == 1 ) { // mp3
+ caps = gst_caps_new_simple("audio/mpeg",
+ "channels", G_TYPE_INT, audio.channels,
+ "rate", G_TYPE_INT, audio.sample_rate,
+ "mpegversion", G_TYPE_INT, audio.version,
+ "layer", G_TYPE_INT, audio.user_info, NULL);
}
}
#if 0
MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
- mm_attrs_set_int_by_name(player->attrs, MM_PLAYER_DRC_MODE, (int)drc);
+ mm_player_set_attribute(hplayer, NULL, MM_PLAYER_DRC_MODE, (int)drc, NULL);
if (player->v_stream_caps) {
gst_caps_set_simple(player->v_stream_caps,
"adaptive-streaming", G_TYPE_BOOLEAN, drc, NULL);
cur_caps = player->v_stream_caps;
} else {
LOGW("streamtype is not audio or video");
- return FALSE;
+ goto __FAILED;
}
if (!cur_caps) {
LOGW("Current caps is NULL");
- return FALSE;
+ goto __FAILED;
}
str = gst_caps_get_structure(cur_caps, 0);
if (!str) {
LOGW("Failed to get caps info");
- return FALSE;
+ goto __FAILED;
}
/* Check if the codec data in the saved caps have been changed */
buffer = gst_value_get_buffer(value);
if (!gst_buffer_map(buffer, &codec_data_map, GST_MAP_READ)) {
LOGW("codec data buffer map failed");
- return FALSE;
+ goto __FAILED;
}
if (codec_data_map.size == codec_data_size) {
for (i = 0; i <= codec_data_map.size; i++) {
break;
}
gst_buffer_unmap(buffer, &codec_data_map);
- return FALSE;
+ goto __FAILED;
}
gst_buffer_unmap(buffer, &codec_data_map);
}
new_caps = gst_caps_copy(cur_caps);
if (!new_caps) {
LOGW("Failed to copy caps");
- return FALSE;
+ goto __FAILED;
}
new_buffer = gst_buffer_new_allocate(NULL, codec_data_size, NULL);
if (!new_buffer) {
LOGW("Failed to alloc gst buffer for codec data");
- gst_caps_unref(new_caps);
- return FALSE;
+ goto __FAILED;
}
gst_buffer_fill(new_buffer, 0, codec_data, codec_data_size);
gst_caps_set_simple(new_caps, "codec_data", GST_TYPE_BUFFER, new_buffer, NULL);
player->v_stream_caps = new_caps;
gst_caps_unref(cur_caps);
+ free(codec_data);
LOGD("need to update caps due to codec data is changed");
+
return TRUE;
-}
\ No newline at end of file
+
+__FAILED:
+ if (new_caps)
+ gst_caps_unref(new_caps);
+
+ if (codec_data)
+ free(codec_data);
+
+ return FALSE;
+}