libavformat/mpegts.c File Reference

#include "libavutil/crc.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/log.h"
#include "libavutil/dict.h"
#include "libavutil/mathematics.h"
#include "libavutil/opt.h"
#include "libavutil/avassert.h"
#include "libavcodec/bytestream.h"
#include "libavcodec/get_bits.h"
#include "avformat.h"
#include "mpegts.h"
#include "internal.h"
#include "avio_internal.h"
#include "seek.h"
#include "mpeg.h"
#include "isom.h"

Go to the source code of this file.

Data Structures

struct  MpegTSPESFilter
struct  MpegTSSectionFilter
struct  MpegTSFilter
struct  Program
struct  MpegTSContext
struct  PESContext
struct  SectionHeader
struct  StreamType
struct  MP4DescrParseContext

Defines

#define MAX_RESYNC_SIZE   65536
#define MAX_PES_PAYLOAD   200*1024
#define MAX_MP4_DESCR_COUNT   16
#define MAX_PIDS_PER_PROGRAM   64
#define PES_START_SIZE   6
#define PES_HEADER_SIZE   9
#define MAX_PES_HEADER_SIZE   (9 + 255)
#define MAX_LEVEL   4
#define CHECK_COUNT   10
#define MAX_PACKET_READAHEAD   ((128 * 1024) / 188)

Typedefs

typedef struct MpegTSFilter MpegTSFilter
typedef int PESCallback (MpegTSFilter *f, const uint8_t *buf, int len, int is_start, int64_t pos)
typedef void SectionCallback (MpegTSFilter *f, const uint8_t *buf, int len)
typedef void SetServiceCallback (void *opaque, int ret)

Enumerations

enum  MpegTSFilterType { MPEGTS_PES, MPEGTS_SECTION }
enum  MpegTSState {
  MPEGTS_HEADER = 0, MPEGTS_PESHEADER, MPEGTS_PESHEADER_FILL, MPEGTS_PAYLOAD,
  MPEGTS_SKIP
}

Functions

static void clear_program (MpegTSContext *ts, unsigned int programid)
static void clear_programs (MpegTSContext *ts)
static void add_pat_entry (MpegTSContext *ts, unsigned int programid)
static void add_pid_to_pmt (MpegTSContext *ts, unsigned int programid, unsigned int pid)
static void set_pcr_pid (AVFormatContext *s, unsigned int programid, unsigned int pid)
static int discard_pid (MpegTSContext *ts, unsigned int pid)
 discard_pid() decides if the pid is to be discarded according to caller's programs selection
static void write_section_data (AVFormatContext *s, MpegTSFilter *tss1, const uint8_t *buf, int buf_size, int is_start)
 Assemble PES packets out of TS packets, and then call the "section_cb" function when they are complete.
