TSPacketizer.h revision 90a92053219ae50ddf4bb54e3d54db2d309e2b8d
1/* 2 * Copyright 2012, 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 TS_PACKETIZER_H_ 18 19#define TS_PACKETIZER_H_ 20 21#include <media/stagefright/foundation/ABase.h> 22#include <utils/Errors.h> 23#include <utils/RefBase.h> 24#include <utils/Vector.h> 25 26namespace android { 27 28struct ABuffer; 29struct AMessage; 30 31// Forms the packets of a transport stream given access units. 32// Emits metadata tables (PAT and PMT) and timestamp stream (PCR) based 33// on flags. 34struct TSPacketizer : public RefBase { 35 TSPacketizer(); 36 37 // Returns trackIndex or error. 38 ssize_t addTrack(const sp<AMessage> &format); 39 40 enum { 41 EMIT_PAT_AND_PMT = 1, 42 EMIT_PCR = 2, 43 IS_ENCRYPTED = 4, 44 PREPEND_SPS_PPS_TO_IDR_FRAMES = 8, 45 }; 46 status_t packetize( 47 size_t trackIndex, const sp<ABuffer> &accessUnit, 48 sp<ABuffer> *packets, 49 uint32_t flags, 50 const uint8_t *PES_private_data, size_t PES_private_data_len, 51 size_t numStuffingBytes = 0); 52 53 // XXX to be removed once encoder config option takes care of this for 54 // encrypted mode. 55 sp<ABuffer> prependCSD( 56 size_t trackIndex, const sp<ABuffer> &accessUnit) const; 57 58protected: 59 virtual ~TSPacketizer(); 60 61private: 62 enum { 63 kPID_PMT = 0x100, 64 kPID_PCR = 0x1000, 65 }; 66 67 struct Track; 68 69 Vector<sp<Track> > mTracks; 70 71 unsigned mPATContinuityCounter; 72 unsigned mPMTContinuityCounter; 73 74 uint32_t mCrcTable[256]; 75 76 void initCrcTable(); 77 uint32_t crc32(const uint8_t *start, size_t size) const; 78 79 DISALLOW_EVIL_CONSTRUCTORS(TSPacketizer); 80}; 81 82} // namespace android 83 84#endif // TS_PACKETIZER_H_ 85 86