Convert native handles to buffers before encoding.

Required to permit conversion of NV12 handles on iOS to I420 for VP8
software encoding, which blocks texture-based capture. This change
enforces that all texture-based input provides a method for converting
native handles to I420 if they are ever used with software encoders that
do not understand the native handles.

BUG=4081
R=emircan@chromium.org, glaznev@webrtc.org, hbos@webrtc.org, magjed@webrtc.org, mflodman@webrtc.org, stefan@webrtc.org, tkchin@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/50909005

Cr-Commit-Position: refs/heads/master@{#9347}
This commit is contained in:
Peter Boström
2015-06-01 20:06:42 +02:00
parent 9ba52f89ac
commit a831dc3a7d
19 changed files with 211 additions and 143 deletions

View File

@@ -654,9 +654,9 @@ bool MediaCodecVideoDecoder::DeliverPendingOutputs(
int32_t callback_status = WEBRTC_VIDEO_CODEC_OK;
if (use_surface_) {
native_handle_.SetTextureObject(surface_texture_, texture_id);
VideoFrame texture_image(&native_handle_, width, height, output_timestamp_,
0, webrtc::kVideoRotation_0,
rtc::Callback0<void>());
VideoFrame texture_image(new rtc::RefCountedObject<JniNativeHandleBuffer>(
&native_handle_, width, height),
output_timestamp_, 0, webrtc::kVideoRotation_0);
texture_image.set_ntp_time_ms(output_ntp_time_ms_);
callback_status = callback_->Decoded(texture_image);
} else {

View File

@@ -29,6 +29,9 @@
#ifndef TALK_APP_WEBRTC_JAVA_JNI_NATIVE_HANDLE_IMPL_H_
#define TALK_APP_WEBRTC_JAVA_JNI_NATIVE_HANDLE_IMPL_H_
#include "webrtc/base/checks.h"
#include "webrtc/common_video/interface/video_frame_buffer.h"
namespace webrtc_jni {
// Wrapper for texture object.
@@ -52,6 +55,23 @@ class NativeHandleImpl {
int32_t texture_id_;
};
class JniNativeHandleBuffer : public webrtc::NativeHandleBuffer {
public:
JniNativeHandleBuffer(void* native_handle, int width, int height)
: NativeHandleBuffer(native_handle, width, height) {}
// TODO(pbos): Override destructor to release native handle, at the moment the
// native handle is not released based on refcount.
private:
rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() override {
// TODO(pbos): Implement before using this in the encoder pipeline (or
// remove the CHECK() in VideoCapture).
RTC_NOTREACHED();
return nullptr;
}
};
} // namespace webrtc_jni
#endif // TALK_APP_WEBRTC_JAVA_JNI_NATIVE_HANDLE_IMPL_H_

View File

@@ -29,6 +29,7 @@
#include "talk/media/base/videoframe_unittest.h"
#include "talk/media/webrtc/webrtcvideoframe.h"
#include "webrtc/test/fake_texture_frame.h"
namespace {
@@ -297,10 +298,11 @@ TEST_F(WebRtcVideoFrameTest, InitRotated90DontApplyRotation) {
}
TEST_F(WebRtcVideoFrameTest, TextureInitialValues) {
void* dummy_handle = reinterpret_cast<void*>(0x1);
webrtc::TextureBuffer* buffer =
new rtc::RefCountedObject<webrtc::TextureBuffer>(dummy_handle, 640, 480,
rtc::Callback0<void>());
webrtc::test::FakeNativeHandle* dummy_handle =
new webrtc::test::FakeNativeHandle();
webrtc::NativeHandleBuffer* buffer =
new rtc::RefCountedObject<webrtc::test::FakeNativeHandleBuffer>(
dummy_handle, 640, 480);
cricket::WebRtcVideoFrame frame(buffer, 100, 200, webrtc::kVideoRotation_0);
EXPECT_EQ(dummy_handle, frame.GetNativeHandle());
EXPECT_EQ(640u, frame.GetWidth());
@@ -314,10 +316,11 @@ TEST_F(WebRtcVideoFrameTest, TextureInitialValues) {
}
TEST_F(WebRtcVideoFrameTest, CopyTextureFrame) {
void* dummy_handle = reinterpret_cast<void*>(0x1);
webrtc::TextureBuffer* buffer =
new rtc::RefCountedObject<webrtc::TextureBuffer>(dummy_handle, 640, 480,
rtc::Callback0<void>());
webrtc::test::FakeNativeHandle* dummy_handle =
new webrtc::test::FakeNativeHandle();
webrtc::NativeHandleBuffer* buffer =
new rtc::RefCountedObject<webrtc::test::FakeNativeHandleBuffer>(
dummy_handle, 640, 480);
cricket::WebRtcVideoFrame frame1(buffer, 100, 200, webrtc::kVideoRotation_0);
cricket::VideoFrame* frame2 = frame1.Copy();
EXPECT_EQ(frame1.GetNativeHandle(), frame2->GetNativeHandle());