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

Side by Side Diff: media/base/test_data_util.cc

Issue 1517473002: Support HLS MPEG2 TS with SAMPLE-AES encryption. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@encryption_scheme
Patch Set: rebase Created 4 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
« no previous file with comments | « media/base/test_data_util.h ('k') | media/formats/mp2t/descriptors.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "media/base/test_data_util.h" 5 #include "media/base/test_data_util.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/numerics/safe_conversions.h" 11 #include "base/numerics/safe_conversions.h"
12 #include "base/path_service.h" 12 #include "base/path_service.h"
13 #include "media/base/decoder_buffer.h" 13 #include "media/base/decoder_buffer.h"
14 14
15 namespace media { 15 namespace media {
16 16
17 namespace {
18
19 // Key used to encrypt test files.
20 const uint8_t kSecretKey[] = {0xeb, 0xdd, 0x62, 0xf1, 0x68, 0x14, 0xd2, 0x7b,
21 0x68, 0xef, 0x12, 0x2a, 0xfc, 0xe4, 0xae, 0x3c};
22
23 // The key ID for all encrypted files.
24 const uint8_t kKeyId[] = {0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
25 0x38, 0x39, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35};
26 }
27
17 const base::FilePath::CharType kTestDataPath[] = 28 const base::FilePath::CharType kTestDataPath[] =
18 FILE_PATH_LITERAL("media/test/data"); 29 FILE_PATH_LITERAL("media/test/data");
19 30
20 base::FilePath GetTestDataFilePath(const std::string& name) { 31 base::FilePath GetTestDataFilePath(const std::string& name) {
21 base::FilePath file_path; 32 base::FilePath file_path;
22 CHECK(PathService::Get(base::DIR_SOURCE_ROOT, &file_path)); 33 CHECK(PathService::Get(base::DIR_SOURCE_ROOT, &file_path));
23 return file_path.Append(GetTestDataPath()).AppendASCII(name); 34 return file_path.Append(GetTestDataPath()).AppendASCII(name);
24 } 35 }
25 36
26 base::FilePath GetTestDataPath() { 37 base::FilePath GetTestDataPath() {
(...skipping 22 matching lines...) Expand all
49 60
50 scoped_refptr<DecoderBuffer> buffer(new DecoderBuffer(file_size)); 61 scoped_refptr<DecoderBuffer> buffer(new DecoderBuffer(file_size));
51 CHECK_EQ(file_size, 62 CHECK_EQ(file_size,
52 base::ReadFile( 63 base::ReadFile(
53 file_path, reinterpret_cast<char*>(buffer->writable_data()), 64 file_path, reinterpret_cast<char*>(buffer->writable_data()),
54 file_size)) << "Failed to read '" << name << "'"; 65 file_size)) << "Failed to read '" << name << "'";
55 66
56 return buffer; 67 return buffer;
57 } 68 }
58 69
70 bool LookupTestKeyVector(const std::vector<uint8_t>& key_id,
71 bool allow_rotation,
72 std::vector<uint8_t>* key) {
73 std::vector<uint8_t> starting_key_id(kKeyId, kKeyId + arraysize(kKeyId));
74 size_t rotate_limit = allow_rotation ? starting_key_id.size() : 1;
75 for (size_t pos = 0; pos < rotate_limit; ++pos) {
76 std::rotate(starting_key_id.begin(), starting_key_id.begin() + pos,
77 starting_key_id.end());
78 if (key_id == starting_key_id) {
79 key->assign(kSecretKey, kSecretKey + arraysize(kSecretKey));
80 std::rotate(key->begin(), key->begin() + pos, key->end());
81 return true;
82 }
83 }
84 return false;
85 }
86
87 bool LookupTestKeyString(const std::string& key_id,
88 bool allow_rotation,
89 std::string* key) {
90 std::vector<uint8_t> key_vector;
91 bool result =
92 LookupTestKeyVector(std::vector<uint8_t>(key_id.begin(), key_id.end()),
93 allow_rotation, &key_vector);
94 if (result)
95 *key = std::string(key_vector.begin(), key_vector.end());
96 return result;
97 }
98
59 } // namespace media 99 } // namespace media
OLDNEW
« no previous file with comments | « media/base/test_data_util.h ('k') | media/formats/mp2t/descriptors.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698