Update API usage to deal with current vs new FFmpeg API.

Index: Makefile
===================================================================
RCS file: /home/cvs/ports/telephony/iaxclient/Makefile,v
retrieving revision 1.40
diff -u -p -u -p -r1.40 Makefile
--- Makefile    17 Dec 2018 01:08:29 -0000      1.40
+++ Makefile    9 Feb 2019 18:44:11 -0000
@@ -6,7 +6,7 @@ COMMENT-tcl=    IAX client library, tcl bin
 DISTNAME=      iaxclient-2.1beta3
 PKGNAME-main=  ${DISTNAME}
 PKGNAME-tcl=   ${DISTNAME:S/iaxclient/iaxclient-tcl/}
-REVISION=      22
+REVISION=      23
 
 CATEGORIES=    telephony
 SHARED_LIBS=   tcliaxclient02 0.0 \
Index: patches/patch-lib_codec_ffmpeg_c
===================================================================
RCS file: /home/cvs/ports/telephony/iaxclient/patches/patch-lib_codec_ffmpeg_c,v
retrieving revision 1.4
diff -u -p -u -p -r1.4 patch-lib_codec_ffmpeg_c
--- patches/patch-lib_codec_ffmpeg_c    27 Apr 2014 20:52:50 -0000      1.4
+++ patches/patch-lib_codec_ffmpeg_c    9 Feb 2019 19:14:46 -0000
@@ -2,8 +2,9 @@ $OpenBSD: patch-lib_codec_ffmpeg_c,v 1.4
 
 Update for newer FFmpeg API.
 
---- lib/codec_ffmpeg.c.orig    Mon Apr  7 12:05:42 2008
-+++ lib/codec_ffmpeg.c Thu Apr 24 20:26:53 2014
+Index: lib/codec_ffmpeg.c
+--- lib/codec_ffmpeg.c.orig
++++ lib/codec_ffmpeg.c
 @@ -23,11 +23,7 @@
  #include "codec_ffmpeg.h"
  #include "iaxclient_lib.h"
