29 #define MAX_SYNC_SIZE 100000 34 int pes2 = (p[3] & 0xC0) == 0x80 &&
35 (p[4] & 0xC0) != 0x40 &&
36 ((p[4] & 0xC0) == 0x00 ||
37 (p[4] & 0xC0) >> 2 == (p[6] & 0xF0));
39 for (p += 3; p < end && *p == 0xFF; p++) ;
40 if ((*p & 0xC0) == 0x40)
43 if ((*p & 0xF0) == 0x20)
44 pes1 = p[0] & p[2] & p[4] & 1;
45 else if ((*p & 0xF0) == 0x30)
46 pes1 = p[0] & p[2] & p[4] & p[5] & p[7] & p[9] & 1;
55 return (buf[1] & 0xC0) == 0x40 || (buf[1] & 0xF0) == 0x20;
62 int sys = 0, pspack = 0, priv1 = 0, vid = 0;
63 int audio = 0, invalid = 0, score = 0;
66 code = (code << 8) + p->
buf[i];
67 if ((code & 0xffffff00) == 0x100) {
68 int len = p->
buf[i + 1] << 8 | p->
buf[i + 2];
76 else if ((code & 0xf0) ==
VIDEO_ID && pes)
80 else if ((code & 0xe0) ==
AUDIO_ID && pes) {
86 }
else if ((code & 0xf0) ==
VIDEO_ID && !pes)
88 else if ((code & 0xe0) ==
AUDIO_ID && !pes)
95 if (vid + audio > invalid)
98 if (sys > invalid && sys * 9 <= pspack * 10)
101 if (pspack > invalid && (priv1 + vid + audio) * 10 >= pspack * 9)
104 if ((!!vid ^ !!audio) && (audio > 4 || vid > 1) && !sys &&
105 !pspack && p->
buf_size > 2048 && vid + audio > invalid)
123 const char *
sofdec =
"Sofdec";
134 }
while (v == sofdec[i] && i++ < 6);
146 buf[0] = c < 0 ?
avio_r8(pb) : c;
155 unsigned int state, v;
165 if (state == 0x000001) {
166 state = ((state << 8) | v) & 0xffffff;
170 state = ((state << 8) | v) & 0xffffff;
175 *header_state =
state;
188 int psm_length, ps_info_length, es_map_length;
200 while (es_map_length >= 4) {
201 unsigned char type =
avio_r8(pb);
202 unsigned char es_id =
avio_r8(pb);
209 es_map_length -= 4 + es_info_length;
212 return 2 + psm_length;
219 int64_t *ppos,
int *pstart_code,
220 int64_t *ppts, int64_t *pdts)
224 int pes_ext, ext2_len, id_ext, skip;
258 m->
sofdec = !memcmp(buf,
"ofdec", 5);
274 if (!((startcode >= 0x1c0 && startcode <= 0x1df) ||
275 (startcode >= 0x1e0 && startcode <= 0x1ef) ||
276 (startcode == 0x1bd) || (startcode == 0x1fd)))
294 if ((c & 0xc0) == 0x40) {
300 if ((c & 0xe0) == 0x20) {
308 }
else if ((c & 0xc0) == 0x80) {
313 if (header_len > len)
324 if (flags & 0x3f && header_len == 0) {
333 skip = (pes_ext >> 4) & 0xb;
335 if (pes_ext & 0x40 || skip > header_len) {
342 if (pes_ext & 0x01) {
345 if ((ext2_len & 0x7f) > 0) {
347 if ((id_ext & 0x80) == 0)
348 startcode = ((startcode & 0xff) << 8) | id_ext;
362 if (startcode >= 0x80 && startcode <= 0xcf) {
368 if (startcode >= 0xb0 && startcode <= 0xbf) {
389 *pstart_code = startcode;
400 int len, startcode, i, es_type, ret;
403 int64_t
pts, dts, dummy_pos;
411 if (startcode == 0x1bd) {
412 dvdaudio_substream_type =
avio_r8(s->
pb);
420 if (st->
id == startcode)
451 }
else if (startcode >= 0x1e0 && startcode <= 0x1ef) {
452 static const unsigned char avs_seqh[4] = { 0, 0, 1, 0xb0 };
453 unsigned char buf[8];
457 if (!memcmp(buf, avs_seqh, 4) && (buf[6] != 0 || buf[7] != 1))
462 }
else if (startcode >= 0x1c0 && startcode <= 0x1df) {
465 }
else if (startcode >= 0x80 && startcode <= 0x87) {
468 }
else if ((startcode >= 0x88 && startcode <= 0x8f) ||
469 (startcode >= 0x98 && startcode <= 0x9f)) {
473 }
else if (startcode >= 0xa0 && startcode <= 0xaf) {
476 }
else if (startcode >= 0xb0 && startcode <= 0xbf) {
479 }
else if (startcode >= 0xc0 && startcode <= 0xcf) {
483 }
else if (startcode >= 0x20 && startcode <= 0x3f) {
486 }
else if (startcode >= 0xfd55 && startcode <= 0xfd5f) {
489 }
else if (startcode == 0x1bd) {
492 switch (dvdaudio_substream_type & 0xe0) {
497 if ((dvdaudio_substream_type & 0xf8) == 0x88)
528 pkt->
pos = dummy_pos;
534 return (ret < 0) ? ret : 0;
538 int64_t *ppos, int64_t pos_limit)
541 int64_t pos,
pts, dts;
553 if (startcode == s->
streams[stream_index]->
id &&
560 pos, dts, dts / 90000.0);
codec_id is not known (like AV_CODEC_ID_NONE) but lavf should attempt to identify it ...
#define STREAM_TYPE_AUDIO_MPEG2
int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp, int size, int distance, int flags)
Add an index entry into a sorted list.
#define AV_LOG_WARNING
Something somehow does not look correct.
int64_t pos
byte position in stream, -1 if unknown
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
int index
stream index in AVFormatContext
av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (%s)\, 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)
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
static int mpegps_read_pes_header(AVFormatContext *s, int64_t *ppos, int *pstart_code, int64_t *ppts, int64_t *pdts)
#define STREAM_TYPE_VIDEO_MPEG1
unsigned int avio_rb16(AVIOContext *s)
int ctx_flags
Flags signalling stream properties.
static int mpegps_read_header(AVFormatContext *s)
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
unsigned int avio_rb32(AVIOContext *s)
enum AVStreamParseType need_parsing
int id
Format-specific stream ID.
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
AVStream ** streams
A list of all streams in the file.
#define SYSTEM_HEADER_START_CODE
#define AVERROR_EOF
End of file.
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
static int64_t mpegps_read_dts(AVFormatContext *s, int stream_index, int64_t *ppos, int64_t pos_limit)
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
#define STREAM_TYPE_AUDIO_AAC
AVCodecID
Identify the syntax and semantics of the bitstream.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static int check_pack_header(const uint8_t *buf)
preferred ID for decoding MPEG audio layer 1, 2 or 3
enum AVMediaType codec_type
General type of the encoded data.
static int64_t ff_parse_pes_pts(const uint8_t *buf)
Parse MPEG-PES five-byte timestamp.
int avio_r8(AVIOContext *s)
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.
static int check_pes(uint8_t *p, uint8_t *end)
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.
#define STREAM_TYPE_VIDEO_H264
static int find_next_start_code(AVIOContext *pb, int *size_ptr, int32_t *header_state)
static long mpegps_psm_parse(MpegDemuxContext *m, AVIOContext *pb)
Extract stream types from a program stream map According to ISO/IEC 13818-1 ('MPEG-2 Systems') table ...
static av_always_inline int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
preferred ID for MPEG-1/2 video decoding
#define STREAM_TYPE_VIDEO_MPEG4
unsigned char psm_es_type[256]
static int read_header(FFV1Context *f)
if(ac->has_optimized_func)
AVIOContext * pb
I/O context.
#define STREAM_TYPE_PRIVATE_DATA
static int read_packet(AVFormatContext *ctx, AVPacket *pkt)
#define PROGRAM_STREAM_MAP
#define STREAM_TYPE_AUDIO_AC3
This structure contains the data a format has to probe a file.
static int64_t get_pts(AVIOContext *pb, int c)
static int64_t pts
Global timestamp for the audio frames.
static int mpegps_read_packet(AVFormatContext *s, AVPacket *pkt)
int eof_reached
true if eof reached
#define STREAM_TYPE_VIDEO_MPEG2
void * priv_data
Format private data.
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
AVCodecParameters * codecpar
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
#define STREAM_TYPE_AUDIO_MPEG1
This structure stores compressed data.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
#define AV_NOPTS_VALUE
Undefined timestamp value.
AVInputFormat ff_mpegps_demuxer
static int mpegps_probe(AVProbeData *p)