OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/bind.h" |
| 6 #include "media/base/decoder_buffer.h" |
| 7 #include "media/base/media_tracks.h" |
| 8 #include "media/base/mock_media_log.h" |
| 9 #include "media/base/test_data_util.h" |
| 10 #include "media/base/text_track_config.h" |
| 11 #include "media/formats/webm/webm_stream_parser.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 |
| 14 using testing::_; |
| 15 |
| 16 namespace media { |
| 17 |
| 18 class WebMStreamParserTest : public testing::Test { |
| 19 public: |
| 20 WebMStreamParserTest() |
| 21 : media_log_(new testing::StrictMock<MockMediaLog>()) {} |
| 22 |
| 23 protected: |
| 24 void ParseWebMFile(const std::string& filename) { |
| 25 scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile(filename); |
| 26 parser_.reset(new WebMStreamParser()); |
| 27 Demuxer::EncryptedMediaInitDataCB encrypted_media_init_data_cb = |
| 28 base::Bind(&WebMStreamParserTest::OnEncryptedMediaInitData, |
| 29 base::Unretained(this)); |
| 30 |
| 31 EXPECT_CALL(*this, InitCB(_)); |
| 32 EXPECT_CALL(*this, NewMediaSegmentCB()).Times(testing::AnyNumber()); |
| 33 EXPECT_CALL(*this, EndMediaSegmentCB()).Times(testing::AnyNumber()); |
| 34 EXPECT_CALL(*this, NewBuffersCB(_, _, _)) |
| 35 .Times(testing::AnyNumber()) |
| 36 .WillRepeatedly(testing::Return(true)); |
| 37 parser_->Init( |
| 38 base::Bind(&WebMStreamParserTest::InitCB, base::Unretained(this)), |
| 39 base::Bind(&WebMStreamParserTest::NewConfigCB, base::Unretained(this)), |
| 40 base::Bind(&WebMStreamParserTest::NewBuffersCB, base::Unretained(this)), |
| 41 true, // ignore_text_track |
| 42 encrypted_media_init_data_cb, |
| 43 base::Bind(&WebMStreamParserTest::NewMediaSegmentCB, |
| 44 base::Unretained(this)), |
| 45 base::Bind(&WebMStreamParserTest::EndMediaSegmentCB, |
| 46 base::Unretained(this)), |
| 47 media_log_); |
| 48 bool result = parser_->Parse(buffer->data(), buffer->data_size()); |
| 49 EXPECT_TRUE(result); |
| 50 } |
| 51 |
| 52 MOCK_METHOD1(InitCB, void(const StreamParser::InitParameters& params)); |
| 53 |
| 54 bool NewConfigCB(scoped_ptr<MediaTracks> tracks, |
| 55 const StreamParser::TextTrackConfigMap& text_track_map) { |
| 56 DCHECK(tracks.get()); |
| 57 media_tracks_ = std::move(tracks); |
| 58 return true; |
| 59 } |
| 60 |
| 61 MOCK_METHOD3(NewBuffersCB, |
| 62 bool(const StreamParser::BufferQueue&, |
| 63 const StreamParser::BufferQueue&, |
| 64 const StreamParser::TextBufferQueueMap&)); |
| 65 MOCK_METHOD2(OnEncryptedMediaInitData, |
| 66 void(EmeInitDataType init_data_type, |
| 67 const std::vector<uint8_t>& init_data)); |
| 68 MOCK_METHOD0(NewMediaSegmentCB, void()); |
| 69 MOCK_METHOD0(EndMediaSegmentCB, void()); |
| 70 |
| 71 scoped_refptr<testing::StrictMock<MockMediaLog>> media_log_; |
| 72 scoped_ptr<WebMStreamParser> parser_; |
| 73 scoped_ptr<MediaTracks> media_tracks_; |
| 74 }; |
| 75 |
| 76 TEST_F(WebMStreamParserTest, VerifyMediaTrackMetadata) { |
| 77 EXPECT_MEDIA_LOG(testing::HasSubstr("Estimating WebM block duration")) |
| 78 .Times(testing::AnyNumber()); |
| 79 ParseWebMFile("bear.webm"); |
| 80 EXPECT_NE(media_tracks_.get(), nullptr); |
| 81 |
| 82 EXPECT_EQ(media_tracks_->tracks().size(), 2u); |
| 83 |
| 84 const MediaTrack& video_track = *(media_tracks_->tracks()[0]); |
| 85 EXPECT_EQ(video_track.type(), MediaTrack::Video); |
| 86 EXPECT_EQ(video_track.id(), "1"); |
| 87 EXPECT_EQ(video_track.kind(), "main"); |
| 88 EXPECT_EQ(video_track.label(), ""); |
| 89 EXPECT_EQ(video_track.language(), "und"); |
| 90 |
| 91 const MediaTrack& audio_track = *(media_tracks_->tracks()[1]); |
| 92 EXPECT_EQ(audio_track.type(), MediaTrack::Audio); |
| 93 EXPECT_EQ(audio_track.id(), "2"); |
| 94 EXPECT_EQ(audio_track.kind(), "main"); |
| 95 EXPECT_EQ(audio_track.label(), ""); |
| 96 EXPECT_EQ(audio_track.language(), "und"); |
| 97 } |
| 98 |
| 99 } // namespace media |
OLD | NEW |