48 #define MAX_RESYNC_SIZE 65536
50 #define MAX_PES_PAYLOAD 200 * 1024
52 #define MAX_MP4_DESCR_COUNT 16
54 #define MOD_UNLIKELY(modulus, dividend, divisor, prev_dividend) \
56 if ((prev_dividend) == 0 || (dividend) - (prev_dividend) != (divisor)) \
57 (modulus) = (dividend) % (divisor); \
58 (prev_dividend) = (dividend); \
61 #define PROBE_PACKET_MAX_BUF 8192
62 #define PROBE_PACKET_MARGIN 5
73 int is_start, int64_t
pos);
115 #define MAX_STREAMS_PER_PROGRAM 128
116 #define MAX_PIDS_PER_PROGRAM (MAX_STREAMS_PER_PROGRAM + 2)
182 #define MPEGTS_OPTIONS \
183 { "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 }
198 {.i64 = 0}, 0, 1, 0 },
200 {.i64 = 0}, 0, 1, 0 },
213 {
"compute_pcr",
"compute exact PCR for each transport stream packet",
216 {
"ts_packetsize",
"output option carrying the raw packet size",
241 #define PES_START_SIZE 6
242 #define PES_HEADER_SIZE 9
243 #define MAX_PES_HEADER_SIZE (9 + 255)
275 if (ts->
prg[
i].
id == programid) {
338 if (p->
pids[
i] == pid)
348 for (
i = 0;
i <
s->nb_programs;
i++) {
350 if (program->
id == programid) {
351 int old_pcr_pid = program->
pcr_pid,
356 if (old_version != -1 && old_version !=
version) {
358 "detected PMT change (program=%d, version=%d/%d, pcr_pid=0x%x/0x%x)\n",
359 programid, old_version,
version, old_pcr_pid, pid);
377 int used = 0, discarded = 0;
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;
522 sec = &
filter->u.section_filter;
542 pes = &
filter->u.pes_filter;
582 memset(stat, 0, packet_size *
sizeof(*stat));
584 for (
i = 0;
i <
size - 3;
i++) {
585 if (buf[
i] == 0x47) {
586 int pid =
AV_RB16(buf+1) & 0x1FFF;
587 int asc = buf[
i + 3] & 0x30;
588 if (!
probe || pid == 0x1FFF || asc) {
589 int x =
i % packet_size;
592 if (stat[x] > best_score) {
593 best_score = stat[x];
599 return best_score -
FFMAX(stat_all - 10*best_score, 0)/10;
605 int score, fec_score, dvhs_score;
612 int max_iterations = 16;
624 buf_size, score, dvhs_score, fec_score);
626 margin =
mid_pred(score, fec_score, dvhs_score);
633 else if (dvhs_score > margin)
635 else if (fec_score > margin)
702 const char *encodings[] = {
703 "ISO6937",
"ISO-8859-5",
"ISO-8859-6",
"ISO-8859-7",
704 "ISO-8859-8",
"ISO-8859-9",
"ISO-8859-10",
"ISO-8859-11",
705 "",
"ISO-8859-13",
"ISO-8859-14",
"ISO-8859-15",
"",
"",
"",
"",
706 "",
"UCS-2BE",
"KSC_5601",
"GB2312",
"UCS-2BE",
"UTF-8",
"",
"",
707 "",
"",
"",
"",
"",
"",
"",
""
711 size_t inlen =
len, outlen = inlen * 6 + 1;
712 if (
len >= 3 && p[0] == 0x10 && !p[1] && p[2] && p[2] <= 0xf && p[2] != 0xc) {
714 snprintf(iso8859,
sizeof(iso8859),
"ISO-8859-%d", p[2]);
717 cd = iconv_open(
"UTF-8", iso8859);
718 }
else if (p[0] < 0x20) {
721 cd = iconv_open(
"UTF-8", encodings[*p]);
724 cd = iconv_open(
"UTF-8", encodings[0]);
726 if (cd == (iconv_t)-1)
733 if (iconv(cd, &
in, &inlen, &
out, &outlen) == -1) {
772 h->version = (
val >> 1) & 0x1f;
780 h->last_sec_num =
val;
799 #if !CONFIG_LOAS_DEMUXER
875 uint32_t stream_type,
892 uint32_t stream_type, uint32_t prog_reg_desc)
912 "stream=%d stream_type=%x pid=%x prog_reg_desc=%.4s\n",
920 if ((prog_reg_desc ==
AV_RL32(
"HDMV") ||
921 prog_reg_desc ==
AV_RL32(
"HDPR")) &&
932 memcpy(sub_pes, pes,
sizeof(*sub_pes));
940 sub_st->
id = pes->
pid;
1037 const uint8_t *buf,
int buf_size)
1040 int au_start_flag = 0, au_end_flag = 0, ocr_flag = 0, idle_flag = 0;
1041 int padding_flag = 0, padding_bits = 0, inst_bitrate_flag = 0;
1042 int dts_flag = -1, cts_flag = -1;
1047 memcpy(buf_padded, buf, buf_padded_size);
1056 au_start_flag = au_end_flag = 1;
1066 if (!idle_flag && (!padding_flag || padding_bits != 0)) {
1074 if (au_start_flag) {
1092 if (inst_bitrate_flag)
1121 const uint8_t *buf,
int buf_size,
int is_start,
1145 while (buf_size > 0) {
1146 switch (pes->
state) {
1158 if (pes->
header[0] == 0x00 && pes->
header[1] == 0x00 &&
1159 pes->
header[2] == 0x01) {
1197 if (
code != 0x1bc &&
code != 0x1bf &&
1204 "pid=%x stream_type=%x probing\n",
1252 unsigned int flags, pes_ext, skip;
1258 if ((
flags & 0xc0) == 0x80) {
1261 }
else if ((
flags & 0xc0) == 0xc0) {
1271 skip = (pes_ext >> 4) & 0xb;
1274 if ((pes_ext & 0x41) == 0x01 &&
1277 if ((
r[0] & 0x7f) > 0 && (
r[1] & 0x80) == 0)
1289 p += sl_header_bytes;
1290 buf_size -= sl_header_bytes;
1321 if (
f->last_pcr != -1 && !
f->discard) {
1326 int64_t pcr =
f->last_pcr / 300;
1333 pes->
pts = pes->
dts = pcr;
1335 pes->
dts > pcr + 3654 + 9000) {
1336 pes->
pts = pes->
dts = pcr + 3654 + 9000;
1338 pes->
dts > pcr + 10*90000) {
1339 pes->
pts = pes->
dts = pcr + 3654 + 9000;
1350 "Forcing DTS/PTS to be unset for a "
1351 "non-trustworthy PES packet for PID %d as "
1352 "PCR hasn't been received yet.\n",
1441 Mp4Descr *descr,
int max_descr_count)
1444 if (
size > (1 << 30))
1464 (*len) -= new_off - *off;
1500 if (!(id_flags & 0x0020)) {
1550 #define R8_CHECK_CLIP_MAX(dst, maxv) do { \
1551 descr->sl.dst = avio_r8(&d->pb); \
1552 if (descr->sl.dst > maxv) { \
1553 descr->sl.dst = maxv; \
1554 return AVERROR_INVALIDDATA; \
1593 if (len < 0 || len1 >
len || len1 <= 0) {
1595 "Tag %x length violation new length %d bytes remaining %d\n",
1606 if (target_tag &&
tag != target_tag) {
1639 Mp4Descr *descr,
int *descr_count,
int max_descr_count)
1655 Mp4Descr *descr,
int *descr_count,
int max_descr_count)
1678 int mp4_descr_count = 0;
1683 p_end =
section + section_len - 4;
1692 mp4_read_od(
s, p, (
unsigned) (p_end - p), mp4_descr, &mp4_descr_count,
1698 for (
i = 0;
i < mp4_descr_count;
i++) {
1712 pes->
sl = mp4_descr[
i].
sl;
1715 mp4_descr[
i].dec_config_descr_len, 0,
1729 for (
i = 0;
i < mp4_descr_count;
i++)
1730 av_free(mp4_descr[
i].dec_config_descr);
1755 if (
f &&
f->last_pcr != -1)
1763 1, 0, 1, 1, 2, 2, 2, 3, 3
1767 1, 1, 1, 2, 2, 3, 4, 4, 5,
1778 { 0,6,1,2,3,4,5,7 },
1783 Mp4Descr *mp4_descr,
int mp4_descr_count,
int pid,
1787 int desc_len, desc_tag, desc_es_id, ext_desc_tag,
channels, channel_config_code;
1791 desc_tag =
get8(pp, desc_list_end);
1794 desc_len =
get8(pp, desc_list_end);
1797 desc_end = *pp + desc_len;
1798 if (desc_end > desc_list_end)
1809 if (
get8(pp, desc_end) & 0x1) {
1814 desc_es_id =
get16(pp, desc_end);
1817 if (ts && ts->
pids[pid])
1819 for (
i = 0;
i < mp4_descr_count;
i++)
1820 if (mp4_descr[
i].dec_config_descr_len &&
1821 mp4_descr[
i].es_id == desc_es_id) {
1824 mp4_descr[
i].dec_config_descr_len, 0,
1837 if (
get16(pp, desc_end) < 0)
1839 if (mp4_descr_count > 0 &&
1860 int language_count = desc_len / 5, ret;
1862 if (desc_len > 0 && desc_len % 5 != 0)
1865 if (language_count > 0) {
1867 av_assert0(language_count <=
sizeof(language) / 4);
1880 for (
i = 0;
i < language_count;
i++) {
1881 language[
i * 4 + 0] =
get8(pp, desc_end);
1882 language[
i * 4 + 1] =
get8(pp, desc_end);
1883 language[
i * 4 + 2] =
get8(pp, desc_end);
1884 language[
i * 4 + 3] =
',';
1886 memcpy(extradata, *pp, 2);
1892 language[
i * 4 - 1] = 0;
1905 int language_count = desc_len / 8, ret;
1907 if (desc_len > 0 && desc_len % 8 != 0)
1910 if (language_count > 1) {
1914 if (language_count > 0) {
1918 av_assert0(language_count <=
sizeof(language) / 4);
1931 for (
i = 0;
i < language_count;
i++) {
1932 language[
i * 4 + 0] =
get8(pp, desc_end);
1933 language[
i * 4 + 1] =
get8(pp, desc_end);
1934 language[
i * 4 + 2] =
get8(pp, desc_end);
1935 language[
i * 4 + 3] =
',';
1949 extradata[4] =
get8(pp, desc_end);
1950 memcpy(extradata, *pp, 4);
1956 language[
i * 4 - 1] = 0;
1963 for (
i = 0;
i + 4 <= desc_len;
i += 4) {
1964 language[
i + 0] =
get8(pp, desc_end);
1965 language[
i + 1] =
get8(pp, desc_end);
1966 language[
i + 2] =
get8(pp, desc_end);
1967 language[
i + 3] =
',';
1968 switch (
get8(pp, desc_end)) {
1981 if (
i && language[0]) {
1982 language[
i - 1] = 0;
2001 if (
get16(pp, desc_end) == 0xFFFF)
2003 if (
get8(pp, desc_end) == 0xFF) {
2010 ext_desc_tag =
get8(pp, desc_end);
2011 if (ext_desc_tag < 0)
2014 ext_desc_tag == 0x80) {
2024 channel_config_code =
get8(pp, desc_end);
2025 if (channel_config_code < 0)
2027 if (channel_config_code <= 0x8) {
2041 if (ext_desc_tag == 0x06) {
2048 if ((
flags & 0x80) == 0)
2051 switch ((
flags >> 2) & 0x1F) {
2067 language[0] =
get8(pp, desc_end);
2068 language[1] =
get8(pp, desc_end);
2069 language[2] =
get8(pp, desc_end);
2081 int component_type_flag =
get8(pp, desc_end) & (1 << 7);
2082 if (component_type_flag) {
2083 int component_type =
get8(pp, desc_end);
2084 int service_type_mask = 0x38;
2085 int service_type = ((component_type & service_type_mask) >> 3);
2086 if (service_type == 0x02 ) {
2095 int component_type_flag =
get8(pp, desc_end) & (1 << 7);
2096 if (component_type_flag) {
2097 int component_type =
get8(pp, desc_end);
2098 int service_type_mask = 0x38;
2099 int service_type = ((component_type & service_type_mask) >> 3);
2100 if (service_type == 0x02 ) {
2118 int data_component_id =
get16(pp, desc_end);
2119 if (data_component_id < 0)
2122 switch (data_component_id) {
2126 if (actual_component_tag >= 0x30 &&
2127 actual_component_tag <= 0x37) {
2134 if (actual_component_tag == 0x87) {
2157 if (desc_end - *pp < 4)
2166 buf =
get16(pp, desc_end);
2168 dovi->
dv_level = (buf >> 3) & 0x3f;
2172 if (desc_end - *pp >= 20) {
2173 buf =
get8(pp, desc_end);
2189 "rpu flag: %d, el flag: %d, bl flag: %d, compatibility id: %d\n",
2206 int stream_identifier,
int pmt_stream_idx,
struct Program *p)
2212 if (stream_identifier) {
2215 if (!found || pmt_stream_idx ==
i)
2219 found =
s->streams[p->
streams[pmt_stream_idx].
idx];
2224 "re-using existing %s stream %d (pid=0x%x) for new pid=0x%x\n",
2238 int desc_len, desc_tag;
2240 desc_list_len =
get16(pp, p_end);
2241 if (desc_list_len < 0)
2243 desc_list_len &= 0xfff;
2244 desc_list_end = p + desc_list_len;
2245 if (desc_list_end > p_end)
2249 desc_tag =
get8(pp, desc_list_end);
2252 desc_len =
get8(pp, desc_list_end);
2255 desc_end = *pp + desc_len;
2256 if (desc_end > desc_list_end)
2259 if (desc_tag == 0x52) {
2260 return get8(pp, desc_end);
2270 return !(stream_type == 0x13 ||
2271 (stream_type == 0x86 && prog_reg_desc ==
AV_RL32(
"CUEI")) );
2282 const uint8_t *p, *p_end, *desc_list_end;
2283 int program_info_length, pcr_pid, pid, stream_type;
2285 uint32_t prog_reg_desc = 0;
2286 int stream_identifier = -1;
2289 int mp4_descr_count = 0;
2296 p_end =
section + section_len - 4;
2306 h->id,
h->sec_num,
h->last_sec_num,
h->version,
h->tid);
2326 pcr_pid =
get16(&p, p_end);
2335 program_info_length =
get16(&p, p_end);
2336 if (program_info_length < 0)
2338 program_info_length &= 0xfff;
2339 while (program_info_length >= 2) {
2346 if (
len > program_info_length - 2)
2349 program_info_length -=
len + 2;
2357 prog_reg_desc = bytestream_get_le32(&p);
2362 p += program_info_length;
2376 stream_type =
get8(&p, p_end);
2377 if (stream_type < 0)
2379 pid =
get16(&p, p_end);
2418 if (pes && !pes->
st) {
2438 if (stream_type == 0x86 && prog_reg_desc ==
AV_RL32(
"CUEI")) {
2460 desc_list_len =
get16(&p, p_end);
2461 if (desc_list_len < 0)
2463 desc_list_len &= 0xfff;
2464 desc_list_end = p + desc_list_len;
2465 if (desc_list_end > p_end)
2469 desc_list_end, mp4_descr,
2470 mp4_descr_count, pid, ts) < 0)
2473 if (pes && prog_reg_desc ==
AV_RL32(
"HDMV") &&
2474 stream_type == 0x83 && pes->
sub_st) {
2483 if (!ts->
pids[pcr_pid])
2487 for (
i = 0;
i < mp4_descr_count;
i++)
2488 av_free(mp4_descr[
i].dec_config_descr);
2504 p_end =
section + section_len - 4;
2518 sid =
get16(&p, p_end);
2521 pmt_pid =
get16(&p, p_end);
2531 if (sid == 0x0000) {
2543 || fil->
pid != pmt_pid
2547 if (!ts->
pids[pmt_pid])
2551 unsigned prg_idx = prg - ts->
prg;
2555 if (prg_idx > nb_prg)
2557 if (prg_idx >= nb_prg)
2599 p_end =
section + section_len - 4;
2613 if (
h->id == 0xFFFF) {
2635 const uint8_t *p, *p_end, *desc_list_end, *desc_end;
2636 int onid,
val, sid, desc_list_len, desc_tag, desc_len, service_type;
2637 char *
name, *provider_name;
2642 p_end =
section + section_len - 4;
2653 onid =
get16(&p, p_end);
2660 sid =
get16(&p, p_end);
2666 desc_list_len =
get16(&p, p_end);
2667 if (desc_list_len < 0)
2669 desc_list_len &= 0xfff;
2670 desc_list_end = p + desc_list_len;
2671 if (desc_list_end > p_end)
2674 desc_tag =
get8(&p, desc_list_end);
2677 desc_len =
get8(&p, desc_list_end);
2678 desc_end = p + desc_len;
2679 if (desc_len < 0 || desc_end > desc_list_end)
2683 desc_tag, desc_len);
2687 service_type =
get8(&p, p_end);
2688 if (service_type < 0)
2690 provider_name =
getstr8(&p, p_end);
2714 static int parse_pcr(int64_t *ppcr_high,
int *ppcr_low,
2721 int len, pid, cc, expected_cc, cc_ok, afc, is_start, is_discontinuity,
2722 has_adaptation, has_payload;
2725 pid =
AV_RB16(packet + 1) & 0x1fff;
2726 is_start = packet[1] & 0x40;
2727 tss = ts->
pids[pid];
2730 tss = ts->
pids[pid];
2740 afc = (packet[3] >> 4) & 3;
2743 has_adaptation = afc & 2;
2744 has_payload = afc & 1;
2745 is_discontinuity = has_adaptation &&
2750 cc = (packet[3] & 0xf);
2751 expected_cc = has_payload ? (tss->
last_cc + 1) & 0x0f : tss->
last_cc;
2752 cc_ok = pid == 0x1FFF ||
2760 "Continuity check failed for pid %d expected %d got %d\n",
2761 pid, expected_cc, cc);
2768 if (packet[1] & 0x80) {
2777 if (has_adaptation) {
2780 if (
parse_pcr(&pcr_h, &pcr_l, packet) == 0)
2781 tss->
last_pcr = pcr_h * 300 + pcr_l;
2787 if (p >= p_end || !has_payload)
2799 if (
len > p_end - p)
2862 int64_t back =
FFMIN(seekback,
pos);
2865 if (current_packet[0] == 0x80 && current_packet[12] == 0x47 &&
pos >=
TS_PACKET_SIZE) {
2877 int new_packet_size, ret;
2893 "max resync size reached, could not find sync byte\n");
2910 if ((*
data)[0] != 0x47) {
2965 if (nb_packets != 0 && packet_num >= nb_packets ||
2992 #define CHECK_COUNT 10
2993 #define CHECK_BLOCK 100
3003 score =
FFMAX3(score, dvhs_score, fec_score);
3005 maxscore =
FFMAX(maxscore, score);
3011 ff_dlog(0,
"TS score: %d %d\n", sumscore, maxscore);
3015 }
else if (check_count >=
CHECK_COUNT && sumscore > 6) {
3017 }
else if (check_count >=
CHECK_COUNT && maxscore > 6) {
3019 }
else if (sumscore > 6) {
3034 afc = (packet[3] >> 4) & 3;
3044 if (!(
flags & 0x10))
3049 *ppcr_high = ((int64_t) v << 1) | (p[4] >> 7);
3050 *ppcr_low = ((p[4] & 1) << 8) | p[5];
3067 int64_t
pos, probesize =
s->probesize;
3070 s->internal->prefer_codec_framerate = 1;
3104 int pcr_pid, pid, nb_packets, nb_pcrs, ret, pcr_l;
3105 int64_t pcrs[2], pcr_h;
3127 if ((pcr_pid == -1 || pcr_pid == pid) &&
3131 pcrs[nb_pcrs] = pcr_h * 300 + pcr_l;
3134 if (pcrs[1] - pcrs[0] > 0) {
3164 #define MAX_PACKET_READAHEAD ((128 * 1024) / 188)
3170 int64_t pcr_h, next_pcr_h,
pos;
3171 int pcr_l, next_pcr_l;
3193 if (
parse_pcr(&next_pcr_h, &next_pcr_l, pcr_buf) == 0) {
3196 ((next_pcr_h - pcr_h) * 300 + (next_pcr_l - pcr_l)) /
3203 ts->
cur_pcr = pcr_h * 300 + pcr_l;
3265 int64_t *ppos, int64_t pos_limit)
3268 int64_t
pos, timestamp;
3270 int pcr_l, pcr_pid =
3271 ((
PESContext *)
s->streams[stream_index]->priv_data)->pcr_pid;
3276 while(
pos < pos_limit) {
3281 if (buf[0] != 0x47) {
3287 if ((pcr_pid < 0 || (
AV_RB16(buf + 1) & 0x1fff) == pcr_pid) &&
3288 parse_pcr(×tamp, &pcr_l, buf) == 0) {
3299 int64_t *ppos, int64_t pos_limit)
3312 while(
pos < pos_limit) {
3371 if (buf[0] != 0x47) {
3405 .
name =
"mpegtsraw",
static int probe(const AVProbeData *p)
static double val(void *priv, double ch)
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)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
#define FF_PROFILE_UNKNOWN
#define FF_PROFILE_ARIB_PROFILE_C
#define FF_PROFILE_ARIB_PROFILE_A
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
#define AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
unsigned int avio_rb16(AVIOContext *s)
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.
int avio_read_partial(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
unsigned int avio_rb32(AVIOContext *s)
int avio_r8(AVIOContext *s)
int ffio_read_indirect(AVIOContext *s, unsigned char *buf, int size, const unsigned char **data)
Read size bytes from AVIOContext, returning a pointer.
int ffio_ensure_seekback(AVIOContext *s, int64_t buf_size)
Ensures that the requested seekback buffer size will be available.
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))
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, buffer_size_t size)
refcounted data buffer API
#define flags(name, subs,...)
#define fc(width, name, range_min, range_max)
static av_always_inline void filter(int16_t *output, ptrdiff_t out_stride, const int16_t *low, ptrdiff_t low_stride, const int16_t *high, ptrdiff_t high_stride, int len, int clip)
common internal and external API header
#define FFSWAP(type, a, b)
#define MKTAG(a, b, c, d)
Public header for CRC hash function implementation.
static int read_header(FFV1Context *f)
bitstream reader API header.
static int get_bits_left(GetBitContext *gb)
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
static unsigned int get_bits1(GetBitContext *s)
static void skip_bits(GetBitContext *s, int n)
static uint64_t get_bits64(GetBitContext *s, int n)
Read 0-64 bits.
static int get_bits_count(const GetBitContext *s)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
enum AVMediaType avcodec_get_type(enum AVCodecID codec_id)
Get the type of the given codec.
AVCodecID
Identify the syntax and semantics of the bitstream.
@ AV_CODEC_ID_MPEG2TS
FAKE codec to indicate a raw MPEG-2 TS stream (only used by libavformat)
@ AV_CODEC_ID_HDMV_PGS_SUBTITLE
@ AV_CODEC_ID_DVB_SUBTITLE
@ AV_CODEC_ID_HDMV_TEXT_SUBTITLE
@ AV_CODEC_ID_SCTE_35
Contain timestamp estimated through PCR of program stream.
@ AV_CODEC_ID_ARIB_CAPTION
@ AV_CODEC_ID_DVB_TELETEXT
@ AV_CODEC_ID_MPEG4SYSTEMS
FAKE codec to indicate a MPEG-4 Systems stream (only used by libavformat)
@ AV_CODEC_ID_MP3
preferred ID for decoding MPEG audio layer 1, 2 or 3
@ AV_CODEC_ID_MPEG2VIDEO
preferred ID for MPEG-1/2 video decoding
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
@ AVDISCARD_ALL
discard all
int avcodec_is_open(AVCodecContext *s)
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
#define AV_PKT_FLAG_CORRUPT
The packet content is corrupted.
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
@ AV_PKT_DATA_MPEGTS_STREAM_ID
MPEGTS stream ID as uint8_t, this is required to pass the stream ID information from the demuxer to t...
@ AV_PKT_DATA_DOVI_CONF
DOVI configuration ref: dolby-vision-bitstreams-within-the-iso-base-media-file-format-v2....
int av_stream_add_side_data(AVStream *st, enum AVPacketSideDataType type, uint8_t *data, size_t size)
Wrap an existing array as stream side data.
AVProgram * av_new_program(AVFormatContext *s, int id)
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
Return the next frame of a stream.
AVProgram * av_find_program_from_stream(AVFormatContext *ic, AVProgram *last, int s)
Find the programs which belong to a given stream.
void av_program_add_stream_index(AVFormatContext *ac, int progid, unsigned int idx)
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.
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
AVBufferPool * av_buffer_pool_init(buffer_size_t size, AVBufferRef *(*alloc)(buffer_size_t size))
Allocate and initialize a buffer pool.
AVBufferRef * av_buffer_pool_get(AVBufferPool *pool)
Allocate a new AVBuffer, reusing an old buffer from the pool when available.
void av_buffer_pool_uninit(AVBufferPool **ppool)
Mark the pool as being available for freeing.
const AVCRC * av_crc_get_table(AVCRCId crc_id)
Get an initialized standard CRC table.
uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length)
Calculate the CRC of a block.
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 AV_DICT_DONT_OVERWRITE
Don't overwrite existing entries.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AVERROR_EOF
End of file.
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
Allocate, reallocate, or free an array through a pointer to a pointer.
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.
@ AVMEDIA_TYPE_DATA
Opaque data information usually continuous.
#define AV_NOPTS_VALUE
Undefined timestamp value.
#define LIBAVUTIL_VERSION_INT
void ff_mp4_parse_es_descr(AVIOContext *pb, int *es_id)
int ff_mp4_read_dec_config_descr(AVFormatContext *fc, AVStream *st, AVIOContext *pb)
int ff_mp4_read_descr(AVFormatContext *fc, AVIOContext *pb, int *tag)
#define MP4DecConfigDescrTag
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
static av_cold int read_close(AVFormatContext *ctx)
#define STREAM_TYPE_PRIVATE_DATA
static int64_t ff_parse_pes_pts(const uint8_t *buf)
Parse MPEG-PES five-byte timestamp.
#define MAX_PIDS_PER_PROGRAM
#define R8_CHECK_CLIP_MAX(dst, maxv)
static const StreamType ISO_types[]
static void mpegts_free(MpegTSContext *ts)
static void clear_program(struct Program *p)
static int parse_mp4_descr_arr(MP4DescrParseContext *d, int64_t off, int len)
#define MAX_STREAMS_PER_PROGRAM
static void seek_back(AVFormatContext *s, AVIOContext *pb, int64_t pos)
static void add_pid_to_program(struct Program *p, unsigned int pid)
static char * getstr8(const uint8_t **pp, const uint8_t *p_end)
static MpegTSFilter * mpegts_open_filter(MpegTSContext *ts, unsigned int pid, enum MpegTSFilterType type)
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...
static const uint8_t opus_channel_map[8][8]
void avpriv_mpegts_parse_close(MpegTSContext *ts)
static int parse_MP4SLDescrTag(MP4DescrParseContext *d, int64_t off, int len)
static const StreamType MISC_types[]
static int skip_identical(const SectionHeader *h, MpegTSSectionFilter *tssf)
static PESContext * add_pes_stream(MpegTSContext *ts, int pid, int pcr_pid)
static const AVOption options[]
AVInputFormat ff_mpegts_demuxer
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 int parse_MP4DecConfigDescrTag(MP4DescrParseContext *d, int64_t off, int len)
static int init_MP4DescrParseContext(MP4DescrParseContext *d, AVFormatContext *s, const uint8_t *buf, unsigned size, Mp4Descr *descr, int max_descr_count)
static void reset_pes_packet_state(PESContext *pes)
static MpegTSFilter * mpegts_open_section_filter(MpegTSContext *ts, unsigned int pid, SectionCallback *section_cb, void *opaque, int check_crc)
static int parse_pcr(int64_t *ppcr_high, int *ppcr_low, const uint8_t *packet)
static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len)
static const uint8_t opus_coupled_stream_cnt[9]
static int get_packet_size(AVFormatContext *s)
static av_unused int64_t mpegts_get_pcr(AVFormatContext *s, int stream_index, int64_t *ppos, int64_t pos_limit)
static int mpegts_read_packet(AVFormatContext *s, AVPacket *pkt)
static int parse_MP4ESDescrTag(MP4DescrParseContext *d, int64_t off, int len)
static void mpegts_close_filter(MpegTSContext *ts, MpegTSFilter *filter)
static void pat_cb(MpegTSFilter *filter, const uint8_t *section, int section_len)
static int parse_mp4_descr(MP4DescrParseContext *d, int64_t off, int len, int target_tag)
static int parse_stream_identifier_desc(const uint8_t *p, const uint8_t *p_end)
static const StreamType REGD_types[]
static int mpegts_set_stream_info(AVStream *st, PESContext *pes, uint32_t stream_type, uint32_t prog_reg_desc)
static void clear_avprogram(MpegTSContext *ts, unsigned int programid)
static void finished_reading_packet(AVFormatContext *s, int raw_packet_size)
static void clear_programs(MpegTSContext *ts)
static int analyze(const uint8_t *buf, int size, int packet_size, int probe)
static const StreamType METADATA_types[]
static int new_pes_packet(PESContext *pes, AVPacket *pkt)
static const AVClass mpegts_class
static int mp4_read_iods(AVFormatContext *s, const uint8_t *buf, unsigned size, Mp4Descr *descr, int *descr_count, int max_descr_count)
void SetServiceCallback(void *opaque, int ret)
static int mpegts_read_header(AVFormatContext *s)
static void m4sl_cb(MpegTSFilter *filter, const uint8_t *section, int section_len)
static int64_t mpegts_get_dts(AVFormatContext *s, int stream_index, int64_t *ppos, int64_t pos_limit)
static AVBufferRef * buffer_pool_get(MpegTSContext *ts, int size)
static void new_data_packet(const uint8_t *buffer, int len, AVPacket *pkt)
static uint64_t get_ts64(GetBitContext *gb, int bits)
#define PROBE_PACKET_MARGIN
static int parse_section_header(SectionHeader *h, const uint8_t **pp, const uint8_t *p_end)
void SectionCallback(MpegTSFilter *f, const uint8_t *buf, int len)
static struct Program * get_program(MpegTSContext *ts, unsigned int programid)
static int is_pes_stream(int stream_type, uint32_t prog_reg_desc)
static int mpegts_push_data(MpegTSFilter *filter, const uint8_t *buf, int buf_size, int is_start, int64_t pos)
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 int handle_packets(MpegTSContext *ts, int64_t nb_packets)
static void eit_cb(MpegTSFilter *filter, const uint8_t *section, int section_len)
static int read_packet(AVFormatContext *s, uint8_t *buf, int raw_packet_size, const uint8_t **data)
static void update_av_program_info(AVFormatContext *s, unsigned int programid, unsigned int pid, int version)
static int get8(const uint8_t **pp, const uint8_t *p_end)
int avpriv_mpegts_parse_packet(MpegTSContext *ts, AVPacket *pkt, const uint8_t *buf, int len)
static int mpegts_read_close(AVFormatContext *s)
static void mpegts_find_stream_type(AVStream *st, uint32_t stream_type, const StreamType *types)
#define PROBE_PACKET_MAX_BUF
static const uint8_t opus_stream_cnt[9]
static void update_offsets(AVIOContext *pb, int64_t *off, int *len)
int PESCallback(MpegTSFilter *f, const uint8_t *buf, int len, int is_start, int64_t pos)
static int mpegts_raw_read_packet(AVFormatContext *s, AVPacket *pkt)
static void sdt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len)
#define MAX_MP4_DESCR_COUNT
static int get16(const uint8_t **pp, const uint8_t *p_end)
static const AVOption raw_options[]
static const AVClass mpegtsraw_class
AVInputFormat ff_mpegtsraw_demuxer
static int mp4_read_od(AVFormatContext *s, const uint8_t *buf, unsigned size, Mp4Descr *descr, int *descr_count, int max_descr_count)
static int handle_packet(MpegTSContext *ts, const uint8_t *packet, int64_t pos)
static MpegTSFilter * mpegts_open_pcr_filter(MpegTSContext *ts, unsigned int pid)
static struct Program * add_program(MpegTSContext *ts, unsigned int programid)
static const StreamType SCTE_types[]
static const StreamType DESC_types[]
#define MAX_PES_HEADER_SIZE
static int mpegts_probe(const AVProbeData *p)
static const StreamType HDMV_types[]
static int mpegts_resync(AVFormatContext *s, int seekback, const uint8_t *current_packet)
static int parse_MP4ODescrTag(MP4DescrParseContext *d, int64_t off, int len)
MpegTSContext * avpriv_mpegts_parse_open(AVFormatContext *s)
static int read_sl_header(PESContext *pes, SLConfigDescr *sl, const uint8_t *buf, int buf_size)
static AVStream * find_matching_stream(MpegTSContext *ts, int pid, unsigned int programid, int stream_identifier, int pmt_stream_idx, struct Program *p)
static int parse_MP4IODescrTag(MP4DescrParseContext *d, int64_t off, int len)
static MpegTSFilter * mpegts_open_pes_filter(MpegTSContext *ts, unsigned int pid, PESCallback *pes_cb, void *opaque)
#define MAX_PACKET_READAHEAD
static void scte_data_cb(MpegTSFilter *filter, const uint8_t *section, int section_len)
#define TS_MAX_PACKET_SIZE
#define TS_FEC_PACKET_SIZE
#define ISO_639_LANGUAGE_DESCRIPTOR
#define TS_DVHS_PACKET_SIZE
#define REGISTRATION_DESCRIPTOR
#define METADATA_DESCRIPTOR
#define VIDEO_STREAM_DESCRIPTOR
#define AV_OPT_FLAG_READONLY
The option may not be set through the AVOptions API, only read.
#define AV_OPT_FLAG_DECODING_PARAM
a generic parameter which can be set by the user for demuxing or decoding
#define AV_OPT_FLAG_EXPORT
The option is intended for exporting values to the caller.
static const uint8_t opus_default_extradata[30]
#define FF_ARRAY_ELEMS(a)
A reference to a data buffer.
uint8_t * data
The data buffer.
Describe the class of an AVClass context structure.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
int extradata_size
Size of the extradata content in bytes.
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
enum AVMediaType codec_type
General type of the encoded data.
int profile
Codec-specific bitstream restrictions that the stream conforms to.
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
uint8_t dv_bl_signal_compatibility_id
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
int ctx_flags
Flags signalling stream properties.
int ts_id
Transport stream id.
AVStream ** streams
A list of all streams in the file.
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
This structure stores compressed data.
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
int flags
A combination of AV_PKT_FLAG values.
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
int64_t pos
byte position in stream, -1 if unknown
This structure contains the data a format has to probe a file.
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.
New fields can be added to the end with minor version bumps.
unsigned int nb_stream_indexes
unsigned int * stream_index
enum AVDiscard discard
selects which program to discard and which to feed to the caller
int64_t pts_wrap_reference
Internal data to check for wrapping of the time stamp.
AVCodecContext * avctx
The codec context used by avformat_find_stream_info, the parser, etc.
int need_context_update
Whether the internal avctx needs to be updated from codecpar (after a late change to codecpar)
int request_probe
stream probing state -1 -> probing finished 0 -> no probing requested rest -> perform probing with re...
int pts_wrap_behavior
Options for behavior, when a wrap is detected.
AVCodecParameters * codecpar
Codec parameters associated with this stream.
int probe_packets
Number of packets to buffer for codec probing.
int stream_identifier
Stream Identifier This is the MPEG-TS stream identifier +1 0 means unknown.
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
int id
Format-specific stream ID.
int index
stream index in AVFormatContext
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base.
enum AVStreamParseType need_parsing
AVStreamInternal * internal
An opaque field for libavformat internal usage.
int disposition
AV_DISPOSITION_* bit field.
int predefined_SLConfigDescriptor_seen
uint8_t * dec_config_descr
int fix_teletext_pts
fix dvb teletext pts
int raw_packet_size
raw packet size, including FEC if present
int stop_parse
stop parsing loop
MpegTSFilter * pids[NB_PID_MAX]
filters for various streams specified by PMT + for the PAT and PMT
int8_t crc_validity[NB_PID_MAX]
int64_t pcr_incr
used to estimate the exact PCR
int auto_guess
if true, all pids are analyzed to find streams
int64_t last_pos
to detect seek
AVPacket * pkt
packet containing Audio/Video data
int mpeg2ts_compute_pcr
compute exact PCR for each transport stream packet
int64_t cur_pcr
used to estimate the exact PCR
unsigned int nb_prg
structure to keep track of Program->pids mapping
enum MpegTSFilterType type
MpegTSSectionFilter section_filter
MpegTSPESFilter pes_filter
union MpegTSFilter::@270 u
SectionCallback * section_cb
unsigned int end_of_section_reached
int64_t ts_packet_pos
position of first TS packet of this PES packet
int pcr_pid
if -1 then all packets containing PCR are considered
uint8_t header[MAX_PES_HEADER_SIZE]
AVStream * sub_st
stream for the embedded AC3 stream in HDMV TrueHD
int flags
copied to the AVPacket flags
int pmt_found
have we found pmt for this program
unsigned int pids[MAX_PIDS_PER_PROGRAM]
struct Stream streams[MAX_STREAMS_PER_PROGRAM]
enum AVMediaType codec_type
#define avpriv_request_sample(...)
static const uint8_t offset[127][2]