diff options
author | pbos@webrtc.org <pbos@webrtc.org@4adac7df-926f-26a2-2b94-8c16560cd09d> | 2013-11-22 13:10:13 +0000 |
---|---|---|
committer | pbos@webrtc.org <pbos@webrtc.org@4adac7df-926f-26a2-2b94-8c16560cd09d> | 2013-11-22 13:10:13 +0000 |
commit | 50293f5d7d3084d1d1389ccda3970cf8e6d4dc9f (patch) | |
tree | 933b9e6a0eeb3aa906760548b4665aec07ee7cba | |
parent | 84d69d428c28904ffff4106b714356ef9f979c04 (diff) | |
download | webrtc-50293f5d7d3084d1d1389ccda3970cf8e6d4dc9f.tar.gz |
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/webrtc@5160 4adac7df-926f-26a2-2b94-8c16560cd09d
-rw-r--r-- | modules/video_capture/include/video_capture_defines.h | 32 | ||||
-rw-r--r-- | modules/video_capture/test/video_capture_unittest.cc | 88 | ||||
-rw-r--r-- | modules/video_capture/video_capture_impl.cc | 22 | ||||
-rw-r--r-- | modules/video_capture/video_capture_impl.h | 6 | ||||
-rw-r--r-- | video_engine/include/vie_capture.h | 1 | ||||
-rw-r--r-- | video_engine/vie_capturer.cc | 36 | ||||
-rw-r--r-- | video_engine/vie_capturer.h | 2 |
7 files changed, 45 insertions, 142 deletions
diff --git a/modules/video_capture/include/video_capture_defines.h b/modules/video_capture/include/video_capture_defines.h index c592633b..330bfc75 100644 --- a/modules/video_capture/include/video_capture_defines.h +++ b/modules/video_capture/include/video_capture_defines.h @@ -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() {} }; diff --git a/modules/video_capture/test/video_capture_unittest.cc b/modules/video_capture/test/video_capture_unittest.cc index b047bee4..0f8052eb 100644 --- a/modules/video_capture/test/video_capture_unittest.cc +++ b/modules/video_capture/test/video_capture_unittest.cc @@ -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; - - EXPECT_EQ(0, capture_input_interface_->IncomingFrameI420(frame_i420, 0)); + frame_i420.CopyFrame(aligned_test_frame); + + EXPECT_EQ(0, + capture_input_interface_->IncomingI420VideoFrame(&frame_i420, 0)); EXPECT_TRUE(capture_callback_.CompareLastFrame(test_frame_)); } diff --git a/modules/video_capture/video_capture_impl.cc b/modules/video_capture/video_capture_impl.cc index a23d22b3..6689fd13 100644 --- a/modules/video_capture/video_capture_impl.cc +++ b/modules/video_capture/video_capture_impl.cc @@ -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; } diff --git a/modules/video_capture/video_capture_impl.h b/modules/video_capture/video_capture_impl.h index 41f555c3..80d5e678 100644 --- a/modules/video_capture/video_capture_impl.h +++ b/modules/video_capture/video_capture_impl.h @@ -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) diff --git a/video_engine/include/vie_capture.h b/video_engine/include/vie_capture.h index 2174d5dc..bcae930b 100644 --- a/video_engine/include/vie_capture.h +++ b/video_engine/include/vie_capture.h @@ -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; diff --git a/video_engine/vie_capturer.cc b/video_engine/vie_capturer.cc index 3f4f1d95..b8de7cd2 100644 --- a/video_engine/vie_capturer.cc +++ b/video_engine/vie_capturer.cc @@ -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; - - return external_capture_module_->IncomingFrameI420(frame, capture_time); + 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); + + 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, diff --git a/video_engine/vie_capturer.h b/video_engine/vie_capturer.h index afacc2da..1b12c45d 100644 --- a/video_engine/vie_capturer.h +++ b/video_engine/vie_capturer.h @@ -180,7 +180,7 @@ class ViECapturer CaptureCapability requested_capability_; - I420VideoFrame capture_device_image_; + I420VideoFrame capture_frame_; scoped_ptr<OveruseFrameDetector> overuse_detector_; }; |