@@ -16,7 +17,7 @@ Update for newer FFmpeg API.
  
  struct slice_header_t
  {
-@@ -63,7 +59,7 @@ struct decoder_ctx
+@@ -63,30 +59,30 @@ struct decoder_ctx
  
  static struct slice_set_t * g_slice_set = 0;
  
@@ -25,6 +26,36 @@ Update for newer FFmpeg API.
  {
        switch (format)
        {
+       case IAXC_FORMAT_H261:
+-              return CODEC_ID_H261;
++              return AV_CODEC_ID_H261;
+ 
+       case IAXC_FORMAT_H263:
+-              return CODEC_ID_H263;
++              return AV_CODEC_ID_H263;
+ 
+       case IAXC_FORMAT_H263_PLUS:
+-              return CODEC_ID_H263P;
++              return AV_CODEC_ID_H263P;
+ 
+       case IAXC_FORMAT_MPEG4:
+-              return CODEC_ID_MPEG4;
++              return AV_CODEC_ID_MPEG4;
+ 
+       case IAXC_FORMAT_H264:
+-              return CODEC_ID_H264;
++              return AV_CODEC_ID_H264;
+ 
+       case IAXC_FORMAT_THEORA:
+-              return CODEC_ID_THEORA;
++              return AV_CODEC_ID_THEORA;
+ 
+       default:
+-              return CODEC_ID_NONE;
++              return AV_CODEC_ID_NONE;
+       }
+ }
+ 
 @@ -165,10 +161,14 @@ static int pass_frame_to_decoder(AVCodecContext * avct
  {
        int bytes_decoded;
@@ -59,6 +90,15 @@ Update for newer FFmpeg API.
                if ( bytes_decoded < 0 )
                {
                        fprintf(stderr,
+@@ -374,7 +378,7 @@ static int encode(struct iaxc_video_codec *c,
+       struct encoder_ctx *e = (struct encoder_ctx *) c->encstate;
+       int encoded_size;
+ 
+-      avcodec_get_frame_defaults(e->picture);
++      av_frame_unref(e->picture);
+ 
+       e->picture->data[0] = (unsigned char *)in;
+       e->picture->data[1] = (unsigned char *)in
 @@ -441,6 +445,7 @@ struct iaxc_video_codec *codec_video_ffmpeg_new(int fo
  {
        struct encoder_ctx *e;
@@ -75,7 +115,7 @@ Update for newer FFmpeg API.
        avcodec_register_all();
  
        c->format = format;
-@@ -475,7 +479,7 @@ struct iaxc_video_codec *codec_video_ffmpeg_new(int fo
+@@ -475,10 +479,10 @@ struct iaxc_video_codec *codec_video_ffmpeg_new(int fo
        if (!c->encstate)
                goto bail;
        e = c->encstate;
@@ -83,7 +123,11 @@ Update for newer FFmpeg API.
 +      e->avctx = avcodec_alloc_context3(NULL);
        if (!e->avctx)
                goto bail;
-       e->picture = avcodec_alloc_frame();
+-      e->picture = avcodec_alloc_frame();
++      e->picture = av_frame_alloc();
+       if (!e->picture)
+               goto bail;
+       /* The idea here is that the encoded frame that will land in this
 @@ -496,7 +500,7 @@ struct iaxc_video_codec *codec_video_ffmpeg_new(int fo
        if (!c->decstate)
                goto bail;
@@ -93,61 +137,150 @@ Update for newer FFmpeg API.
        if (!d->avctx)
                goto bail;
        d->picture = avcodec_alloc_frame();
-@@ -524,9 +528,6 @@ struct iaxc_video_codec *codec_video_ffmpeg_new(int fo
-       e->avctx->pix_fmt = PIX_FMT_YUV420P;
+@@ -521,20 +525,20 @@ struct iaxc_video_codec *codec_video_ffmpeg_new(int fo
+ 
+       /* This determines how often i-frames are sent */
+       e->avctx->gop_size = framerate * 3;
+-      e->avctx->pix_fmt = PIX_FMT_YUV420P;
++      e->avctx->pix_fmt = AV_PIX_FMT_YUV420P;
        e->avctx->has_b_frames = 0;
  
 -      e->avctx->mb_qmin = e->avctx->qmin = 10;
 -      e->avctx->mb_qmax = e->avctx->qmax = 10;
 -
++#if 0
        e->avctx->lmin = 2 * FF_QP2LAMBDA;
        e->avctx->lmax = 10 * FF_QP2LAMBDA;
++#endif
++
        e->avctx->global_quality = FF_QP2LAMBDA * 2;
-@@ -561,7 +562,8 @@ struct iaxc_video_codec *codec_video_ffmpeg_new(int fo
+       e->avctx->qblur = 0.5;
+       e->avctx->global_quality = 10;
+ 
+-      e->avctx->flags |= CODEC_FLAG_PSNR;
+-      e->avctx->flags |= CODEC_FLAG_QSCALE;
++      e->avctx->flags |= AV_CODEC_FLAG_PSNR;
++      e->avctx->flags |= AV_CODEC_FLAG_QSCALE;
+ 
+       e->avctx->mb_decision = FF_MB_DECISION_SIMPLE;
+ 
+@@ -555,37 +559,38 @@ struct iaxc_video_codec *codec_video_ffmpeg_new(int fo
+       case IAXC_FORMAT_H263:
+               /* TODO: H263 only works with specific resolutions. */
+               name = "H.263";
+-              e->avctx->flags |= CODEC_FLAG_AC_PRED;
++              e->avctx->flags |= AV_CODEC_FLAG_AC_PRED;
+               if (fragsize)
+               {
                        c->decode = decode_rtp_slice;
                        e->avctx->rtp_payload_size = fragsize;
                        e->avctx->flags |=
 -                              CODEC_FLAG_TRUNCATED | CODEC_FLAG2_STRICT_GOP;
-+                              CODEC_FLAG_TRUNCATED;
++                              AV_CODEC_FLAG_TRUNCATED;
 +                      av_dict_set(&opts, "strict_gop", "1", 0);
                        e->avctx->rtp_callback = encode_rtp_callback;
-                       d->avctx->flags |= CODEC_FLAG_TRUNCATED;
+-                      d->avctx->flags |= CODEC_FLAG_TRUNCATED;
++                      d->avctx->flags |= AV_CODEC_FLAG_TRUNCATED;
                }
-@@ -581,9 +583,9 @@ struct iaxc_video_codec *codec_video_ffmpeg_new(int fo
+               break;
+ 
+       case IAXC_FORMAT_H263_PLUS:
+-              /* Although the encoder is CODEC_ID_H263P, the decoder
++              /* Although the encoder is AV_CODEC_ID_H263P, the decoder
+                * is the regular h.263, so we handle this special case
+                * here.
+                */
+-              ff_dec_id = CODEC_ID_H263;
++              ff_dec_id = AV_CODEC_ID_H263;
+               name = "H.263+";
+-              e->avctx->flags |= CODEC_FLAG_AC_PRED;
++              e->avctx->flags |= AV_CODEC_FLAG_AC_PRED;
+               if (fragsize)
+               {
+                       c->decode = decode_rtp_slice;
                        e->avctx->rtp_payload_size = fragsize;
                        e->avctx->flags |=
-                               CODEC_FLAG_TRUNCATED |
+-                              CODEC_FLAG_TRUNCATED |
 -                              CODEC_FLAG_H263P_SLICE_STRUCT |
 -                              CODEC_FLAG2_STRICT_GOP |
-                               CODEC_FLAG2_LOCAL_HEADER;
+-                              CODEC_FLAG2_LOCAL_HEADER;
++                              AV_CODEC_FLAG_TRUNCATED |
++                              AV_CODEC_FLAG2_LOCAL_HEADER;
 +                      av_dict_set(&opts, "strict_gop", "1", 0);
 +                      av_dict_set(&opts, "structured_slices", "1", 0);
                        e->avctx->rtp_callback = encode_rtp_callback;
-                       d->avctx->flags |= CODEC_FLAG_TRUNCATED;
+-                      d->avctx->flags |= CODEC_FLAG_TRUNCATED;
++                      d->avctx->flags |= AV_CODEC_FLAG_TRUNCATED;
                }
-@@ -596,10 +598,9 @@ struct iaxc_video_codec *codec_video_ffmpeg_new(int fo
+               break;
+ 
+@@ -595,12 +600,11 @@ struct iaxc_video_codec *codec_video_ffmpeg_new(int fo
+               e->avctx->rtp_payload_size = fragsize;
                e->avctx->rtp_callback = encode_rtp_callback;
                e->avctx->flags |=
-                       CODEC_FLAG_TRUNCATED |
+-                      CODEC_FLAG_TRUNCATED |
 -                      CODEC_FLAG_H263P_SLICE_STRUCT |
 -                      CODEC_FLAG2_STRICT_GOP |
-                       CODEC_FLAG2_LOCAL_HEADER;
+-                      CODEC_FLAG2_LOCAL_HEADER;
 -
+-              d->avctx->flags |= CODEC_FLAG_TRUNCATED;
++                      AV_CODEC_FLAG_TRUNCATED |
++                      AV_CODEC_FLAG2_LOCAL_HEADER;
 +              av_dict_set(&opts, "strict_gop", "1", 0);
 +              av_dict_set(&opts, "structured_slices", "1", 0);
-               d->avctx->flags |= CODEC_FLAG_TRUNCATED;
++              d->avctx->flags |= AV_CODEC_FLAG_TRUNCATED;
                break;
  
-@@ -625,7 +626,7 @@ struct iaxc_video_codec *codec_video_ffmpeg_new(int fo
-               /* e->avctx->flags2 |= CODEC_FLAG2_8X8DCT; */
+       case IAXC_FORMAT_H264:
+@@ -611,35 +615,35 @@ struct iaxc_video_codec *codec_video_ffmpeg_new(int fo
+                */
+ 
+               /* Headers are not repeated */
+-              /* e->avctx->flags |= CODEC_FLAG_GLOBAL_HEADER; */
++              /* e->avctx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; */
+ 
+               /* Slower, less blocky */
+-              /* e->avctx->flags |= CODEC_FLAG_LOOP_FILTER; */
++              /* e->avctx->flags |= AV_CODEC_FLAG_LOOP_FILTER; */
+ 
+-              e->avctx->flags |= CODEC_FLAG_PASS1;
+-              /* e->avctx->flags |= CODEC_FLAG_PASS2; */
++              e->avctx->flags |= AV_CODEC_FLAG_PASS1;
++              /* e->avctx->flags |= AV_CODEC_FLAG_PASS2; */
+ 
+               /* Compute psnr values at encode-time (avctx->error[]) */
+-              /* e->avctx->flags |= CODEC_FLAG_PSNR; */
++              /* e->avctx->flags |= AV_CODEC_FLAG_PSNR; */
+ 
+-              /* e->avctx->flags2 |= CODEC_FLAG2_8X8DCT; */
++              /* e->avctx->flags2 |= AV_CODEC_FLAG2_8X8DCT; */
  
                /* Access Unit Delimiters */
 -              e->avctx->flags2 |= CODEC_FLAG2_AUD;
 +              av_dict_set(&opts, "aud", "1", 0);
  
                /* Allow b-frames to be used as reference */
-               /* e->avctx->flags2 |= CODEC_FLAG2_BPYRAMID; */
-@@ -686,7 +687,7 @@ struct iaxc_video_codec *codec_video_ffmpeg_new(int fo
+-              /* e->avctx->flags2 |= CODEC_FLAG2_BPYRAMID; */
++              /* e->avctx->flags2 |= AV_CODEC_FLAG2_BPYRAMID; */
+ 
+               /* b-frame rate distortion optimization */
+-              /* e->avctx->flags2 |= CODEC_FLAG2_BRDO; */
++              /* e->avctx->flags2 |= AV_CODEC_FLAG2_BRDO; */
+ 
+-              /* e->avctx->flags2 |= CODEC_FLAG2_FASTPSKIP; */
++              /* e->avctx->flags2 |= AV_CODEC_FLAG2_FASTPSKIP; */
+ 
+               /* Multiple references per partition */
+-              /* e->avctx->flags2 |= CODEC_FLAG2_MIXED_REFS; */
++              /* e->avctx->flags2 |= AV_CODEC_FLAG2_MIXED_REFS; */
+ 
+               /* Weighted biprediction for b-frames */
+-              /* e->avctx->flags2 |= CODEC_FLAG2_WPRED; */
++              /* e->avctx->flags2 |= AV_CODEC_FLAG2_WPRED; */
+ 
+               /*
+                * Decoder flags
+@@ -686,7 +690,7 @@ struct iaxc_video_codec *codec_video_ffmpeg_new(int fo
                goto bail;
        }
  
@@ -156,7 +289,7 @@ Update for newer FFmpeg API.
        {
                iaxci_usermsg(IAXC_TEXT_TYPE_ERROR,
                             "codec_ffmpeg: cannot open encoder %s\n", name);
-@@ -701,7 +702,7 @@ struct iaxc_video_codec *codec_video_ffmpeg_new(int fo
+@@ -701,7 +705,7 @@ struct iaxc_video_codec *codec_video_ffmpeg_new(int fo
                             ff_dec_id);
                goto bail;
        }
@@ -165,7 +298,18 @@ Update for newer FFmpeg API.
        {
                iaxci_usermsg(IAXC_TEXT_TYPE_ERROR,
                             "codec_ffmpeg: cannot open decoder %s\n", name);
-@@ -728,12 +729,11 @@ bail:
+@@ -709,8 +713,8 @@ struct iaxc_video_codec *codec_video_ffmpeg_new(int fo
+       }
+ 
+       {
+-              enum PixelFormat fmts[] = { PIX_FMT_YUV420P, -1 };
+-              if (d->avctx->get_format(d->avctx, fmts) != PIX_FMT_YUV420P)
++              enum AVPixelFormat fmts[] = { AV_PIX_FMT_YUV420P, -1 };
++              if (d->avctx->get_format(d->avctx, fmts) != AV_PIX_FMT_YUV420P)
+               {
+                       iaxci_usermsg(IAXC_TEXT_TYPE_ERROR,
+                                       "codec_ffmpeg: cannot set decode format 
to YUV420P\n");
+@@ -728,17 +732,16 @@ bail:
  int codec_video_ffmpeg_check_codec(int format)
  {
        AVCodec *codec;
@@ -179,3 +323,9 @@ Update for newer FFmpeg API.
        avcodec_register_all();
  
        codec_id = map_iaxc_codec_to_avcodec(format);
+ 
+-      if (codec_id == CODEC_ID_NONE)
++      if (codec_id == AV_CODEC_ID_NONE)
+               return 0;
+ 
+       codec = avcodec_find_encoder(codec_id);

Reply via email to