New helper function test::ReadI420Buffer, refactor FrameReader to use it.
This change reduces the number of places where we first fread a I420 frame into a uint8_t buffer, followed by a copy into a frame buffer object. BUG=None Review-Url: https://codereview.webrtc.org/2362683002 Cr-Commit-Position: refs/heads/master@{#14456}
This commit is contained in:
@ -72,5 +72,22 @@ bool FrameBufsEqual(const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& f1,
|
||||
half_width, half_height);
|
||||
}
|
||||
|
||||
rtc::scoped_refptr<I420Buffer> ReadI420Buffer(int width, int height, FILE *f) {
|
||||
int half_width = (width + 1) / 2;
|
||||
rtc::scoped_refptr<I420Buffer> buffer(
|
||||
// Explicit stride, no padding between rows.
|
||||
I420Buffer::Create(width, height, width, half_width, half_width));
|
||||
size_t size_y = static_cast<size_t>(width) * height;
|
||||
size_t size_uv = static_cast<size_t>(half_width) * ((height + 1) / 2);
|
||||
|
||||
if (fread(buffer->MutableDataY(), 1, size_y, f) < size_y)
|
||||
return nullptr;
|
||||
if (fread(buffer->MutableDataU(), 1, size_uv, f) < size_uv)
|
||||
return nullptr;
|
||||
if (fread(buffer->MutableDataV(), 1, size_uv, f) < size_uv)
|
||||
return nullptr;
|
||||
return buffer;
|
||||
}
|
||||
|
||||
} // namespace test
|
||||
} // namespace webrtc
|
||||
|
||||
Reference in New Issue
Block a user