[FFmpeg-cvslog] Merge commit 'b7e64fba7f37cc0399beae844f0a5dbef9219376'

Clément Bœsch git at videolan.org
Tue Jun 21 22:42:39 CEST 2016


ffmpeg | branch: master | Clément Bœsch <u at pkh.me> | Tue Jun 21 22:40:56 2016 +0200| [a4403e49b93a68f8c197615f346f2f891c35a4e5] | committer: Clément Bœsch

Merge commit 'b7e64fba7f37cc0399beae844f0a5dbef9219376'

* commit 'b7e64fba7f37cc0399beae844f0a5dbef9219376':
  Reduce the scope of some variables

Merged-by: Clément Bœsch <u at pkh.me>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=a4403e49b93a68f8c197615f346f2f891c35a4e5
---

 libavcodec/dvbsubdec.c     |    5 ++++-
 libavcodec/mpegvideo_enc.c |    4 ++--
 libavcodec/pgssubdec.c     |    6 ++++--
 libavcodec/xsubdec.c       |    6 ++++--
 libavdevice/v4l2.c         |    2 +-
 5 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/libavcodec/dvbsubdec.c b/libavcodec/dvbsubdec.c
index a4663d9..e9f4765 100644
--- a/libavcodec/dvbsubdec.c
+++ b/libavcodec/dvbsubdec.c
@@ -827,7 +827,7 @@ static int save_subtitle_set(AVCodecContext *avctx, AVSubtitle *sub, int *got_ou
     AVSubtitleRect *rect;
     DVBSubCLUT *clut;
     uint32_t *clut_table;
-    int i,j;
+    int i;
     int offset_x=0, offset_y=0;
     int ret = 0;
 
@@ -924,10 +924,13 @@ static int save_subtitle_set(AVCodecContext *avctx, AVSubtitle *sub, int *got_ou
 
 #if FF_API_AVPICTURE
 FF_DISABLE_DEPRECATION_WARNINGS
+{
+            int j;
             for (j = 0; j < 4; j++) {
                 rect->pict.data[j] = rect->data[j];
                 rect->pict.linesize[j] = rect->linesize[j];
             }
+}
 FF_ENABLE_DEPRECATION_WARNINGS
 #endif
 
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 2e12a3d..87d7954 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -2931,7 +2931,7 @@ int ff_mpv_reallocate_putbitbuffer(MpegEncContext *s, size_t threshold, size_t s
 
 static int encode_thread(AVCodecContext *c, void *arg){
     MpegEncContext *s= *(void**)arg;
-    int mb_x, mb_y, pdif = 0;
+    int mb_x, mb_y;
     int chr_h= 16>>s->chroma_y_shift;
     int i, j;
     MpegEncContext best_s = { 0 }, backup_s;
@@ -3569,7 +3569,7 @@ FF_DISABLE_DEPRECATION_WARNINGS
     /* Send the last GOB if RTP */
     if (s->avctx->rtp_callback) {
         int number_mb = (mb_y - s->resync_mb_y)*s->mb_width - s->resync_mb_x;
-        pdif = put_bits_ptr(&s->pb) - s->ptr_lastgob;
+        int pdif = put_bits_ptr(&s->pb) - s->ptr_lastgob;
         /* Call the RTP callback to send the last GOB */
         emms_c();
         s->avctx->rtp_callback(s->avctx, s->ptr_lastgob, pdif, number_mb);
diff --git a/libavcodec/pgssubdec.c b/libavcodec/pgssubdec.c
index 880fc96..cef477d 100644
--- a/libavcodec/pgssubdec.c
+++ b/libavcodec/pgssubdec.c
@@ -529,8 +529,6 @@ static int display_end_segment(AVCodecContext *avctx, void *data,
     }
     for (i = 0; i < ctx->presentation.object_count; i++) {
         PGSSubObject *object;
-        AVSubtitleRect *rect;
-        int j;
 
         sub->rects[i]  = av_mallocz(sizeof(*sub->rects[0]));
         if (!sub->rects[i]) {
@@ -597,11 +595,15 @@ static int display_end_segment(AVCodecContext *avctx, void *data,
 
 #if FF_API_AVPICTURE
 FF_DISABLE_DEPRECATION_WARNINGS
+{
+        AVSubtitleRect *rect;
+        int j;
         rect = sub->rects[i];
         for (j = 0; j < 4; j++) {
             rect->pict.data[j] = rect->data[j];
             rect->pict.linesize[j] = rect->linesize[j];
         }
+}
 FF_ENABLE_DEPRECATION_WARNINGS
 #endif
     }
diff --git a/libavcodec/xsubdec.c b/libavcodec/xsubdec.c
index 540607a..b024535 100644
--- a/libavcodec/xsubdec.c
+++ b/libavcodec/xsubdec.c
@@ -57,8 +57,6 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
     int64_t packet_time = 0;
     GetBitContext gb;
     int has_alpha = avctx->codec_tag == MKTAG('D','X','S','A');
-    AVSubtitleRect *rect;
-    int j;
 
     // check that at least header fits
     if (buf_size < 27 + 7 * 2 + 4 * (3 + has_alpha)) {
@@ -134,11 +132,15 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
 
 #if FF_API_AVPICTURE
 FF_DISABLE_DEPRECATION_WARNINGS
+{
+    AVSubtitleRect *rect;
+    int j;
     rect = sub->rects[0];
     for (j = 0; j < 4; j++) {
         rect->pict.data[j] = rect->data[j];
         rect->pict.linesize[j] = rect->linesize[j];
     }
+}
 FF_ENABLE_DEPRECATION_WARNINGS
 #endif
 
diff --git a/libavdevice/v4l2.c b/libavdevice/v4l2.c
index c8915e0..9153ad4 100644
--- a/libavdevice/v4l2.c
+++ b/libavdevice/v4l2.c
@@ -971,9 +971,9 @@ fail:
 
 static int v4l2_read_packet(AVFormatContext *ctx, AVPacket *pkt)
 {
-    struct video_data *s = ctx->priv_data;
 #if FF_API_CODED_FRAME
 FF_DISABLE_DEPRECATION_WARNINGS
+    struct video_data *s = ctx->priv_data;
     AVFrame *frame = ctx->streams[0]->codec->coded_frame;
 FF_ENABLE_DEPRECATION_WARNINGS
 #endif


======================================================================

diff --cc libavcodec/dvbsubdec.c
index a4663d9,526f125..e9f4765
--- a/libavcodec/dvbsubdec.c
+++ b/libavcodec/dvbsubdec.c
@@@ -761,196 -717,7 +761,199 @@@ static int dvbsub_read_8bit_string(AVCo
      return pixels_read;
  }
  
 +static void compute_default_clut(AVSubtitleRect *rect, int w, int h)
 +{
 +    uint8_t list[256] = {0};
 +    uint8_t list_inv[256];
 +    int counttab[256] = {0};
 +    int count, i, x, y;
 +
 +#define V(x,y) rect->data[0][(x) + (y)*rect->linesize[0]]
 +    for (y = 0; y<h; y++) {
 +        for (x = 0; x<w; x++) {
 +            int v = V(x,y) + 1;
 +            int vl = x     ? V(x-1,y) + 1 : 0;
 +            int vr = x+1<w ? V(x+1,y) + 1 : 0;
 +            int vt = y     ? V(x,y-1) + 1 : 0;
 +            int vb = y+1<h ? V(x,y+1) + 1 : 0;
 +            counttab[v-1] += !!((v!=vl) + (v!=vr) + (v!=vt) + (v!=vb));
 +        }
 +    }
 +#define L(x,y) list[ rect->data[0][(x) + (y)*rect->linesize[0]] ]
 +
 +    for (i = 0; i<256; i++) {
 +        int scoretab[256] = {0};
 +        int bestscore = 0;
 +        int bestv = 0;
 +        for (y = 0; y<h; y++) {
 +            for (x = 0; x<w; x++) {
 +                int v = rect->data[0][x + y*rect->linesize[0]];
 +                int l_m = list[v];
 +                int l_l = x     ? L(x-1, y) : 1;
 +                int l_r = x+1<w ? L(x+1, y) : 1;
 +                int l_t = y     ? L(x, y-1) : 1;
 +                int l_b = y+1<h ? L(x, y+1) : 1;
 +                int score;
 +                if (l_m)
 +                    continue;
 +                scoretab[v] += l_l + l_r + l_t + l_b;
 +                score = 1024LL*scoretab[v] / counttab[v];
 +                if (score > bestscore) {
 +                    bestscore = score;
 +                    bestv = v;
 +                }
 +            }
 +        }
 +        if (!bestscore)
 +            break;
 +        list    [ bestv ] = 1;
 +        list_inv[     i ] = bestv;
 +    }
 +
 +    count = i - 1;
 +    for (i--; i>=0; i--) {
 +        int v = i*255/count;
 +        AV_WN32(rect->data[1] + 4*list_inv[i], RGBA(v/2,v,v/2,v));
 +    }
 +}
 +
 +
 +static int save_subtitle_set(AVCodecContext *avctx, AVSubtitle *sub, int *got_output)
 +{
 +    DVBSubContext *ctx = avctx->priv_data;
 +    DVBSubRegionDisplay *display;
 +    DVBSubDisplayDefinition *display_def = ctx->display_definition;
 +    DVBSubRegion *region;
 +    AVSubtitleRect *rect;
 +    DVBSubCLUT *clut;
 +    uint32_t *clut_table;
-     int i,j;
++    int i;
 +    int offset_x=0, offset_y=0;
 +    int ret = 0;
 +
 +
 +    if (display_def) {
 +        offset_x = display_def->x;
 +        offset_y = display_def->y;
 +    }
 +
 +    /* Not touching AVSubtitles again*/
 +    if(sub->num_rects) {
 +        avpriv_request_sample(ctx, "Different Version of Segment asked Twice");
 +        return AVERROR_PATCHWELCOME;
 +    }
 +    for (display = ctx->display_list; display; display = display->next) {
 +        region = get_region(ctx, display->region_id);
 +        if (region && region->dirty)
 +            sub->num_rects++;
 +    }
 +
 +    if(ctx->compute_edt == 0) {
 +        sub->end_display_time = ctx->time_out * 1000;
 +        *got_output = 1;
 +    } else if (ctx->prev_start != AV_NOPTS_VALUE) {
 +        sub->end_display_time = av_rescale_q((sub->pts - ctx->prev_start ), AV_TIME_BASE_Q, (AVRational){ 1, 1000 }) - 1;
 +        *got_output = 1;
 +    }
 +    if (sub->num_rects > 0) {
 +
 +        sub->rects = av_mallocz_array(sizeof(*sub->rects), sub->num_rects);
 +        if (!sub->rects) {
 +            ret = AVERROR(ENOMEM);
 +            goto fail;
 +        }
 +
 +        for(i=0; i<sub->num_rects; i++)
 +            sub->rects[i] = av_mallocz(sizeof(*sub->rects[i]));
 +
 +        i = 0;
 +
 +        for (display = ctx->display_list; display; display = display->next) {
 +            region = get_region(ctx, display->region_id);
 +
 +            if (!region)
 +                continue;
 +
 +            if (!region->dirty)
 +                continue;
 +
 +            rect = sub->rects[i];
 +            rect->x = display->x_pos + offset_x;
 +            rect->y = display->y_pos + offset_y;
 +            rect->w = region->width;
 +            rect->h = region->height;
 +            rect->nb_colors = (1 << region->depth);
 +            rect->type      = SUBTITLE_BITMAP;
 +            rect->linesize[0] = region->width;
 +
 +            clut = get_clut(ctx, region->clut);
 +
 +            if (!clut)
 +                clut = &default_clut;
 +
 +            switch (region->depth) {
 +            case 2:
 +                clut_table = clut->clut4;
 +                break;
 +            case 8:
 +                clut_table = clut->clut256;
 +                break;
 +            case 4:
 +            default:
 +                clut_table = clut->clut16;
 +                break;
 +            }
 +
 +            rect->data[1] = av_mallocz(AVPALETTE_SIZE);
 +            if (!rect->data[1]) {
 +                ret = AVERROR(ENOMEM);
 +                goto fail;
 +            }
 +            memcpy(rect->data[1], clut_table, (1 << region->depth) * sizeof(uint32_t));
 +
 +            rect->data[0] = av_malloc(region->buf_size);
 +            if (!rect->data[0]) {
 +                ret = AVERROR(ENOMEM);
 +                goto fail;
 +            }
 +
 +            memcpy(rect->data[0], region->pbuf, region->buf_size);
 +
 +            if ((clut == &default_clut && ctx->compute_clut == -1) || ctx->compute_clut == 1)
 +                compute_default_clut(rect, rect->w, rect->h);
 +
 +#if FF_API_AVPICTURE
 +FF_DISABLE_DEPRECATION_WARNINGS
++{
++            int j;
 +            for (j = 0; j < 4; j++) {
 +                rect->pict.data[j] = rect->data[j];
 +                rect->pict.linesize[j] = rect->linesize[j];
 +            }
++}
 +FF_ENABLE_DEPRECATION_WARNINGS
 +#endif
 +
 +            i++;
 +        }
 +    }
  
 +    return 0;
 +fail:
 +    if (sub->rects) {
 +        for(i=0; i<sub->num_rects; i++) {
 +            rect = sub->rects[i];
 +            if (rect) {
 +                av_freep(&rect->data[0]);
 +                av_freep(&rect->data[1]);
 +            }
 +            av_freep(&sub->rects[i]);
 +        }
 +        av_freep(&sub->rects);
 +    }
 +    sub->num_rects = 0;
 +    return ret;
 +}
  
  static void dvbsub_parse_pixel_data_block(AVCodecContext *avctx, DVBSubObjectDisplay *display,
                                            const uint8_t *buf, int buf_size, int top_bottom, int non_mod)
diff --cc libavcodec/mpegvideo_enc.c
index 2e12a3d,2667f3b..87d7954
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@@ -2895,43 -2681,9 +2895,43 @@@ static void update_mb_info(MpegEncConte
      write_mb_info(s);
  }
  
 +int ff_mpv_reallocate_putbitbuffer(MpegEncContext *s, size_t threshold, size_t size_increase)
 +{
 +    if (   s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb)>>3) < threshold
 +        && s->slice_context_count == 1
 +        && s->pb.buf == s->avctx->internal->byte_buffer) {
 +        int lastgob_pos = s->ptr_lastgob - s->pb.buf;
 +        int vbv_pos     = s->vbv_delay_ptr - s->pb.buf;
 +
 +        uint8_t *new_buffer = NULL;
 +        int new_buffer_size = 0;
 +
 +        if ((s->avctx->internal->byte_buffer_size + size_increase) >= INT_MAX/8) {
 +            av_log(s->avctx, AV_LOG_ERROR, "Cannot reallocate putbit buffer\n");
 +            return AVERROR(ENOMEM);
 +        }
 +
 +        av_fast_padded_malloc(&new_buffer, &new_buffer_size,
 +                              s->avctx->internal->byte_buffer_size + size_increase);
 +        if (!new_buffer)
 +            return AVERROR(ENOMEM);
 +
 +        memcpy(new_buffer, s->avctx->internal->byte_buffer, s->avctx->internal->byte_buffer_size);
 +        av_free(s->avctx->internal->byte_buffer);
 +        s->avctx->internal->byte_buffer      = new_buffer;
 +        s->avctx->internal->byte_buffer_size = new_buffer_size;
 +        rebase_put_bits(&s->pb, new_buffer, new_buffer_size);
 +        s->ptr_lastgob   = s->pb.buf + lastgob_pos;
 +        s->vbv_delay_ptr = s->pb.buf + vbv_pos;
 +    }
 +    if (s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb)>>3) < threshold)
 +        return AVERROR(EINVAL);
 +    return 0;
 +}
 +
  static int encode_thread(AVCodecContext *c, void *arg){
      MpegEncContext *s= *(void**)arg;
-     int mb_x, mb_y, pdif = 0;
+     int mb_x, mb_y;
      int chr_h= 16>>s->chroma_y_shift;
      int i, j;
      MpegEncContext best_s = { 0 }, backup_s;
diff --cc libavcodec/pgssubdec.c
index 880fc96,886685b..cef477d
--- a/libavcodec/pgssubdec.c
+++ b/libavcodec/pgssubdec.c
@@@ -592,18 -576,22 +590,22 @@@ static int display_end_segment(AVCodecC
              return AVERROR(ENOMEM);
          }
  
 +        if (!ctx->forced_subs_only || ctx->presentation.objects[i].composition_flag & 0x40)
 +        memcpy(sub->rects[i]->data[1], palette->clut, sub->rects[i]->nb_colors * sizeof(uint32_t));
 +
  #if FF_API_AVPICTURE
  FF_DISABLE_DEPRECATION_WARNINGS
+ {
+         AVSubtitleRect *rect;
+         int j;
          rect = sub->rects[i];
          for (j = 0; j < 4; j++) {
              rect->pict.data[j] = rect->data[j];
              rect->pict.linesize[j] = rect->linesize[j];
          }
+ }
  FF_ENABLE_DEPRECATION_WARNINGS
  #endif
 -
 -        memcpy(sub->rects[i]->data[1], palette->clut, sub->rects[i]->nb_colors * sizeof(uint32_t));
 -
      }
      return 1;
  }
diff --cc libavcodec/xsubdec.c
index 540607a,3af300c..b024535
--- a/libavcodec/xsubdec.c
+++ b/libavcodec/xsubdec.c
@@@ -57,12 -57,12 +57,10 @@@ static int decode_frame(AVCodecContext 
      int64_t packet_time = 0;
      GetBitContext gb;
      int has_alpha = avctx->codec_tag == MKTAG('D','X','S','A');
-     AVSubtitleRect *rect;
-     int j;
  
 -    memset(sub, 0, sizeof(*sub));
 -
      // check that at least header fits
      if (buf_size < 27 + 7 * 2 + 4 * (3 + has_alpha)) {
 -        av_log(avctx, AV_LOG_ERROR, "coded frame too small\n");
 +        av_log(avctx, AV_LOG_ERROR, "coded frame size %d too small\n", buf_size);
          return -1;
      }
  
diff --cc libavdevice/v4l2.c
index c8915e0,b59f29f..9153ad4
--- a/libavdevice/v4l2.c
+++ b/libavdevice/v4l2.c
@@@ -950,31 -844,19 +950,31 @@@ static int v4l2_read_header(AVFormatCon
      if (codec_id == AV_CODEC_ID_RAWVIDEO)
          st->codecpar->codec_tag =
              avcodec_pix_fmt_to_codec_tag(st->codecpar->format);
 +    else if (codec_id == AV_CODEC_ID_H264) {
 +        st->need_parsing = AVSTREAM_PARSE_FULL_ONCE;
 +    }
 +    if (desired_format == V4L2_PIX_FMT_YVU420)
 +        st->codecpar->codec_tag = MKTAG('Y', 'V', '1', '2');
 +    else if (desired_format == V4L2_PIX_FMT_YVU410)
 +        st->codecpar->codec_tag = MKTAG('Y', 'V', 'U', '9');
      st->codecpar->width = s->width;
      st->codecpar->height = s->height;
 -    st->codecpar->bit_rate = s->frame_size * av_q2d(st->avg_frame_rate) * 8;
 +    if (st->avg_frame_rate.den)
 +        st->codecpar->bit_rate = s->frame_size * av_q2d(st->avg_frame_rate) * 8;
  
      return 0;
 +
 +fail:
 +    v4l2_close(s->fd);
 +    return res;
  }
  
 -static int v4l2_read_packet(AVFormatContext *s1, AVPacket *pkt)
 +static int v4l2_read_packet(AVFormatContext *ctx, AVPacket *pkt)
  {
-     struct video_data *s = ctx->priv_data;
  #if FF_API_CODED_FRAME
  FF_DISABLE_DEPRECATION_WARNINGS
 -    struct video_data *s = s1->priv_data;
 -    AVFrame *frame = s1->streams[0]->codec->coded_frame;
++    struct video_data *s = ctx->priv_data;
 +    AVFrame *frame = ctx->streams[0]->codec->coded_frame;
  FF_ENABLE_DEPRECATION_WARNINGS
  #endif
      int res;



More information about the ffmpeg-cvslog mailing list