From: Gilbok Lee Date: Thu, 11 Jul 2024 07:10:53 +0000 (+0900) Subject: Support mkv/webm container and vp8/vp9 video format X-Git-Tag: accepted/tizen/unified/20240715.155358^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fheads%2Ftizen_9.0;p=platform%2Fcore%2Fapi%2Fmediademuxer.git Support mkv/webm container and vp8/vp9 video format [Version] 0.1.44 [Issue Type] Add features Change-Id: Ie56087ffd6f6c0aa39c1ce129edf08acb5d666b0 --- diff --git a/packaging/capi-mediademuxer.spec b/packaging/capi-mediademuxer.spec index 87ead85..294147c 100644 --- a/packaging/capi-mediademuxer.spec +++ b/packaging/capi-mediademuxer.spec @@ -1,6 +1,6 @@ Name: capi-mediademuxer Summary: A Media Demuxer library in Tizen Native API -Version: 0.1.43 +Version: 0.1.44 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/port_gst/mediademuxer_port_gst.c b/src/port_gst/mediademuxer_port_gst.c index 653c675..303b757 100644 --- a/src/port_gst/mediademuxer_port_gst.c +++ b/src/port_gst/mediademuxer_port_gst.c @@ -783,7 +783,8 @@ static void __gst_cb_typefind(GstElement *tf, guint probability, MD_I("Media type %s found, probability %d%%", type, probability); if (strstr(type, "quicktime") || strstr(type, "audio/x-m4a") || strstr(type, "x-3gp") || strstr(type, "ogg") || - strstr(type, "flv") || strstr(type, "x-msvideo")) { + strstr(type, "flv") || strstr(type, "x-msvideo") || + strstr(type, "x-matroska") || strstr(type, "webm")) { gst_handle->is_valid_container = true; if (strstr(type, "ogg")) gst_handle->demux = gst_element_factory_make("oggdemux", NULL); @@ -791,12 +792,14 @@ static void __gst_cb_typefind(GstElement *tf, guint probability, gst_handle->demux = gst_element_factory_make("flvdemux", NULL); else if (strstr(type, "x-msvideo")) gst_handle->demux = gst_element_factory_make("avidemux", NULL); + else if (strstr(type, "x-matroska") || strstr(type, "webm")) + gst_handle->demux = gst_element_factory_make("matroskademux", NULL); else gst_handle->demux = gst_element_factory_make("qtdemux", NULL); if (!gst_handle->demux) { gst_handle->is_valid_container = false; - MD_E("factory not able to create qtdemux"); + MD_E("factory not able to create demuxer (%s) caps", type); goto ERROR; } g_signal_connect(gst_handle->demux, "pad-added", @@ -1178,13 +1181,13 @@ int _set_mime_text(media_format_h format, track *head) { MEDIADEMUXER_FENTER(); int ret = MD_ERROR_NONE; - GstStructure *struc = NULL; - struc = gst_caps_get_structure(head->caps, 0); - if (!struc) { + GstStructure *structure = NULL; + structure = gst_caps_get_structure(head->caps, 0); + if (!structure) { MD_E("cannot get structure from caps."); goto ERROR; } - if (gst_structure_has_name(struc, "text/x-raw")) { + if (gst_structure_has_name(structure, "text/x-raw")) { if (media_format_set_text_mime(format, MEDIA_FORMAT_TEXT_MP4)) goto ERROR; } else { @@ -1199,48 +1202,102 @@ ERROR: return MD_ERROR; } +media_format_mimetype_e _convert_mimetype(GstStructure *structure) +{ + if (!structure) { + MD_E("input structure is NULL"); + return MEDIA_FORMAT_MAX; + } + + const char *mime = gst_structure_get_name(structure); + if (!mime) { + MD_E("Failed to get structure name"); + return MEDIA_FORMAT_MAX; + } + + if (g_strrstr(mime, "video/x-h264")) { + return MEDIA_FORMAT_H264_SP; + } else if (g_strrstr(mime, "video/x-h263")) { + return MEDIA_FORMAT_H263; + } else if (g_strrstr(mime, "video/mpeg")) { + return MEDIA_FORMAT_MPEG4_SP; + } else if (g_strrstr(mime, "video/x-vp8")) { + return MEDIA_FORMAT_VP8; + } else if (g_strrstr(mime, "video/x-vp9")) { + return MEDIA_FORMAT_VP9; + } else if (g_strrstr(mime, "application/x-id3")) { + return MEDIA_FORMAT_MP3; + } else if (g_strrstr(mime, "audio/mpeg")) { + gint mpegversion; + int layer; + gst_structure_get_int(structure, "mpegversion", &mpegversion); + if (mpegversion == 4 || mpegversion == 2) { + return MEDIA_FORMAT_AAC_LC; + } else if (mpegversion == 1) { + gst_structure_get_int(structure, "layer", &layer); + if (layer == 3) + return MEDIA_FORMAT_MP3; + MD_I("No Support for MPEG%d Layer %d media", mpegversion, layer); + return MEDIA_FORMAT_MAX; + } + return MEDIA_FORMAT_MAX; + } else if (g_strrstr(mime, "audio/x-amr-wb-sh") || g_strrstr(mime, "audio/AMR-WB")) { + return MEDIA_FORMAT_AMR_WB; + } else if (g_strrstr(mime, "audio/x-amr-nb-sh") || g_strrstr(mime, "audio/AMR")) { + return MEDIA_FORMAT_AMR_NB; + } else if (g_strrstr(mime, "audio/x-wav")) { + return MEDIA_FORMAT_PCM; + } else if (g_strrstr(mime, "audio/x-flac")) { + return MEDIA_FORMAT_FLAC; + } else if (g_strrstr(mime, "audio/x-vorbis")) { + return MEDIA_FORMAT_VORBIS; + } else { + MD_W("mime (%s) not supported so far", mime); + return MEDIA_FORMAT_MAX; + } +} + int _set_mime_video(media_format_h format, track *head) { MEDIADEMUXER_FENTER(); int ret = MD_ERROR_NONE; - GstStructure *struc = NULL; + GstStructure *structure = NULL; int src_width; int src_height; int frame_rate_numerator = 0; int frame_rate_denominator = 0; int frame_rate = 0; media_format_mimetype_e mime_type = MEDIA_FORMAT_MAX; - struc = gst_caps_get_structure(head->caps, 0); - if (!struc) { + structure = gst_caps_get_structure(head->caps, 0); + if (!structure) { MD_E("cannot get structure from caps."); goto ERROR; } - if (gst_structure_has_name(struc, "video/x-h264")) { - mime_type = MEDIA_FORMAT_H264_SP; - } else if (gst_structure_has_name(struc, "video/x-h263")) { - mime_type = MEDIA_FORMAT_H263; - } else if (gst_structure_has_name(struc, "video/mpeg")) { - mime_type = MEDIA_FORMAT_MPEG4_SP; - } else { - MD_W("Video mime (%s) not supported so far", gst_structure_get_name(struc)); + + mime_type = _convert_mimetype(structure); + if (mime_type == MEDIA_FORMAT_MAX) { + MD_W("Video mime (%s) not supported so far", gst_structure_get_name(structure)); goto ERROR; } + if (media_format_set_video_mime(format, mime_type)) { MD_E("Unable to set video mime type (%x)", mime_type); goto ERROR; } - gst_structure_get_int(struc, "width", &src_width); - gst_structure_get_int(struc, "height", &src_height); + + gst_structure_get_int(structure, "width", &src_width); + gst_structure_get_int(structure, "height", &src_height); if (media_format_set_video_width(format, src_width)) { MD_E("Unable to set video width"); goto ERROR; } + if (media_format_set_video_height(format, src_height)) { MD_E("Unable to set video height"); goto ERROR; } - gst_structure_get_fraction(struc, "framerate", &frame_rate_numerator, &frame_rate_denominator); + gst_structure_get_fraction(structure, "framerate", &frame_rate_numerator, &frame_rate_denominator); /* Round off the framerate */ if (frame_rate_denominator) frame_rate = (int)floor(((gdouble)frame_rate_numerator / frame_rate_denominator) + 0.5); @@ -1250,8 +1307,10 @@ int _set_mime_video(media_format_h format, track *head) MD_E("Unable to set video frame rate"); goto ERROR; } + MEDIADEMUXER_FLEAVE(); return ret; + ERROR: MEDIADEMUXER_FLEAVE(); return MD_ERROR; @@ -1261,74 +1320,35 @@ int _set_mime_audio(media_format_h format, track *head) { MEDIADEMUXER_FENTER(); int ret = MD_ERROR_NONE; - GstStructure *struc = NULL; + GstStructure *structure = NULL; int rate = 0; int bit = 0; int channels = 0; - int id3_flag = 0; - const gchar *stream_format = NULL; media_format_mimetype_e mime_type = MEDIA_FORMAT_MAX; - struc = gst_caps_get_structure(head->caps, 0); - if (!struc) { + structure = gst_caps_get_structure(head->caps, 0); + if (!structure) { MD_E("cannot get structure from caps."); goto ERROR; } - if (gst_structure_has_name(struc, "application/x-id3")) - id3_flag = 1; - if (gst_structure_has_name(struc, "audio/mpeg") || id3_flag) { - gint mpegversion; - int layer; - gst_structure_get_int(struc, "mpegversion", &mpegversion); - if (mpegversion == 4 || mpegversion == 2) { - mime_type = MEDIA_FORMAT_AAC_LC; - if (media_format_set_audio_mime(format, mime_type)) - goto ERROR; - stream_format = gst_structure_get_string(struc, "stream-format"); - - if (stream_format) { - if (strncmp(stream_format, "adts", 4) == 0) - media_format_set_audio_aac_type(format, 1); - else - media_format_set_audio_aac_type(format, 0); - } - - } else if (mpegversion == 1 || id3_flag) { - gst_structure_get_int(struc, "layer", &layer); - if ((layer == 3) || (id3_flag == 1)) { - mime_type = MEDIA_FORMAT_MP3; - } else { - MD_I("No Support for MPEG%d Layer %d media", mpegversion, layer); - goto ERROR; - } - } - } else if (gst_structure_has_name(struc, "audio/x-amr-nb-sh") || - gst_structure_has_name(struc, "audio/x-amr-wb-sh")) { - if (gst_structure_has_name(struc, "audio/x-amr-nb-sh")) { - mime_type = MEDIA_FORMAT_AMR_NB; - rate = 8000; - } else { - mime_type = MEDIA_FORMAT_AMR_WB; - rate = 16000; - } - } else if (gst_structure_has_name(struc, "audio/AMR")) { - mime_type = MEDIA_FORMAT_AMR_NB; - } else if (gst_structure_has_name(struc, "audio/AMR-WB")) { - mime_type = MEDIA_FORMAT_AMR_WB; - } else if (gst_structure_has_name(struc, "audio/x-wav")) { - mime_type = MEDIA_FORMAT_PCM; - } else if (gst_structure_has_name(struc, "audio/x-flac")) { - mime_type = MEDIA_FORMAT_FLAC; - } else if (gst_structure_has_name(struc, "audio/x-vorbis")) { - mime_type = MEDIA_FORMAT_VORBIS; - } else { - MD_W("Audio mime (%s) not supported so far", gst_structure_get_name(struc)); + mime_type = _convert_mimetype(structure); + if (mime_type == MEDIA_FORMAT_MAX) { + MD_W("Audio mime (%s) not supported so far", gst_structure_get_name(structure)); goto ERROR; } + if (media_format_set_audio_mime(format, mime_type)) goto ERROR; - gst_structure_get_int(struc, "channels", &channels); + + if (mime_type == MEDIA_FORMAT_AAC_LC) { + if (g_strcmp0(gst_structure_get_string(structure, "stream-format"), "adts") == 0) + media_format_set_audio_aac_type(format, 1); + else + media_format_set_audio_aac_type(format, 0); + } + + gst_structure_get_int(structure, "channels", &channels); if (channels == 0) { /* default */ if (mime_type == MEDIA_FORMAT_AMR_NB || mime_type == MEDIA_FORMAT_AMR_WB) channels = 1; @@ -1337,19 +1357,28 @@ int _set_mime_audio(media_format_h format, track *head) } if (media_format_set_audio_channel(format, channels)) goto ERROR; - if (rate == 0) - gst_structure_get_int(struc, "rate", &rate); - if (rate == 0) - rate = 44100; /* default */ + + if (mime_type == MEDIA_FORMAT_AMR_NB) { + rate = 8000; + } else if (mime_type == MEDIA_FORMAT_AMR_WB) { + rate = 16000; + } else { + gst_structure_get_int(structure, "rate", &rate); + if (rate == 0) + rate = 44100; /* default */ + } if (media_format_set_audio_samplerate(format, rate)) goto ERROR; - gst_structure_get_int(struc, "bit", &bit); + + gst_structure_get_int(structure, "bit", &bit); if (bit == 0) bit = 16; /* default */ if (media_format_set_audio_bit(format, bit)) goto ERROR; + MEDIADEMUXER_FLEAVE(); return ret; + ERROR: MEDIADEMUXER_FLEAVE(); return MD_ERROR;