OLD | NEW |
---|---|
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 |
(...skipping 25 matching lines...) Expand all Loading... | |
41 EXPECT_EQ(config.kind(), text_kind); | 42 EXPECT_EQ(config.kind(), text_kind); |
42 EXPECT_TRUE(config.label() == name); | 43 EXPECT_TRUE(config.label() == name); |
43 EXPECT_TRUE(config.language() == language); | 44 EXPECT_TRUE(config.language() == language); |
44 } | 45 } |
45 | 46 |
46 TEST_F(WebMTracksParserTest, SubtitleNoNameNoLang) { | 47 TEST_F(WebMTracksParserTest, SubtitleNoNameNoLang) { |
47 InSequence s; | 48 InSequence s; |
48 | 49 |
49 TracksBuilder tb; | 50 TracksBuilder tb; |
50 tb.AddTrack(1, kWebMTrackTypeSubtitlesOrCaptions, 1, | 51 tb.AddTrack(1, kWebMTrackTypeSubtitlesOrCaptions, 1, |
51 kWebMCodecSubtitles, "", ""); | 52 kWebMCodecSubtitles, "", "", -1, -1, -1, -1, -1); |
52 | 53 |
53 const std::vector<uint8> buf = tb.Finish(); | 54 const std::vector<uint8> buf = tb.Finish(); |
54 VerifyTextTrackInfo(&buf[0], buf.size(), kTextSubtitles, "", ""); | 55 VerifyTextTrackInfo(&buf[0], buf.size(), kTextSubtitles, "", ""); |
55 } | 56 } |
56 | 57 |
57 TEST_F(WebMTracksParserTest, SubtitleYesNameNoLang) { | 58 TEST_F(WebMTracksParserTest, SubtitleYesNameNoLang) { |
58 InSequence s; | 59 InSequence s; |
59 | 60 |
60 TracksBuilder tb; | 61 TracksBuilder tb; |
61 tb.AddTrack(1, kWebMTrackTypeSubtitlesOrCaptions, 1, | 62 tb.AddTrack(1, kWebMTrackTypeSubtitlesOrCaptions, 1, |
62 kWebMCodecSubtitles, "Spock", ""); | 63 kWebMCodecSubtitles, "Spock", "", -1, -1, -1, -1, -1); |
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.AddTrack(1, kWebMTrackTypeSubtitlesOrCaptions, 1, |
73 kWebMCodecSubtitles, "", "eng"); | 74 kWebMCodecSubtitles, "", "eng", -1, -1, -1, -1, -1); |
74 | 75 |
75 const std::vector<uint8> buf = tb.Finish(); | 76 const std::vector<uint8> buf = tb.Finish(); |
76 VerifyTextTrackInfo(&buf[0], buf.size(), kTextSubtitles, "", "eng"); | 77 VerifyTextTrackInfo(&buf[0], buf.size(), kTextSubtitles, "", "eng"); |
77 } | 78 } |
78 | 79 |
79 TEST_F(WebMTracksParserTest, SubtitleYesNameYesLang) { | 80 TEST_F(WebMTracksParserTest, SubtitleYesNameYesLang) { |
80 InSequence s; | 81 InSequence s; |
81 | 82 |
82 TracksBuilder tb; | 83 TracksBuilder tb; |
83 tb.AddTrack(1, kWebMTrackTypeSubtitlesOrCaptions, 1, | 84 tb.AddTrack(1, kWebMTrackTypeSubtitlesOrCaptions, 1, |
84 kWebMCodecSubtitles, "Picard", "fre"); | 85 kWebMCodecSubtitles, "Picard", "fre", -1, -1, -1, -1, -1); |
85 | 86 |
86 const std::vector<uint8> buf = tb.Finish(); | 87 const std::vector<uint8> buf = tb.Finish(); |
87 VerifyTextTrackInfo(&buf[0], buf.size(), kTextSubtitles, "Picard", "fre"); | 88 VerifyTextTrackInfo(&buf[0], buf.size(), kTextSubtitles, "Picard", "fre"); |
88 } | 89 } |
89 | 90 |
90 TEST_F(WebMTracksParserTest, IgnoringTextTracks) { | 91 TEST_F(WebMTracksParserTest, IgnoringTextTracks) { |
91 InSequence s; | 92 InSequence s; |
92 | 93 |
93 TracksBuilder tb; | 94 TracksBuilder tb; |
94 tb.AddTrack(1, kWebMTrackTypeSubtitlesOrCaptions, 1, | 95 tb.AddTrack(1, kWebMTrackTypeSubtitlesOrCaptions, 1, |
95 kWebMCodecSubtitles, "Subtitles", "fre"); | 96 kWebMCodecSubtitles, "Subtitles", "fre", -1, -1, -1, -1, -1); |
96 tb.AddTrack(2, kWebMTrackTypeSubtitlesOrCaptions, 2, | 97 tb.AddTrack(2, kWebMTrackTypeSubtitlesOrCaptions, 2, |
97 kWebMCodecSubtitles, "Commentary", "fre"); | 98 kWebMCodecSubtitles, "Commentary", "fre", -1, -1, -1, -1, -1); |
98 | 99 |
99 const std::vector<uint8> buf = tb.Finish(); | 100 const std::vector<uint8> buf = tb.Finish(); |
100 scoped_ptr<WebMTracksParser> parser(new WebMTracksParser(LogCB(), true)); | 101 scoped_ptr<WebMTracksParser> parser(new WebMTracksParser(LogCB(), true)); |
101 | 102 |
102 int result = parser->Parse(&buf[0], buf.size()); | 103 int result = parser->Parse(&buf[0], buf.size()); |
103 EXPECT_GT(result, 0); | 104 EXPECT_GT(result, 0); |
104 EXPECT_EQ(result, static_cast<int>(buf.size())); | 105 EXPECT_EQ(result, static_cast<int>(buf.size())); |
105 | 106 |
106 EXPECT_EQ(parser->text_tracks().size(), 0u); | 107 EXPECT_EQ(parser->text_tracks().size(), 0u); |
107 | 108 |
108 const std::set<int64>& ignored_tracks = parser->ignored_tracks(); | 109 const std::set<int64>& ignored_tracks = parser->ignored_tracks(); |
109 EXPECT_TRUE(ignored_tracks.find(1) != ignored_tracks.end()); | 110 EXPECT_TRUE(ignored_tracks.find(1) != ignored_tracks.end()); |
110 EXPECT_TRUE(ignored_tracks.find(2) != ignored_tracks.end()); | 111 EXPECT_TRUE(ignored_tracks.find(2) != ignored_tracks.end()); |
111 | 112 |
112 // Test again w/o ignoring the test tracks. | 113 // Test again w/o ignoring the test tracks. |
113 parser.reset(new WebMTracksParser(LogCB(), false)); | 114 parser.reset(new WebMTracksParser(LogCB(), false)); |
114 | 115 |
115 result = parser->Parse(&buf[0], buf.size()); | 116 result = parser->Parse(&buf[0], buf.size()); |
116 EXPECT_GT(result, 0); | 117 EXPECT_GT(result, 0); |
117 | 118 |
118 EXPECT_EQ(parser->ignored_tracks().size(), 0u); | 119 EXPECT_EQ(parser->ignored_tracks().size(), 0u); |
119 EXPECT_EQ(parser->text_tracks().size(), 2u); | 120 EXPECT_EQ(parser->text_tracks().size(), 2u); |
120 } | 121 } |
121 | 122 |
123 TEST_F(WebMTracksParserTest, AudioVideoDefaultDurationUnset) { | |
124 // Other audio/video decoder config fields are necessary in the test | |
125 // audio/video TrackEntry configurations. This method does only very minimal | |
126 // verification of their inclusion and parsing; the goal is to confirm | |
127 // TrackEntry DefaultDuration defaults to -1 if not included in audio or | |
128 // video TrackEntry. | |
129 TracksBuilder tb; | |
130 tb.AddTrack(1, kWebMTrackTypeAudio, 1, "A_VORBIS", "audio", "", -1, -1, -1, | |
acolwell GONE FROM CHROMIUM
2014/03/26 22:25:32
nit: Should we have AddVideoTrack(), AddAudioTrack
wolenetz
2014/03/27 01:21:43
Done.
| |
131 2, 8000); | |
132 tb.AddTrack(2, kWebMTrackTypeVideo, 2, "V_VP8", "video", "", -1, 320, 240, | |
133 -1, -1); | |
134 const std::vector<uint8> buf = tb.Finish(); | |
135 | |
136 scoped_ptr<WebMTracksParser> parser(new WebMTracksParser(LogCB(), true)); | |
137 int result = parser->Parse(&buf[0], buf.size()); | |
138 EXPECT_LE(0, result); | |
139 EXPECT_EQ(static_cast<int>(buf.size()), result); | |
140 | |
141 EXPECT_EQ(kNoTimestamp(), parser->GetAudioDefaultDuration(1000.0)); | |
acolwell GONE FROM CHROMIUM
2014/03/26 22:25:32
nit: make this a constant so it's a little clearer
wolenetz
2014/03/27 01:21:43
Done.
| |
142 EXPECT_EQ(kNoTimestamp(), parser->GetVideoDefaultDuration(1000.0)); | |
143 | |
144 const VideoDecoderConfig& video_config = parser->video_decoder_config(); | |
145 EXPECT_TRUE(video_config.IsValidConfig()); | |
146 EXPECT_EQ(320, video_config.coded_size().width()); | |
147 EXPECT_EQ(240, video_config.coded_size().height()); | |
148 | |
149 const AudioDecoderConfig& audio_config = parser->audio_decoder_config(); | |
150 EXPECT_TRUE(audio_config.IsValidConfig()); | |
151 EXPECT_EQ(CHANNEL_LAYOUT_STEREO, audio_config.channel_layout()); | |
152 EXPECT_EQ(8000, audio_config.samples_per_second()); | |
153 } | |
154 | |
155 TEST_F(WebMTracksParserTest, AudioVideoDefaultDurationSet) { | |
156 // Confirm audio or video TrackEntry DefaultDuration values are parsed, if | |
157 // present. | |
158 TracksBuilder tb; | |
159 tb.AddTrack(1, kWebMTrackTypeAudio, 1, "A_VORBIS", "audio", "", 12345678, | |
160 -1, -1, 2, 8000); | |
161 tb.AddTrack(2, kWebMTrackTypeVideo, 2, "V_VP8", "video", "", 987654321, | |
162 320, 240, -1, -1); | |
163 const std::vector<uint8> buf = tb.Finish(); | |
164 | |
165 scoped_ptr<WebMTracksParser> parser(new WebMTracksParser(LogCB(), true)); | |
166 int result = parser->Parse(&buf[0], buf.size()); | |
167 EXPECT_LE(0, result); | |
168 EXPECT_EQ(static_cast<int>(buf.size()), result); | |
169 | |
170 EXPECT_EQ(base::TimeDelta::FromMicroseconds(12000), | |
171 parser->GetAudioDefaultDuration(1000.0)); // 1 ms resolution | |
172 EXPECT_EQ(base::TimeDelta::FromMicroseconds(985000), | |
173 parser->GetVideoDefaultDuration(5000.0)); // 5 ms resolution | |
174 EXPECT_EQ(kNoTimestamp(), parser->GetAudioDefaultDuration(12346.0)); | |
175 EXPECT_EQ(base::TimeDelta::FromMicroseconds(12345), | |
176 parser->GetAudioDefaultDuration(12345.0)); | |
177 } | |
178 | |
122 } // namespace media | 179 } // namespace media |
OLD | NEW |