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

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

Issue 213153008: MSE: Parse WebM TrackEntry DefaultDuration field (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixes lint err (c-style cast). Created 6 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 | Annotate | Revision Log
« no previous file with comments | « media/formats/webm/webm_tracks_parser.cc ('k') | 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 "base/logging.h" 5 #include "base/logging.h"
6 #include "media/base/channel_layout.h"
6 #include "media/formats/webm/tracks_builder.h" 7 #include "media/formats/webm/tracks_builder.h"
7 #include "media/formats/webm/webm_constants.h" 8 #include "media/formats/webm/webm_constants.h"
8 #include "media/formats/webm/webm_tracks_parser.h" 9 #include "media/formats/webm/webm_tracks_parser.h"
9 #include "testing/gmock/include/gmock/gmock.h" 10 #include "testing/gmock/include/gmock/gmock.h"
10 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
11 12
12 using ::testing::InSequence; 13 using ::testing::InSequence;
13 using ::testing::Return; 14 using ::testing::Return;
14 using ::testing::_; 15 using ::testing::_;
15 16
16 namespace media { 17 namespace media {
17 18
19 static const double kDefaultTimecodeScaleInUs = 1000.0; // 1 ms resolution
20
18 class WebMTracksParserTest : public testing::Test { 21 class WebMTracksParserTest : public testing::Test {
19 public: 22 public:
20 WebMTracksParserTest() {} 23 WebMTracksParserTest() {}
21 }; 24 };
22 25
23 static void VerifyTextTrackInfo(const uint8* buffer, 26 static void VerifyTextTrackInfo(const uint8* buffer,
24 int buffer_size, 27 int buffer_size,
25 TextKind text_kind, 28 TextKind text_kind,
26 const std::string& name, 29 const std::string& name,
27 const std::string& language) { 30 const std::string& language) {
(...skipping 12 matching lines...) Expand all
40 const TextTrackConfig& config = itr->second; 43 const TextTrackConfig& config = itr->second;
41 EXPECT_EQ(config.kind(), text_kind); 44 EXPECT_EQ(config.kind(), text_kind);
42 EXPECT_TRUE(config.label() == name); 45 EXPECT_TRUE(config.label() == name);
43 EXPECT_TRUE(config.language() == language); 46 EXPECT_TRUE(config.language() == language);
44 } 47 }
45 48
46 TEST_F(WebMTracksParserTest, SubtitleNoNameNoLang) { 49 TEST_F(WebMTracksParserTest, SubtitleNoNameNoLang) {
47 InSequence s; 50 InSequence s;
48 51
49 TracksBuilder tb; 52 TracksBuilder tb;
50 tb.AddTrack(1, kWebMTrackTypeSubtitlesOrCaptions, 1, 53 tb.AddTextTrack(1, 1, kWebMCodecSubtitles, "", "");
51 kWebMCodecSubtitles, "", "");
52 54
53 const std::vector<uint8> buf = tb.Finish(); 55 const std::vector<uint8> buf = tb.Finish();
54 VerifyTextTrackInfo(&buf[0], buf.size(), kTextSubtitles, "", ""); 56 VerifyTextTrackInfo(&buf[0], buf.size(), kTextSubtitles, "", "");
55 } 57 }
56 58
57 TEST_F(WebMTracksParserTest, SubtitleYesNameNoLang) { 59 TEST_F(WebMTracksParserTest, SubtitleYesNameNoLang) {
58 InSequence s; 60 InSequence s;
59 61
60 TracksBuilder tb; 62 TracksBuilder tb;
61 tb.AddTrack(1, kWebMTrackTypeSubtitlesOrCaptions, 1, 63 tb.AddTextTrack(1, 1, kWebMCodecSubtitles, "Spock", "");
62 kWebMCodecSubtitles, "Spock", "");
63 64
64 const std::vector<uint8> buf = tb.Finish(); 65 const std::vector<uint8> buf = tb.Finish();
65 VerifyTextTrackInfo(&buf[0], buf.size(), kTextSubtitles, "Spock", ""); 66 VerifyTextTrackInfo(&buf[0], buf.size(), kTextSubtitles, "Spock", "");
66 } 67 }
67 68
68 TEST_F(WebMTracksParserTest, SubtitleNoNameYesLang) { 69 TEST_F(WebMTracksParserTest, SubtitleNoNameYesLang) {
69 InSequence s; 70 InSequence s;
70 71
71 TracksBuilder tb; 72 TracksBuilder tb;
72 tb.AddTrack(1, kWebMTrackTypeSubtitlesOrCaptions, 1, 73 tb.AddTextTrack(1, 1, kWebMCodecSubtitles, "", "eng");
73 kWebMCodecSubtitles, "", "eng");
74 74
75 const std::vector<uint8> buf = tb.Finish(); 75 const std::vector<uint8> buf = tb.Finish();
76 VerifyTextTrackInfo(&buf[0], buf.size(), kTextSubtitles, "", "eng"); 76 VerifyTextTrackInfo(&buf[0], buf.size(), kTextSubtitles, "", "eng");
77 } 77 }
78 78
79 TEST_F(WebMTracksParserTest, SubtitleYesNameYesLang) { 79 TEST_F(WebMTracksParserTest, SubtitleYesNameYesLang) {
80 InSequence s; 80 InSequence s;
81 81
82 TracksBuilder tb; 82 TracksBuilder tb;
83 tb.AddTrack(1, kWebMTrackTypeSubtitlesOrCaptions, 1, 83 tb.AddTextTrack(1, 1, kWebMCodecSubtitles, "Picard", "fre");
84 kWebMCodecSubtitles, "Picard", "fre");
85 84
86 const std::vector<uint8> buf = tb.Finish(); 85 const std::vector<uint8> buf = tb.Finish();
87 VerifyTextTrackInfo(&buf[0], buf.size(), kTextSubtitles, "Picard", "fre"); 86 VerifyTextTrackInfo(&buf[0], buf.size(), kTextSubtitles, "Picard", "fre");
88 } 87 }
89 88
90 TEST_F(WebMTracksParserTest, IgnoringTextTracks) { 89 TEST_F(WebMTracksParserTest, IgnoringTextTracks) {
91 InSequence s; 90 InSequence s;
92 91
93 TracksBuilder tb; 92 TracksBuilder tb;
94 tb.AddTrack(1, kWebMTrackTypeSubtitlesOrCaptions, 1, 93 tb.AddTextTrack(1, 1, kWebMCodecSubtitles, "Subtitles", "fre");
95 kWebMCodecSubtitles, "Subtitles", "fre"); 94 tb.AddTextTrack(2, 2, kWebMCodecSubtitles, "Commentary", "fre");
96 tb.AddTrack(2, kWebMTrackTypeSubtitlesOrCaptions, 2,
97 kWebMCodecSubtitles, "Commentary", "fre");
98 95
99 const std::vector<uint8> buf = tb.Finish(); 96 const std::vector<uint8> buf = tb.Finish();
100 scoped_ptr<WebMTracksParser> parser(new WebMTracksParser(LogCB(), true)); 97 scoped_ptr<WebMTracksParser> parser(new WebMTracksParser(LogCB(), true));
101 98
102 int result = parser->Parse(&buf[0], buf.size()); 99 int result = parser->Parse(&buf[0], buf.size());
103 EXPECT_GT(result, 0); 100 EXPECT_GT(result, 0);
104 EXPECT_EQ(result, static_cast<int>(buf.size())); 101 EXPECT_EQ(result, static_cast<int>(buf.size()));
105 102
106 EXPECT_EQ(parser->text_tracks().size(), 0u); 103 EXPECT_EQ(parser->text_tracks().size(), 0u);
107 104
108 const std::set<int64>& ignored_tracks = parser->ignored_tracks(); 105 const std::set<int64>& ignored_tracks = parser->ignored_tracks();
109 EXPECT_TRUE(ignored_tracks.find(1) != ignored_tracks.end()); 106 EXPECT_TRUE(ignored_tracks.find(1) != ignored_tracks.end());
110 EXPECT_TRUE(ignored_tracks.find(2) != ignored_tracks.end()); 107 EXPECT_TRUE(ignored_tracks.find(2) != ignored_tracks.end());
111 108
112 // Test again w/o ignoring the test tracks. 109 // Test again w/o ignoring the test tracks.
113 parser.reset(new WebMTracksParser(LogCB(), false)); 110 parser.reset(new WebMTracksParser(LogCB(), false));
114 111
115 result = parser->Parse(&buf[0], buf.size()); 112 result = parser->Parse(&buf[0], buf.size());
116 EXPECT_GT(result, 0); 113 EXPECT_GT(result, 0);
117 114
118 EXPECT_EQ(parser->ignored_tracks().size(), 0u); 115 EXPECT_EQ(parser->ignored_tracks().size(), 0u);
119 EXPECT_EQ(parser->text_tracks().size(), 2u); 116 EXPECT_EQ(parser->text_tracks().size(), 2u);
120 } 117 }
121 118
119 TEST_F(WebMTracksParserTest, AudioVideoDefaultDurationUnset) {
120 // Other audio/video decoder config fields are necessary in the test
121 // audio/video TrackEntry configurations. This method does only very minimal
122 // verification of their inclusion and parsing; the goal is to confirm
123 // TrackEntry DefaultDuration defaults to -1 if not included in audio or
124 // video TrackEntry.
125 TracksBuilder tb;
126 tb.AddAudioTrack(1, 1, "A_VORBIS", "audio", "", -1, 2, 8000);
127 tb.AddVideoTrack(2, 2, "V_VP8", "video", "", -1, 320, 240);
128 const std::vector<uint8> buf = tb.Finish();
129
130 scoped_ptr<WebMTracksParser> parser(new WebMTracksParser(LogCB(), true));
131 int result = parser->Parse(&buf[0], buf.size());
132 EXPECT_LE(0, result);
133 EXPECT_EQ(static_cast<int>(buf.size()), result);
134
135 EXPECT_EQ(kNoTimestamp(),
136 parser->GetAudioDefaultDuration(kDefaultTimecodeScaleInUs));
137 EXPECT_EQ(kNoTimestamp(),
138 parser->GetVideoDefaultDuration(kDefaultTimecodeScaleInUs));
139
140 const VideoDecoderConfig& video_config = parser->video_decoder_config();
141 EXPECT_TRUE(video_config.IsValidConfig());
142 EXPECT_EQ(320, video_config.coded_size().width());
143 EXPECT_EQ(240, video_config.coded_size().height());
144
145 const AudioDecoderConfig& audio_config = parser->audio_decoder_config();
146 EXPECT_TRUE(audio_config.IsValidConfig());
147 EXPECT_EQ(CHANNEL_LAYOUT_STEREO, audio_config.channel_layout());
148 EXPECT_EQ(8000, audio_config.samples_per_second());
149 }
150
151 TEST_F(WebMTracksParserTest, AudioVideoDefaultDurationSet) {
152 // Confirm audio or video TrackEntry DefaultDuration values are parsed, if
153 // present.
154 TracksBuilder tb;
155 tb.AddAudioTrack(1, 1, "A_VORBIS", "audio", "", 12345678, 2, 8000);
156 tb.AddVideoTrack(2, 2, "V_VP8", "video", "", 987654321, 320, 240);
157 const std::vector<uint8> buf = tb.Finish();
158
159 scoped_ptr<WebMTracksParser> parser(new WebMTracksParser(LogCB(), true));
160 int result = parser->Parse(&buf[0], buf.size());
161 EXPECT_LE(0, result);
162 EXPECT_EQ(static_cast<int>(buf.size()), result);
163
164 EXPECT_EQ(base::TimeDelta::FromMicroseconds(12000),
165 parser->GetAudioDefaultDuration(kDefaultTimecodeScaleInUs));
166 EXPECT_EQ(base::TimeDelta::FromMicroseconds(985000),
167 parser->GetVideoDefaultDuration(5000.0)); // 5 ms resolution
168 EXPECT_EQ(kNoTimestamp(), parser->GetAudioDefaultDuration(12346.0));
169 EXPECT_EQ(base::TimeDelta::FromMicroseconds(12345),
170 parser->GetAudioDefaultDuration(12345.0));
171 EXPECT_EQ(base::TimeDelta::FromMicroseconds(12003),
172 parser->GetAudioDefaultDuration(1000.3)); // 1.0003 ms resolution
173 }
174
175 TEST_F(WebMTracksParserTest, InvalidZeroDefaultDurationSet) {
176 // Confirm parse error if TrackEntry DefaultDuration is present, but is 0ns.
177 TracksBuilder tb(true);
178 tb.AddAudioTrack(1, 1, "A_VORBIS", "audio", "", 0, 2, 8000);
179 const std::vector<uint8> buf = tb.Finish();
180
181 scoped_ptr<WebMTracksParser> parser(new WebMTracksParser(LogCB(), true));
182 EXPECT_EQ(-1, parser->Parse(&buf[0], buf.size()));
183 }
184
122 } // namespace media 185 } // namespace media
OLDNEW
« no previous file with comments | « media/formats/webm/webm_tracks_parser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698