| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 14 matching lines...) Expand all Loading... |
| 25 namespace media { | 25 namespace media { |
| 26 namespace mp4 { | 26 namespace mp4 { |
| 27 | 27 |
| 28 // TODO(xhwang): Figure out the init data type appropriately once it's spec'ed. | 28 // TODO(xhwang): Figure out the init data type appropriately once it's spec'ed. |
| 29 static const char kMp4InitDataType[] = "video/mp4"; | 29 static const char kMp4InitDataType[] = "video/mp4"; |
| 30 | 30 |
| 31 class MP4StreamParserTest : public testing::Test { | 31 class MP4StreamParserTest : public testing::Test { |
| 32 public: | 32 public: |
| 33 MP4StreamParserTest() | 33 MP4StreamParserTest() |
| 34 : configs_received_(false), | 34 : configs_received_(false), |
| 35 lower_bound_(base::TimeDelta::Max()) { | 35 lower_bound_( |
| 36 DecodeTimestamp::FromPresentationTime(base::TimeDelta::Max())) { |
| 36 std::set<int> audio_object_types; | 37 std::set<int> audio_object_types; |
| 37 audio_object_types.insert(kISO_14496_3); | 38 audio_object_types.insert(kISO_14496_3); |
| 38 parser_.reset(new MP4StreamParser(audio_object_types, false)); | 39 parser_.reset(new MP4StreamParser(audio_object_types, false)); |
| 39 } | 40 } |
| 40 | 41 |
| 41 protected: | 42 protected: |
| 42 scoped_ptr<MP4StreamParser> parser_; | 43 scoped_ptr<MP4StreamParser> parser_; |
| 43 bool configs_received_; | 44 bool configs_received_; |
| 44 base::TimeDelta lower_bound_; | 45 DecodeTimestamp lower_bound_; |
| 45 | 46 |
| 46 bool AppendData(const uint8* data, size_t length) { | 47 bool AppendData(const uint8* data, size_t length) { |
| 47 return parser_->Parse(data, length); | 48 return parser_->Parse(data, length); |
| 48 } | 49 } |
| 49 | 50 |
| 50 bool AppendDataInPieces(const uint8* data, size_t length, size_t piece_size) { | 51 bool AppendDataInPieces(const uint8* data, size_t length, size_t piece_size) { |
| 51 const uint8* start = data; | 52 const uint8* start = data; |
| 52 const uint8* end = data + length; | 53 const uint8* end = data + length; |
| 53 while (start < end) { | 54 while (start < end) { |
| 54 size_t append_size = std::min(piece_size, | 55 size_t append_size = std::min(piece_size, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 DumpBuffers("audio_buffers", audio_buffers); | 93 DumpBuffers("audio_buffers", audio_buffers); |
| 93 DumpBuffers("video_buffers", video_buffers); | 94 DumpBuffers("video_buffers", video_buffers); |
| 94 | 95 |
| 95 // TODO(wolenetz/acolwell): Add text track support to more MSE parsers. See | 96 // TODO(wolenetz/acolwell): Add text track support to more MSE parsers. See |
| 96 // http://crbug.com/336926. | 97 // http://crbug.com/336926. |
| 97 if (!text_map.empty()) | 98 if (!text_map.empty()) |
| 98 return false; | 99 return false; |
| 99 | 100 |
| 100 // Find the second highest timestamp so that we know what the | 101 // Find the second highest timestamp so that we know what the |
| 101 // timestamps on the next set of buffers must be >= than. | 102 // timestamps on the next set of buffers must be >= than. |
| 102 base::TimeDelta audio = !audio_buffers.empty() ? | 103 DecodeTimestamp audio = !audio_buffers.empty() ? |
| 103 audio_buffers.back()->GetDecodeTimestamp() : kNoTimestamp(); | 104 audio_buffers.back()->GetDecodeTimestamp() : kNoDecodeTimestamp(); |
| 104 base::TimeDelta video = !video_buffers.empty() ? | 105 DecodeTimestamp video = !video_buffers.empty() ? |
| 105 video_buffers.back()->GetDecodeTimestamp() : kNoTimestamp(); | 106 video_buffers.back()->GetDecodeTimestamp() : kNoDecodeTimestamp(); |
| 106 base::TimeDelta second_highest_timestamp = | 107 DecodeTimestamp second_highest_timestamp = |
| 107 (audio == kNoTimestamp() || | 108 (audio == kNoDecodeTimestamp() || |
| 108 (video != kNoTimestamp() && audio > video)) ? video : audio; | 109 (video != kNoDecodeTimestamp() && audio > video)) ? video : audio; |
| 109 | 110 |
| 110 DCHECK(second_highest_timestamp != kNoTimestamp()); | 111 DCHECK(second_highest_timestamp != kNoDecodeTimestamp()); |
| 111 | 112 |
| 112 if (lower_bound_ != kNoTimestamp() && | 113 if (lower_bound_ != kNoDecodeTimestamp() && |
| 113 second_highest_timestamp < lower_bound_) { | 114 second_highest_timestamp < lower_bound_) { |
| 114 return false; | 115 return false; |
| 115 } | 116 } |
| 116 | 117 |
| 117 lower_bound_ = second_highest_timestamp; | 118 lower_bound_ = second_highest_timestamp; |
| 118 return true; | 119 return true; |
| 119 } | 120 } |
| 120 | 121 |
| 121 void KeyNeededF(const std::string& type, | 122 void KeyNeededF(const std::string& type, |
| 122 const std::vector<uint8>& init_data) { | 123 const std::vector<uint8>& init_data) { |
| 123 DVLOG(1) << "KeyNeededF: " << init_data.size(); | 124 DVLOG(1) << "KeyNeededF: " << init_data.size(); |
| 124 EXPECT_EQ(kMp4InitDataType, type); | 125 EXPECT_EQ(kMp4InitDataType, type); |
| 125 EXPECT_FALSE(init_data.empty()); | 126 EXPECT_FALSE(init_data.empty()); |
| 126 } | 127 } |
| 127 | 128 |
| 128 void NewSegmentF() { | 129 void NewSegmentF() { |
| 129 DVLOG(1) << "NewSegmentF"; | 130 DVLOG(1) << "NewSegmentF"; |
| 130 lower_bound_ = kNoTimestamp(); | 131 lower_bound_ = kNoDecodeTimestamp(); |
| 131 } | 132 } |
| 132 | 133 |
| 133 void EndOfSegmentF() { | 134 void EndOfSegmentF() { |
| 134 DVLOG(1) << "EndOfSegmentF()"; | 135 DVLOG(1) << "EndOfSegmentF()"; |
| 135 lower_bound_ = base::TimeDelta::Max(); | 136 lower_bound_ = |
| 137 DecodeTimestamp::FromPresentationTime(base::TimeDelta::Max()); |
| 136 } | 138 } |
| 137 | 139 |
| 138 void InitializeParser() { | 140 void InitializeParser() { |
| 139 parser_->Init( | 141 parser_->Init( |
| 140 base::Bind(&MP4StreamParserTest::InitF, base::Unretained(this)), | 142 base::Bind(&MP4StreamParserTest::InitF, base::Unretained(this)), |
| 141 base::Bind(&MP4StreamParserTest::NewConfigF, base::Unretained(this)), | 143 base::Bind(&MP4StreamParserTest::NewConfigF, base::Unretained(this)), |
| 142 base::Bind(&MP4StreamParserTest::NewBuffersF, base::Unretained(this)), | 144 base::Bind(&MP4StreamParserTest::NewBuffersF, base::Unretained(this)), |
| 143 true, | 145 true, |
| 144 base::Bind(&MP4StreamParserTest::KeyNeededF, base::Unretained(this)), | 146 base::Bind(&MP4StreamParserTest::KeyNeededF, base::Unretained(this)), |
| 145 base::Bind(&MP4StreamParserTest::NewSegmentF, base::Unretained(this)), | 147 base::Bind(&MP4StreamParserTest::NewSegmentF, base::Unretained(this)), |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 // Delimiter (AUD) NALU. | 243 // Delimiter (AUD) NALU. |
| 242 TEST_F(MP4StreamParserTest, VideoSamplesStartWithAUDs) { | 244 TEST_F(MP4StreamParserTest, VideoSamplesStartWithAUDs) { |
| 243 ParseMP4File("bear-1280x720-av_with-aud-nalus_frag.mp4", 512); | 245 ParseMP4File("bear-1280x720-av_with-aud-nalus_frag.mp4", 512); |
| 244 } | 246 } |
| 245 | 247 |
| 246 // TODO(strobe): Create and test media which uses CENC auxiliary info stored | 248 // TODO(strobe): Create and test media which uses CENC auxiliary info stored |
| 247 // inside a private box | 249 // inside a private box |
| 248 | 250 |
| 249 } // namespace mp4 | 251 } // namespace mp4 |
| 250 } // namespace media | 252 } // namespace media |
| OLD | NEW |