43 #define MAX_RESYNC_SIZE 65536
45 #define MAX_PES_PAYLOAD 200 * 1024
47 #define MAX_MP4_DESCR_COUNT 16
49 #define MOD_UNLIKELY(modulus, dividend, divisor, prev_dividend) \
51 if ((prev_dividend) == 0 || (dividend) - (prev_dividend) != (divisor)) \
52 (modulus) = (dividend) % (divisor); \
53 (prev_dividend) = (dividend); \
65 int is_start, int64_t pos);
101 #define MAX_PIDS_PER_PROGRAM 64
120 #define SIZE_STAT_THRESHOLD 10
164 #define MPEGTS_OPTIONS \
165 { "resync_size", "set size limit for looking up a new synchronization", offsetof(MpegTSContext, resync_size), AV_OPT_TYPE_INT, { .i64 = MAX_RESYNC_SIZE}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM }
176 {.i64 = 0}, 0, 1, 0 },
178 {.i64 = 0}, 0, 1, 0 },
191 {
"compute_pcr",
"compute exact PCR for each transport stream packet",
194 {
"ts_packetsize",
"output option carrying the raw packet size",
219 #define PES_START_SIZE 6
220 #define PES_HEADER_SIZE 9
221 #define MAX_PES_HEADER_SIZE (9 + 255)
250 for (i = 0; i < ts->
nb_prg; i++) {
251 if (ts->
prg[i].
id == programid) {
278 for (i = 0; i < ts->
nb_prg; i++)
279 if (ts->
prg[i].
id == programid) {
316 for (i = 0; i < p->
nb_pids; i++)
317 if (p->
pids[i] == pid)
354 int used = 0, discarded = 0;
365 for (i = 0; i < ts->
nb_prg; i++) {
367 for (j = 0; j < p->
nb_pids; j++) {
368 if (p->
pids[j] != pid)
382 return !used && discarded;
390 const uint8_t *
buf,
int buf_size,
int is_start)
541 memset(stat, 0, packet_size *
sizeof(*stat));
543 for (i = 0; i < size - 3; i++) {
544 if (buf[i] == 0x47 &&
545 (!probe || (!(buf[i + 1] & 0x80) && buf[i + 3] != 0x47))) {
546 int x = i % packet_size;
549 if (stat[x] > best_score) {
550 best_score = stat[x];
557 return best_score -
FFMAX(stat_all - 10*best_score, 0)/10;
563 int score, fec_score, dvhs_score;
572 score, dvhs_score, fec_score);
574 if (score > fec_score && score > dvhs_score)
576 else if (dvhs_score > score && dvhs_score > fec_score)
578 else if (score < fec_score && dvhs_score < fec_score)
638 len =
get8(&p, p_end);
658 val =
get8(pp, p_end);
663 val =
get16(pp, p_end);
667 val =
get8(pp, p_end);
670 h->
version = (val >> 1) & 0x1f;
671 val =
get8(pp, p_end);
675 val =
get8(pp, p_end);
697 #if !CONFIG_LOAS_DEMUXER
763 uint32_t stream_type,
781 uint32_t stream_type, uint32_t prog_reg_desc)
800 "stream=%d stream_type=%x pid=%x prog_reg_desc=%.4s\n",
806 if ((prog_reg_desc ==
AV_RL32(
"HDMV") ||
807 prog_reg_desc ==
AV_RL32(
"HDPR")) &&
818 memcpy(sub_pes, pes,
sizeof(*sub_pes));
826 sub_st->
id = pes->
pid;
904 int au_start_flag = 0, au_end_flag = 0, ocr_flag = 0, idle_flag = 0;
905 int padding_flag = 0, padding_bits = 0, inst_bitrate_flag = 0;
906 int dts_flag = -1, cts_flag = -1;
911 memcpy(buf_padded, buf, buf_padded_size);
920 au_start_flag = au_end_flag = 1;
930 if (!idle_flag && (!padding_flag || padding_bits != 0)) {
956 if (inst_bitrate_flag)
973 const uint8_t *
buf,
int buf_size,
int is_start,
995 while (buf_size > 0) {
996 switch (pes->
state) {
1008 if (pes->
header[0] == 0x00 && pes->
header[1] == 0x00 &&
1009 pes->
header[2] == 0x01) {
1011 code = pes->
header[3] | 0x100;
1045 if (code != 0x1bc && code != 0x1bf &&
1046 code != 0x1f0 && code != 0x1f1 &&
1047 code != 0x1ff && code != 0x1f2 &&
1052 "pid=%x stream_type=%x probing\n",
1100 unsigned int flags, pes_ext, skip;
1106 if ((flags & 0xc0) == 0x80) {
1109 }
else if ((flags & 0xc0) == 0xc0) {
1119 skip = (pes_ext >> 4) & 0xb;
1122 if ((pes_ext & 0x41) == 0x01 &&
1125 if ((r[0] & 0x7f) > 0 && (r[1] & 0x80) == 0)
1137 p += sl_header_bytes;
1138 buf_size -= sl_header_bytes;
1177 pes->
pts = pes->
dts = pcr;
1179 pes->
dts > pcr + 3654 + 9000) {
1180 pes->
pts = pes->
dts = pcr + 3654 + 9000;
1182 pes->
dts > pcr + 10*90000) {
1183 pes->
pts = pes->
dts = pcr + 3654 + 9000;
1272 Mp4Descr *descr,
int max_descr_count)
1275 if (size > (1 << 30))
1295 (*len) -= new_off - *off;
1331 if (!(id_flags & 0x0020)) {
1416 if (len < 0 || len1 > len || len1 <= 0) {
1418 "Tag %x length violation new length %d bytes remaining %d\n",
1428 if (target_tag && tag != target_tag) {
1460 Mp4Descr *descr,
int *descr_count,
int max_descr_count)
1476 Mp4Descr *descr,
int *descr_count,
int max_descr_count)
1499 int mp4_descr_count = 0;
1504 p_end = section + section_len - 4;
1513 mp4_read_od(s, p, (
unsigned) (p_end - p), mp4_descr, &mp4_descr_count,
1519 for (i = 0; i < mp4_descr_count; i++) {
1533 pes->
sl = mp4_descr[i].
sl;
1536 mp4_descr[i].dec_config_descr_len, 0,
1556 for (i = 0; i < mp4_descr_count; i++)
1557 av_free(mp4_descr[i].dec_config_descr);
1561 1, 0, 1, 1, 2, 2, 2, 3, 3
1565 1, 1, 1, 2, 2, 3, 4, 4, 5,
1576 { 0,6,1,2,3,4,5,7 },
1581 Mp4Descr *mp4_descr,
int mp4_descr_count,
int pid,
1585 int desc_len, desc_tag, desc_es_id, ext_desc_tag, channels, channel_config_code;
1589 desc_tag =
get8(pp, desc_list_end);
1592 desc_len =
get8(pp, desc_list_end);
1595 desc_end = *pp + desc_len;
1596 if (desc_end > desc_list_end)
1607 desc_es_id =
get16(pp, desc_end);
1610 if (ts && ts->
pids[pid])
1612 for (i = 0; i < mp4_descr_count; i++)
1613 if (mp4_descr[i].dec_config_descr_len &&
1614 mp4_descr[i].es_id == desc_es_id) {
1617 mp4_descr[i].dec_config_descr_len, 0,
1628 if (
get16(pp, desc_end) < 0)
1630 if (mp4_descr_count > 0 &&
1650 int language_count = desc_len / 5;
1652 if (desc_len > 0 && desc_len % 5 != 0)
1655 if (language_count > 0) {
1657 av_assert0(language_count <=
sizeof(language) / 4);
1670 for (i = 0; i < language_count; i++) {
1671 language[i * 4 + 0] =
get8(pp, desc_end);
1672 language[i * 4 + 1] =
get8(pp, desc_end);
1673 language[i * 4 + 2] =
get8(pp, desc_end);
1674 language[i * 4 + 3] =
',';
1676 memcpy(extradata, *pp, 2);
1682 language[i * 4 - 1] = 0;
1694 int language_count = desc_len / 8;
1696 if (desc_len > 0 && desc_len % 8 != 0)
1699 if (language_count > 1) {
1703 if (language_count > 0) {
1707 av_assert0(language_count <=
sizeof(language) / 4);
1720 for (i = 0; i < language_count; i++) {
1721 language[i * 4 + 0] =
get8(pp, desc_end);
1722 language[i * 4 + 1] =
get8(pp, desc_end);
1723 language[i * 4 + 2] =
get8(pp, desc_end);
1724 language[i * 4 + 3] =
',';
1738 extradata[4] =
get8(pp, desc_end);
1739 memcpy(extradata, *pp, 4);
1745 language[i * 4 - 1] = 0;
1751 for (i = 0; i + 4 <= desc_len; i += 4) {
1752 language[i + 0] =
get8(pp, desc_end);
1753 language[i + 1] =
get8(pp, desc_end);
1754 language[i + 2] =
get8(pp, desc_end);
1755 language[i + 3] =
',';
1756 switch (
get8(pp, desc_end)) {
1768 if (i && language[0]) {
1769 language[i - 1] = 0;
1783 if (
get16(pp, desc_end) == 0xFFFF)
1785 if (
get8(pp, desc_end) == 0xFF) {
1792 ext_desc_tag =
get8(pp, desc_end);
1793 if (ext_desc_tag < 0)
1796 ext_desc_tag == 0x80) {
1806 channel_config_code =
get8(pp, desc_end);
1807 if (channel_config_code < 0)
1809 if (channel_config_code <= 0x8) {
1810 st->
codec->
extradata[9] = channels = channel_config_code ? channel_config_code : 2;
1811 st->
codec->
extradata[18] = channel_config_code ? (channels > 2) : 255;
1836 const uint8_t *p, *p_end, *desc_list_end;
1837 int program_info_length, pcr_pid, pid, stream_type;
1839 uint32_t prog_reg_desc = 0;
1841 int mp4_descr_count = 0;
1848 p_end = section + section_len - 4;
1866 pcr_pid =
get16(&p, p_end);
1875 program_info_length =
get16(&p, p_end);
1876 if (program_info_length < 0)
1878 program_info_length &= 0xfff;
1879 while (program_info_length >= 2) {
1881 tag =
get8(&p, p_end);
1882 len =
get8(&p, p_end);
1886 if (len > program_info_length - 2)
1889 program_info_length -= len + 2;
1896 }
else if (tag == 0x05 && len >= 4) {
1897 prog_reg_desc = bytestream_get_le32(&p);
1902 p += program_info_length;
1916 stream_type =
get8(&p, p_end);
1917 if (stream_type < 0)
1919 pid =
get16(&p, p_end);
1936 }
else if (stream_type != 0x13) {
1969 desc_list_len =
get16(&p, p_end);
1970 if (desc_list_len < 0)
1972 desc_list_len &= 0xfff;
1973 desc_list_end = p + desc_list_len;
1974 if (desc_list_end > p_end)
1978 desc_list_end, mp4_descr,
1979 mp4_descr_count, pid, ts) < 0)
1982 if (pes && prog_reg_desc ==
AV_RL32(
"HDMV") &&
1983 stream_type == 0x83 && pes->
sub_st) {
1992 if (!ts->
pids[pcr_pid])
1996 for (i = 0; i < mp4_descr_count; i++)
1997 av_free(mp4_descr[i].dec_config_descr);
2012 p_end = section + section_len - 4;
2027 sid =
get16(&p, p_end);
2030 pmt_pid =
get16(&p, p_end);
2040 if (sid == 0x0000) {
2051 || fil->
pid != pmt_pid
2055 if (!ts->
pids[pmt_pid])
2066 for (i = 0; i < ts->
nb_prg; i++)
2080 const uint8_t *p, *p_end, *desc_list_end, *desc_end;
2081 int onid,
val, sid, desc_list_len, desc_tag, desc_len, service_type;
2082 char *
name, *provider_name;
2087 p_end = section + section_len - 4;
2098 onid =
get16(&p, p_end);
2101 val =
get8(&p, p_end);
2105 sid =
get16(&p, p_end);
2108 val =
get8(&p, p_end);
2111 desc_list_len =
get16(&p, p_end);
2112 if (desc_list_len < 0)
2114 desc_list_len &= 0xfff;
2115 desc_list_end = p + desc_list_len;
2116 if (desc_list_end > p_end)
2119 desc_tag =
get8(&p, desc_list_end);
2122 desc_len =
get8(&p, desc_list_end);
2123 desc_end = p + desc_len;
2124 if (desc_len < 0 || desc_end > desc_list_end)
2128 desc_tag, desc_len);
2132 service_type =
get8(&p, p_end);
2133 if (service_type < 0)
2135 provider_name =
getstr8(&p, p_end);
2159 static int parse_pcr(int64_t *ppcr_high,
int *ppcr_low,
2166 int len, pid, cc, expected_cc, cc_ok, afc, is_start, is_discontinuity,
2167 has_adaptation, has_payload;
2171 pid =
AV_RB16(packet + 1) & 0x1fff;
2174 is_start = packet[1] & 0x40;
2175 tss = ts->
pids[pid];
2178 tss = ts->
pids[pid];
2184 afc = (packet[3] >> 4) & 3;
2187 has_adaptation = afc & 2;
2188 has_payload = afc & 1;
2189 is_discontinuity = has_adaptation &&
2194 cc = (packet[3] & 0xf);
2195 expected_cc = has_payload ? (tss->
last_cc + 1) & 0x0f : tss->
last_cc;
2196 cc_ok = pid == 0x1FFF ||
2204 "Continuity check failed for pid %d expected %d got %d\n",
2205 pid, expected_cc, cc);
2213 if (has_adaptation) {
2216 if (
parse_pcr(&pcr_h, &pcr_l, packet) == 0)
2217 tss->
last_pcr = pcr_h * 300 + pcr_l;
2223 if (p >= p_end || !has_payload)
2236 if (len > p_end - p)
2262 for (i = 0; i < ts->
nb_prg; i++) {
2344 "max resync size reached, could not find sync byte\n");
2361 if ((*data)[0] != 0x47) {
2418 if (nb_packets != 0 && packet_num >= nb_packets ||
2445 #define CHECK_COUNT 10
2446 #define CHECK_BLOCK 100
2456 score =
FFMAX3(score, dvhs_score, fec_score);
2458 maxscore =
FFMAX(maxscore, score);
2464 ff_dlog(0,
"TS score: %d %d\n", sumscore, maxscore);
2480 afc = (packet[3] >> 4) & 3;
2490 if (!(flags & 0x10))
2495 *ppcr_high = ((int64_t) v << 1) | (p[4] >> 7);
2496 *ppcr_low = ((p[4] & 1) << 8) | p[5];
2515 int64_t pos, probesize =
2516 #if FF_API_PROBESIZE_32
2536 if (s->
iformat == &ff_mpegts_demuxer) {
2556 int pcr_pid, pid, nb_packets, nb_pcrs, ret, pcr_l;
2557 int64_t pcrs[2], pcr_h;
2558 int packet_count[2];
2579 pid =
AV_RB16(data + 1) & 0x1fff;
2580 if ((pcr_pid == -1 || pcr_pid == pid) &&
2584 packet_count[nb_pcrs] = nb_packets;
2585 pcrs[nb_pcrs] = pcr_h * 300 + pcr_l;
2597 ts->
pcr_incr = (pcrs[1] - pcrs[0]) / (packet_count[1] - packet_count[0]);
2610 #define MAX_PACKET_READAHEAD ((128 * 1024) / 188)
2616 int64_t pcr_h, next_pcr_h, pos;
2617 int pcr_l, next_pcr_l;
2629 if (data != pkt->
data)
2640 if (
parse_pcr(&next_pcr_h, &next_pcr_l, pcr_buf) == 0) {
2643 ((next_pcr_h - pcr_h) * 300 + (next_pcr_l - pcr_l)) /
2650 ts->
cur_pcr = pcr_h * 300 + pcr_l;
2683 if (!ret && pkt->
size < 0)
2707 int64_t *ppos, int64_t pos_limit)
2710 int64_t pos, timestamp;
2712 int pcr_l, pcr_pid =
2718 while(pos < pos_limit) {
2723 if (buf[0] != 0x47) {
2730 if ((pcr_pid < 0 || (
AV_RB16(buf + 1) & 0x1fff) == pcr_pid) &&
2731 parse_pcr(×tamp, &pcr_l, buf) == 0) {
2742 int64_t *ppos, int64_t pos_limit)
2751 while(pos < pos_limit) {
2806 if (buf[0] != 0x47) {
2836 .priv_class = &mpegts_class,
2840 .
name =
"mpegtsraw",
2848 .priv_class = &mpegtsraw_class,
static void mpegts_free(MpegTSContext *ts)
int64_t probesize
Maximum size of the data read from input for determining the input container format.
const char const char void * val
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it...
void av_free_packet(AVPacket *pkt)
Free a packet.
static int mpegts_resync(AVFormatContext *s)
void ff_mp4_parse_es_descr(AVIOContext *pb, int *es_id)
static void finished_reading_packet(AVFormatContext *s, int raw_packet_size)
A dummy id pointing at the start of audio codecs.
ptrdiff_t const GLvoid * data
int64_t cur_pcr
used to estimate the exact PCR
#define AV_OPT_FLAG_EXPORT
The option is inteded for exporting values to the caller.
int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp, int size, int distance, int flags)
Add an index entry into a sorted list.
#define MAX_PACKET_READAHEAD
enum AVMediaType codec_type
static int parse_MP4ODescrTag(MP4DescrParseContext *d, int64_t off, int len)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
#define AV_LOG_WARNING
Something somehow does not look correct.
static int handle_packet(MpegTSContext *ts, const uint8_t *packet)
#define LIBAVUTIL_VERSION_INT
int64_t pos
byte position in stream, -1 if unknown
static void clear_program(MpegTSContext *ts, unsigned int programid)
static void skip_bits_long(GetBitContext *s, int n)
static int mpegts_probe(AVProbeData *p)
int8_t crc_validity[NB_PID_MAX]
MpegTSContext * avpriv_mpegts_parse_open(AVFormatContext *s)
int64_t pts_wrap_reference
Internal data to check for wrapping of the time stamp.
int index
stream index in AVFormatContext
MpegTSPESFilter pes_filter
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
AVInputFormat ff_mpegts_demuxer
static void sdt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len)
A dummy ID pointing at the start of various fake codecs.
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
static int parse_section_header(SectionHeader *h, const uint8_t **pp, const uint8_t *p_end)
enum MpegTSFilterType type
static int mpegts_read_packet(AVFormatContext *s, AVPacket *pkt)
unsigned int avio_rb16(AVIOContext *s)
int ctx_flags
Flags signalling stream properties.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_WB24 unsigned int_TMPL AV_RB16
int pcr_pid
if -1 then all packets containing PCR are considered
unsigned int nb_prg
structure to keep track of Program->pids mapping
static int read_packet(AVFormatContext *s, uint8_t *buf, int raw_packet_size, const uint8_t **data)
unsigned int nb_stream_indexes
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
unsigned int pids[MAX_PIDS_PER_PROGRAM]
#define av_assert0(cond)
assert() equivalent, that is always enabled.
#define SIZE_STAT_THRESHOLD
static int read_sl_header(PESContext *pes, SLConfigDescr *sl, const uint8_t *buf, int buf_size)
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
MpegTSFilter * pids[NB_PID_MAX]
filters for various streams specified by PMT + for the PAT and PMT
static int mpegts_read_header(AVFormatContext *s)
int stream_identifier
Stream Identifier This is the MPEG-TS stream identifier +1 0 means unknown.
Opaque data information usually continuous.
static struct Program * get_program(MpegTSContext *ts, unsigned int programid)
static int64_t mpegts_get_dts(AVFormatContext *s, int stream_index, int64_t *ppos, int64_t pos_limit)
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
unsigned int avio_rb32(AVIOContext *s)
int stop_parse
stop parsing loop
static int parse_MP4ESDescrTag(MP4DescrParseContext *d, int64_t off, int len)
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 add_pat_entry(MpegTSContext *ts, unsigned int programid)
static int mpegts_push_data(MpegTSFilter *filter, const uint8_t *buf, int buf_size, int is_start, int64_t pos)
int id
Format-specific stream ID.
enum AVStreamParseType need_parsing
static const AVOption raw_options[]
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
static const uint8_t opus_channel_map[8][8]
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
AVStream ** streams
A list of all streams in the file.
int ffio_read_indirect(AVIOContext *s, unsigned char *buf, int size, const unsigned char **data)
Read size bytes from AVIOContext, returning a pointer.
static void update_offsets(AVIOContext *pb, int64_t *off, int *len)
AVProgram * av_new_program(AVFormatContext *s, int id)
static int get_bits_count(const GetBitContext *s)
#define AVERROR_EOF
End of file.
bitstream reader API header.
static av_cold int read_close(AVFormatContext *ctx)
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
static void seek_back(AVFormatContext *s, AVIOContext *pb, int64_t pos)
enum AVDiscard discard
selects which program to discard and which to feed to the caller
static int probe(AVProbeData *p)
static PESContext * add_pes_stream(MpegTSContext *ts, int pid, int pcr_pid)
int duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
unsigned int * stream_index
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
static MpegTSFilter * mpegts_open_pes_filter(MpegTSContext *ts, unsigned int pid, PESCallback *pes_cb, void *opaque)
AVInputFormat ff_mpegtsraw_demuxer
static int init_MP4DescrParseContext(MP4DescrParseContext *d, AVFormatContext *s, const uint8_t *buf, unsigned size, Mp4Descr *descr, int max_descr_count)
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
static int get_bits_left(GetBitContext *gb)
static uint64_t get_bits64(GetBitContext *s, int n)
Read 0-64 bits.
AVProgram * av_find_program_from_stream(AVFormatContext *ic, AVProgram *last, int s)
Find the programs which belong to a given stream.
static const uint8_t opus_default_extradata[30]
int ff_mp4_read_dec_config_descr(AVFormatContext *fc, AVStream *st, AVIOContext *pb)
static void reanalyze(MpegTSContext *ts)
int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
AVCodecID
Identify the syntax and semantics of the bitstream.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int predefined_SLConfigDescriptor_seen
static const StreamType HDMV_types[]
static void clear_avprogram(MpegTSContext *ts, unsigned int programid)
static int mpegts_read_close(AVFormatContext *s)
static int mpegts_raw_read_packet(AVFormatContext *s, AVPacket *pkt)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
int avcodec_is_open(AVCodecContext *s)
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
preferred ID for decoding MPEG audio layer 1, 2 or 3
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
simple assert() macros that are a bit more flexible than ISO C assert().
#define TS_FEC_PACKET_SIZE
New fields can be added to the end with minor version bumps.
static int64_t ff_parse_pes_pts(const uint8_t *buf)
Parse MPEG-PES five-byte timestamp.
static int parse_MP4DecConfigDescrTag(MP4DescrParseContext *d, int64_t off, int len)
int flags
copied to the AVPacket flags
int pcr_incr
used to estimate the exact PCR
int flags
A combination of AV_PKT_FLAG values.
int avio_r8(AVIOContext *s)
AVCodecContext * codec
Codec context associated with this stream.
int buf_size
Size of buf except extra allocated bytes.
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
common internal API header
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
static const uint16_t fc[]
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
int bit_rate
the average bitrate
int64_t ts_packet_pos
position of first TS packet of this PES packet
SectionCallback * section_cb
static const StreamType REGD_types[]
int PESCallback(MpegTSFilter *f, const uint8_t *buf, int len, int is_start, int64_t pos)
static const StreamType MISC_types[]
static void set_pcr_pid(AVFormatContext *s, unsigned int programid, unsigned int pid)
static int mp4_read_od(AVFormatContext *s, const uint8_t *buf, unsigned size, Mp4Descr *descr, int *descr_count, int max_descr_count)
#define TS_DVHS_PACKET_SIZE
uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length)
Calculate the CRC of a block.
static void set_pmt_found(MpegTSContext *ts, unsigned int programid)
static int mpegts_set_stream_info(AVStream *st, PESContext *pes, uint32_t stream_type, uint32_t prog_reg_desc)
static const uint8_t opus_stream_cnt[9]
static int parse_mp4_descr(MP4DescrParseContext *d, int64_t off, int len, int target_tag)
static int parse_MP4SLDescrTag(MP4DescrParseContext *d, int64_t off, int len)
int mpeg2ts_compute_pcr
compute exact PCR for each transport stream packet
static const AVClass mpegtsraw_class
MpegTSSectionFilter section_filter
static const uint8_t opus_coupled_stream_cnt[9]
static uint64_t get_ts64(GetBitContext *gb, int bits)
preferred ID for MPEG-1/2 video decoding
union MpegTSFilter::@172 u
int auto_guess
if true, all pids are analyzed to find streams
int raw_packet_size
raw packet size, including FEC if present
static const StreamType ISO_types[]
static int read_header(FFV1Context *f)
int ts_id
Transport stream id.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
FAKE codec to indicate a MPEG-4 Systems stream (only used by libavformat)
static av_unused int64_t mpegts_get_pcr(AVFormatContext *s, int stream_index, int64_t *ppos, int64_t pos_limit)
#define AV_LOG_INFO
Standard information.
#define TS_MAX_PACKET_SIZE
uint8_t * dec_config_descr
enum AVMediaType codec_type
#define MP4DecConfigDescrTag
static MpegTSFilter * mpegts_open_filter(MpegTSContext *ts, unsigned int pid, enum MpegTSFilterType type)
AVBufferRef * av_buffer_alloc(int size)
Allocate an AVBuffer of the given size using av_malloc().
AVIOContext * pb
I/O context.
static const StreamType METADATA_types[]
static int parse_mp4_descr_arr(MP4DescrParseContext *d, int64_t off, int len)
uint8_t * data
The data buffer.
static void new_pes_packet(PESContext *pes, AVPacket *pkt)
static int get_packet_size(const uint8_t *buf, int size)
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
#define STREAM_TYPE_PRIVATE_DATA
#define MAX_PES_HEADER_SIZE
static int get8(const uint8_t **pp, const uint8_t *p_end)
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
#define MAX_PIDS_PER_PROGRAM
static unsigned int get_bits1(GetBitContext *s)
static int parse_pcr(int64_t *ppcr_high, int *ppcr_low, const uint8_t *packet)
Describe the class of an AVClass context structure.
static void skip_bits(GetBitContext *s, int n)
static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len)
#define AV_OPT_FLAG_DECODING_PARAM
a generic parameter which can be set by the user for demuxing or decoding
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
static int analyze(const uint8_t *buf, int size, int packet_size, int *index, int probe)
int avpriv_mpegts_parse_packet(MpegTSContext *ts, AVPacket *pkt, const uint8_t *buf, int len)
refcounted data buffer API
static void mpegts_close_filter(MpegTSContext *ts, MpegTSFilter *filter)
static const StreamType DESC_types[]
This structure contains the data a format has to probe a file.
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
Return the next frame of a stream.
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
unsigned int end_of_section_reached
static void write_section_data(MpegTSContext *ts, 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 complet...
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 clear_programs(MpegTSContext *ts)
int ffio_ensure_seekback(AVIOContext *s, int64_t buf_size)
Ensures that the requested seekback buffer size will be available.
const AVCRC * av_crc_get_table(AVCRCId crc_id)
Get an initialized standard CRC table.
A reference to a data buffer.
static const AVOption options[]
static void pat_cb(MpegTSFilter *filter, const uint8_t *section, int section_len)
int ff_mp4_read_descr(AVFormatContext *fc, AVIOContext *pb, int *tag)
static void filter(MpegAudioContext *s, int ch, const short *samples, int incr)
static const AVClass mpegts_class
int pts_wrap_behavior
Options for behavior, when a wrap is detected.
int ffio_init_context(AVIOContext *s, unsigned char *buffer, int buffer_size, int write_flag, void *opaque, int(*read_packet)(void *opaque, uint8_t *buf, int buf_size), int(*write_packet)(void *opaque, uint8_t *buf, int buf_size), int64_t(*seek)(void *opaque, int64_t offset, int whence))
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base...
int disposition
AV_DISPOSITION_* bit field.
uint8_t header[MAX_PES_HEADER_SIZE]
static void reset_pes_packet_state(PESContext *pes)
void av_init_packet(AVPacket *pkt)
Initialize optional fields of a packet with default values.
int pmt_found
have we found pmt for this program
#define AV_PKT_FLAG_CORRUPT
The packet content is corrupted.
struct AVInputFormat * iformat
The input container format.
static int skip_identical(const SectionHeader *h, MpegTSSectionFilter *tssf)
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
static MpegTSFilter * mpegts_open_section_filter(MpegTSContext *ts, unsigned int pid, SectionCallback *section_cb, void *opaque, int check_crc)
FAKE codec to indicate a raw MPEG-2 TS stream (only used by libavformat)
static int get16(const uint8_t **pp, const uint8_t *p_end)
AVPacket * pkt
packet containing Audio/Video data
void * priv_data
Format private data.
int64_t last_pos
to detect seek
#define AV_OPT_FLAG_READONLY
The option may not be set through the AVOptions API, only read.
static void add_pid_to_pmt(MpegTSContext *ts, unsigned int programid, unsigned int pid)
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> out
void SetServiceCallback(void *opaque, int ret)
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
int bit_rate
Total stream bitrate in bit/s, 0 if not available.
int avio_feof(AVIOContext *s)
feof() equivalent for AVIOContext.
static MpegTSFilter * mpegts_open_pcr_filter(MpegTSContext *ts, unsigned int pid)
static int parse_MP4IODescrTag(MP4DescrParseContext *d, int64_t off, int len)
static void m4sl_cb(MpegTSFilter *filter, const uint8_t *section, int section_len)
#define MAX_MP4_DESCR_COUNT
#define MKTAG(a, b, c, d)
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
static void mpegts_find_stream_type(AVStream *st, uint32_t stream_type, const StreamType *types)
void avpriv_mpegts_parse_close(MpegTSContext *ts)
int request_probe
stream probing state -1 -> probing finished 0 -> no probing requested rest -> perform probing with re...
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
This structure stores compressed data.
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
static char * getstr8(const uint8_t **pp, const uint8_t *p_end)
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
A dummy ID pointing at the start of subtitle codecs.
#define AV_NOPTS_VALUE
Undefined timestamp value.
int fix_teletext_pts
fix dvb teletext pts
static int handle_packets(MpegTSContext *ts, int64_t nb_packets)
void SectionCallback(MpegTSFilter *f, const uint8_t *buf, int len)
AVStream * sub_st
stream for the embedded AC3 stream in HDMV TrueHD
static int mp4_read_iods(AVFormatContext *s, const uint8_t *buf, unsigned size, Mp4Descr *descr, int *descr_count, int max_descr_count)