]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/mpeg.c
RELEASE: 0.8.5 has been released
[ffmpeg] / libavformat / mpeg.c
index dc5d264b686b70cc1f91d3aa3e679492acab7183..6fb1c5c31b8eedf502e8608cdbc933801addfea1 100644 (file)
@@ -49,6 +49,10 @@ static int check_pes(uint8_t *p, uint8_t *end){
     return pes1||pes2;
 }
 
+static int check_pack_header(const uint8_t *buf) {
+    return (buf[1] & 0xC0) == 0x40 || (buf[1] & 0xF0) == 0x20;
+}
+
 static int mpegps_probe(AVProbeData *p)
 {
     uint32_t code= -1;
@@ -61,9 +65,10 @@ static int mpegps_probe(AVProbeData *p)
         if ((code & 0xffffff00) == 0x100) {
             int len= p->buf[i+1] << 8 | p->buf[i+2];
             int pes= check_pes(p->buf+i, p->buf+p->buf_size);
+            int pack = check_pack_header(p->buf+i);
 
             if(code == SYSTEM_HEADER_START_CODE) sys++;
-            else if(code == PACK_START_CODE)     pspack++;
+            else if(code == PACK_START_CODE && pack) pspack++;
             else if((code & 0xf0) == VIDEO_ID &&  pes) vid++;
             // skip pes payload to avoid start code emulation for private
             // and audio streams
@@ -106,6 +111,7 @@ static int mpegps_read_header(AVFormatContext *s,
     MpegDemuxContext *m = s->priv_data;
     const char *sofdec = "Sofdec";
     int v, i = 0;
+    int64_t last_pos = avio_tell(s->pb);
 
     m->header_state = 0xff;
     s->ctx_flags |= AVFMTCTX_NOHEADER;
@@ -119,6 +125,9 @@ static int mpegps_read_header(AVFormatContext *s,
 
     m->sofdec = (m->sofdec == 6) ? 1 : 0;
 
+    if (!m->sofdec)
+       avio_seek(s->pb, last_pos, SEEK_SET);
+
     /* no need to do more */
     return 0;
 }
@@ -419,7 +428,7 @@ static int mpegps_read_packet(AVFormatContext *s,
 {
     MpegDemuxContext *m = s->priv_data;
     AVStream *st;
-    int len, startcode, i, es_type;
+    int len, startcode, i, es_type, ret;
     int request_probe= 0;
     enum CodecID codec_id = CODEC_ID_NONE;
     enum AVMediaType type;
@@ -565,7 +574,13 @@ static int mpegps_read_packet(AVFormatContext *s,
             return AVERROR(EINVAL);
     }
     av_new_packet(pkt, len);
-    avio_read(s->pb, pkt->data, pkt->size);
+    ret = avio_read(s->pb, pkt->data, pkt->size);
+    if (ret < 0) {
+        pkt->size = 0;
+    } else if (ret < pkt->size) {
+        pkt->size = ret;
+        memset(pkt->data + ret, 0, FF_INPUT_BUFFER_PADDING_SIZE);
+    }
     pkt->pts = pts;
     pkt->dts = dts;
     pkt->pos = dummy_pos;
@@ -574,7 +589,7 @@ static int mpegps_read_packet(AVFormatContext *s,
             pkt->stream_index, pkt->pts / 90000.0, pkt->dts / 90000.0,
             pkt->size);
 
-    return 0;
+    return (ret < 0) ? ret : 0;
 }
 
 static int64_t mpegps_read_dts(AVFormatContext *s, int stream_index,