]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/options.c
hevc: reduce variable scope
[ffmpeg] / libavcodec / options.c
index d140552711d0a0df174b58b088811f8bdba473dd..c00dca078e59b1d52b4ae9ee5485e1c5dde22058 100644 (file)
@@ -27,6 +27,7 @@
 #include "avcodec.h"
 #include "internal.h"
 #include "libavutil/avassert.h"
+#include "libavutil/internal.h"
 #include "libavutil/mem.h"
 #include "libavutil/opt.h"
 #include <float.h>              /* FLT_MIN, FLT_MAX */
@@ -70,7 +71,7 @@ static const AVClass *codec_child_class_next(const AVClass *prev)
 static const AVClass av_codec_context_class = {
     .class_name              = "AVCodecContext",
     .item_name               = context_to_name,
-    .option                  = options,
+    .option                  = avcodec_options,
     .version                 = LIBAVUTIL_VERSION_INT,
     .log_level_offset_offset = offsetof(AVCodecContext, log_level_offset),
     .child_next              = codec_child_next,
@@ -88,6 +89,7 @@ int avcodec_get_context_defaults3(AVCodecContext *s, const AVCodec *codec)
     av_opt_set_defaults(s);
 
     s->time_base           = (AVRational){0,1};
+    s->framerate           = (AVRational){ 0, 1 };
     s->get_buffer2         = avcodec_default_get_buffer2;
     s->get_format          = avcodec_default_get_format;
     s->execute             = avcodec_default_execute;
@@ -125,7 +127,8 @@ AVCodecContext *avcodec_alloc_context3(const AVCodec *codec)
 {
     AVCodecContext *avctx= av_malloc(sizeof(AVCodecContext));
 
-    if(avctx==NULL) return NULL;
+    if (!avctx)
+        return NULL;
 
     if(avcodec_get_context_defaults3(avctx, codec) < 0){
         av_free(avctx);
@@ -135,8 +138,26 @@ AVCodecContext *avcodec_alloc_context3(const AVCodec *codec)
     return avctx;
 }
 
+void avcodec_free_context(AVCodecContext **pavctx)
+{
+    AVCodecContext *avctx = *pavctx;
+
+    if (!avctx)
+        return;
+
+    avcodec_close(avctx);
+
+    av_freep(&avctx->extradata);
+    av_freep(&avctx->subtitle_header);
+
+    av_freep(pavctx);
+}
+
 int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src)
 {
+    const AVCodec *orig_codec = dest->codec;
+    uint8_t *orig_priv_data = dest->priv_data;
+
     if (avcodec_is_open(dest)) { // check that the dest context is uninitialized
         av_log(dest, AV_LOG_ERROR,
                "Tried to copy AVCodecContext %p into already-initialized %p\n",
@@ -145,25 +166,30 @@ int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src)
     }
     memcpy(dest, src, sizeof(*dest));
 
+    dest->priv_data       = orig_priv_data;
+    dest->codec           = orig_codec;
+
     /* set values specific to opened codecs back to their default state */
-    dest->priv_data       = NULL;
-    dest->codec           = NULL;
     dest->slice_offset    = NULL;
     dest->hwaccel         = NULL;
-    dest->thread_opaque   = NULL;
     dest->internal        = NULL;
 
     /* reallocate values that should be allocated separately */
-    dest->rc_eq           = NULL;
     dest->extradata       = NULL;
     dest->intra_matrix    = NULL;
     dest->inter_matrix    = NULL;
     dest->rc_override     = NULL;
+    dest->subtitle_header = NULL;
+#if FF_API_MPV_OPT
+    FF_DISABLE_DEPRECATION_WARNINGS
+    dest->rc_eq           = NULL;
     if (src->rc_eq) {
         dest->rc_eq = av_strdup(src->rc_eq);
         if (!dest->rc_eq)
             return AVERROR(ENOMEM);
     }
+    FF_ENABLE_DEPRECATION_WARNINGS
+#endif
 
 #define alloc_and_copy_or_fail(obj, size, pad) \
     if (src->obj && size > 0) { \
@@ -179,6 +205,8 @@ int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src)
     alloc_and_copy_or_fail(intra_matrix, 64 * sizeof(int16_t), 0);
     alloc_and_copy_or_fail(inter_matrix, 64 * sizeof(int16_t), 0);
     alloc_and_copy_or_fail(rc_override,  src->rc_override_count * sizeof(*src->rc_override), 0);
+    alloc_and_copy_or_fail(subtitle_header, src->subtitle_header_size, 0);
+    dest->subtitle_header_size = src->subtitle_header_size;
 #undef alloc_and_copy_or_fail
 
     return 0;
@@ -188,7 +216,11 @@ fail:
     av_freep(&dest->intra_matrix);
     av_freep(&dest->inter_matrix);
     av_freep(&dest->extradata);
+#if FF_API_MPV_OPT
+    FF_DISABLE_DEPRECATION_WARNINGS
     av_freep(&dest->rc_eq);
+    FF_ENABLE_DEPRECATION_WARNINGS
+#endif
     return AVERROR(ENOMEM);
 }