static MpegTSFiltermpegts_open_section_filter (MpegTSContext *ts, unsigned int pid, SectionCallback *section_cb, void *opaque, int check_crc)
static MpegTSFiltermpegts_open_pes_filter (MpegTSContext *ts, unsigned int pid, PESCallback *pes_cb, void *opaque)
static void mpegts_close_filter (MpegTSContext *ts, MpegTSFilter *filter)
static int analyze (const uint8_t *buf, int size, int packet_size, int *index)
static int get_packet_size (const uint8_t *buf, int size)
static int get8 (const uint8_t **pp, const uint8_t *p_end)
static int get16 (const uint8_t **pp, const uint8_t *p_end)
static char * getstr8 (const uint8_t **pp, const uint8_t *p_end)
static int parse_section_header (SectionHeader *h, const uint8_t **pp, const uint8_t *p_end)
static void mpegts_find_stream_type (AVStream *st, uint32_t stream_type, const StreamType *types)
static int mpegts_set_stream_info (AVStream *st, PESContext *pes, uint32_t stream_type, uint32_t prog_reg_desc)
static void new_pes_packet (PESContext *pes, AVPacket *pkt)
static uint64_t get_bits64 (GetBitContext *gb, int bits)
static int read_sl_header (PESContext *pes, SLConfigDescr *sl, const uint8_t *buf, int buf_size)
static int mpegts_push_data (MpegTSFilter *filter, const uint8_t *buf, int buf_size, int is_start, int64_t pos)
static PESContextadd_pes_stream (MpegTSContext *ts, int pid, int pcr_pid)
static int init_MP4DescrParseContext (MP4DescrParseContext *d, AVFormatContext *s, const uint8_t *buf, unsigned size, Mp4Descr *descr, int max_descr_count)
static void update_offsets (AVIOContext *pb, int64_t *off, int *len)
static int parse_mp4_descr (MP4DescrParseContext *d, int64_t off, int len, int target_tag)
static int parse_mp4_descr_arr (MP4DescrParseContext *d, int64_t off, int len)
static int parse_MP4IODescrTag (MP4DescrParseContext *d, int64_t off, int len)
static int parse_MP4ODescrTag (MP4DescrParseContext *d, int64_t off, int len)
static int parse_MP4ESDescrTag (MP4DescrParseContext *d, int64_t off, int len)
static int parse_MP4DecConfigDescrTag (MP4DescrParseContext *d, int64_t off, int len)
static int parse_MP4SLDescrTag (MP4DescrParseContext *d, int64_t off, int len)
static int mp4_read_iods (AVFormatContext *s, const uint8_t *buf, unsigned size, Mp4Descr *descr, int *descr_count, int max_descr_count)
static int mp4_read_od (AVFormatContext *s, const uint8_t *buf, unsigned size, Mp4Descr *descr, int *descr_count, int max_descr_count)
static void m4sl_cb (MpegTSFilter *filter, const uint8_t *section, int section_len)
int ff_parse_mpeg2_descriptor (AVFormatContext *fc, AVStream *st, int stream_type, const uint8_t **pp, const uint8_t *desc_list_end, Mp4Descr *mp4_descr, int mp4_descr_count, int pid, MpegTSContext *ts)
 Parse an MPEG-2 descriptor.
static void pmt_cb (MpegTSFilter *filter, const uint8_t *section, int section_len)
static void pat_cb (MpegTSFilter *filter, const uint8_t *section, int section_len)
static void sdt_cb (MpegTSFilter *filter, const uint8_t *section, int section_len)
static int handle_packet (MpegTSContext *ts, const uint8_t *packet)
static int mpegts_resync (AVFormatContext *s)
static int read_packet (AVFormatContext *s, uint8_t *buf, int raw_packet_size)
static int handle_packets (MpegTSContext *ts, int nb_packets)
static int mpegts_probe (AVProbeData *p)
static int parse_pcr (int64_t *ppcr_high, int *ppcr_low, const uint8_t *packet)
static int mpegts_read_header (AVFormatContext *s)
static int mpegts_raw_read_packet (AVFormatContext *s, AVPacket *pkt)
static int mpegts_read_packet (AVFormatContext *s, AVPacket *pkt)
static int mpegts_read_close (AVFormatContext *s)
static av_unused int64_t mpegts_get_pcr (AVFormatContext *s, int stream_index, int64_t *ppos, int64_t pos_limit)
static int64_t mpegts_get_dts (AVFormatContext *s, int stream_index, int64_t *ppos, int64_t pos_limit)
MpegTSContextff_mpegts_parse_open (AVFormatContext *s)
int ff_mpegts_parse_packet (MpegTSContext *ts, AVPacket *pkt, const uint8_t *buf, int len)
void ff_mpegts_parse_close (MpegTSContext *ts)

Variables

static const AVOption options []
static const AVClass mpegtsraw_class
AVInputFormat ff_mpegts_demuxer
static const StreamType ISO_types []
static const StreamType HDMV_types []
static const StreamType MISC_types []
static const StreamType REGD_types []
static const StreamType DESC_types []
AVInputFormat ff_mpegtsraw_demuxer


Define Documentation

#define CHECK_COUNT   10

#define MAX_LEVEL   4

Definition at line 996 of file mpegts.c.

#define MAX_MP4_DESCR_COUNT   16

Definition at line 47 of file mpegts.c.

Referenced by m4sl_cb(), and pmt_cb().

#define MAX_PACKET_READAHEAD   ((128 * 1024) / 188)

Definition at line 2023 of file mpegts.c.

Referenced by mpegts_raw_read_packet().

#define MAX_PES_HEADER_SIZE   (9 + 255)

Definition at line 159 of file mpegts.c.

#define MAX_PES_PAYLOAD   200*1024

