32 #define MAX_SYNC_SIZE 100000
37 int pes2 = (p[3] & 0xC0) == 0x80 &&
38 (p[4] & 0xC0) != 0x40 &&
39 ((p[4] & 0xC0) == 0x00 ||
40 (p[4] & 0xC0) >> 2 == (p[6] & 0xF0));
42 for (p += 3; p < end && *p == 0xFF; p++) ;
43 if ((*p & 0xC0) == 0x40)
46 if ((*p & 0xF0) == 0x20)
47 pes1 = p[0] & p[2] & p[4] & 1;
48 else if ((*p & 0xF0) == 0x30)
49 pes1 = p[0] & p[2] & p[4] & p[5] & p[7] & p[9] & 1;
58 return (buf[1] & 0xC0) == 0x40 || (buf[1] & 0xF0) == 0x20;
65 int sys = 0, pspack = 0, priv1 = 0, vid = 0;
66 int audio = 0, invalid = 0, score = 0;
69 code = (code << 8) + p->
buf[i];
70 if ((code & 0xffffff00) == 0x100) {
71 int len = p->
buf[i + 1] << 8 | p->
buf[i + 2];
79 else if ((code & 0xf0) ==
VIDEO_ID && pes)
83 else if ((code & 0xe0) ==
AUDIO_ID && pes) {
89 }
else if ((code & 0xf0) ==
VIDEO_ID && !pes)
91 else if ((code & 0xe0) ==
AUDIO_ID && !pes)
98 if (vid + audio > invalid)
101 if (sys > invalid && sys * 9 <= pspack * 10)
104 if (pspack > invalid && (priv1 + vid + audio) * 10 >= pspack * 9)
107 if ((!!vid ^ !!audio) && (audio > 4 || vid > 1) && !sys &&
108 !pspack && p->
buf_size > 2048 && vid + audio > invalid)
126 const char *sofdec =
"Sofdec";
137 }
while (v == sofdec[i] && i++ < 6);
149 buf[0] = c < 0 ?
avio_r8(pb) : c;
158 unsigned int state, v;
161 state = *header_state;
168 if (state == 0x000001) {
169 state = ((state << 8) | v) & 0xffffff;
173 state = ((state << 8) | v) & 0xffffff;
178 *header_state =
state;
191 int psm_length, ps_info_length, es_map_length;
203 while (es_map_length >= 4) {
204 unsigned char type =
avio_r8(pb);
205 unsigned char es_id =
avio_r8(pb);
212 es_map_length -= 4 + es_info_length;
215 return 2 + psm_length;
222 int64_t *ppos,
int *pstart_code,
223 int64_t *ppts, int64_t *pdts)
227 int pes_ext, ext2_len, id_ext, skip;
261 m->
sofdec = !memcmp(buf,
"ofdec", 5);
277 if (!((startcode >= 0x1c0 && startcode <= 0x1df) ||
278 (startcode >= 0x1e0 && startcode <= 0x1ef) ||
279 (startcode == 0x1bd) || (startcode == 0x1fd)))
297 if ((c & 0xc0) == 0x40) {
303 if ((c & 0xe0) == 0x20) {
311 }
else if ((c & 0xc0) == 0x80) {
316 if (header_len > len)
327 if (flags & 0x3f && header_len == 0) {
336 skip = (pes_ext >> 4) & 0xb;
338 if (pes_ext & 0x40 || skip > header_len) {
345 if (pes_ext & 0x01) {
348 if ((ext2_len & 0x7f) > 0) {
350 if ((id_ext & 0x80) == 0)
351 startcode = ((startcode & 0xff) << 8) | id_ext;
365 if (startcode >= 0x80 && startcode <= 0xcf) {
371 if (startcode >= 0xb0 && startcode <= 0xbf) {
392 *pstart_code = startcode;
403 int len, startcode, i, es_type, ret;
406 int64_t pts, dts, dummy_pos;
414 if (startcode == 0x1bd) {
415 dvdaudio_substream_type =
avio_r8(s->
pb);
423 if (st->
id == startcode)
454 }
else if (startcode >= 0x1e0 && startcode <= 0x1ef) {
455 static const unsigned char avs_seqh[4] = { 0, 0, 1, 0xb0 };
456 unsigned char buf[8];
460 if (!memcmp(buf, avs_seqh, 4) && (buf[6] != 0 || buf[7] != 1))
465 }
else if (startcode >= 0x1c0 && startcode <= 0x1df) {
468 }
else if (startcode >= 0x80 && startcode <= 0x87) {
471 }
else if ((startcode >= 0x88 && startcode <= 0x8f) ||
472 (startcode >= 0x98 && startcode <= 0x9f)) {
476 }
else if (startcode >= 0xa0 && startcode <= 0xaf) {
479 }
else if (startcode >= 0xb0 && startcode <= 0xbf) {
482 }
else if (startcode >= 0xc0 && startcode <= 0xcf) {
486 }
else if (startcode >= 0x20 && startcode <= 0x3f) {
489 }
else if (startcode >= 0xfd55 && startcode <= 0xfd5f) {
492 }
else if (startcode == 0x1bd) {
495 switch (dvdaudio_substream_type & 0xe0) {
500 if ((dvdaudio_substream_type & 0xf8) == 0x88)
531 pkt->
pos = dummy_pos;
533 av_dlog(s,
"%d: pts=%0.3f dts=%0.3f size=%d\n",
537 return (ret < 0) ? ret : 0;
541 int64_t *ppos, int64_t pos_limit)
544 int64_t pos, pts, dts;
553 av_dlog(s,
"none (ret=%d)\n", len);
556 if (startcode == s->
streams[stream_index]->
id &&
562 av_dlog(s,
"pos=0x%"PRIx64
" dts=0x%"PRIx64
" %0.3f\n",
563 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
AVCodecContext * codec
Codec context associated with this stream.
int index
stream index in AVFormatContext
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...
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 mpegps_read_pes_header(AVFormatContext *s, int64_t *ppos, int *pstart_code, int64_t *ppts, int64_t *pdts)
#define STREAM_TYPE_VIDEO_MPEG1
int ctx_flags
Flags signalling stream properties.
static int mpegps_read_header(AVFormatContext *s)
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
enum AVStreamParseType need_parsing
int id
Format-specific stream ID.
#define SYSTEM_HEADER_START_CODE
#define AVERROR_EOF
End of file.
static int64_t mpegps_read_dts(AVFormatContext *s, int stream_index, int64_t *ppos, int64_t pos_limit)
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
#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.
void * priv_data
Format private data.
#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
static int64_t ff_parse_pes_pts(const uint8_t *buf)
Parse MPEG-PES five-byte timestamp.
int buf_size
Size of buf except extra allocated bytes.
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
AVStream ** streams
A list of all streams in the file.
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 ...
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)
enum AVMediaType codec_type
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 int mpegps_read_packet(AVFormatContext *s, AVPacket *pkt)
int eof_reached
true if eof reached
#define STREAM_TYPE_VIDEO_MPEG2
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
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)