#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(MMPlayerVideoStreamInfo *video, MMPlayerAudioStreamInfo *audio, media_format_h format);
-static int __convert_media_format_video_mime_to_str(MMPlayerVideoStreamInfo *video, media_format_mimetype_e mime);
-static int __convert_media_format_audio_mime_to_str(MMPlayerAudioStreamInfo *audio, media_format_mimetype_e mime);
-static gboolean __mm_player_is_codec_data_changed(mm_player_t *player, media_packet_h packet, MMPlayerStreamType streamtype);
+static gboolean __mm_player_is_codec_data_changed(mmplayer_t *player, media_packet_h packet, mmplayer_stream_type_e streamtype);
/*===========================================================================================
| |
========================================================================================== */
static int
-__convert_media_format_video_mime_to_str(MMPlayerVideoStreamInfo *video,
+__convert_media_format_video_mime_to_str(mmplayer_video_stream_info_t *video,
media_format_mimetype_e mime)
{
MMPLAYER_RETURN_VAL_IF_FAIL(video, MM_ERROR_INVALID_ARGUMENT);
}
static int
-__convert_media_format_audio_mime_to_str(MMPlayerAudioStreamInfo *audio,
+__convert_media_format_audio_mime_to_str(mmplayer_audio_stream_info_t *audio,
media_format_mimetype_e mime)
{
MMPLAYER_RETURN_VAL_IF_FAIL(audio, MM_ERROR_INVALID_ARGUMENT);
}
static int
-__parse_media_format(MMPlayerVideoStreamInfo *video,
- MMPlayerAudioStreamInfo *audio, media_format_h format)
+__parse_media_format(mmplayer_video_stream_info_t *video,
+ mmplayer_audio_stream_info_t *audio, media_format_h format)
{
if (audio) {
media_format_mimetype_e mime;
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)
{
- mm_player_t *player = (mm_player_t *)hplayer;
+ mmplayer_t *player = (mmplayer_t *)hplayer;
gboolean ret = FALSE;
GstStructure *str = NULL;
media_format_mimetype_e mimetype = 0;
return ret;
}
-int
-_mmplayer_set_media_stream_buffer_status_cb(MMHandleType hplayer,
- MMPlayerStreamType 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)
{
- mm_player_t *player = (mm_player_t *)hplayer;
+ 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,
- MMPlayerStreamType type,
- mm_player_media_stream_seek_data_callback callback,
- void *user_param)
-{
- mm_player_t *player = (mm_player_t *)hplayer;
-
- MMPLAYER_FENTER();
+ str = gst_caps_get_structure(player->a_stream_caps, 0);
+ if (!str) {
+ LOGE("failed to get caps info");
+ return FALSE;
+ }
- MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+ if (!gst_structure_get_int(str, "channels", &cur_channel))
+ LOGD("missing 'channel' field in audio caps");
- MMPLAYER_MEDIA_STREAM_CALLBACK_LOCK(player);
+ if (!gst_structure_get_int(str, "rate", &cur_samplerate))
+ LOGD("missing 'rate' field in audio caps");
- 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_get_source_element(mm_player_t *player, MMPlayerStreamType type)
+__mmplayer_get_source_element(mmplayer_t *player, mmplayer_stream_type_e type)
{
- enum MainElementID elemId = MMPLAYER_M_NUM;
+ main_element_id_e elemId = MMPLAYER_M_NUM;
if (player && player->pipeline && player->pipeline->mainbin) {
/* get elem according to the stream type */
}
int
-_mmplayer_set_media_stream_max_size(MMHandleType hplayer, MMPlayerStreamType type, guint64 max_size)
+_mmplayer_set_media_stream_max_size(MMHandleType hplayer, mmplayer_stream_type_e type, guint64 max_size)
{
- mm_player_t *player = (mm_player_t *)hplayer;
+ mmplayer_t *player = (mmplayer_t *)hplayer;
GstElement *element = NULL;
MMPLAYER_FENTER();
}
int
-_mmplayer_get_media_stream_max_size(MMHandleType hplayer, MMPlayerStreamType type, guint64 *max_size)
+_mmplayer_get_media_stream_max_size(MMHandleType hplayer, mmplayer_stream_type_e type, guint64 *max_size)
{
- mm_player_t *player = (mm_player_t *)hplayer;
+ mmplayer_t *player = (mmplayer_t *)hplayer;
MMPLAYER_FENTER();
}
int
-_mmplayer_set_media_stream_min_percent(MMHandleType hplayer, MMPlayerStreamType type, guint min_percent)
+_mmplayer_set_media_stream_min_percent(MMHandleType hplayer, mmplayer_stream_type_e type, guint min_percent)
{
- mm_player_t *player = (mm_player_t *)hplayer;
+ mmplayer_t *player = (mmplayer_t *)hplayer;
GstElement *element = NULL;
MMPLAYER_FENTER();
}
int
-_mmplayer_get_media_stream_min_percent(MMHandleType hplayer, MMPlayerStreamType type, guint *min_percent)
+_mmplayer_get_media_stream_min_percent(MMHandleType hplayer, mmplayer_stream_type_e type, guint *min_percent)
{
- mm_player_t *player = (mm_player_t *)hplayer;
+ mmplayer_t *player = (mmplayer_t *)hplayer;
MMPLAYER_FENTER();
}
static int
-__mmplayer_check_buffer_level(mm_player_t *player, GstElement *element, MMPlayerStreamType type)
+__mmplayer_check_buffer_level(mmplayer_t *player, GstElement *element, mmplayer_stream_type_e type)
{
guint64 current_level_bytes = 0;
guint64 max_bytes = 0;
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();
{
int ret = MM_ERROR_NONE;
GstBuffer *_buffer = NULL;
- mm_player_t *player = (mm_player_t *)hplayer;
+ mmplayer_t *player = (mmplayer_t *)hplayer;
guint8 *buf = NULL;
uint64_t size = 0;
GstElement *element = NULL;
- MMPlayerStreamType streamtype = MM_PLAYER_STREAM_TYPE_AUDIO;
+ mmplayer_stream_type_e streamtype = MM_PLAYER_STREAM_TYPE_AUDIO;
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 */
}
static int
-__mmplayer_video_caps_new(MMHandleType hplayer, MMPlayerVideoStreamInfo *video,
+__mmplayer_video_caps_new(MMHandleType hplayer, mmplayer_video_stream_info_t *video,
const char *fieldname, ...)
{
int cap_size;
GstCaps *caps = NULL;
GstStructure *structure = NULL;
va_list var_args;
- mm_player_t *player = MM_PLAYER_CAST(hplayer);
+ mmplayer_t *player = MM_PLAYER_CAST(hplayer);
MMPLAYER_FENTER();
MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
}
static void
-__mmplayer_set_uri_type(mm_player_t *player)
+__mmplayer_set_uri_type(mmplayer_t *player)
{
MMPLAYER_FENTER();
int
_mmplayer_set_video_info(MMHandleType hplayer, media_format_h format)
{
- mm_player_t *player = MM_PLAYER_CAST(hplayer);
- MMPlayerVideoStreamInfo video = { 0, };
+ mmplayer_t *player = MM_PLAYER_CAST(hplayer);
+ mmplayer_video_stream_info_t video = { 0, };
int ret = MM_ERROR_NONE;
gboolean drc = FALSE;
"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();
int
_mmplayer_set_audio_info(MMHandleType hplayer, media_format_h format)
{
- mm_player_t *player = MM_PLAYER_CAST(hplayer);
+ mmplayer_t *player = MM_PLAYER_CAST(hplayer);
GstCaps *caps = NULL;
- MMPlayerAudioStreamInfo audio = { 0, };
+ mmplayer_audio_stream_info_t audio = { 0, };
int ret = MM_ERROR_NONE;
MMPLAYER_FENTER();
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
int
_mmplayer_set_subtitle_info(MMHandleType hplayer,
- MMPlayerSubtitleStreamInfo *subtitle)
+ mmplayer_subtitle_stream_info_t *subtitle)
{
#if 0 //todo
- mm_player_t *player = MM_PLAYER_CAST(hplayer);
+ mmplayer_t *player = MM_PLAYER_CAST(hplayer);
GstCaps *caps = NULL;
MMPLAYER_FENTER();
int
_mmplayer_set_media_stream_dynamic_resolution(MMHandleType hplayer, bool drc)
{
- mm_player_t *player = MM_PLAYER_CAST(hplayer);
+ mmplayer_t *player = MM_PLAYER_CAST(hplayer);
int ret = MM_ERROR_NONE;
MMPLAYER_FENTER();
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);
}
static gboolean
-__mm_player_is_codec_data_changed(mm_player_t *player, media_packet_h packet,
- MMPlayerStreamType streamtype)
+__mm_player_is_codec_data_changed(mmplayer_t *player, media_packet_h packet,
+ mmplayer_stream_type_e streamtype)
{
GstCaps *cur_caps = NULL;
GstCaps *new_caps = NULL;
GstBuffer *buffer = NULL;
GstMapInfo codec_data_map = GST_MAP_INFO_INIT;
GstBuffer *new_buffer = NULL;
- char *codec_data;
- unsigned int codec_data_size;
+ char *codec_data = NULL;
+ unsigned int codec_data_size = 0;
MMPLAYER_RETURN_VAL_IF_FAIL(player, FALSE);
MMPLAYER_RETURN_VAL_IF_FAIL(packet, FALSE);
if (media_packet_get_codec_data(packet, (void **)&codec_data, &codec_data_size)
- != MEDIA_PACKET_ERROR_NONE) {
- LOGD("Failed to get coodec data in media_packet");
+ != MEDIA_PACKET_ERROR_NONE)
return FALSE;
- }
if (codec_data_size == 0) {
LOGW("codec_data_size is zero");
LOGD("need to update caps due to codec data is changed");
return TRUE;
-}
\ No newline at end of file
+}