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

Side by Side Diff: media/filters/chunk_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: Refactored decryption code. Add 2 unittests. 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
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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/message_loop.h" 6 #include "base/message_loop.h"
7 #include "media/base/audio_decoder_config.h" 7 #include "media/base/audio_decoder_config.h"
8 #include "media/base/decoder_buffer.h" 8 #include "media/base/decoder_buffer.h"
9 #include "media/base/mock_demuxer_host.h" 9 #include "media/base/mock_demuxer_host.h"
10 #include "media/base/test_data_util.h" 10 #include "media/base/test_data_util.h"
11 #include "media/base/test_helpers.h" 11 #include "media/base/test_helpers.h"
12 #include "media/filters/chunk_demuxer.h" 12 #include "media/filters/chunk_demuxer.h"
13 #include "media/webm/cluster_builder.h" 13 #include "media/webm/cluster_builder.h"
14 #include "media/webm/webm_constants.h" 14 #include "media/webm/webm_constants.h"
15 #include "media/webm/webm_crypto_helpers.h"
15 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
16 17
17 using ::testing::AnyNumber; 18 using ::testing::AnyNumber;
18 using ::testing::Exactly; 19 using ::testing::Exactly;
19 using ::testing::InSequence; 20 using ::testing::InSequence;
20 using ::testing::NotNull; 21 using ::testing::NotNull;
21 using ::testing::Return; 22 using ::testing::Return;
22 using ::testing::SaveArg; 23 using ::testing::SaveArg;
23 using ::testing::SetArgumentPointee; 24 using ::testing::SetArgumentPointee;
24 using ::testing::_; 25 using ::testing::_;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 static const int kAudioTrackNum = 2; 60 static const int kAudioTrackNum = 2;
60 61
61 static const int kAudioBlockDuration = 23; 62 static const int kAudioBlockDuration = 23;
62 static const int kVideoBlockDuration = 33; 63 static const int kVideoBlockDuration = 33;
63 64
64 static const char kSourceId[] = "SourceId"; 65 static const char kSourceId[] = "SourceId";
65 static const char kDefaultFirstClusterRange[] = "{ [0,46) }"; 66 static const char kDefaultFirstClusterRange[] = "{ [0,46) }";
66 static const int kDefaultFirstClusterEndTimestamp = 66; 67 static const int kDefaultFirstClusterEndTimestamp = 66;
67 static const int kDefaultSecondClusterEndTimestamp = 132; 68 static const int kDefaultSecondClusterEndTimestamp = 132;
68 69
69 static const char kWebMInitDataType[] = "video/webm";
70
71 base::TimeDelta kDefaultDuration() { 70 base::TimeDelta kDefaultDuration() {
72 return base::TimeDelta::FromMilliseconds(201224); 71 return base::TimeDelta::FromMilliseconds(201224);
73 } 72 }
74 73
75 // Write an integer into buffer in the form of vint that spans 8 bytes. 74 // Write an integer into buffer in the form of vint that spans 8 bytes.
76 // The data pointed by |buffer| should be at least 8 bytes long. 75 // The data pointed by |buffer| should be at least 8 bytes long.
77 // |number| should be in the range 0 <= number < 0x00FFFFFFFFFFFFFF. 76 // |number| should be in the range 0 <= number < 0x00FFFFFFFFFFFFFF.
78 static void WriteInt64(uint8* buffer, int64 number) { 77 static void WriteInt64(uint8* buffer, int64 number) {
79 DCHECK(number >= 0 && number < GG_LONGLONG(0x00FFFFFFFFFFFFFF)); 78 DCHECK(number >= 0 && number < GG_LONGLONG(0x00FFFFFFFFFFFFFF));
80 buffer[0] = 0x01; 79 buffer[0] = 0x01;
(...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 if ((!has_audio && is_audio_encrypted) || 783 if ((!has_audio && is_audio_encrypted) ||
785 (!has_video && is_video_encrypted)) { 784 (!has_video && is_video_encrypted)) {
786 continue; 785 continue;
787 } 786 }
788 787
789 CreateNewDemuxer(); 788 CreateNewDemuxer();
790 789
791 if (is_audio_encrypted || is_video_encrypted) { 790 if (is_audio_encrypted || is_video_encrypted) {
792 int need_key_count = (is_audio_encrypted ? 1 : 0) + 791 int need_key_count = (is_audio_encrypted ? 1 : 0) +
793 (is_video_encrypted ? 1 : 0); 792 (is_video_encrypted ? 1 : 0);
794 EXPECT_CALL(*this, NeedKeyMock(kWebMInitDataType, NotNull(), 16)) 793 EXPECT_CALL(*this, NeedKeyMock(kWebMEncryptInitDataType, NotNull(), 16))
795 .Times(Exactly(need_key_count)); 794 .Times(Exactly(need_key_count));
796 } 795 }
797 796
798 ASSERT_TRUE(InitDemuxerWithEncryptionInfo( 797 ASSERT_TRUE(InitDemuxerWithEncryptionInfo(
799 has_audio, has_video, is_audio_encrypted, is_video_encrypted)); 798 has_audio, has_video, is_audio_encrypted, is_video_encrypted));
800 799
801 scoped_refptr<DemuxerStream> audio_stream = 800 scoped_refptr<DemuxerStream> audio_stream =
802 demuxer_->GetStream(DemuxerStream::AUDIO); 801 demuxer_->GetStream(DemuxerStream::AUDIO);
803 if (has_audio) { 802 if (has_audio) {
804 ASSERT_TRUE(audio_stream); 803 ASSERT_TRUE(audio_stream);
(...skipping 1743 matching lines...) Expand 10 before | Expand all | Expand 10 after
2548 // call. This can happen if video element gets destroyed before 2547 // call. This can happen if video element gets destroyed before
2549 // the pipeline has a chance to initialize the demuxer. 2548 // the pipeline has a chance to initialize the demuxer.
2550 TEST_F(ChunkDemuxerTest, TestShutdownBeforeInitialize) { 2549 TEST_F(ChunkDemuxerTest, TestShutdownBeforeInitialize) {
2551 demuxer_->Shutdown(); 2550 demuxer_->Shutdown();
2552 demuxer_->Initialize( 2551 demuxer_->Initialize(
2553 &host_, CreateInitDoneCB(DEMUXER_ERROR_COULD_NOT_OPEN)); 2552 &host_, CreateInitDoneCB(DEMUXER_ERROR_COULD_NOT_OPEN));
2554 message_loop_.RunUntilIdle(); 2553 message_loop_.RunUntilIdle();
2555 } 2554 }
2556 2555
2557 } // namespace media 2556 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698