From 9476e826d56e2450ae498f9469d3e517e5d2fd46 Mon Sep 17 00:00:00 2001 From: KongQun Yang Date: Thu, 1 Mar 2018 08:18:22 -0800 Subject: [PATCH] Skip reading meta box as it may not be well formed In the video captured by Android's default camera app, meta box is written as as Box instead of FullBox specified in the spec. Closes #319. Change-Id: I526492fdd505d5929c5161cb1ed1503b724de7e9 --- packager/media/formats/mp4/box_definitions.cc | 16 ++++++++++------ packager/media/formats/mp4/box_reader.cc | 2 ++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/packager/media/formats/mp4/box_definitions.cc b/packager/media/formats/mp4/box_definitions.cc index 331c0c2fb9..3602031c1c 100644 --- a/packager/media/formats/mp4/box_definitions.cc +++ b/packager/media/formats/mp4/box_definitions.cc @@ -2230,17 +2230,21 @@ Movie::~Movie() {} FourCC Movie::BoxType() const { return FOURCC_moov; } bool Movie::ReadWriteInternal(BoxBuffer* buffer) { - RCHECK(ReadWriteHeaderInternal(buffer) && - buffer->PrepareChildren() && - buffer->ReadWriteChild(&header) && - buffer->TryReadWriteChild(&metadata)); + RCHECK(ReadWriteHeaderInternal(buffer) && buffer->PrepareChildren() && + buffer->ReadWriteChild(&header)); if (buffer->Reading()) { BoxReader* reader = buffer->reader(); DCHECK(reader); - RCHECK(reader->ReadChildren(&tracks) && - reader->TryReadChild(&extends) && + RCHECK(reader->ReadChildren(&tracks) && reader->TryReadChild(&extends) && reader->TryReadChildren(&pssh)); } else { + // The 'meta' box is not well formed in the video captured by Android's + // default camera app: spec indicates that it is a FullBox but it is written + // as a Box. This results in the box failed to be parsed. See + // https://github.com/google/shaka-packager/issues/319 for details. + // We do not care the content of metadata box in the source content, so just + // skip reading the box. + RCHECK(buffer->TryReadWriteChild(&metadata)); for (uint32_t i = 0; i < tracks.size(); ++i) RCHECK(buffer->ReadWriteChild(&tracks[i])); RCHECK(buffer->TryReadWriteChild(&extends)); diff --git a/packager/media/formats/mp4/box_reader.cc b/packager/media/formats/mp4/box_reader.cc index b673e7304f..424a1cc546 100644 --- a/packager/media/formats/mp4/box_reader.cc +++ b/packager/media/formats/mp4/box_reader.cc @@ -79,6 +79,8 @@ bool BoxReader::ScanChildren() { size_t box_size = child->size(); children_.insert(std::pair>( box_type, std::move(child))); + VLOG(2) << "Child " << FourCCToString(box_type) << " size 0x" << std::hex + << box_size << std::dec; RCHECK(SkipBytes(box_size)); }