[MPlayer-dev-eng] [PATCH] Update vo_png to use updated API

Alexander Strasser eclipse7 at gmx.net
Thu Aug 8 22:18:32 CEST 2013


On 2013-07-31 02:11 +0200, Alexander Strasser wrote:
> On 2013-07-14 21:56 +0200, Jiang Jiang wrote:
> > avcodec_encode_video is deprecated.
> > ---
> >  libvo/vo_png.c | 10 +++++++---
> >  1 file changed, 7 insertions(+), 3 deletions(-)
> > 
> > diff --git a/libvo/vo_png.c b/libvo/vo_png.c
> > index ae93dcf..3556c81 100644
> > --- a/libvo/vo_png.c
> > +++ b/libvo/vo_png.c
> > @@ -146,9 +146,10 @@ config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uin
> >  static uint32_t draw_image(mp_image_t* mpi){
> >      AVFrame pic;
> >      int buffersize;
> > -    int res;
> > +    int res, got_pkt;
> >      char buf[100];
> >      FILE *outfile;
> > +    AVPacket pkt;
> >  
> >      // if -dr or -slices then do nothing:
> >      if(mpi->flags&(MP_IMGFLAG_DIRECT|MP_IMGFLAG_DRAW_CALLBACK)) return VO_TRUE;
> > @@ -170,7 +171,10 @@ static uint32_t draw_image(mp_image_t* mpi){
> >          outbuffer = av_malloc(buffersize);
> >          outbuffer_size = buffersize;
> >      }
> > -    res = avcodec_encode_video(avctx, outbuffer, outbuffer_size, &pic);
> > +    av_init_packet(&pkt);
> > +    pkt.data = outbuffer;
> > +    pkt.size = outbuffer_size;
> > +    res = avcodec_encode_video2(avctx, &pkt, &pic, &got_pkt);
> >  
> >      if(res < 0){
> >   	    mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_PNG_ErrorInCreatePng);
> > @@ -178,7 +182,7 @@ static uint32_t draw_image(mp_image_t* mpi){
> >  	    return 1;
> >      }
> >  
> > -    fwrite(outbuffer, res, 1, outfile);
> > +    fwrite(outbuffer, pkt.size, 1, outfile);
> >      fclose(outfile);
> >  
> >      return VO_TRUE;
> > -- 
> 
>   LGTM but it is pretty late here. I will re-review next week and apply
> if I hear no objections and find no flaws.

  I am going to commit this soon. Together with a simplified error
path and the addition of a call to av_free_packet. I think it is more
correct that way, even if today it won't do much. In future it makes
sure the packet and potentially attached side data will be freed
accordingly.

  Looks like this when viewed as an incremental patch:

diff --git a/libvo/vo_png.c b/libvo/vo_png.c
index 3556c81..b28ea38 100644
--- a/libvo/vo_png.c
+++ b/libvo/vo_png.c
@@ -176,14 +176,16 @@ static uint32_t draw_image(mp_image_t* mpi){
     pkt.size = outbuffer_size;
     res = avcodec_encode_video2(avctx, &pkt, &pic, &got_pkt);
 
     if(res < 0){
            mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_PNG_ErrorInCreatePng);
-            fclose(outfile);
-       return 1;
+    } else {
+        fwrite(outbuffer, pkt.size, 1, outfile);
     }
 
-    fwrite(outbuffer, pkt.size, 1, outfile);
     fclose(outfile);
+    av_free_packet(&pkt);
 
     return VO_TRUE;
 } 


>   BTW using the newer API seems also to fix the less common cases with
> small video resolution where we currently would let avcodec_encode_video
> fail demanding a minimum size.


  Alexander
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/attachments/20130808/3738cdb0/attachment.asc>


More information about the MPlayer-dev-eng mailing list