22 #include "libavutil/buffer.h"
23 #include "libavutil/crc.h"
24 #include "libavutil/intreadwrite.h"
25 #include "libavutil/log.h"
26 #include "libavutil/dict.h"
27 #include "libavutil/mathematics.h"
28 #include "libavutil/opt.h"
41 #define MAX_RESYNC_SIZE 65536
43 #define MAX_PES_PAYLOAD 200 * 1024
45 #define MAX_MP4_DESCR_COUNT 16
47 #define MOD_UNLIKELY(modulus, dividend, divisor, prev_dividend) \
49 if ((prev_dividend) == 0 || (dividend) - (prev_dividend) != (divisor)) \
50 (modulus) = (dividend) % (divisor); \
51 (prev_dividend) = (dividend); \
62 int is_start, int64_t pos);
94 #define MAX_PIDS_PER_PROGRAM 64
141 {
"compute_pcr",
"Compute exact PCR for each transport stream packet.",
144 {
"ts_packetsize",
"Output option carrying the raw packet size.",
169 #define PES_START_SIZE 6
170 #define PES_HEADER_SIZE 9
171 #define MAX_PES_HEADER_SIZE (9 + 255)
201 for (i = 0; i < ts->
nb_prg; i++)
202 if (ts->
prg[i].
id == programid)
230 for (i = 0; i < ts->
nb_prg; i++) {
231 if (ts->
prg[i].
id == programid) {
255 int used = 0, discarded = 0;
266 for (i = 0; i < ts->
nb_prg; i++) {
268 for (j = 0; j < p->
nb_pids; j++) {
269 if (p->
pids[j] != pid)
283 return !used && discarded;
291 const uint8_t *buf,
int buf_size,
int is_start)
417 memset(stat, 0, packet_size *
sizeof(
int));
419 for (x = i = 0; i < size - 3; i++) {
420 if (buf[i] == 0x47 && !(buf[i + 1] & 0x80) && (buf[i + 3] & 0x30)) {
422 if (stat[x] > best_score) {
423 best_score = stat[x];
430 if (x == packet_size)
440 int score, fec_score, dvhs_score;
448 av_dlog(
NULL,
"score: %d, dvhs_score: %d, fec_score: %d \n",
449 score, dvhs_score, fec_score);
451 if (score > fec_score && score > dvhs_score)
453 else if (dvhs_score > score && dvhs_score > fec_score)
455 else if (score < fec_score && dvhs_score < fec_score)
488 if ((p + 1) >= p_end)
504 len =
get8(&p, p_end);
507 if ((p + len) > p_end)
524 val =
get8(pp, p_end);
529 val =
get16(pp, p_end);
533 val =
get8(pp, p_end);
536 h->
version = (val >> 1) & 0x1f;
537 val =
get8(pp, p_end);
541 val =
get8(pp, p_end);
612 uint32_t stream_type,
624 uint32_t stream_type, uint32_t prog_reg_desc)
635 "stream=%d stream_type=%x pid=%x prog_reg_desc=%.4s\n",
641 if (prog_reg_desc ==
AV_RL32(
"HDMV") &&
652 memcpy(sub_pes, pes,
sizeof(*sub_pes));
660 sub_st->
id = pes->
pid;
711 const uint8_t *buf,
int buf_size)
714 int au_start_flag = 0, au_end_flag = 0, ocr_flag = 0, idle_flag = 0;
715 int padding_flag = 0, padding_bits = 0, inst_bitrate_flag = 0;
716 int dts_flag = -1, cts_flag = -1;
725 au_start_flag = au_end_flag = 1;
735 if (!idle_flag && (!padding_flag || padding_bits != 0)) {
761 if (inst_bitrate_flag)
778 const uint8_t *buf,
int buf_size,
int is_start,
799 while (buf_size > 0) {
800 switch (pes->
state) {
815 code = pes->
header[3] | 0x100;
846 if (code != 0x1bc && code != 0x1bf &&
847 code != 0x1f0 && code != 0x1f1 &&
848 code != 0x1ff && code != 0x1f2 &&
853 "pid=%x stream_type=%x probing\n",
900 unsigned int flags, pes_ext, skip;
906 if ((flags & 0xc0) == 0x80) {
909 }
else if ((flags & 0xc0) == 0xc0) {
919 skip = (pes_ext >> 4) & 0xb;
922 if ((pes_ext & 0x41) == 0x01 &&
925 if ((r[0] & 0x7f) > 0 && (r[1] & 0x80) == 0)
937 p += sl_header_bytes;
938 buf_size -= sl_header_bytes;
943 if (buf_size > 0 && pes->
buffer) {
1020 Mp4Descr *descr,
int max_descr_count)
1023 if (size > (1 << 30))
1043 (*len) -= new_off - *off;
1079 if (!(id_flags & 0x0020)) {
1158 if (len < 0 || len1 > len || len1 <= 0) {
1160 "Tag %x length violation new length %d bytes remaining %d\n",
1170 if (target_tag && tag != target_tag) {
1202 Mp4Descr *descr,
int *descr_count,
int max_descr_count)
1218 Mp4Descr *descr,
int *descr_count,
int max_descr_count)
1240 int mp4_descr_count = 0;
1245 p_end = section + section_len - 4;
1252 mp4_read_od(s, p, (
unsigned) (p_end - p), mp4_descr, &mp4_descr_count,
1258 for (i = 0; i < mp4_descr_count; i++) {
1272 pes->
sl = mp4_descr[i].
sl;
1275 mp4_descr[i].dec_config_descr_len, 0,
1295 for (i = 0; i < mp4_descr_count; i++)
1296 av_free(mp4_descr[i].dec_config_descr);
1301 Mp4Descr *mp4_descr,
int mp4_descr_count,
int pid,
1305 int desc_len, desc_tag, desc_es_id;
1309 desc_tag =
get8(pp, desc_list_end);
1312 desc_len =
get8(pp, desc_list_end);
1315 desc_end = *pp + desc_len;
1316 if (desc_end > desc_list_end)
1319 av_dlog(fc,
"tag: 0x%02x len=%d\n", desc_tag, desc_len);
1327 desc_es_id =
get16(pp, desc_end);
1328 if (ts && ts->
pids[pid])
1330 for (i = 0; i < mp4_descr_count; i++)
1331 if (mp4_descr[i].dec_config_descr_len &&
1332 mp4_descr[i].es_id == desc_es_id) {
1335 mp4_descr[i].dec_config_descr_len, 0,
1346 get16(pp, desc_end);
1347 if (mp4_descr_count > 0 &&
1361 language[0] =
get8(pp, desc_end);
1362 language[1] =
get8(pp, desc_end);
1363 language[2] =
get8(pp, desc_end);
1368 language[0] =
get8(pp, desc_end);
1369 language[1] =
get8(pp, desc_end);
1370 language[2] =
get8(pp, desc_end);
1373 switch (
get8(pp, desc_end)) {
1398 for (i = 0; i + 4 <= desc_len; i += 4) {
1399 language[i + 0] =
get8(pp, desc_end);
1400 language[i + 1] =
get8(pp, desc_end);
1401 language[i + 2] =
get8(pp, desc_end);
1402 language[i + 3] =
',';
1403 switch (
get8(pp, desc_end)) {
1415 if (i && language[0]) {
1416 language[i - 1] = 0;
1439 const uint8_t *p, *p_end, *desc_list_end;
1440 int program_info_length, pcr_pid, pid, stream_type;
1442 uint32_t prog_reg_desc = 0;
1444 int mp4_descr_count = 0;
1451 p_end = section + section_len - 4;
1463 pcr_pid =
get16(&p, p_end);
1471 program_info_length =
get16(&p, p_end);
1472 if (program_info_length < 0)
1474 program_info_length &= 0xfff;
1475 while (program_info_length >= 2) {
1477 tag =
get8(&p, p_end);
1478 len =
get8(&p, p_end);
1480 av_dlog(ts->
stream,
"program tag: 0x%02x len=%d\n", tag, len);
1482 if (len > program_info_length - 2)
1485 program_info_length -= len + 2;
1492 }
else if (tag == 0x05 && len >= 4) {
1493 prog_reg_desc = bytestream_get_le32(&p);
1498 p += program_info_length;
1510 stream_type =
get8(&p, p_end);
1511 if (stream_type < 0)
1513 pid =
get16(&p, p_end);
1526 }
else if (stream_type != 0x13) {
1555 desc_list_len =
get16(&p, p_end);
1556 if (desc_list_len < 0)
1558 desc_list_len &= 0xfff;
1559 desc_list_end = p + desc_list_len;
1560 if (desc_list_end > p_end)
1564 desc_list_end, mp4_descr,
1565 mp4_descr_count, pid, ts) < 0)
1568 if (pes && prog_reg_desc ==
AV_RL32(
"HDMV") &&
1569 stream_type == 0x83 && pes->
sub_st) {
1579 for (i = 0; i < mp4_descr_count; i++)
1580 av_free(mp4_descr[i].dec_config_descr);
1593 p_end = section + section_len - 4;
1602 sid =
get16(&p, p_end);
1605 pmt_pid =
get16(&p, p_end);
1612 if (sid == 0x0000) {
1616 if (ts->
pids[pmt_pid])
1630 const uint8_t *p, *p_end, *desc_list_end, *desc_end;
1631 int onid, val, sid, desc_list_len, desc_tag, desc_len, service_type;
1632 char *
name, *provider_name;
1637 p_end = section + section_len - 4;
1643 onid =
get16(&p, p_end);
1646 val =
get8(&p, p_end);
1650 sid =
get16(&p, p_end);
1653 val =
get8(&p, p_end);
1656 desc_list_len =
get16(&p, p_end);
1657 if (desc_list_len < 0)
1659 desc_list_len &= 0xfff;
1660 desc_list_end = p + desc_list_len;
1661 if (desc_list_end > p_end)
1664 desc_tag =
get8(&p, desc_list_end);
1667 desc_len =
get8(&p, desc_list_end);
1668 desc_end = p + desc_len;
1669 if (desc_end > desc_list_end)
1673 desc_tag, desc_len);
1677 service_type =
get8(&p, p_end);
1678 if (service_type < 0)
1680 provider_name =
getstr8(&p, p_end);
1708 int len, pid, cc, expected_cc, cc_ok, afc, is_start, is_discontinuity,
1709 has_adaptation, has_payload;
1713 pid =
AV_RB16(packet + 1) & 0x1fff;
1716 is_start = packet[1] & 0x40;
1717 tss = ts->
pids[pid];
1720 tss = ts->
pids[pid];
1725 afc = (packet[3] >> 4) & 3;
1728 has_adaptation = afc & 2;
1729 has_payload = afc & 1;
1730 is_discontinuity = has_adaptation &&
1735 cc = (packet[3] & 0xf);
1736 expected_cc = has_payload ? (tss->
last_cc + 1) & 0x0f : tss->
last_cc;
1737 cc_ok = pid == 0x1FFF ||
1745 "Continuity check failed for pid %d expected %d got %d\n",
1746 pid, expected_cc, cc);
1756 if (has_adaptation) {
1772 if (p + len > p_end)
1821 "max resync size reached, could not find sync byte\n");
1838 if ((*data)[0] != 0x47) {
1865 int packet_num, ret = 0;
1891 if (nb_packets != 0 && packet_num >= nb_packets)
1908 int score, fec_score, dvhs_score;
1910 #define CHECK_COUNT 10
1921 av_dlog(
NULL,
"score: %d, dvhs_score: %d, fec_score: %d \n",
1922 score, dvhs_score, fec_score);
1926 if (score > fec_score && score > dvhs_score && score > 6)
1928 else if (dvhs_score > score && dvhs_score > fec_score && dvhs_score > 6)
1930 else if (fec_score > 6)
1944 afc = (packet[3] >> 4) & 3;
1954 if (!(flags & 0x10))
1959 *ppcr_high = ((int64_t) v << 1) | (p[4] >> 7);
1960 *ppcr_low = ((p[4] & 1) << 8) | p[5];
1977 if (len !=
sizeof(buf))
1985 if (s->
iformat == &ff_mpegts_demuxer) {
2006 int pcr_pid, pid, nb_packets, nb_pcrs, ret, pcr_l;
2007 int64_t pcrs[2], pcr_h;
2008 int packet_count[2];
2029 pid =
AV_RB16(data + 1) & 0x1fff;
2030 if ((pcr_pid == -1 || pcr_pid == pid) &&
2034 packet_count[nb_pcrs] = nb_packets;
2035 pcrs[nb_pcrs] = pcr_h * 300 + pcr_l;
2047 ts->
pcr_incr = (pcrs[1] - pcrs[0]) / (packet_count[1] - packet_count[0]);
2060 #define MAX_PACKET_READAHEAD ((128 * 1024) / 188)
2066 int64_t pcr_h, next_pcr_h, pos;
2067 int pcr_l, next_pcr_l;
2079 if (data != pkt->
data)
2090 if (
parse_pcr(&next_pcr_h, &next_pcr_l, pcr_buf) == 0) {
2093 ((next_pcr_h - pcr_h) * 300 + (next_pcr_l - pcr_l)) /
2100 ts->
cur_pcr = pcr_h * 300 + pcr_l;
2132 if (!ret && pkt->
size < 0)
2156 int64_t *ppos, int64_t pos_limit)
2159 int64_t pos, timestamp;
2161 int pcr_l, pcr_pid =
2163 const int find_next = 1;
2172 if ((pcr_pid < 0 || (
AV_RB16(buf + 1) & 0x1fff) == pcr_pid) &&
2173 parse_pcr(×tamp, &pcr_l, buf) == 0) {
2186 if ((pcr_pid < 0 || (
AV_RB16(buf + 1) & 0x1fff) == pcr_pid) &&
2187 parse_pcr(×tamp, &pcr_l, buf) == 0) {
2259 if (buf[0] != 0x47) {
2291 .
name =
"mpegtsraw",
2300 .priv_class = &mpegtsraw_class,
static void mpegts_free(MpegTSContext *ts)
codec_id is not known (like AV_CODEC_ID_NONE) but lavf should attempt to identify it ...
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it...
void av_free_packet(AVPacket *pkt)
Free a packet.
static int mpegts_resync(AVFormatContext *s)
void ff_mp4_parse_es_descr(AVIOContext *pb, int *es_id)
static void finished_reading_packet(AVFormatContext *s, int raw_packet_size)
A dummy id pointing at the start of audio codecs.
int64_t cur_pcr
used to estimate the exact PCR
#define MAX_PACKET_READAHEAD
enum AVMediaType codec_type
static int parse_MP4ODescrTag(MP4DescrParseContext *d, int64_t off, int len)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
#define AV_LOG_WARNING
Something somehow does not look correct.
static int handle_packet(MpegTSContext *ts, const uint8_t *packet)
int64_t pos
byte position in stream, -1 if unknown
static void clear_program(MpegTSContext *ts, unsigned int programid)
static void skip_bits_long(GetBitContext *s, int n)
static int mpegts_probe(AVProbeData *p)
AVCodecContext * codec
Codec context associated with this stream.
int index
stream index in AVFormatContext
MpegTSPESFilter pes_filter
enum AVMediaType codec_type
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
AVInputFormat ff_mpegts_demuxer
static void sdt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len)
A dummy ID pointing at the start of various fake codecs.
av_dlog(ac->avr,"%d samples - audio_convert: %s to %s (%s)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic?ac->func_descr_generic:ac->func_descr)
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)
int ctx_flags
Flags signalling stream properties.
int pcr_pid
if -1 then all packets containing PCR are considered
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
unsigned int nb_prg
structure to keep track of Program->pids mapping
void av_freep(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
static int read_packet(AVFormatContext *s, uint8_t *buf, int raw_packet_size, const uint8_t **data)
const AVCRC * av_crc_get_table(AVCRCId crc_id)
Get an initialized standard CRC table.
unsigned int pids[MAX_PIDS_PER_PROGRAM]
static int read_sl_header(PESContext *pes, SLConfigDescr *sl, const uint8_t *buf, int buf_size)
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
MpegTSFilter * pids[NB_PID_MAX]
filters for various streams specified by PMT + for the PAT and PMT
static int mpegts_read_header(AVFormatContext *s)
Opaque data information usually continuous.
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 stop_parse
stop parsing loop
static int parse_MP4ESDescrTag(MP4DescrParseContext *d, int64_t off, int len)
static int discard_pid(MpegTSContext *ts, unsigned int pid)
discard_pid() decides if the pid is to be discarded according to caller's programs selection ...
static void add_pat_entry(MpegTSContext *ts, unsigned int programid)
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
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
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)
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)
enum AVDiscard discard
selects which program to discard and which to feed to the caller
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
static PESContext * add_pes_stream(MpegTSContext *ts, int pid, int pcr_pid)
int duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
static MpegTSFilter * mpegts_open_pes_filter(MpegTSContext *ts, unsigned int pid, PESCallback *pes_cb, void *opaque)
AVInputFormat ff_mpegtsraw_demuxer
static int init_MP4DescrParseContext(MP4DescrParseContext *d, AVFormatContext *s, const uint8_t *buf, unsigned size, Mp4Descr *descr, int max_descr_count)
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
static uint64_t get_bits64(GetBitContext *s, int n)
int ff_mp4_read_dec_config_descr(AVFormatContext *fc, AVStream *st, AVIOContext *pb)
int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
AVCodecID
Identify the syntax and semantics of the bitstream.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
static const StreamType HDMV_types[]
void * priv_data
Format private data.
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. ...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
struct AVInputFormat * iformat
The input container format.
preferred ID for decoding MPEG audio layer 1, 2 or 3
#define TS_FEC_PACKET_SIZE
New fields can be added to the end with minor version bumps.
static int64_t ff_parse_pes_pts(const uint8_t *buf)
Parse MPEG-PES five-byte timestamp.
static int parse_MP4DecConfigDescrTag(MP4DescrParseContext *d, int64_t off, int len)
int flags
copied to the AVPacket flags
int pcr_incr
used to estimate the exact PCR
int flags
A combination of AV_PKT_FLAG values.
MpegTSContext * ff_mpegts_parse_open(AVFormatContext *s)
int buf_size
Size of buf except extra allocated bytes.
#define FF_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
static void filter(MpegAudioContext *s, int ch, const short *samples, int incr)
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
int bit_rate
the average bitrate
int64_t ts_packet_pos
position of first TS packet of this PES packet
SectionCallback * section_cb
uint8_t * data
The data buffer.
static const StreamType REGD_types[]
int PESCallback(MpegTSFilter *f, const uint8_t *buf, int len, int is_start, int64_t pos)
static const StreamType MISC_types[]
static 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
AVStream ** streams
A list of all streams in the file.
void * av_malloc(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
static int handle_packets(MpegTSContext *ts, int nb_packets)
AVProgram * av_new_program(AVFormatContext *s, int id)
static int mpegts_set_stream_info(AVStream *st, PESContext *pes, uint32_t stream_type, uint32_t prog_reg_desc)
static int parse_mp4_descr(MP4DescrParseContext *d, int64_t off, int len, int target_tag)
static int parse_MP4SLDescrTag(MP4DescrParseContext *d, int64_t off, int len)
int mpeg2ts_compute_pcr
compute exact PCR for each transport stream packet
static const AVClass mpegtsraw_class
MpegTSSectionFilter section_filter
unsigned int probesize
Maximum size of the data read from input for determining the input container format.
int ff_mpegts_parse_packet(MpegTSContext *ts, AVPacket *pkt, const uint8_t *buf, int len)
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)
if(ac->has_optimized_func)
FAKE codec to indicate a MPEG-4 Systems stream (only used by libavformat)
union MpegTSFilter::@115 u
#define TS_MAX_PACKET_SIZE
uint8_t * dec_config_descr
AVBufferRef * av_buffer_alloc(int size)
Allocate an AVBuffer of the given size using av_malloc().
enum AVMediaType codec_type
#define MP4DecConfigDescrTag
static int read_seek(AVFormatContext *s, int stream_index, int64_t target_ts, int flags)
static int parse_mp4_descr_arr(MP4DescrParseContext *d, int64_t off, int len)
static void new_pes_packet(PESContext *pes, AVPacket *pkt)
static int get_packet_size(const uint8_t *buf, int size)
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
AVIOContext * pb
I/O context.
#define STREAM_TYPE_PRIVATE_DATA
static int64_t mpegts_get_pcr(AVFormatContext *s, int stream_index, int64_t *ppos, int64_t pos_limit)
#define MAX_PES_HEADER_SIZE
static int get8(const uint8_t **pp, const uint8_t *p_end)
#define MOD_UNLIKELY(modulus, dividend, divisor, prev_dividend)
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 AVERROR_BUG
Bug detected, please report the issue.
#define MAX_PIDS_PER_PROGRAM
static unsigned int get_bits1(GetBitContext *s)
static int parse_pcr(int64_t *ppcr_high, int *ppcr_low, const uint8_t *packet)
Describe the class of an AVClass context structure.
static void skip_bits(GetBitContext *s, int n)
static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len)
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
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.
#define AV_OPT_FLAG_EXPORT
The option is inteded for exporting values to the caller.
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
#define MKTAG(a, b, c, d)
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.
#define AV_OPT_FLAG_DECODING_PARAM
a generic parameter which can be set by the user for demuxing or decoding
static void clear_programs(MpegTSContext *ts)
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_dlog(ac->avr,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> out
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)
void ff_mpegts_parse_close(MpegTSContext *ts)
#define AV_OPT_FLAG_READONLY
The option may not be set through the AVOptions API, only read.
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 stream time base.
int disposition
AV_DISPOSITION_* bit field.
int64_t pos
position corresponding to pos47, or 0 if pos47 invalid
uint8_t header[MAX_PES_HEADER_SIZE]
void av_init_packet(AVPacket *pkt)
Initialize optional fields of a packet with default values.
#define AV_PKT_FLAG_CORRUPT
The packet content is corrupted.
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)
int eof_reached
true if eof reached
AVPacket * pkt
packet containing Audio/Video data
int64_t last_pos
to detect seek
static int analyze(const uint8_t *buf, int size, int packet_size, int *index)
static void add_pid_to_pmt(MpegTSContext *ts, unsigned int programid, unsigned int pid)
uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length) av_pure
Calculate the CRC of a block.
void SetServiceCallback(void *opaque, int ret)
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
int bit_rate
Total stream bitrate in bit/s, 0 if not available.
static int parse_MP4IODescrTag(MP4DescrParseContext *d, int64_t off, int len)
static void m4sl_cb(MpegTSFilter *filter, const uint8_t *section, int section_len)
av_default_item_name
Return the context name.
#define MAX_MP4_DESCR_COUNT
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)
This structure stores compressed data.
static char * getstr8(const uint8_t **pp, const uint8_t *p_end)
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
A dummy ID pointing at the start of subtitle codecs.
#define AV_NOPTS_VALUE
Undefined timestamp value.
void * av_mallocz(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
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)