shithub: libvpx

Download patch

ref: d579a85949864faf4063186aa5b75448c96e86ca
parent: 76d9afc349fec0d1edc4d674daaca89b6c8c9c90
parent: 027ead10dc37c0471ebe17962f83077039b07977
author: Angie Chiang <angiebird@google.com>
date: Mon Nov 18 14:33:55 EST 2019

Merge changes Id42dbddd,I6dff1bda

* changes:
  Add const to oxcf of vp9_create_compressor
  Add simple_encode.cc/h

--- a/vp9/encoder/vp9_encoder.c
+++ b/vp9/encoder/vp9_encoder.c
@@ -1468,7 +1468,7 @@
   }
 }
 
-static void init_config(struct VP9_COMP *cpi, VP9EncoderConfig *oxcf) {
+static void init_config(struct VP9_COMP *cpi, const VP9EncoderConfig *oxcf) {
   VP9_COMMON *const cm = &cpi->common;
 
   cpi->oxcf = *oxcf;
@@ -2264,7 +2264,7 @@
   alloc_raw_frame_buffers(cpi);
 }
 
-VP9_COMP *vp9_create_compressor(VP9EncoderConfig *oxcf,
+VP9_COMP *vp9_create_compressor(const VP9EncoderConfig *oxcf,
                                 BufferPool *const pool) {
   unsigned int i;
   VP9_COMP *volatile const cpi = vpx_memalign(32, sizeof(VP9_COMP));
--- a/vp9/encoder/vp9_encoder.h
+++ b/vp9/encoder/vp9_encoder.h
@@ -825,7 +825,7 @@
 void vp9_initialize_enc(void);
 
 void vp9_update_compressor_with_img_fmt(VP9_COMP *cpi, vpx_img_fmt_t img_fmt);
-struct VP9_COMP *vp9_create_compressor(VP9EncoderConfig *oxcf,
+struct VP9_COMP *vp9_create_compressor(const VP9EncoderConfig *oxcf,
                                        BufferPool *const pool);
 void vp9_remove_compressor(VP9_COMP *cpi);
 
--- /dev/null
+++ b/vp9/simple_encode.cc
@@ -1,0 +1,27 @@
+#include "vp9/common/vp9_onyxc_int.h"
+#include "vp9/encoder/vp9_encoder.h"
+#include "vp9/simple_encode.h"
+#include "vp9/vp9_cx_iface.h"
+
+class SimpleEncode::impl {
+ public:
+  VP9_COMP *cpi;
+  BufferPool *buffer_pool;
+};
+
+SimpleEncode::SimpleEncode(int frame_width, int frame_height,
+                           vpx_rational_t frame_rate, int target_bitrate)
+    : pimpl{ std::unique_ptr<impl>(new impl()) } {
+  VP9EncoderConfig oxcf = vp9_get_encoder_config(
+      frame_width, frame_height, frame_rate, target_bitrate, VPX_RC_LAST_PASS);
+  pimpl->buffer_pool = (BufferPool *)vpx_calloc(1, sizeof(*pimpl->buffer_pool));
+  vp9_initialize_enc();
+  pimpl->cpi = vp9_create_compressor(&oxcf, pimpl->buffer_pool);
+  vp9_update_compressor_with_img_fmt(pimpl->cpi, VPX_IMG_FMT_I420);
+}
+
+SimpleEncode::~SimpleEncode() {
+  vpx_free(pimpl->buffer_pool);
+  vp9_remove_compressor(pimpl->cpi);
+  pimpl->cpi = nullptr;
+}
--- /dev/null
+++ b/vp9/simple_encode.h
@@ -1,0 +1,13 @@
+#include <memory>
+class SimpleEncode {
+ public:
+  SimpleEncode(int frame_width, int frame_height, vpx_rational_t frame_rate,
+               int target_bitrate);
+  ~SimpleEncode();
+  SimpleEncode(SimpleEncode &&) = delete;
+  SimpleEncode &operator=(SimpleEncode &&) = delete;
+
+ private:
+  class impl;
+  std::unique_ptr<impl> pimpl;
+};
--- a/vp9/vp9cx.mk
+++ b/vp9/vp9cx.mk
@@ -18,6 +18,9 @@
 VP9_CX_SRCS-yes += vp9_cx_iface.c
 VP9_CX_SRCS-yes += vp9_cx_iface.h
 
+VP9_CX_SRCS-$(CONFIG_RATE_CTRL) += simple_encode.cc
+VP9_CX_SRCS-$(CONFIG_RATE_CTRL) += simple_encode.h
+
 VP9_CX_SRCS-yes += encoder/vp9_bitstream.c
 VP9_CX_SRCS-yes += encoder/vp9_context_tree.c
 VP9_CX_SRCS-yes += encoder/vp9_context_tree.h