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