Re: [libav-devel] [RFC][PATCH] Drop non-refcounted-frame code on the next version bump

2017-10-24 Thread Vittorio Giovara
On Tue, Oct 24, 2017 at 2:21 PM, Diego Biurrun  wrote:

> ---
>
> I'm quite suspicious of this. It passes tests w/ and w/o a lavc version
> bump,
>

doesn't that mean that the compat layer works as expected?
-- 
Vittorio
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

[libav-devel] [RFC][PATCH] Drop non-refcounted-frame code on the next version bump

2017-10-24 Thread Diego Biurrun
---

I'm quite suspicious of this. It passes tests w/ and w/o a lavc version
bump, but I'm sure it's not completely correct and/or may need further
changes in other parts of the codebase. The documentation bits probably
need changes as well.

 avtools/avconv.c   |  2 ++
 avtools/avplay.c   |  2 ++
 doc/examples/qsvdec.c  |  2 ++
 libavcodec/avcodec.h   | 10 ++
 libavcodec/decode.c| 13 +
 libavcodec/encode.c|  2 ++
 libavcodec/options_table.h |  2 ++
 libavcodec/qsv_internal.h  |  6 --
 libavcodec/version.h   |  3 +++
 libavfilter/buffersrc.c| 20 +++-
 libavfilter/vsrc_movie.c   |  5 +
 libavutil/frame.c  |  6 ++
 libavutil/frame.h  |  6 ++
 13 files changed, 76 insertions(+), 3 deletions(-)

diff --git a/avtools/avconv.c b/avtools/avconv.c
index 4e3ffecdef..372290bb89 100644
--- a/avtools/avconv.c
+++ b/avtools/avconv.c
@@ -1713,7 +1713,9 @@ static int init_input_stream(int ist_index, char *error, 
int error_len)
 ist->dec_ctx->get_buffer2   = get_buffer;
 ist->dec_ctx->thread_safe_callbacks = 1;
 
+#if FF_API_REFCOUNTED_FRAMES
 av_opt_set_int(ist->dec_ctx, "refcounted_frames", 1, 0);
+#endif /* FF_API_REFCOUNTED_FRAMES */
 
 if (!av_dict_get(ist->decoder_opts, "threads", NULL, 0))
 av_dict_set(>decoder_opts, "threads", "auto", 0);
diff --git a/avtools/avplay.c b/avtools/avplay.c
index b6dbc52cf7..5b1114d454 100644
--- a/avtools/avplay.c
+++ b/avtools/avplay.c
@@ -2069,8 +2069,10 @@ static int stream_component_open(PlayerState *is, int 
stream_index)
 
 if (!av_dict_get(opts, "threads", NULL, 0))
 av_dict_set(, "threads", "auto", 0);
+#if FF_API_REFCOUNTED_FRAMES
 if (avctx->codec_type == AVMEDIA_TYPE_VIDEO)
 av_dict_set(, "refcounted_frames", "1", 0);
+#endif /* FF_API_REFCOUNTED_FRAMES */
 if (!codec ||
 (ret = avcodec_open2(avctx, codec, )) < 0) {
 goto fail;
diff --git a/doc/examples/qsvdec.c b/doc/examples/qsvdec.c
index 46e6ddcb0d..d77190595e 100644
--- a/doc/examples/qsvdec.c
+++ b/doc/examples/qsvdec.c
@@ -210,7 +210,9 @@ int main(int argc, char **argv)
video_st->codecpar->extradata_size);
 decoder_ctx->extradata_size = video_st->codecpar->extradata_size;
 }
+#if FF_API_REFCOUNTED_FRAMES
 decoder_ctx->refcounted_frames = 1;
