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

Side by Side Diff: media/webm/webm_cluster_parser_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 <algorithm> 5 #include <algorithm>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "media/webm/cluster_builder.h" 9 #include "media/webm/cluster_builder.h"
10 #include "media/webm/webm_cluster_parser.h" 10 #include "media/webm/webm_cluster_parser.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 CHECK_GE(block_info[i].duration, 0); 60 CHECK_GE(block_info[i].duration, 0);
61 cb.AddBlockGroup(block_info[i].track_num, 61 cb.AddBlockGroup(block_info[i].track_num,
62 block_info[i].timestamp, 62 block_info[i].timestamp,
63 block_info[i].duration, 63 block_info[i].duration,
64 0, data, sizeof(data)); 64 0, data, sizeof(data));
65 } 65 }
66 66
67 return cb.Finish(); 67 return cb.Finish();
68 } 68 }
69 69
70 const uint8 encrypted_frame[] = {
ddorwin 2013/03/12 04:40:06 kEncryptedFrame. This should be with other constan
fgalligan1 2013/03/12 17:20:13 Done.
71 0x01, // Block is encrypted
xhwang 2013/03/12 17:28:57 nit: 2 spaces before //
fgalligan1 2013/03/13 17:58:09 Done.
72 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 // IV
73 };
74
75 // Creates a Cluster with one encrypted Block. |bytes_to_write| is number of
76 // bytes of the encrypted frame to write.
77 static scoped_ptr<Cluster> CreateEncryptedCluster(int bytes_to_write) {
78 ClusterBuilder cb;
79 cb.SetClusterTimecode(0);
80 int frame_size = (bytes_to_write < 1) ? 1 : bytes_to_write;
81 if (frame_size > sizeof(encrypted_frame))
82 frame_size = sizeof(encrypted_frame);
ddorwin 2013/03/12 04:40:06 This seems unexpected. DCHECK or something if you
fgalligan1 2013/03/12 17:20:13 Done.
83 cb.AddSimpleBlock(kVideoTrackNum, 0, 0, encrypted_frame, frame_size);
84 return cb.Finish();
85 }
86
70 static bool VerifyBuffers(const WebMClusterParser::BufferQueue& audio_buffers, 87 static bool VerifyBuffers(const WebMClusterParser::BufferQueue& audio_buffers,
71 const WebMClusterParser::BufferQueue& video_buffers, 88 const WebMClusterParser::BufferQueue& video_buffers,
72 const WebMClusterParser::BufferQueue& text_buffers, 89 const WebMClusterParser::BufferQueue& text_buffers,
73 const BlockInfo* block_info, 90 const BlockInfo* block_info,
74 int block_count) { 91 int block_count) {
75 size_t audio_offset = 0; 92 size_t audio_offset = 0;
76 size_t video_offset = 0; 93 size_t video_offset = 0;
77 size_t text_offset = 0; 94 size_t text_offset = 0;
78 for (int i = 0; i < block_count; i++) { 95 for (int i = 0; i < block_count; i++) {
79 const WebMClusterParser::BufferQueue* buffers = NULL; 96 const WebMClusterParser::BufferQueue* buffers = NULL;
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 450
434 while (text_it(&text_track_num, &text_buffers)) { 451 while (text_it(&text_track_num, &text_buffers)) {
435 const TextTrackSet::const_iterator find_result = 452 const TextTrackSet::const_iterator find_result =
436 text_tracks.find(text_track_num); 453 text_tracks.find(text_track_num);
437 ASSERT_TRUE(find_result != text_tracks.end()); 454 ASSERT_TRUE(find_result != text_tracks.end());
438 ASSERT_TRUE(VerifyTextBuffers(parser_, kInputBlockInfo, input_block_count, 455 ASSERT_TRUE(VerifyTextBuffers(parser_, kInputBlockInfo, input_block_count,
439 text_track_num, *text_buffers)); 456 text_track_num, *text_buffers));
440 } 457 }
441 } 458 }
442 459
460 TEST_F(WebMClusterParserTest, ParseEncryptedBlock) {
461 scoped_ptr<Cluster> cluster(CreateEncryptedCluster(sizeof(encrypted_frame)));
462
463 parser_.reset(new WebMClusterParser(
464 kTimecodeScale, kAudioTrackNum, kVideoTrackNum,
465 std::set<int>(),
466 std::set<int64>(), "", "video_key_id",
467 LogCB()));
468 int result = parser_->Parse(cluster->data(), cluster->size());
469 EXPECT_EQ(cluster->size(), result);
ddorwin 2013/03/12 04:40:06 Can we check is_encrypted or anything?
fgalligan1 2013/03/12 17:20:13 Done.
470 }
471
472 TEST_F(WebMClusterParserTest, ParseBadEncryptedBlock) {
473 scoped_ptr<Cluster> cluster(
474 CreateEncryptedCluster(sizeof(encrypted_frame) - 1));
475
476 parser_.reset(new WebMClusterParser(
477 kTimecodeScale, kAudioTrackNum, kVideoTrackNum,
478 std::set<int>(),
479 std::set<int64>(), "", "video_key_id",
480 LogCB()));
481 int result = parser_->Parse(cluster->data(), cluster->size());
482 EXPECT_EQ(-1, result);
483 }
484
443 } // namespace media 485 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698