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;
}
+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 && player->a_stream_caps, FALSE);
+ MMPLAYER_RETURN_VAL_IF_FAIL(fmt, FALSE);
+
+ 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;
+ }
+
+ str = gst_caps_get_structure(player->a_stream_caps, 0);
+ if (!str) {
+ LOGE("failed to get caps info");
+ return FALSE;
+ }
+
+ if (!gst_structure_get_int(str, "channels", &cur_channel))
+ LOGD("missing 'channel' field in audio caps");
+
+ if (!gst_structure_get_int(str, "rate", &cur_samplerate))
+ LOGD("missing 'rate' field in audio caps");
+
+ 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;
+ }
+
+ MMPLAYER_FLEAVE();
+ return ret;
+}
+
static GstElement *
__mmplayer_get_source_element(mmplayer_t *player, mmplayer_stream_type_e type)
{
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
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;
+
+__FAILED:
+ if (new_caps)
+ gst_caps_unref(new_caps);
+
+ if (codec_data)
+ free(codec_data);
+
+ return FALSE;
}