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

Side by Side Diff: media/formats/webm/webm_tracks_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
« no previous file with comments | « media/formats/webm/webm_tracks_parser.cc ('k') | media/formats/webm/webm_video_client.h » ('j') | 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 "media/formats/webm/webm_tracks_parser.h" 5 #include "media/formats/webm/webm_tracks_parser.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 12 matching lines...) Expand all
23 using ::testing::Return; 23 using ::testing::Return;
24 using ::testing::StrictMock; 24 using ::testing::StrictMock;
25 using ::testing::_; 25 using ::testing::_;
26 26
27 namespace media { 27 namespace media {
28 28
29 static const double kDefaultTimecodeScaleInUs = 1000.0; // 1 ms resolution 29 static const double kDefaultTimecodeScaleInUs = 1000.0; // 1 ms resolution
30 30
31 class WebMTracksParserTest : public testing::Test { 31 class WebMTracksParserTest : public testing::Test {
32 public: 32 public:
33 WebMTracksParserTest() : media_log_(new StrictMock<MockMediaLog>()) {} 33 WebMTracksParserTest() {}
34 34
35 protected: 35 protected:
36 void VerifyTextTrackInfo(const uint8_t* buffer, 36 void VerifyTextTrackInfo(const uint8_t* buffer,
37 int buffer_size, 37 int buffer_size,
38 TextKind text_kind, 38 TextKind text_kind,
39 const std::string& name, 39 const std::string& name,
40 const std::string& language) { 40 const std::string& language) {
41 std::unique_ptr<WebMTracksParser> parser( 41 std::unique_ptr<WebMTracksParser> parser(
42 new WebMTracksParser(media_log_, false)); 42 new WebMTracksParser(&media_log_, false));
43 43
44 int result = parser->Parse(buffer, buffer_size); 44 int result = parser->Parse(buffer, buffer_size);
45 EXPECT_GT(result, 0); 45 EXPECT_GT(result, 0);
46 EXPECT_EQ(result, buffer_size); 46 EXPECT_EQ(result, buffer_size);
47 47
48 const WebMTracksParser::TextTracks& text_tracks = parser->text_tracks(); 48 const WebMTracksParser::TextTracks& text_tracks = parser->text_tracks();
49 EXPECT_EQ(text_tracks.size(), WebMTracksParser::TextTracks::size_type(1)); 49 EXPECT_EQ(text_tracks.size(), WebMTracksParser::TextTracks::size_type(1));
50 50
51 const WebMTracksParser::TextTracks::const_iterator itr = 51 const WebMTracksParser::TextTracks::const_iterator itr =
52 text_tracks.begin(); 52 text_tracks.begin();
53 EXPECT_EQ(itr->first, 1); // track num 53 EXPECT_EQ(itr->first, 1); // track num
54 54
55 const TextTrackConfig& config = itr->second; 55 const TextTrackConfig& config = itr->second;
56 EXPECT_EQ(config.kind(), text_kind); 56 EXPECT_EQ(config.kind(), text_kind);
57 EXPECT_TRUE(config.label() == name); 57 EXPECT_TRUE(config.label() == name);
58 EXPECT_TRUE(config.language() == language); 58 EXPECT_TRUE(config.language() == language);
59 } 59 }
60 60
61 scoped_refptr<StrictMock<MockMediaLog>> media_log_; 61 StrictMock<MockMediaLog> media_log_;
62 }; 62 };
63 63
64 TEST_F(WebMTracksParserTest, SubtitleNoNameNoLang) { 64 TEST_F(WebMTracksParserTest, SubtitleNoNameNoLang) {
65 InSequence s; 65 InSequence s;
66 66
67 TracksBuilder tb; 67 TracksBuilder tb;
68 tb.AddTextTrack(1, 1, kWebMCodecSubtitles, "", ""); 68 tb.AddTextTrack(1, 1, kWebMCodecSubtitles, "", "");
69 69
70 const std::vector<uint8_t> buf = tb.Finish(); 70 const std::vector<uint8_t> buf = tb.Finish();
71 VerifyTextTrackInfo(&buf[0], buf.size(), kTextSubtitles, "", ""); 71 VerifyTextTrackInfo(&buf[0], buf.size(), kTextSubtitles, "", "");
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 103
104 TEST_F(WebMTracksParserTest, IgnoringTextTracks) { 104 TEST_F(WebMTracksParserTest, IgnoringTextTracks) {
105 InSequence s; 105 InSequence s;
106 106
107 TracksBuilder tb; 107 TracksBuilder tb;
108 tb.AddTextTrack(1, 1, kWebMCodecSubtitles, "Subtitles", "fre"); 108 tb.AddTextTrack(1, 1, kWebMCodecSubtitles, "Subtitles", "fre");
109 tb.AddTextTrack(2, 2, kWebMCodecSubtitles, "Commentary", "fre"); 109 tb.AddTextTrack(2, 2, kWebMCodecSubtitles, "Commentary", "fre");
110 110
111 const std::vector<uint8_t> buf = tb.Finish(); 111 const std::vector<uint8_t> buf = tb.Finish();
112 std::unique_ptr<WebMTracksParser> parser( 112 std::unique_ptr<WebMTracksParser> parser(
113 new WebMTracksParser(media_log_, true)); 113 new WebMTracksParser(&media_log_, true));
114 114
115 EXPECT_MEDIA_LOG(HasSubstr("Ignoring text track 1")); 115 EXPECT_MEDIA_LOG(HasSubstr("Ignoring text track 1"));
116 EXPECT_MEDIA_LOG(HasSubstr("Ignoring text track 2")); 116 EXPECT_MEDIA_LOG(HasSubstr("Ignoring text track 2"));
117 117
118 int result = parser->Parse(&buf[0], buf.size()); 118 int result = parser->Parse(&buf[0], buf.size());
119 EXPECT_GT(result, 0); 119 EXPECT_GT(result, 0);
120 EXPECT_EQ(result, static_cast<int>(buf.size())); 120 EXPECT_EQ(result, static_cast<int>(buf.size()));
121 121
122 EXPECT_EQ(parser->text_tracks().size(), 0u); 122 EXPECT_EQ(parser->text_tracks().size(), 0u);
123 123
124 const std::set<int64_t>& ignored_tracks = parser->ignored_tracks(); 124 const std::set<int64_t>& ignored_tracks = parser->ignored_tracks();
125 EXPECT_TRUE(ignored_tracks.find(1) != ignored_tracks.end()); 125 EXPECT_TRUE(ignored_tracks.find(1) != ignored_tracks.end());
126 EXPECT_TRUE(ignored_tracks.find(2) != ignored_tracks.end()); 126 EXPECT_TRUE(ignored_tracks.find(2) != ignored_tracks.end());
127 127
128 // Test again w/o ignoring the test tracks. 128 // Test again w/o ignoring the test tracks.
129 parser.reset(new WebMTracksParser(media_log_, false)); 129 parser.reset(new WebMTracksParser(&media_log_, false));
130 130
131 result = parser->Parse(&buf[0], buf.size()); 131 result = parser->Parse(&buf[0], buf.size());
132 EXPECT_GT(result, 0); 132 EXPECT_GT(result, 0);
133 133
134 EXPECT_EQ(parser->ignored_tracks().size(), 0u); 134 EXPECT_EQ(parser->ignored_tracks().size(), 0u);
135 EXPECT_EQ(parser->text_tracks().size(), 2u); 135 EXPECT_EQ(parser->text_tracks().size(), 2u);
136 } 136 }
137 137
138 TEST_F(WebMTracksParserTest, AudioVideoDefaultDurationUnset) { 138 TEST_F(WebMTracksParserTest, AudioVideoDefaultDurationUnset) {
139 // Other audio/video decoder config fields are necessary in the test 139 // Other audio/video decoder config fields are necessary in the test
140 // audio/video TrackEntry configurations. This method does only very minimal 140 // audio/video TrackEntry configurations. This method does only very minimal
141 // verification of their inclusion and parsing; the goal is to confirm 141 // verification of their inclusion and parsing; the goal is to confirm
142 // TrackEntry DefaultDuration defaults to -1 if not included in audio or 142 // TrackEntry DefaultDuration defaults to -1 if not included in audio or
143 // video TrackEntry. 143 // video TrackEntry.
144 TracksBuilder tb; 144 TracksBuilder tb;
145 tb.AddAudioTrack(1, 1, "A_VORBIS", "audio", "", -1, 2, 8000); 145 tb.AddAudioTrack(1, 1, "A_VORBIS", "audio", "", -1, 2, 8000);
146 tb.AddVideoTrack(2, 2, "V_VP8", "video", "", -1, 320, 240); 146 tb.AddVideoTrack(2, 2, "V_VP8", "video", "", -1, 320, 240);
147 const std::vector<uint8_t> buf = tb.Finish(); 147 const std::vector<uint8_t> buf = tb.Finish();
148 148
149 std::unique_ptr<WebMTracksParser> parser( 149 std::unique_ptr<WebMTracksParser> parser(
150 new WebMTracksParser(media_log_, true)); 150 new WebMTracksParser(&media_log_, true));
151 int result = parser->Parse(&buf[0], buf.size()); 151 int result = parser->Parse(&buf[0], buf.size());
152 EXPECT_LE(0, result); 152 EXPECT_LE(0, result);
153 EXPECT_EQ(static_cast<int>(buf.size()), result); 153 EXPECT_EQ(static_cast<int>(buf.size()), result);
154 154
155 EXPECT_EQ(kNoTimestamp, 155 EXPECT_EQ(kNoTimestamp,
156 parser->GetAudioDefaultDuration(kDefaultTimecodeScaleInUs)); 156 parser->GetAudioDefaultDuration(kDefaultTimecodeScaleInUs));
157 EXPECT_EQ(kNoTimestamp, 157 EXPECT_EQ(kNoTimestamp,
158 parser->GetVideoDefaultDuration(kDefaultTimecodeScaleInUs)); 158 parser->GetVideoDefaultDuration(kDefaultTimecodeScaleInUs));
159 159
160 const VideoDecoderConfig& video_config = parser->video_decoder_config(); 160 const VideoDecoderConfig& video_config = parser->video_decoder_config();
161 EXPECT_TRUE(video_config.IsValidConfig()); 161 EXPECT_TRUE(video_config.IsValidConfig());
162 EXPECT_EQ(320, video_config.coded_size().width()); 162 EXPECT_EQ(320, video_config.coded_size().width());
163 EXPECT_EQ(240, video_config.coded_size().height()); 163 EXPECT_EQ(240, video_config.coded_size().height());
164 164
165 const AudioDecoderConfig& audio_config = parser->audio_decoder_config(); 165 const AudioDecoderConfig& audio_config = parser->audio_decoder_config();
166 EXPECT_TRUE(audio_config.IsValidConfig()); 166 EXPECT_TRUE(audio_config.IsValidConfig());
167 EXPECT_EQ(CHANNEL_LAYOUT_STEREO, audio_config.channel_layout()); 167 EXPECT_EQ(CHANNEL_LAYOUT_STEREO, audio_config.channel_layout());
168 EXPECT_EQ(8000, audio_config.samples_per_second()); 168 EXPECT_EQ(8000, audio_config.samples_per_second());
169 } 169 }
170 170
171 TEST_F(WebMTracksParserTest, AudioVideoDefaultDurationSet) { 171 TEST_F(WebMTracksParserTest, AudioVideoDefaultDurationSet) {
172 // Confirm audio or video TrackEntry DefaultDuration values are parsed, if 172 // Confirm audio or video TrackEntry DefaultDuration values are parsed, if
173 // present. 173 // present.
174 TracksBuilder tb; 174 TracksBuilder tb;
175 tb.AddAudioTrack(1, 1, "A_VORBIS", "audio", "", 12345678, 2, 8000); 175 tb.AddAudioTrack(1, 1, "A_VORBIS", "audio", "", 12345678, 2, 8000);
176 tb.AddVideoTrack(2, 2, "V_VP8", "video", "", 987654321, 320, 240); 176 tb.AddVideoTrack(2, 2, "V_VP8", "video", "", 987654321, 320, 240);
177 const std::vector<uint8_t> buf = tb.Finish(); 177 const std::vector<uint8_t> buf = tb.Finish();
178 178
179 std::unique_ptr<WebMTracksParser> parser( 179 std::unique_ptr<WebMTracksParser> parser(
180 new WebMTracksParser(media_log_, true)); 180 new WebMTracksParser(&media_log_, true));
181 int result = parser->Parse(&buf[0], buf.size()); 181 int result = parser->Parse(&buf[0], buf.size());
182 EXPECT_LE(0, result); 182 EXPECT_LE(0, result);
183 EXPECT_EQ(static_cast<int>(buf.size()), result); 183 EXPECT_EQ(static_cast<int>(buf.size()), result);
184 184
185 EXPECT_EQ(base::TimeDelta::FromMicroseconds(12000), 185 EXPECT_EQ(base::TimeDelta::FromMicroseconds(12000),
186 parser->GetAudioDefaultDuration(kDefaultTimecodeScaleInUs)); 186 parser->GetAudioDefaultDuration(kDefaultTimecodeScaleInUs));
187 EXPECT_EQ(base::TimeDelta::FromMicroseconds(985000), 187 EXPECT_EQ(base::TimeDelta::FromMicroseconds(985000),
188 parser->GetVideoDefaultDuration(5000.0)); // 5 ms resolution 188 parser->GetVideoDefaultDuration(5000.0)); // 5 ms resolution
189 EXPECT_EQ(kNoTimestamp, parser->GetAudioDefaultDuration(12346.0)); 189 EXPECT_EQ(kNoTimestamp, parser->GetAudioDefaultDuration(12346.0));
190 EXPECT_EQ(base::TimeDelta::FromMicroseconds(12345), 190 EXPECT_EQ(base::TimeDelta::FromMicroseconds(12345),
191 parser->GetAudioDefaultDuration(12345.0)); 191 parser->GetAudioDefaultDuration(12345.0));
192 EXPECT_EQ(base::TimeDelta::FromMicroseconds(12003), 192 EXPECT_EQ(base::TimeDelta::FromMicroseconds(12003),
193 parser->GetAudioDefaultDuration(1000.3)); // 1.0003 ms resolution 193 parser->GetAudioDefaultDuration(1000.3)); // 1.0003 ms resolution
194 } 194 }
195 195
196 TEST_F(WebMTracksParserTest, InvalidZeroDefaultDurationSet) { 196 TEST_F(WebMTracksParserTest, InvalidZeroDefaultDurationSet) {
197 // Confirm parse error if TrackEntry DefaultDuration is present, but is 0ns. 197 // Confirm parse error if TrackEntry DefaultDuration is present, but is 0ns.
198 TracksBuilder tb(true); 198 TracksBuilder tb(true);
199 tb.AddAudioTrack(1, 1, "A_VORBIS", "audio", "", 0, 2, 8000); 199 tb.AddAudioTrack(1, 1, "A_VORBIS", "audio", "", 0, 2, 8000);
200 const std::vector<uint8_t> buf = tb.Finish(); 200 const std::vector<uint8_t> buf = tb.Finish();
201 201
202 std::unique_ptr<WebMTracksParser> parser( 202 std::unique_ptr<WebMTracksParser> parser(
203 new WebMTracksParser(media_log_, true)); 203 new WebMTracksParser(&media_log_, true));
204 204
205 EXPECT_MEDIA_LOG(HasSubstr("Illegal 0ns audio TrackEntry DefaultDuration")); 205 EXPECT_MEDIA_LOG(HasSubstr("Illegal 0ns audio TrackEntry DefaultDuration"));
206 206
207 EXPECT_EQ(-1, parser->Parse(&buf[0], buf.size())); 207 EXPECT_EQ(-1, parser->Parse(&buf[0], buf.size()));
208 } 208 }
209 209
210 TEST_F(WebMTracksParserTest, HighTrackUID) { 210 TEST_F(WebMTracksParserTest, HighTrackUID) {
211 // Confirm no parse error if TrackEntry TrackUID has MSb set 211 // Confirm no parse error if TrackEntry TrackUID has MSb set
212 // (http://crbug.com/397067). 212 // (http://crbug.com/397067).
213 TracksBuilder tb(true); 213 TracksBuilder tb(true);
214 tb.AddAudioTrack(1, 1ULL << 31, "A_VORBIS", "audio", "", 40, 2, 8000); 214 tb.AddAudioTrack(1, 1ULL << 31, "A_VORBIS", "audio", "", 40, 2, 8000);
215 const std::vector<uint8_t> buf = tb.Finish(); 215 const std::vector<uint8_t> buf = tb.Finish();
216 216
217 std::unique_ptr<WebMTracksParser> parser( 217 std::unique_ptr<WebMTracksParser> parser(
218 new WebMTracksParser(media_log_, true)); 218 new WebMTracksParser(&media_log_, true));
219 EXPECT_GT(parser->Parse(&buf[0], buf.size()),0); 219 EXPECT_GT(parser->Parse(&buf[0], buf.size()),0);
220 } 220 }
221 221
222 } // namespace media 222 } // namespace media
OLDNEW
« no previous file with comments | « media/formats/webm/webm_tracks_parser.cc ('k') | media/formats/webm/webm_video_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698