blob: 4a664ee279196bf3e152629ef0e335b3b62355f9 [file] [log] [blame]
Andreas Huberd7bee3a2012-08-29 11:41:50 -07001/*
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 {
Andreas Huberbfd79f22013-03-07 10:33:20 -080035 enum {
36 EMIT_HDCP20_DESCRIPTOR = 1,
37 EMIT_HDCP21_DESCRIPTOR = 2,
38 };
39 TSPacketizer(uint32_t flags);
Andreas Huberd7bee3a2012-08-29 11:41:50 -070040
41 // Returns trackIndex or error.
42 ssize_t addTrack(const sp<AMessage> &format);
43
44 enum {
Andreas Huberc6920df2012-10-02 10:16:47 -070045 EMIT_PAT_AND_PMT = 1,
46 EMIT_PCR = 2,
47 IS_ENCRYPTED = 4,
48 PREPEND_SPS_PPS_TO_IDR_FRAMES = 8,
Andreas Huberd7bee3a2012-08-29 11:41:50 -070049 };
50 status_t packetize(
51 size_t trackIndex, const sp<ABuffer> &accessUnit,
52 sp<ABuffer> *packets,
Andreas Huberb8c7bd42012-09-18 14:47:48 -070053 uint32_t flags,
Andreas Huber90a92052012-10-30 15:53:03 -070054 const uint8_t *PES_private_data, size_t PES_private_data_len,
55 size_t numStuffingBytes = 0);
Andreas Huberd7bee3a2012-08-29 11:41:50 -070056
Andreas Hubera556c482013-03-05 10:56:27 -080057 status_t extractCSDIfNecessary(size_t trackIndex);
58
Andreas Hubere399acc2012-09-27 08:53:23 -070059 // XXX to be removed once encoder config option takes care of this for
60 // encrypted mode.
61 sp<ABuffer> prependCSD(
62 size_t trackIndex, const sp<ABuffer> &accessUnit) const;
63
Andreas Huberd7bee3a2012-08-29 11:41:50 -070064protected:
65 virtual ~TSPacketizer();
66
67private:
68 enum {
69 kPID_PMT = 0x100,
70 kPID_PCR = 0x1000,
71 };
72
73 struct Track;
74
Andreas Huberbfd79f22013-03-07 10:33:20 -080075 uint32_t mFlags;
Andreas Huberd7bee3a2012-08-29 11:41:50 -070076 Vector<sp<Track> > mTracks;
77
Andreas Huberbfd79f22013-03-07 10:33:20 -080078 Vector<sp<ABuffer> > mProgramInfoDescriptors;
79
Andreas Huberd7bee3a2012-08-29 11:41:50 -070080 unsigned mPATContinuityCounter;
81 unsigned mPMTContinuityCounter;
82
83 uint32_t mCrcTable[256];
84
85 void initCrcTable();
86 uint32_t crc32(const uint8_t *start, size_t size) const;
87
88 DISALLOW_EVIL_CONSTRUCTORS(TSPacketizer);
89};
90
91} // namespace android
92
93#endif // TS_PACKETIZER_H_
94