ffmpeg中ff_scale_image()内存泄露

版本:ffmpeg1.2


 

 
 

 

 
  int    ff_scale_image( uint8_t *dst_data[4], int dst_linesize[4],
                                         int dst_w, int dst_h, enum AVPixelFormat dst_pix_fmt,
                                          uint8_t * const src_data[4], int src_linesize[4],
                                        int src_w, int src_h, enum AVPixelFormat src_pix_fmt,
                                         void *log_ctx)
{
                             int ret;
                             SwsContext *sws_ctx = sws_getContext (src_w, src_h, src_pix_fmt,
                                                                                                     dst_w, dst_h, dst_pix_fmt,
                                                                                                           SWS_BILINEAR , NULL , NULL , NULL );
                              if (!sws_ctx) {
                                                       av_log(log_ctx, AV_LOG_ERROR,
                                                       "Impossible to create scale context for the conversion "
                                                       "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n",
                                                    av_get_pix_fmt_name(src_pix_fmt), src_w, src_h,
                                                    av_get_pix_fmt_name(dst_pix_fmt), dst_w, dst_h);
                                                       ret = AVERROR(EINVAL);
                                                   goto end;
                                             }

                      if ((ret = av_image_alloc(dst_data, dst_linesize, dst_w, dst_h, dst_pix_fmt, 16)) < 0)
                                   goto end;
                    ret = 0;
                       sws_scale(sws_ctx, ( const uint8_t * const*)src_data, src_linesize, 0, src_h, dst_data, dst_linesize);

       end:
                         sws_freeContext(sws_ctx);
                       return ret;
              }
 
 

 

 

我在使用这个函数进行像素转换的时候,如果反复进行调用就会出现内存泄露,不知道什么原因;

但是如果把这个函数分开使用,即

init()

{

、、、、、

 

struct SwsContext *sws_ctx = sws_getContext(src_w, src_h, src_pix_fmt,
                                                                             dst_w, dst_h, dst_pix_fmt,
                                                                              SWS_BILINEAR, NULL, NULL, NULL);

if ((ret = av_image_alloc(dst_data, dst_linesize, dst_w, dst_h, dst_pix_fmt, 16)) < 0)
                 release();

 

}


process()

{

、、、、、、、、

sws_scale(sws_ctx, (constuint8_t * const*)src_data, src_linesize, 0, src_h, dst_data, dst_linesize);

}


release()

{

、、、、、、、

sws_freeContext(sws_ctx);

}


这样的话就是正确的,不会出现内存泄露。

 

posted @ 2013-07-18 18:47  jlins  阅读(1733)  评论(0编辑  收藏  举报