blob: 6704bd1e5c4dcb9e42fdefade3f8a182efd0da89 [file] [log] [blame]
Hassan Shojaniacefac142017-02-06 21:02:02 -08001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef NUPLAYER_DRM_H_
18#define NUPLAYER_DRM_H_
19
20#include <binder/Parcel.h>
21#include <media/ICrypto.h>
22#include <media/IDrm.h>
23#include <media/stagefright/MetaData.h> // for CryptInfo
24
25
26namespace android {
27
28 struct DrmUUID {
29 static const int UUID_SIZE = 16;
30
31 DrmUUID() {
32 memset(this->uuid, 0, sizeof(uuid));
33 }
34
35 // to allow defining Vector/KeyedVector of UUID type
36 DrmUUID(const DrmUUID &a) {
37 memcpy(this->uuid, a.uuid, sizeof(uuid));
38 }
39
40 // to allow defining Vector/KeyedVector of UUID type
41 DrmUUID(const uint8_t uuid_in[UUID_SIZE]) {
42 memcpy(this->uuid, uuid_in, sizeof(uuid));
43 }
44
45 const uint8_t *ptr() const {
46 return uuid;
47 }
48
49 String8 toHexString() const {
50 return arrayToHex(uuid, UUID_SIZE);
51 }
52
53 static String8 toHexString(const uint8_t uuid_in[UUID_SIZE]) {
54 return arrayToHex(uuid_in, UUID_SIZE);
55 }
56
57 static String8 arrayToHex(const uint8_t *array, int bytes) {
58 String8 result;
59 for (int i = 0; i < bytes; i++) {
60 result.appendFormat("%02x", array[i]);
61 }
62
63 return result;
64 }
65
66 protected:
67 uint8_t uuid[UUID_SIZE];
68 };
69
70
71 struct NuPlayerDrm {
72
73 // static helpers - internal
74
75 protected:
76 static sp<IDrm> CreateDrm(status_t *pstatus);
77 static sp<ICrypto> createCrypto(status_t *pstatus);
78 static Vector<DrmUUID> parsePSSH(const void *pssh, size_t psshsize);
79 static Vector<DrmUUID> getSupportedDrmSchemes(const void *pssh, size_t psshsize);
80
81 // static helpers - public
82
83 public:
84 static sp<ICrypto> createCryptoAndPlugin(const uint8_t uuid[16],
85 const Vector<uint8_t> &drmSessionId, status_t &status);
86 // Parcel has only private copy constructor so passing it in rather than returning
87 static void retrieveDrmInfo(const void *pssh, size_t psshsize,
88 const Vector<String8> &mimes_in, Parcel *parcel);
89
90 ////////////////////////////////////////////////////////////////////////////////////////////
91 /// Helpers for NuPlayerDecoder
92 ////////////////////////////////////////////////////////////////////////////////////////////
93
94 static const uint8_t kBlockSize = 16; // AES_BLOCK_SIZE
95
96 struct CryptoInfo {
97 int numSubSamples;
98 uint8_t key[kBlockSize];
99 uint8_t iv[kBlockSize];
100 CryptoPlugin::Mode mode;
101 CryptoPlugin::Pattern pattern;
102 CryptoPlugin::SubSample *subSamples;
103 };
104
105 static CryptoInfo *makeCryptoInfo(
106 int numSubSamples,
107 uint8_t key[kBlockSize],
108 uint8_t iv[kBlockSize],
109 CryptoPlugin::Mode mode,
110 size_t *clearbytes,
111 size_t *encryptedbytes);
112
113 static CryptoInfo *getSampleCryptoInfo(sp<MetaData> meta);
114
115 }; // NuPlayerDrm
116
117} // android
118
119#endif //NUPLAYER_DRM_H_