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

Side by Side Diff: media/filters/source_buffer_stream_unittest.cc

Issue 1534273002: Switch to standard integer types in media/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more Created 5 years 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 (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 "media/filters/source_buffer_stream.h" 5 #include "media/filters/source_buffer_stream.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 16 matching lines...) Expand all
27 using ::testing::HasSubstr; 27 using ::testing::HasSubstr;
28 using ::testing::InSequence; 28 using ::testing::InSequence;
29 using ::testing::StrictMock; 29 using ::testing::StrictMock;
30 30
31 namespace media { 31 namespace media {
32 32
33 typedef StreamParser::BufferQueue BufferQueue; 33 typedef StreamParser::BufferQueue BufferQueue;
34 34
35 static const int kDefaultFramesPerSecond = 30; 35 static const int kDefaultFramesPerSecond = 30;
36 static const int kDefaultKeyframesPerSecond = 6; 36 static const int kDefaultKeyframesPerSecond = 6;
37 static const uint8 kDataA = 0x11; 37 static const uint8_t kDataA = 0x11;
38 static const uint8 kDataB = 0x33; 38 static const uint8_t kDataB = 0x33;
39 static const int kDataSize = 1; 39 static const int kDataSize = 1;
40 40
41 // Matchers for verifying common media log entry strings. 41 // Matchers for verifying common media log entry strings.
42 MATCHER(ContainsMissingKeyframeLog, "") { 42 MATCHER(ContainsMissingKeyframeLog, "") {
43 return CONTAINS_STRING(arg, 43 return CONTAINS_STRING(arg,
44 "Media segment did not begin with key frame. Support " 44 "Media segment did not begin with key frame. Support "
45 "for such segments will be available in a future " 45 "for such segments will be available in a future "
46 "version. Please see https://crbug.com/229412."); 46 "version. Please see https://crbug.com/229412.");
47 } 47 }
48 48
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 111
112 // Equivalent to 2ms per frame. 112 // Equivalent to 2ms per frame.
113 SetStreamInfo(500, 500); 113 SetStreamInfo(500, 500);
114 } 114 }
115 115
116 void NewSegmentAppend(int starting_position, int number_of_buffers) { 116 void NewSegmentAppend(int starting_position, int number_of_buffers) {
117 AppendBuffers(starting_position, number_of_buffers, true, 117 AppendBuffers(starting_position, number_of_buffers, true,
118 base::TimeDelta(), true, &kDataA, kDataSize); 118 base::TimeDelta(), true, &kDataA, kDataSize);
119 } 119 }
120 120
121 void NewSegmentAppend(int starting_position, int number_of_buffers, 121 void NewSegmentAppend(int starting_position,
122 const uint8* data) { 122 int number_of_buffers,
123 const uint8_t* data) {
123 AppendBuffers(starting_position, number_of_buffers, true, 124 AppendBuffers(starting_position, number_of_buffers, true,
124 base::TimeDelta(), true, data, kDataSize); 125 base::TimeDelta(), true, data, kDataSize);
125 } 126 }
126 127
127 void NewSegmentAppend_OffsetFirstBuffer( 128 void NewSegmentAppend_OffsetFirstBuffer(
128 int starting_position, int number_of_buffers, 129 int starting_position, int number_of_buffers,
129 base::TimeDelta first_buffer_offset) { 130 base::TimeDelta first_buffer_offset) {
130 AppendBuffers(starting_position, number_of_buffers, true, 131 AppendBuffers(starting_position, number_of_buffers, true,
131 first_buffer_offset, true, &kDataA, kDataSize); 132 first_buffer_offset, true, &kDataA, kDataSize);
132 } 133 }
133 134
134 void NewSegmentAppend_ExpectFailure( 135 void NewSegmentAppend_ExpectFailure(
135 int starting_position, int number_of_buffers) { 136 int starting_position, int number_of_buffers) {
136 AppendBuffers(starting_position, number_of_buffers, true, 137 AppendBuffers(starting_position, number_of_buffers, true,
137 base::TimeDelta(), false, &kDataA, kDataSize); 138 base::TimeDelta(), false, &kDataA, kDataSize);
138 } 139 }
139 140
140 void AppendBuffers(int starting_position, int number_of_buffers) { 141 void AppendBuffers(int starting_position, int number_of_buffers) {
141 AppendBuffers(starting_position, number_of_buffers, false, 142 AppendBuffers(starting_position, number_of_buffers, false,
142 base::TimeDelta(), true, &kDataA, kDataSize); 143 base::TimeDelta(), true, &kDataA, kDataSize);
143 } 144 }
144 145
145 void AppendBuffers(int starting_position, int number_of_buffers, 146 void AppendBuffers(int starting_position,
146 const uint8* data) { 147 int number_of_buffers,
148 const uint8_t* data) {
147 AppendBuffers(starting_position, number_of_buffers, false, 149 AppendBuffers(starting_position, number_of_buffers, false,
148 base::TimeDelta(), true, data, kDataSize); 150 base::TimeDelta(), true, data, kDataSize);
149 } 151 }
150 152
151 void NewSegmentAppend(const std::string& buffers_to_append) { 153 void NewSegmentAppend(const std::string& buffers_to_append) {
152 AppendBuffers(buffers_to_append, true, kNoTimestamp(), false, true); 154 AppendBuffers(buffers_to_append, true, kNoTimestamp(), false, true);
153 } 155 }
154 156
155 void NewSegmentAppend(base::TimeDelta start_timestamp, 157 void NewSegmentAppend(base::TimeDelta start_timestamp,
156 const std::string& buffers_to_append) { 158 const std::string& buffers_to_append) {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 *removal_end = removal_end_timestamp.InMilliseconds(); 215 *removal_end = removal_end_timestamp.InMilliseconds();
214 return bytes_removed; 216 return bytes_removed;
215 } 217 }
216 218
217 void CheckExpectedRanges(const std::string& expected) { 219 void CheckExpectedRanges(const std::string& expected) {
218 Ranges<base::TimeDelta> r = stream_->GetBufferedTime(); 220 Ranges<base::TimeDelta> r = stream_->GetBufferedTime();
219 221
220 std::stringstream ss; 222 std::stringstream ss;
221 ss << "{ "; 223 ss << "{ ";
222 for (size_t i = 0; i < r.size(); ++i) { 224 for (size_t i = 0; i < r.size(); ++i) {
223 int64 start = (r.start(i) / frame_duration_); 225 int64_t start = (r.start(i) / frame_duration_);
224 int64 end = (r.end(i) / frame_duration_) - 1; 226 int64_t end = (r.end(i) / frame_duration_) - 1;
225 ss << "[" << start << "," << end << ") "; 227 ss << "[" << start << "," << end << ") ";
226 } 228 }
227 ss << "}"; 229 ss << "}";
228 EXPECT_EQ(expected, ss.str()); 230 EXPECT_EQ(expected, ss.str());
229 } 231 }
230 232
231 void CheckExpectedRangesByTimestamp(const std::string& expected) { 233 void CheckExpectedRangesByTimestamp(const std::string& expected) {
232 Ranges<base::TimeDelta> r = stream_->GetBufferedTime(); 234 Ranges<base::TimeDelta> r = stream_->GetBufferedTime();
233 235
234 std::stringstream ss; 236 std::stringstream ss;
235 ss << "{ "; 237 ss << "{ ";
236 for (size_t i = 0; i < r.size(); ++i) { 238 for (size_t i = 0; i < r.size(); ++i) {
237 int64 start = r.start(i).InMilliseconds(); 239 int64_t start = r.start(i).InMilliseconds();
238 int64 end = r.end(i).InMilliseconds(); 240 int64_t end = r.end(i).InMilliseconds();
239 ss << "[" << start << "," << end << ") "; 241 ss << "[" << start << "," << end << ") ";
240 } 242 }
241 ss << "}"; 243 ss << "}";
242 EXPECT_EQ(expected, ss.str()); 244 EXPECT_EQ(expected, ss.str());
243 } 245 }
244 246
245 void CheckExpectedBuffers( 247 void CheckExpectedBuffers(
246 int starting_position, int ending_position) { 248 int starting_position, int ending_position) {
247 CheckExpectedBuffers(starting_position, ending_position, false, NULL, 0); 249 CheckExpectedBuffers(starting_position, ending_position, false, NULL, 0);
248 } 250 }
249 251
250 void CheckExpectedBuffers( 252 void CheckExpectedBuffers(
251 int starting_position, int ending_position, bool expect_keyframe) { 253 int starting_position, int ending_position, bool expect_keyframe) {
252 CheckExpectedBuffers(starting_position, ending_position, expect_keyframe, 254 CheckExpectedBuffers(starting_position, ending_position, expect_keyframe,
253 NULL, 0); 255 NULL, 0);
254 } 256 }
255 257
256 void CheckExpectedBuffers( 258 void CheckExpectedBuffers(int starting_position,
257 int starting_position, int ending_position, const uint8* data) { 259 int ending_position,
260 const uint8_t* data) {
258 CheckExpectedBuffers(starting_position, ending_position, false, data, 261 CheckExpectedBuffers(starting_position, ending_position, false, data,
259 kDataSize); 262 kDataSize);
260 } 263 }
261 264
262 void CheckExpectedBuffers( 265 void CheckExpectedBuffers(int starting_position,
263 int starting_position, int ending_position, const uint8* data, 266 int ending_position,
264 bool expect_keyframe) { 267 const uint8_t* data,
268 bool expect_keyframe) {
265 CheckExpectedBuffers(starting_position, ending_position, expect_keyframe, 269 CheckExpectedBuffers(starting_position, ending_position, expect_keyframe,
266 data, kDataSize); 270 data, kDataSize);
267 } 271 }
268 272
269 void CheckExpectedBuffers( 273 void CheckExpectedBuffers(int starting_position,
270 int starting_position, int ending_position, bool expect_keyframe, 274 int ending_position,
271 const uint8* expected_data, int expected_size) { 275 bool expect_keyframe,
276 const uint8_t* expected_data,
277 int expected_size) {
272 int current_position = starting_position; 278 int current_position = starting_position;
273 for (; current_position <= ending_position; current_position++) { 279 for (; current_position <= ending_position; current_position++) {
274 scoped_refptr<StreamParserBuffer> buffer; 280 scoped_refptr<StreamParserBuffer> buffer;
275 SourceBufferStream::Status status = stream_->GetNextBuffer(&buffer); 281 SourceBufferStream::Status status = stream_->GetNextBuffer(&buffer);
276 282
277 EXPECT_NE(status, SourceBufferStream::kConfigChange); 283 EXPECT_NE(status, SourceBufferStream::kConfigChange);
278 if (status != SourceBufferStream::kSuccess) 284 if (status != SourceBufferStream::kSuccess)
279 break; 285 break;
280 286
281 if (expect_keyframe && current_position == starting_position) 287 if (expect_keyframe && current_position == starting_position)
282 EXPECT_TRUE(buffer->is_key_frame()); 288 EXPECT_TRUE(buffer->is_key_frame());
283 289
284 if (expected_data) { 290 if (expected_data) {
285 const uint8* actual_data = buffer->data(); 291 const uint8_t* actual_data = buffer->data();
286 const int actual_size = buffer->data_size(); 292 const int actual_size = buffer->data_size();
287 EXPECT_EQ(expected_size, actual_size); 293 EXPECT_EQ(expected_size, actual_size);
288 for (int i = 0; i < std::min(actual_size, expected_size); i++) { 294 for (int i = 0; i < std::min(actual_size, expected_size); i++) {
289 EXPECT_EQ(expected_data[i], actual_data[i]); 295 EXPECT_EQ(expected_data[i], actual_data[i]);
290 } 296 }
291 } 297 }
292 298
293 EXPECT_EQ(buffer->GetDecodeTimestamp() / frame_duration_, 299 EXPECT_EQ(buffer->GetDecodeTimestamp() / frame_duration_,
294 current_position); 300 current_position);
295 } 301 }
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 base::TimeDelta ConvertToFrameDuration(int frames_per_second) { 433 base::TimeDelta ConvertToFrameDuration(int frames_per_second) {
428 return base::TimeDelta::FromMicroseconds( 434 return base::TimeDelta::FromMicroseconds(
429 base::Time::kMicrosecondsPerSecond / frames_per_second); 435 base::Time::kMicrosecondsPerSecond / frames_per_second);
430 } 436 }
431 437
432 void AppendBuffers(int starting_position, 438 void AppendBuffers(int starting_position,
433 int number_of_buffers, 439 int number_of_buffers,
434 bool begin_media_segment, 440 bool begin_media_segment,
435 base::TimeDelta first_buffer_offset, 441 base::TimeDelta first_buffer_offset,
436 bool expect_success, 442 bool expect_success,
437 const uint8* data, 443 const uint8_t* data,
438 int size) { 444 int size) {
439 if (begin_media_segment) 445 if (begin_media_segment)
440 stream_->OnNewMediaSegment(DecodeTimestamp::FromPresentationTime( 446 stream_->OnNewMediaSegment(DecodeTimestamp::FromPresentationTime(
441 starting_position * frame_duration_)); 447 starting_position * frame_duration_));
442 448
443 int keyframe_interval = frames_per_second_ / keyframes_per_second_; 449 int keyframe_interval = frames_per_second_ / keyframes_per_second_;
444 450
445 BufferQueue queue; 451 BufferQueue queue;
446 for (int i = 0; i < number_of_buffers; i++) { 452 for (int i = 0; i < number_of_buffers; i++) {
447 int position = starting_position + i; 453 int position = starting_position + i;
(...skipping 604 matching lines...) Expand 10 before | Expand all | Expand 10 after
1052 1058
1053 // Seek back to beginning; all data should be new. 1059 // Seek back to beginning; all data should be new.
1054 Seek(5); 1060 Seek(5);
1055 CheckExpectedBuffers(5, 14, &kDataB); 1061 CheckExpectedBuffers(5, 14, &kDataB);
1056 1062
1057 // Check range continues to be correct. 1063 // Check range continues to be correct.
1058 CheckExpectedRanges("{ [5,14) }"); 1064 CheckExpectedRanges("{ [5,14) }");
1059 } 1065 }
1060 1066
1061 TEST_F(SourceBufferStreamTest, Complete_Overlap_Selected_Multiple) { 1067 TEST_F(SourceBufferStreamTest, Complete_Overlap_Selected_Multiple) {
1062 static const uint8 kDataC = 0x55; 1068 static const uint8_t kDataC = 0x55;
1063 static const uint8 kDataD = 0x77; 1069 static const uint8_t kDataD = 0x77;
1064 1070
1065 // Append 5 buffers at positions 5 through 9. 1071 // Append 5 buffers at positions 5 through 9.
1066 NewSegmentAppend(5, 5, &kDataA); 1072 NewSegmentAppend(5, 5, &kDataA);
1067 1073
1068 // Seek to buffer at position 5 and get next buffer. 1074 // Seek to buffer at position 5 and get next buffer.
1069 Seek(5); 1075 Seek(5);
1070 CheckExpectedBuffers(5, 5, &kDataA); 1076 CheckExpectedBuffers(5, 5, &kDataA);
1071 1077
1072 // Replace existing data with new data. 1078 // Replace existing data with new data.
1073 NewSegmentAppend(5, 5, &kDataB); 1079 NewSegmentAppend(5, 5, &kDataB);
(...skipping 3538 matching lines...) Expand 10 before | Expand all | Expand 10 after
4612 CheckNoNextBuffer(); 4618 CheckNoNextBuffer();
4613 } 4619 }
4614 4620
4615 // TODO(vrk): Add unit tests where keyframes are unaligned between streams. 4621 // TODO(vrk): Add unit tests where keyframes are unaligned between streams.
4616 // (crbug.com/133557) 4622 // (crbug.com/133557)
4617 4623
4618 // TODO(vrk): Add unit tests with end of stream being called at interesting 4624 // TODO(vrk): Add unit tests with end of stream being called at interesting
4619 // times. 4625 // times.
4620 4626
4621 } // namespace media 4627 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698