From 39d32b239490bd13bd58548d16f7df881a282771 Mon Sep 17 00:00:00 2001 From: Charlie Turner Date: Thu, 7 Feb 2019 11:58:19 +0000 Subject: [PATCH] qtdemux: Find mp4a esds atoms in protected streams sample description tables. This problem was found in Test. 2 of the YouTube 2018 EME tests[1]. The code was accidentally not finding an mp4a's esds atom in the sample description table when the stream was encrypted. It assumed that if the stream is protected, then only an enca atom will be found here. What happens with YouTube is they often provide protected content with a few seconds of clear content, and then switch to the encrypted stream. The failure case here was an incorrect codec_data field being sent into aacparse. The advertisement of stereo audio @ 44.1kHz for the mp4a (unprotected) stream was incorrect. As usual, the esds contained the real values here which were mono at 22050 Hz. Here's what the MP4 tree looks like for these types of files, demonstrating why the code was making a wrong assumption (or maybe YouTube is being unusual), [ftyp] size=8+16 ... [moov] size=8+1571 ... [trak] size=8+559 ... [stsd] size=12+234 entry-count = 2 [enca] size=8+147 channel_count = 2 sample_size = 16 sample_rate = 44100 [esds] size=12+27 ... ... [mp4a] size=8+67 channel_count = 2 sample_size = 16 sample_rate = 44100 [esds] size=12+27 ... In addition to fixing this, the checks for esds atoms in mp4a and mp4v have been made symmetrical. While I haven't seen a test case for video with the same problem, it seemed better to make the same checks. This also fixes a crash reported from another user[2], they also noted the asymmetry with mp4v and mp4a. [1] https://yt-dash-mse-test.commondatastorage.googleapis.com/unit-tests/2018.html?test_type=encryptedmedia-test [2] https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/issues/398 --- gst/isomp4/qtdemux.c | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/gst/isomp4/qtdemux.c b/gst/isomp4/qtdemux.c index 5476d0e24a..502085ba5e 100644 --- a/gst/isomp4/qtdemux.c +++ b/gst/isomp4/qtdemux.c @@ -10852,14 +10852,17 @@ qtdemux_parse_trak (GstQTDemux * qtdemux, GNode * trak) fiel = NULL; /* pick 'the' stsd child */ mp4v = qtdemux_tree_get_child_by_index (stsd, stsd_index); - if (!stream->protected) { - if (QTDEMUX_TREE_NODE_FOURCC (mp4v) != fourcc) { + // We should skip parsing the stsd for non-protected streams if + // the entry doesn't match the fourcc, since they don't change + // format. However, for protected streams we can have partial + // encryption, where parts of the stream are encrypted and parts + // not. For both parts of such streams, we should ensure the + // esds overrides are parsed for both from the stsd. + if (QTDEMUX_TREE_NODE_FOURCC (mp4v) != fourcc) { + if (stream->protected && QTDEMUX_TREE_NODE_FOURCC (mp4v) != FOURCC_encv) mp4v = NULL; - } - } else { - if (QTDEMUX_TREE_NODE_FOURCC (mp4v) != FOURCC_encv) { + else if (!stream->protected) mp4v = NULL; - } } if (mp4v) { @@ -12043,20 +12046,11 @@ qtdemux_parse_trak (GstQTDemux * qtdemux, GNode * trak) } mp4a = qtdemux_tree_get_child_by_index (stsd, stsd_index); - if (!stream->protected) { - } else { - if (QTDEMUX_TREE_NODE_FOURCC (mp4v) != FOURCC_encv) { - mp4v = NULL; - } - } - if (stream->protected && fourcc == FOURCC_mp4a) { - if (QTDEMUX_TREE_NODE_FOURCC (mp4a) != FOURCC_enca) { + if (QTDEMUX_TREE_NODE_FOURCC (mp4a) != fourcc) { + if (stream->protected && QTDEMUX_TREE_NODE_FOURCC (mp4a) != FOURCC_enca) mp4a = NULL; - } - } else { - if (QTDEMUX_TREE_NODE_FOURCC (mp4a) != FOURCC_mp4a) { + else if (!stream->protected) mp4a = NULL; - } } wave = NULL;