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 13 matching lines...) Expand all Loading... |
24 | 24 |
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 std::set<int> audio_object_types; | 36 std::set<int> audio_object_types; |
36 audio_object_types.insert(kISO_14496_3); | 37 audio_object_types.insert(kISO_14496_3); |
37 parser_.reset(new MP4StreamParser(audio_object_types, false)); | 38 parser_.reset(new MP4StreamParser(audio_object_types, false)); |
38 } | 39 } |
39 | 40 |
40 protected: | 41 protected: |
41 scoped_ptr<MP4StreamParser> parser_; | 42 scoped_ptr<MP4StreamParser> parser_; |
42 bool configs_received_; | 43 bool configs_received_; |
| 44 base::TimeDelta lower_bound_; |
43 | 45 |
44 bool AppendData(const uint8* data, size_t length) { | 46 bool AppendData(const uint8* data, size_t length) { |
45 return parser_->Parse(data, length); | 47 return parser_->Parse(data, length); |
46 } | 48 } |
47 | 49 |
48 bool AppendDataInPieces(const uint8* data, size_t length, size_t piece_size) { | 50 bool AppendDataInPieces(const uint8* data, size_t length, size_t piece_size) { |
49 const uint8* start = data; | 51 const uint8* start = data; |
50 const uint8* end = data + length; | 52 const uint8* end = data + length; |
51 while (start < end) { | 53 while (start < end) { |
52 size_t append_size = std::min(piece_size, | 54 size_t append_size = std::min(piece_size, |
(...skipping 13 matching lines...) Expand all Loading... |
66 | 68 |
67 bool NewConfigF(const AudioDecoderConfig& ac, | 69 bool NewConfigF(const AudioDecoderConfig& ac, |
68 const VideoDecoderConfig& vc, | 70 const VideoDecoderConfig& vc, |
69 const StreamParser::TextTrackConfigMap& tc) { | 71 const StreamParser::TextTrackConfigMap& tc) { |
70 DVLOG(1) << "NewConfigF: audio=" << ac.IsValidConfig() | 72 DVLOG(1) << "NewConfigF: audio=" << ac.IsValidConfig() |
71 << ", video=" << vc.IsValidConfig(); | 73 << ", video=" << vc.IsValidConfig(); |
72 configs_received_ = true; | 74 configs_received_ = true; |
73 return true; | 75 return true; |
74 } | 76 } |
75 | 77 |
76 | |
77 void DumpBuffers(const std::string& label, | 78 void DumpBuffers(const std::string& label, |
78 const StreamParser::BufferQueue& buffers) { | 79 const StreamParser::BufferQueue& buffers) { |
79 DVLOG(2) << "DumpBuffers: " << label << " size " << buffers.size(); | 80 DVLOG(2) << "DumpBuffers: " << label << " size " << buffers.size(); |
80 for (StreamParser::BufferQueue::const_iterator buf = buffers.begin(); | 81 for (StreamParser::BufferQueue::const_iterator buf = buffers.begin(); |
81 buf != buffers.end(); buf++) { | 82 buf != buffers.end(); buf++) { |
82 DVLOG(3) << " n=" << buf - buffers.begin() | 83 DVLOG(3) << " n=" << buf - buffers.begin() |
83 << ", size=" << (*buf)->data_size() | 84 << ", size=" << (*buf)->data_size() |
84 << ", dur=" << (*buf)->duration().InMilliseconds(); | 85 << ", dur=" << (*buf)->duration().InMilliseconds(); |
85 } | 86 } |
86 } | 87 } |
87 | 88 |
88 bool NewBuffersF(const StreamParser::BufferQueue& audio_buffers, | 89 bool NewBuffersF(const StreamParser::BufferQueue& audio_buffers, |
89 const StreamParser::BufferQueue& video_buffers, | 90 const StreamParser::BufferQueue& video_buffers, |
90 const StreamParser::TextBufferQueueMap& text_map) { | 91 const StreamParser::TextBufferQueueMap& text_map) { |
91 DumpBuffers("audio_buffers", audio_buffers); | 92 DumpBuffers("audio_buffers", audio_buffers); |
92 DumpBuffers("video_buffers", video_buffers); | 93 DumpBuffers("video_buffers", video_buffers); |
93 | 94 |
94 // TODO(wolenetz/acolwell): Add text track support to more MSE parsers. See | 95 // TODO(wolenetz/acolwell): Add text track support to more MSE parsers. See |
95 // http://crbug.com/336926. | 96 // http://crbug.com/336926. |
96 if (!text_map.empty()) | 97 if (!text_map.empty()) |
97 return false; | 98 return false; |
98 | 99 |
| 100 // Find the second highest timestamp so that we know what the |
| 101 // timestamps on the next set of buffers must be >= than. |
| 102 base::TimeDelta audio = !audio_buffers.empty() ? |
| 103 audio_buffers.back()->GetDecodeTimestamp() : kNoTimestamp(); |
| 104 base::TimeDelta video = !video_buffers.empty() ? |
| 105 video_buffers.back()->GetDecodeTimestamp() : kNoTimestamp(); |
| 106 base::TimeDelta second_highest_timestamp = |
| 107 (audio == kNoTimestamp() || |
| 108 (video != kNoTimestamp() && audio > video)) ? video : audio; |
| 109 |
| 110 DCHECK(second_highest_timestamp != kNoTimestamp()); |
| 111 |
| 112 if (lower_bound_ != kNoTimestamp() && |
| 113 second_highest_timestamp < lower_bound_) { |
| 114 return false; |
| 115 } |
| 116 |
| 117 lower_bound_ = second_highest_timestamp; |
99 return true; | 118 return true; |
100 } | 119 } |
101 | 120 |
102 void KeyNeededF(const std::string& type, | 121 void KeyNeededF(const std::string& type, |
103 const std::vector<uint8>& init_data) { | 122 const std::vector<uint8>& init_data) { |
104 DVLOG(1) << "KeyNeededF: " << init_data.size(); | 123 DVLOG(1) << "KeyNeededF: " << init_data.size(); |
105 EXPECT_EQ(kMp4InitDataType, type); | 124 EXPECT_EQ(kMp4InitDataType, type); |
106 EXPECT_FALSE(init_data.empty()); | 125 EXPECT_FALSE(init_data.empty()); |
107 } | 126 } |
108 | 127 |
109 void NewSegmentF() { | 128 void NewSegmentF() { |
110 DVLOG(1) << "NewSegmentF"; | 129 DVLOG(1) << "NewSegmentF"; |
| 130 lower_bound_ = kNoTimestamp(); |
111 } | 131 } |
112 | 132 |
113 void EndOfSegmentF() { | 133 void EndOfSegmentF() { |
114 DVLOG(1) << "EndOfSegmentF()"; | 134 DVLOG(1) << "EndOfSegmentF()"; |
| 135 lower_bound_ = base::TimeDelta::Max(); |
115 } | 136 } |
116 | 137 |
117 void InitializeParser() { | 138 void InitializeParser() { |
118 parser_->Init( | 139 parser_->Init( |
119 base::Bind(&MP4StreamParserTest::InitF, base::Unretained(this)), | 140 base::Bind(&MP4StreamParserTest::InitF, base::Unretained(this)), |
120 base::Bind(&MP4StreamParserTest::NewConfigF, base::Unretained(this)), | 141 base::Bind(&MP4StreamParserTest::NewConfigF, base::Unretained(this)), |
121 base::Bind(&MP4StreamParserTest::NewBuffersF, base::Unretained(this)), | 142 base::Bind(&MP4StreamParserTest::NewBuffersF, base::Unretained(this)), |
122 true, | 143 true, |
123 base::Bind(&MP4StreamParserTest::KeyNeededF, base::Unretained(this)), | 144 base::Bind(&MP4StreamParserTest::KeyNeededF, base::Unretained(this)), |
124 base::Bind(&MP4StreamParserTest::NewSegmentF, base::Unretained(this)), | 145 base::Bind(&MP4StreamParserTest::NewSegmentF, base::Unretained(this)), |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 // Delimiter (AUD) NALU. | 241 // Delimiter (AUD) NALU. |
221 TEST_F(MP4StreamParserTest, VideoSamplesStartWithAUDs) { | 242 TEST_F(MP4StreamParserTest, VideoSamplesStartWithAUDs) { |
222 ParseMP4File("bear-1280x720-av_with-aud-nalus_frag.mp4", 512); | 243 ParseMP4File("bear-1280x720-av_with-aud-nalus_frag.mp4", 512); |
223 } | 244 } |
224 | 245 |
225 // TODO(strobe): Create and test media which uses CENC auxiliary info stored | 246 // TODO(strobe): Create and test media which uses CENC auxiliary info stored |
226 // inside a private box | 247 // inside a private box |
227 | 248 |
228 } // namespace mp4 | 249 } // namespace mp4 |
229 } // namespace media | 250 } // namespace media |
OLD | NEW |