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