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:
nisse
2016-09-30 04:14:07 -07:00
committed by Commit bot
parent 6f112cc136
commit 115bd153c7
19 changed files with 182 additions and 229 deletions

View File

@ -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