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

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

Issue 784493002: Encrypted Media: Rename NeedKey to EncryptedMediaInitData. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years 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
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 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/string_split.h" 10 #include "base/strings/string_split.h"
(...skipping 27 matching lines...) Expand all
38 }; 38 };
39 39
40 // WebM Block bytes that represent a VP8 key frame. 40 // WebM Block bytes that represent a VP8 key frame.
41 const uint8 kVP8Keyframe[] = { 41 const uint8 kVP8Keyframe[] = {
42 0x010, 0x00, 0x00, 0x9d, 0x01, 0x2a, 0x00, 0x10, 0x00, 0x10, 0x00 42 0x010, 0x00, 0x00, 0x9d, 0x01, 0x2a, 0x00, 0x10, 0x00, 0x10, 0x00
43 }; 43 };
44 44
45 // WebM Block bytes that represent a VP8 interframe. 45 // WebM Block bytes that represent a VP8 interframe.
46 const uint8 kVP8Interframe[] = { 0x11, 0x00, 0x00 }; 46 const uint8 kVP8Interframe[] = { 0x11, 0x00, 0x00 };
47 47
48 static const uint8 kCuesHeader[] = { 48 const uint8 kCuesHeader[] = {
49 0x1C, 0x53, 0xBB, 0x6B, // Cues ID 49 0x1C, 0x53, 0xBB, 0x6B, // Cues ID
50 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // cues(size = 0) 50 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // cues(size = 0)
51 }; 51 };
52 52
53 const uint8 kEncryptedMediaInitData[] = {
54 0x68, 0xFE, 0xF9, 0xA1, 0xB3, 0x0D, 0x6B, 0x4D,
55 0xF2, 0x22, 0xB5, 0x0B, 0x4D, 0xE9, 0xE9, 0x95,
56 };
57
53 const int kTracksHeaderSize = sizeof(kTracksHeader); 58 const int kTracksHeaderSize = sizeof(kTracksHeader);
54 const int kTracksSizeOffset = 4; 59 const int kTracksSizeOffset = 4;
55 60
56 // The size of TrackEntry element in test file "webm_vorbis_track_entry" starts 61 // The size of TrackEntry element in test file "webm_vorbis_track_entry" starts
57 // at index 1 and spans 8 bytes. 62 // at index 1 and spans 8 bytes.
58 const int kAudioTrackSizeOffset = 1; 63 const int kAudioTrackSizeOffset = 1;
59 const int kAudioTrackSizeWidth = 8; 64 const int kAudioTrackSizeWidth = 8;
60 const int kAudioTrackEntryHeaderSize = 65 const int kAudioTrackEntryHeaderSize =
61 kAudioTrackSizeOffset + kAudioTrackSizeWidth; 66 kAudioTrackSizeOffset + kAudioTrackSizeWidth;
62 67
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 : append_window_end_for_next_append_(kInfiniteDuration()) { 169 : append_window_end_for_next_append_(kInfiniteDuration()) {
165 init_segment_received_cb_ = 170 init_segment_received_cb_ =
166 base::Bind(&ChunkDemuxerTest::InitSegmentReceived, 171 base::Bind(&ChunkDemuxerTest::InitSegmentReceived,
167 base::Unretained(this)); 172 base::Unretained(this));
168 CreateNewDemuxer(); 173 CreateNewDemuxer();
169 } 174 }
170 175
171 void CreateNewDemuxer() { 176 void CreateNewDemuxer() {
172 base::Closure open_cb = 177 base::Closure open_cb =
173 base::Bind(&ChunkDemuxerTest::DemuxerOpened, base::Unretained(this)); 178 base::Bind(&ChunkDemuxerTest::DemuxerOpened, base::Unretained(this));
174 Demuxer::NeedKeyCB need_key_cb = 179 Demuxer::EncryptedMediaInitDataCB encrypted_media_init_data_cb = base::Bind(
175 base::Bind(&ChunkDemuxerTest::DemuxerNeedKey, base::Unretained(this)); 180 &ChunkDemuxerTest::OnEncryptedMediaInitData, base::Unretained(this));
176 demuxer_.reset(new ChunkDemuxer(open_cb, need_key_cb, base::Bind(&LogFunc), 181 demuxer_.reset(new ChunkDemuxer(
177 scoped_refptr<MediaLog>(new MediaLog()), 182 open_cb, encrypted_media_init_data_cb, base::Bind(&LogFunc),
178 true)); 183 scoped_refptr<MediaLog>(new MediaLog()), true));
179 } 184 }
180 185
181 virtual ~ChunkDemuxerTest() { 186 virtual ~ChunkDemuxerTest() {
182 ShutdownDemuxer(); 187 ShutdownDemuxer();
183 } 188 }
184 189
185 void CreateInitSegment(int stream_flags, 190 void CreateInitSegment(int stream_flags,
186 bool is_audio_encrypted, 191 bool is_audio_encrypted,
187 bool is_video_encrypted, 192 bool is_video_encrypted,
188 scoped_ptr<uint8[]>* buffer, 193 scoped_ptr<uint8[]>* buffer,
(...skipping 958 matching lines...) Expand 10 before | Expand all | Expand 10 after
1147 timestamps[i].video_time_ms), 1152 timestamps[i].video_time_ms),
1148 &video_read_done)); 1153 &video_read_done));
1149 EXPECT_TRUE(video_read_done); 1154 EXPECT_TRUE(video_read_done);
1150 } 1155 }
1151 } 1156 }
1152 1157
1153 return true; 1158 return true;
1154 } 1159 }
1155 1160
1156 MOCK_METHOD0(DemuxerOpened, void()); 1161 MOCK_METHOD0(DemuxerOpened, void());
1157 // TODO(xhwang): This is a workaround of the issue that move-only parameters 1162 MOCK_METHOD2(OnEncryptedMediaInitData,
1158 // are not supported in mocked methods. Remove this when the issue is fixed 1163 void(const std::string& type,
jrummell 2014/12/06 01:08:06 nit: Should this be init_data_type?
xhwang 2014/12/06 07:03:50 Done.
1159 // (http://code.google.com/p/googletest/issues/detail?id=395) or when we use 1164 const std::vector<uint8>& init_data));
1160 // std::string instead of scoped_ptr<uint8[]> (http://crbug.com/130689).
1161 MOCK_METHOD3(NeedKeyMock, void(const std::string& type,
1162 const uint8* init_data, int init_data_size));
1163 void DemuxerNeedKey(const std::string& type,
1164 const std::vector<uint8>& init_data) {
1165 const uint8* init_data_ptr = init_data.empty() ? NULL : &init_data[0];
1166 NeedKeyMock(type, init_data_ptr, init_data.size());
1167 }
1168 1165
1169 MOCK_METHOD0(InitSegmentReceived, void(void)); 1166 MOCK_METHOD0(InitSegmentReceived, void(void));
1170 1167
1171 void Seek(base::TimeDelta seek_time) { 1168 void Seek(base::TimeDelta seek_time) {
1172 demuxer_->StartWaitingForSeek(seek_time); 1169 demuxer_->StartWaitingForSeek(seek_time);
1173 demuxer_->Seek(seek_time, NewExpectedStatusCB(PIPELINE_OK)); 1170 demuxer_->Seek(seek_time, NewExpectedStatusCB(PIPELINE_OK));
1174 message_loop_.RunUntilIdle(); 1171 message_loop_.RunUntilIdle();
1175 } 1172 }
1176 1173
1177 void MarkEndOfStream(PipelineStatus status) { 1174 void MarkEndOfStream(PipelineStatus status) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1218 if ((!has_audio && is_audio_encrypted) || 1215 if ((!has_audio && is_audio_encrypted) ||
1219 (!has_video && is_video_encrypted)) { 1216 (!has_video && is_video_encrypted)) {
1220 continue; 1217 continue;
1221 } 1218 }
1222 1219
1223 CreateNewDemuxer(); 1220 CreateNewDemuxer();
1224 1221
1225 if (is_audio_encrypted || is_video_encrypted) { 1222 if (is_audio_encrypted || is_video_encrypted) {
1226 int need_key_count = (is_audio_encrypted ? 1 : 0) + 1223 int need_key_count = (is_audio_encrypted ? 1 : 0) +
1227 (is_video_encrypted ? 1 : 0); 1224 (is_video_encrypted ? 1 : 0);
1228 EXPECT_CALL(*this, NeedKeyMock(kWebMInitDataType, NotNull(), 1225 EXPECT_CALL(*this, OnEncryptedMediaInitData(
1229 DecryptConfig::kDecryptionKeySize)) 1226 kWebMInitDataType,
1227 std::vector<uint8>(
1228 kEncryptedMediaInitData,
1229 kEncryptedMediaInitData +
1230 arraysize(kEncryptedMediaInitData))))
1230 .Times(Exactly(need_key_count)); 1231 .Times(Exactly(need_key_count));
1231 } 1232 }
1232 1233
1233 int stream_flags = 0; 1234 int stream_flags = 0;
1234 if (has_audio) 1235 if (has_audio)
1235 stream_flags |= HAS_AUDIO; 1236 stream_flags |= HAS_AUDIO;
1236 1237
1237 if (has_video) 1238 if (has_video)
1238 stream_flags |= HAS_VIDEO; 1239 stream_flags |= HAS_VIDEO;
1239 1240
(...skipping 2508 matching lines...) Expand 10 before | Expand all | Expand 10 after
3748 TEST_F(ChunkDemuxerTest, CuesBetweenClusters) { 3749 TEST_F(ChunkDemuxerTest, CuesBetweenClusters) {
3749 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 3750 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
3750 3751
3751 AppendCluster(GenerateCluster(0, 0, 4)); 3752 AppendCluster(GenerateCluster(0, 0, 4));
3752 AppendData(kCuesHeader, sizeof(kCuesHeader)); 3753 AppendData(kCuesHeader, sizeof(kCuesHeader));
3753 AppendCluster(GenerateCluster(46, 66, 5)); 3754 AppendCluster(GenerateCluster(46, 66, 5));
3754 CheckExpectedRanges(kSourceId, "{ [0,115) }"); 3755 CheckExpectedRanges(kSourceId, "{ [0,115) }");
3755 } 3756 }
3756 3757
3757 } // namespace media 3758 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698