Merge commit 'b9b689550e7531b1a2cc893d2af623e37f266936' into release/2.4
authorMichael Niedermayer <michaelni@gmx.at>
Sun, 18 Jan 2015 00:19:35 +0000 (01:19 +0100)
committerMichael Niedermayer <michaelni@gmx.at>
Sun, 18 Jan 2015 00:19:51 +0000 (01:19 +0100)
* commit 'b9b689550e7531b1a2cc893d2af623e37f266936':
  img2dec: check av_new_packet return value

Conflicts:
libavformat/img2dec.c

See: 3f8148911c6e6e1f2a042bd4ca3ad8516a92130c
Merged-by: Michael Niedermayer <michaelni@gmx.at>
1  2 
libavformat/img2dec.c

@@@ -355,12 -217,11 +355,12 @@@ int ff_img_read_header(AVFormatContext 
      return 0;
  }
  
 -static int img_read_packet(AVFormatContext *s1, AVPacket *pkt)
 +int ff_img_read_packet(AVFormatContext *s1, AVPacket *pkt)
  {
      VideoDemuxData *s = s1->priv_data;
 -    char filename[1024];
 +    char filename_bytes[1024];
 +    char *filename = filename_bytes;
-     int i;
+     int i, res;
      int size[3]           = { 0 }, ret[3] = { 0 };
      AVIOContext *f[3]     = { NULL };
      AVCodecContext *codec = s1->streams[0]->codec;
              infer_size(&codec->width, &codec->height, size[0]);
      } else {
          f[0] = s1->pb;
 -        if (f[0]->eof_reached)
 -            return AVERROR(EIO);
 -        size[0] = 4096;
 +        if (avio_feof(f[0]) && s->loop && s->is_pipe)
 +            avio_seek(f[0], 0, SEEK_SET);
 +        if (avio_feof(f[0]))
 +            return AVERROR_EOF;
 +        if (s->frame_size > 0) {
 +            size[0] = s->frame_size;
 +        } else if (!s1->streams[0]->parser) {
 +            size[0] = avio_size(s1->pb);
 +        } else {
 +            size[0] = 4096;
 +        }
      }
  
-     if (av_new_packet(pkt, size[0] + size[1] + size[2]) < 0)
-         return AVERROR(ENOMEM);
+     res = av_new_packet(pkt, size[0] + size[1] + size[2]);
+     if (res < 0)
+         return res;
      pkt->stream_index = 0;
      pkt->flags       |= AV_PKT_FLAG_KEY;
 +    if (s->ts_from_file) {
 +        struct stat img_stat;
 +        if (stat(filename, &img_stat))
 +            return AVERROR(EIO);
 +        pkt->pts = (int64_t)img_stat.st_mtime;
 +#if HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
 +        if (s->ts_from_file == 2)
 +            pkt->pts = 1000000000*pkt->pts + img_stat.st_mtim.tv_nsec;
 +#endif
 +        av_add_index_entry(s1->streams[0], s->img_number, pkt->pts, 0, 0, AVINDEX_KEYFRAME);
 +    } else if (!s->is_pipe) {
 +        pkt->pts      = s->pts;
 +    }
 +
 +    if (s->is_pipe)
 +        pkt->pos = avio_tell(f[0]);
  
      pkt->size = 0;
      for (i = 0; i < 3; i++) {