Home | History | Annotate | Download | only in mpeg2ts
      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 SAMPLE_AES_PROCESSOR_H_
     18 
     19 #define 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 namespace android {
     32 
     33 struct HlsSampleDecryptor : RefBase {
     34 
     35     HlsSampleDecryptor();
     36     explicit HlsSampleDecryptor(const sp<AMessage> &sampleAesKeyItem);
     37 
     38     void signalNewSampleAesKey(const sp<AMessage> &sampleAesKeyItem);
     39 
     40     size_t processNal(uint8_t *nalData, size_t nalSize);
     41     void processAAC(size_t adtsHdrSize, uint8_t *data, size_t size);
     42     void processAC3(uint8_t *data, size_t size);
     43 
     44     static AString aesBlockToStr(uint8_t block[AES_BLOCK_SIZE]);
     45 
     46 private:
     47     size_t unescapeStream(uint8_t *data, size_t limit) const;
     48     size_t findNextUnescapeIndex(uint8_t *data, size_t offset, size_t limit) const;
     49     status_t decryptBlock(uint8_t *buffer, size_t size, uint8_t AESInitVec[AES_BLOCK_SIZE]);
     50 
     51     static const int VIDEO_CLEAR_LEAD = 32;
     52     static const int AUDIO_CLEAR_LEAD = 16;
     53 
     54     AES_KEY mAesKey;
     55     uint8_t mAESInitVec[AES_BLOCK_SIZE];
     56     bool mValidKeyInfo;
     57 
     58     DISALLOW_EVIL_CONSTRUCTORS(HlsSampleDecryptor);
     59 };
     60 
     61 }  // namespace android
     62 
     63 #endif // SAMPLE_AES_PROCESSOR_H_
     64