From f8b87c8a05e4d694118b2097aee135d7bd26705d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sebastian=20Dr=C3=B6ge?= Date: Thu, 28 Apr 2016 16:24:52 +0300 Subject: [PATCH] qtmux: Allow MPEG-1 Layer 1 and 2 in addition to 3 in MP4 Via the MPEG-4 Part 3 spec we can support the other layers too. Also correct the samples per frame calculation for MP3 if it's MPEG-2 or MPEG-2.5. https://bugzilla.gnome.org/show_bug.cgi?id=765725 --- gst/isomp4/gstqtmux.c | 42 +++++++++++++++++++++++++----------------- gst/isomp4/gstqtmuxmap.c | 8 +++++++- 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/gst/isomp4/gstqtmux.c b/gst/isomp4/gstqtmux.c index 9ac7c77..5be830b 100644 --- a/gst/isomp4/gstqtmux.c +++ b/gst/isomp4/gstqtmux.c @@ -3461,30 +3461,38 @@ gst_qt_mux_audio_sink_set_caps (GstQTPad * qtpad, GstCaps * caps) /* now map onto a fourcc, and some extra properties */ if (strcmp (mimetype, "audio/mpeg") == 0) { - gint mpegversion = 0; + gint mpegversion = 0, mpegaudioversion = 0; gint layer = -1; gst_structure_get_int (structure, "mpegversion", &mpegversion); switch (mpegversion) { case 1: gst_structure_get_int (structure, "layer", &layer); - switch (layer) { - case 3: - /* mp3 */ - /* note: QuickTime player does not like mp3 either way in iso/mp4 */ - if (format == GST_QT_MUX_FORMAT_QT) - entry.fourcc = FOURCC__mp3; - else { - entry.fourcc = FOURCC_mp4a; - ext_atom = - build_esds_extension (qtpad->trak, ESDS_OBJECT_TYPE_MPEG1_P3, - ESDS_STREAM_TYPE_AUDIO, codec_data, qtpad->avg_bitrate, - qtpad->max_bitrate); - } - entry.samples_per_packet = 1152; - entry.bytes_per_sample = 2; - break; + gst_structure_get_int (structure, "mpegaudioversion", + &mpegaudioversion); + + /* mp1/2/3 */ + /* note: QuickTime player does not like mp3 either way in iso/mp4 */ + if (format == GST_QT_MUX_FORMAT_QT) + entry.fourcc = FOURCC__mp3; + else { + entry.fourcc = FOURCC_mp4a; + ext_atom = + build_esds_extension (qtpad->trak, ESDS_OBJECT_TYPE_MPEG1_P3, + ESDS_STREAM_TYPE_AUDIO, codec_data, qtpad->avg_bitrate, + qtpad->max_bitrate); + } + if (layer == 1) { + g_warn_if_fail (format == GST_QT_MUX_FORMAT_MP4); + entry.samples_per_packet = 384; + } else if (layer == 2) { + g_warn_if_fail (format == GST_QT_MUX_FORMAT_MP4); + entry.samples_per_packet = 1152; + } else { + g_warn_if_fail (layer == 3); + entry.samples_per_packet = (mpegaudioversion <= 1) ? 1152 : 576; } + entry.bytes_per_sample = 2; break; case 4: diff --git a/gst/isomp4/gstqtmuxmap.c b/gst/isomp4/gstqtmuxmap.c index 61b11a4..5fabc92 100644 --- a/gst/isomp4/gstqtmuxmap.c +++ b/gst/isomp4/gstqtmuxmap.c @@ -104,6 +104,12 @@ "layer = (int) 3, " \ COMMON_AUDIO_CAPS (2, MAX) +#define MP123_CAPS \ + "audio/mpeg, " \ + "mpegversion = (int) 1, " \ + "layer = (int) [1, 3], " \ + COMMON_AUDIO_CAPS (2, MAX) + #define AAC_CAPS \ "audio/mpeg, " \ "mpegversion = (int) 4, " \ @@ -190,7 +196,7 @@ GstQTMuxFormatProp gst_qt_mux_format_list[] = { GST_STATIC_CAPS ("video/quicktime, variant = (string) iso"), GST_STATIC_CAPS (MPEG4V_CAPS "; " H264_CAPS ";" "video/x-mp4-part," COMMON_VIDEO_CAPS), - GST_STATIC_CAPS (MP3_CAPS "; " + GST_STATIC_CAPS (MP123_CAPS "; " AAC_CAPS " ; " AC3_CAPS " ; " ALAC_CAPS " ; " OPUS_CAPS), GST_STATIC_CAPS (TEXT_UTF8)} , -- 2.7.4