Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(194)

Side by Side Diff: media/formats/mp4/mp4_stream_parser_unittest.cc

Issue 348623003: Fix muxed MP4 parsing so it won't crash on partial media segment appends. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make ChromeOS compiler happy Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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) {
wolenetz 2014/06/19 22:01:15 nit: initialize lower_bound_ to base::TimeDelta::M
acolwell GONE FROM CHROMIUM 2014/06/19 23:46:47 Done.
35 std::set<int> audio_object_types; 35 std::set<int> audio_object_types;
36 audio_object_types.insert(kISO_14496_3); 36 audio_object_types.insert(kISO_14496_3);
37 parser_.reset(new MP4StreamParser(audio_object_types, false)); 37 parser_.reset(new MP4StreamParser(audio_object_types, false));
38 } 38 }
39 39
40 protected: 40 protected:
41 scoped_ptr<MP4StreamParser> parser_; 41 scoped_ptr<MP4StreamParser> parser_;
42 bool configs_received_; 42 bool configs_received_;
43 base::TimeDelta lower_bound_;
43 44
44 bool AppendData(const uint8* data, size_t length) { 45 bool AppendData(const uint8* data, size_t length) {
45 return parser_->Parse(data, length); 46 return parser_->Parse(data, length);
46 } 47 }
47 48
48 bool AppendDataInPieces(const uint8* data, size_t length, size_t piece_size) { 49 bool AppendDataInPieces(const uint8* data, size_t length, size_t piece_size) {
49 const uint8* start = data; 50 const uint8* start = data;
50 const uint8* end = data + length; 51 const uint8* end = data + length;
51 while (start < end) { 52 while (start < end) {
52 size_t append_size = std::min(piece_size, 53 size_t append_size = std::min(piece_size,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
wolenetz 2014/06/19 22:01:15 nit: remove extra whitespace
acolwell GONE FROM CHROMIUM 2014/06/19 23:46:47 Done.
101 // Find the second highest timestamp so that we know what the
102 // timestamps on the next set of buffers must be >= than.
103 base::TimeDelta audio = !audio_buffers.empty() ?
104 audio_buffers.back()->GetDecodeTimestamp() : kNoTimestamp();
105 base::TimeDelta video = video_buffers.empty() ?
106 video_buffers.back()->GetDecodeTimestamp() : kNoTimestamp();
107 base::TimeDelta second_highest_timestamp =
108 (audio == kNoTimestamp() ||
109 (video != kNoTimestamp() && audio > video)) ? video : audio;
110
111 DCHECK(second_highest_timestamp != kNoTimestamp());
112
113 if (lower_bound_ != kNoTimestamp() &&
114 second_highest_timestamp < lower_bound_) {
115 return false;
116 }
117
118 lower_bound_ = second_highest_timestamp;
99 return true; 119 return true;
100 } 120 }
101 121
102 void KeyNeededF(const std::string& type, 122 void KeyNeededF(const std::string& type,
103 const std::vector<uint8>& init_data) { 123 const std::vector<uint8>& init_data) {
104 DVLOG(1) << "KeyNeededF: " << init_data.size(); 124 DVLOG(1) << "KeyNeededF: " << init_data.size();
105 EXPECT_EQ(kMp4InitDataType, type); 125 EXPECT_EQ(kMp4InitDataType, type);
106 EXPECT_FALSE(init_data.empty()); 126 EXPECT_FALSE(init_data.empty());
107 } 127 }
108 128
109 void NewSegmentF() { 129 void NewSegmentF() {
110 DVLOG(1) << "NewSegmentF"; 130 DVLOG(1) << "NewSegmentF";
131 lower_bound_ = kNoTimestamp();
111 } 132 }
112 133
113 void EndOfSegmentF() { 134 void EndOfSegmentF() {
114 DVLOG(1) << "EndOfSegmentF()"; 135 DVLOG(1) << "EndOfSegmentF()";
wolenetz 2014/06/19 22:01:15 nit: set lower_bound_ = base::TimeDelta::Max() to
acolwell GONE FROM CHROMIUM 2014/06/19 23:46:47 Done.
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
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
OLDNEW
« media/formats/mp4/mp4_stream_parser.cc ('K') | « media/formats/mp4/mp4_stream_parser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698