Definition at line 45 of file mpegts.c.

Referenced by mpegts_push_data(), and new_pes_packet().

#define MAX_PIDS_PER_PROGRAM   64

Definition at line 88 of file mpegts.c.

Referenced by add_pid_to_pmt().

#define MAX_RESYNC_SIZE   65536

Definition at line 43 of file mpegts.c.

Referenced by mpegts_resync().

#define PES_HEADER_SIZE   9

Definition at line 158 of file mpegts.c.

Referenced by mpegts_push_data().

#define PES_START_SIZE   6

Definition at line 157 of file mpegts.c.

Referenced by mpegts_push_data(), and new_pes_packet().


Typedef Documentation

typedef struct MpegTSFilter MpegTSFilter

Definition at line 54 of file mpegts.c.

typedef int PESCallback(MpegTSFilter *f, const uint8_t *buf, int len, int is_start, int64_t pos)

Definition at line 56 of file mpegts.c.

typedef void SectionCallback(MpegTSFilter *f, const uint8_t *buf, int len)

Definition at line 63 of file mpegts.c.

typedef void SetServiceCallback(void *opaque, int ret)

Definition at line 65 of file mpegts.c.


Enumeration Type Documentation

Enumerator:
MPEGTS_PES 
MPEGTS_SECTION 

Definition at line 49 of file mpegts.c.

Enumerator:
MPEGTS_HEADER 
MPEGTS_PESHEADER 
MPEGTS_PESHEADER_FILL 
MPEGTS_PAYLOAD 
MPEGTS_SKIP 

Definition at line 148 of file mpegts.c.


Function Documentation

static void add_pat_entry ( MpegTSContext ts,
unsigned int  programid 
) [static]

Definition at line 200 of file mpegts.c.

Referenced by pat_cb().

static PESContext* add_pes_stream ( MpegTSContext ts,
int  pid,
int  pcr_pid 
) [static]

Definition at line 972 of file mpegts.c.

Referenced by handle_packet(), and pmt_cb().

static void add_pid_to_pmt ( MpegTSContext ts,
unsigned int  programid,
unsigned int  pid 
) [static]

Definition at line 213 of file mpegts.c.

Referenced by pat_cb(), and pmt_cb().

static int analyze ( const uint8_t buf,
int  size,
int  packet_size,
int *  index 
) [static]

Definition at line 393 of file mpegts.c.

static void clear_program ( MpegTSContext ts,
unsigned int  programid 
) [static]

Definition at line 185 of file mpegts.c.

Referenced by pmt_cb().

static void clear_programs ( MpegTSContext ts  )  [static]

Definition at line 194 of file mpegts.c.

Referenced by mpegts_read_close(), and pat_cb().

static int discard_pid ( MpegTSContext ts,
unsigned int  pid 
) [static]

discard_pid() decides if the pid is to be discarded according to caller's programs selection

Parameters:
ts : - TS context
pid : - pid
Returns:
1 if the pid is only comprised in programs that have .discard=AVDISCARD_ALL 0 otherwise

Definition at line 250 of file mpegts.c.

Referenced by handle_packet().

void ff_mpegts_parse_close ( MpegTSContext ts  ) 

Definition at line 2305 of file mpegts.c.

Referenced by ff_rtp_parse_close().

MpegTSContext* ff_mpegts_parse_open ( AVFormatContext s  ) 

Definition at line 2261 of file mpegts.c.

Referenced by ff_rtp_parse_open().

int ff_mpegts_parse_packet ( MpegTSContext ts,
AVPacket pkt,
const uint8_t buf,
int  len 
)

Definition at line 2280 of file mpegts.c.

Referenced by rtp_parse_one_packet(), and rtp_parse_packet_internal().

int ff_parse_mpeg2_descriptor ( AVFormatContext fc,
AVStream st,
int  stream_type,
const uint8_t **  pp,
const uint8_t desc_list_end,
Mp4Descr mp4_descr,
int  mp4_descr_count,
int  pid,
MpegTSContext ts 
)

Parse an MPEG-2 descriptor.

Parameters:
[in] fc Format context (used for logging only)
st Stream
stream_type STREAM_TYPE_xxx
pp Descriptor buffer pointer
desc_list_end End of buffer
Returns:
<0 to stop processing

