Hi,

The following diff uses a patch from upstream to avoid some deprecation
warnings when building audio/cmus with our current version of FFmpeg.

Update my email address, while here.

(I'm not upgrading to the latest 2.8.0 for the moment.  It's been
released just after the project has been declared not maintained, and
there are some regressions.)

Also available here if the diff gets mangled:
https://www.dwatteau.fr/tmp/cmus_ffmpeg_fixes-20190310.diff

Thanks.

Index: Makefile
===================================================================
RCS file: /cvs/ports/audio/cmus/Makefile,v
retrieving revision 1.19
diff -u -p -r1.19 Makefile
--- Makefile    5 Dec 2018 20:19:00 -0000       1.19
+++ Makefile    10 Mar 2019 12:53:48 -0000
@@ -7,7 +7,7 @@ V=                      2.7.1
 DISTNAME=              cmus-${V}
 PKGNAME-main=          ${PKGNAME}
 PKGNAME-ffmpeg=                cmus-ffmpeg-${V}
-REVISION=              5
+REVISION=              6
 
 GH_ACCOUNT=            cmus
 GH_PROJECT=            cmus
@@ -16,7 +16,7 @@ GH_TAGNAME=           v${V}
 CATEGORIES=            audio
 HOMEPAGE=              https://cmus.github.io/
 
-MAINTAINER=            Donovan Watteau <tso...@gmail.com>
+MAINTAINER=            Donovan Watteau <cont...@dwatteau.fr>
 
 # GPLv2+
 PERMIT_PACKAGE_CDROM=  Yes
Index: patches/patch-ffmpeg_c
===================================================================
RCS file: /cvs/ports/audio/cmus/patches/patch-ffmpeg_c,v
retrieving revision 1.1
diff -u -p -r1.1 patch-ffmpeg_c
--- patches/patch-ffmpeg_c      6 Jun 2018 12:14:44 -0000       1.1
+++ patches/patch-ffmpeg_c      10 Mar 2019 12:53:48 -0000
@@ -8,6 +8,7 @@ among other things:
 98ab2a6: Replace deprecated FFmpeg API
 ef65f69: remove dead code for ancient ffmpeg versions
 b595b8c: Fix ffmpeg plugin build
+9877eb0: Fixes ffmpeg deprecations
 
 Index: ffmpeg.c
 --- ffmpeg.c.orig
@@ -91,7 +92,7 @@ Index: ffmpeg.c
        free(input);
  }
  
-@@ -157,30 +128,9 @@ static void ffmpeg_init(void)
+@@ -157,26 +128,7 @@ static void ffmpeg_init(void)
  
        av_log_set_level(AV_LOG_QUIET);
  
@@ -115,14 +116,18 @@ Index: ffmpeg.c
 -
 -      register_protocol(&file_protocol);
 -#else
++#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(58, 18, 100)
        /* We could register decoders explicitly to save memory, but we have to
         * be careful about compatibility. */
        av_register_all();
