<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">From de2fda7fcdb2c4314d4cfff9b4b5052125131276 Mon Sep 17 00:00:00 2001
From: Robert Swain &lt;rob@opendot.cl&gt;
Date: Thu, 5 Jun 2008 12:58:08 +0100
Subject: [PATCH] - Add AVCodec argument to avcodec_get_context_defaults2
 - Add defaults function pointer to AVCodec
 - If available, call per codec defaults function at the end of
   avcodec_get_context_defaults2

---
 ffmpeg.c             |    6 +++---
 libavcodec/avcodec.h |    3 ++-
 libavcodec/utils.c   |    9 ++++++---
 3 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/ffmpeg.c b/ffmpeg.c
index 639973c..27430aa 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -2914,7 +2914,7 @@ static void new_video_stream(AVFormatContext *oc)
         codec = avcodec_find_encoder(codec_id);
     }
 
-    avcodec_get_context_defaults2(st-&gt;codec, CODEC_TYPE_VIDEO);
+    avcodec_get_context_defaults2(st-&gt;codec, codec, CODEC_TYPE_VIDEO);
     bitstream_filters[nb_output_files][oc-&gt;nb_streams - 1]= video_bitstream_filters;
     video_bitstream_filters= NULL;
 
@@ -3072,7 +3072,7 @@ static void new_audio_stream(AVFormatContext *oc)
         codec = avcodec_find_encoder(codec_id);
     }
 
-    avcodec_get_context_defaults2(st-&gt;codec, CODEC_TYPE_AUDIO);
+    avcodec_get_context_defaults2(st-&gt;codec, codec, CODEC_TYPE_AUDIO);
 
     bitstream_filters[nb_output_files][oc-&gt;nb_streams - 1]= audio_bitstream_filters;
     audio_bitstream_filters= NULL;
@@ -3144,7 +3144,7 @@ static void new_subtitle_stream(AVFormatContext *oc)
         codec = avcodec_find_encoder(codec_id);
     }
 
-    avcodec_get_context_defaults2(st-&gt;codec, CODEC_TYPE_SUBTITLE);
+    avcodec_get_context_defaults2(st-&gt;codec, codec, CODEC_TYPE_SUBTITLE);
 
     bitstream_filters[nb_output_files][oc-&gt;nb_streams - 1]= subtitle_bitstream_filters;
     subtitle_bitstream_filters= NULL;
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 3772850..e8e5175 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -2244,6 +2244,7 @@ typedef struct AVCodec {
     const enum PixelFormat *pix_fmts;       ///&lt; array of supported pixel formats, or NULL if unknown, array is terminated by -1
     const char *long_name;                  ///&lt; descriptive name for the codec, meant to be more human readable than \p name
     const int *supported_samplerates;       ///&lt; array of supported audio samplerates, or NULL if unknown, array is terminated by 0
+    void (*defaults)(AVCodecContext *);     ///&lt; optionally assign default values for the codec in question
 } AVCodec;
 
 /**
@@ -2562,7 +2563,7 @@ void avcodec_get_context_defaults(AVCodecContext *s);
 
 /** THIS FUNCTION IS NOT YET PART OF THE PUBLIC API!
  *  we WILL change its arguments and name a few times! */
-void avcodec_get_context_defaults2(AVCodecContext *s, enum CodecType);
+void avcodec_get_context_defaults2(AVCodecContext *s, AVCodec *codec, enum CodecType);
 
 /**
  * Allocates an AVCodecContext and sets its fields to default values.  The
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 1a2dca3..e261bd2 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -723,7 +723,7 @@ static const AVOption options[]={
 
 static const AVClass av_codec_context_class = { "AVCodecContext", context_to_name, options };
 
-void avcodec_get_context_defaults2(AVCodecContext *s, enum CodecType codec_type){
+void avcodec_get_context_defaults2(AVCodecContext *s, AVCodec *codec, enum CodecType codec_type){
     int flags=0;
     memset(s, 0, sizeof(AVCodecContext));
 
@@ -750,6 +750,9 @@ void avcodec_get_context_defaults2(AVCodecContext *s, enum CodecType codec_type)
 
     s-&gt;palctrl = NULL;
     s-&gt;reget_buffer= avcodec_default_reget_buffer;
+
+    if(codec &amp;&amp; codec-&gt;defaults)
+        codec-&gt;defaults(s);
 }
 
 AVCodecContext *avcodec_alloc_context2(enum CodecType codec_type){
@@ -757,13 +760,13 @@ AVCodecContext *avcodec_alloc_context2(enum CodecType codec_type){
 
     if(avctx==NULL) return NULL;
 
-    avcodec_get_context_defaults2(avctx, codec_type);
+    avcodec_get_context_defaults2(avctx, 0, codec_type);
 
     return avctx;
 }
 
 void avcodec_get_context_defaults(AVCodecContext *s){
-    avcodec_get_context_defaults2(s, CODEC_TYPE_UNKNOWN);
+    avcodec_get_context_defaults2(s, 0, CODEC_TYPE_UNKNOWN);
 }
 
 AVCodecContext *avcodec_alloc_context(void){
-- 
1.5.5.1

</pre></body></html>