Definition at line 1272 of file mpegts.c.

Referenced by parse_chunks(), and pmt_cb().

static int get16 ( const uint8_t **  pp,
const uint8_t p_end 
) [inline, static]

Definition at line 457 of file mpegts.c.

Referenced by ff_parse_mpeg2_descriptor(), parse_section_header(), pat_cb(), pmt_cb(), and sdt_cb().

static int get8 ( const uint8_t **  pp,
const uint8_t p_end 
) [inline, static]

Definition at line 444 of file mpegts.c.

Referenced by ff_parse_mpeg2_descriptor(), getstr8(), parse_section_header(), pmt_cb(), and sdt_cb().

static uint64_t get_bits64 ( GetBitContext gb,
int  bits 
) [static]

Definition at line 693 of file mpegts.c.

Referenced by read_sl_header().

static int get_packet_size ( const uint8_t buf,
int  size 
) [static]

Definition at line 418 of file mpegts.c.

Referenced by mpegts_read_header().

static char* getstr8 ( const uint8_t **  pp,
const uint8_t p_end 
) [static]

Definition at line 472 of file mpegts.c.

Referenced by sdt_cb().

static int handle_packet ( MpegTSContext ts,
const uint8_t packet 
) [static]

Definition at line 1673 of file mpegts.c.

Referenced by ff_mpegts_parse_packet(), and handle_packets().

static int handle_packets ( MpegTSContext ts,
int  nb_packets 
) [static]

Definition at line 1822 of file mpegts.c.

Referenced by mpegts_read_header(), and mpegts_read_packet().

static int init_MP4DescrParseContext ( MP4DescrParseContext d,
AVFormatContext s,
const uint8_t buf,
unsigned  size,
Mp4Descr descr,
int  max_descr_count 
) [static]

Definition at line 1007 of file mpegts.c.

Referenced by mp4_read_iods(), and mp4_read_od().

static void m4sl_cb ( MpegTSFilter filter,
const uint8_t section,
int  section_len 
) [static]

Definition at line 1208 of file mpegts.c.

Referenced by ff_parse_mpeg2_descriptor().

static int mp4_read_iods ( AVFormatContext s,
const uint8_t buf,
unsigned  size,
Mp4Descr descr,
int *  descr_count,
int  max_descr_count 
) [static]

Definition at line 1182 of file mpegts.c.

Referenced by pmt_cb().

static int mp4_read_od ( AVFormatContext s,
const uint8_t buf,
unsigned  size,
Mp4Descr descr,
int *  descr_count,
int  max_descr_count 
) [static]

Definition at line 1195 of file mpegts.c.

Referenced by m4sl_cb().

static void mpegts_close_filter ( MpegTSContext ts,
MpegTSFilter filter 
) [static]

Definition at line 372 of file mpegts.c.

Referenced by mpegts_read_close(), pat_cb(), and pmt_cb().

static void mpegts_find_stream_type ( AVStream st,
uint32_t  stream_type,
const StreamType types 
) [static]

Definition at line 587 of file mpegts.c.

Referenced by ff_parse_mpeg2_descriptor(), and mpegts_set_stream_info().

static int64_t mpegts_get_dts ( AVFormatContext s,
int  stream_index,
int64_t *  ppos,
int64_t  pos_limit 
) [static]

Definition at line 2141 of file mpegts.c.

static av_unused int64_t mpegts_get_pcr ( AVFormatContext s,
int  stream_index,
int64_t *  ppos,
int64_t  pos_limit 
) [static]

Definition at line 2111 of file mpegts.c.

static MpegTSFilter* mpegts_open_pes_filter ( MpegTSContext ts,
unsigned int  pid,
PESCallback pes_cb,
void *  opaque 
) [static]

Definition at line 349 of file mpegts.c.

Referenced by add_pes_stream().

static MpegTSFilter* mpegts_open_section_filter ( MpegTSContext ts,
unsigned int  pid,
SectionCallback section_cb,
void *  opaque,
int  check_crc 
) [static]

static int mpegts_probe ( AVProbeData p  )  [static]

Definition at line 1869 of file mpegts.c.

static int mpegts_push_data ( MpegTSFilter filter,
const uint8_t buf,
int  buf_size,
int  is_start,
int64_t  pos 
) [static]

