diff options
author | acolwell@chromium.org <acolwell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-08 04:22:21 +0000 |
---|---|---|
committer | acolwell@chromium.org <acolwell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-08 04:22:21 +0000 |
commit | 2ef9960c1302cdb0ef78ed54957fda504fe9681d (patch) | |
tree | 3efa4701c6b78527c8600bcb304d133f14bca31c /media/mp4 | |
parent | f306c41f3250a2c66170e2b9951797ba1e38a0cd (diff) | |
download | chromium_src-2ef9960c1302cdb0ef78ed54957fda504fe9681d.zip chromium_src-2ef9960c1302cdb0ef78ed54957fda504fe9681d.tar.gz chromium_src-2ef9960c1302cdb0ef78ed54957fda504fe9681d.tar.bz2 |
Log MediaSource parsing errors to the MediaLog so they can appear in chrome:media-internals.
BUG=164673
Review URL: https://chromiumcodereview.appspot.com/11471006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@171936 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/mp4')
-rw-r--r-- | media/mp4/box_reader.cc | 23 | ||||
-rw-r--r-- | media/mp4/box_reader.h | 11 | ||||
-rw-r--r-- | media/mp4/box_reader_unittest.cc | 12 | ||||
-rw-r--r-- | media/mp4/mp4_stream_parser.cc | 24 | ||||
-rw-r--r-- | media/mp4/mp4_stream_parser.h | 4 | ||||
-rw-r--r-- | media/mp4/mp4_stream_parser_unittest.cc | 3 | ||||
-rw-r--r-- | media/mp4/track_run_iterator.cc | 8 | ||||
-rw-r--r-- | media/mp4/track_run_iterator.h | 4 | ||||
-rw-r--r-- | media/mp4/track_run_iterator_unittest.cc | 21 |
9 files changed, 66 insertions, 44 deletions
diff --git a/media/mp4/box_reader.cc b/media/mp4/box_reader.cc index 1285ebf..71d93a0 100644 --- a/media/mp4/box_reader.cc +++ b/media/mp4/box_reader.cc @@ -79,8 +79,10 @@ bool BufferReader::Read4sInto8s(int64* v) { } -BoxReader::BoxReader(const uint8* buf, const int size) +BoxReader::BoxReader(const uint8* buf, const int size, + const LogCB& log_cb) : BufferReader(buf, size), + log_cb_(log_cb), type_(FOURCC_NULL), version_(0), flags_(0), @@ -99,12 +101,13 @@ BoxReader::~BoxReader() { // static BoxReader* BoxReader::ReadTopLevelBox(const uint8* buf, const int buf_size, + const LogCB& log_cb, bool* err) { - scoped_ptr<BoxReader> reader(new BoxReader(buf, buf_size)); + scoped_ptr<BoxReader> reader(new BoxReader(buf, buf_size, log_cb)); if (!reader->ReadHeader(err)) return NULL; - if (!IsValidTopLevelBox(reader->type())) { + if (!IsValidTopLevelBox(reader->type(), log_cb)) { *err = true; return NULL; } @@ -118,12 +121,13 @@ BoxReader* BoxReader::ReadTopLevelBox(const uint8* buf, // static bool BoxReader::StartTopLevelBox(const uint8* buf, const int buf_size, + const LogCB& log_cb, FourCC* type, int* box_size, bool* err) { - BoxReader reader(buf, buf_size); + BoxReader reader(buf, buf_size, log_cb); if (!reader.ReadHeader(err)) return false; - if (!IsValidTopLevelBox(reader.type())) { + if (!IsValidTopLevelBox(reader.type(), log_cb)) { *err = true; return false; } @@ -133,7 +137,8 @@ bool BoxReader::StartTopLevelBox(const uint8* buf, } // static -bool BoxReader::IsValidTopLevelBox(const FourCC& type) { +bool BoxReader::IsValidTopLevelBox(const FourCC& type, + const LogCB& log_cb) { switch (type) { case FOURCC_FTYP: case FOURCC_PDIN: @@ -152,8 +157,8 @@ bool BoxReader::IsValidTopLevelBox(const FourCC& type) { return true; default: // Hex is used to show nonprintable characters and aid in debugging - LOG(WARNING) << "Unrecognized top-level box type 0x" - << std::hex << type; + MEDIA_LOG(log_cb) << "Unrecognized top-level box type 0x" + << std::hex << type; return false; } } @@ -164,7 +169,7 @@ bool BoxReader::ScanChildren() { bool err = false; while (pos() < size()) { - BoxReader child(&buf_[pos_], size_ - pos_); + BoxReader child(&buf_[pos_], size_ - pos_, log_cb_); if (!child.ReadHeader(&err)) break; children_.insert(std::pair<FourCC, BoxReader>(child.type(), child)); diff --git a/media/mp4/box_reader.h b/media/mp4/box_reader.h index bcc3200..43f11d56 100644 --- a/media/mp4/box_reader.h +++ b/media/mp4/box_reader.h @@ -11,6 +11,7 @@ #include "base/compiler_specific.h" #include "base/logging.h" #include "media/base/media_export.h" +#include "media/base/media_log.h" #include "media/mp4/fourccs.h" #include "media/mp4/rcheck.h" @@ -78,6 +79,7 @@ class MEDIA_EXPORT BoxReader : public BufferReader { // |buf| is retained but not owned, and must outlive the BoxReader instance. static BoxReader* ReadTopLevelBox(const uint8* buf, const int buf_size, + const LogCB& log_cb, bool* err); // Read the box header from the current buffer. This function returns true if @@ -88,6 +90,7 @@ class MEDIA_EXPORT BoxReader : public BufferReader { // |buf| is not retained. static bool StartTopLevelBox(const uint8* buf, const int buf_size, + const LogCB& log_cb, FourCC* type, int* box_size, bool* err) WARN_UNUSED_RESULT; @@ -95,7 +98,8 @@ class MEDIA_EXPORT BoxReader : public BufferReader { // Returns true if |type| is recognized to be a top-level box, false // otherwise. This returns true for some boxes which we do not parse. // Helpful in debugging misaligned appends. - static bool IsValidTopLevelBox(const FourCC& type); + static bool IsValidTopLevelBox(const FourCC& type, + const LogCB& log_cb); // Scan through all boxes within the current box, starting at the current // buffer position. Must be called before any of the *Child functions work. @@ -133,7 +137,7 @@ class MEDIA_EXPORT BoxReader : public BufferReader { uint32 flags() const { return flags_; } private: - BoxReader(const uint8* buf, const int size); + BoxReader(const uint8* buf, const int size, const LogCB& log_cb); // Must be called immediately after init. If the return is false, this // indicates that the box header and its contents were not available in the @@ -144,6 +148,7 @@ class MEDIA_EXPORT BoxReader : public BufferReader { // true, the error is unrecoverable and the stream should be aborted. bool ReadHeader(bool* err); + LogCB log_cb_; FourCC type_; uint8 version_; uint32 flags_; @@ -192,7 +197,7 @@ bool BoxReader::ReadAllChildren(std::vector<T>* children) { bool err = false; while (pos() < size()) { - BoxReader child_reader(&buf_[pos_], size_ - pos_); + BoxReader child_reader(&buf_[pos_], size_ - pos_, log_cb_); if (!child_reader.ReadHeader(&err)) break; T child; RCHECK(child.Parse(&child_reader)); diff --git a/media/mp4/box_reader_unittest.cc b/media/mp4/box_reader_unittest.cc index 38fd896..419b5af 100644 --- a/media/mp4/box_reader_unittest.cc +++ b/media/mp4/box_reader_unittest.cc @@ -86,7 +86,7 @@ TEST_F(BoxReaderTest, ExpectedOperationTest) { std::vector<uint8> buf = GetBuf(); bool err; scoped_ptr<BoxReader> reader( - BoxReader::ReadTopLevelBox(&buf[0], buf.size(), &err)); + BoxReader::ReadTopLevelBox(&buf[0], buf.size(), LogCB(), &err)); EXPECT_FALSE(err); EXPECT_TRUE(reader.get()); @@ -114,7 +114,7 @@ TEST_F(BoxReaderTest, OuterTooShortTest) { // Create a soft failure by truncating the outer box. scoped_ptr<BoxReader> r( - BoxReader::ReadTopLevelBox(&buf[0], buf.size() - 2, &err)); + BoxReader::ReadTopLevelBox(&buf[0], buf.size() - 2, LogCB(), &err)); EXPECT_FALSE(err); EXPECT_FALSE(r.get()); @@ -127,7 +127,7 @@ TEST_F(BoxReaderTest, InnerTooLongTest) { // Make an inner box too big for its outer box. buf[25] = 1; scoped_ptr<BoxReader> reader( - BoxReader::ReadTopLevelBox(&buf[0], buf.size(), &err)); + BoxReader::ReadTopLevelBox(&buf[0], buf.size(), LogCB(), &err)); SkipBox box; EXPECT_FALSE(box.Parse(reader.get())); @@ -140,7 +140,7 @@ TEST_F(BoxReaderTest, WrongFourCCTest) { // Set an unrecognized top-level FourCC. buf[5] = 1; scoped_ptr<BoxReader> reader( - BoxReader::ReadTopLevelBox(&buf[0], buf.size(), &err)); + BoxReader::ReadTopLevelBox(&buf[0], buf.size(), LogCB(), &err)); EXPECT_FALSE(reader.get()); EXPECT_TRUE(err); } @@ -149,7 +149,7 @@ TEST_F(BoxReaderTest, ScanChildrenTest) { std::vector<uint8> buf = GetBuf(); bool err; scoped_ptr<BoxReader> reader( - BoxReader::ReadTopLevelBox(&buf[0], buf.size(), &err)); + BoxReader::ReadTopLevelBox(&buf[0], buf.size(), LogCB(), &err)); EXPECT_TRUE(reader->SkipBytes(16) && reader->ScanChildren()); @@ -173,7 +173,7 @@ TEST_F(BoxReaderTest, ReadAllChildrenTest) { buf[3] = 0x38; bool err; scoped_ptr<BoxReader> reader( - BoxReader::ReadTopLevelBox(&buf[0], buf.size(), &err)); + BoxReader::ReadTopLevelBox(&buf[0], buf.size(), LogCB(), &err)); std::vector<PsshBox> kids; EXPECT_TRUE(reader->SkipBytes(16) && reader->ReadAllChildren(&kids)); diff --git a/media/mp4/mp4_stream_parser.cc b/media/mp4/mp4_stream_parser.cc index 3546be9..69a35f2 100644 --- a/media/mp4/mp4_stream_parser.cc +++ b/media/mp4/mp4_stream_parser.cc @@ -42,7 +42,8 @@ void MP4StreamParser::Init(const InitCB& init_cb, const NewBuffersCB& video_cb, const NeedKeyCB& need_key_cb, const NewMediaSegmentCB& new_segment_cb, - const base::Closure& end_of_segment_cb) { + const base::Closure& end_of_segment_cb, + const LogCB& log_cb) { DCHECK_EQ(state_, kWaitingForInit); DCHECK(init_cb_.is_null()); DCHECK(!init_cb.is_null()); @@ -59,6 +60,7 @@ void MP4StreamParser::Init(const InitCB& init_cb, need_key_cb_ = need_key_cb; new_segment_cb_ = new_segment_cb; end_of_segment_cb_ = end_of_segment_cb; + log_cb_ = log_cb; } void MP4StreamParser::Reset() { @@ -120,7 +122,8 @@ bool MP4StreamParser::ParseBox(bool* err) { queue_.Peek(&buf, &size); if (!size) return false; - scoped_ptr<BoxReader> reader(BoxReader::ReadTopLevelBox(buf, size, err)); + scoped_ptr<BoxReader> reader( + BoxReader::ReadTopLevelBox(buf, size, log_cb_, err)); if (reader.get() == NULL) return false; if (reader->type() == FOURCC_MOOV) { @@ -138,8 +141,8 @@ bool MP4StreamParser::ParseBox(bool* err) { // before the head of the 'moof', so keeping this box around is sufficient.) return !(*err); } else { - DVLOG(2) << "Skipping unrecognized top-level box: " - << FourCCToString(reader->type()); + MEDIA_LOG(log_cb_) << "Skipping unrecognized top-level box: " + << FourCCToString(reader->type()); } queue_.Pop(reader->size()); @@ -150,7 +153,7 @@ bool MP4StreamParser::ParseBox(bool* err) { bool MP4StreamParser::ParseMoov(BoxReader* reader) { moov_.reset(new Movie); RCHECK(moov_->Parse(reader)); - runs_.reset(new TrackRunIterator(moov_.get())); + runs_.reset(new TrackRunIterator(moov_.get(), log_cb_)); has_audio_ = false; has_video_ = false; @@ -412,7 +415,7 @@ bool MP4StreamParser::EnqueueSample(BufferQueue* audio_buffers, if (video) { if (!PrepareAVCBuffer(runs_->video_description().avcc, &frame_buf, &subsamples)) { - DLOG(ERROR) << "Failed to prepare AVC sample for decode"; + MEDIA_LOG(log_cb_) << "Failed to prepare AVC sample for decode"; *err = true; return false; } @@ -421,7 +424,7 @@ bool MP4StreamParser::EnqueueSample(BufferQueue* audio_buffers, if (audio) { if (!PrepareAACBuffer(runs_->audio_description().esds.aac, &frame_buf, &subsamples)) { - DLOG(ERROR) << "Failed to prepare AAC sample for decode"; + MEDIA_LOG(log_cb_) << "Failed to prepare AAC sample for decode"; *err = true; return false; } @@ -486,12 +489,13 @@ bool MP4StreamParser::ReadAndDiscardMDATsUntil(const int64 offset) { FourCC type; int box_sz; - if (!BoxReader::StartTopLevelBox(buf, size, &type, &box_sz, &err)) + if (!BoxReader::StartTopLevelBox(buf, size, log_cb_, + &type, &box_sz, &err)) break; if (type != FOURCC_MDAT) { - DLOG(WARNING) << "Unexpected box type while parsing MDATs: " - << FourCCToString(type); + MEDIA_LOG(log_cb_) << "Unexpected box type while parsing MDATs: " + << FourCCToString(type); } mdat_tail_ += box_sz; } diff --git a/media/mp4/mp4_stream_parser.h b/media/mp4/mp4_stream_parser.h index 41b8272..292f628 100644 --- a/media/mp4/mp4_stream_parser.h +++ b/media/mp4/mp4_stream_parser.h @@ -32,7 +32,8 @@ class MEDIA_EXPORT MP4StreamParser : public StreamParser { const NewBuffersCB& video_cb, const NeedKeyCB& need_key_cb, const NewMediaSegmentCB& new_segment_cb, - const base::Closure& end_of_segment_cb) OVERRIDE; + const base::Closure& end_of_segment_cb, + const LogCB& log_cb) OVERRIDE; virtual void Flush() OVERRIDE; virtual bool Parse(const uint8* buf, int size) OVERRIDE; @@ -85,6 +86,7 @@ class MEDIA_EXPORT MP4StreamParser : public StreamParser { NeedKeyCB need_key_cb_; NewMediaSegmentCB new_segment_cb_; base::Closure end_of_segment_cb_; + LogCB log_cb_; OffsetByteQueue queue_; diff --git a/media/mp4/mp4_stream_parser_unittest.cc b/media/mp4/mp4_stream_parser_unittest.cc index 81dbdd8..66f3410 100644 --- a/media/mp4/mp4_stream_parser_unittest.cc +++ b/media/mp4/mp4_stream_parser_unittest.cc @@ -106,7 +106,8 @@ class MP4StreamParserTest : public testing::Test { base::Bind(&MP4StreamParserTest::KeyNeededF, base::Unretained(this)), base::Bind(&MP4StreamParserTest::NewSegmentF, base::Unretained(this)), base::Bind(&MP4StreamParserTest::EndOfSegmentF, - base::Unretained(this))); + base::Unretained(this)), + LogCB()); } bool ParseMP4File(const std::string& filename, int append_bytes) { diff --git a/media/mp4/track_run_iterator.cc b/media/mp4/track_run_iterator.cc index 36ec206..5538562 100644 --- a/media/mp4/track_run_iterator.cc +++ b/media/mp4/track_run_iterator.cc @@ -62,10 +62,12 @@ TimeDelta TimeDeltaFromRational(int64 numer, int64 denom) { base::Time::kMicrosecondsPerSecond * numer / denom); } -TrackRunIterator::TrackRunIterator(const Movie* moov) - : moov_(moov), sample_offset_(0) { +TrackRunIterator::TrackRunIterator(const Movie* moov, + const LogCB& log_cb) + : moov_(moov), log_cb_(log_cb), sample_offset_(0) { CHECK(moov); } + TrackRunIterator::~TrackRunIterator() {} static void PopulateSampleInfo(const TrackExtends& trex, @@ -430,7 +432,7 @@ scoped_ptr<DecryptConfig> TrackRunIterator::GetDecryptConfig() { if (!cenc_info.subsamples.empty() && (cenc_info.GetTotalSizeOfSubsamples() != static_cast<size_t>(sample_size()))) { - DVLOG(1) << "Incorrect CENC subsample size."; + MEDIA_LOG(log_cb_) << "Incorrect CENC subsample size."; return scoped_ptr<DecryptConfig>(); } diff --git a/media/mp4/track_run_iterator.h b/media/mp4/track_run_iterator.h index 85cadce..1e083ca 100644 --- a/media/mp4/track_run_iterator.h +++ b/media/mp4/track_run_iterator.h @@ -10,6 +10,7 @@ #include "base/memory/scoped_ptr.h" #include "base/time.h" #include "media/base/media_export.h" +#include "media/base/media_log.h" #include "media/mp4/box_definitions.h" #include "media/mp4/cenc.h" @@ -29,7 +30,7 @@ class MEDIA_EXPORT TrackRunIterator { public: // Create a new TrackRunIterator. A reference to |moov| will be retained for // the lifetime of this object. - explicit TrackRunIterator(const Movie* moov); + TrackRunIterator(const Movie* moov, const LogCB& log_cb); ~TrackRunIterator(); void Reset(); @@ -92,6 +93,7 @@ class MEDIA_EXPORT TrackRunIterator { const TrackEncryption& track_encryption() const; const Movie* moov_; + LogCB log_cb_; std::vector<TrackRunInfo> runs_; std::vector<TrackRunInfo>::const_iterator run_itr_; diff --git a/media/mp4/track_run_iterator_unittest.cc b/media/mp4/track_run_iterator_unittest.cc index 40385cc..c0cbbe6 100644 --- a/media/mp4/track_run_iterator_unittest.cc +++ b/media/mp4/track_run_iterator_unittest.cc @@ -48,6 +48,7 @@ class TrackRunIteratorTest : public testing::Test { protected: Movie moov_; + LogCB log_cb_; scoped_ptr<TrackRunIterator> iter_; void CreateMovie() { @@ -153,14 +154,14 @@ class TrackRunIteratorTest : public testing::Test { }; TEST_F(TrackRunIteratorTest, NoRunsTest) { - iter_.reset(new TrackRunIterator(&moov_)); + iter_.reset(new TrackRunIterator(&moov_, log_cb_)); ASSERT_TRUE(iter_->Init(MovieFragment())); EXPECT_FALSE(iter_->IsRunValid()); EXPECT_FALSE(iter_->IsSampleValid()); } TEST_F(TrackRunIteratorTest, BasicOperationTest) { - iter_.reset(new TrackRunIterator(&moov_)); + iter_.reset(new TrackRunIterator(&moov_, log_cb_)); MovieFragment moof = CreateFragment(); // Test that runs are sorted correctly, and that properties of the initial @@ -218,7 +219,7 @@ TEST_F(TrackRunIteratorTest, TrackExtendsDefaultsTest) { moov_.extends.tracks[0].default_sample_size = 3; moov_.extends.tracks[0].default_sample_flags = kSampleIsDifferenceSampleFlagMask; - iter_.reset(new TrackRunIterator(&moov_)); + iter_.reset(new TrackRunIterator(&moov_, log_cb_)); MovieFragment moof = CreateFragment(); moof.tracks[0].header.has_default_sample_flags = false; moof.tracks[0].header.default_sample_size = 0; @@ -237,7 +238,7 @@ TEST_F(TrackRunIteratorTest, FirstSampleFlagTest) { // Ensure that keyframes are flagged correctly in the face of BMFF boxes which // explicitly specify the flags for the first sample in a run and rely on // defaults for all subsequent samples - iter_.reset(new TrackRunIterator(&moov_)); + iter_.reset(new TrackRunIterator(&moov_, log_cb_)); MovieFragment moof = CreateFragment(); moof.tracks[1].header.has_default_sample_flags = true; moof.tracks[1].header.default_sample_flags = @@ -251,7 +252,7 @@ TEST_F(TrackRunIteratorTest, FirstSampleFlagTest) { } TEST_F(TrackRunIteratorTest, MinDecodeTest) { - iter_.reset(new TrackRunIterator(&moov_)); + iter_.reset(new TrackRunIterator(&moov_, log_cb_)); MovieFragment moof = CreateFragment(); moof.tracks[0].decode_time.decode_time = kAudioScale; ASSERT_TRUE(iter_->Init(moof)); @@ -276,7 +277,7 @@ TEST_F(TrackRunIteratorTest, ReorderingTest) { // (that is, 2 / kVideoTimescale) and a duration of zero (which is treated as // infinite according to 14496-12:2012). This will cause the first 80ms of the // media timeline - which will be empty, due to CTS biasing - to be discarded. - iter_.reset(new TrackRunIterator(&moov_)); + iter_.reset(new TrackRunIterator(&moov_, log_cb_)); EditListEntry entry; entry.segment_duration = 0; entry.media_time = 2; @@ -313,7 +314,7 @@ TEST_F(TrackRunIteratorTest, ReorderingTest) { } TEST_F(TrackRunIteratorTest, IgnoreUnknownAuxInfoTest) { - iter_.reset(new TrackRunIterator(&moov_)); + iter_.reset(new TrackRunIterator(&moov_, log_cb_)); MovieFragment moof = CreateFragment(); moof.tracks[1].auxiliary_offset.offsets.push_back(50); moof.tracks[1].auxiliary_size.default_sample_info_size = 2; @@ -326,7 +327,7 @@ TEST_F(TrackRunIteratorTest, IgnoreUnknownAuxInfoTest) { TEST_F(TrackRunIteratorTest, DecryptConfigTest) { AddEncryption(&moov_.tracks[1]); - iter_.reset(new TrackRunIterator(&moov_)); + iter_.reset(new TrackRunIterator(&moov_, log_cb_)); MovieFragment moof = CreateFragment(); AddAuxInfoHeaders(50, &moof.tracks[1]); @@ -366,7 +367,7 @@ TEST_F(TrackRunIteratorTest, DecryptConfigTest) { TEST_F(TrackRunIteratorTest, SharedAuxInfoTest) { AddEncryption(&moov_.tracks[0]); AddEncryption(&moov_.tracks[1]); - iter_.reset(new TrackRunIterator(&moov_)); + iter_.reset(new TrackRunIterator(&moov_, log_cb_)); MovieFragment moof = CreateFragment(); moof.tracks[0].runs.resize(1); @@ -408,7 +409,7 @@ TEST_F(TrackRunIteratorTest, SharedAuxInfoTest) { TEST_F(TrackRunIteratorTest, UnexpectedOrderingTest) { AddEncryption(&moov_.tracks[0]); AddEncryption(&moov_.tracks[1]); - iter_.reset(new TrackRunIterator(&moov_)); + iter_.reset(new TrackRunIterator(&moov_, log_cb_)); MovieFragment moof = CreateFragment(); AddAuxInfoHeaders(20000, &moof.tracks[0]); |