46 #define MAX_RESYNC_SIZE 65536 48 #define MAX_PES_PAYLOAD 200 * 1024 50 #define MAX_MP4_DESCR_COUNT 16 52 #define MOD_UNLIKELY(modulus, dividend, divisor, prev_dividend) \ 54 if ((prev_dividend) == 0 || (dividend) - (prev_dividend) != (divisor)) \ 55 (modulus) = (dividend) % (divisor); \ 56 (prev_dividend) = (dividend); \ 59 #define PROBE_PACKET_MAX_BUF 8192 60 #define PROBE_PACKET_MARGIN 5 71 int is_start, int64_t pos);
108 #define MAX_PIDS_PER_PROGRAM 64 127 #define SIZE_STAT_THRESHOLD 10 173 #define MPEGTS_OPTIONS \ 174 { "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 } 189 {.i64 = 0}, 0, 1, 0 },
191 {.i64 = 0}, 0, 1, 0 },
204 {
"compute_pcr",
"compute exact PCR for each transport stream packet",
207 {
"ts_packetsize",
"output option carrying the raw packet size",
232 #define PES_START_SIZE 6 233 #define PES_HEADER_SIZE 9 234 #define MAX_PES_HEADER_SIZE (9 + 255) 265 for (i = 0; i < ts->
nb_prg; i++) {
266 if (ts->
prg[i].
id == programid) {
293 for (i = 0; i < ts->
nb_prg; i++)
294 if (ts->
prg[i].
id == programid) {
331 for (i = 0; i < p->
nb_pids; i++)
332 if (p->
pids[i] == pid)
353 if (program->
id == programid) {
354 int old_pcr_pid = program->
pcr_pid,
359 if (old_version != -1 && old_version != version) {
361 "detected PMT change (program=%d, version=%d/%d, pcr_pid=0x%x/0x%x)\n",
362 programid, old_version, version, old_pcr_pid, pid);
380 int used = 0, discarded = 0;
391 for (i = 0; i < ts->
nb_prg; i++) {
393 for (j = 0; j < p->
nb_pids; j++) {
394 if (p->
pids[j] != pid)
408 return !used && discarded;
416 const uint8_t *
buf,
int buf_size,
int is_start)
442 len = (
AV_RB16(cur_section_buf + 1) & 0xfff) + 3;
580 memset(stat, 0, packet_size *
sizeof(*stat));
582 for (i = 0; i < size - 3; i++) {
583 if (buf[i] == 0x47) {
584 int pid =
AV_RB16(buf+1) & 0x1FFF;
585 int asc = buf[i + 3] & 0x30;
586 if (!probe || pid == 0x1FFF || asc) {
587 int x = i % packet_size;
590 if (stat[x] > best_score) {
591 best_score = stat[x];
597 return best_score -
FFMAX(stat_all - 10*best_score, 0)/10;
603 int score, fec_score, dvhs_score;
621 buf_size, score, dvhs_score, fec_score);
623 margin =
mid_pred(score, fec_score, dvhs_score);
630 else if (dvhs_score > margin)
632 else if (fec_score > margin)
692 len =
get8(&p, p_end);
699 const char *encodings[] = {
700 "ISO6937",
"ISO-8859-5",
"ISO-8859-6",
"ISO-8859-7",
701 "ISO-8859-8",
"ISO-8859-9",
"ISO-8859-10",
"ISO-8859-11",
702 "",
"ISO-8859-13",
"ISO-8859-14",
"ISO-8859-15",
"",
"",
"",
"",
703 "",
"UCS-2BE",
"KSC_5601",
"GB2312",
"UCS-2BE",
"UTF-8",
"",
"",
704 "",
"",
"",
"",
"",
"",
"",
"" 708 size_t inlen =
len, outlen = inlen * 6 + 1;
709 if (len >= 3 && p[0] == 0x10 && !p[1] && p[2] && p[2] <= 0
xf && p[2] != 0xc) {
711 snprintf(iso8859,
sizeof(iso8859),
"ISO-8859-%d", p[2]);
714 cd = iconv_open(
"UTF-8", iso8859);
715 }
else if (p[0] < 0x20) {
718 cd = iconv_open(
"UTF-8", encodings[*p]);
721 cd = iconv_open(
"UTF-8", encodings[0]);
723 if (cd == (iconv_t)-1)
730 if (iconv(cd, &in, &inlen, &out, &outlen) == -1) {
757 val =
get8(pp, p_end);
762 val =
get16(pp, p_end);
766 val =
get8(pp, p_end);
769 h->
version = (val >> 1) & 0x1f;
770 val =
get8(pp, p_end);
774 val =
get8(pp, p_end);
796 #if !CONFIG_LOAS_DEMUXER 871 uint32_t stream_type,
888 uint32_t stream_type, uint32_t prog_reg_desc)
908 "stream=%d stream_type=%x pid=%x prog_reg_desc=%.4s\n",
916 if ((prog_reg_desc ==
AV_RL32(
"HDMV") ||
917 prog_reg_desc ==
AV_RL32(
"HDPR")) &&
928 memcpy(sub_pes, pes,
sizeof(*sub_pes));
936 sub_st->
id = pes->
pid;
1036 int au_start_flag = 0, au_end_flag = 0, ocr_flag = 0, idle_flag = 0;
1037 int padding_flag = 0, padding_bits = 0, inst_bitrate_flag = 0;
1038 int dts_flag = -1, cts_flag = -1;
1043 memcpy(buf_padded, buf, buf_padded_size);
1052 au_start_flag = au_end_flag = 1;
1062 if (!idle_flag && (!padding_flag || padding_bits != 0)) {
1070 if (au_start_flag) {
1088 if (inst_bitrate_flag)
1105 const uint8_t *
buf,
int buf_size,
int is_start,
1129 while (buf_size > 0) {
1130 switch (pes->
state) {
1142 if (pes->
header[0] == 0x00 && pes->
header[1] == 0x00 &&
1143 pes->
header[2] == 0x01) {
1145 code = pes->
header[3] | 0x100;
1182 if (code != 0x1bc && code != 0x1bf &&
1183 code != 0x1f0 && code != 0x1f1 &&
1184 code != 0x1ff && code != 0x1f2 &&
1189 "pid=%x stream_type=%x probing\n",
1237 unsigned int flags, pes_ext, skip;
1243 if ((flags & 0xc0) == 0x80) {
1246 }
else if ((flags & 0xc0) == 0xc0) {
1256 skip = (pes_ext >> 4) & 0xb;
1259 if ((pes_ext & 0x41) == 0x01 &&
1262 if ((r[0] & 0x7f) > 0 && (r[1] & 0x80) == 0)
1274 p += sl_header_bytes;
1275 buf_size -= sl_header_bytes;
1318 pes->
pts = pes->
dts = pcr;
1320 pes->
dts > pcr + 3654 + 9000) {
1321 pes->
pts = pes->
dts = pcr + 3654 + 9000;
1323 pes->
dts > pcr + 10*90000) {
1324 pes->
pts = pes->
dts = pcr + 3654 + 9000;
1334 "Forcing DTS/PTS to be unset for a " 1335 "non-trustworthy PES packet for PID %d as " 1336 "PCR hasn't been received yet.\n",
1426 Mp4Descr *descr,
int max_descr_count)
1429 if (size > (1 << 30))
1449 (*len) -= new_off - *off;
1485 if (!(id_flags & 0x0020)) {
1535 #define R8_CHECK_CLIP_MAX(dst, maxv) do { \ 1536 descr->sl.dst = avio_r8(&d->pb); \ 1537 if (descr->sl.dst > maxv) { \ 1538 descr->sl.dst = maxv; \ 1539 return AVERROR_INVALIDDATA; \ 1578 if (len < 0 || len1 > len || len1 <= 0) {
1580 "Tag %x length violation new length %d bytes remaining %d\n",
1591 if (target_tag && tag != target_tag) {
1624 Mp4Descr *descr,
int *descr_count,
int max_descr_count)
1640 Mp4Descr *descr,
int *descr_count,
int max_descr_count)
1663 int mp4_descr_count = 0;
1668 p_end = section + section_len - 4;
1677 mp4_read_od(s, p, (
unsigned) (p_end - p), mp4_descr, &mp4_descr_count,
1683 for (i = 0; i < mp4_descr_count; i++) {
1697 pes->
sl = mp4_descr[
i].
sl;
1700 mp4_descr[i].dec_config_descr_len, 0,
1714 for (i = 0; i < mp4_descr_count; i++)
1715 av_free(mp4_descr[i].dec_config_descr);
1748 1, 0, 1, 1, 2, 2, 2, 3, 3
1752 1, 1, 1, 2, 2, 3, 4, 4, 5,
1763 { 0,6,1,2,3,4,5,7 },
1768 Mp4Descr *mp4_descr,
int mp4_descr_count,
int pid,
1772 int desc_len, desc_tag, desc_es_id, ext_desc_tag,
channels, channel_config_code;
1776 desc_tag =
get8(pp, desc_list_end);
1779 desc_len =
get8(pp, desc_list_end);
1782 desc_end = *pp + desc_len;
1783 if (desc_end > desc_list_end)
1794 if (
get8(pp, desc_end) & 0x1) {
1799 desc_es_id =
get16(pp, desc_end);
1802 if (ts && ts->
pids[pid])
1804 for (i = 0; i < mp4_descr_count; i++)
1805 if (mp4_descr[i].dec_config_descr_len &&
1806 mp4_descr[i].es_id == desc_es_id) {
1809 mp4_descr[i].dec_config_descr_len, 0,
1822 if (
get16(pp, desc_end) < 0)
1824 if (mp4_descr_count > 0 &&
1845 int language_count = desc_len / 5;
1847 if (desc_len > 0 && desc_len % 5 != 0)
1850 if (language_count > 0) {
1852 av_assert0(language_count <=
sizeof(language) / 4);
1865 for (i = 0; i < language_count; i++) {
1866 language[i * 4 + 0] =
get8(pp, desc_end);
1867 language[i * 4 + 1] =
get8(pp, desc_end);
1868 language[i * 4 + 2] =
get8(pp, desc_end);
1869 language[i * 4 + 3] =
',';
1871 memcpy(extradata, *pp, 2);
1877 language[i * 4 - 1] = 0;
1890 int language_count = desc_len / 8;
1892 if (desc_len > 0 && desc_len % 8 != 0)
1895 if (language_count > 1) {
1899 if (language_count > 0) {
1903 av_assert0(language_count <=
sizeof(language) / 4);
1916 for (i = 0; i < language_count; i++) {
1917 language[i * 4 + 0] =
get8(pp, desc_end);
1918 language[i * 4 + 1] =
get8(pp, desc_end);
1919 language[i * 4 + 2] =
get8(pp, desc_end);
1920 language[i * 4 + 3] =
',';
1934 extradata[4] =
get8(pp, desc_end);
1935 memcpy(extradata, *pp, 4);
1941 language[i * 4 - 1] = 0;
1948 for (i = 0; i + 4 <= desc_len; i += 4) {
1949 language[i + 0] =
get8(pp, desc_end);
1950 language[i + 1] =
get8(pp, desc_end);
1951 language[i + 2] =
get8(pp, desc_end);
1952 language[i + 3] =
',';
1953 switch (
get8(pp, desc_end)) {
1966 if (i && language[0]) {
1967 language[i - 1] = 0;
1986 if (
get16(pp, desc_end) == 0xFFFF)
1988 if (
get8(pp, desc_end) == 0xFF) {
1995 ext_desc_tag =
get8(pp, desc_end);
1996 if (ext_desc_tag < 0)
1999 ext_desc_tag == 0x80) {
2009 channel_config_code =
get8(pp, desc_end);
2010 if (channel_config_code < 0)
2012 if (channel_config_code <= 0x8) {
2013 st->
codecpar->
extradata[9] = channels = channel_config_code ? channel_config_code : 2;
2025 if (ext_desc_tag == 0x06) {
2030 flags =
get8(pp, desc_end);
2032 if ((flags & 0x80) == 0)
2035 switch ((flags >> 2) & 0x1F) {
2051 language[0] =
get8(pp, desc_end);
2052 language[1] =
get8(pp, desc_end);
2053 language[2] =
get8(pp, desc_end);
2065 int component_type_flag =
get8(pp, desc_end) & (1 << 7);
2066 if (component_type_flag) {
2067 int component_type =
get8(pp, desc_end);
2068 int service_type_mask = 0x38;
2069 int service_type = ((component_type & service_type_mask) >> 3);
2070 if (service_type == 0x02 ) {
2079 int component_type_flag =
get8(pp, desc_end) & (1 << 7);
2080 if (component_type_flag) {
2081 int component_type =
get8(pp, desc_end);
2082 int service_type_mask = 0x38;
2083 int service_type = ((component_type & service_type_mask) >> 3);
2084 if (service_type == 0x02 ) {
2102 int data_component_id =
get16(pp, desc_end);
2103 if (data_component_id < 0)
2106 switch (data_component_id) {
2110 if (actual_component_tag >= 0x30 &&
2111 actual_component_tag <= 0x37) {
2118 if (actual_component_tag == 0x87) {
2143 int stream_identifier,
int pmt_stream_idx)
2153 if (stream_identifier != -1) {
2166 "re-using existing %s stream %d (pid=0x%x) for new pid=0x%x\n",
2180 int desc_len, desc_tag;
2182 desc_list_len =
get16(pp, p_end);
2183 if (desc_list_len < 0)
2185 desc_list_len &= 0xfff;
2186 desc_list_end = p + desc_list_len;
2187 if (desc_list_end > p_end)
2191 desc_tag =
get8(pp, desc_list_end);
2194 desc_len =
get8(pp, desc_list_end);
2197 desc_end = *pp + desc_len;
2198 if (desc_end > desc_list_end)
2201 if (desc_tag == 0x52) {
2202 return get8(pp, desc_end);
2212 return !(stream_type == 0x13 ||
2213 (stream_type == 0x86 && prog_reg_desc ==
AV_RL32(
"CUEI")) );
2223 const uint8_t *p, *p_end, *desc_list_end;
2224 int program_info_length, pcr_pid, pid, stream_type;
2226 uint32_t prog_reg_desc = 0;
2227 int stream_identifier = -1;
2229 int mp4_descr_count = 0;
2236 p_end = section + section_len - 4;
2256 pcr_pid =
get16(&p, p_end);
2265 program_info_length =
get16(&p, p_end);
2266 if (program_info_length < 0)
2268 program_info_length &= 0xfff;
2269 while (program_info_length >= 2) {
2271 tag =
get8(&p, p_end);
2272 len =
get8(&p, p_end);
2276 if (len > program_info_length - 2)
2279 program_info_length -= len + 2;
2286 }
else if (tag == 0x05 && len >= 4) {
2287 prog_reg_desc = bytestream_get_le32(&p);
2292 p += program_info_length;
2303 for (i = 0; ; i++) {
2306 stream_type =
get8(&p, p_end);
2307 if (stream_type < 0)
2309 pid =
get16(&p, p_end);
2352 if (pes && !pes->
st) {
2378 if (stream_type == 0x86 && prog_reg_desc ==
AV_RL32(
"CUEI")) {
2395 desc_list_len =
get16(&p, p_end);
2396 if (desc_list_len < 0)
2398 desc_list_len &= 0xfff;
2399 desc_list_end = p + desc_list_len;
2400 if (desc_list_end > p_end)
2404 desc_list_end, mp4_descr,
2405 mp4_descr_count, pid, ts) < 0)
2408 if (pes && prog_reg_desc ==
AV_RL32(
"HDMV") &&
2409 stream_type == 0x83 && pes->
sub_st) {
2418 if (!ts->
pids[pcr_pid])
2422 for (i = 0; i < mp4_descr_count; i++)
2423 av_free(mp4_descr[i].dec_config_descr);
2438 p_end = section + section_len - 4;
2453 sid =
get16(&p, p_end);
2456 pmt_pid =
get16(&p, p_end);
2466 if (sid == 0x0000) {
2477 || fil->
pid != pmt_pid
2481 if (!ts->
pids[pmt_pid])
2492 for (i = 0; i < ts->
nb_prg; i++)
2506 const uint8_t *p, *p_end, *desc_list_end, *desc_end;
2507 int onid,
val, sid, desc_list_len, desc_tag, desc_len, service_type;
2508 char *
name, *provider_name;
2513 p_end = section + section_len - 4;
2524 onid =
get16(&p, p_end);
2527 val =
get8(&p, p_end);
2531 sid =
get16(&p, p_end);
2534 val =
get8(&p, p_end);
2537 desc_list_len =
get16(&p, p_end);
2538 if (desc_list_len < 0)
2540 desc_list_len &= 0xfff;
2541 desc_list_end = p + desc_list_len;
2542 if (desc_list_end > p_end)
2545 desc_tag =
get8(&p, desc_list_end);
2548 desc_len =
get8(&p, desc_list_end);
2549 desc_end = p + desc_len;
2550 if (desc_len < 0 || desc_end > desc_list_end)
2554 desc_tag, desc_len);
2558 service_type =
get8(&p, p_end);
2559 if (service_type < 0)
2561 provider_name =
getstr8(&p, p_end);
2585 static int parse_pcr(int64_t *ppcr_high,
int *ppcr_low,
2592 int len, pid, cc, expected_cc, cc_ok, afc, is_start, is_discontinuity,
2593 has_adaptation, has_payload;
2596 pid =
AV_RB16(packet + 1) & 0x1fff;
2597 is_start = packet[1] & 0x40;
2598 tss = ts->
pids[pid];
2601 tss = ts->
pids[pid];
2611 afc = (packet[3] >> 4) & 3;
2614 has_adaptation = afc & 2;
2615 has_payload = afc & 1;
2616 is_discontinuity = has_adaptation &&
2621 cc = (packet[3] & 0xf);
2622 expected_cc = has_payload ? (tss->
last_cc + 1) & 0x0f : tss->
last_cc;
2623 cc_ok = pid == 0x1FFF ||
2631 "Continuity check failed for pid %d expected %d got %d\n",
2632 pid, expected_cc, cc);
2639 if (packet[1] & 0x80) {
2648 if (has_adaptation) {
2651 if (
parse_pcr(&pcr_h, &pcr_l, packet) == 0)
2652 tss->
last_pcr = pcr_h * 300 + pcr_l;
2658 if (p >= p_end || !has_payload)
2670 if (len > p_end - p)
2696 for (i = 0; i < ts->
nb_prg; i++) {
2768 int64_t back =
FFMIN(seekback, pos);
2771 if (current_packet[0] == 0x80 && current_packet[12] == 0x47) {
2789 "max resync size reached, could not find sync byte\n");
2806 if ((*data)[0] != 0x47) {
2861 if (nb_packets != 0 && packet_num >= nb_packets ||
2888 #define CHECK_COUNT 10 2889 #define CHECK_BLOCK 100 2899 score =
FFMAX3(score, dvhs_score, fec_score);
2901 maxscore =
FFMAX(maxscore, score);
2907 ff_dlog(0,
"TS score: %d %d\n", sumscore, maxscore);
2911 }
else if (check_count >=
CHECK_COUNT && sumscore > 6) {
2913 }
else if (check_count >=
CHECK_COUNT && maxscore > 6) {
2915 }
else if (sumscore > 6) {
2930 afc = (packet[3] >> 4) & 3;
2940 if (!(flags & 0x10))
2945 *ppcr_high = ((int64_t) v << 1) | (p[4] >> 7);
2946 *ppcr_low = ((p[4] & 1) << 8) | p[5];
2979 if (s->
iformat == &ff_mpegts_demuxer) {
2999 int pcr_pid, pid, nb_packets, nb_pcrs, ret, pcr_l;
3000 int64_t pcrs[2], pcr_h;
3001 int packet_count[2];
3022 pid =
AV_RB16(data + 1) & 0x1fff;
3023 if ((pcr_pid == -1 || pcr_pid == pid) &&
3027 packet_count[nb_pcrs] = nb_packets;
3028 pcrs[nb_pcrs] = pcr_h * 300 + pcr_l;
3031 if (pcrs[1] - pcrs[0] > 0) {
3037 packet_count[0] = packet_count[1];
3049 ts->
pcr_incr = (pcrs[1] - pcrs[0]) / (packet_count[1] - packet_count[0]);
3062 #define MAX_PACKET_READAHEAD ((128 * 1024) / 188) 3068 int64_t pcr_h, next_pcr_h, pos;
3069 int pcr_l, next_pcr_l;
3081 if (data != pkt->
data)
3092 if (
parse_pcr(&next_pcr_h, &next_pcr_l, pcr_buf) == 0) {
3095 ((next_pcr_h - pcr_h) * 300 + (next_pcr_l - pcr_l)) /
3102 ts->
cur_pcr = pcr_h * 300 + pcr_l;
3137 if (!ret && pkt->
size < 0)
3161 int64_t *ppos, int64_t pos_limit)
3164 int64_t pos, timestamp;
3166 int pcr_l, pcr_pid =
3172 while(pos < pos_limit) {
3177 if (buf[0] != 0x47) {
3183 if ((pcr_pid < 0 || (
AV_RB16(buf + 1) & 0x1fff) == pcr_pid) &&
3184 parse_pcr(×tamp, &pcr_l, buf) == 0) {
3195 int64_t *ppos, int64_t pos_limit)
3204 while(pos < pos_limit) {
3215 int64_t dts = pkt.
dts;
3261 if (buf[0] != 0x47) {
3291 .priv_class = &mpegts_class,
3295 .
name =
"mpegtsraw",
3303 .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 ff_mp4_parse_es_descr(AVIOContext *pb, int *es_id)
static void finished_reading_packet(AVFormatContext *s, int raw_packet_size)
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 PROBE_PACKET_MAX_BUF
#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.
#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.
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)
#define avpriv_request_sample(...)
#define PROBE_PACKET_MARGIN
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.
enum AVMediaType codec_type
int64_t bit_rate
Total stream bitrate in bit/s, 0 if not available.
int avio_read_partial(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
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.
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.
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)
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]
#define u(width, name, range_min, range_max)
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.
#define FF_PROFILE_ARIB_PROFILE_C
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
static const uint8_t header[24]
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 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 as uint8_t, this is required to pass the stream ID information from the demuxer to t...
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)
#define i(width, name, range_min, range_max)
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. ...
ff_const59 struct AVInputFormat * iformat
The input container format.
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.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
#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)
Allocate, reallocate, or free an array through a pointer to a pointer.
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.
union MpegTSFilter::@269 u
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)
#define FF_PROFILE_UNKNOWN
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_probe(const AVProbeData *p)
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
static AVStream * find_matching_stream(MpegTSContext *ts, int pid, unsigned int programid, int stream_identifier, int pmt_stream_idx)
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)
static int get_packet_size(AVFormatContext *s)
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 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.
#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)
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;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);return NULL;} return ac;} 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;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->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);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
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.
static int probe(const AVProbeData *p)
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
static int handle_packet(MpegTSContext *ts, const uint8_t *packet, int64_t pos)
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 profile
Codec-specific bitstream restrictions that the stream conforms to.
int disposition
AV_DISPOSITION_* bit field.
uint8_t header[MAX_PES_HEADER_SIZE]
#define FF_PROFILE_ARIB_PROFILE_A
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.
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)
#define xf(width, name, var, range_min, range_max, subs,...)
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)
Similar to feof() but also returns nonzero on read errors.
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...
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)