Remove usage of webrtc::NativeHandle since is just adds an extra level of indirection.
BUG=1128 R=magjed@webrtc.org, pbos@webrtc.org TBR=mflodman@webrtc.org Review URL: https://webrtc-codereview.appspot.com/43999004 Cr-Commit-Position: refs/heads/master@{#8932}
This commit is contained in:
parent
e1c1ee211e
commit
75db861258
@ -654,8 +654,9 @@ bool MediaCodecVideoDecoder::DeliverPendingOutputs(
|
|||||||
int32_t callback_status = WEBRTC_VIDEO_CODEC_OK;
|
int32_t callback_status = WEBRTC_VIDEO_CODEC_OK;
|
||||||
if (use_surface_) {
|
if (use_surface_) {
|
||||||
native_handle_.SetTextureObject(surface_texture_, texture_id);
|
native_handle_.SetTextureObject(surface_texture_, texture_id);
|
||||||
I420VideoFrame texture_image(
|
I420VideoFrame texture_image(&native_handle_, width, height,
|
||||||
&native_handle_, width, height, output_timestamp_, 0);
|
output_timestamp_, 0, webrtc::kVideoRotation_0,
|
||||||
|
rtc::Callback0<void>());
|
||||||
texture_image.set_ntp_time_ms(output_ntp_time_ms_);
|
texture_image.set_ntp_time_ms(output_ntp_time_ms_);
|
||||||
callback_status = callback_->Decoded(texture_image);
|
callback_status = callback_->Decoded(texture_image);
|
||||||
} else {
|
} else {
|
||||||
|
@ -33,19 +33,12 @@
|
|||||||
|
|
||||||
namespace webrtc_jni {
|
namespace webrtc_jni {
|
||||||
|
|
||||||
// Wrapper for texture object in TextureBuffer.
|
// Wrapper for texture object.
|
||||||
class NativeHandleImpl : public webrtc::NativeHandle {
|
class NativeHandleImpl {
|
||||||
public:
|
public:
|
||||||
NativeHandleImpl() :
|
NativeHandleImpl() : texture_object_(NULL), texture_id_(-1) {}
|
||||||
ref_count_(0), texture_object_(NULL), texture_id_(-1) {}
|
|
||||||
virtual ~NativeHandleImpl() {}
|
void* GetHandle() {
|
||||||
virtual int32_t AddRef() {
|
|
||||||
return ++ref_count_;
|
|
||||||
}
|
|
||||||
virtual int32_t Release() {
|
|
||||||
return --ref_count_;
|
|
||||||
}
|
|
||||||
virtual void* GetHandle() {
|
|
||||||
return texture_object_;
|
return texture_object_;
|
||||||
}
|
}
|
||||||
int GetTextureId() {
|
int GetTextureId() {
|
||||||
@ -55,12 +48,8 @@ class NativeHandleImpl : public webrtc::NativeHandle {
|
|||||||
texture_object_ = reinterpret_cast<jobject>(texture_object);
|
texture_object_ = reinterpret_cast<jobject>(texture_object);
|
||||||
texture_id_ = texture_id;
|
texture_id_ = texture_id;
|
||||||
}
|
}
|
||||||
int32_t ref_count() {
|
|
||||||
return ref_count_;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int32_t ref_count_;
|
|
||||||
jobject texture_object_;
|
jobject texture_object_;
|
||||||
int32_t texture_id_;
|
int32_t texture_id_;
|
||||||
};
|
};
|
||||||
|
@ -71,23 +71,6 @@ WebRtcVideoFrame::WebRtcVideoFrame(
|
|||||||
rotation_(webrtc::kVideoRotation_0) {
|
rotation_(webrtc::kVideoRotation_0) {
|
||||||
}
|
}
|
||||||
|
|
||||||
WebRtcVideoFrame::WebRtcVideoFrame(webrtc::NativeHandle* handle,
|
|
||||||
int width,
|
|
||||||
int height,
|
|
||||||
int64_t elapsed_time_ns,
|
|
||||||
int64_t time_stamp_ns,
|
|
||||||
webrtc::VideoRotation rotation)
|
|
||||||
: video_frame_buffer_(
|
|
||||||
new rtc::RefCountedObject<webrtc::TextureBuffer>(handle,
|
|
||||||
width,
|
|
||||||
height)),
|
|
||||||
pixel_width_(1),
|
|
||||||
pixel_height_(1),
|
|
||||||
elapsed_time_ns_(elapsed_time_ns),
|
|
||||||
time_stamp_ns_(time_stamp_ns),
|
|
||||||
rotation_(rotation) {
|
|
||||||
}
|
|
||||||
|
|
||||||
WebRtcVideoFrame::~WebRtcVideoFrame() {}
|
WebRtcVideoFrame::~WebRtcVideoFrame() {}
|
||||||
|
|
||||||
bool WebRtcVideoFrame::Init(uint32 format,
|
bool WebRtcVideoFrame::Init(uint32 format,
|
||||||
|
@ -52,12 +52,6 @@ class WebRtcVideoFrame : public VideoFrame {
|
|||||||
int64_t elapsed_time_ns,
|
int64_t elapsed_time_ns,
|
||||||
int64_t time_stamp_ns);
|
int64_t time_stamp_ns);
|
||||||
|
|
||||||
WebRtcVideoFrame(webrtc::NativeHandle* handle,
|
|
||||||
int width,
|
|
||||||
int height,
|
|
||||||
int64_t elapsed_time_ns,
|
|
||||||
int64_t time_stamp_ns,
|
|
||||||
webrtc::VideoRotation rotation);
|
|
||||||
~WebRtcVideoFrame();
|
~WebRtcVideoFrame();
|
||||||
|
|
||||||
// Creates a frame from a raw sample with FourCC "format" and size "w" x "h".
|
// Creates a frame from a raw sample with FourCC "format" and size "w" x "h".
|
||||||
|
@ -30,19 +30,6 @@
|
|||||||
#include "talk/media/base/videoframe_unittest.h"
|
#include "talk/media/base/videoframe_unittest.h"
|
||||||
#include "talk/media/webrtc/webrtcvideoframe.h"
|
#include "talk/media/webrtc/webrtcvideoframe.h"
|
||||||
|
|
||||||
class NativeHandleImpl : public webrtc::NativeHandle {
|
|
||||||
public:
|
|
||||||
NativeHandleImpl() : ref_count_(0) {}
|
|
||||||
virtual ~NativeHandleImpl() {}
|
|
||||||
virtual int32_t AddRef() { return ++ref_count_; }
|
|
||||||
virtual int32_t Release() { return --ref_count_; }
|
|
||||||
virtual void* GetHandle() { return NULL; }
|
|
||||||
|
|
||||||
int32_t ref_count() { return ref_count_; }
|
|
||||||
private:
|
|
||||||
int32_t ref_count_;
|
|
||||||
};
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
class WebRtcVideoTestFrame : public cricket::WebRtcVideoFrame {
|
class WebRtcVideoTestFrame : public cricket::WebRtcVideoFrame {
|
||||||
@ -339,10 +326,12 @@ TEST_F(WebRtcVideoFrameTest, InitRotated90DontApplyRotation) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(WebRtcVideoFrameTest, TextureInitialValues) {
|
TEST_F(WebRtcVideoFrameTest, TextureInitialValues) {
|
||||||
NativeHandleImpl handle;
|
void* dummy_handle = reinterpret_cast<void*>(0x1);
|
||||||
cricket::WebRtcVideoFrame frame(&handle, 640, 480, 100, 200,
|
webrtc::TextureBuffer* buffer =
|
||||||
webrtc::kVideoRotation_0);
|
new rtc::RefCountedObject<webrtc::TextureBuffer>(dummy_handle, 640, 480,
|
||||||
EXPECT_EQ(&handle, frame.GetNativeHandle());
|
rtc::Callback0<void>());
|
||||||
|
cricket::WebRtcVideoFrame frame(buffer, 100, 200, webrtc::kVideoRotation_0);
|
||||||
|
EXPECT_EQ(dummy_handle, frame.GetNativeHandle());
|
||||||
EXPECT_EQ(640u, frame.GetWidth());
|
EXPECT_EQ(640u, frame.GetWidth());
|
||||||
EXPECT_EQ(480u, frame.GetHeight());
|
EXPECT_EQ(480u, frame.GetHeight());
|
||||||
EXPECT_EQ(100, frame.GetElapsedTime());
|
EXPECT_EQ(100, frame.GetElapsedTime());
|
||||||
@ -354,9 +343,11 @@ TEST_F(WebRtcVideoFrameTest, TextureInitialValues) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(WebRtcVideoFrameTest, CopyTextureFrame) {
|
TEST_F(WebRtcVideoFrameTest, CopyTextureFrame) {
|
||||||
NativeHandleImpl handle;
|
void* dummy_handle = reinterpret_cast<void*>(0x1);
|
||||||
cricket::WebRtcVideoFrame frame1(&handle, 640, 480, 100, 200,
|
webrtc::TextureBuffer* buffer =
|
||||||
webrtc::kVideoRotation_0);
|
new rtc::RefCountedObject<webrtc::TextureBuffer>(dummy_handle, 640, 480,
|
||||||
|
rtc::Callback0<void>());
|
||||||
|
cricket::WebRtcVideoFrame frame1(buffer, 100, 200, webrtc::kVideoRotation_0);
|
||||||
cricket::VideoFrame* frame2 = frame1.Copy();
|
cricket::VideoFrame* frame2 = frame1.Copy();
|
||||||
EXPECT_EQ(frame1.GetNativeHandle(), frame2->GetNativeHandle());
|
EXPECT_EQ(frame1.GetNativeHandle(), frame2->GetNativeHandle());
|
||||||
EXPECT_EQ(frame1.GetWidth(), frame2->GetWidth());
|
EXPECT_EQ(frame1.GetWidth(), frame2->GetWidth());
|
||||||
|
@ -38,9 +38,7 @@ class PooledI420Buffer : public webrtc::VideoFrameBuffer {
|
|||||||
int stride(webrtc::PlaneType type) const override {
|
int stride(webrtc::PlaneType type) const override {
|
||||||
return buffer_->stride(type);
|
return buffer_->stride(type);
|
||||||
}
|
}
|
||||||
rtc::scoped_refptr<webrtc::NativeHandle> native_handle() const override {
|
void* native_handle() const override { return nullptr; }
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
friend class rtc::RefCountedObject<PooledI420Buffer>;
|
friend class rtc::RefCountedObject<PooledI420Buffer>;
|
||||||
rtc::scoped_refptr<webrtc::I420Buffer> buffer_;
|
rtc::scoped_refptr<webrtc::I420Buffer> buffer_;
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
#include <algorithm> // swap
|
#include <algorithm> // swap
|
||||||
|
|
||||||
|
#include "webrtc/base/bind.h"
|
||||||
#include "webrtc/base/checks.h"
|
#include "webrtc/base/checks.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
@ -52,6 +53,22 @@ I420VideoFrame::I420VideoFrame(NativeHandle* handle,
|
|||||||
DCHECK_GT(height, 0);
|
DCHECK_GT(height, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
I420VideoFrame::I420VideoFrame(void* native_handle,
|
||||||
|
int width,
|
||||||
|
int height,
|
||||||
|
uint32_t timestamp,
|
||||||
|
int64_t render_time_ms,
|
||||||
|
VideoRotation rotation,
|
||||||
|
const rtc::Callback0<void>& no_longer_used)
|
||||||
|
: I420VideoFrame(new rtc::RefCountedObject<TextureBuffer>(native_handle,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
no_longer_used),
|
||||||
|
timestamp,
|
||||||
|
render_time_ms,
|
||||||
|
rotation) {
|
||||||
|
}
|
||||||
|
|
||||||
int I420VideoFrame::CreateEmptyFrame(int width, int height,
|
int I420VideoFrame::CreateEmptyFrame(int width, int height,
|
||||||
int stride_y, int stride_u, int stride_v) {
|
int stride_y, int stride_u, int stride_v) {
|
||||||
const int half_width = (width + 1) / 2;
|
const int half_width = (width + 1) / 2;
|
||||||
|
@ -12,22 +12,21 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "testing/gtest/include/gtest/gtest.h"
|
#include "testing/gtest/include/gtest/gtest.h"
|
||||||
|
#include "webrtc/base/bind.h"
|
||||||
#include "webrtc/base/scoped_ptr.h"
|
#include "webrtc/base/scoped_ptr.h"
|
||||||
#include "webrtc/common_video/interface/i420_video_frame.h"
|
#include "webrtc/common_video/interface/i420_video_frame.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|
||||||
class NativeHandleImpl : public NativeHandle {
|
class NativeHandleImpl {
|
||||||
public:
|
public:
|
||||||
NativeHandleImpl() : ref_count_(0) {}
|
NativeHandleImpl() : no_longer_needed_(false) {}
|
||||||
virtual ~NativeHandleImpl() {}
|
virtual ~NativeHandleImpl() {}
|
||||||
virtual int32_t AddRef() { return ++ref_count_; }
|
bool no_longer_needed() const { return no_longer_needed_; }
|
||||||
virtual int32_t Release() { return --ref_count_; }
|
void SetNoLongerNeeded() { no_longer_needed_ = true; }
|
||||||
virtual void* GetHandle() { return NULL; }
|
|
||||||
|
|
||||||
int32_t ref_count() { return ref_count_; }
|
|
||||||
private:
|
private:
|
||||||
int32_t ref_count_;
|
bool no_longer_needed_;
|
||||||
};
|
};
|
||||||
|
|
||||||
bool EqualPlane(const uint8_t* data1,
|
bool EqualPlane(const uint8_t* data1,
|
||||||
@ -256,7 +255,8 @@ TEST(TestI420VideoFrame, FailToReuseAllocation) {
|
|||||||
|
|
||||||
TEST(TestI420VideoFrame, TextureInitialValues) {
|
TEST(TestI420VideoFrame, TextureInitialValues) {
|
||||||
NativeHandleImpl handle;
|
NativeHandleImpl handle;
|
||||||
I420VideoFrame frame(&handle, 640, 480, 100, 10);
|
I420VideoFrame frame(&handle, 640, 480, 100, 10, webrtc::kVideoRotation_0,
|
||||||
|
rtc::Callback0<void>());
|
||||||
EXPECT_EQ(640, frame.width());
|
EXPECT_EQ(640, frame.width());
|
||||||
EXPECT_EQ(480, frame.height());
|
EXPECT_EQ(480, frame.height());
|
||||||
EXPECT_EQ(100u, frame.timestamp());
|
EXPECT_EQ(100u, frame.timestamp());
|
||||||
@ -269,13 +269,15 @@ TEST(TestI420VideoFrame, TextureInitialValues) {
|
|||||||
EXPECT_EQ(20, frame.render_time_ms());
|
EXPECT_EQ(20, frame.render_time_ms());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TestI420VideoFrame, RefCount) {
|
TEST(TestI420VideoFrame, NoLongerNeeded) {
|
||||||
NativeHandleImpl handle;
|
NativeHandleImpl handle;
|
||||||
EXPECT_EQ(0, handle.ref_count());
|
ASSERT_FALSE(handle.no_longer_needed());
|
||||||
I420VideoFrame *frame = new I420VideoFrame(&handle, 640, 480, 100, 200);
|
I420VideoFrame* frame = new I420VideoFrame(
|
||||||
EXPECT_EQ(1, handle.ref_count());
|
&handle, 640, 480, 100, 200, webrtc::kVideoRotation_0,
|
||||||
|
rtc::Bind(&NativeHandleImpl::SetNoLongerNeeded, &handle));
|
||||||
|
EXPECT_FALSE(handle.no_longer_needed());
|
||||||
delete frame;
|
delete frame;
|
||||||
EXPECT_EQ(0, handle.ref_count());
|
EXPECT_TRUE(handle.no_longer_needed());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EqualPlane(const uint8_t* data1,
|
bool EqualPlane(const uint8_t* data1,
|
||||||
|
@ -20,6 +20,9 @@ namespace webrtc {
|
|||||||
// TextureBuffer. This object keeps a reference to the handle. The reference
|
// TextureBuffer. This object keeps a reference to the handle. The reference
|
||||||
// is cleared when the object is destroyed. It is important to destroy the
|
// is cleared when the object is destroyed. It is important to destroy the
|
||||||
// object as soon as possible so the texture can be recycled.
|
// object as soon as possible so the texture can be recycled.
|
||||||
|
|
||||||
|
// TODO(perkj): Remove this class once Chrome uses TextureBuffer directly
|
||||||
|
// instead. This is just an extra level of indirection.
|
||||||
class NativeHandle {
|
class NativeHandle {
|
||||||
public:
|
public:
|
||||||
virtual ~NativeHandle() {}
|
virtual ~NativeHandle() {}
|
||||||
|
@ -51,7 +51,7 @@ class VideoFrameBuffer : public rtc::RefCountInterface {
|
|||||||
|
|
||||||
// Return the handle of the underlying video frame. This is used when the
|
// Return the handle of the underlying video frame. This is used when the
|
||||||
// frame is backed by a texture.
|
// frame is backed by a texture.
|
||||||
virtual rtc::scoped_refptr<NativeHandle> native_handle() const = 0;
|
virtual void* native_handle() const = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual ~VideoFrameBuffer();
|
virtual ~VideoFrameBuffer();
|
||||||
@ -68,7 +68,7 @@ class I420Buffer : public VideoFrameBuffer {
|
|||||||
const uint8_t* data(PlaneType type) const override;
|
const uint8_t* data(PlaneType type) const override;
|
||||||
uint8_t* data(PlaneType type) override;
|
uint8_t* data(PlaneType type) override;
|
||||||
int stride(PlaneType type) const override;
|
int stride(PlaneType type) const override;
|
||||||
rtc::scoped_refptr<NativeHandle> native_handle() const override;
|
void* native_handle() const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
~I420Buffer() override;
|
~I420Buffer() override;
|
||||||
@ -82,9 +82,17 @@ class I420Buffer : public VideoFrameBuffer {
|
|||||||
const rtc::scoped_ptr<uint8_t, AlignedFreeDeleter> data_;
|
const rtc::scoped_ptr<uint8_t, AlignedFreeDeleter> data_;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Texture buffer around a NativeHandle.
|
// Texture buffer is a VideoFrameBuffer wrapper around a |native_handle|.
|
||||||
|
// |native_handle| must be valid for the lifetime of an instance of this object.
|
||||||
|
// |no_longer_used| can be used to manage the lifetime of |native_handle|.
|
||||||
class TextureBuffer : public VideoFrameBuffer {
|
class TextureBuffer : public VideoFrameBuffer {
|
||||||
public:
|
public:
|
||||||
|
TextureBuffer(void* native_handle,
|
||||||
|
int width,
|
||||||
|
int height,
|
||||||
|
const rtc::Callback0<void>& no_longer_used);
|
||||||
|
|
||||||
|
// TODO(perkj): Remove once Chrome does not need it.
|
||||||
TextureBuffer(const rtc::scoped_refptr<NativeHandle>& native_handle,
|
TextureBuffer(const rtc::scoped_refptr<NativeHandle>& native_handle,
|
||||||
int width,
|
int width,
|
||||||
int height);
|
int height);
|
||||||
@ -94,15 +102,17 @@ class TextureBuffer : public VideoFrameBuffer {
|
|||||||
const uint8_t* data(PlaneType type) const override;
|
const uint8_t* data(PlaneType type) const override;
|
||||||
uint8_t* data(PlaneType type) override;
|
uint8_t* data(PlaneType type) override;
|
||||||
int stride(PlaneType type) const override;
|
int stride(PlaneType type) const override;
|
||||||
rtc::scoped_refptr<NativeHandle> native_handle() const override;
|
void* native_handle() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class rtc::RefCountedObject<TextureBuffer>;
|
friend class rtc::RefCountedObject<TextureBuffer>;
|
||||||
~TextureBuffer() override;
|
~TextureBuffer() override;
|
||||||
|
|
||||||
const rtc::scoped_refptr<NativeHandle> native_handle_;
|
// |native_handle_| is a raw pointer and not owned by TextureBuffer.
|
||||||
|
void* native_handle_;
|
||||||
const int width_;
|
const int width_;
|
||||||
const int height_;
|
const int height_;
|
||||||
|
rtc::Callback0<void> no_longer_used_cb_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class WrappedI420Buffer : public webrtc::VideoFrameBuffer {
|
class WrappedI420Buffer : public webrtc::VideoFrameBuffer {
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
#include "webrtc/common_video/interface/video_frame_buffer.h"
|
#include "webrtc/common_video/interface/video_frame_buffer.h"
|
||||||
|
|
||||||
|
#include "webrtc/base/bind.h"
|
||||||
#include "webrtc/base/checks.h"
|
#include "webrtc/base/checks.h"
|
||||||
|
|
||||||
// Aligning pointer to 64 bytes for improved performance, e.g. use SIMD.
|
// Aligning pointer to 64 bytes for improved performance, e.g. use SIMD.
|
||||||
@ -89,21 +90,39 @@ int I420Buffer::stride(PlaneType type) const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rtc::scoped_refptr<NativeHandle> I420Buffer::native_handle() const {
|
void* I420Buffer::native_handle() const {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TextureBuffer::TextureBuffer(void* native_handle,
|
||||||
|
int width,
|
||||||
|
int height,
|
||||||
|
const rtc::Callback0<void>& no_longer_used)
|
||||||
|
: native_handle_(native_handle),
|
||||||
|
width_(width),
|
||||||
|
height_(height),
|
||||||
|
no_longer_used_cb_(no_longer_used) {
|
||||||
|
DCHECK(native_handle != nullptr);
|
||||||
|
DCHECK_GT(width, 0);
|
||||||
|
DCHECK_GT(height, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ReleaseNativeHandle(
|
||||||
|
rtc::scoped_refptr<NativeHandle> native_handle) {
|
||||||
|
}
|
||||||
|
|
||||||
TextureBuffer::TextureBuffer(
|
TextureBuffer::TextureBuffer(
|
||||||
const rtc::scoped_refptr<NativeHandle>& native_handle,
|
const rtc::scoped_refptr<NativeHandle>& native_handle,
|
||||||
int width,
|
int width,
|
||||||
int height)
|
int height)
|
||||||
: native_handle_(native_handle), width_(width), height_(height) {
|
: TextureBuffer(native_handle->GetHandle(),
|
||||||
DCHECK(native_handle.get());
|
width,
|
||||||
DCHECK_GT(width, 0);
|
height,
|
||||||
DCHECK_GT(height, 0);
|
rtc::Bind(&ReleaseNativeHandle, native_handle)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TextureBuffer::~TextureBuffer() {
|
TextureBuffer::~TextureBuffer() {
|
||||||
|
no_longer_used_cb_();
|
||||||
}
|
}
|
||||||
|
|
||||||
int TextureBuffer::width() const {
|
int TextureBuffer::width() const {
|
||||||
@ -129,7 +148,7 @@ int TextureBuffer::stride(PlaneType type) const {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
rtc::scoped_refptr<NativeHandle> TextureBuffer::native_handle() const {
|
void* TextureBuffer::native_handle() const {
|
||||||
return native_handle_;
|
return native_handle_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
#include "testing/gtest/include/gtest/gtest.h"
|
#include "testing/gtest/include/gtest/gtest.h"
|
||||||
|
|
||||||
|
#include "webrtc/base/bind.h"
|
||||||
#include "webrtc/base/checks.h"
|
#include "webrtc/base/checks.h"
|
||||||
#include "webrtc/base/scoped_ptr.h"
|
#include "webrtc/base/scoped_ptr.h"
|
||||||
#include "webrtc/call.h"
|
#include "webrtc/call.h"
|
||||||
@ -50,13 +51,16 @@ void ExpectEqualFramesVector(const std::vector<I420VideoFrame>& frames1,
|
|||||||
const std::vector<I420VideoFrame>& frames2);
|
const std::vector<I420VideoFrame>& frames2);
|
||||||
I420VideoFrame CreateI420VideoFrame(int width, int height, uint8_t data);
|
I420VideoFrame CreateI420VideoFrame(int width, int height, uint8_t data);
|
||||||
|
|
||||||
class FakeNativeHandle : public NativeHandle {
|
class FakeNativeHandle {
|
||||||
public:
|
public:
|
||||||
FakeNativeHandle() {}
|
FakeNativeHandle() {}
|
||||||
virtual ~FakeNativeHandle() {}
|
~FakeNativeHandle() {}
|
||||||
virtual void* GetHandle() { return nullptr; }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void DeleteNativeHandle(FakeNativeHandle* handle) {
|
||||||
|
delete handle;
|
||||||
|
}
|
||||||
|
|
||||||
class VideoSendStreamTest : public test::CallTest {
|
class VideoSendStreamTest : public test::CallTest {
|
||||||
protected:
|
protected:
|
||||||
void TestNackRetransmission(uint32_t retransmit_ssrc,
|
void TestNackRetransmission(uint32_t retransmit_ssrc,
|
||||||
@ -1074,17 +1078,20 @@ TEST_F(VideoSendStreamTest, CapturesTextureAndI420VideoFrames) {
|
|||||||
std::vector<I420VideoFrame> input_frames;
|
std::vector<I420VideoFrame> input_frames;
|
||||||
int width = static_cast<int>(encoder_config_.streams[0].width);
|
int width = static_cast<int>(encoder_config_.streams[0].width);
|
||||||
int height = static_cast<int>(encoder_config_.streams[0].height);
|
int height = static_cast<int>(encoder_config_.streams[0].height);
|
||||||
webrtc::RefCountImpl<FakeNativeHandle>* handle1 =
|
FakeNativeHandle* handle1 = new FakeNativeHandle();
|
||||||
new webrtc::RefCountImpl<FakeNativeHandle>();
|
FakeNativeHandle* handle2 = new FakeNativeHandle();
|
||||||
webrtc::RefCountImpl<FakeNativeHandle>* handle2 =
|
FakeNativeHandle* handle3 = new FakeNativeHandle();
|
||||||
new webrtc::RefCountImpl<FakeNativeHandle>();
|
input_frames.push_back(
|
||||||
webrtc::RefCountImpl<FakeNativeHandle>* handle3 =
|
I420VideoFrame(handle1, width, height, 1, 1, kVideoRotation_0,
|
||||||
new webrtc::RefCountImpl<FakeNativeHandle>();
|
rtc::Bind(&DeleteNativeHandle, handle1)));
|
||||||
input_frames.push_back(I420VideoFrame(handle1, width, height, 1, 1));
|
input_frames.push_back(
|
||||||
input_frames.push_back(I420VideoFrame(handle2, width, height, 2, 2));
|
I420VideoFrame(handle2, width, height, 2, 2, kVideoRotation_0,
|
||||||
|
rtc::Bind(&DeleteNativeHandle, handle2)));
|
||||||
input_frames.push_back(CreateI420VideoFrame(width, height, 3));
|
input_frames.push_back(CreateI420VideoFrame(width, height, 3));
|
||||||
input_frames.push_back(CreateI420VideoFrame(width, height, 4));
|
input_frames.push_back(CreateI420VideoFrame(width, height, 4));
|
||||||
input_frames.push_back(I420VideoFrame(handle3, width, height, 5, 5));
|
input_frames.push_back(
|
||||||
|
I420VideoFrame(handle3, width, height, 5, 5, kVideoRotation_0,
|
||||||
|
rtc::Bind(&DeleteNativeHandle, handle3)));
|
||||||
|
|
||||||
send_stream_->Start();
|
send_stream_->Start();
|
||||||
for (size_t i = 0; i < input_frames.size(); i++) {
|
for (size_t i = 0; i < input_frames.size(); i++) {
|
||||||
|
@ -48,13 +48,6 @@ bool EqualFramesVector(const ScopedVector<I420VideoFrame>& frames1,
|
|||||||
const ScopedVector<I420VideoFrame>& frames2);
|
const ScopedVector<I420VideoFrame>& frames2);
|
||||||
I420VideoFrame* CreateI420VideoFrame(uint8_t length);
|
I420VideoFrame* CreateI420VideoFrame(uint8_t length);
|
||||||
|
|
||||||
class FakeNativeHandle : public NativeHandle {
|
|
||||||
public:
|
|
||||||
FakeNativeHandle() {}
|
|
||||||
virtual ~FakeNativeHandle() {}
|
|
||||||
virtual void* GetHandle() { return NULL; }
|
|
||||||
};
|
|
||||||
|
|
||||||
class ViECapturerTest : public ::testing::Test {
|
class ViECapturerTest : public ::testing::Test {
|
||||||
protected:
|
protected:
|
||||||
ViECapturerTest()
|
ViECapturerTest()
|
||||||
@ -181,13 +174,14 @@ TEST_F(ViECapturerTest, TestRtpTimeStampSet) {
|
|||||||
TEST_F(ViECapturerTest, TestTextureFrames) {
|
TEST_F(ViECapturerTest, TestTextureFrames) {
|
||||||
const int kNumFrame = 3;
|
const int kNumFrame = 3;
|
||||||
for (int i = 0 ; i < kNumFrame; ++i) {
|
for (int i = 0 ; i < kNumFrame; ++i) {
|
||||||
webrtc::RefCountImpl<FakeNativeHandle>* handle =
|
void* dummy_handle = reinterpret_cast<void*>(i+1);
|
||||||
new webrtc::RefCountImpl<FakeNativeHandle>();
|
|
||||||
// Add one to |i| so that width/height > 0.
|
// Add one to |i| so that width/height > 0.
|
||||||
input_frames_.push_back(
|
input_frames_.push_back(
|
||||||
new I420VideoFrame(handle, i + 1, i + 1, i + 1, i + 1));
|
new I420VideoFrame(dummy_handle, i + 1, i + 1, i + 1, i + 1,
|
||||||
|
webrtc::kVideoRotation_0, rtc::Callback0<void>()));
|
||||||
AddInputFrame(input_frames_[i]);
|
AddInputFrame(input_frames_[i]);
|
||||||
WaitOutputFrame();
|
WaitOutputFrame();
|
||||||
|
EXPECT_EQ(dummy_handle, output_frames_[i]->native_handle());
|
||||||
}
|
}
|
||||||
|
|
||||||
EXPECT_TRUE(EqualFramesVector(input_frames_, output_frames_));
|
EXPECT_TRUE(EqualFramesVector(input_frames_, output_frames_));
|
||||||
@ -211,11 +205,13 @@ TEST_F(ViECapturerTest, TestI420Frames) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ViECapturerTest, TestI420FrameAfterTextureFrame) {
|
TEST_F(ViECapturerTest, TestI420FrameAfterTextureFrame) {
|
||||||
webrtc::RefCountImpl<FakeNativeHandle>* handle =
|
void* dummy_handle = &input_frames_;
|
||||||
new webrtc::RefCountImpl<FakeNativeHandle>();
|
input_frames_.push_back(new I420VideoFrame(dummy_handle, 1, 1, 1, 1,
|
||||||
input_frames_.push_back(new I420VideoFrame(handle, 1, 1, 1, 1));
|
webrtc::kVideoRotation_0,
|
||||||
|
rtc::Callback0<void>()));
|
||||||
AddInputFrame(input_frames_[0]);
|
AddInputFrame(input_frames_[0]);
|
||||||
WaitOutputFrame();
|
WaitOutputFrame();
|
||||||
|
EXPECT_EQ(dummy_handle, output_frames_[0]->native_handle());
|
||||||
|
|
||||||
input_frames_.push_back(CreateI420VideoFrame(2));
|
input_frames_.push_back(CreateI420VideoFrame(2));
|
||||||
AddInputFrame(input_frames_[1]);
|
AddInputFrame(input_frames_[1]);
|
||||||
@ -229,9 +225,10 @@ TEST_F(ViECapturerTest, TestTextureFrameAfterI420Frame) {
|
|||||||
AddInputFrame(input_frames_[0]);
|
AddInputFrame(input_frames_[0]);
|
||||||
WaitOutputFrame();
|
WaitOutputFrame();
|
||||||
|
|
||||||
webrtc::RefCountImpl<FakeNativeHandle>* handle =
|
void* dummy_handle = &input_frames_;
|
||||||
new webrtc::RefCountImpl<FakeNativeHandle>();
|
input_frames_.push_back(new I420VideoFrame(dummy_handle, 1, 1, 2, 2,
|
||||||
input_frames_.push_back(new I420VideoFrame(handle, 1, 1, 2, 2));
|
webrtc::kVideoRotation_0,
|
||||||
|
rtc::Callback0<void>()));
|
||||||
AddInputFrame(input_frames_[1]);
|
AddInputFrame(input_frames_[1]);
|
||||||
WaitOutputFrame();
|
WaitOutputFrame();
|
||||||
|
|
||||||
|
@ -26,11 +26,19 @@ class I420VideoFrame {
|
|||||||
uint32_t timestamp,
|
uint32_t timestamp,
|
||||||
int64_t render_time_ms,
|
int64_t render_time_ms,
|
||||||
VideoRotation rotation);
|
VideoRotation rotation);
|
||||||
|
// TODO(perkj): Remove this constructor once Chrome no longer use it.
|
||||||
I420VideoFrame(NativeHandle* handle,
|
I420VideoFrame(NativeHandle* handle,
|
||||||
int width,
|
int width,
|
||||||
int height,
|
int height,
|
||||||
uint32_t timestamp,
|
uint32_t timestamp,
|
||||||
int64_t render_time_ms);
|
int64_t render_time_ms);
|
||||||
|
I420VideoFrame(void* native_handle,
|
||||||
|
int width,
|
||||||
|
int height,
|
||||||
|
uint32_t timestamp,
|
||||||
|
int64_t render_time_ms,
|
||||||
|
VideoRotation rotation,
|
||||||
|
const rtc::Callback0<void>& no_longer_used);
|
||||||
|
|
||||||
// TODO(pbos): Make all create/copy functions void, they should not be able to
|
// TODO(pbos): Make all create/copy functions void, they should not be able to
|
||||||
// fail (which should be DCHECK/CHECKed instead).
|
// fail (which should be DCHECK/CHECKed instead).
|
||||||
|
Loading…
x
Reference in New Issue
Block a user