OSDN Git Service

CygWin:
[handbrake-jp/handbrake-jp-git.git] / contrib / patch-ffmpeg-mpegleak.patch
1 Index: libavcodec/h264.c
2 ===================================================================
3 --- libavcodec/h264.c   (revision 14820)
4 +++ libavcodec/h264.c   (working copy)
5 @@ -3355,7 +3355,7 @@
6           * stream. Need to discard one frame. Prevents overrun of the
7           * short_ref and long_ref buffers.
8           */
9 -        av_log(h->s.avctx, AV_LOG_ERROR,
10 +        av_log(h->s.avctx, AV_LOG_DEBUG,
11                 "number of reference frames exceeds max (probably "
12                 "corrupt input), discarding one\n");
13  
14 @@ -7557,7 +7557,7 @@
15  
16      if(!(s->flags2 & CODEC_FLAG2_CHUNKS) && !s->current_picture_ptr){
17          if (avctx->skip_frame >= AVDISCARD_NONREF || s->hurry_up) return 0;
18 -        av_log(avctx, AV_LOG_ERROR, "no frame!\n");
19 +        av_log(avctx, AV_LOG_DEBUG, "no frame!\n");
20          return -1;
21      }
22  
23 Index: libavcodec/mpegvideo.c
24 ===================================================================
25 --- libavcodec/mpegvideo.c      (revision 14820)
26 +++ libavcodec/mpegvideo.c      (working copy)
27 @@ -779,19 +779,18 @@
28      }
29  
30      av_log(s->avctx, AV_LOG_FATAL, "Internal error, picture buffer overflow\n");
31 -    /* We could return -1, but the codec would crash trying to draw into a
32 -     * non-existing frame anyway. This is safer than waiting for a random crash.
33 -     * Also the return of this is never useful, an encoder must only allocate
34 -     * as much as allowed in the specification. This has no relationship to how
35 -     * much libavcodec could allocate (and MAX_PICTURE_COUNT is always large
36 -     * enough for such valid streams).
37 -     * Plus, a decoder has to check stream validity and remove frames if too
38 -     * many reference frames are around. Waiting for "OOM" is not correct at
39 -     * all. Similarly, missing reference frames have to be replaced by
40 -     * interpolated/MC frames, anything else is a bug in the codec ...
41 -     */
42 -    abort();
43 -    return -1;
44 +    /* XXX there seems to be a leak caused by h264 in mpeg transport
45 +     * streams: Over-the-air streams have a lot of errors. A picture
46 +     * may be marked as referenced but the actual references get lost
47 +     * so it never gets released. We take care of that here by releasing
48 +     * the oldest we have & reusing its slot. */
49 +    int oldest=0;
50 +    for(i=0; i<MAX_PICTURE_COUNT; i++){
51 +        if (s->picture[i].coded_picture_number < s->picture[oldest].coded_picture_number)
52 +            oldest = i;
53 +    }
54 +    s->avctx->release_buffer(s->avctx, (AVFrame*)&s->picture[oldest]);
55 +    return oldest;
56  }
57  
58  static void update_noise_reduction(MpegEncContext *s){