Definition at line 776 of file mpegts.c.

Referenced by add_pes_stream().

static int mpegts_raw_read_packet ( AVFormatContext s,
AVPacket pkt 
) [static]

Definition at line 2025 of file mpegts.c.

static int mpegts_read_close ( AVFormatContext s  )  [static]

Definition at line 2098 of file mpegts.c.

static int mpegts_read_header ( AVFormatContext s  )  [static]

Definition at line 1928 of file mpegts.c.

static int mpegts_read_packet ( AVFormatContext s,
AVPacket pkt 
) [static]

Definition at line 2069 of file mpegts.c.

static int mpegts_resync ( AVFormatContext s  )  [static]

Definition at line 1775 of file mpegts.c.

Referenced by mpegts_get_pcr(), and read_packet().

static int mpegts_set_stream_info ( AVStream st,
PESContext pes,
uint32_t  stream_type,
uint32_t  prog_reg_desc 
) [static]

Definition at line 600 of file mpegts.c.

Referenced by mpegts_push_data(), and pmt_cb().

static void new_pes_packet ( PESContext pes,
AVPacket pkt 
) [static]

Definition at line 659 of file mpegts.c.

Referenced by mpegts_push_data(), and mpegts_read_packet().

static int parse_mp4_descr ( MP4DescrParseContext d,
int64_t  off,
int  len,
int  target_tag 
) [static]

Definition at line 1138 of file mpegts.c.

Referenced by mp4_read_iods(), parse_mp4_descr_arr(), and parse_MP4ESDescrTag().

static int parse_mp4_descr_arr ( MP4DescrParseContext d,
int64_t  off,
int  len 
) [static]

Definition at line 1038 of file mpegts.c.

Referenced by mp4_read_od(), parse_MP4IODescrTag(), and parse_MP4ODescrTag().

static int parse_MP4DecConfigDescrTag ( MP4DescrParseContext d,
int64_t  off,
int  len 
) [static]

Definition at line 1092 of file mpegts.c.

Referenced by parse_mp4_descr().

static int parse_MP4ESDescrTag ( MP4DescrParseContext d,
int64_t  off,
int  len 
) [static]

Definition at line 1074 of file mpegts.c.

Referenced by parse_mp4_descr().

static int parse_MP4IODescrTag ( MP4DescrParseContext d,
int64_t  off,
int  len 
) [static]

Definition at line 1048 of file mpegts.c.

Referenced by parse_mp4_descr().

static int parse_MP4ODescrTag ( MP4DescrParseContext d,
int64_t  off,
int  len 
) [static]

Definition at line 1060 of file mpegts.c.

Referenced by parse_mp4_descr().

static int parse_MP4SLDescrTag ( MP4DescrParseContext d,
int64_t  off,
int  len 
) [static]

Definition at line 1105 of file mpegts.c.

Referenced by parse_mp4_descr().

static int parse_pcr ( int64_t *  ppcr_high,
int *  ppcr_low,
const uint8_t packet 
) [static]

Definition at line 1901 of file mpegts.c.

Referenced by mpegts_get_pcr(), mpegts_raw_read_packet(), and mpegts_read_header().

static int parse_section_header ( SectionHeader h,
const uint8_t **  pp,
const uint8_t p_end 
) [static]

Definition at line 494 of file mpegts.c.

Referenced by m4sl_cb(), pat_cb(), pmt_cb(), and sdt_cb().

static void pat_cb ( MpegTSFilter filter,
const uint8_t section,
int  section_len 
) [static]

Definition at line 1547 of file mpegts.c.

Referenced by ff_mpegts_parse_open(), and mpegts_read_header().

static void pmt_cb ( MpegTSFilter filter,
const uint8_t section,
int  section_len 
) [static]

Definition at line 1401 of file mpegts.c.

Referenced by pat_cb().

static int read_packet ( AVFormatContext s,
uint8_t buf,
int  raw_packet_size 
) [static]

Definition at line 1795 of file mpegts.c.

static int read_sl_header ( PESContext pes,
SLConfigDescr sl,
const uint8_t buf,
int  buf_size 
) [static]

Definition at line 709 of file mpegts.c.

Referenced by mpegts_push_data().

static void sdt_cb ( MpegTSFilter filter,
const uint8_t section,
int  section_len 
) [static]

