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 "HlsSampleDecryptor.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 MPEG_AUDIO, 42 MPEG_VIDEO, 43 MPEG4_VIDEO, 44 PCM_AUDIO, 45 METADATA, 46 }; 47 48 enum Flags { 49 // Data appended to the queue is always at access unit boundaries. 50 kFlag_AlignedData = 1, 51 kFlag_ScrambledData = 2, 52 kFlag_SampleEncryptedData = 4, 53 }; 54 explicit ElementaryStreamQueue(Mode mode, uint32_t flags = 0); 55 56 status_t appendData(const void *data, size_t size, 57 int64_t timeUs, int32_t payloadOffset = 0, 58 uint32_t pesScramblingControl = 0); 59 60 void appendScrambledData( 61 const void *data, size_t size, 62 int32_t keyId, bool isSync, 63 sp<ABuffer> clearSizes, sp<ABuffer> encSizes); 64 65 void signalEOS(); 66 void clear(bool clearFormat); 67 68 sp<ABuffer> dequeueAccessUnit(); 69 70 sp<MetaData> getFormat(); 71 72 bool isScrambled() const; 73 74 void setCasInfo(int32_t systemId, const std::vector<uint8_t> &sessionId); 75 76 void signalNewSampleAesKey(const sp<AMessage> &keyItem); 77 78 private: 79 struct RangeInfo { 80 int64_t mTimestampUs; 81 size_t mLength; 82 int32_t mPesOffset; 83 uint32_t mPesScramblingControl; 84 }; 85 86 struct ScrambledRangeInfo { 87 //int64_t mTimestampUs; 88 size_t mLength; 89 int32_t mKeyId; 90 int32_t mIsSync; 91 sp<ABuffer> mClearSizes; 92 sp<ABuffer> mEncSizes; 93 }; 94 95 Mode mMode; 96 uint32_t mFlags; 97 bool mEOSReached; 98 99 sp<ABuffer> mBuffer; 100 List<RangeInfo> mRangeInfos; 101 102 sp<ABuffer> mScrambledBuffer; 103 List<ScrambledRangeInfo> mScrambledRangeInfos; 104 int32_t mCASystemId; 105 std::vector<uint8_t> mCasSessionId; 106 107 sp<MetaData> mFormat; 108 109 sp<HlsSampleDecryptor> mSampleDecryptor; 110 int mAUIndex; 111 isSampleEncryptedElementaryStreamQueue112 bool isSampleEncrypted() const { 113 return (mFlags & kFlag_SampleEncryptedData) != 0; 114 } 115 116 sp<ABuffer> dequeueAccessUnitH264(); 117 sp<ABuffer> dequeueAccessUnitAAC(); 118 sp<ABuffer> dequeueAccessUnitAC3(); 119 sp<ABuffer> dequeueAccessUnitMPEGAudio(); 120 sp<ABuffer> dequeueAccessUnitMPEGVideo(); 121 sp<ABuffer> dequeueAccessUnitMPEG4Video(); 122 sp<ABuffer> dequeueAccessUnitPCMAudio(); 123 sp<ABuffer> dequeueAccessUnitMetadata(); 124 125 // consume a logical (compressed) access unit of size "size", 126 // returns its timestamp in us (or -1 if no time information). 127 int64_t fetchTimestamp(size_t size, 128 int32_t *pesOffset = NULL, 129 int32_t *pesScramblingControl = NULL); 130 131 sp<ABuffer> dequeueScrambledAccessUnit(); 132 133 DISALLOW_EVIL_CONSTRUCTORS(ElementaryStreamQueue); 134 }; 135 136 } // namespace android 137 138 #endif // ES_QUEUE_H_ 139