1 /* 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 HLS_SAMPLE_AES_PROCESSOR_H_ 18 19 #define HLS_SAMPLE_AES_PROCESSOR_H_ 20 21 #include <media/stagefright/foundation/AMessage.h> 22 #include <media/stagefright/foundation/AString.h> 23 24 #include <openssl/aes.h> 25 26 #include <utils/Errors.h> 27 #include <utils/List.h> 28 #include <utils/RefBase.h> 29 #include <utils/Vector.h> 30 31 #include "SampleDecryptor.h" 32 33 namespace android { 34 35 struct HlsSampleDecryptor : SampleDecryptor { 36 37 HlsSampleDecryptor(); 38 explicit HlsSampleDecryptor(const sp<AMessage> &sampleAesKeyItem); 39 40 virtual void signalNewSampleAesKey(const sp<AMessage> &sampleAesKeyItem); 41 42 virtual size_t processNal(uint8_t *nalData, size_t nalSize); 43 virtual void processAAC(size_t adtsHdrSize, uint8_t *data, size_t size); 44 virtual void processAC3(uint8_t *data, size_t size); 45 46 static AString aesBlockToStr(uint8_t block[AES_BLOCK_SIZE]); 47 48 private: 49 size_t unescapeStream(uint8_t *data, size_t limit) const; 50 size_t findNextUnescapeIndex(uint8_t *data, size_t offset, size_t limit) const; 51 status_t decryptBlock(uint8_t *buffer, size_t size, uint8_t AESInitVec[AES_BLOCK_SIZE]); 52 53 static const int VIDEO_CLEAR_LEAD = 32; 54 static const int AUDIO_CLEAR_LEAD = 16; 55 56 AES_KEY mAesKey; 57 uint8_t mAESInitVec[AES_BLOCK_SIZE]; 58 bool mValidKeyInfo; 59 60 DISALLOW_EVIL_CONSTRUCTORS(HlsSampleDecryptor); 61 }; 62 63 } // namespace android 64 65 #endif // HLS_SAMPLE_AES_PROCESSOR_H_ 66