]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/options.c
lavc: mark the old audio/video encoding API as deprecated
[ffmpeg] / libavcodec / options.c
index 8b1f6a3bc855ba50d750a958f1c6bad4a9218f9a..49c8aea030436e7f213b9c0ab41417c0141605ca 100644 (file)
 #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 */
 #include <string.h>
 
+FF_DISABLE_DEPRECATION_WARNINGS
 #include "options_table.h"
+FF_ENABLE_DEPRECATION_WARNINGS
 
 static const char* context_to_name(void* ptr) {
     AVCodecContext *avc= ptr;
@@ -70,14 +73,15 @@ 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,
     .child_class_next        = codec_child_class_next,
 };
 
-int avcodec_get_context_defaults3(AVCodecContext *s, AVCodec *codec){
+int avcodec_get_context_defaults3(AVCodecContext *s, const AVCodec *codec)
+{
     memset(s, 0, sizeof(AVCodecContext));
 
     s->av_class = &av_codec_context_class;
@@ -87,16 +91,15 @@ int avcodec_get_context_defaults3(AVCodecContext *s, AVCodec *codec){
     av_opt_set_defaults(s);
 
     s->time_base           = (AVRational){0,1};
-    s->get_buffer          = avcodec_default_get_buffer;
-    s->release_buffer      = avcodec_default_release_buffer;
+    s->framerate           = (AVRational){ 0, 1 };
+    s->get_buffer2         = avcodec_default_get_buffer2;
     s->get_format          = avcodec_default_get_format;
     s->execute             = avcodec_default_execute;
     s->execute2            = avcodec_default_execute2;
     s->sample_aspect_ratio = (AVRational){0,1};
-    s->pix_fmt             = PIX_FMT_NONE;
+    s->pix_fmt             = AV_PIX_FMT_NONE;
     s->sample_fmt          = AV_SAMPLE_FMT_NONE;
 
-    s->reget_buffer        = avcodec_default_reget_buffer;
     s->reordered_opaque    = AV_NOPTS_VALUE;
     if(codec && codec->priv_data_size){
         if(!s->priv_data){
@@ -122,10 +125,12 @@ int avcodec_get_context_defaults3(AVCodecContext *s, AVCodec *codec){
     return 0;
 }
 
-AVCodecContext *avcodec_alloc_context3(AVCodec *codec){
+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 +140,26 @@ AVCodecContext *avcodec_alloc_context3(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 +168,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) { \
@@ -175,10 +203,12 @@ int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src)
             memset(((uint8_t *) dest->obj) + size, 0, pad); \
     }
     alloc_and_copy_or_fail(extradata,    src->extradata_size,
-                           FF_INPUT_BUFFER_PADDING_SIZE);
+                           AV_INPUT_BUFFER_PADDING_SIZE);
     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 +218,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);
 }