Replace VideoFrameI420 with I420VideoFrame.
Gives one less struct/class for I420 video frames. BUG=2657 R=mflodman@webrtc.org, wu@webrtc.org Review URL: https://webrtc-codereview.appspot.com/4149004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@5160 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
@@ -84,33 +84,6 @@ enum VideoCaptureAlarm
|
||||
Cleared = 1
|
||||
};
|
||||
|
||||
// VideoFrameI420 doesn't take the ownership of the buffer.
|
||||
// It's mostly used to group the parameters for external capture.
|
||||
struct VideoFrameI420
|
||||
{
|
||||
VideoFrameI420() {
|
||||
y_plane = NULL;
|
||||
u_plane = NULL;
|
||||
v_plane = NULL;
|
||||
y_pitch = 0;
|
||||
u_pitch = 0;
|
||||
v_pitch = 0;
|
||||
width = 0;
|
||||
height = 0;
|
||||
}
|
||||
|
||||
unsigned char* y_plane;
|
||||
unsigned char* u_plane;
|
||||
unsigned char* v_plane;
|
||||
|
||||
int y_pitch;
|
||||
int u_pitch;
|
||||
int v_pitch;
|
||||
|
||||
unsigned short width;
|
||||
unsigned short height;
|
||||
};
|
||||
|
||||
/* External Capture interface. Returned by Create
|
||||
and implemented by the capture module.
|
||||
*/
|
||||
@@ -122,8 +95,9 @@ public:
|
||||
int32_t videoFrameLength,
|
||||
const VideoCaptureCapability& frameInfo,
|
||||
int64_t captureTime = 0) = 0;
|
||||
virtual int32_t IncomingFrameI420(const VideoFrameI420& video_frame,
|
||||
int64_t captureTime = 0) = 0;
|
||||
virtual int32_t IncomingI420VideoFrame(I420VideoFrame* video_frame,
|
||||
int64_t captureTime = 0) = 0;
|
||||
|
||||
protected:
|
||||
~VideoCaptureExternal() {}
|
||||
};
|
||||
|
@@ -84,60 +84,6 @@ static bool CompareFrames(const webrtc::I420VideoFrame& frame1,
|
||||
return true;
|
||||
}
|
||||
|
||||
// Compares the content of a I420 frame in planar form and the new video frame.
|
||||
static bool CompareFrames(const webrtc::VideoFrameI420& frame1,
|
||||
const webrtc::I420VideoFrame& frame2) {
|
||||
if (frame1.width != frame2.width() ||
|
||||
frame1.height != frame2.height()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Compare Y
|
||||
const unsigned char* y_plane = frame1.y_plane;
|
||||
const unsigned char* y_plane2 = frame2.buffer(webrtc::kYPlane);
|
||||
for (int i = 0; i < frame2.height(); ++i) {
|
||||
for (int j = 0; j < frame2.width(); ++j) {
|
||||
if (*y_plane != *y_plane2)
|
||||
return false;
|
||||
++y_plane;
|
||||
++y_plane2;
|
||||
}
|
||||
y_plane += frame1.y_pitch - frame1.width;
|
||||
y_plane2 += frame2.stride(webrtc::kYPlane) - frame2.width();
|
||||
}
|
||||
|
||||
// Compare U
|
||||
const unsigned char* u_plane = frame1.u_plane;
|
||||
const unsigned char* u_plane2 = frame2.buffer(webrtc::kUPlane);
|
||||
for (int i = 0; i < (frame2.height() + 1) / 2; ++i) {
|
||||
for (int j = 0; j < (frame2.width() + 1) / 2; ++j) {
|
||||
if (*u_plane != *u_plane2)
|
||||
return false;
|
||||
++u_plane;
|
||||
++u_plane2;
|
||||
}
|
||||
u_plane += frame1.u_pitch - (frame1.width + 1) / 2;
|
||||
u_plane2+= frame2.stride(webrtc::kUPlane) - (frame2.width() + 1) / 2;
|
||||
}
|
||||
|
||||
// Compare V
|
||||
unsigned char* v_plane = frame1.v_plane;
|
||||
const unsigned char* v_plane2 = frame2.buffer(webrtc::kVPlane);
|
||||
for (int i = 0; i < frame2.height() /2; ++i) {
|
||||
for (int j = 0; j < frame2.width() /2; ++j) {
|
||||
if (*u_plane != *u_plane2) {
|
||||
return false;
|
||||
}
|
||||
++v_plane;
|
||||
++v_plane2;
|
||||
}
|
||||
v_plane += frame1.v_pitch - (frame1.width + 1) / 2;
|
||||
u_plane2+= frame2.stride(webrtc::kVPlane) - (frame2.width() + 1) / 2;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
class TestVideoCaptureCallback : public VideoCaptureDataCallback {
|
||||
public:
|
||||
TestVideoCaptureCallback()
|
||||
@@ -229,11 +175,6 @@ class TestVideoCaptureCallback : public VideoCaptureDataCallback {
|
||||
return CompareFrames(last_frame_, frame);
|
||||
}
|
||||
|
||||
bool CompareLastFrame(const webrtc::VideoFrameI420& frame) {
|
||||
CriticalSectionScoped cs(capture_cs_.get());
|
||||
return CompareFrames(frame, last_frame_);
|
||||
}
|
||||
|
||||
void SetExpectedCaptureRotation(webrtc::VideoCaptureRotation rotation) {
|
||||
CriticalSectionScoped cs(capture_cs_.get());
|
||||
rotate_frame_ = rotation;
|
||||
@@ -503,16 +444,11 @@ TEST_F(VideoCaptureExternalTest, TestExternalCapture) {
|
||||
// NOTE: flaky, sometimes fails on the last CompareLastFrame.
|
||||
// http://code.google.com/p/webrtc/issues/detail?id=777
|
||||
TEST_F(VideoCaptureExternalTest, DISABLED_TestExternalCaptureI420) {
|
||||
webrtc::VideoFrameI420 frame_i420;
|
||||
frame_i420.width = kTestWidth;
|
||||
frame_i420.height = kTestHeight;
|
||||
frame_i420.y_plane = test_frame_.buffer(webrtc::kYPlane);
|
||||
frame_i420.u_plane = frame_i420.y_plane + (kTestWidth * kTestHeight);
|
||||
frame_i420.v_plane = frame_i420.u_plane + ((kTestWidth * kTestHeight) >> 2);
|
||||
frame_i420.y_pitch = kTestWidth;
|
||||
frame_i420.u_pitch = kTestWidth / 2;
|
||||
frame_i420.v_pitch = kTestWidth / 2;
|
||||
EXPECT_EQ(0, capture_input_interface_->IncomingFrameI420(frame_i420, 0));
|
||||
webrtc::I420VideoFrame frame_i420;
|
||||
frame_i420.CopyFrame(test_frame_);
|
||||
|
||||
EXPECT_EQ(0,
|
||||
capture_input_interface_->IncomingI420VideoFrame(&frame_i420, 0));
|
||||
EXPECT_TRUE(capture_callback_.CompareLastFrame(frame_i420));
|
||||
|
||||
// Test with a frame with pitch not equal to width
|
||||
@@ -566,16 +502,10 @@ TEST_F(VideoCaptureExternalTest, DISABLED_TestExternalCaptureI420) {
|
||||
current_pointer += v_pitch;
|
||||
v_plane += uv_width;
|
||||
}
|
||||
frame_i420.width = kTestWidth;
|
||||
frame_i420.height = kTestHeight;
|
||||
frame_i420.y_plane = aligned_test_frame.buffer(webrtc::kYPlane);
|
||||
frame_i420.u_plane = aligned_test_frame.buffer(webrtc::kYPlane);
|
||||
frame_i420.v_plane = aligned_test_frame.buffer(webrtc::kVPlane);
|
||||
frame_i420.y_pitch = y_pitch;
|
||||
frame_i420.u_pitch = u_pitch;
|
||||
frame_i420.v_pitch = v_pitch;
|
||||
frame_i420.CopyFrame(aligned_test_frame);
|
||||
|
||||
EXPECT_EQ(0, capture_input_interface_->IncomingFrameI420(frame_i420, 0));
|
||||
EXPECT_EQ(0,
|
||||
capture_input_interface_->IncomingI420VideoFrame(&frame_i420, 0));
|
||||
EXPECT_TRUE(capture_callback_.CompareLastFrame(test_frame_));
|
||||
}
|
||||
|
||||
|
@@ -358,27 +358,11 @@ int32_t VideoCaptureImpl::IncomingFrame(
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t VideoCaptureImpl::IncomingFrameI420(
|
||||
const VideoFrameI420& video_frame, int64_t captureTime) {
|
||||
int32_t VideoCaptureImpl::IncomingI420VideoFrame(I420VideoFrame* video_frame,
|
||||
int64_t captureTime) {
|
||||
|
||||
CriticalSectionScoped cs(&_callBackCs);
|
||||
int size_y = video_frame.height * video_frame.y_pitch;
|
||||
int size_u = video_frame.u_pitch * ((video_frame.height + 1) / 2);
|
||||
int size_v = video_frame.v_pitch * ((video_frame.height + 1) / 2);
|
||||
// TODO(mikhal): Can we use Swap here? This will do a memcpy.
|
||||
int ret = _captureFrame.CreateFrame(size_y, video_frame.y_plane,
|
||||
size_u, video_frame.u_plane,
|
||||
size_v, video_frame.v_plane,
|
||||
video_frame.width, video_frame.height,
|
||||
video_frame.y_pitch, video_frame.u_pitch,
|
||||
video_frame.v_pitch);
|
||||
if (ret < 0) {
|
||||
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, _id,
|
||||
"Failed to create I420VideoFrame");
|
||||
return -1;
|
||||
}
|
||||
|
||||
DeliverCapturedFrame(_captureFrame, captureTime);
|
||||
DeliverCapturedFrame(*video_frame, captureTime);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@@ -86,9 +86,9 @@ public:
|
||||
int32_t videoFrameLength,
|
||||
const VideoCaptureCapability& frameInfo,
|
||||
int64_t captureTime = 0);
|
||||
virtual int32_t IncomingFrameI420(
|
||||
const VideoFrameI420& video_frame,
|
||||
int64_t captureTime = 0);
|
||||
|
||||
virtual int32_t IncomingI420VideoFrame(I420VideoFrame* video_frame,
|
||||
int64_t captureTime = 0);
|
||||
|
||||
// Platform dependent
|
||||
virtual int32_t StartCapture(const VideoCaptureCapability& capability)
|
||||
|
@@ -114,6 +114,7 @@ class WEBRTC_DLLEXPORT ViEExternalCapture {
|
||||
// This method is specifically for delivering a new captured I420 frame to
|
||||
// VideoEngine.
|
||||
// |capture_time| must be specified in the NTP time format in milliseconds.
|
||||
// This method uses an internal buffer and must be called sequentially.
|
||||
virtual int IncomingFrameI420(
|
||||
const ViEVideoFrameI420& video_frame,
|
||||
unsigned long long capture_time = 0) = 0;
|
||||
|
@@ -327,17 +327,31 @@ int ViECapturer::IncomingFrameI420(const ViEVideoFrameI420& video_frame,
|
||||
return -1;
|
||||
}
|
||||
|
||||
VideoFrameI420 frame;
|
||||
frame.width = video_frame.width;
|
||||
frame.height = video_frame.height;
|
||||
frame.y_plane = video_frame.y_plane;
|
||||
frame.u_plane = video_frame.u_plane;
|
||||
frame.v_plane = video_frame.v_plane;
|
||||
frame.y_pitch = video_frame.y_pitch;
|
||||
frame.u_pitch = video_frame.u_pitch;
|
||||
frame.v_pitch = video_frame.v_pitch;
|
||||
int size_y = video_frame.height * video_frame.y_pitch;
|
||||
int size_u = video_frame.u_pitch * ((video_frame.height + 1) / 2);
|
||||
int size_v = video_frame.v_pitch * ((video_frame.height + 1) / 2);
|
||||
int ret = capture_frame_.CreateFrame(size_y,
|
||||
video_frame.y_plane,
|
||||
size_u,
|
||||
video_frame.u_plane,
|
||||
size_v,
|
||||
video_frame.v_plane,
|
||||
video_frame.width,
|
||||
video_frame.height,
|
||||
video_frame.y_pitch,
|
||||
video_frame.u_pitch,
|
||||
video_frame.v_pitch);
|
||||
|
||||
return external_capture_module_->IncomingFrameI420(frame, capture_time);
|
||||
if (ret < 0) {
|
||||
WEBRTC_TRACE(kTraceError,
|
||||
kTraceVideo,
|
||||
ViEId(engine_id_, capture_id_),
|
||||
"Failed to create I420VideoFrame");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return external_capture_module_->IncomingI420VideoFrame(&capture_frame_,
|
||||
capture_time);
|
||||
}
|
||||
|
||||
void ViECapturer::OnIncomingCapturedFrame(const int32_t capture_id,
|
||||
|
@@ -180,7 +180,7 @@ class ViECapturer
|
||||
|
||||
CaptureCapability requested_capability_;
|
||||
|
||||
I420VideoFrame capture_device_image_;
|
||||
I420VideoFrame capture_frame_;
|
||||
|
||||
scoped_ptr<OveruseFrameDetector> overuse_detector_;
|
||||
};
|
||||
|
Reference in New Issue
Block a user