Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include <algorithm> | |
| 6 #include <string> | |
| 7 | |
| 8 #include "base/bind.h" | |
| 9 #include "base/bind_helpers.h" | |
| 10 #include "base/memory/ref_counted.h" | |
| 11 #include "base/move.h" | |
| 12 #include "base/time.h" | |
| 13 #include "base/logging.h" | |
|
acolwell GONE FROM CHROMIUM
2012/06/08 16:10:38
lint nit: alphabetical order.
strobe_
2012/06/11 18:44:21
Done.
| |
| 14 #include "media/base/audio_decoder_config.h" | |
| 15 #include "media/base/decoder_buffer.h" | |
| 16 #include "media/base/stream_parser_buffer.h" | |
| 17 #include "media/base/video_decoder_config.h" | |
| 18 #include "media/base/test_data_util.h" | |
|
acolwell GONE FROM CHROMIUM
2012/06/08 16:10:38
lint nit: alphabetical order.
strobe_
2012/06/11 18:44:21
Done.
| |
| 19 #include "media/mp4/mp4_stream_parser.h" | |
| 20 #include "testing/gtest/include/gtest/gtest.h" | |
| 21 | |
| 22 using base::TimeDelta; | |
| 23 | |
| 24 namespace media { | |
| 25 namespace mp4 { | |
| 26 | |
| 27 class MP4StreamParserTest : public testing::Test { | |
| 28 public: | |
| 29 MP4StreamParserTest() : parser_(new MP4StreamParser) {} | |
| 30 | |
| 31 protected: | |
| 32 scoped_ptr<MP4StreamParser> parser_; | |
| 33 | |
| 34 bool AppendData(const uint8* data, size_t length) { | |
| 35 parser_->Parse(data, length); | |
| 36 return true; | |
| 37 } | |
| 38 | |
| 39 bool AppendDataInPieces(const uint8* data, size_t length) { | |
| 40 return AppendDataInPieces(data, length, 7); | |
| 41 } | |
| 42 | |
| 43 bool AppendDataInPieces(const uint8* data, size_t length, size_t piece_size) { | |
| 44 const uint8* start = data; | |
| 45 const uint8* end = data + length; | |
| 46 while (start < end) { | |
| 47 size_t append_size = std::min(piece_size, | |
| 48 static_cast<size_t>(end - start)); | |
| 49 if (!AppendData(start, append_size)) | |
| 50 return false; | |
| 51 start += append_size; | |
| 52 } | |
| 53 return true; | |
| 54 } | |
| 55 | |
| 56 void InitF(bool init_ok, base::TimeDelta duration) { | |
| 57 DVLOG(1) << "InitF: ok=" << init_ok | |
| 58 << ", dur=" << duration.InMilliseconds(); | |
| 59 } | |
| 60 | |
| 61 bool NewConfigF(const AudioDecoderConfig& ac, | |
| 62 const VideoDecoderConfig& vc) { | |
| 63 DVLOG(1) << "NewConfigF: audio=" << ac.IsValidConfig() | |
| 64 << ", video=" << vc.IsValidConfig(); | |
| 65 return true; | |
| 66 } | |
| 67 | |
| 68 bool NewBuffersF(const StreamParser::BufferQueue& bufs) { | |
| 69 DVLOG(2) << "NewBuffersF: " << bufs.size() << " buffers"; | |
| 70 for (auto buf = bufs.begin(); buf != bufs.end(); buf++) { | |
| 71 DVLOG(3) << " n=" << buf - bufs.begin() | |
| 72 << ", size=" << (*buf)->GetDataSize() | |
| 73 << ", dur=" << (*buf)->GetDuration().InMilliseconds(); | |
| 74 } | |
| 75 return true; | |
| 76 } | |
| 77 | |
| 78 bool KeyNeededF(scoped_array<uint8> init_data, int init_data_size) { | |
| 79 DVLOG(1) << "KeyNeededF: " << init_data_size; | |
| 80 return true; | |
| 81 } | |
| 82 | |
| 83 void InitializeParser() { | |
| 84 parser_->Init( | |
| 85 base::Bind(&MP4StreamParserTest::InitF, base::Unretained(this)), | |
| 86 base::Bind(&MP4StreamParserTest::NewConfigF, base::Unretained(this)), | |
| 87 base::Bind(&MP4StreamParserTest::NewBuffersF, base::Unretained(this)), | |
| 88 base::Bind(&MP4StreamParserTest::NewBuffersF, base::Unretained(this)), | |
| 89 base::Bind(&MP4StreamParserTest::KeyNeededF, base::Unretained(this))); | |
| 90 } | |
| 91 | |
| 92 bool ParseMP4File(const std::string& filename, | |
| 93 const base::TimeDelta& duration) { | |
| 94 InitializeParser(); | |
| 95 | |
| 96 scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile(filename); | |
| 97 EXPECT_TRUE(AppendDataInPieces(buffer->GetData(), | |
| 98 buffer->GetDataSize(), | |
| 99 512)); | |
| 100 return true; | |
| 101 } | |
| 102 }; | |
| 103 | |
| 104 TEST_F(MP4StreamParserTest, TestParseVideo) { | |
| 105 ParseMP4File("google_track1_dash.mp4", | |
| 106 base::TimeDelta::FromMilliseconds(0)); | |
| 107 } | |
| 108 | |
| 109 TEST_F(MP4StreamParserTest, TestParseAudio) { | |
| 110 ParseMP4File("google_track2_dash.mp4", | |
| 111 base::TimeDelta::FromMilliseconds(0)); | |
| 112 } | |
| 113 | |
| 114 // Avoid logspam while encryption is known to be broken | |
| 115 /* | |
| 116 TEST_F(MP4StreamParserTest, TestParseAudioCENC) { | |
| 117 ParseMP4File("dash_audio_cenc_gold.mp4", | |
| 118 base::TimeDelta::FromMilliseconds(0)); | |
| 119 } | |
| 120 | |
| 121 TEST_F(MP4StreamParserTest, TestParseVideoCENC) { | |
| 122 ParseMP4File("dash_video_cenc_gold.mp4", | |
| 123 base::TimeDelta::FromMilliseconds(0)); | |
| 124 } | |
| 125 */ | |
| 126 | |
| 127 TEST_F(MP4StreamParserTest, TestParseAudioClear) { | |
| 128 ParseMP4File("dash_audio_clear.mp4", | |
| 129 base::TimeDelta::FromMilliseconds(0)); | |
| 130 } | |
| 131 | |
| 132 TEST_F(MP4StreamParserTest, TestParseVideoClear) { | |
| 133 ParseMP4File("dash_video_clear.mp4", | |
| 134 base::TimeDelta::FromMilliseconds(0)); | |
| 135 } | |
| 136 | |
| 137 } // namespace mp4 | |
| 138 } // namespace media | |
| OLD | NEW |