OLD | NEW |
---|---|
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 "media/filters/pipeline_integration_test_base.h" | 5 #include "media/filters/pipeline_integration_test_base.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "media/base/decoder_buffer.h" | 8 #include "media/base/decoder_buffer.h" |
9 #include "media/base/test_data_util.h" | 9 #include "media/base/test_data_util.h" |
10 #include "media/filters/chunk_demuxer_client.h" | 10 #include "media/filters/chunk_demuxer_client.h" |
11 | 11 |
12 namespace media { | 12 namespace media { |
13 | 13 |
14 // Key ID of the video track in test file "bear-320x240-encrypted.webm". | 14 // Key used to encrypt video track in test file "bear-320x240-encrypted.webm". |
15 static const unsigned char kKeyId[] = | 15 static const unsigned char kKey[] = |
16 "\x11\xa5\x18\x37\xc4\x73\x84\x03\xe5\xe6\x57\xed\x8e\x06\xd9\x7c"; | 16 "\x5b\x4e\xe8\xb6\xd0\x7e\x4e\x58\xea\x24\x4c\x40\x13\xfd\xb5\x2d"; |
xhwang
2012/06/14 19:42:27
ditto about using { 0x5b, 0x4e, ... } style. But I
fgalligan1
2012/07/03 22:00:15
Done.
| |
17 | 17 |
18 static const char* kSourceId = "SourceId"; | 18 static const char* kSourceId = "SourceId"; |
19 | 19 |
20 // Helper class that emulates calls made on the ChunkDemuxer by the | 20 // Helper class that emulates calls made on the ChunkDemuxer by the |
21 // Media Source API. | 21 // Media Source API. |
22 class MockMediaSource : public ChunkDemuxerClient { | 22 class MockMediaSource : public ChunkDemuxerClient { |
23 public: | 23 public: |
24 MockMediaSource(const std::string& filename, int initial_append_size) | 24 MockMediaSource(const std::string& filename, int initial_append_size) |
25 : url_(GetTestDataURL(filename)), | 25 : url_(GetTestDataURL(filename)), |
26 current_position_(0), | 26 current_position_(0), |
27 initial_append_size_(initial_append_size) { | 27 initial_append_size_(initial_append_size) { |
28 file_data_ = ReadTestDataFile(filename); | 28 file_data_ = ReadTestDataFile(filename); |
29 | 29 |
30 DCHECK_GT(initial_append_size_, 0); | 30 DCHECK_GT(initial_append_size_, 0); |
31 DCHECK_LE(initial_append_size_, file_data_->GetDataSize()); | 31 DCHECK_LE(initial_append_size_, file_data_->GetDataSize()); |
32 } | 32 } |
33 | 33 |
34 virtual ~MockMediaSource() {} | 34 virtual ~MockMediaSource() {} |
35 | 35 |
36 void set_decryptor(AesDecryptor* decryptor) { | 36 void set_decryptor(Decryptor* decryptor) { |
37 decryptor_ = decryptor; | 37 decryptor_ = decryptor; |
38 } | 38 } |
39 AesDecryptor* decryptor() const { | 39 Decryptor* decryptor() const { |
40 return decryptor_; | 40 return decryptor_; |
41 } | 41 } |
42 | 42 |
43 const std::string& url() const { return url_; } | 43 const std::string& url() const { return url_; } |
44 | 44 |
45 void Seek(int new_position, int seek_append_size) { | 45 void Seek(int new_position, int seek_append_size) { |
46 chunk_demuxer_->StartWaitingForSeek(); | 46 chunk_demuxer_->StartWaitingForSeek(); |
47 | 47 |
48 chunk_demuxer_->Abort(kSourceId); | 48 chunk_demuxer_->Abort(kSourceId); |
49 | 49 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
83 chunk_demuxer_->AddId(kSourceId, "video/webm", codecs); | 83 chunk_demuxer_->AddId(kSourceId, "video/webm", codecs); |
84 AppendData(initial_append_size_); | 84 AppendData(initial_append_size_); |
85 } | 85 } |
86 | 86 |
87 virtual void DemuxerClosed() { | 87 virtual void DemuxerClosed() { |
88 chunk_demuxer_ = NULL; | 88 chunk_demuxer_ = NULL; |
89 } | 89 } |
90 | 90 |
91 virtual void KeyNeeded(scoped_array<uint8> init_data, int init_data_size) { | 91 virtual void KeyNeeded(scoped_array<uint8> init_data, int init_data_size) { |
92 DCHECK(init_data.get()); | 92 DCHECK(init_data.get()); |
93 DCHECK_EQ(init_data_size, 16); | |
94 DCHECK(decryptor()); | 93 DCHECK(decryptor()); |
95 // In test file bear-320x240-encrypted.webm, the decryption key is equal to | |
96 // |init_data|. | |
97 decryptor()->AddKey(init_data.get(), init_data_size, | 94 decryptor()->AddKey(init_data.get(), init_data_size, |
98 init_data.get(), init_data_size); | 95 kKey, sizeof(kKey) - 1); |
99 } | 96 } |
100 | 97 |
101 private: | 98 private: |
102 std::string url_; | 99 std::string url_; |
103 scoped_refptr<DecoderBuffer> file_data_; | 100 scoped_refptr<DecoderBuffer> file_data_; |
104 int current_position_; | 101 int current_position_; |
105 int initial_append_size_; | 102 int initial_append_size_; |
106 scoped_refptr<ChunkDemuxer> chunk_demuxer_; | 103 scoped_refptr<ChunkDemuxer> chunk_demuxer_; |
107 AesDecryptor* decryptor_; | 104 Decryptor* decryptor_; |
108 }; | 105 }; |
109 | 106 |
110 class PipelineIntegrationTest | 107 class PipelineIntegrationTest |
111 : public testing::Test, | 108 : public testing::Test, |
112 public PipelineIntegrationTestBase { | 109 public PipelineIntegrationTestBase { |
113 public: | 110 public: |
114 void StartPipelineWithMediaSource(MockMediaSource& source) { | 111 void StartPipelineWithMediaSource(MockMediaSource& source) { |
115 pipeline_->Start( | 112 pipeline_->Start( |
116 CreateFilterCollection(&source), | 113 CreateFilterCollection(&source), |
117 base::Bind(&PipelineIntegrationTest::OnEnded, base::Unretained(this)), | 114 base::Bind(&PipelineIntegrationTest::OnEnded, base::Unretained(this)), |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
243 | 240 |
244 // Verify video decoder & renderer can handle aborted demuxer reads. | 241 // Verify video decoder & renderer can handle aborted demuxer reads. |
245 TEST_F(PipelineIntegrationTest, ChunkDemuxerAbortRead_VideoOnly) { | 242 TEST_F(PipelineIntegrationTest, ChunkDemuxerAbortRead_VideoOnly) { |
246 ASSERT_TRUE(TestSeekDuringRead("bear-320x240-video-only.webm", 32768, | 243 ASSERT_TRUE(TestSeekDuringRead("bear-320x240-video-only.webm", 32768, |
247 base::TimeDelta::FromMilliseconds(200), | 244 base::TimeDelta::FromMilliseconds(200), |
248 base::TimeDelta::FromMilliseconds(1668), | 245 base::TimeDelta::FromMilliseconds(1668), |
249 0x1C896, 65536)); | 246 0x1C896, 65536)); |
250 } | 247 } |
251 | 248 |
252 } // namespace media | 249 } // namespace media |
OLD | NEW |