| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <algorithm> | 5 #include <algorithm> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 using base::TimeDelta; | 22 using base::TimeDelta; |
| 23 | 23 |
| 24 namespace media { | 24 namespace media { |
| 25 namespace mp4 { | 25 namespace mp4 { |
| 26 | 26 |
| 27 class MP4StreamParserTest : public testing::Test { | 27 class MP4StreamParserTest : public testing::Test { |
| 28 public: | 28 public: |
| 29 MP4StreamParserTest() | 29 MP4StreamParserTest() |
| 30 : parser_(new MP4StreamParser), | 30 : parser_(new MP4StreamParser), |
| 31 got_configs_(false) { | 31 configs_received_(false) { |
| 32 } | 32 } |
| 33 | 33 |
| 34 protected: | 34 protected: |
| 35 scoped_ptr<MP4StreamParser> parser_; | 35 scoped_ptr<MP4StreamParser> parser_; |
| 36 base::TimeDelta segment_start_; | 36 base::TimeDelta segment_start_; |
| 37 bool got_configs_; | 37 bool configs_received_; |
| 38 | 38 |
| 39 bool AppendData(const uint8* data, size_t length) { | 39 bool AppendData(const uint8* data, size_t length) { |
| 40 parser_->Parse(data, length); | 40 return parser_->Parse(data, length); |
| 41 return true; | |
| 42 } | |
| 43 | |
| 44 bool AppendDataInPieces(const uint8* data, size_t length) { | |
| 45 return AppendDataInPieces(data, length, 7); | |
| 46 } | 41 } |
| 47 | 42 |
| 48 bool AppendDataInPieces(const uint8* data, size_t length, size_t piece_size) { | 43 bool AppendDataInPieces(const uint8* data, size_t length, size_t piece_size) { |
| 49 const uint8* start = data; | 44 const uint8* start = data; |
| 50 const uint8* end = data + length; | 45 const uint8* end = data + length; |
| 51 while (start < end) { | 46 while (start < end) { |
| 52 size_t append_size = std::min(piece_size, | 47 size_t append_size = std::min(piece_size, |
| 53 static_cast<size_t>(end - start)); | 48 static_cast<size_t>(end - start)); |
| 54 if (!AppendData(start, append_size)) | 49 if (!AppendData(start, append_size)) |
| 55 return false; | 50 return false; |
| 56 start += append_size; | 51 start += append_size; |
| 57 } | 52 } |
| 58 return true; | 53 return true; |
| 59 } | 54 } |
| 60 | 55 |
| 61 void InitF(bool init_ok, base::TimeDelta duration) { | 56 void InitF(bool init_ok, base::TimeDelta duration) { |
| 62 DVLOG(1) << "InitF: ok=" << init_ok | 57 DVLOG(1) << "InitF: ok=" << init_ok |
| 63 << ", dur=" << duration.InMilliseconds(); | 58 << ", dur=" << duration.InMilliseconds(); |
| 64 } | 59 } |
| 65 | 60 |
| 66 bool NewConfigF(const AudioDecoderConfig& ac, | 61 bool NewConfigF(const AudioDecoderConfig& ac, |
| 67 const VideoDecoderConfig& vc) { | 62 const VideoDecoderConfig& vc) { |
| 68 DVLOG(1) << "NewConfigF: audio=" << ac.IsValidConfig() | 63 DVLOG(1) << "NewConfigF: audio=" << ac.IsValidConfig() |
| 69 << ", video=" << vc.IsValidConfig(); | 64 << ", video=" << vc.IsValidConfig(); |
| 70 | 65 |
| 71 // TODO(strobe): Until http://crbug.com/122913 is fixed, we want to make | 66 // TODO(strobe): Until http://crbug.com/122913 is fixed, we want to make |
| 72 // sure that this callback isn't called more than once per stream. Remove | 67 // sure that this callback isn't called more than once per stream. Remove |
| 73 // when that bug is fixed. | 68 // when that bug is fixed. |
| 74 EXPECT_FALSE(got_configs_); | 69 EXPECT_FALSE(configs_received_); |
| 75 got_configs_ = true; | 70 configs_received_ = true; |
| 76 return true; | 71 return true; |
| 77 } | 72 } |
| 78 | 73 |
| 79 bool NewBuffersF(const StreamParser::BufferQueue& bufs) { | 74 bool NewBuffersF(const StreamParser::BufferQueue& bufs) { |
| 80 DVLOG(2) << "NewBuffersF: " << bufs.size() << " buffers"; | 75 DVLOG(2) << "NewBuffersF: " << bufs.size() << " buffers"; |
| 81 for (StreamParser::BufferQueue::const_iterator buf = bufs.begin(); | 76 for (StreamParser::BufferQueue::const_iterator buf = bufs.begin(); |
| 82 buf != bufs.end(); buf++) { | 77 buf != bufs.end(); buf++) { |
| 83 DVLOG(3) << " n=" << buf - bufs.begin() | 78 DVLOG(3) << " n=" << buf - bufs.begin() |
| 84 << ", size=" << (*buf)->GetDataSize() | 79 << ", size=" << (*buf)->GetDataSize() |
| 85 << ", dur=" << (*buf)->GetDuration().InMilliseconds(); | 80 << ", dur=" << (*buf)->GetDuration().InMilliseconds(); |
| 86 EXPECT_LE(segment_start_, (*buf)->GetTimestamp()); | 81 EXPECT_GE((*buf)->GetTimestamp(), segment_start_); |
| 87 } | 82 } |
| 88 return true; | 83 return true; |
| 89 } | 84 } |
| 90 | 85 |
| 91 bool KeyNeededF(scoped_array<uint8> init_data, int init_data_size) { | 86 bool KeyNeededF(scoped_array<uint8> init_data, int init_data_size) { |
| 92 DVLOG(1) << "KeyNeededF: " << init_data_size; | 87 DVLOG(1) << "KeyNeededF: " << init_data_size; |
| 93 return true; | 88 return true; |
| 94 } | 89 } |
| 95 | 90 |
| 96 void NewSegmentF(TimeDelta start_dts) { | 91 void NewSegmentF(TimeDelta start_dts) { |
| 97 DVLOG(1) << "NewSegmentF: " << start_dts.InMilliseconds(); | 92 DVLOG(1) << "NewSegmentF: " << start_dts.InMilliseconds(); |
| 98 segment_start_ = start_dts; | 93 segment_start_ = start_dts; |
| 99 } | 94 } |
| 100 | 95 |
| 101 void InitializeParser() { | 96 void InitializeParser() { |
| 102 parser_->Init( | 97 parser_->Init( |
| 103 base::Bind(&MP4StreamParserTest::InitF, base::Unretained(this)), | 98 base::Bind(&MP4StreamParserTest::InitF, base::Unretained(this)), |
| 104 base::Bind(&MP4StreamParserTest::NewConfigF, base::Unretained(this)), | 99 base::Bind(&MP4StreamParserTest::NewConfigF, base::Unretained(this)), |
| 105 base::Bind(&MP4StreamParserTest::NewBuffersF, base::Unretained(this)), | 100 base::Bind(&MP4StreamParserTest::NewBuffersF, base::Unretained(this)), |
| 106 base::Bind(&MP4StreamParserTest::NewBuffersF, base::Unretained(this)), | 101 base::Bind(&MP4StreamParserTest::NewBuffersF, base::Unretained(this)), |
| 107 base::Bind(&MP4StreamParserTest::KeyNeededF, base::Unretained(this)), | 102 base::Bind(&MP4StreamParserTest::KeyNeededF, base::Unretained(this)), |
| 108 base::Bind(&MP4StreamParserTest::NewSegmentF, base::Unretained(this))); | 103 base::Bind(&MP4StreamParserTest::NewSegmentF, base::Unretained(this))); |
| 109 } | 104 } |
| 110 | 105 |
| 111 bool ParseMP4File(const std::string& filename, int append_size) { | 106 bool ParseMP4File(const std::string& filename, int append_bytes) { |
| 112 InitializeParser(); | 107 InitializeParser(); |
| 113 | 108 |
| 114 scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile(filename); | 109 scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile(filename); |
| 115 EXPECT_TRUE(AppendDataInPieces(buffer->GetData(), | 110 EXPECT_TRUE(AppendDataInPieces(buffer->GetData(), |
| 116 buffer->GetDataSize(), | 111 buffer->GetDataSize(), |
| 117 append_size)); | 112 append_bytes)); |
| 118 return true; | 113 return true; |
| 119 } | 114 } |
| 120 }; | 115 }; |
| 121 | 116 |
| 122 TEST_F(MP4StreamParserTest, TestParseBearDASH) { | 117 |
| 118 |
| 119 TEST_F(MP4StreamParserTest, TestUnalignedAppend) { |
| 120 // Test small, non-segment-aligned appends (small enough to exercise |
| 121 // incremental append system) |
| 123 ParseMP4File("bear.1280x720_dash.mp4", 512); | 122 ParseMP4File("bear.1280x720_dash.mp4", 512); |
| 124 } | 123 } |
| 125 | 124 |
| 126 TEST_F(MP4StreamParserTest, TestMultiFragmentAppend) { | 125 TEST_F(MP4StreamParserTest, TestMultiFragmentAppend) { |
| 126 // Large size ensures multiple fragments are appended in one call (size is |
| 127 // larger than this particular test file) |
| 127 ParseMP4File("bear.1280x720_dash.mp4", 768432); | 128 ParseMP4File("bear.1280x720_dash.mp4", 768432); |
| 128 } | 129 } |
| 129 | 130 |
| 130 TEST_F(MP4StreamParserTest, TestReinitialization) { | 131 TEST_F(MP4StreamParserTest, TestReinitialization) { |
| 131 InitializeParser(); | 132 InitializeParser(); |
| 132 | 133 |
| 133 scoped_refptr<DecoderBuffer> buffer = | 134 scoped_refptr<DecoderBuffer> buffer = |
| 134 ReadTestDataFile("bear.1280x720_dash.mp4"); | 135 ReadTestDataFile("bear.1280x720_dash.mp4"); |
| 135 EXPECT_TRUE(AppendDataInPieces(buffer->GetData(), | 136 EXPECT_TRUE(AppendDataInPieces(buffer->GetData(), |
| 136 buffer->GetDataSize(), | 137 buffer->GetDataSize(), |
| 137 512)); | 138 512)); |
| 138 EXPECT_TRUE(AppendDataInPieces(buffer->GetData(), | 139 EXPECT_TRUE(AppendDataInPieces(buffer->GetData(), |
| 139 buffer->GetDataSize(), | 140 buffer->GetDataSize(), |
| 140 512)); | 141 512)); |
| 141 } | 142 } |
| 142 | 143 |
| 143 } // namespace mp4 | 144 } // namespace mp4 |
| 144 } // namespace media | 145 } // namespace media |
| OLD | NEW |