--#endif
- }
- 
- static int ffmpeg_open(struct input_plugin_data *ip_data)
-@@ -197,22 +147,14 @@ static int ffmpeg_open(struct input_plugin_data *ip_da
+@@ -193,26 +145,21 @@ static int ffmpeg_open(struct input_plugin_data *ip_da
+       AVCodec *codec;
+       AVCodecContext *cc = NULL;
+       AVFormatContext *ic = NULL;
++#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 48, 101)
++      AVCodecParameters *cp = NULL;
++#endif
+       SwrContext *swr = NULL;
  
        ffmpeg_init();
  
@@ -145,9 +150,39 @@ Index: ffmpeg.c
                if (err < 0) {
                        d_print("unable to find stream info: %d\n", err);
                        err = -IP_ERROR_FILE_FORMAT;
-@@ -235,20 +177,16 @@ static int ffmpeg_open(struct input_plugin_data *ip_da
+@@ -220,11 +167,21 @@ static int ffmpeg_open(struct input_plugin_data *ip_da
+               }
+ 
+               for (i = 0; i < ic->nb_streams; i++) {
++
++#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 48, 101)
++                      cp = ic->streams[i]->codecpar;
++                      if (cp->codec_type == AVMEDIA_TYPE_AUDIO) {
++                              stream_index = i;
++                              break;
++                      }
++#else
++
+                       cc = ic->streams[i]->codec;
+                       if (cc->codec_type == AVMEDIA_TYPE_AUDIO) {
+                               stream_index = i;
+                               break;
+                       }
++#endif
+               }
  
+               if (stream_index == -1) {
+@@ -233,22 +190,24 @@ static int ffmpeg_open(struct input_plugin_data *ip_da
+                       break;
+               }
+ 
++#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 48, 101)
++              codec = avcodec_find_decoder(cp->codec_id);
++              cc = avcodec_alloc_context3(codec);
++              avcodec_parameters_to_context(cc, cp);
++#else
                codec = avcodec_find_decoder(cc->codec_id);
++#endif
                if (!codec) {
 -                      d_print("codec not found: %d, %s\n", cc->codec_id, 
cc->codec_name);
 +                      d_print("codec not found: %d, %s\n", cc->codec_id, 
avcodec_get_name(cc->codec_id));
@@ -170,19 +205,22 @@ Index: ffmpeg.c
                        err = -IP_ERROR_UNSUPPORTED_FILE_TYPE;
                        break;
                }
-@@ -258,11 +196,7 @@ static int ffmpeg_open(struct input_plugin_data *ip_da
+@@ -258,11 +217,10 @@ static int ffmpeg_open(struct input_plugin_data *ip_da
  
        if (err < 0) {
                /* Clean up.  cc is never opened at this point.  (See above 
assumption.) */
 -#if (LIBAVCODEC_VERSION_INT < ((53<<16)+(25<<8)+0))
 -              av_close_input_file(ic);
 -#else
-               avformat_close_input(&ic);
--#endif
+-              avformat_close_input(&ic);
++#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 48, 101)
++              avcodec_free_context(&cc);
+ #endif
++              avformat_close_input(&ic);
                return err;
        }
  
-@@ -270,18 +204,14 @@ static int ffmpeg_open(struct input_plugin_data *ip_da
+@@ -270,18 +228,17 @@ static int ffmpeg_open(struct input_plugin_data *ip_da
        priv->codec_context = cc;
        priv->input_context = ic;
        priv->codec = codec;
@@ -193,8 +231,11 @@ Index: ffmpeg.c
 -#if (LIBAVCODEC_VERSION_INT < ((53<<16)+(25<<8)+0))
 -              av_close_input_file(ic);
 -#else
-               avformat_close_input(&ic);
--#endif
+-              avformat_close_input(&ic);
++#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 48, 101)
++              avcodec_free_context(&cc);
+ #endif
++              avformat_close_input(&ic);
                free(priv);
                return -IP_ERROR_INTERNAL;
        }
@@ -202,7 +243,7 @@ Index: ffmpeg.c
        priv->output = ffmpeg_output_create();
  
        /* Prepare for resampling. */
-@@ -314,9 +244,7 @@ static int ffmpeg_open(struct input_plugin_data *ip_da
+@@ -314,9 +271,7 @@ static int ffmpeg_open(struct input_plugin_data *ip_da
  #ifdef WORDS_BIGENDIAN
        ip_data->sf |= sf_bigendian(1);
  #endif
@@ -212,19 +253,22 @@ Index: ffmpeg.c
        channel_map_init_waveex(cc->channels, channel_layout, 
ip_data->channel_map);
        return 0;
  }
-@@ -326,11 +254,7 @@ static int ffmpeg_close(struct input_plugin_data *ip_d
+@@ -326,11 +281,10 @@ static int ffmpeg_close(struct input_plugin_data *ip_d
        struct ffmpeg_private *priv = ip_data->private;
  
        avcodec_close(priv->codec_context);
 -#if (LIBAVCODEC_VERSION_INT < ((53<<16)+(25<<8)+0))
 -      av_close_input_file(priv->input_context);
 -#else
-       avformat_close_input(&priv->input_context);
--#endif
+-      avformat_close_input(&priv->input_context);
++#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 48, 101)
++      avcodec_free_context(&priv->codec_context);
+ #endif
++      avformat_close_input(&priv->input_context);
        swr_free(&priv->swr);
        ffmpeg_input_free(priv->input);
        ffmpeg_output_free(priv->output);
-@@ -346,62 +270,50 @@ static int ffmpeg_close(struct input_plugin_data *ip_d
+@@ -346,62 +300,63 @@ static int ffmpeg_close(struct input_plugin_data *ip_d
  static int ffmpeg_fill_buffer(AVFormatContext *ic, AVCodecContext *cc, struct 
ffmpeg_input *input,
                              struct ffmpeg_output *output, SwrContext *swr)
  {
@@ -297,7 +341,20 @@ Index: ffmpeg.c
 -                      AVPacket avpkt;
                        av_new_packet(&avpkt, input->curr_pkt_size);
                        memcpy(avpkt.data, input->curr_pkt_buf, 
input->curr_pkt_size);
++#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 48, 101)
++                      if (avcodec_send_packet(cc, &avpkt) == 0) {
++                              got_frame = !avcodec_receive_frame(cc, frame);
++                              if (got_frame)
++                                      len = input->curr_pkt_size;
++                              else
++                                      len = 0;
++                      } else {
++                              got_frame = 0;
++                              len = 0;
++                      }
++#else
                        len = avcodec_decode_audio4(cc, frame, &got_frame, 
&avpkt);
++#endif
 +#if LIBAVCODEC_VERSION_MAJOR >= 56
 +                      av_packet_unref(&avpkt);
 +#else
@@ -308,7 +365,7 @@ Index: ffmpeg.c
                if (len < 0) {
                        /* this is often reached when seeking, not sure why */
                        input->curr_pkt_size = 0;
-@@ -409,13 +321,6 @@ static int ffmpeg_fill_buffer(AVFormatContext *ic, AVC
+@@ -409,13 +364,6 @@ static int ffmpeg_fill_buffer(AVFormatContext *ic, AVC
                }
                input->curr_pkt_size -= len;
                input->curr_pkt_buf += len;
@@ -322,7 +379,7 @@ Index: ffmpeg.c
                if (got_frame) {
                        int res = swr_convert(swr,
                                        &output->buffer,
-@@ -426,10 +331,13 @@ static int ffmpeg_fill_buffer(AVFormatContext *ic, AVC
+@@ -426,10 +374,13 @@ static int ffmpeg_fill_buffer(AVFormatContext *ic, AVC
                                res = 0;
                        output->buffer_pos = output->buffer;
                        output->buffer_used_len = res * cc->channels * 
sizeof(int16_t);
@@ -337,7 +394,7 @@ Index: ffmpeg.c
        }
        /* This should never get here. */
        return -IP_ERROR_INTERNAL;
-@@ -459,30 +367,16 @@ static int ffmpeg_read(struct input_plugin_data *ip_da
+@@ -459,30 +410,16 @@ static int ffmpeg_read(struct input_plugin_data *ip_da
  static int ffmpeg_seek(struct input_plugin_data *ip_data, double offset)
  {
        struct ffmpeg_private *priv = ip_data->private;
@@ -373,7 +430,7 @@ Index: ffmpeg.c
  
        if (ret < 0) {
                return -IP_ERROR_FUNCTION_NOT_SUPPORTED;
-@@ -492,56 +386,30 @@ static int ffmpeg_seek(struct input_plugin_data *ip_da
+@@ -492,56 +429,30 @@ static int ffmpeg_seek(struct input_plugin_data *ip_da
        }
  }
  
@@ -439,7 +496,7 @@ Index: ffmpeg.c
  
        return 0;
  }
-@@ -562,13 +430,15 @@ static long ffmpeg_bitrate(struct input_plugin_data *i
+@@ -562,13 +473,15 @@ static long ffmpeg_bitrate(struct input_plugin_data *i
  static long ffmpeg_current_bitrate(struct input_plugin_data *ip_data)
  {
        struct ffmpeg_private *priv = ip_data->private;
@@ -458,7 +515,7 @@ Index: ffmpeg.c
        if (priv->input->curr_duration > 0) {
                double seconds = priv->input->curr_duration * 
av_q2d(st->time_base);
                bitrate = (8 * priv->input->curr_size) / seconds;
-@@ -584,32 +454,11 @@ static char *ffmpeg_codec(struct input_plugin_data *ip
+@@ -584,32 +497,11 @@ static char *ffmpeg_codec(struct input_plugin_data *ip
        return xstrdup(priv->codec->name);
  }
  

Reply via email to