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
166 #define MPEGTS_OPTIONS \
167 { "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 }
182 {.i64 = 0}, 0, 1, 0 },
184 {.i64 = 0}, 0, 1, 0 },
197 {
"compute_pcr",
"compute exact PCR for each transport stream packet",
200 {
"ts_packetsize",
"output option carrying the raw packet size",
225 #define PES_START_SIZE 6
226 #define PES_HEADER_SIZE 9
227 #define MAX_PES_HEADER_SIZE (9 + 255)
258 for (i = 0; i < ts->
nb_prg; i++) {
259 if (ts->
prg[i].
id == programid) {
286 for (i = 0; i < ts->
nb_prg; i++)
287 if (ts->
prg[i].
id == programid) {
324 for (i = 0; i < p->
nb_pids; i++)
325 if (p->
pids[i] == pid)
346 if (program->
id == programid) {
347 int old_pcr_pid = program->
pcr_pid,
352 if (old_version != -1 && old_version != version) {
354 "detected PMT change (program=%d, version=%d/%d, pcr_pid=0x%x/0x%x)\n",
355 programid, old_version, version, old_pcr_pid, pid);
373 int used = 0, discarded = 0;
384 for (i = 0; i < ts->
nb_prg; i++) {
386 for (j = 0; j < p->
nb_pids; j++) {
387 if (p->
pids[j] != pid)
401 return !used && discarded;
409 const uint8_t *
buf,
int buf_size,
int is_start)
435 len = (
AV_RB16(cur_section_buf + 1) & 0xfff) + 3;
573 memset(stat, 0, packet_size *
sizeof(*stat));
575 for (i = 0; i < size - 3; i++) {
576 if (buf[i] == 0x47) {
577 int pid =
AV_RB16(buf+1) & 0x1FFF;
578 int asc = buf[i + 3] & 0x30;
579 if (!probe || pid == 0x1FFF || asc) {
580 int x = i % packet_size;
583 if (stat[x] > best_score) {
584 best_score = stat[x];
590 return best_score -
FFMAX(stat_all - 10*best_score, 0)/10;
596 int score, fec_score, dvhs_score;
605 score, dvhs_score, fec_score);
607 if (score > fec_score && score > dvhs_score)
609 else if (dvhs_score > score && dvhs_score > fec_score)
611 else if (score < fec_score && dvhs_score < fec_score)
671 len =
get8(&p, p_end);
691 val =
get8(pp, p_end);
696 val =
get16(pp, p_end);
700 val =
get8(pp, p_end);
703 h->
version = (val >> 1) & 0x1f;
704 val =
get8(pp, p_end);
708 val =
get8(pp, p_end);
730 #if !CONFIG_LOAS_DEMUXER
805 uint32_t stream_type,
822 uint32_t stream_type, uint32_t prog_reg_desc)
842 "stream=%d stream_type=%x pid=%x prog_reg_desc=%.4s\n",
850 if ((prog_reg_desc ==
AV_RL32(
"HDMV") ||
851 prog_reg_desc ==
AV_RL32(
"HDPR")) &&
862 memcpy(sub_pes, pes,
sizeof(*sub_pes));
870 sub_st->
id = pes->
pid;
970 int au_start_flag = 0, au_end_flag = 0, ocr_flag = 0, idle_flag = 0;
971 int padding_flag = 0, padding_bits = 0, inst_bitrate_flag = 0;
972 int dts_flag = -1, cts_flag = -1;
977 memcpy(buf_padded, buf, buf_padded_size);
986 au_start_flag = au_end_flag = 1;
996 if (!idle_flag && (!padding_flag || padding_bits != 0)) {
1004 if (au_start_flag) {
1022 if (inst_bitrate_flag)
1039 const uint8_t *
buf,
int buf_size,
int is_start,
1063 while (buf_size > 0) {
1064 switch (pes->
state) {
1076 if (pes->
header[0] == 0x00 && pes->
header[1] == 0x00 &&
1077 pes->
header[2] == 0x01) {
1079 code = pes->
header[3] | 0x100;
1116 if (code != 0x1bc && code != 0x1bf &&
1117 code != 0x1f0 && code != 0x1f1 &&
1118 code != 0x1ff && code != 0x1f2 &&
1123 "pid=%x stream_type=%x probing\n",
1171 unsigned int flags, pes_ext, skip;
1177 if ((flags & 0xc0) == 0x80) {
1180 }
else if ((flags & 0xc0) == 0xc0) {
1190 skip = (pes_ext >> 4) & 0xb;
1193 if ((pes_ext & 0x41) == 0x01 &&
1196 if ((r[0] & 0x7f) > 0 && (r[1] & 0x80) == 0)
1208 p += sl_header_bytes;
1209 buf_size -= sl_header_bytes;
1248 pes->
pts = pes->
dts = pcr;
1250 pes->
dts > pcr + 3654 + 9000) {
1251 pes->
pts = pes->
dts = pcr + 3654 + 9000;
1253 pes->
dts > pcr + 10*90000) {
1254 pes->
pts = pes->
dts = pcr + 3654 + 9000;
1347 Mp4Descr *descr,
int max_descr_count)
1350 if (size > (1 << 30))
1370 (*len) -= new_off - *off;
1406 if (!(id_flags & 0x0020)) {
1456 #define R8_CHECK_CLIP_MAX(dst, maxv) do { \
1457 descr->sl.dst = avio_r8(&d->pb); \
1458 if (descr->sl.dst > maxv) { \
1459 descr->sl.dst = maxv; \
1460 return AVERROR_INVALIDDATA; \
1499 if (len < 0 || len1 > len || len1 <= 0) {
1501 "Tag %x length violation new length %d bytes remaining %d\n",
1512 if (target_tag && tag != target_tag) {
1545 Mp4Descr *descr,
int *descr_count,
int max_descr_count)
1561 Mp4Descr *descr,
int *descr_count,
int max_descr_count)
1584 int mp4_descr_count = 0;
1589 p_end = section + section_len - 4;
1598 mp4_read_od(s, p, (
unsigned) (p_end - p), mp4_descr, &mp4_descr_count,
1604 for (i = 0; i < mp4_descr_count; i++) {
1618 pes->
sl = mp4_descr[i].
sl;
1621 mp4_descr[i].dec_config_descr_len, 0,
1635 for (i = 0; i < mp4_descr_count; i++)
1636 av_free(mp4_descr[i].dec_config_descr);
1662 1, 0, 1, 1, 2, 2, 2, 3, 3
1666 1, 1, 1, 2, 2, 3, 4, 4, 5,
1677 { 0,6,1,2,3,4,5,7 },
1682 Mp4Descr *mp4_descr,
int mp4_descr_count,
int pid,
1686 int desc_len, desc_tag, desc_es_id, ext_desc_tag,
channels, channel_config_code;
1690 desc_tag =
get8(pp, desc_list_end);
1693 desc_len =
get8(pp, desc_list_end);
1696 desc_end = *pp + desc_len;
1697 if (desc_end > desc_list_end)
1708 if (
get8(pp, desc_end) & 0x1) {
1713 desc_es_id =
get16(pp, desc_end);
1716 if (ts && ts->
pids[pid])
1718 for (i = 0; i < mp4_descr_count; i++)
1719 if (mp4_descr[i].dec_config_descr_len &&
1720 mp4_descr[i].es_id == desc_es_id) {
1723 mp4_descr[i].dec_config_descr_len, 0,
1736 if (
get16(pp, desc_end) < 0)
1738 if (mp4_descr_count > 0 &&
1759 int language_count = desc_len / 5;
1761 if (desc_len > 0 && desc_len % 5 != 0)
1764 if (language_count > 0) {
1766 av_assert0(language_count <=
sizeof(language) / 4);
1779 for (i = 0; i < language_count; i++) {
1780 language[i * 4 + 0] =
get8(pp, desc_end);
1781 language[i * 4 + 1] =
get8(pp, desc_end);
1782 language[i * 4 + 2] =
get8(pp, desc_end);
1783 language[i * 4 + 3] =
',';
1785 memcpy(extradata, *pp, 2);
1791 language[i * 4 - 1] = 0;
1804 int language_count = desc_len / 8;
1806 if (desc_len > 0 && desc_len % 8 != 0)
1809 if (language_count > 1) {
1813 if (language_count > 0) {
1817 av_assert0(language_count <=
sizeof(language) / 4);
1830 for (i = 0; i < language_count; i++) {
1831 language[i * 4 + 0] =
get8(pp, desc_end);
1832 language[i * 4 + 1] =
get8(pp, desc_end);
1833 language[i * 4 + 2] =
get8(pp, desc_end);
1834 language[i * 4 + 3] =
',';
1848 extradata[4] =
get8(pp, desc_end);
1849 memcpy(extradata, *pp, 4);
1855 language[i * 4 - 1] = 0;
1862 for (i = 0; i + 4 <= desc_len; i += 4) {
1863 language[i + 0] =
get8(pp, desc_end);
1864 language[i + 1] =
get8(pp, desc_end);
1865 language[i + 2] =
get8(pp, desc_end);
1866 language[i + 3] =
',';
1867 switch (
get8(pp, desc_end)) {
1880 if (i && language[0]) {
1881 language[i - 1] = 0;
1900 if (
get16(pp, desc_end) == 0xFFFF)
1902 if (
get8(pp, desc_end) == 0xFF) {
1909 ext_desc_tag =
get8(pp, desc_end);
1910 if (ext_desc_tag < 0)
1913 ext_desc_tag == 0x80) {
1923 channel_config_code =
get8(pp, desc_end);
1924 if (channel_config_code < 0)
1926 if (channel_config_code <= 0x8) {
1927 st->
codecpar->
extradata[9] = channels = channel_config_code ? channel_config_code : 2;
1939 if (ext_desc_tag == 0x06) {
1944 flags =
get8(pp, desc_end);
1946 if ((flags & 0x80) == 0)
1949 switch ((flags >> 2) & 0x1F) {
1965 language[0] =
get8(pp, desc_end);
1966 language[1] =
get8(pp, desc_end);
1967 language[2] =
get8(pp, desc_end);
1979 int component_type_flag =
get8(pp, desc_end) & (1 << 7);
1980 if (component_type_flag) {
1981 int component_type =
get8(pp, desc_end);
1982 int service_type_mask = 0x38;
1983 int service_type = ((component_type & service_type_mask) >> 3);
1984 if (service_type == 0x02 ) {
1993 int component_type_flag =
get8(pp, desc_end) & (1 << 7);
1994 if (component_type_flag) {
1995 int component_type =
get8(pp, desc_end);
1996 int service_type_mask = 0x38;
1997 int service_type = ((component_type & service_type_mask) >> 3);
1998 if (service_type == 0x02 ) {
2013 int stream_identifier,
int pmt_stream_idx)
2021 if (stream_identifier != -1) {
2034 "re-using existing %s stream %d (pid=0x%x) for new pid=0x%x\n",
2048 int desc_len, desc_tag;
2050 desc_list_len =
get16(pp, p_end);
2051 if (desc_list_len < 0)
2053 desc_list_len &= 0xfff;
2054 desc_list_end = p + desc_list_len;
2055 if (desc_list_end > p_end)
2059 desc_tag =
get8(pp, desc_list_end);
2062 desc_len =
get8(pp, desc_list_end);
2065 desc_end = *pp + desc_len;
2066 if (desc_end > desc_list_end)
2069 if (desc_tag == 0x52) {
2070 return get8(pp, desc_end);
2080 return !(stream_type == 0x13 ||
2081 (stream_type == 0x86 && prog_reg_desc ==
AV_RL32(
"CUEI")) );
2091 const uint8_t *p, *p_end, *desc_list_end;
2092 int program_info_length, pcr_pid, pid, stream_type;
2094 uint32_t prog_reg_desc = 0;
2095 int stream_identifier = -1;
2097 int mp4_descr_count = 0;
2104 p_end = section + section_len - 4;
2124 pcr_pid =
get16(&p, p_end);
2133 program_info_length =
get16(&p, p_end);
2134 if (program_info_length < 0)
2136 program_info_length &= 0xfff;
2137 while (program_info_length >= 2) {
2139 tag =
get8(&p, p_end);
2140 len =
get8(&p, p_end);
2144 if (len > program_info_length - 2)
2147 program_info_length -= len + 2;
2154 }
else if (tag == 0x05 && len >= 4) {
2155 prog_reg_desc = bytestream_get_le32(&p);
2160 p += program_info_length;
2171 for (i = 0; ; i++) {
2174 stream_type =
get8(&p, p_end);
2175 if (stream_type < 0)
2177 pid =
get16(&p, p_end);
2220 if (pes && !pes->
st) {
2246 if (stream_type == 0x86 && prog_reg_desc ==
AV_RL32(
"CUEI")) {
2263 desc_list_len =
get16(&p, p_end);
2264 if (desc_list_len < 0)
2266 desc_list_len &= 0xfff;
2267 desc_list_end = p + desc_list_len;
2268 if (desc_list_end > p_end)
2272 desc_list_end, mp4_descr,
2273 mp4_descr_count, pid, ts) < 0)
2276 if (pes && prog_reg_desc ==
AV_RL32(
"HDMV") &&
2277 stream_type == 0x83 && pes->
sub_st) {
2286 if (!ts->
pids[pcr_pid])
2290 for (i = 0; i < mp4_descr_count; i++)
2291 av_free(mp4_descr[i].dec_config_descr);
2306 p_end = section + section_len - 4;
2321 sid =
get16(&p, p_end);
2324 pmt_pid =
get16(&p, p_end);
2334 if (sid == 0x0000) {
2345 || fil->
pid != pmt_pid
2349 if (!ts->
pids[pmt_pid])
2360 for (i = 0; i < ts->
nb_prg; i++)
2374 const uint8_t *p, *p_end, *desc_list_end, *desc_end;
2375 int onid,
val, sid, desc_list_len, desc_tag, desc_len, service_type;
2376 char *
name, *provider_name;
2381 p_end = section + section_len - 4;
2392 onid =
get16(&p, p_end);
2395 val =
get8(&p, p_end);
2399 sid =
get16(&p, p_end);
2402 val =
get8(&p, p_end);
2405 desc_list_len =
get16(&p, p_end);
2406 if (desc_list_len < 0)
2408 desc_list_len &= 0xfff;
2409 desc_list_end = p + desc_list_len;
2410 if (desc_list_end > p_end)
2413 desc_tag =
get8(&p, desc_list_end);
2416 desc_len =
get8(&p, desc_list_end);
2417 desc_end = p + desc_len;
2418 if (desc_len < 0 || desc_end > desc_list_end)
2422 desc_tag, desc_len);
2426 service_type =
get8(&p, p_end);
2427 if (service_type < 0)
2429 provider_name =
getstr8(&p, p_end);
2453 static int parse_pcr(int64_t *ppcr_high,
int *ppcr_low,
2460 int len, pid, cc, expected_cc, cc_ok, afc, is_start, is_discontinuity,
2461 has_adaptation, has_payload;
2465 pid =
AV_RB16(packet + 1) & 0x1fff;
2468 is_start = packet[1] & 0x40;
2469 tss = ts->
pids[pid];
2472 tss = ts->
pids[pid];
2478 afc = (packet[3] >> 4) & 3;
2481 has_adaptation = afc & 2;
2482 has_payload = afc & 1;
2483 is_discontinuity = has_adaptation &&
2488 cc = (packet[3] & 0xf);
2489 expected_cc = has_payload ? (tss->
last_cc + 1) & 0x0f : tss->
last_cc;
2490 cc_ok = pid == 0x1FFF ||
2498 "Continuity check failed for pid %d expected %d got %d\n",
2499 pid, expected_cc, cc);
2506 if (packet[1] & 0x80) {
2515 if (has_adaptation) {
2518 if (
parse_pcr(&pcr_h, &pcr_l, packet) == 0)
2519 tss->
last_pcr = pcr_h * 300 + pcr_l;
2525 if (p >= p_end || !has_payload)
2538 if (len > p_end - p)
2564 for (i = 0; i < ts->
nb_prg; i++) {
2640 if (current_packet[0] == 0x80 && current_packet[12] == 0x47) {
2656 "max resync size reached, could not find sync byte\n");
2673 if ((*data)[0] != 0x47) {
2728 if (nb_packets != 0 && packet_num >= nb_packets ||
2755 #define CHECK_COUNT 10
2756 #define CHECK_BLOCK 100
2766 score =
FFMAX3(score, dvhs_score, fec_score);
2768 maxscore =
FFMAX(maxscore, score);
2774 ff_dlog(0,
"TS score: %d %d\n", sumscore, maxscore);
2778 }
else if (check_count >=
CHECK_COUNT && sumscore > 6) {
2780 }
else if (check_count >=
CHECK_COUNT && maxscore > 6) {
2782 }
else if (sumscore > 6) {
2797 afc = (packet[3] >> 4) & 3;
2807 if (!(flags & 0x10))
2812 *ppcr_high = ((int64_t) v << 1) | (p[4] >> 7);
2813 *ppcr_low = ((p[4] & 1) << 8) | p[5];
2850 if (s->
iformat == &ff_mpegts_demuxer) {
2870 int pcr_pid, pid, nb_packets, nb_pcrs, ret, pcr_l;
2871 int64_t pcrs[2], pcr_h;
2872 int packet_count[2];
2893 pid =
AV_RB16(data + 1) & 0x1fff;
2894 if ((pcr_pid == -1 || pcr_pid == pid) &&
2898 packet_count[nb_pcrs] = nb_packets;
2899 pcrs[nb_pcrs] = pcr_h * 300 + pcr_l;
2902 if (pcrs[1] - pcrs[0] > 0) {
2908 packet_count[0] = packet_count[1];
2920 ts->
pcr_incr = (pcrs[1] - pcrs[0]) / (packet_count[1] - packet_count[0]);
2933 #define MAX_PACKET_READAHEAD ((128 * 1024) / 188)
2939 int64_t pcr_h, next_pcr_h, pos;
2940 int pcr_l, next_pcr_l;
2952 if (data != pkt->
data)
2963 if (
parse_pcr(&next_pcr_h, &next_pcr_l, pcr_buf) == 0) {
2966 ((next_pcr_h - pcr_h) * 300 + (next_pcr_l - pcr_l)) /
2973 ts->
cur_pcr = pcr_h * 300 + pcr_l;
3008 if (!ret && pkt->
size < 0)
3032 int64_t *ppos, int64_t pos_limit)
3035 int64_t pos, timestamp;
3037 int pcr_l, pcr_pid =
3043 while(pos < pos_limit) {
3048 if (buf[0] != 0x47) {
3054 if ((pcr_pid < 0 || (
AV_RB16(buf + 1) & 0x1fff) == pcr_pid) &&
3055 parse_pcr(×tamp, &pcr_l, buf) == 0) {
3066 int64_t *ppos, int64_t pos_limit)
3075 while(pos < pos_limit) {
3086 int64_t dts = pkt.
dts;
3132 if (buf[0] != 0x47) {
3162 .priv_class = &mpegts_class,
3166 .
name =
"mpegtsraw",
3174 .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...
union MpegTSFilter::@260 u
void ff_mp4_parse_es_descr(AVIOContext *pb, int *es_id)
static void finished_reading_packet(AVFormatContext *s, int raw_packet_size)
ptrdiff_t const GLvoid * data
int64_t cur_pcr
used to estimate the exact PCR
#define AV_OPT_FLAG_EXPORT
The option is intended 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)
#define AV_DICT_DONT_OVERWRITE
Don't overwrite existing entries.
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
static int mpegts_probe(AVProbeData *p)
int8_t crc_validity[NB_PID_MAX]
int probe_packets
Number of packets to buffer for codec probing.
MpegTSContext * avpriv_mpegts_parse_open(AVFormatContext *s)
static int analyze(const uint8_t *buf, int size, int packet_size, int probe)
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
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.
const char * av_default_item_name(void *ptr)
Return the context name.
AVFormatInternal * internal
An opaque field for libavformat internal usage.
int64_t bit_rate
Total stream bitrate in bit/s, 0 if not available.
Contain timestamp estimated through PCR of program stream.
AVInputFormat ff_mpegts_demuxer
static void sdt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len)
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
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
static int mpegts_resync(AVFormatContext *s, int seekback, const uint8_t *current_packet)
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.
static void filter(int16_t *output, ptrdiff_t out_stride, int16_t *low, ptrdiff_t low_stride, int16_t *high, ptrdiff_t high_stride, int len, int clip)
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 ...
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
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[]
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.
Public header for CRC hash function implementation.
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)
#define AV_LOG_VERBOSE
Detailed information.
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)
unsigned int * stream_index
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
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)
MPEGTS stream ID, this is required to pass the stream ID information from the demuxer to the correspo...
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.
#define fc(width, name, range_min, range_max)
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)
AVCodecID
Identify the syntax and semantics of the bitstream.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static const StreamType SCTE_types[]
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
enum AVMediaType codec_type
General type of the encoded data.
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().
enum AVMediaType avcodec_get_type(enum AVCodecID codec_id)
Get the type of the given codec.
#define TS_FEC_PACKET_SIZE
static const uint8_t offset[127][2]
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 extradata_size
Size of the extradata content in bytes.
int avio_r8(AVIOContext *s)
int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
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.
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
int64_t ts_packet_pos
position of first TS packet of this PES packet
SectionCallback * section_cb
static const StreamType REGD_types[]
void av_program_add_stream_index(AVFormatContext *ac, int progid, unsigned int idx)
int PESCallback(MpegTSFilter *f, const uint8_t *buf, int len, int is_start, int64_t pos)
static const StreamType MISC_types[]
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
static int parse_stream_identifier_desc(const uint8_t *p, const uint8_t *p_end)
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]
int program_num
Details of the MPEG-TS program which created this stream.
static uint64_t get_ts64(GetBitContext *gb, int bits)
preferred ID for MPEG-1/2 video decoding
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 AVStream * find_matching_stream(MpegTSContext *ts, int pid, int stream_identifier, int pmt_stream_idx)
static int read_header(FFV1Context *f)
int ts_id
Transport stream id.
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 AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
#define AV_LOG_INFO
Standard information.
#define TS_MAX_PACKET_SIZE
uint8_t * dec_config_descr
AVStreamInternal * internal
An opaque field for libavformat internal usage.
#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)
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
static int new_pes_packet(PESContext *pes, AVPacket *pkt)
uint8_t * data
The data buffer.
static int get_packet_size(const uint8_t *buf, int size)
#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.
int need_context_update
Whether the internal avctx needs to be updated from codecpar (after a late change to codecpar) ...
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.
const char * av_get_media_type_string(enum AVMediaType media_type)
Return a string describing the media_type enum, NULL if media_type is unknown.
#define flags(name, subs,...)
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 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)
static int is_pes_stream(int stream_type, uint32_t prog_reg_desc)
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 * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
AVCodecContext * avctx
The codec context used by avformat_find_stream_info, the parser, etc.
void SetServiceCallback(void *opaque, int ret)
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
AVCodecParameters * codecpar
Codec parameters associated with this stream.
int avio_feof(AVIOContext *s)
feof() equivalent for AVIOContext.
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
static MpegTSFilter * mpegts_open_pcr_filter(MpegTSContext *ts, unsigned int pid)
static void scte_data_cb(MpegTSFilter *filter, const uint8_t *section, int section_len)
static int parse_MP4IODescrTag(MP4DescrParseContext *d, int64_t off, int len)
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, int size)
Allocate new information of a packet.
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.
#define R8_CHECK_CLIP_MAX(dst, maxv)
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...
static void update_av_program_info(AVFormatContext *s, unsigned int programid, unsigned int pid, int version)
static void new_data_packet(const uint8_t *buffer, int len, AVPacket *pkt)
#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)