From 3e5d652eba1fb004ce78466b63b84b40732e3d5f Mon Sep 17 00:00:00 2001
From: philippegorley <philippe.gorley@savoirfairelinux.com>
Date: Mon, 17 Jul 2017 17:57:33 -0400
Subject: [PATCH] android: improve vp8 video streaming

During a VP8 video call on the android client, the peer video freezes.
Optimizes android video buffers using an array instead of a vector. Lets
VP8 decide when to send a keyframe.

Change-Id: I19893c2ac080782daee72958fb6c174eea42037a
Reviewed-by: Guillaume Roguez <guillaume.roguez@savoirfairelinux.com>
---
 src/media/media_encoder.cpp     | 3 +--
 src/media/video/video_input.cpp | 2 +-
 src/media/video/video_input.h   | 3 ++-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/media/media_encoder.cpp b/src/media/media_encoder.cpp
index 3c8e39b532..9d2505a8c0 100644
--- a/src/media/media_encoder.cpp
+++ b/src/media/media_encoder.cpp
@@ -181,11 +181,10 @@ MediaEncoder::openOutput(const char *filename,
         av_opt_set_int(encoderCtx_->priv_data, "error-resilient", 1, 0);
         av_opt_set_int(encoderCtx_->priv_data, "cpu-used", 3, 0);
         av_opt_set_int(encoderCtx_->priv_data, "lag-in-frames", 0, 0);
+        // don't set encoderCtx_->gop_size: let libvpx decide when to insert a keyframe
         encoderCtx_->slices = 2; // VP8E_SET_TOKEN_PARTITIONS
         encoderCtx_->qmin = 4;
         encoderCtx_->qmax = 56;
-        encoderCtx_->gop_size = 999999;
-
         encoderCtx_->rc_buffer_size = maxBitrate;
         encoderCtx_->bit_rate = maxBitrate;
         if (crf != SystemCodecInfo::DEFAULT_NO_QUALITY) {
diff --git a/src/media/video/video_input.cpp b/src/media/video/video_input.cpp
index 0e67ce0c7a..1c98606757 100644
--- a/src/media/video/video_input.cpp
+++ b/src/media/video/video_input.cpp
@@ -57,7 +57,7 @@ VideoInput::VideoInput()
             std::bind(&VideoInput::process, this),
             std::bind(&VideoInput::cleanup, this))
 #if defined(__ANDROID__) || defined(RING_UWP)
-    , mutex_(), frame_cv_(), buffers_(8)
+    , mutex_(), frame_cv_(), buffers_()
 #endif
 {}
 
diff --git a/src/media/video/video_input.h b/src/media/video/video_input.h
index 7ffeefbb0d..323792661a 100644
--- a/src/media/video/video_input.h
+++ b/src/media/video/video_input.h
@@ -34,6 +34,7 @@
 #include <string>
 #include <mutex>
 #include <condition_variable>
+#include <array>
 
 namespace ring {
 class MediaDecoder;
@@ -132,7 +133,7 @@ private:
 
     /* Get notified when libav is done with this buffer */
     void releaseBufferCb(uint8_t* ptr);
-    std::vector<struct VideoFrameBuffer> buffers_;
+    std::array<struct VideoFrameBuffer, 8> buffers_;
 #endif
 };
 
-- 
GitLab