shithub: libvpx

Download patch

ref: 04f50db953df5b8f48d1b928c93d2492b46e8b95
parent: b0e761f95b71450a8808497d840f59c00d97fe8b
author: angiebird <angiebird@google.com>
date: Fri Nov 8 15:31:10 EST 2019

Add simple_encode.cc/h

Change-Id: I6dff1bda4bea760a32c2f8e38773e5913c830204

--- /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