1 /* 2 * Copyright (C) 2010 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 ES_QUEUE_H_ 18 19 #define ES_QUEUE_H_ 20 21 #include <media/stagefright/foundation/ABase.h> 22 #include <media/stagefright/foundation/AMessage.h> 23 #include <utils/Errors.h> 24 #include <utils/List.h> 25 #include <utils/RefBase.h> 26 #include <vector> 27 28 #include "SampleDecryptor.h" 29 30 namespace android { 31 32 struct ABuffer; 33 class MetaData; 34 35 struct ElementaryStreamQueue { 36 enum Mode { 37 INVALID = 0, 38 H264, 39 AAC, 40 AC3, 41 EAC3, 42 AC4, 43 MPEG_AUDIO, 44 MPEG_VIDEO, 45 MPEG4_VIDEO, 46 PCM_AUDIO, 47 METADATA, 48 DTS, 49 DTS_HD, 50 DTS_UHD, 51 }; 52 53 enum Flags { 54 // Data appended to the queue is always at access unit boundaries. 55 kFlag_AlignedData = 1, 56 kFlag_ScrambledData = 2, 57 kFlag_SampleEncryptedData = 4, 58 }; 59 explicit ElementaryStreamQueue(Mode mode, uint32_t flags = 0); 60 61 status_t appendData(const void *data, size_t size, 62 int64_t timeUs, int32_t payloadOffset = 0, 63 uint32_t pesScramblingControl = 0); 64 65 void appendScrambledData( 66 const void *data, size_t size, 67 size_t leadingClearBytes, 68 int32_t keyId, bool isSync, 69 sp<ABuffer> clearSizes, sp<ABuffer> encSizes); 70 71 void signalEOS(); 72 void clear(bool clearFormat); 73 74 sp<ABuffer> dequeueAccessUnit(); 75 76 sp<MetaData> getFormat(); 77 78 bool isScrambled() const; 79 80 void setCasInfo(int32_t systemId, const std::vector<uint8_t> &sessionId); 81 82 void signalNewSampleAesKey(const sp<AMessage> &keyItem); 83 84 private: 85 struct RangeInfo { 86 int64_t mTimestampUs; 87 size_t mLength; 88 int32_t mPesOffset; 89 uint32_t mPesScramblingControl; 90 }; 91 92 struct ScrambledRangeInfo { 93 size_t mLength; 94 size_t mLeadingClearBytes; 95 int32_t mKeyId; 96 int32_t mIsSync; 97 sp<ABuffer> mClearSizes; 98 sp<ABuffer> mEncSizes; 99 }; 100 101 Mode mMode; 102 uint32_t mFlags; 103 bool mEOSReached; 104 105 sp<ABuffer> mBuffer; 106 List<RangeInfo> mRangeInfos; 107 108 sp<ABuffer> mScrambledBuffer; 109 List<ScrambledRangeInfo> mScrambledRangeInfos; 110 int32_t mCASystemId; 111 std::vector<uint8_t> mCasSessionId; 112 113 sp<MetaData> mFormat; 114 115 sp<SampleDecryptor> mSampleDecryptor; 116 int mAUIndex; 117 isSampleEncryptedElementaryStreamQueue118 bool isSampleEncrypted() const { 119 return (mFlags & kFlag_SampleEncryptedData) != 0; 120 } 121 122 sp<ABuffer> dequeueAccessUnitH264(); 123 sp<ABuffer> dequeueAccessUnitAAC(); 124 sp<ABuffer> dequeueAccessUnitEAC3(); 125 sp<ABuffer> dequeueAccessUnitAC4(); 126 sp<ABuffer> dequeueAccessUnitMPEGAudio(); 127 sp<ABuffer> dequeueAccessUnitMPEGVideo(); 128 sp<ABuffer> dequeueAccessUnitMPEG4Video(); 129 sp<ABuffer> dequeueAccessUnitPCMAudio(); 130 sp<ABuffer> dequeueAccessUnitMetadata(); 131 sp<ABuffer> dequeueAccessUnitDTSOrDTSHD(); 132 sp<ABuffer> dequeueAccessUnitDTSUHD(); 133 134 // consume a logical (compressed) access unit of size "size", 135 // returns its timestamp in us (or -1 if no time information). 136 int64_t fetchTimestamp(size_t size, 137 int32_t *pesOffset = NULL, 138 int32_t *pesScramblingControl = NULL); 139 140 sp<ABuffer> dequeueScrambledAccessUnit(); 141 142 DISALLOW_EVIL_CONSTRUCTORS(ElementaryStreamQueue); 143 }; 144 145 } // namespace android 146 147 #endif // ES_QUEUE_H_ 148