ATSParser.h revision 386d609dc513e838c7e7c4c46c604493ccd560be
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 A_TS_PARSER_H_
18
19#define A_TS_PARSER_H_
20
21#include <sys/types.h>
22
23#include <media/stagefright/foundation/ABase.h>
24#include <media/stagefright/foundation/AMessage.h>
25#include <utils/Vector.h>
26#include <utils/RefBase.h>
27
28namespace android {
29
30struct ABitReader;
31struct ABuffer;
32struct MediaSource;
33
34struct ATSParser : public RefBase {
35    enum DiscontinuityType {
36        DISCONTINUITY_NONE,
37        DISCONTINUITY_SEEK,
38        DISCONTINUITY_FORMATCHANGE
39    };
40
41    ATSParser();
42
43    void feedTSPacket(const void *data, size_t size);
44
45    void signalDiscontinuity(
46            DiscontinuityType type, const sp<AMessage> &extra);
47
48    void signalEOS(status_t finalResult);
49
50    enum SourceType {
51        VIDEO,
52        AUDIO
53    };
54    sp<MediaSource> getSource(SourceType type);
55
56    bool PTSTimeDeltaEstablished();
57
58protected:
59    virtual ~ATSParser();
60
61private:
62    enum {
63        // From ISO/IEC 13818-1: 2000 (E), Table 2-29
64        STREAMTYPE_MPEG1_VIDEO          = 0x01,
65        STREAMTYPE_MPEG2_VIDEO          = 0x02,
66        STREAMTYPE_MPEG1_AUDIO          = 0x03,
67        STREAMTYPE_MPEG2_AUDIO          = 0x04,
68        STREAMTYPE_MPEG2_AUDIO_ATDS     = 0x0f,
69        STREAMTYPE_MPEG4_VIDEO          = 0x10,
70        STREAMTYPE_H264                 = 0x1b,
71    };
72
73    struct Program;
74    struct Stream;
75
76    Vector<sp<Program> > mPrograms;
77
78    void parseProgramAssociationTable(ABitReader *br);
79    void parseProgramMap(ABitReader *br);
80    void parsePES(ABitReader *br);
81
82    void parsePID(
83        ABitReader *br, unsigned PID,
84        unsigned payload_unit_start_indicator);
85
86    void parseAdaptationField(ABitReader *br);
87    void parseTS(ABitReader *br);
88
89    DISALLOW_EVIL_CONSTRUCTORS(ATSParser);
90};
91
92}  // namespace android
93
94#endif  // A_TS_PARSER_H_
95