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

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

Issue 1316013002: MSE: Refine WebM parser unit test MediaLog verification (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@fix_and_reland_mse_webm_parser_medialog_verifications
Patch Set: Created 5 years, 3 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <cstdlib> 6 #include <cstdlib>
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
13 #include "media/base/audio_decoder_config.h" 13 #include "media/base/audio_decoder_config.h"
14 #include "media/base/decrypt_config.h" 14 #include "media/base/decrypt_config.h"
15 #include "media/base/mock_media_log.h" 15 #include "media/base/mock_media_log.h"
16 #include "media/formats/webm/cluster_builder.h" 16 #include "media/formats/webm/cluster_builder.h"
17 #include "media/formats/webm/opus_packet_builder.h" 17 #include "media/formats/webm/opus_packet_builder.h"
18 #include "media/formats/webm/webm_cluster_parser.h" 18 #include "media/formats/webm/webm_cluster_parser.h"
19 #include "media/formats/webm/webm_constants.h" 19 #include "media/formats/webm/webm_constants.h"
20 #include "testing/gmock/include/gmock/gmock.h" 20 #include "testing/gmock/include/gmock/gmock.h"
21 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
22 22
23 using ::testing::HasSubstr; 23 using ::testing::HasSubstr;
24 using ::testing::InSequence; 24 using ::testing::InSequence;
25 using ::testing::Return; 25 using ::testing::Return;
26 using ::testing::StrictMock; 26 using ::testing::StrictMock;
27 using ::testing::Mock;
27 using ::testing::_; 28 using ::testing::_;
28 29
29 namespace media { 30 namespace media {
30 31
31 typedef WebMTracksParser::TextTracks TextTracks; 32 typedef WebMTracksParser::TextTracks TextTracks;
32 33
33 // Matchers for verifying common media log entry strings. 34 // Matchers for verifying common media log entry strings.
34 MATCHER_P(OpusPacketDurationTooHigh, actual_duration_ms, "") { 35 MATCHER_P(OpusPacketDurationTooHigh, actual_duration_ms, "") {
35 return CONTAINS_STRING( 36 return CONTAINS_STRING(
36 arg, "Warning, demuxed Opus packet with encoded duration: " + 37 arg, "Warning, demuxed Opus packet with encoded duration: " +
(...skipping 993 matching lines...) Expand 10 before | Expand all | Expand 10 after
1030 }; 1031 };
1031 1032
1032 int block_count = arraysize(kBlockInfo); 1033 int block_count = arraysize(kBlockInfo);
1033 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); 1034 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count));
1034 int result = parser_->Parse(cluster->data(), cluster->size()); 1035 int result = parser_->Parse(cluster->data(), cluster->size());
1035 EXPECT_EQ(cluster->size(), result); 1036 EXPECT_EQ(cluster->size(), result);
1036 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count)); 1037 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count));
1037 } 1038 }
1038 1039
1039 TEST_F(WebMClusterParserTest, ReadOpusDurationsSimpleBlockAtEndOfCluster) { 1040 TEST_F(WebMClusterParserTest, ReadOpusDurationsSimpleBlockAtEndOfCluster) {
1040 InSequence s;
1041
1042 int loop_count = 0; 1041 int loop_count = 0;
1043 for (const auto* packet_ptr : BuildAllOpusPackets()) { 1042 for (const auto* packet_ptr : BuildAllOpusPackets()) {
1043 InSequence s;
1044
1044 // Get a new parser each iteration to prevent exceeding the media log cap. 1045 // Get a new parser each iteration to prevent exceeding the media log cap.
1045 parser_.reset(CreateParserWithKeyIdsAndAudioCodec( 1046 parser_.reset(CreateParserWithKeyIdsAndAudioCodec(
1046 std::string(), std::string(), kCodecOpus)); 1047 std::string(), std::string(), kCodecOpus));
1047 1048
1048 const BlockInfo kBlockInfo[] = {{kAudioTrackNum, 1049 const BlockInfo kBlockInfo[] = {{kAudioTrackNum,
1049 0, 1050 0,
1050 packet_ptr->duration_ms(), 1051 packet_ptr->duration_ms(),
1051 true, // Make it a SimpleBlock. 1052 true, // Make it a SimpleBlock.
1052 packet_ptr->data(), 1053 packet_ptr->data(),
1053 packet_ptr->size()}}; 1054 packet_ptr->size()}};
1054 1055
1055 int block_count = arraysize(kBlockInfo); 1056 int block_count = arraysize(kBlockInfo);
1056 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); 1057 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count));
1057 int duration_ms = packet_ptr->duration_ms(); // Casts from double. 1058 int duration_ms = packet_ptr->duration_ms(); // Casts from double.
1058 if (duration_ms > 120) { 1059 if (duration_ms > 120) {
1059 EXPECT_MEDIA_LOG(OpusPacketDurationTooHigh(duration_ms)); 1060 EXPECT_MEDIA_LOG(OpusPacketDurationTooHigh(duration_ms));
1060 } 1061 }
1061 1062
1062 int result = parser_->Parse(cluster->data(), cluster->size()); 1063 int result = parser_->Parse(cluster->data(), cluster->size());
1063 EXPECT_EQ(cluster->size(), result); 1064 EXPECT_EQ(cluster->size(), result);
1064 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count)); 1065 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count));
1066
1067 // Fail early if any iteration fails to meet the logging expectations.
1068 ASSERT_TRUE(Mock::VerifyAndClearExpectations(media_log_.get()));
1069
1065 loop_count++; 1070 loop_count++;
1066 } 1071 }
1067 1072
1068 // Test should minimally cover all the combinations of config and frame count. 1073 // Test should minimally cover all the combinations of config and frame count.
1069 ASSERT_GE(loop_count, kNumPossibleOpusConfigs * kMaxOpusPacketFrameCount); 1074 ASSERT_GE(loop_count, kNumPossibleOpusConfigs * kMaxOpusPacketFrameCount);
1070 } 1075 }
1071 1076
1072 TEST_F(WebMClusterParserTest, PreferOpusDurationsOverBlockDurations) { 1077 TEST_F(WebMClusterParserTest, PreferOpusDurationsOverBlockDurations) {
1073 // Exhaustively testing expected media logs' emission sequence in this test at
1074 // least causes 10x execution time. Therefore, no InSequence is used here, but
1075 // the set of expected messages is verified.
1076
1077 int loop_count = 0; 1078 int loop_count = 0;
1078 for (const auto* packet_ptr : BuildAllOpusPackets()) { 1079 for (const auto* packet_ptr : BuildAllOpusPackets()) {
1080 InSequence s;
1081
1079 // Get a new parser each iteration to prevent exceeding the media log cap. 1082 // Get a new parser each iteration to prevent exceeding the media log cap.
1080 parser_.reset(CreateParserWithKeyIdsAndAudioCodec( 1083 parser_.reset(CreateParserWithKeyIdsAndAudioCodec(
1081 std::string(), std::string(), kCodecOpus)); 1084 std::string(), std::string(), kCodecOpus));
1082 1085
1083 // Setting BlockDuration != Opus duration to see which one the parser uses. 1086 // Setting BlockDuration != Opus duration to see which one the parser uses.
1084 int block_duration_ms = packet_ptr->duration_ms() + 10; 1087 int block_duration_ms = packet_ptr->duration_ms() + 10;
1085 if (packet_ptr->duration_ms() > 120) { 1088 if (packet_ptr->duration_ms() > 120) {
1086 EXPECT_MEDIA_LOG(OpusPacketDurationTooHigh(packet_ptr->duration_ms())); 1089 EXPECT_MEDIA_LOG(OpusPacketDurationTooHigh(packet_ptr->duration_ms()));
1087 } 1090 }
1088 1091
(...skipping 10 matching lines...) Expand all
1099 int block_count = arraysize(block_infos); 1102 int block_count = arraysize(block_infos);
1100 scoped_ptr<Cluster> cluster(CreateCluster(0, block_infos, block_count)); 1103 scoped_ptr<Cluster> cluster(CreateCluster(0, block_infos, block_count));
1101 int result = parser_->Parse(cluster->data(), cluster->size()); 1104 int result = parser_->Parse(cluster->data(), cluster->size());
1102 EXPECT_EQ(cluster->size(), result); 1105 EXPECT_EQ(cluster->size(), result);
1103 1106
1104 // BlockInfo duration will be used to verify buffer duration, so changing 1107 // BlockInfo duration will be used to verify buffer duration, so changing
1105 // duration to be that of the Opus packet to verify it was preferred. 1108 // duration to be that of the Opus packet to verify it was preferred.
1106 block_infos[0].duration = packet_ptr->duration_ms(); 1109 block_infos[0].duration = packet_ptr->duration_ms();
1107 1110
1108 ASSERT_TRUE(VerifyBuffers(parser_, block_infos, block_count)); 1111 ASSERT_TRUE(VerifyBuffers(parser_, block_infos, block_count));
1112
1113 // Fail early if any iteration fails to meet the logging expectations.
1114 ASSERT_TRUE(Mock::VerifyAndClearExpectations(media_log_.get()));
1115
1109 loop_count++; 1116 loop_count++;
1110 } 1117 }
1111 1118
1112 // Test should minimally cover all the combinations of config and frame count. 1119 // Test should minimally cover all the combinations of config and frame count.
1113 ASSERT_GE(loop_count, kNumPossibleOpusConfigs * kMaxOpusPacketFrameCount); 1120 ASSERT_GE(loop_count, kNumPossibleOpusConfigs * kMaxOpusPacketFrameCount);
1114 } 1121 }
1115 1122
1116 // Tests that BlockDuration is used to set duration on buffer rather than 1123 // Tests that BlockDuration is used to set duration on buffer rather than
1117 // encoded duration in Opus packet (or hard coded duration estimates). Encoded 1124 // encoded duration in Opus packet (or hard coded duration estimates). Encoded
1118 // Opus duration is usually preferred but cannot be known when encrypted. 1125 // Opus duration is usually preferred but cannot be known when encrypted.
(...skipping 16 matching lines...) Expand all
1135 int block_count = arraysize(kBlockInfo); 1142 int block_count = arraysize(kBlockInfo);
1136 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); 1143 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count));
1137 int result = parser_->Parse(cluster->data(), cluster->size()); 1144 int result = parser_->Parse(cluster->data(), cluster->size());
1138 EXPECT_EQ(cluster->size(), result); 1145 EXPECT_EQ(cluster->size(), result);
1139 1146
1140 // Will verify that duration of buffer matches that of BlockDuration. 1147 // Will verify that duration of buffer matches that of BlockDuration.
1141 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count)); 1148 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count));
1142 } 1149 }
1143 1150
1144 } // namespace media 1151 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698