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 namespace android { 27 28 struct DrmUUID { 29 static const int UUID_SIZE = 16; 30 DrmUUIDDrmUUID31 DrmUUID() { 32 memset(this->uuid, 0, sizeof(uuid)); 33 } 34 35 // to allow defining Vector/KeyedVector of UUID type DrmUUIDDrmUUID36 DrmUUID(const DrmUUID &a) { 37 memcpy(this->uuid, a.uuid, sizeof(uuid)); 38 } 39 40 // to allow defining Vector/KeyedVector of UUID type DrmUUIDDrmUUID41 DrmUUID(const uint8_t uuid_in[UUID_SIZE]) { 42 memcpy(this->uuid, uuid_in, sizeof(uuid)); 43 } 44 ptrDrmUUID45 const uint8_t *ptr() const { 46 return uuid; 47 } 48 toHexStringDrmUUID49 String8 toHexString() const { 50 return arrayToHex(uuid, UUID_SIZE); 51 } 52 toHexStringDrmUUID53 static String8 toHexString(const uint8_t uuid_in[UUID_SIZE]) { 54 return arrayToHex(uuid_in, UUID_SIZE); 55 } 56 arrayToHexDrmUUID57 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 NuPlayer2Drm { 72 73 // static helpers - internal 74 75 protected: 76 static Vector<DrmUUID> parsePSSH(const void *pssh, size_t psshsize); 77 static Vector<DrmUUID> getSupportedDrmSchemes(const void *pssh, size_t psshsize); 78 79 // static helpers - public 80 81 public: 82 static sp<ABuffer> retrieveDrmInfo(const void *pssh, uint32_t psshsize); 83 static sp<ABuffer> retrieveDrmInfo(PsshInfo *); 84 85 }; // NuPlayer2Drm 86 87 } // android 88 89 #endif //NUPLAYER2_DRM_H_ 90