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

Side by Side Diff: media/formats/webm/webm_cluster_parser_unittest.cc

Issue 2815303006: Convert MediaLog from being ref counted to owned by WebMediaPlayer. (Closed)
Patch Set: Rebase. Created 3 years, 8 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 "media/formats/webm/webm_cluster_parser.h" 5 #include "media/formats/webm/webm_cluster_parser.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 for (StreamParser::BufferQueue::const_iterator itr = src.begin(); 287 for (StreamParser::BufferQueue::const_iterator itr = src.begin();
288 itr != src.end(); ++itr) { 288 itr != src.end(); ++itr) {
289 dest->push_back(*itr); 289 dest->push_back(*itr);
290 } 290 }
291 } 291 }
292 292
293 } // namespace 293 } // namespace
294 294
295 class WebMClusterParserTest : public testing::Test { 295 class WebMClusterParserTest : public testing::Test {
296 public: 296 public:
297 WebMClusterParserTest() 297 WebMClusterParserTest() : parser_(CreateDefaultParser()) {}
298 : media_log_(new StrictMock<MockMediaLog>()),
299 parser_(CreateDefaultParser()) {}
300 298
301 protected: 299 protected:
302 void ResetParserToHaveDefaultDurations() { 300 void ResetParserToHaveDefaultDurations() {
303 base::TimeDelta default_audio_duration = base::TimeDelta::FromMilliseconds( 301 base::TimeDelta default_audio_duration = base::TimeDelta::FromMilliseconds(
304 kTestAudioFrameDefaultDurationInMs); 302 kTestAudioFrameDefaultDurationInMs);
305 base::TimeDelta default_video_duration = base::TimeDelta::FromMilliseconds( 303 base::TimeDelta default_video_duration = base::TimeDelta::FromMilliseconds(
306 kTestVideoFrameDefaultDurationInMs); 304 kTestVideoFrameDefaultDurationInMs);
307 ASSERT_GE(default_audio_duration, base::TimeDelta()); 305 ASSERT_GE(default_audio_duration, base::TimeDelta());
308 ASSERT_GE(default_video_duration, base::TimeDelta()); 306 ASSERT_GE(default_video_duration, base::TimeDelta());
309 ASSERT_NE(kNoTimestamp, default_audio_duration); 307 ASSERT_NE(kNoTimestamp, default_audio_duration);
310 ASSERT_NE(kNoTimestamp, default_video_duration); 308 ASSERT_NE(kNoTimestamp, default_video_duration);
311 309
312 parser_.reset(CreateParserWithDefaultDurationsAndOptionalTextTracks( 310 parser_.reset(CreateParserWithDefaultDurationsAndOptionalTextTracks(
313 default_audio_duration, default_video_duration)); 311 default_audio_duration, default_video_duration));
314 } 312 }
315 313
316 // Helper that hard-codes some non-varying constructor parameters. 314 // Helper that hard-codes some non-varying constructor parameters.
317 WebMClusterParser* CreateParserHelper( 315 WebMClusterParser* CreateParserHelper(
318 base::TimeDelta audio_default_duration, 316 base::TimeDelta audio_default_duration,
319 base::TimeDelta video_default_duration, 317 base::TimeDelta video_default_duration,
320 const WebMTracksParser::TextTracks& text_tracks, 318 const WebMTracksParser::TextTracks& text_tracks,
321 const std::set<int64_t>& ignored_tracks, 319 const std::set<int64_t>& ignored_tracks,
322 const std::string& audio_encryption_key_id, 320 const std::string& audio_encryption_key_id,
323 const std::string& video_encryption_key_id, 321 const std::string& video_encryption_key_id,
324 const AudioCodec audio_codec) { 322 const AudioCodec audio_codec) {
325 return new WebMClusterParser( 323 return new WebMClusterParser(
326 kTimecodeScale, kAudioTrackNum, audio_default_duration, kVideoTrackNum, 324 kTimecodeScale, kAudioTrackNum, audio_default_duration, kVideoTrackNum,
327 video_default_duration, text_tracks, ignored_tracks, 325 video_default_duration, text_tracks, ignored_tracks,
328 audio_encryption_key_id, video_encryption_key_id, audio_codec, 326 audio_encryption_key_id, video_encryption_key_id, audio_codec,
329 media_log_); 327 &media_log_);
330 } 328 }
331 329
332 // Create a default version of the parser for test. 330 // Create a default version of the parser for test.
333 WebMClusterParser* CreateDefaultParser() { 331 WebMClusterParser* CreateDefaultParser() {
334 return CreateParserHelper(kNoTimestamp, kNoTimestamp, TextTracks(), 332 return CreateParserHelper(kNoTimestamp, kNoTimestamp, TextTracks(),
335 std::set<int64_t>(), std::string(), std::string(), 333 std::set<int64_t>(), std::string(), std::string(),
336 kUnknownAudioCodec); 334 kUnknownAudioCodec);
337 } 335 }
338 336
339 // Create a parser for test with custom audio and video default durations, and 337 // Create a parser for test with custom audio and video default durations, and
(...skipping 18 matching lines...) Expand all
358 // Create a parser for test with custom encryption key ids and audio codec. 356 // Create a parser for test with custom encryption key ids and audio codec.
359 WebMClusterParser* CreateParserWithKeyIdsAndAudioCodec( 357 WebMClusterParser* CreateParserWithKeyIdsAndAudioCodec(
360 const std::string& audio_encryption_key_id, 358 const std::string& audio_encryption_key_id,
361 const std::string& video_encryption_key_id, 359 const std::string& video_encryption_key_id,
362 const AudioCodec audio_codec) { 360 const AudioCodec audio_codec) {
363 return CreateParserHelper(kNoTimestamp, kNoTimestamp, TextTracks(), 361 return CreateParserHelper(kNoTimestamp, kNoTimestamp, TextTracks(),
364 std::set<int64_t>(), audio_encryption_key_id, 362 std::set<int64_t>(), audio_encryption_key_id,
365 video_encryption_key_id, audio_codec); 363 video_encryption_key_id, audio_codec);
366 } 364 }
367 365
368 scoped_refptr<StrictMock<MockMediaLog>> media_log_; 366 StrictMock<MockMediaLog> media_log_;
369 std::unique_ptr<WebMClusterParser> parser_; 367 std::unique_ptr<WebMClusterParser> parser_;
370 368
371 private: 369 private:
372 DISALLOW_COPY_AND_ASSIGN(WebMClusterParserTest); 370 DISALLOW_COPY_AND_ASSIGN(WebMClusterParserTest);
373 }; 371 };
374 372
375 TEST_F(WebMClusterParserTest, HeldBackBufferHoldsBackAllTracks) { 373 TEST_F(WebMClusterParserTest, HeldBackBufferHoldsBackAllTracks) {
376 // If a buffer is missing duration and is being held back, then all other 374 // If a buffer is missing duration and is being held back, then all other
377 // tracks' buffers that have same or higher (decode) timestamp should be held 375 // tracks' buffers that have same or higher (decode) timestamp should be held
378 // back too to keep the timestamps emitted for a cluster monotonically 376 // back too to keep the timestamps emitted for a cluster monotonically
(...skipping 708 matching lines...) Expand 10 before | Expand all | Expand 10 after
1087 int duration_ms = packet_ptr->duration_ms(); // Casts from double. 1085 int duration_ms = packet_ptr->duration_ms(); // Casts from double.
1088 if (duration_ms > 120) { 1086 if (duration_ms > 120) {
1089 EXPECT_MEDIA_LOG(OpusPacketDurationTooHigh(duration_ms)); 1087 EXPECT_MEDIA_LOG(OpusPacketDurationTooHigh(duration_ms));
1090 } 1088 }
1091 1089
1092 int result = parser_->Parse(cluster->data(), cluster->size()); 1090 int result = parser_->Parse(cluster->data(), cluster->size());
1093 EXPECT_EQ(cluster->size(), result); 1091 EXPECT_EQ(cluster->size(), result);
1094 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count)); 1092 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count));
1095 1093
1096 // Fail early if any iteration fails to meet the logging expectations. 1094 // Fail early if any iteration fails to meet the logging expectations.
1097 ASSERT_TRUE(Mock::VerifyAndClearExpectations(media_log_.get())); 1095 ASSERT_TRUE(Mock::VerifyAndClearExpectations(&media_log_));
1098 1096
1099 loop_count++; 1097 loop_count++;
1100 } 1098 }
1101 1099
1102 // Test should minimally cover all the combinations of config and frame count. 1100 // Test should minimally cover all the combinations of config and frame count.
1103 ASSERT_GE(loop_count, kNumPossibleOpusConfigs * kMaxOpusPacketFrameCount); 1101 ASSERT_GE(loop_count, kNumPossibleOpusConfigs * kMaxOpusPacketFrameCount);
1104 } 1102 }
1105 1103
1106 TEST_F(WebMClusterParserTest, PreferOpusDurationsOverBlockDurations) { 1104 TEST_F(WebMClusterParserTest, PreferOpusDurationsOverBlockDurations) {
1107 int loop_count = 0; 1105 int loop_count = 0;
(...skipping 26 matching lines...) Expand all
1134 int result = parser_->Parse(cluster->data(), cluster->size()); 1132 int result = parser_->Parse(cluster->data(), cluster->size());
1135 EXPECT_EQ(cluster->size(), result); 1133 EXPECT_EQ(cluster->size(), result);
1136 1134
1137 // BlockInfo duration will be used to verify buffer duration, so changing 1135 // BlockInfo duration will be used to verify buffer duration, so changing
1138 // duration to be that of the Opus packet to verify it was preferred. 1136 // duration to be that of the Opus packet to verify it was preferred.
1139 block_infos[0].duration = packet_ptr->duration_ms(); 1137 block_infos[0].duration = packet_ptr->duration_ms();
1140 1138
1141 ASSERT_TRUE(VerifyBuffers(parser_, block_infos, block_count)); 1139 ASSERT_TRUE(VerifyBuffers(parser_, block_infos, block_count));
1142 1140
1143 // Fail early if any iteration fails to meet the logging expectations. 1141 // Fail early if any iteration fails to meet the logging expectations.
1144 ASSERT_TRUE(Mock::VerifyAndClearExpectations(media_log_.get())); 1142 ASSERT_TRUE(Mock::VerifyAndClearExpectations(&media_log_));
1145 1143
1146 loop_count++; 1144 loop_count++;
1147 } 1145 }
1148 1146
1149 // Test should minimally cover all the combinations of config and frame count. 1147 // Test should minimally cover all the combinations of config and frame count.
1150 ASSERT_GE(loop_count, kNumPossibleOpusConfigs * kMaxOpusPacketFrameCount); 1148 ASSERT_GE(loop_count, kNumPossibleOpusConfigs * kMaxOpusPacketFrameCount);
1151 } 1149 }
1152 1150
1153 // Tests that BlockDuration is used to set duration on buffer rather than 1151 // Tests that BlockDuration is used to set duration on buffer rather than
1154 // encoded duration in Opus packet (or hard coded duration estimates). Encoded 1152 // encoded duration in Opus packet (or hard coded duration estimates). Encoded
(...skipping 17 matching lines...) Expand all
1172 int block_count = arraysize(kBlockInfo); 1170 int block_count = arraysize(kBlockInfo);
1173 std::unique_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); 1171 std::unique_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count));
1174 int result = parser_->Parse(cluster->data(), cluster->size()); 1172 int result = parser_->Parse(cluster->data(), cluster->size());
1175 EXPECT_EQ(cluster->size(), result); 1173 EXPECT_EQ(cluster->size(), result);
1176 1174
1177 // Will verify that duration of buffer matches that of BlockDuration. 1175 // Will verify that duration of buffer matches that of BlockDuration.
1178 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count)); 1176 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count));
1179 } 1177 }
1180 1178
1181 } // namespace media 1179 } // namespace media
OLDNEW
« no previous file with comments | « media/formats/webm/webm_cluster_parser.cc ('k') | media/formats/webm/webm_content_encodings_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698