---
 libavcodec/internal.h       |  5 +++++
 libavcodec/libopenh264enc.c |  9 +++++++++
 libavcodec/utils.c          | 26 ++++++++++++++++++++++++++
 3 files changed, 40 insertions(+)

diff --git a/libavcodec/internal.h b/libavcodec/internal.h
index 500511d..24d28e2 100644
--- a/libavcodec/internal.h
+++ b/libavcodec/internal.h
@@ -240,4 +240,9 @@ int ff_get_format(AVCodecContext *avctx, const enum 
AVPixelFormat *fmt);
  */
 int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame);
 
+/**
+ * Add a CPB properties side data to an encoding context.
+ */
+AVCPBProperties *ff_add_cpb_sd(AVCodecContext *avctx);
+
 #endif /* AVCODEC_INTERNAL_H */
diff --git a/libavcodec/libopenh264enc.c b/libavcodec/libopenh264enc.c
index 0f18f80..351cae2 100644
--- a/libavcodec/libopenh264enc.c
+++ b/libavcodec/libopenh264enc.c
@@ -100,6 +100,7 @@ static av_cold int svc_encode_init(AVCodecContext *avctx)
     int err = AVERROR_UNKNOWN;
     int log_level;
     WelsTraceCallback callback_function;
+    AVCPBProperties *props;
 
     // Mingw GCC < 4.7 on x86_32 uses an incorrect/buggy ABI for the 
WelsGetCodecVersion
     // function (for functions returning larger structs), thus skip the check 
in those
@@ -190,6 +191,14 @@ static av_cold int svc_encode_init(AVCodecContext *avctx)
         memcpy(avctx->extradata, fbi.sLayerInfo[0].pBsBuf, size);
     }
 
+    props = ff_add_cpb_sd(avctx);
+    if (!props) {
+        err = AVERROR(ENOMEM);
+        goto fail;
+    }
+    props->max_bitrate = param.iMaxBitrate;
+    props->avg_bitrate = param.iTargetBitrate;
+
     return 0;
 
 fail:
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 6db0a5c..779bee0 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -2378,3 +2378,29 @@ AVCPBProperties *av_cpb_properties_alloc(size_t *size)
 
     return props;
 }
+
+AVCPBProperties *ff_add_cpb_sd(AVCodecContext *avctx)
+{
+    AVPacketSideData *tmp;
+    AVCPBProperties  *props;
+    size_t size;
+
+    props = av_cpb_properties_alloc(&size);
+    if (!props)
+        return NULL;
+
+    tmp = av_realloc_array(avctx->coded_side_data, avctx->nb_coded_side_data + 
1, sizeof(*tmp));
+    if (!tmp) {
+        av_freep(&props);
+        return NULL;
+    }
+
+    avctx->coded_side_data = tmp;
+    avctx->nb_coded_side_data++;
+
+    avctx->coded_side_data[avctx->nb_coded_side_data - 1].type = 
AV_PKT_DATA_CPB_PROPERTIES;
+    avctx->coded_side_data[avctx->nb_coded_side_data - 1].data = 
(uint8_t*)props;
+    avctx->coded_side_data[avctx->nb_coded_side_data - 1].size = size;
+
+    return props;
+}
-- 
2.0.0

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

Reply via email to