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

Side by Side Diff: media/filters/ffmpeg_demuxer_unittest.cc

Issue 10829470: Support for parsing encrypted WebM streams by src. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix tool player_x11 Created 7 years, 9 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/filters/ffmpeg_demuxer.cc ('k') | media/filters/pipeline_integration_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <algorithm> 5 #include <algorithm>
6 #include <deque> 6 #include <deque>
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/path_service.h" 12 #include "base/path_service.h"
13 #include "base/threading/thread.h" 13 #include "base/threading/thread.h"
14 #include "media/base/decrypt_config.h"
14 #include "media/base/mock_demuxer_host.h" 15 #include "media/base/mock_demuxer_host.h"
15 #include "media/base/test_helpers.h" 16 #include "media/base/test_helpers.h"
16 #include "media/ffmpeg/ffmpeg_common.h" 17 #include "media/ffmpeg/ffmpeg_common.h"
17 #include "media/filters/ffmpeg_demuxer.h" 18 #include "media/filters/ffmpeg_demuxer.h"
18 #include "media/filters/file_data_source.h" 19 #include "media/filters/file_data_source.h"
20 #include "media/webm/webm_crypto_helpers.h"
19 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
20 22
21 using ::testing::AnyNumber; 23 using ::testing::AnyNumber;
22 using ::testing::DoAll; 24 using ::testing::DoAll;
25 using ::testing::Exactly;
23 using ::testing::InSequence; 26 using ::testing::InSequence;
24 using ::testing::Invoke; 27 using ::testing::Invoke;
28 using ::testing::NotNull;
25 using ::testing::Return; 29 using ::testing::Return;
26 using ::testing::SaveArg; 30 using ::testing::SaveArg;
27 using ::testing::SetArgPointee; 31 using ::testing::SetArgPointee;
28 using ::testing::StrictMock; 32 using ::testing::StrictMock;
29 using ::testing::WithArgs; 33 using ::testing::WithArgs;
30 using ::testing::_; 34 using ::testing::_;
31 35
32 namespace media { 36 namespace media {
33 37
34 MATCHER(IsEndOfStreamBuffer, 38 MATCHER(IsEndOfStreamBuffer,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 } 74 }
71 75
72 void CreateDemuxer(const std::string& name) { 76 void CreateDemuxer(const std::string& name) {
73 CHECK(!demuxer_); 77 CHECK(!demuxer_);
74 78
75 EXPECT_CALL(host_, SetTotalBytes(_)).Times(AnyNumber()); 79 EXPECT_CALL(host_, SetTotalBytes(_)).Times(AnyNumber());
76 EXPECT_CALL(host_, AddBufferedByteRange(_, _)).Times(AnyNumber()); 80 EXPECT_CALL(host_, AddBufferedByteRange(_, _)).Times(AnyNumber());
77 EXPECT_CALL(host_, AddBufferedTimeRange(_, _)).Times(AnyNumber()); 81 EXPECT_CALL(host_, AddBufferedTimeRange(_, _)).Times(AnyNumber());
78 82
79 CreateDataSource(name); 83 CreateDataSource(name);
84
85 media::FFmpegNeedKeyCB need_key_cb =
86 base::Bind(&FFmpegDemuxerTest::NeedKeyCB, base::Unretained(this));
80 demuxer_ = new FFmpegDemuxer(message_loop_.message_loop_proxy(), 87 demuxer_ = new FFmpegDemuxer(message_loop_.message_loop_proxy(),
81 data_source_); 88 data_source_,
89 need_key_cb);
82 } 90 }
83 91
84 MOCK_METHOD1(CheckPoint, void(int v)); 92 MOCK_METHOD1(CheckPoint, void(int v));
85 93
86 void InitializeDemuxer() { 94 void InitializeDemuxer() {
87 EXPECT_CALL(host_, SetDuration(_)); 95 EXPECT_CALL(host_, SetDuration(_));
88 WaitableMessageLoopEvent event; 96 WaitableMessageLoopEvent event;
89 demuxer_->Initialize(&host_, event.GetPipelineStatusCB()); 97 demuxer_->Initialize(&host_, event.GetPipelineStatusCB());
90 event.RunAndWaitForStatus(PIPELINE_OK); 98 event.RunAndWaitForStatus(PIPELINE_OK);
91 } 99 }
(...skipping 22 matching lines...) Expand all
114 message_loop_.PostTask(FROM_HERE, MessageLoop::QuitWhenIdleClosure()); 122 message_loop_.PostTask(FROM_HERE, MessageLoop::QuitWhenIdleClosure());
115 } 123 }
116 124
117 DemuxerStream::ReadCB NewReadCB(const tracked_objects::Location& location, 125 DemuxerStream::ReadCB NewReadCB(const tracked_objects::Location& location,
118 int size, int64 timestampInMicroseconds) { 126 int size, int64 timestampInMicroseconds) {
119 EXPECT_CALL(*this, OnReadDoneCalled(size, timestampInMicroseconds)); 127 EXPECT_CALL(*this, OnReadDoneCalled(size, timestampInMicroseconds));
120 return base::Bind(&FFmpegDemuxerTest::OnReadDone, base::Unretained(this), 128 return base::Bind(&FFmpegDemuxerTest::OnReadDone, base::Unretained(this),
121 location, size, timestampInMicroseconds); 129 location, size, timestampInMicroseconds);
122 } 130 }
123 131
132 // TODO(xhwang): This is a workaround of the issue that move-only parameters
133 // are not supported in mocked methods. Remove this when the issue is fixed
134 // (http://code.google.com/p/googletest/issues/detail?id=395) or when we use
135 // std::string instead of scoped_array<uint8> (http://crbug.com/130689).
136 MOCK_METHOD3(NeedKeyCBMock, void(const std::string& type,
137 const uint8* init_data, int init_data_size));
138 void NeedKeyCB(const std::string& type,
139 scoped_array<uint8> init_data, int init_data_size) {
140 NeedKeyCBMock(type, init_data.get(), init_data_size);
141 }
142
124 // Accessor to demuxer internals. 143 // Accessor to demuxer internals.
125 void set_duration_known(bool duration_known) { 144 void set_duration_known(bool duration_known) {
126 demuxer_->duration_known_ = duration_known; 145 demuxer_->duration_known_ = duration_known;
127 } 146 }
128 147
129 bool IsStreamStopped(DemuxerStream::Type type) { 148 bool IsStreamStopped(DemuxerStream::Type type) {
130 DemuxerStream* stream = demuxer_->GetStream(type); 149 DemuxerStream* stream = demuxer_->GetStream(type);
131 CHECK(stream); 150 CHECK(stream);
132 return static_cast<FFmpegDemuxerStream*>(stream)->stopped_; 151 return static_cast<FFmpegDemuxerStream*>(stream)->stopped_;
133 } 152 }
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 // Audio stream should be Vorbis. 293 // Audio stream should be Vorbis.
275 stream = demuxer_->GetStream(DemuxerStream::AUDIO); 294 stream = demuxer_->GetStream(DemuxerStream::AUDIO);
276 ASSERT_TRUE(stream); 295 ASSERT_TRUE(stream);
277 EXPECT_EQ(DemuxerStream::AUDIO, stream->type()); 296 EXPECT_EQ(DemuxerStream::AUDIO, stream->type());
278 EXPECT_EQ(kCodecVorbis, stream->audio_decoder_config().codec()); 297 EXPECT_EQ(kCodecVorbis, stream->audio_decoder_config().codec());
279 298
280 // Unknown stream should never be present. 299 // Unknown stream should never be present.
281 EXPECT_FALSE(demuxer_->GetStream(DemuxerStream::UNKNOWN)); 300 EXPECT_FALSE(demuxer_->GetStream(DemuxerStream::UNKNOWN));
282 } 301 }
283 302
303 // TODO(fgalligan): Enable test when code to parse encrypted WebM files lands
304 // in Chromium's FFmpeg. crbug.com/189221
305 TEST_F(FFmpegDemuxerTest, DISABLED_Initialize_Encrypted) {
306 EXPECT_CALL(*this, NeedKeyCBMock(kWebMEncryptInitDataType, NotNull(),
307 DecryptConfig::kDecryptionKeySize))
308 .Times(Exactly(2));
309
310 CreateDemuxer("bear-320x240-av_enc-av.webm");
311 InitializeDemuxer();
312 }
313
284 TEST_F(FFmpegDemuxerTest, Read_Audio) { 314 TEST_F(FFmpegDemuxerTest, Read_Audio) {
285 // We test that on a successful audio packet read. 315 // We test that on a successful audio packet read.
286 CreateDemuxer("bear-320x240.webm"); 316 CreateDemuxer("bear-320x240.webm");
287 InitializeDemuxer(); 317 InitializeDemuxer();
288 318
289 // Attempt a read from the audio stream and run the message loop until done. 319 // Attempt a read from the audio stream and run the message loop until done.
290 scoped_refptr<DemuxerStream> audio = 320 scoped_refptr<DemuxerStream> audio =
291 demuxer_->GetStream(DemuxerStream::AUDIO); 321 demuxer_->GetStream(DemuxerStream::AUDIO);
292 322
293 audio->Read(NewReadCB(FROM_HERE, 29, 0)); 323 audio->Read(NewReadCB(FROM_HERE, 29, 0));
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 TEST_F(FFmpegDemuxerTest, MP4_ZeroStszEntry) { 651 TEST_F(FFmpegDemuxerTest, MP4_ZeroStszEntry) {
622 #if !defined(USE_PROPRIETARY_CODECS) 652 #if !defined(USE_PROPRIETARY_CODECS)
623 return; 653 return;
624 #endif 654 #endif
625 CreateDemuxer("bear-1280x720-zero-stsz-entry.mp4"); 655 CreateDemuxer("bear-1280x720-zero-stsz-entry.mp4");
626 InitializeDemuxer(); 656 InitializeDemuxer();
627 ReadUntilEndOfStream(); 657 ReadUntilEndOfStream();
628 } 658 }
629 659
630 } // namespace media 660 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/ffmpeg_demuxer.cc ('k') | media/filters/pipeline_integration_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698