]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/mpeg.c
mxfdec: Move FooterPartition to MXFContext and make sure it's never set to zero
[ffmpeg] / libavformat / mpeg.c
index dc5d264b686b70cc1f91d3aa3e679492acab7183..8a79eca14d39d1315b2f236918b3a4390e5612b5 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;
@@ -113,12 +119,14 @@ static int mpegps_read_header(AVFormatContext *s,
     m->sofdec = -1;
     do {
         v = avio_r8(s->pb);
-        m->header_state = m->header_state << 8 | v;
         m->sofdec++;
     } while (v == sofdec[i] && i++ < 6);
 
     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 +427,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;
@@ -564,8 +572,7 @@ static int mpegps_read_packet(AVFormatContext *s,
         else if (st->codec->bits_per_coded_sample == 28)
             return AVERROR(EINVAL);
     }
-    av_new_packet(pkt, len);
-    avio_read(s->pb, pkt->data, pkt->size);
+    ret = av_get_packet(s->pb, pkt, len);
     pkt->pts = pts;
     pkt->dts = dts;
     pkt->pos = dummy_pos;
@@ -574,7 +581,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,