Commit a648b776 authored by Dale Curtis's avatar Dale Curtis Committed by Commit Bot

Increase VideoFrame stride alignment to 32; required by ffmpeg.

Per code inspection and commentary from ffmpeg developers, we
need to be using a stride that is aligned to 32 for software
video frames.

It seems at somepoint we might be able to use av_cpu_max_align(),
but even ffmpeg doesn't follow this internally and has exceptions
for when H264 content is used, so just leave a TODO for now.

BUG=773673
TEST=no more ubsan failure.

Change-Id: I012bf7ca5531559df63061fc1edc9fdeaebf4c08
Reviewed-on: https://chromium-review.googlesource.com/801775Reviewed-by: default avatarDan Sanders <sandersd@chromium.org>
Commit-Queue: Dale Curtis <dalecurtis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#520727}
parent 7f86d891
......@@ -1211,12 +1211,11 @@ void VideoFrame::AllocateMemory(bool zero_initialize_memory) {
strides_[0] = row_bytes(0);
} else {
for (size_t plane = 0; plane < NumPlanes(format_); ++plane) {
// The *2 in alignment for height is because some formats (e.g. h264)
// allow interlaced coding, and then the size needs to be a multiple of
// two macroblocks (vertically). See
// libavcodec/utils.c:avcodec_align_dimensions2().
const size_t height = RoundUp(rows(plane), kFrameSizeAlignment * 2);
strides_[plane] = RoundUp(row_bytes(plane), kFrameSizeAlignment);
// These values were chosen to mirror ffmpeg's get_video_buffer().
// TODO(dalecurtis): This should be configurable; eventually ffmpeg wants
// us to use av_cpu_max_align(), but... for now, they just hard-code 32.
const size_t height = RoundUp(rows(plane), kFrameAddressAlignment);
strides_[plane] = RoundUp(row_bytes(plane), kFrameAddressAlignment);
offset[plane] = data_size;
data_size += height * strides_[plane];
}
......
......@@ -38,6 +38,9 @@ class MEDIA_EXPORT VideoFrame : public base::RefCountedThreadSafe<VideoFrame> {
enum {
kFrameSizeAlignment = 16,
kFrameSizePadding = 16,
// Note: This value is dependent on what's used by ffmpeg, do not change
// without inspecting av_frame_get_buffer() first.
kFrameAddressAlignment = 32
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment