Go to the documentation of this file.
22 #include "config_components.h"
52 #define MAX_RESYNC_SIZE 65536
54 #define MAX_MP4_DESCR_COUNT 16
56 #define MOD_UNLIKELY(modulus, dividend, divisor, prev_dividend) \
58 if ((prev_dividend) == 0 || (dividend) - (prev_dividend) != (divisor)) \
59 (modulus) = (dividend) % (divisor); \
60 (prev_dividend) = (dividend); \
63 #define PROBE_PACKET_MAX_BUF 8192
64 #define PROBE_PACKET_MARGIN 5
117 #define MAX_STREAMS_PER_PROGRAM 128
118 #define MAX_PIDS_PER_PROGRAM (MAX_STREAMS_PER_PROGRAM + 2)
197 #define MPEGTS_OPTIONS \
198 { "resync_size", "set size limit for looking up a new synchronization", \
199 offsetof(MpegTSContext, resync_size), AV_OPT_TYPE_INT, \
200 { .i64 = MAX_RESYNC_SIZE}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM }, \
201 { "ts_id", "transport stream id", \
202 offsetof(MpegTSContext, id), AV_OPT_TYPE_INT, \
203 { .i64 = 0 }, 0, INT_MAX, AV_OPT_FLAG_EXPORT | AV_OPT_FLAG_READONLY }, \
204 { "ts_packetsize", "output option carrying the raw packet size", \
205 offsetof(MpegTSContext, raw_packet_size), AV_OPT_TYPE_INT, \
206 { .i64 = 0 }, 0, INT_MAX, AV_OPT_FLAG_EXPORT | AV_OPT_FLAG_READONLY }
219 {.i64 = 0}, 0, 1, 0 },
221 {.i64 = 0}, 0, 1, 0 },
236 {
"compute_pcr",
"compute exact PCR for each transport stream packet",
260 #define PES_START_SIZE 6
261 #define PES_HEADER_SIZE 9
262 #define MAX_PES_HEADER_SIZE (9 + 255)
296 if (ts->
prg[
i].
id == programid) {
324 p->nb_stream_groups = 0;
325 memset(
p->stream_groups, 0,
sizeof(
p->stream_groups));
360 for (
i = 0;
i <
p->nb_pids;
i++)
361 if (
p->pids[
i] == pid)
364 p->pids[
p->nb_pids++] = pid;
371 for (
i = 0;
i <
s->nb_programs;
i++) {
373 if (
program->id == programid) {
374 int old_pcr_pid =
program->pcr_pid,
375 old_version =
program->pmt_version;
379 if (old_version != -1 && old_version !=
version) {
381 "detected PMT change (program=%d, version=%d/%d, pcr_pid=0x%x/0x%x)\n",
382 programid, old_version,
version, old_pcr_pid, pid);
400 int used = 0, discarded = 0;
416 for (j = 0; j <
p->nb_pids; j++) {
417 if (
p->pids[j] != pid)
431 return !used && discarded;
439 const uint8_t *buf,
int buf_size,
int is_start)
442 uint8_t *cur_section_buf =
NULL;
465 len = (
AV_RB16(cur_section_buf + 1) & 0xfff) + 3;
545 sec = &
filter->u.section_filter;
565 pes = &
filter->u.pes_filter;
605 memset(stat, 0, packet_size *
sizeof(*stat));
607 for (
i = 0;
i <
size - 3;
i++) {
609 int pid =
AV_RB16(buf+1) & 0x1FFF;
610 int asc = buf[
i + 3] & 0x30;
611 if (!
probe || pid == 0x1FFF || asc) {
612 int x =
i % packet_size;
615 if (stat[x] > best_score) {
616 best_score = stat[x];
622 return best_score -
FFMAX(stat_all - 10*best_score, 0)/10;
628 int score, fec_score, dvhs_score;
635 int max_iterations = 16;
647 buf_size, score, dvhs_score, fec_score);
649 margin =
mid_pred(score, fec_score, dvhs_score);
656 else if (dvhs_score > margin)
658 else if (fec_score > margin)
684 static inline int get8(
const uint8_t **pp,
const uint8_t *p_end)
697 static inline int get16(
const uint8_t **pp,
const uint8_t *p_end)
712 static char *
getstr8(
const uint8_t **pp,
const uint8_t *p_end)
726 const char *encodings[] = {
727 "ISO6937",
"ISO-8859-5",
"ISO-8859-6",
"ISO-8859-7",
728 "ISO-8859-8",
"ISO-8859-9",
"ISO-8859-10",
"ISO-8859-11",
729 "",
"ISO-8859-13",
"ISO-8859-14",
"ISO-8859-15",
"",
"",
"",
"",
730 "",
"UCS-2BE",
"KSC_5601",
"GB2312",
"UCS-2BE",
"UTF-8",
"",
"",
731 "",
"",
"",
"",
"",
"",
"",
""
735 size_t inlen =
len, outlen = inlen * 6 + 1;
736 if (
len >= 3 &&
p[0] == 0x10 && !
p[1] &&
p[2] &&
p[2] <= 0
xf &&
p[2] != 0xc) {
738 snprintf(iso8859,
sizeof(iso8859),
"ISO-8859-%d",
p[2]);
741 cd = iconv_open(
"UTF-8", iso8859);
742 }
else if (
p[0] < 0x20) {
745 cd = iconv_open(
"UTF-8", encodings[*
p]);
748 cd = iconv_open(
"UTF-8", encodings[0]);
750 if (cd == (iconv_t)-1)
757 if (iconv(cd, &in, &inlen, &
out, &outlen) == -1) {
780 const uint8_t **pp,
const uint8_t *p_end)
796 h->version = (
val >> 1) & 0x1f;
797 h->current_next =
val & 0x01;
805 h->last_sec_num =
val;
824 #if !CONFIG_LOAS_DEMUXER
917 uint32_t stream_type,
935 uint32_t stream_type, uint32_t prog_reg_desc)
951 "stream=%d stream_type=%x pid=%x prog_reg_desc=%.4s\n",
961 if ((prog_reg_desc ==
AV_RL32(
"HDMV") ||
962 prog_reg_desc ==
AV_RL32(
"HDPR")) &&
980 sub_st->
id = pes->
pid;
1053 if (header_size >
pkt->
size) {
1055 "Invalid JPEG-XS header size %"PRIu32
" > packet size %d\n",
1096 const uint8_t *buf,
int buf_size)
1099 int au_start_flag = 0, au_end_flag = 0, ocr_flag = 0, idle_flag = 0;
1100 int padding_flag = 0, padding_bits = 0, inst_bitrate_flag = 0;
1101 int dts_flag = -1, cts_flag = -1;
1106 memcpy(buf_padded, buf, buf_padded_size);
1115 au_start_flag = au_end_flag = 1;
1125 if (!idle_flag && (!padding_flag || padding_bits != 0)) {
1133 if (au_start_flag) {
1151 if (inst_bitrate_flag)
1180 const uint8_t *buf,
int buf_size,
int is_start,
1204 while (buf_size > 0) {
1205 switch (pes->
state) {
1217 if (pes->
header[0] == 0x00 && pes->
header[1] == 0x00 &&
1218 pes->
header[2] == 0x01) {
1257 "pid=%x stream_type=%x probing\n",
1311 if ((
flags & 0xc0) == 0x80) {
1314 }
else if ((
flags & 0xc0) == 0xc0) {
1324 skip = (pes_ext >> 4) & 0xb;
1327 if ((pes_ext & 0x41) == 0x01 &&
1330 if ((
r[0] & 0x7f) > 0 && (
r[1] & 0x80) == 0)
1342 p += sl_header_bytes;
1343 buf_size -= sl_header_bytes;
1371 for (
i = 0;
i <
p->nb_stream_indexes;
i++) {
1377 if (
f->last_pcr != -1 && !
f->discard) {
1392 pes->
pts = pes->
dts = pcr;
1394 pes->
dts > pcr + 3654 + 9000) {
1395 pes->
pts = pes->
dts = pcr + 3654 + 9000;
1397 pes->
dts > pcr + 10*90000) {
1398 pes->
pts = pes->
dts = pcr + 3654 + 9000;
1409 "Forcing DTS/PTS to be unset for a "
1410 "non-trustworthy PES packet for PID %d as "
1411 "PCR hasn't been received yet.\n",
1425 pes->
data_index + buf_size > max_packet_size) {
1433 buf_size > max_packet_size) {
1436 buf_size = max_packet_size;
1507 const uint8_t *buf,
unsigned size,
1508 Mp4Descr *descr,
int max_descr_count)
1510 if (
size > (1 << 30))
1528 (*len) -= new_off - *off;
1565 if (!(id_flags & 0x0020)) {
1617 #define R8_CHECK_CLIP_MAX(dst, maxv) do { \
1618 descr->sl.dst = avio_r8(pb); \
1619 if (descr->sl.dst > maxv) { \
1620 descr->sl.dst = maxv; \
1621 return AVERROR_INVALIDDATA; \
1661 if (len < 0 || len1 >
len || len1 <= 0) {
1663 "Tag %x length violation new length %d bytes remaining %d\n",
1674 if (target_tag &&
tag != target_tag) {
1707 Mp4Descr *descr,
int *descr_count,
int max_descr_count)
1725 Mp4Descr *descr,
int *descr_count,
int max_descr_count)
1746 const uint8_t *
p, *p_end;
1747 int mp4_descr_count = 0;
1752 p_end = section + section_len - 4;
1761 mp4_read_od(
s,
p, (
unsigned) (p_end -
p), mp4_descr, &mp4_descr_count,
1767 for (
i = 0;
i < mp4_descr_count;
i++) {
1784 pes->
sl = mp4_descr[
i].
sl;
1787 mp4_descr[
i].dec_config_descr_len);
1800 for (
i = 0;
i < mp4_descr_count;
i++)
1801 av_free(mp4_descr[
i].dec_config_descr);
1826 if (
f &&
f->last_pcr != -1)
1834 1, 0, 1, 1, 2, 2, 2, 3, 3
1838 1, 1, 1, 2, 2, 3, 4, 4, 5,
1849 { 0,6,1,2,3,4,5,7 },
1853 const uint8_t **pp,
const uint8_t *desc_end,
1856 int ext_tag =
get8(pp, desc_end);
1861 int horizontal_size, vertical_size, schar;
1863 int descriptor_version, interlace_mode, n_fields;
1866 if (desc_end - *pp < 29)
1869 descriptor_version =
get8(pp, desc_end);
1870 if (descriptor_version) {
1875 horizontal_size =
get16(pp, desc_end);
1876 vertical_size =
get16(pp, desc_end);
1878 frat = bytestream_get_be32(pp);
1879 schar =
get16(pp, desc_end);
1884 colour_primaries =
get8(pp, desc_end);
1886 matrix_coefficients =
get8(pp, desc_end);
1887 video_full_range_flag = (
get8(pp, desc_end) & 0x80) == 0x80 ? 1 : 0;
1889 interlace_mode = (frat >> 30) & 0x3;
1890 if (interlace_mode == 3) {
1903 int framerate_num = (frat & 0x0000FFFF
U);
1904 int framerate_den = ((frat >> 24) & 0x0000003FU);
1906 if (framerate_den == 2) {
1907 framerate_num *= 1000;
1908 framerate_den = 1001;
1909 }
else if (framerate_den != 1) {
1918 switch (schar & 0
xf) {
1936 int lcevc_stream_tag =
get8(pp, desc_end);
1945 for (
i = 0;
i <
p->nb_stream_groups;
i++) {
1946 stg = &
p->stream_groups[
i];
1949 if (stg->
id == lcevc_stream_tag)
1952 if (
i ==
p->nb_stream_groups) {
1955 p->nb_stream_groups++;
1958 stg = &
p->stream_groups[
i];
1959 stg->
id = lcevc_stream_tag;
1978 int num_lcevc_stream_tags =
get8(pp, desc_end);
1986 for (
int i = 0;
i < num_lcevc_stream_tags;
i++) {
1988 int lcevc_stream_tag =
get8(pp, desc_end);;
1991 for (j = 0; j <
p->nb_stream_groups; j++) {
1992 stg = &
p->stream_groups[j];
1995 if (stg->
id == lcevc_stream_tag)
1998 if (j ==
p->nb_stream_groups) {
2001 p->nb_stream_groups++;
2004 stg = &
p->stream_groups[j];
2005 stg->
id = lcevc_stream_tag;
2027 const uint8_t **pp,
const uint8_t *desc_list_end,
2028 Mp4Descr *mp4_descr,
int mp4_descr_count,
int pid,
2032 const uint8_t *desc_end;
2033 int desc_len, desc_tag, desc_es_id, ext_desc_tag,
channels, channel_config_code;
2037 desc_tag =
get8(pp, desc_list_end);
2040 desc_len =
get8(pp, desc_list_end);
2043 desc_end = *pp + desc_len;
2044 if (desc_end > desc_list_end)
2055 if (
get8(pp, desc_end) & 0x1) {
2060 desc_es_id =
get16(pp, desc_end);
2063 if (ts && ts->
pids[pid])
2065 for (
i = 0;
i < mp4_descr_count;
i++)
2066 if (mp4_descr[
i].dec_config_descr_len &&
2067 mp4_descr[
i].es_id == desc_es_id) {
2070 mp4_descr[
i].dec_config_descr_len);
2082 if (
get16(pp, desc_end) < 0)
2084 if (mp4_descr_count > 0 &&
2103 uint8_t *extradata =
NULL;
2104 int language_count = desc_len / 5,
ret;
2106 if (desc_len > 0 && desc_len % 5 != 0)
2109 if (language_count > 0) {
2124 for (
i = 0;
i < language_count;
i++) {
2130 memcpy(extradata, *pp, 2);
2149 int language_count = desc_len / 8,
ret;
2151 if (desc_len > 0 && desc_len % 8 != 0)
2154 if (language_count > 1) {
2158 if (language_count > 0) {
2175 for (
i = 0;
i < language_count;
i++) {
2193 extradata[4] =
get8(pp, desc_end);
2194 memcpy(extradata, *pp, 4);
2207 for (
i = 0;
i + 4 <= desc_len;
i += 4) {
2212 switch (
get8(pp, desc_end)) {
2245 if (
get16(pp, desc_end) == 0xFFFF)
2247 if (
get8(pp, desc_end) == 0xFF) {
2254 ext_desc_tag =
get8(pp, desc_end);
2255 if (ext_desc_tag < 0)
2258 ext_desc_tag == 0x80) {
2268 channel_config_code =
get8(pp, desc_end);
2269 if (channel_config_code < 0)
2271 if (channel_config_code <= 0x8) {
2294 if ((
flags & 0x80) == 0)
2297 switch ((
flags >> 2) & 0x1F) {
2333 int component_type_flag =
get8(pp, desc_end) & (1 << 7);
2334 if (component_type_flag) {
2335 int component_type =
get8(pp, desc_end);
2336 int service_type_mask = 0x38;
2337 int service_type = ((component_type & service_type_mask) >> 3);
2338 if (service_type == 0x02 ) {
2356 int data_component_id =
get16(pp, desc_end);
2357 if (data_component_id < 0)
2360 switch (data_component_id) {
2364 if (actual_component_tag >= 0x30 &&
2365 actual_component_tag <= 0x37) {
2372 if (actual_component_tag == 0x87) {
2398 int dependency_pid = -1;
2400 if (desc_end - *pp < 4)
2409 buf =
get16(pp, desc_end);
2411 dovi->
dv_level = (buf >> 3) & 0x3f;
2416 buf =
get16(pp, desc_end);
2417 dependency_pid = buf >> 3;
2419 if (desc_end - *pp >= 1) {
2420 buf =
get8(pp, desc_end);
2433 (uint8_t *)dovi, dovi_size, 0)) {
2439 "rpu flag: %d, el flag: %d, bl flag: %d, dependency_pid: %d, "
2440 "compatibility id: %d, compression: %d\n",
2467 int stream_identifier,
int pmt_stream_idx,
struct Program *
p)
2472 if (stream_identifier) {
2473 for (
int i = 0;
i <
p->nb_streams;
i++) {
2474 if (
p->streams[
i].stream_identifier == stream_identifier)
2475 if (!found || pmt_stream_idx ==
i)
2476 found =
s->streams[
p->streams[
i].idx];
2479 found =
s->streams[
p->streams[pmt_stream_idx].idx];
2484 "reusing existing %s stream %d (pid=0x%x) for new pid=0x%x\n",
2486 found->
index, found->
id, pid);
2494 const uint8_t **pp = &
p;
2495 const uint8_t *desc_list_end;
2496 const uint8_t *desc_end;
2498 int desc_len, desc_tag;
2500 desc_list_len =
get16(pp, p_end);
2501 if (desc_list_len < 0)
2503 desc_list_len &= 0xfff;
2504 desc_list_end =
p + desc_list_len;
2505 if (desc_list_end > p_end)
2509 desc_tag =
get8(pp, desc_list_end);
2512 desc_len =
get8(pp, desc_list_end);
2515 desc_end = *pp + desc_len;
2516 if (desc_end > desc_list_end)
2520 return get8(pp, desc_end);
2530 switch (stream_type) {
2538 return !(prog_reg_desc ==
AV_RL32(
"CUEI"));
2554 if (stg->
id == grp->
id)
2585 const uint8_t *
p, *p_end, *desc_list_end;
2586 int program_info_length, pcr_pid, pid, stream_type;
2588 uint32_t prog_reg_desc = 0;
2589 int stream_identifier = -1;
2592 int mp4_descr_count = 0;
2599 p_end = section + section_len - 4;
2605 if (!
h->current_next)
2611 h->id,
h->sec_num,
h->last_sec_num,
h->version,
h->tid);
2631 pcr_pid =
get16(&
p, p_end);
2640 program_info_length =
get16(&
p, p_end);
2642 if (program_info_length < 0 || (program_info_length & 0xFFF) > p_end -
p)
2644 program_info_length &= 0xfff;
2645 while (program_info_length >= 2) {
2652 program_info_length -= 2;
2653 if (
len > program_info_length)
2656 program_info_length -=
len;
2664 prog_reg_desc = bytestream_get_le32(&
p);
2669 p += program_info_length;
2683 stream_type =
get8(&
p, p_end);
2684 if (stream_type < 0)
2725 if (pes && !pes->
st) {
2767 desc_list_len =
get16(&
p, p_end);
2768 if (desc_list_len < 0)
2770 desc_list_len &= 0xfff;
2771 desc_list_end =
p + desc_list_len;
2772 if (desc_list_end > p_end)
2776 desc_list_end, mp4_descr,
2777 mp4_descr_count, pid, ts) < 0)
2780 if (pes && prog_reg_desc ==
AV_RL32(
"HDMV") &&
2790 if (!ts->
pids[pcr_pid])
2797 for (
i = 0;
i < mp4_descr_count;
i++)
2798 av_free(mp4_descr[
i].dec_config_descr);
2806 const uint8_t *
p, *p_end;
2814 p_end = section + section_len - 4;
2820 if (!
h->current_next)
2833 pmt_pid =
get16(&
p, p_end);
2838 if (pmt_pid <= 0x000F || pmt_pid == 0x1FFF) {
2840 "Ignoring invalid PAT entry: sid=0x%x pid=0x%x\n", sid, pmt_pid);
2846 if (sid == 0x0000) {
2858 || fil->
pid != pmt_pid
2862 if (!ts->
pids[pmt_pid])
2866 unsigned prg_idx = prg - ts->
prg;
2870 if (prg_idx > nb_prg)
2872 if (prg_idx >= nb_prg)
2895 const uint8_t *
p, *p_end;
2915 p_end = section + section_len - 4;
2929 if (
h->id == 0xFFFF) {
2951 const uint8_t *
p, *p_end, *desc_list_end, *desc_end;
2952 int onid,
val, sid, desc_list_len, desc_tag, desc_len, service_type;
2953 char *
name, *provider_name;
2958 p_end = section + section_len - 4;
2964 if (!
h->current_next)
2984 desc_list_len =
get16(&
p, p_end);
2985 if (desc_list_len < 0)
2987 desc_list_len &= 0xfff;
2988 desc_list_end =
p + desc_list_len;
2989 if (desc_list_end > p_end)
2992 desc_tag =
get8(&
p, desc_list_end);
2995 desc_len =
get8(&
p, desc_list_end);
2996 desc_end =
p + desc_len;
2997 if (desc_len < 0 || desc_end > desc_list_end)
3001 desc_tag, desc_len);
3005 service_type =
get8(&
p, desc_end);
3006 if (service_type < 0)
3008 provider_name =
getstr8(&
p, desc_end);
3033 const uint8_t *packet);
3039 int len, pid, cc, expected_cc, cc_ok, afc, is_start, is_discontinuity,
3040 has_adaptation, has_payload;
3041 const uint8_t *
p, *p_end;
3043 pid =
AV_RB16(packet + 1) & 0x1fff;
3044 is_start = packet[1] & 0x40;
3045 tss = ts->
pids[pid];
3048 tss = ts->
pids[pid];
3058 afc = (packet[3] >> 4) & 3;
3061 has_adaptation = afc & 2;
3062 has_payload = afc & 1;
3063 is_discontinuity = has_adaptation &&
3068 cc = (packet[3] & 0xf);
3069 expected_cc = has_payload ? (tss->
last_cc + 1) & 0x0f : tss->
last_cc;
3078 "Continuity check failed for pid %d expected %d got %d\n",
3079 pid, expected_cc, cc);
3086 if (packet[1] & 0x80) {
3095 if (has_adaptation) {
3098 if (
parse_pcr(&pcr_h, &pcr_l, packet) == 0)
3105 if (
p >= p_end || !has_payload)
3117 if (
len > p_end -
p)
3187 int new_packet_size,
ret;
3203 "max resync size reached, could not find sync byte\n");
3210 const uint8_t **
data)
3256 const uint8_t *
data;
3285 if (nb_packets != 0 && packet_num >= nb_packets ||
3307 const int size =
p->buf_size;
3312 #define CHECK_COUNT 10
3313 #define CHECK_BLOCK 100
3323 score =
FFMAX3(score, dvhs_score, fec_score);
3325 maxscore =
FFMAX(maxscore, score);
3331 ff_dlog(0,
"TS score: %d %d\n", sumscore, maxscore);
3335 }
else if (check_count >=
CHECK_COUNT && sumscore > 6) {
3337 }
else if (check_count >=
CHECK_COUNT && maxscore > 6) {
3339 }
else if (sumscore > 6) {
3354 afc = (packet[3] >> 4) & 3;
3364 if (!(
flags & 0x10))
3369 *ppcr_high = ((
int64_t) v << 1) | (
p[4] >> 7);
3370 *ppcr_low = ((
p[4] & 1) << 8) |
p[5];
3422 int pcr_pid, pid, nb_packets, nb_pcrs,
ret, pcr_l;
3425 const uint8_t *
data;
3445 if ((pcr_pid == -1 || pcr_pid == pid) &&
3452 if (pcrs[1] - pcrs[0] > 0) {
3482 #define MAX_PACKET_READAHEAD ((128 * 1024) / 188)
3489 int pcr_l, next_pcr_l;
3490 uint8_t pcr_buf[12];
3491 const uint8_t *
data;
3511 if (
parse_pcr(&next_pcr_h, &next_pcr_l, pcr_buf) == 0) {
3588 int pcr_l, pcr_pid =
3589 ((
PESContext *)
s->streams[stream_index]->priv_data)->pcr_pid;
3594 while(
pos < pos_limit) {
3605 if ((pcr_pid < 0 || (
AV_RB16(buf + 1) & 0x1fff) == pcr_pid) &&
3606 parse_pcr(×tamp, &pcr_l, buf) == 0) {
3630 while(
pos < pos_limit) {
3680 const uint8_t *buf,
int len)
3725 .
p.
name =
"mpegtsraw",
static int parse_MP4DecConfigDescrTag(MP4DescrParseContext *d, int64_t off, int len)
static int mpegts_set_stream_info(AVStream *st, PESContext *pes, uint32_t stream_type, uint32_t prog_reg_desc)
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
static int parse_mp4_descr_arr(MP4DescrParseContext *d, int64_t off, int len)
static int new_pes_packet(PESContext *pes, AVPacket *pkt)
AVBufferPool * av_buffer_pool_init(size_t size, AVBufferRef *(*alloc)(size_t size))
Allocate and initialize a buffer pool.
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
#define AV_LOG_WARNING
Something somehow does not look correct.
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
AVStreamGroup ** stream_groups
A list of all stream groups in the file.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
#define MP4DecConfigDescrTag
int64_t id
Group type-specific group ID.
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C program
AVStream * streams[MAX_STREAMS_PER_PROGRAM]
static int get_bits_left(GetBitContext *gb)
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
#define SYSTEM_CLOCK_FREQUENCY_DIVISOR
enum AVMediaType codec_type
General type of the encoded data.
unsigned int nb_stream_indexes
int ff_mp4_read_dec_config_descr(void *logctx, AVStream *st, AVIOContext *pb)
#define STREAM_TYPE_AUDIO_AAC
static int64_t ff_parse_pes_pts(const uint8_t *buf)
Parse MPEG-PES five-byte timestamp.
#define TS_DVHS_PACKET_SIZE
static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len)
int ffio_read_indirect(AVIOContext *s, unsigned char *buf, int size, const unsigned char **data)
Read size bytes from AVIOContext, returning a pointer.
#define STREAM_TYPE_VIDEO_VC1
#define STREAM_TYPE_PRIVATE_DATA
enum AVColorSpace color_space
int flags
copied to the AVPacket flags
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
#define AVERROR_EOF
End of file.
int avpriv_mpegts_parse_packet(MpegTSContext *ts, AVPacket *pkt, const uint8_t *buf, int len)
uint8_t * data
The data buffer.
static const uint8_t opus_default_extradata[30]
enum AVMediaType avcodec_get_type(enum AVCodecID codec_id)
Get the type of the given codec.
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
AVProgram * av_find_program_from_stream(AVFormatContext *ic, AVProgram *last, int s)
Find the programs which belong to a given stream.
#define STREAM_ID_EMM_STREAM
static void mpegts_close_filter(MpegTSContext *ts, MpegTSFilter *filter)
#define STREAM_ID_PADDING_STREAM
#define STREAM_ID_PROGRAM_STREAM_MAP
int pmt_found
have we found pmt for this program
static int get_bits_count(const GetBitContext *s)
static const StreamType METADATA_types[]
#define STREAM_TYPE_AUDIO_MPEG1
AVStream ** streams
A list of all streams in the file.
@ AVCOL_RANGE_JPEG
Full range content.
static void mpegts_find_stream_type(AVStream *st, uint32_t stream_type, const StreamType *types)
#define STREAM_TYPE_VIDEO_VVC
int auto_guess
if true, all pids are analyzed to find streams
@ AV_CODEC_ID_DVB_TELETEXT
static void clear_avprogram(MpegTSContext *ts, unsigned int programid)
static char * getstr8(const uint8_t **pp, const uint8_t *p_end)
MpegTSSectionFilter section_filter
static const StreamType HLS_SAMPLE_ENC_types[]
#define DVB_EXTENSION_DESCRIPTOR
AVRational framerate
Number of frames per second, for streams with constant frame durations.
#define AV_LOG_VERBOSE
Detailed information.
void(* filter)(uint8_t *src, int stride, int qscale)
static unsigned int nb_streams
static AVBufferRef * buffer_pool_get(MpegTSContext *ts, int size)
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
#define DOVI_VIDEO_STREAM_DESCRIPTOR
see "Dolby Vision Streams Within the MPEG-2 Transport Stream Format" https://professional....
void ffio_init_read_context(FFIOContext *s, const uint8_t *buffer, int buffer_size)
Wrap a buffer in an AVIOContext for reading.
void SetServiceCallback(void *opaque, int ret)
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
Return the next frame of a stream.
#define AV_PROFILE_ARIB_PROFILE_C
@ AV_CODEC_ID_HDMV_PGS_SUBTITLE
void ff_read_frame_flush(AVFormatContext *s)
Flush the frame reader.
static void add_pid_to_program(struct Program *p, unsigned int pid)
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
#define STREAM_TYPE_VIDEO_JPEGXS
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
unsigned int nb_prg
structure to keep track of Program->pids mapping
#define ENHANCED_AC3_DESCRIPTOR
struct Stream streams[MAX_STREAMS_PER_PROGRAM]
#define STREAM_TYPE_AUDIO_MPEG2
int pcr_pid
if -1 then all packets containing PCR are considered
void * av_memdup(const void *p, size_t size)
Duplicate a buffer with av_malloc().
@ AV_PKT_DATA_DOVI_CONF
DOVI configuration ref: dolby-vision-bitstreams-within-the-iso-base-media-file-format-v2....
static void skip_bits(GetBitContext *s, int n)
enum AVColorPrimaries color_primaries
#define PROBE_PACKET_MAX_BUF
static const AVClass mpegtsraw_class
#define AV_PROFILE_ARIB_PROFILE_A
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
@ AV_FIELD_TT
Top coded_first, top displayed first.
MpegTSPESFilter pes_filter
#define STREAM_TYPE_HLS_SE_AUDIO_AC3
#define METADATA_DESCRIPTOR
#define REGISTRATION_DESCRIPTOR
static int mpegts_read_close(AVFormatContext *s)
static int mpegts_raw_read_packet(AVFormatContext *s, AVPacket *pkt)
static AVStream * find_matching_stream(MpegTSContext *ts, int pid, unsigned int programid, int stream_identifier, int pmt_stream_idx, struct Program *p)
static void update_av_program_info(AVFormatContext *s, unsigned int programid, unsigned int pid, int version)
int PESCallback(MpegTSFilter *f, const uint8_t *buf, int len, int is_start, int64_t pos)
#define VIDEO_STREAM_DESCRIPTOR
#define STREAM_TYPE_VIDEO_AVS2
#define STREAM_TYPE_VIDEO_AVS3
#define STREAM_ID_DSMCC_STREAM
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.
static void pat_cb(MpegTSFilter *filter, const uint8_t *section, int section_len)
uint8_t dv_md_compression
static int mp4_read_iods(AVFormatContext *s, const uint8_t *buf, unsigned size, Mp4Descr *descr, int *descr_count, int max_descr_count)
enum AVDiscard discard
selects which program to discard and which to feed to the caller
static av_cold int read_close(AVFormatContext *ctx)
#define STREAM_TYPE_ATSC_AUDIO_EAC3
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
static double val(void *priv, double ch)
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
#define STREAM_TYPE_HLS_SE_AUDIO_EAC3
AVProgram * av_new_program(AVFormatContext *ac, int id)
@ AV_CODEC_ID_MP3
preferred ID for decoding MPEG audio layer 1, 2 or 3
#define STREAM_TYPE_VIDEO_JPEG2000
#define STREAM_ID_METADATA_STREAM
@ AV_CODEC_ID_DVB_SUBTITLE
AVStream * sub_st
stream for the embedded AC3 stream in HDMV TrueHD
void ff_mp4_parse_es_descr(AVIOContext *pb, int *es_id)
enum AVColorTransferCharacteristic color_trc
uint8_t header[MAX_PES_HEADER_SIZE]
#define SUBTITLING_DESCRIPTOR
unsigned int avio_rb32(AVIOContext *s)
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
void avpriv_mpegts_parse_close(MpegTSContext *ts)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define STREAM_TYPE_BLURAY_AUDIO_AC3
#define FF_ARRAY_ELEMS(a)
#define AV_PKT_FLAG_CORRUPT
The packet content is corrupted.
#define AV_PROFILE_UNKNOWN
static const uint8_t opus_coupled_stream_cnt[9]
static const struct TransferCharacteristics transfer_characteristics[]
int ctx_flags
Flags signalling stream properties.
static int parse_pcr(int64_t *ppcr_high, int *ppcr_low, const uint8_t *packet)
AVBufferRef * av_buffer_pool_get(AVBufferPool *pool)
Allocate a new AVBuffer, reusing an old buffer from the pool when available.
@ AV_CODEC_ID_MPEG4SYSTEMS
FAKE codec to indicate a MPEG-4 Systems stream (only used by libavformat)
#define STREAM_TYPE_VIDEO_MPEG4
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
static av_unused int64_t mpegts_get_pcr(AVFormatContext *s, int stream_index, int64_t *ppos, int64_t pos_limit)
static const AVClass mpegts_class
#define TELETEXT_DESCRIPTOR
int width
The width of the video frame in pixels.
#define STREAM_TYPE_SCTE_DATA_SCTE_35
#define STREAM_TYPE_ISO_IEC_14496_PES
ISO/IEC 14496-1 (MPEG-4 Systems) SL-packetized stream or FlexMux stream carried in PES packets.
#define fc(width, name, range_min, range_max)
#define STREAM_TYPE_BLURAY_AUDIO_TRUEHD
#define av_assert0(cond)
assert() equivalent, that is always enabled.
const FFInputFormat ff_mpegtsraw_demuxer
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
static MpegTSFilter * mpegts_open_filter(MpegTSContext *ts, unsigned int pid, enum MpegTSFilterType type)
#define STREAM_ID_TYPE_E_STREAM
static int parse_MP4IODescrTag(MP4DescrParseContext *d, int64_t off, int len)
static int skip_identical(const SectionHeader *h, MpegTSSectionFilter *tssf)
static const uint8_t opus_stream_cnt[9]
int nb_coded_side_data
Amount of entries in coded_side_data.
@ AVMEDIA_TYPE_DATA
Opaque data information usually continuous.
#define STREAM_TYPE_VIDEO_MPEG1
@ AV_PIX_FMT_YUV444P10LE
planar YUV 4:4:4, 30bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
static int get8(const uint8_t **pp, const uint8_t *p_end)
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
@ AV_CODEC_ID_ARIB_CAPTION
int64_t cur_pcr
used to estimate the exact PCR
static void clear_programs(MpegTSContext *ts)
enum AVStreamParseType need_parsing
@ AVDISCARD_ALL
discard all
int64_t pcr_incr
used to estimate the exact PCR
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
AVCodecParameters * codecpar
Codec parameters associated with this stream.
#define LIBAVUTIL_VERSION_INT
Describe the class of an AVClass context structure.
#define STREAM_TYPE_ATSC_AUDIO_AC3
uint8_t dv_bl_signal_compatibility_id
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
int stop_parse
stop parsing loop
int64_t last_pos
to detect seek
static const StreamType DESC_types[]
#define STREAM_TYPE_BLURAY_AUDIO_EAC3_SECONDARY
const char * av_default_item_name(void *ptr)
Return the context name.
static unsigned int get_bits1(GetBitContext *s)
static void eit_cb(MpegTSFilter *filter, const uint8_t *section, int section_len)
void av_buffer_pool_uninit(AVBufferPool **ppool)
Mark the pool as being available for freeing.
enum MpegTSFilterType type
static MpegTSFilter * mpegts_open_pcr_filter(MpegTSContext *ts, unsigned int pid)
This structure contains the data a format has to probe a file.
static void seek_back(AVFormatContext *s, AVIOContext *pb, int64_t pos)
@ AV_CODEC_ID_MPEG2TS
FAKE codec to indicate a raw MPEG-2 TS stream (only used by libavformat)
static PESContext * add_pes_stream(MpegTSContext *ts, int pid, int pcr_pid)
#define AV_DICT_DONT_OVERWRITE
Don't overwrite existing entries.
#define JXS_VIDEO_DESCRIPTOR
#define STREAM_TYPE_HLS_SE_VIDEO_H264
struct StreamGroup stream_groups[MAX_STREAMS_PER_PROGRAM]
static MpegTSFilter * mpegts_open_section_filter(MpegTSContext *ts, unsigned int pid, SectionCallback *section_cb, void *opaque, int check_crc)
#define LCEVC_LINKAGE_DESCRIPTOR
#define EXTENSION_DESCRIPTOR
static MpegTSFilter * mpegts_open_pes_filter(MpegTSContext *ts, unsigned int pid, PESCallback *pes_cb, void *opaque)
#define STREAM_TYPE_VIDEO_MVC
static int init_MP4DescrParseContext(MP4DescrParseContext *d, AVFormatContext *s, const uint8_t *buf, unsigned size, Mp4Descr *descr, int max_descr_count)
#define MAX_PES_HEADER_SIZE
#define MAX_PACKET_READAHEAD
#define MAX_PIDS_PER_PROGRAM
unsigned int end_of_section_reached
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
static int parse_MP4ODescrTag(MP4DescrParseContext *d, int64_t off, int len)
int ff_mp4_read_descr(void *logctx, AVIOContext *pb, int *tag)
static int mpegts_push_data(MpegTSFilter *filter, const uint8_t *buf, int buf_size, int is_start, int64_t pos)
static void new_data_packet(const uint8_t *buffer, int len, AVPacket *pkt)
AVCodecID
Identify the syntax and semantics of the bitstream.
int avformat_stream_group_add_stream(AVStreamGroup *stg, AVStream *st)
Add an already allocated stream to a stream group.
int extradata_size
Size of the extradata content in bytes.
static const StreamType SCTE_types[]
union MpegTSFilter::@493 u
const EXTERN FFInputFormat ff_mpegts_demuxer
static void create_stream_groups(MpegTSContext *ts, const struct Program *prg)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
#define STREAM_TYPE_VIDEO_HEVC
static void reset_pes_packet_state(PESContext *pes)
@ AV_PIX_FMT_YUV422P10LE
planar YUV 4:2:2, 20bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
#define i(width, name, range_min, range_max)
#define FF_INFMT_FLAG_PREFER_CODEC_FRAMERATE
#define AV_NOPTS_VALUE
Undefined timestamp value.
int raw_packet_size
raw packet size, including FEC if present
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
static void finished_reading_packet(AVFormatContext *s, int raw_packet_size)
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
#define STREAM_ID_PRIVATE_STREAM_2
int profile
Codec-specific bitstream restrictions that the stream conforms to.
static int64_t mpegts_get_dts(AVFormatContext *s, int stream_index, int64_t *ppos, int64_t pos_limit)
static int mpegts_read_packet(AVFormatContext *s, AVPacket *pkt)
int ff_find_stream_index(const AVFormatContext *s, int id)
Find stream index based on format-specific stream ID.
static int parse_MP4ESDescrTag(MP4DescrParseContext *d, int64_t off, int len)
#define STREAM_IDENTIFIER_DESCRIPTOR
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
#define STREAM_TYPE_AUDIO_MPEG4
ISO/IEC 14496-3 Audio, without using any additional transport syntax, such as DST,...
int avio_r8(AVIOContext *s)
int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
Allocate, reallocate an array through a pointer to a pointer.
#define STREAM_TYPE_VIDEO_MPEG2
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.
void SectionCallback(MpegTSFilter *f, const uint8_t *buf, int len)
AVPacketSideData * av_packet_side_data_add(AVPacketSideData **psd, int *pnb_sd, enum AVPacketSideDataType type, void *data, size_t size, int flags)
Wrap existing data as packet side data.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
int pts_wrap_behavior
Options for behavior, when a wrap is detected.
unsigned int lcevc_index
Index of the LCEVC data stream in AVStreamGroup.
struct AVStreamGroupLCEVC * lcevc
int flags
A combination of AV_PKT_FLAG values.
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
static int read_header(FFV1Context *f, RangeCoder *c)
#define xf(width, name, var, range_min, range_max, subs,...)
int probe_packets
Number of packets to buffer for codec probing.
static int handle_packet(MpegTSContext *ts, const uint8_t *packet, int64_t pos)
#define STREAM_TYPE_AUDIO_AAC_LATM
#define DATA_COMPONENT_DESCRIPTOR
#define AV_LOG_INFO
Standard information.
static void update_offsets(AVIOContext *pb, int64_t *off, int *len)
static uint64_t get_bits64(GetBitContext *s, int n)
Read 0-64 bits.
static int is_pes_stream(int stream_type, uint32_t prog_reg_desc)
#define LCEVC_VIDEO_DESCRIPTOR
#define STREAM_TYPE_VIDEO_DIRAC
#define ISO_639_LANGUAGE_DESCRIPTOR
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
static int parse_stream_identifier_desc(const uint8_t *p, const uint8_t *p_end)
#define MAX_MP4_DESCR_COUNT
static struct Program * get_program(MpegTSContext *ts, unsigned int programid)
int height
The height of the video frame in pixels.
#define STREAM_TYPE_BLURAY_SUBTITLE_TEXT
MpegTSFilter * pids[NB_PID_MAX]
filters for various streams specified by PMT + for the PAT and PMT
static int get16(const uint8_t **pp, const uint8_t *p_end)
static int parse_section_header(SectionHeader *h, const uint8_t **pp, const uint8_t *p_end)
@ AV_FIELD_BB
Bottom coded first, bottom displayed first.
static int mpegts_resync(AVFormatContext *s, int seekback, const uint8_t *current_packet)
int8_t crc_validity[NB_PID_MAX]
#define STREAM_TYPE_BLURAY_AUDIO_DTS_HD_MASTER
@ 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...
New fields can be added to the end with minor version bumps.
static int handle_packets(MpegTSContext *ts, int64_t nb_packets)
union AVStreamGroup::@447 params
Group type-specific parameters.
enum AVColorRange color_range
Additional colorspace characteristics.
#define STREAM_TYPE_BLURAY_AUDIO_DTS_HD
AVPacketSideData * coded_side_data
Additional data associated with the entire stream.
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
#define SERVICE_DESCRIPTOR
enum AVFieldOrder field_order
The order of the fields in interlaced video.
static void check_crc(const AVCRC *table_new, const char *name, unsigned idx)
#define STREAM_TYPE_PRIVATE_SECTION
Undefined Behavior In the C language
#define STREAM_TYPE_BLURAY_AUDIO_DTS_EXPRESS_SECONDARY
int disposition
Stream disposition - a combination of AV_DISPOSITION_* flags.
#define SUPPLEMENTARY_AUDIO_DESCRIPTOR
int id
Format-specific stream ID.
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
#define FFSWAP(type, a, b)
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
uint8_t * dec_config_descr
unsigned int avio_rb16(AVIOContext *s)
#define STREAM_TYPE_BLURAY_AUDIO_EAC3
static int mp4_read_od(AVFormatContext *s, const uint8_t *buf, unsigned size, Mp4Descr *descr, int *descr_count, int max_descr_count)
static void scte_data_cb(MpegTSFilter *filter, const uint8_t *section, int section_len)
#define STREAM_TYPE_HLS_SE_AUDIO_AAC
static void m4sl_cb(MpegTSFilter *filter, const uint8_t *section, int section_len)
#define AV_INPUT_BUFFER_PADDING_SIZE
Tag MUST be and< 10hcoeff half pel interpolation filter coefficients, hcoeff[0] are the 2 middle coefficients[1] are the next outer ones and so on, resulting in a filter like:...eff[2], hcoeff[1], hcoeff[0], hcoeff[0], hcoeff[1], hcoeff[2] ... the sign of the coefficients is not explicitly stored but alternates after each coeff and coeff[0] is positive, so ...,+,-,+,-,+,+,-,+,-,+,... hcoeff[0] is not explicitly stored but found by subtracting the sum of all stored coefficients with signs from 32 hcoeff[0]=32 - hcoeff[1] - hcoeff[2] - ... a good choice for hcoeff and htaps is htaps=6 hcoeff={40,-10, 2} an alternative which requires more computations at both encoder and decoder side and may or may not be better is htaps=8 hcoeff={42,-14, 6,-2}ref_frames minimum of the number of available reference frames and max_ref_frames for example the first frame after a key frame always has ref_frames=1spatial_decomposition_type wavelet type 0 is a 9/7 symmetric compact integer wavelet 1 is a 5/3 symmetric compact integer wavelet others are reserved stored as delta from last, last is reset to 0 if always_reset||keyframeqlog quality(logarithmic quantizer scale) stored as delta from last, last is reset to 0 if always_reset||keyframemv_scale stored as delta from last, last is reset to 0 if always_reset||keyframe FIXME check that everything works fine if this changes between framesqbias dequantization bias stored as delta from last, last is reset to 0 if always_reset||keyframeblock_max_depth maximum depth of the block tree stored as delta from last, last is reset to 0 if always_reset||keyframequant_table quantization tableHighlevel bitstream structure:==============================--------------------------------------------|Header|--------------------------------------------|------------------------------------|||Block0||||split?||||yes no||||......... intra?||||:Block01 :yes no||||:Block02 :....... ..........||||:Block03 ::y DC ::ref index:||||:Block04 ::cb DC ::motion x :||||......... :cr DC ::motion y :||||....... ..........|||------------------------------------||------------------------------------|||Block1|||...|--------------------------------------------|------------ ------------ ------------|||Y subbands||Cb subbands||Cr subbands||||--- ---||--- ---||--- ---|||||LL0||HL0||||LL0||HL0||||LL0||HL0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||LH0||HH0||||LH0||HH0||||LH0||HH0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HL1||LH1||||HL1||LH1||||HL1||LH1|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HH1||HL2||||HH1||HL2||||HH1||HL2|||||...||...||...|||------------ ------------ ------------|--------------------------------------------Decoding process:=================------------|||Subbands|------------||||------------|Intra DC||||LL0 subband prediction ------------|\ Dequantization ------------------- \||Reference frames|\ IDWT|------- -------|Motion \|||Frame 0||Frame 1||Compensation . OBMC v -------|------- -------|--------------. \------> Frame n output Frame Frame<----------------------------------/|...|------------------- Range Coder:============Binary Range Coder:------------------- The implemented range coder is an adapted version based upon "Range encoding: an algorithm for removing redundancy from a digitised message." by G. N. N. Martin. The symbols encoded by the Snow range coder are bits(0|1). The associated probabilities are not fix but change depending on the symbol mix seen so far. bit seen|new state ---------+----------------------------------------------- 0|256 - state_transition_table[256 - old_state];1|state_transition_table[old_state];state_transition_table={ 0, 0, 0, 0, 0, 0, 0, 0, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 190, 191, 192, 194, 194, 195, 196, 197, 198, 199, 200, 201, 202, 202, 204, 205, 206, 207, 208, 209, 209, 210, 211, 212, 213, 215, 215, 216, 217, 218, 219, 220, 220, 222, 223, 224, 225, 226, 227, 227, 229, 229, 230, 231, 232, 234, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 248, 0, 0, 0, 0, 0, 0, 0};FIXME Range Coding of integers:------------------------- FIXME Neighboring Blocks:===================left and top are set to the respective blocks unless they are outside of the image in which case they are set to the Null block top-left is set to the top left block unless it is outside of the image in which case it is set to the left block if this block has no larger parent block or it is at the left side of its parent block and the top right block is not outside of the image then the top right block is used for top-right else the top-left block is used Null block y, cb, cr are 128 level, ref, mx and my are 0 Motion Vector Prediction:=========================1. the motion vectors of all the neighboring blocks are scaled to compensate for the difference of reference frames scaled_mv=(mv *(256 *(current_reference+1)/(mv.reference+1))+128)> the median of the scaled left
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
#define TS_MAX_PACKET_SIZE
#define STREAM_TYPE_BLURAY_AUDIO_PCM_BLURAY
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.
int index
stream index in AVFormatContext
#define R8_CHECK_CLIP_MAX(dst, maxv)
static int probe(const AVProbeData *p)
static int mpegts_probe(const AVProbeData *p)
unsigned int nb_streams
Number of elements in AVStreamGroup.streams.
#define STREAM_TYPE_VIDEO_H264
static void clear_program(struct Program *p)
#define AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, size_t size)
Allocate new information of a packet.
the frame and frame reference mechanism is intended to as much as expensive copies of that data while still allowing the filters to produce correct results The data is stored in buffers represented by AVFrame structures Several references can point to the same frame buffer
uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length)
Calculate the CRC of a block.
@ AV_OPT_TYPE_INT
Underlying C type is int.
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
#define STREAM_TYPE_VIDEO_CAVS
static int parse_MP4SLDescrTag(MP4DescrParseContext *d, int64_t off, int len)
MpegTSContext * avpriv_mpegts_parse_open(AVFormatContext *s)
static void mpegts_free(MpegTSContext *ts)
static const StreamType HDMV_types[]
IDirect3DDxgiInterfaceAccess _COM_Outptr_ void ** p
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
static const StreamType ISO_types[]
enum AVStreamGroupParamsType type
#define AV_OPT_FLAG_DECODING_PARAM
A generic parameter which can be set by the user for demuxing or decoding.
static int read_probe(const AVProbeData *p)
static int read_sl_header(PESContext *pes, SLConfigDescr *sl, const uint8_t *buf, int buf_size)
A reference to a data buffer.
AVPacket * pkt
packet containing Audio/Video data
static int mpegts_read_header(AVFormatContext *s)
#define avpriv_request_sample(...)
#define STREAM_TYPE_METADATA
#define STREAM_TYPE_VIDEO_LCEVC
AVStreamGroup * avformat_stream_group_create(AVFormatContext *s, enum AVStreamGroupParamsType type, AVDictionary **options)
Add a new empty stream group to a media file.
int request_probe
stream probing state -1 -> probing finished 0 -> no probing requested rest -> perform probing with re...
#define STREAM_ID_ECM_STREAM
unsigned int nb_stream_groups
Number of elements in AVFormatContext.stream_groups.
#define TS_FEC_PACKET_SIZE
unsigned int nb_stream_groups
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
#define MAX_STREAMS_PER_PROGRAM
This structure stores compressed data.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
#define STREAM_ID_PROGRAM_STREAM_DIRECTORY
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
int64_t pos
byte position in stream, -1 if unknown
int predefined_SLConfigDescriptor_seen
int stream_identifier
Stream Identifier This is the MPEG-TS stream identifier +1 0 means unknown.
#define STREAM_TYPE_ISO_IEC_14496_SECTION
ISO/IEC 14496-1 (MPEG-4 Systems) SL-packetized stream or FlexMux stream carried in ISO_IEC_14496_sect...
static const AVOption raw_options[]
int need_context_update
Whether the internal avctx needs to be updated from codecpar (after a late change to codecpar)
static const uint8_t opus_channel_map[8][8]
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
unsigned int pids[MAX_PIDS_PER_PROGRAM]
int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type, int prg_id, 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_mp4_descr(MP4DescrParseContext *d, int64_t off, int len, int target_tag)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define STREAM_TYPE_BLURAY_AUDIO_DTS
@ AV_CODEC_ID_HDMV_TEXT_SUBTITLE
SectionCallback * section_cb
#define MKTAG(a, b, c, d)
#define PROBE_PACKET_MARGIN
static int64_t read_timestamp(AVFormatContext *s, int stream_index, int64_t *ppos, int64_t pos_limit, int64_t(*read_timestamp)(struct AVFormatContext *, int, int64_t *, int64_t))
static uint64_t get_ts64(GetBitContext *gb, int bits)
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base.
static int get_packet_size(AVFormatContext *s)
static int analyze(const uint8_t *buf, int size, int packet_size, int probe)
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...
void ff_reduce_index(AVFormatContext *s, int stream_index)
Ensure the index uses less memory than the maximum specified in AVFormatContext.max_index_size by dis...
static int read_packet(AVFormatContext *s, uint8_t *buf, int raw_packet_size, const uint8_t **data)
int mpeg2ts_compute_pcr
compute exact PCR for each transport stream packet
static const StreamType REGD_types[]
static const StreamType MISC_types[]
#define STREAM_TYPE_BLURAY_SUBTITLE_PGS
@ AV_CODEC_ID_MPEG2VIDEO
preferred ID for MPEG-1/2 video decoding
static struct Program * add_program(MpegTSContext *ts, unsigned int programid)
static const AVOption options[]
int64_t ts_packet_pos
position of first TS packet of this PES packet
static int parse_mpeg2_extension_descriptor(AVFormatContext *fc, AVStream *st, int prg_id, const uint8_t **pp, const uint8_t *desc_end, MpegTSContext *ts)
int64_t pts_wrap_reference
Internal data to check for wrapping of the time stamp.
int avio_read_partial(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
static void BS_FUNC() skip(BSCTX *bc, unsigned int n)
Skip n bits in the buffer.
static void sdt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len)
int fix_teletext_pts
fix dvb teletext pts
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 avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.
@ AV_CODEC_ID_SCTE_35
Contain timestamp estimated through PCR of program stream.
enum AVMediaType codec_type