Home | History | Annotate | Download | only in mpeg2ts
      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 
     28 namespace android {
     29 
     30 struct ABitReader;
     31 struct ABuffer;
     32 struct MediaSource;
     33 
     34 struct ATSParser : public RefBase {
     35     enum DiscontinuityType {
     36         DISCONTINUITY_NONE,
     37         DISCONTINUITY_SEEK,
     38         DISCONTINUITY_FORMATCHANGE
     39     };
     40 
     41     enum Flags {
     42         // The 90kHz clock (PTS/DTS) is absolute, i.e. PTS=0 corresponds to
     43         // a media time of 0.
     44         // If this flag is _not_ specified, the first PTS encountered in a
     45         // program of this stream will be assumed to correspond to media time 0
     46         // instead.
     47         TS_TIMESTAMPS_ARE_ABSOLUTE = 1
     48     };
     49 
     50     ATSParser(uint32_t flags = 0);
     51 
     52     status_t feedTSPacket(const void *data, size_t size);
     53 
     54     void signalDiscontinuity(
     55             DiscontinuityType type, const sp<AMessage> &extra);
     56 
     57     void signalEOS(status_t finalResult);
     58 
     59     enum SourceType {
     60         VIDEO,
     61         AUDIO
     62     };
     63     sp<MediaSource> getSource(SourceType type);
     64 
     65     bool PTSTimeDeltaEstablished();
     66 
     67 protected:
     68     virtual ~ATSParser();
     69 
     70 private:
     71     enum {
     72         // From ISO/IEC 13818-1: 2000 (E), Table 2-29
     73         STREAMTYPE_MPEG1_VIDEO          = 0x01,
     74         STREAMTYPE_MPEG2_VIDEO          = 0x02,
     75         STREAMTYPE_MPEG1_AUDIO          = 0x03,
     76         STREAMTYPE_MPEG2_AUDIO          = 0x04,
     77         STREAMTYPE_MPEG2_AUDIO_ATDS     = 0x0f,
     78         STREAMTYPE_MPEG4_VIDEO          = 0x10,
     79         STREAMTYPE_H264                 = 0x1b,
     80     };
     81 
     82     struct Program;
     83     struct Stream;
     84 
     85     uint32_t mFlags;
     86     Vector<sp<Program> > mPrograms;
     87 
     88     void parseProgramAssociationTable(ABitReader *br);
     89     void parseProgramMap(ABitReader *br);
     90     void parsePES(ABitReader *br);
     91 
     92     status_t parsePID(
     93         ABitReader *br, unsigned PID,
     94         unsigned payload_unit_start_indicator);
     95 
     96     void parseAdaptationField(ABitReader *br);
     97     status_t parseTS(ABitReader *br);
     98 
     99     DISALLOW_EVIL_CONSTRUCTORS(ATSParser);
    100 };
    101 
    102 }  // namespace android
    103 
    104 #endif  // A_TS_PARSER_H_
    105