Add support for scaling textures in AndroidVideoCapturer.
The idea is to also reuse AndroidTextureBuffer::CropAndScale when scaling in the encoder. BUG=webrtc:4993 R=magjed@webrtc.org Review URL: https://codereview.webrtc.org/1471333003 . Cr-Commit-Position: refs/heads/master@{#10802}
This commit is contained in:
@ -300,6 +300,8 @@ public class VideoCapturerAndroid extends VideoCapturer implements
|
||||
|
||||
// Requests a new output format from the video capturer. Captured frames
|
||||
// by the camera will be scaled/or dropped by the video capturer.
|
||||
// It does not matter if width and height are flipped. I.E, |width| = 640, |height| = 480 produce
|
||||
// the same result as |width| = 480, |height| = 640.
|
||||
// TODO(magjed/perkj): Document what this function does. Change name?
|
||||
public void onOutputFormatRequest(final int width, final int height, final int framerate) {
|
||||
cameraThreadHandler.post(new Runnable() {
|
||||
|
||||
@ -28,9 +28,17 @@
|
||||
#include "talk/app/webrtc/java/jni/native_handle_impl.h"
|
||||
|
||||
#include "webrtc/base/checks.h"
|
||||
#include "webrtc/base/bind.h"
|
||||
|
||||
using rtc::scoped_refptr;
|
||||
using webrtc::NativeHandleBuffer;
|
||||
|
||||
namespace webrtc_jni {
|
||||
|
||||
namespace {
|
||||
void ScaledFrameNotInUse(scoped_refptr<NativeHandleBuffer> original) {}
|
||||
} // anonymous namespace
|
||||
|
||||
NativeHandleImpl::NativeHandleImpl(JNIEnv* jni,
|
||||
jint j_oes_texture_id,
|
||||
jfloatArray j_transform_matrix)
|
||||
@ -64,4 +72,22 @@ AndroidTextureBuffer::NativeToI420Buffer() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
rtc::scoped_refptr<AndroidTextureBuffer> AndroidTextureBuffer::CropAndScale(
|
||||
int cropped_input_width,
|
||||
int cropped_input_height,
|
||||
int dst_widht,
|
||||
int dst_height) {
|
||||
// TODO(perkj) Implement cropping.
|
||||
RTC_CHECK_EQ(cropped_input_width, width_);
|
||||
RTC_CHECK_EQ(cropped_input_height, height_);
|
||||
|
||||
// Here we use Bind magic to add a reference count to |this| until the newly
|
||||
// created AndroidTextureBuffer is destructed. ScaledFrameNotInUse will be
|
||||
// called that happens and when it finishes, the reference count to |this|
|
||||
// will be decreased by one.
|
||||
return new rtc::RefCountedObject<AndroidTextureBuffer>(
|
||||
dst_widht, dst_height, native_handle_,
|
||||
rtc::Bind(&ScaledFrameNotInUse, this));
|
||||
}
|
||||
|
||||
} // namespace webrtc_jni
|
||||
|
||||
@ -54,6 +54,12 @@ class AndroidTextureBuffer : public webrtc::NativeHandleBuffer {
|
||||
~AndroidTextureBuffer();
|
||||
rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() override;
|
||||
|
||||
rtc::scoped_refptr<AndroidTextureBuffer> CropAndScale(
|
||||
int cropped_input_width,
|
||||
int cropped_input_height,
|
||||
int dst_widht,
|
||||
int dst_height);
|
||||
|
||||
private:
|
||||
NativeHandleImpl native_handle_;
|
||||
rtc::Callback0<void> no_longer_used_cb_;
|
||||
|
||||
Reference in New Issue
Block a user