ATSParser.h revision ed8d14f6a934072cd012992c4ef16990a54baa9a
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    void signalDiscontinuity(DiscontinuityType type);
45    void signalEOS(status_t finalResult);
46
47    enum SourceType {
48        AVC_VIDEO,
49        MPEG2ADTS_AUDIO
50    };
51    sp<MediaSource> getSource(SourceType type);
52
53    bool PTSTimeDeltaEstablished();
54
55protected:
56    virtual ~ATSParser();
57
58private:
59    struct Program;
60    struct Stream;
61
62    Vector<sp<Program> > mPrograms;
63
64    void parseProgramAssociationTable(ABitReader *br);
65    void parseProgramMap(ABitReader *br);
66    void parsePES(ABitReader *br);
67
68    void parsePID(
69        ABitReader *br, unsigned PID,
70        unsigned payload_unit_start_indicator);
71
72    void parseAdaptationField(ABitReader *br);
73    void parseTS(ABitReader *br);
74
75    DISALLOW_EVIL_CONSTRUCTORS(ATSParser);
76};
77
78}  // namespace android
79
80#endif  // A_TS_PARSER_H_
81