lavc: deprecate avcodec_close()

Its use has been discouraged since 2016, but now is no longer used in
avformat, so there is no reason to keep it public.
This commit is contained in:
Anton Khirnov 2024-02-01 09:19:46 +01:00
parent ca18bb5972
commit 1cc24d7495
6 changed files with 21 additions and 7 deletions

View File

@ -377,7 +377,7 @@ end:
return ret; return ret;
free_and_end: free_and_end:
avcodec_close(avctx); ff_codec_close(avctx);
goto end; goto end;
} }
@ -432,12 +432,12 @@ void avsubtitle_free(AVSubtitle *sub)
memset(sub, 0, sizeof(*sub)); memset(sub, 0, sizeof(*sub));
} }
av_cold int avcodec_close(AVCodecContext *avctx) av_cold void ff_codec_close(AVCodecContext *avctx)
{ {
int i; int i;
if (!avctx) if (!avctx)
return 0; return;
if (avcodec_is_open(avctx)) { if (avcodec_is_open(avctx)) {
AVCodecInternal *avci = avctx->internal; AVCodecInternal *avci = avctx->internal;
@ -497,9 +497,15 @@ av_cold int avcodec_close(AVCodecContext *avctx)
avctx->codec = NULL; avctx->codec = NULL;
avctx->active_thread_type = 0; avctx->active_thread_type = 0;
}
#if FF_API_AVCODEC_CLOSE
int avcodec_close(AVCodecContext *avctx)
{
ff_codec_close(avctx);
return 0; return 0;
} }
#endif
static const char *unknown_if_null(const char *str) static const char *unknown_if_null(const char *str)
{ {

View File

@ -2411,6 +2411,7 @@ int avcodec_parameters_to_context(AVCodecContext *codec,
*/ */
int avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options); int avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options);
#if FF_API_AVCODEC_CLOSE
/** /**
* Close a given AVCodecContext and free all the data associated with it * Close a given AVCodecContext and free all the data associated with it
* (but not the AVCodecContext itself). * (but not the AVCodecContext itself).
@ -2419,12 +2420,14 @@ int avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **op
* the codec-specific data allocated in avcodec_alloc_context3() with a non-NULL * the codec-specific data allocated in avcodec_alloc_context3() with a non-NULL
* codec. Subsequent calls will do nothing. * codec. Subsequent calls will do nothing.
* *
* @note Do not use this function. Use avcodec_free_context() to destroy a * @deprecated Do not use this function. Use avcodec_free_context() to destroy a
* codec context (either open or closed). Opening and closing a codec context * codec context (either open or closed). Opening and closing a codec context
* multiple times is not supported anymore -- use multiple codec contexts * multiple times is not supported anymore -- use multiple codec contexts
* instead. * instead.
*/ */
attribute_deprecated
int avcodec_close(AVCodecContext *avctx); int avcodec_close(AVCodecContext *avctx);
#endif
/** /**
* Free all allocated data in the given subtitle struct. * Free all allocated data in the given subtitle struct.

View File

@ -56,4 +56,6 @@ void ff_encode_flush_buffers(struct AVCodecContext *avctx);
struct AVCodecInternal *ff_decode_internal_alloc(void); struct AVCodecInternal *ff_decode_internal_alloc(void);
struct AVCodecInternal *ff_encode_internal_alloc(void); struct AVCodecInternal *ff_encode_internal_alloc(void);
void ff_codec_close(struct AVCodecContext *avctx);
#endif // AVCODEC_AVCODEC_INTERNAL_H #endif // AVCODEC_AVCODEC_INTERNAL_H

View File

@ -27,6 +27,7 @@
#include "libavutil/opt.h" #include "libavutil/opt.h"
#include "libavutil/thread.h" #include "libavutil/thread.h"
#include "avcodec.h" #include "avcodec.h"
#include "avcodec_internal.h"
#include "encode.h" #include "encode.h"
#include "internal.h" #include "internal.h"
#include "pthread_internal.h" #include "pthread_internal.h"
@ -110,7 +111,7 @@ static void * attribute_align_arg worker(void *v){
pthread_mutex_unlock(&c->finished_task_mutex); pthread_mutex_unlock(&c->finished_task_mutex);
} }
end: end:
avcodec_close(avctx); ff_codec_close(avctx);
av_freep(&avctx); av_freep(&avctx);
return NULL; return NULL;
} }
@ -230,7 +231,7 @@ av_cold int ff_frame_thread_encoder_init(AVCodecContext *avctx)
return 0; return 0;
fail: fail:
avcodec_close(thread_avctx); ff_codec_close(thread_avctx);
av_freep(&thread_avctx); av_freep(&thread_avctx);
avctx->thread_count = i; avctx->thread_count = i;
av_log(avctx, AV_LOG_ERROR, "ff_frame_thread_encoder_init failed\n"); av_log(avctx, AV_LOG_ERROR, "ff_frame_thread_encoder_init failed\n");

View File

@ -27,6 +27,7 @@
#include "config_components.h" #include "config_components.h"
#include "avcodec.h" #include "avcodec.h"
#include "avcodec_internal.h"
#include "codec_internal.h" #include "codec_internal.h"
#include "libavutil/avassert.h" #include "libavutil/avassert.h"
#include "libavutil/internal.h" #include "libavutil/internal.h"
@ -172,7 +173,7 @@ void avcodec_free_context(AVCodecContext **pavctx)
if (!avctx) if (!avctx)
return; return;
avcodec_close(avctx); ff_codec_close(avctx);
av_freep(&avctx->extradata); av_freep(&avctx->extradata);
av_freep(&avctx->subtitle_header); av_freep(&avctx->subtitle_header);

View File

@ -52,6 +52,7 @@
#define FF_API_AVFFT (LIBAVCODEC_VERSION_MAJOR < 62) #define FF_API_AVFFT (LIBAVCODEC_VERSION_MAJOR < 62)
#define FF_API_FF_PROFILE_LEVEL (LIBAVCODEC_VERSION_MAJOR < 62) #define FF_API_FF_PROFILE_LEVEL (LIBAVCODEC_VERSION_MAJOR < 62)
#define FF_API_AVCODEC_CLOSE (LIBAVCODEC_VERSION_MAJOR < 62)
// reminder to remove CrystalHD decoders on next major bump // reminder to remove CrystalHD decoders on next major bump
#define FF_CODEC_CRYSTAL_HD (LIBAVCODEC_VERSION_MAJOR < 61) #define FF_CODEC_CRYSTAL_HD (LIBAVCODEC_VERSION_MAJOR < 61)