Definition at line 1595 of file mpegts.c.

Referenced by ff_mpegts_parse_open(), and mpegts_read_header().

static void set_pcr_pid ( AVFormatContext s,
unsigned int  programid,
unsigned int  pid 
) [static]

Definition at line 231 of file mpegts.c.

Referenced by pmt_cb().

static void update_offsets ( AVIOContext pb,
int64_t *  off,
int *  len 
) [static]

static void write_section_data ( AVFormatContext s,
MpegTSFilter tss1,
const uint8_t buf,
int  buf_size,
int  is_start 
) [static]

Assemble PES packets out of TS packets, and then call the "section_cb" function when they are complete.

Definition at line 279 of file mpegts.c.

Referenced by handle_packet().


Variable Documentation

const StreamType DESC_types[] [static]

Initial value:

Definition at line 578 of file mpegts.c.

Initial value:

 {
    .name           = "mpegts",
    .long_name      = NULL_IF_CONFIG_SMALL("MPEG-2 transport stream format"),
    .priv_data_size = sizeof(MpegTSContext),
    .read_probe     = mpegts_probe,
    .read_header    = mpegts_read_header,
    .read_packet    = mpegts_read_packet,
    .read_close     = mpegts_read_close,
    .read_timestamp = mpegts_get_dts,
    .flags          = AVFMT_SHOW_IDS | AVFMT_TS_DISCONT,



}

Definition at line 2314 of file mpegts.c.

Initial value:

 {
    .name           = "mpegtsraw",
    .long_name      = NULL_IF_CONFIG_SMALL("MPEG-2 raw transport stream format"),
    .priv_data_size = sizeof(MpegTSContext),
    .read_header    = mpegts_read_header,
    .read_packet    = mpegts_raw_read_packet,
    .read_close     = mpegts_read_close,
    .read_timestamp = mpegts_get_dts,
    .flags          = AVFMT_SHOW_IDS | AVFMT_TS_DISCONT,



    .priv_class     = &mpegtsraw_class,
}

Definition at line 2329 of file mpegts.c.

const StreamType HDMV_types[] [static]

const StreamType ISO_types[] [static]

const StreamType MISC_types[] [static]

Initial value:

 {
    { 0x81, AVMEDIA_TYPE_AUDIO,   CODEC_ID_AC3 },
    { 0x8a, AVMEDIA_TYPE_AUDIO,   CODEC_ID_DTS },
    { 0 },
}

Definition at line 560 of file mpegts.c.

const AVClass mpegtsraw_class [static]

Initial value:

 {
    .class_name = "mpegtsraw demuxer",
    .item_name  = av_default_item_name,
    .option     = options,
    .version    = LIBAVUTIL_VERSION_INT,
}

Definition at line 139 of file mpegts.c.

const AVOption options[] [static]

Initial value:

 {
    {"compute_pcr", "Compute exact PCR for each transport stream packet.", 0x42, AV_OPT_TYPE_INT,
     {.dbl = 0}, 0, 1, AV_OPT_FLAG_DECODING_PARAM },
    { NULL },
}

Definition at line 133 of file mpegts.c.

const StreamType REGD_types[] [static]

Initial value:

 {
    { MKTAG('d','r','a','c'), AVMEDIA_TYPE_VIDEO, CODEC_ID_DIRAC },
    { MKTAG('A','C','-','3'), AVMEDIA_TYPE_AUDIO,   CODEC_ID_AC3 },
    { MKTAG('B','S','S','D'), AVMEDIA_TYPE_AUDIO, CODEC_ID_S302M },
    { MKTAG('D','T','S','1'), AVMEDIA_TYPE_AUDIO,   CODEC_ID_DTS },
    { MKTAG('D','T','S','2'), AVMEDIA_TYPE_AUDIO,   CODEC_ID_DTS },
    { MKTAG('D','T','S','3'), AVMEDIA_TYPE_AUDIO,   CODEC_ID_DTS },
    { MKTAG('V','C','-','1'), AVMEDIA_TYPE_VIDEO,   CODEC_ID_VC1 },
    { 0 },
}

Definition at line 566 of file mpegts.c.


Generated on Fri Oct 26 02:48:02 2012 for FFmpeg by  doxygen 1.5.8