Skip to content

Commit 21a18ee

Browse files
ivocCommit bot
authored andcommitted
Revert of Delete webrtc::VideoFrame::CopyFrame. (patchset #2 id:20001 of https://codereview.webrtc.org/2371363003/ )
Reason for revert: This CL breaks internal dependencies. Original issue's description: > Delete webrtc::VideoFrame::CopyFrame. > > BUG=webrtc:5682 > > Committed: https://crrev.com/0e7c7ce35d9449c5bb13328d1bfb04ad32e48ccc > Cr-Commit-Position: refs/heads/master@{#14550} TBR=magjed@webrtc.org,tommi@webrtc.org,nisse@webrtc.org # Skipping CQ checks because original CL landed less than 1 days ago. NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=webrtc:5682 Review-Url: https://codereview.webrtc.org/2397943003 Cr-Commit-Position: refs/heads/master@{#14553}
1 parent 327e9d0 commit 21a18ee

6 files changed

Lines changed: 65 additions & 6 deletions

File tree

webrtc/common_video/i420_video_frame_unittest.cc

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ TEST(TestVideoFrame, InitialValues) {
8484
EXPECT_EQ(kVideoRotation_0, frame.rotation());
8585
}
8686

87+
TEST(TestVideoFrame, CopiesInitialFrameWithoutCrashing) {
88+
VideoFrame frame;
89+
VideoFrame frame2;
90+
frame2.CopyFrame(frame);
91+
}
92+
8793
TEST(TestVideoFrame, WidthHeightValues) {
8894
VideoFrame frame(I420Buffer::Create(10, 10, 10, 14, 90),
8995
webrtc::kVideoRotation_0,
@@ -98,6 +104,44 @@ TEST(TestVideoFrame, WidthHeightValues) {
98104
EXPECT_EQ(789, frame.render_time_ms());
99105
}
100106

107+
TEST(TestVideoFrame, CopyFrame) {
108+
int stride_y = 15;
109+
int stride_u = 10;
110+
int stride_v = 10;
111+
int width = 15;
112+
int height = 15;
113+
// Copy frame.
114+
VideoFrame small_frame;
115+
const int kSizeY = 400;
116+
const int kSizeU = 100;
117+
const int kSizeV = 100;
118+
const VideoRotation kRotation = kVideoRotation_270;
119+
uint8_t buffer_y[kSizeY];
120+
uint8_t buffer_u[kSizeU];
121+
uint8_t buffer_v[kSizeV];
122+
memset(buffer_y, 16, kSizeY);
123+
memset(buffer_u, 8, kSizeU);
124+
memset(buffer_v, 4, kSizeV);
125+
VideoFrame big_frame;
126+
big_frame.CreateFrame(buffer_y, buffer_u, buffer_v,
127+
width + 5, height + 5, stride_y + 5,
128+
stride_u, stride_v, kRotation);
129+
// Frame of smaller dimensions.
130+
small_frame.CopyFrame(big_frame);
131+
EXPECT_TRUE(test::FramesEqual(small_frame, big_frame));
132+
EXPECT_EQ(kRotation, small_frame.rotation());
133+
134+
// Frame of larger dimensions.
135+
rtc::scoped_refptr<I420Buffer> buffer =
136+
I420Buffer::Create(width, height, stride_y, stride_u, stride_v);
137+
memset(buffer->MutableDataY(), 1, width * height);
138+
memset(buffer->MutableDataU(), 2, ((height + 1) / 2) * stride_u);
139+
memset(buffer->MutableDataV(), 3, ((height + 1) / 2) * stride_u);
140+
VideoFrame other_frame(buffer, 0, 0, webrtc::kVideoRotation_0);
141+
big_frame.CopyFrame(other_frame);
142+
EXPECT_TRUE(test::FramesEqual(other_frame, big_frame));
143+
}
144+
101145
TEST(TestVideoFrame, ShallowCopy) {
102146
uint32_t timestamp = 1;
103147
int64_t ntp_time_ms = 2;

webrtc/common_video/video_frame.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,15 @@ void VideoFrame::CreateFrame(const uint8_t* buffer,
9393
stride_uv, stride_uv, rotation);
9494
}
9595

96+
void VideoFrame::CopyFrame(const VideoFrame& videoFrame) {
97+
ShallowCopy(videoFrame);
98+
99+
// If backed by a plain memory buffer, create a new, non-shared, copy.
100+
if (video_frame_buffer_ && !video_frame_buffer_->native_handle()) {
101+
video_frame_buffer_ = I420Buffer::Copy(video_frame_buffer_);
102+
}
103+
}
104+
96105
void VideoFrame::ShallowCopy(const VideoFrame& videoFrame) {
97106
video_frame_buffer_ = videoFrame.video_frame_buffer();
98107
timestamp_rtp_ = videoFrame.timestamp_rtp_;

webrtc/modules/video_coding/codecs/vp8/test/vp8_impl_unittest.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ bool Vp8UnitTestDecodeCompleteCallback::DecodeComplete() {
110110
}
111111

112112
int Vp8UnitTestDecodeCompleteCallback::Decoded(VideoFrame& image) {
113-
decoded_frame_->ShallowCopy(image);
113+
decoded_frame_->CopyFrame(image);
114114
decode_complete = true;
115115
return 0;
116116
}

webrtc/modules/video_processing/test/video_processing_unittest.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,9 @@ void TestSize(const VideoFrame& source_frame,
250250

251251
// Scale |resampled_source_frame| back to the source scale.
252252
VideoFrame resampled_source_frame;
253-
resampled_source_frame.ShallowCopy(*out_frame);
253+
resampled_source_frame.CopyFrame(*out_frame);
254254
// Compute PSNR against the cropped source frame and check expectation.
255-
PreprocessFrameAndVerify(resampled_source_frame,
256-
cropped_source.width(),
255+
PreprocessFrameAndVerify(resampled_source_frame, cropped_source.width(),
257256
cropped_source.height(), vpm, out_frame);
258257
WriteProcessedFrameForVisualInspection(resampled_source_frame, *out_frame);
259258

webrtc/video/video_quality_test.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,8 +482,8 @@ class VideoAnalyzer : public PacketReceiver,
482482

483483
rtc::CritScope crit(&comparison_lock_);
484484
if (comparisons_.size() < kMaxComparisons) {
485-
reference_copy.ShallowCopy(reference);
486-
render_copy.ShallowCopy(render);
485+
reference_copy.CopyFrame(reference);
486+
render_copy.CopyFrame(render);
487487
} else {
488488
// Copy the time to ensure that delay calculations can still be made.
489489
reference_copy.set_ntp_time_ms(reference.ntp_time_ms());

webrtc/video_frame.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ class VideoFrame {
7070
int height,
7171
VideoRotation rotation);
7272

73+
// Deep copy frame: If required size is bigger than allocated one, new
74+
// buffers of adequate size will be allocated.
75+
// TODO(nisse): Should be deleted in the cricket::VideoFrame and
76+
// webrtc::VideoFrame merge. Instead, use I420Buffer::Copy to make a copy of
77+
// the pixel data, and use the constructor to wrap it into a VideoFrame.
78+
void CopyFrame(const VideoFrame& videoFrame);
79+
7380
// Creates a shallow copy of |videoFrame|, i.e, the this object will retain a
7481
// reference to the video buffer also retained by |videoFrame|.
7582
// TODO(nisse): Deprecated. Should be deleted in the cricket::VideoFrame and

0 commit comments

Comments
 (0)