passing |buffer| by reference in AndroidVideoCapturer::OnIncomingFrame

BUG=webrtc:5062

Review URL: https://codereview.webrtc.org/1414703002

Cr-Commit-Position: refs/heads/master@{#10342}
diff --git a/talk/app/webrtc/androidvideocapturer.cc b/talk/app/webrtc/androidvideocapturer.cc
index 2d5a1af..afcfb5b 100644
--- a/talk/app/webrtc/androidvideocapturer.cc
+++ b/talk/app/webrtc/androidvideocapturer.cc
@@ -211,7 +211,7 @@
 }
 
 void AndroidVideoCapturer::OnIncomingFrame(
-    rtc::scoped_refptr<webrtc::VideoFrameBuffer> buffer,
+    const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& buffer,
     int rotation,
     int64_t time_stamp) {
   RTC_CHECK(thread_checker_.CalledOnValidThread());
diff --git a/talk/app/webrtc/androidvideocapturer.h b/talk/app/webrtc/androidvideocapturer.h
index fdc8629..df783bd 100644
--- a/talk/app/webrtc/androidvideocapturer.h
+++ b/talk/app/webrtc/androidvideocapturer.h
@@ -67,9 +67,10 @@
 
   // Called from JNI when a new frame has been captured.
   // Argument |buffer| is intentionally by value, for use with rtc::Bind.
-  void OnIncomingFrame(rtc::scoped_refptr<webrtc::VideoFrameBuffer> buffer,
-                       int rotation,
-                       int64_t time_stamp);
+  void OnIncomingFrame(
+      const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& buffer,
+      int rotation,
+      int64_t time_stamp);
 
   // Called from JNI to request a new video format.
   void OnOutputFormatRequest(int width, int height, int fps);
diff --git a/talk/app/webrtc/java/jni/androidvideocapturer_jni.cc b/talk/app/webrtc/java/jni/androidvideocapturer_jni.cc
index cd6cfc0..02b9f22 100644
--- a/talk/app/webrtc/java/jni/androidvideocapturer_jni.cc
+++ b/talk/app/webrtc/java/jni/androidvideocapturer_jni.cc
@@ -118,7 +118,7 @@
 void AndroidVideoCapturerJni::AsyncCapturerInvoke(
     const char* method_name,
     void (webrtc::AndroidVideoCapturer::*method)(Args...),
-    Args... args) {
+    typename Identity<Args>::type... args) {
   rtc::CritScope cs(&capturer_lock_);
   if (!invoker_) {
     LOG(LS_WARNING) << method_name << "() called for closed capturer.";
diff --git a/talk/app/webrtc/java/jni/androidvideocapturer_jni.h b/talk/app/webrtc/java/jni/androidvideocapturer_jni.h
index 360674b..d1eb3a0 100644
--- a/talk/app/webrtc/java/jni/androidvideocapturer_jni.h
+++ b/talk/app/webrtc/java/jni/androidvideocapturer_jni.h
@@ -71,13 +71,19 @@
   void ReturnBuffer(int64_t time_stamp);
   JNIEnv* jni();
 
+  // To avoid deducing Args from the 3rd parameter of AsyncCapturerInvoke.
+  template <typename T>
+  struct Identity {
+    typedef T type;
+  };
+
   // Helper function to make safe asynchronous calls to |capturer_|. The calls
   // are not guaranteed to be delivered.
   template <typename... Args>
   void AsyncCapturerInvoke(
       const char* method_name,
       void (webrtc::AndroidVideoCapturer::*method)(Args...),
-      Args... args);
+      typename Identity<Args>::type... args);
 
   const ScopedGlobalRef<jobject> j_capturer_global_;
   const ScopedGlobalRef<jclass> j_video_capturer_class_;