32 #define MAX_SYNC_SIZE 100000
36 int pes2= (p[3] & 0xC0) == 0x80
37 && (p[4] & 0xC0) != 0x40
38 &&((p[4] & 0xC0) == 0x00 || (p[4]&0xC0)>>2 == (p[6]&0xF0));
40 for(p+=3; p<end && *p == 0xFF; p++);
41 if((*p&0xC0) == 0x40) p+=2;
42 if((*p&0xF0) == 0x20){
43 pes1= p[0]&p[2]&p[4]&1;
44 }
else if((*p&0xF0) == 0x30){
45 pes1= p[0]&p[2]&p[4]&p[5]&p[7]&p[9]&1;
53 return (buf[1] & 0xC0) == 0x40 || (buf[1] & 0xF0) == 0x20;
59 int sys=0, pspack=0, priv1=0, vid=0, audio=0, invalid=0;
64 code = (code<<8) + p->
buf[i];
65 if ((code & 0xffffff00) == 0x100) {
72 else if((code & 0xf0) ==
VIDEO_ID && pes) vid++;
75 else if((code & 0xe0) ==
AUDIO_ID && pes) {audio++; i+=
len;}
78 else if((code & 0xf0) ==
VIDEO_ID && !pes) invalid++;
79 else if((code & 0xe0) ==
AUDIO_ID && !pes) invalid++;
84 if(vid+audio > invalid)
88 if(sys>invalid && sys*9 <= pspack*10)
90 if(pspack > invalid && (priv1+vid+audio)*10 >= pspack*9)
92 if((!!vid ^ !!audio) && (audio > 4 || vid > 1) && !sys && !pspack && p->
buf_size>2048 && vid + audio > invalid)
111 const char *sofdec =
"Sofdec";
122 }
while (v == sofdec[i] && i++ < 6);
134 buf[0] = c<0 ?
avio_r8(pb) : c;
141 int32_t *header_state)
146 state = *header_state;
153 if (state == 0x000001) {
154 state = ((state << 8) | v) & 0xffffff;
158 state = ((state << 8) | v) & 0xffffff;
162 *header_state =
state;
169 static int find_prev_start_code(
AVIOContext *pb,
int *size_ptr)
171 int64_t pos, pos_start;
172 int max_size, start_code;
174 max_size = *size_ptr;
178 pos = pos_start - 16386;
187 if (pos < 0 || (pos_start - pos) >= max_size) {
193 if ((start_code & 0xffffff00) == 0x100)
197 *size_ptr = pos_start - pos;
210 int psm_length, ps_info_length, es_map_length;
222 while (es_map_length >= 4){
223 unsigned char type =
avio_r8(pb);
224 unsigned char es_id =
avio_r8(pb);
230 es_map_length -= 4 + es_info_length;
233 return 2 + psm_length;
240 int64_t *ppos,
int *pstart_code,
241 int64_t *ppts, int64_t *pdts)
245 int pes_ext, ext2_len, id_ext, skip;
280 m->
sofdec = !memcmp(buf,
"ofdec", 5);
296 if (!((startcode >= 0x1c0 && startcode <= 0x1df) ||
297 (startcode >= 0x1e0 && startcode <= 0x1ef) ||
298 (startcode == 0x1bd) || (startcode == 0x1fd)))
316 if ((c & 0xc0) == 0x40) {
322 if ((c & 0xe0) == 0x20) {
329 }
else if ((c & 0xc0) == 0x80) {
332 if ((c & 0x30) != 0) {
340 if (header_len > len)
351 if (flags & 0x3f && header_len == 0){
359 skip = (pes_ext >> 4) & 0xb;
361 if (pes_ext & 0x40 || skip > header_len){
368 if (pes_ext & 0x01) {
371 if ((ext2_len & 0x7f) > 0) {
373 if ((id_ext & 0x80) == 0)
374 startcode = ((startcode & 0xff) << 8) | id_ext;
389 if (startcode >= 0x80 && startcode <= 0xcf) {
395 if (startcode >= 0xb0 && startcode <= 0xbf) {
415 *pstart_code = startcode;
426 int len, startcode, i, es_type, ret;
429 int64_t pts, dts, dummy_pos;
430 uint8_t
av_uninit(dvdaudio_substream_type);
437 if(startcode == 0x1bd) {
438 dvdaudio_substream_type =
avio_r8(s->
pb);
446 if (st->
id == startcode)
477 }
else if (startcode >= 0x1e0 && startcode <= 0x1ef) {
478 static const unsigned char avs_seqh[4] = { 0, 0, 1, 0xb0 };
479 unsigned char buf[8];
482 if(!memcmp(buf, avs_seqh, 4) && (buf[6] != 0 || buf[7] != 1))
487 }
else if (startcode >= 0x1c0 && startcode <= 0x1df) {
490 }
else if (startcode >= 0x80 && startcode <= 0x87) {
493 }
else if ( ( startcode >= 0x88 && startcode <= 0x8f)
494 ||( startcode >= 0x98 && startcode <= 0x9f)) {
498 }
else if (startcode >= 0xa0 && startcode <= 0xaf) {
502 }
else if (startcode >= 0xb0 && startcode <= 0xbf) {
505 }
else if (startcode >= 0xc0 && startcode <= 0xcf) {
509 }
else if (startcode >= 0x20 && startcode <= 0x3f) {
512 }
else if (startcode >= 0xfd55 && startcode <= 0xfd5f) {
515 }
else if (startcode == 0x1bd) {
518 switch(dvdaudio_substream_type & 0xe0) {
521 case 0x80:
if((dvdaudio_substream_type & 0xf8) == 0x88)
546 if ((startcode >= 0xa0 && startcode <= 0xaf) ||
547 (startcode == 0x1bd && ((dvdaudio_substream_type & 0xe0) == 0xa0))) {
558 freq = (b1 >> 4) & 3;
573 pkt->
pos = dummy_pos;
575 av_dlog(s,
"%d: pts=%0.3f dts=%0.3f size=%d\n",
579 return (ret < 0) ? ret : 0;
583 int64_t *ppos, int64_t pos_limit)
586 int64_t pos, pts, dts;
595 av_dlog(s,
"none (ret=%d)\n", len);
598 if (startcode == s->
streams[stream_index]->
id &&
604 av_dlog(s,
"pos=0x%"PRIx64
" dts=0x%"PRIx64
" %0.3f\n",
605 pos, dts, dts / 90000.0);
#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.
int64_t pos
byte position in stream, -1 if unknown
#define AV_LOG_WARNING
Something somehow does not look correct.
static const int lpcm_freq_tab[4]
int index
stream index in AVFormatContext
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
Format-specific flags, see AVFMTCTX_xx.
unsigned int avio_rb32(AVIOContext *s)
enum AVStreamParseType need_parsing
int id
format-specific stream ID
#define SYSTEM_HEADER_START_CODE
static int read_header(FFV1Context *f)
#define AVERROR_EOF
End of file.
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
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.
preferred ID for MPEG-1/2 video decoding
#define STREAM_TYPE_AUDIO_AAC
#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)
void av_log(void *avcl, int level, const char *fmt,...)
AVStream * avformat_new_stream(AVFormatContext *s, AVCodec *c)
Add a new stream to a media file.
static int64_t ff_parse_pes_pts(const uint8_t *buf)
Parse MPEG-PES five-byte timestamp.
int avio_r8(AVIOContext *s)
AVCodecContext * codec
codec context
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
A list of all streams in the file.
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
int bit_rate
the average bitrate
#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.
static int read_probe(AVProbeData *p)
#define av_dlog(pctx,...)
av_dlog macros Useful to print debug messages that shouldn't get compiled in normally.
#define STREAM_TYPE_VIDEO_MPEG4
unsigned char psm_es_type[256]
codec_id is not known (like CODEC_ID_NONE) but lavf should attempt to identify it ...
enum AVMediaType codec_type
int sample_rate
samples per second
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#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)
static int mpegps_read_header(AVFormatContext *s, AVFormatParameters *ap)
struct MpegDemuxContext MpegDemuxContext
CodecID
Identify the syntax and semantics of the bitstream.
int eof_reached
true if eof reached
int channels
number of audio channels
#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...
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
#define STREAM_TYPE_AUDIO_MPEG1
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
preferred ID for decoding MPEG audio layer 1, 2 or 3
static int mpegps_probe(AVProbeData *p)