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 <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 Loading... | |
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 static const uint8 kEncryptedFrame[] = { | |
ddorwin
2013/03/12 19:31:02
Please move up with other constants.
fgalligan1
2013/03/13 17:58:09
Done.
| |
71 0x01, // Block is encrypted | |
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 CHECK_GT(bytes_to_write, 0); | |
79 CHECK_LE(bytes_to_write, static_cast<int>(sizeof(kEncryptedFrame))); | |
80 | |
81 ClusterBuilder cb; | |
82 cb.SetClusterTimecode(0); | |
83 cb.AddSimpleBlock(kVideoTrackNum, 0, 0, kEncryptedFrame, bytes_to_write); | |
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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
158 | 175 |
159 const scoped_refptr<StreamParserBuffer> buffer = *buffer_iter++; | 176 const scoped_refptr<StreamParserBuffer> buffer = *buffer_iter++; |
160 EXPECT_EQ(buffer->GetTimestamp().InMilliseconds(), block_info.timestamp); | 177 EXPECT_EQ(buffer->GetTimestamp().InMilliseconds(), block_info.timestamp); |
161 EXPECT_EQ(buffer->GetDuration().InMilliseconds(), block_info.duration); | 178 EXPECT_EQ(buffer->GetDuration().InMilliseconds(), block_info.duration); |
162 } | 179 } |
163 | 180 |
164 EXPECT_TRUE(buffer_iter == buffer_end); | 181 EXPECT_TRUE(buffer_iter == buffer_end); |
165 return true; | 182 return true; |
166 } | 183 } |
167 | 184 |
185 static bool VerifyEncryptedFrame( | |
ddorwin
2013/03/12 19:31:02
IsEncryptedFrame(). The verification is at the cal
fgalligan1
2013/03/13 17:58:09
Done.
| |
186 const WebMClusterParser::BufferQueue& video_buffers) { | |
ddorwin
2013/03/12 19:31:02
Since this just verifies one frame, it should only
fgalligan1
2013/03/13 17:58:09
Done.
| |
187 scoped_refptr<StreamParserBuffer> buffer = video_buffers[0]; | |
188 const uint8* data = buffer->GetData(); | |
189 return data[0] & kWebMFlagEncryptedFrame; | |
190 } | |
191 | |
168 static void AppendToEnd(const WebMClusterParser::BufferQueue& src, | 192 static void AppendToEnd(const WebMClusterParser::BufferQueue& src, |
169 WebMClusterParser::BufferQueue* dest) { | 193 WebMClusterParser::BufferQueue* dest) { |
170 for (WebMClusterParser::BufferQueue::const_iterator itr = src.begin(); | 194 for (WebMClusterParser::BufferQueue::const_iterator itr = src.begin(); |
171 itr != src.end(); ++itr) { | 195 itr != src.end(); ++itr) { |
172 dest->push_back(*itr); | 196 dest->push_back(*itr); |
173 } | 197 } |
174 } | 198 } |
175 | 199 |
176 class WebMClusterParserTest : public testing::Test { | 200 class WebMClusterParserTest : public testing::Test { |
177 public: | 201 public: |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
433 | 457 |
434 while (text_it(&text_track_num, &text_buffers)) { | 458 while (text_it(&text_track_num, &text_buffers)) { |
435 const TextTrackSet::const_iterator find_result = | 459 const TextTrackSet::const_iterator find_result = |
436 text_tracks.find(text_track_num); | 460 text_tracks.find(text_track_num); |
437 ASSERT_TRUE(find_result != text_tracks.end()); | 461 ASSERT_TRUE(find_result != text_tracks.end()); |
438 ASSERT_TRUE(VerifyTextBuffers(parser_, kInputBlockInfo, input_block_count, | 462 ASSERT_TRUE(VerifyTextBuffers(parser_, kInputBlockInfo, input_block_count, |
439 text_track_num, *text_buffers)); | 463 text_track_num, *text_buffers)); |
440 } | 464 } |
441 } | 465 } |
442 | 466 |
467 TEST_F(WebMClusterParserTest, ParseEncryptedBlock) { | |
468 scoped_ptr<Cluster> cluster(CreateEncryptedCluster(sizeof(kEncryptedFrame))); | |
469 | |
470 parser_.reset(new WebMClusterParser( | |
471 kTimecodeScale, kAudioTrackNum, kVideoTrackNum, | |
472 std::set<int>(), | |
473 std::set<int64>(), "", "video_key_id", | |
474 LogCB())); | |
475 int result = parser_->Parse(cluster->data(), cluster->size()); | |
476 EXPECT_EQ(cluster->size(), result); | |
477 EXPECT_TRUE(VerifyEncryptedFrame(parser_->video_buffers())); | |
ddorwin
2013/03/12 19:31:02
The implementation of this really just checks the
fgalligan1
2013/03/13 17:58:09
Done. PTAL
| |
478 } | |
479 | |
480 TEST_F(WebMClusterParserTest, ParseBadEncryptedBlock) { | |
481 scoped_ptr<Cluster> cluster( | |
482 CreateEncryptedCluster(sizeof(kEncryptedFrame) - 1)); | |
483 | |
484 parser_.reset(new WebMClusterParser( | |
485 kTimecodeScale, kAudioTrackNum, kVideoTrackNum, | |
486 std::set<int>(), | |
487 std::set<int64>(), "", "video_key_id", | |
488 LogCB())); | |
489 int result = parser_->Parse(cluster->data(), cluster->size()); | |
490 EXPECT_EQ(-1, result); | |
491 } | |
492 | |
443 } // namespace media | 493 } // namespace media |
OLD | NEW |