1 /*
2  * Copyright 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 NUPLAYER2_DRM_H_
18 #define NUPLAYER2_DRM_H_
19 
20 #include <media/NdkMediaExtractor.h>
21 #include <media/stagefright/foundation/ABuffer.h>
22 
23 #include <utils/String8.h>
24 #include <utils/Vector.h>
25 
26 #include "mediaplayer2.pb.h"
27 
28 using android::media::MediaPlayer2Proto::PlayerMessage;
29 
30 namespace android {
31 
32     struct DrmUUID {
33         static const int UUID_SIZE = 16;
34 
DrmUUIDDrmUUID35         DrmUUID() {
36             memset(this->uuid, 0, sizeof(uuid));
37         }
38 
39         // to allow defining Vector/KeyedVector of UUID type
DrmUUIDDrmUUID40         DrmUUID(const DrmUUID &a) {
41             memcpy(this->uuid, a.uuid, sizeof(uuid));
42         }
43 
44         // to allow defining Vector/KeyedVector of UUID type
DrmUUIDDrmUUID45         DrmUUID(const uint8_t uuid_in[UUID_SIZE]) {
46             memcpy(this->uuid, uuid_in, sizeof(uuid));
47         }
48 
ptrDrmUUID49         const uint8_t *ptr() const {
50             return uuid;
51         }
52 
toHexStringDrmUUID53         String8 toHexString() const {
54             return arrayToHex(uuid, UUID_SIZE);
55         }
56 
toHexStringDrmUUID57         static String8 toHexString(const uint8_t uuid_in[UUID_SIZE]) {
58             return arrayToHex(uuid_in, UUID_SIZE);
59         }
60 
arrayToHexDrmUUID61         static String8 arrayToHex(const uint8_t *array, int bytes) {
62             String8 result;
63             for (int i = 0; i < bytes; i++) {
64                 result.appendFormat("%02x", array[i]);
65             }
66 
67             return result;
68         }
69 
70     protected:
71         uint8_t uuid[UUID_SIZE];
72     };
73 
74 
75     struct NuPlayer2Drm {
76 
77         // static helpers - internal
78 
79     protected:
80         static Vector<DrmUUID> parsePSSH(const void *pssh, size_t psshsize);
81         static Vector<DrmUUID> getSupportedDrmSchemes(const void *pssh, size_t psshsize);
82 
83         // static helpers - public
84 
85     public:
86         static sp<ABuffer> retrieveDrmInfo(const void *pssh, uint32_t psshsize);
87         static status_t retrieveDrmInfo(PsshInfo *, PlayerMessage *);
88 
89     };  // NuPlayer2Drm
90 
91 }   // android
92 
93 #endif     //NUPLAYER2_DRM_H_
94