+#endif /* FF_API_REFCOUNTED_FRAMES */
 
 decoder_ctx->opaque  = 
 decoder_ctx->get_format  = get_format;
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 5624835023..e76753cfed 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -1982,6 +1982,7 @@ typedef struct AVCodecContext {
  */
 int (*get_buffer2)(struct AVCodecContext *s, AVFrame *frame, int flags);
 
+#if FF_API_REFCOUNTED_FRAMES
 /**
  * If non-zero, the decoded audio and video frames returned from
  * avcodec_decode_video2() and avcodec_decode_audio4() are 
reference-counted
@@ -1996,6 +1997,7 @@ typedef struct AVCodecContext {
  * - decoding: set by the caller before avcodec_open2().
  */
 attribute_deprecated int refcounted_frames;
+#endif /* FF_API_REFCOUNTED_FRAMES */
 
 /* - encoding parameters */
 float qcompress;  ///< amount of qscale change between easy & hard scenes 
(0.0-1.0)
@@ -3767,6 +3769,7 @@ void avcodec_align_dimensions2(AVCodecContext *s, int 
*width, int *height,
  * @param  avctx the codec context
  * @param[out] frame The AVFrame in which to store decoded audio samples.
  *   The decoder will allocate a buffer for the decoded frame 
by
+#if FF_API_REFCOUNTED_FRAMES
  *   calling the AVCodecContext.get_buffer2() callback.
  *   When AVCodecContext.refcounted_frames is set to 1, the 
frame is
  *   reference counted and the returned reference belongs to 
the
@@ -3777,6 +3780,13 @@ void avcodec_align_dimensions2(AVCodecContext *s, int 
*width, int *height,
  *   reference belongs to the decoder and is valid only until 
the
  *   next call to this function or until closing or flushing 
the
  *   decoder. The caller may not write to it.
+#else
+ *   calling the AVCodecContext.get_buffer2() callback. The
+ *   returned reference belongs to the caller. The caller must
+ *   release the frame using av_frame_unref() when the frame is
+ *   no longer needed. The caller may safely write to the frame
+ *   if av_frame_is_writable() returns 1.
+#endif
  * @param[out] got_frame_ptr Zero if no frame could be decoded, otherwise it is
  *   non-zero. Note that this field being set to zero
  *   does not mean that an error has occurred. For
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 27f75d73e3..110cc6529b 100644
--- a/libavcodec/decode.c

Re: [libav-devel] [RFC] [PATCH] Drop non-refcounted-frame code on the next version bump

2017-10-24 Thread Diego Biurrun
On Tue, Oct 24, 2017 at 10:35:19AM +0200, wm4 wrote:
> On Sun, 22 Oct 2017 07:57:42 +0200
> Diego Biurrun  wrote:
> > ---
> >  libavcodec/decode.c  | 11 +++
> >  libavcodec/version.h |  3 +++
> >  libavfilter/vsrc_movie.c |  5 +
> >  3 files changed, 19 insertions(+)
> 
> LGTM, but wondering what'll happen with the avctx field.

Now that you mention the field I wonder why I made such a silly mistake. :)
Thanks for the review, better patch coming later.

Diego
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

Re: [libav-devel] [RFC] [PATCH] Drop non-refcounted-frame code on the next version bump

2017-10-24 Thread wm4
On Sun, 22 Oct 2017 07:57:42 +0200
Diego Biurrun  wrote:

> ---
>  libavcodec/decode.c  | 11 +++
>  libavcodec/version.h |  3 +++
>  libavfilter/vsrc_movie.c |  5 +
>  3 files changed, 19 insertions(+)
> 
> diff --git a/libavcodec/decode.c b/libavcodec/decode.c
> index b74c163f92..040e1cc08e 100644
> --- a/libavcodec/decode.c
> +++ b/libavcodec/decode.c
> @@ -36,6 +36,7 @@
>  #include "decode.h"
>  #include "internal.h"
>  #include "thread.h"
> +#include "version.h"
>  
>  static int apply_param_change(AVCodecContext *avctx, AVPacket *avpkt)
>  {
> @@ -576,11 +577,15 @@ static int compat_decode(AVCodecContext *avctx, AVFrame 
> *frame,
>  }
>  
>  if (frame != avci->compat_decode_frame) {
> +#if FF_API_REFCOUNTED_FRAMES
> +FF_DISABLE_DEPRECATION_WARNINGS
>  if (!avctx->refcounted_frames) {
>  ret = unrefcount_frame(avci, frame);
>  if (ret < 0)
>  goto finish;
>  }
> +FF_ENABLE_DEPRECATION_WARNINGS
> +#endif
>  
>  *got_frame = 1;
>  frame = avci->compat_decode_frame;
> @@ -1277,8 +1282,14 @@ void avcodec_flush_buffers(AVCodecContext *avctx)
>  
>  ff_decode_bsfs_uninit(avctx);
>  
> +#if FF_API_REFCOUNTED_FRAMES
> +FF_DISABLE_DEPRECATION_WARNINGS
>  if (!avctx->refcounted_frames)
>  av_frame_unref(avctx->internal->to_free);
> +FF_ENABLE_DEPRECATION_WARNINGS
> +#else
> +av_frame_unref(avctx->internal->to_free);
> +#endif
>  }
>  
>  void ff_decode_bsfs_uninit(AVCodecContext *avctx)
> diff --git a/libavcodec/version.h b/libavcodec/version.h
> index aa6cdcd6bc..f0cba4cc6b 100644
> --- a/libavcodec/version.h
> +++ b/libavcodec/version.h
> @@ -95,5 +95,8 @@
>  #ifndef FF_API_VAAPI_CONTEXT
>  #define FF_API_VAAPI_CONTEXT(LIBAVCODEC_VERSION_MAJOR < 59)
>  #endif
> +#ifndef FF_API_REFCOUNTED_FRAMES
> +#define FF_API_REFCOUNTED_FRAMES (LIBAVCODEC_VERSION_MAJOR < 59)
> +#endif
>  
>  #endif /* AVCODEC_VERSION_H */
> diff --git a/libavfilter/vsrc_movie.c b/libavfilter/vsrc_movie.c
> index aff6e620ff..0bacb672fd 100644
> --- a/libavfilter/vsrc_movie.c
> +++ b/libavfilter/vsrc_movie.c
> @@ -37,6 +37,7 @@
>  #include "libavutil/imgutils.h"
>  
>  #include "libavcodec/avcodec.h"
> +#include "libavcodec/version.h"
>  
>  #include "libavformat/avformat.h"
>  
> @@ -157,7 +158,11 @@ static av_cold int movie_init(AVFilterContext *ctx)
>  if (ret < 0)
>  return ret;
>  
> +#if FF_API_REFCOUNTED_FRAMES
> +FF_DISABLE_DEPRECATION_WARNINGS
>  movie->codec_ctx->refcounted_frames = 1;
> +FF_ENABLE_DEPRECATION_WARNINGS
> +#endif
>  
>  if ((ret = avcodec_open2(movie->codec_ctx, codec, NULL)) < 0) {
>  av_log(ctx, AV_LOG_ERROR, "Failed to open codec\n");

LGTM, but wondering what'll happen with the avctx field.
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

[libav-devel] [RFC] [PATCH] Drop non-refcounted-frame code on the next version bump

2017-10-21 Thread Diego Biurrun
---
 libavcodec/decode.c  | 11 +++
 libavcodec/version.h |  3 +++
 libavfilter/vsrc_movie.c |  5 +
 3 files changed, 19 insertions(+)

diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index b74c163f92..040e1cc08e 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -36,6 +36,7 @@
 #include "decode.h"
 #include "internal.h"
 #include "thread.h"
+#include "version.h"
 
 static int apply_param_change(AVCodecContext *avctx, AVPacket *avpkt)
 {
@@ -576,11 +577,15 @@ static int compat_decode(AVCodecContext *avctx, AVFrame 
*frame,
 }
 
 if (frame != avci->compat_decode_frame) {
+#if FF_API_REFCOUNTED_FRAMES
+FF_DISABLE_DEPRECATION_WARNINGS
 if (!avctx->refcounted_frames) {
 ret = unrefcount_frame(avci, frame);
 if (ret < 0)
 goto finish;
 }
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
 
 *got_frame = 1;
 frame = avci->compat_decode_frame;
@@ -1277,8 +1282,14 @@ void avcodec_flush_buffers(AVCodecContext *avctx)
 
 ff_decode_bsfs_uninit(avctx);
 
+#if FF_API_REFCOUNTED_FRAMES
+FF_DISABLE_DEPRECATION_WARNINGS
 if (!avctx->refcounted_frames)
 av_frame_unref(avctx->internal->to_free);
+FF_ENABLE_DEPRECATION_WARNINGS
+#else
+av_frame_unref(avctx->internal->to_free);
+#endif
 }
 
 void ff_decode_bsfs_uninit(AVCodecContext *avctx)
diff --git a/libavcodec/version.h b/libavcodec/version.h
index aa6cdcd6bc..f0cba4cc6b 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -95,5 +95,8 @@
 #ifndef FF_API_VAAPI_CONTEXT
 #define FF_API_VAAPI_CONTEXT(LIBAVCODEC_VERSION_MAJOR < 59)
 #endif
+#ifndef FF_API_REFCOUNTED_FRAMES
+#define FF_API_REFCOUNTED_FRAMES (LIBAVCODEC_VERSION_MAJOR < 59)
+#endif
 
 #endif /* AVCODEC_VERSION_H */
diff --git a/libavfilter/vsrc_movie.c b/libavfilter/vsrc_movie.c
index aff6e620ff..0bacb672fd 100644
--- a/libavfilter/vsrc_movie.c
+++ b/libavfilter/vsrc_movie.c
@@ -37,6 +37,7 @@
 #include "libavutil/imgutils.h"
 
 #include "libavcodec/avcodec.h"
+#include "libavcodec/version.h"
 
 #include "libavformat/avformat.h"
 
@@ -157,7 +158,11 @@ static av_cold int movie_init(AVFilterContext *ctx)
 if (ret < 0)
 return ret;
 
+#if FF_API_REFCOUNTED_FRAMES
+FF_DISABLE_DEPRECATION_WARNINGS
 movie->codec_ctx->refcounted_frames = 1;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
 
 if ((ret = avcodec_open2(movie->codec_ctx, codec, NULL)) < 0) {
 av_log(ctx, AV_LOG_ERROR, "Failed to open codec\n");
-- 
2.11.0

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel