Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(34)

Side by Side Diff: media/filters/ffmpeg_video_decoder.cc

Issue 1267003004: Revert to zero-initializing buffers for FFmpegVideoDecoder (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Zero initialize only the planes. Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/base/video_frame_pool_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/filters/ffmpeg_video_decoder.h" 5 #include "media/filters/ffmpeg_video_decoder.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 // since we don't use this, just DCHECK that it's zero. 108 // since we don't use this, just DCHECK that it's zero.
109 DCHECK_EQ(codec_context->lowres, 0); 109 DCHECK_EQ(codec_context->lowres, 0);
110 gfx::Size coded_size(std::max(size.width(), codec_context->coded_width), 110 gfx::Size coded_size(std::max(size.width(), codec_context->coded_width),
111 std::max(size.height(), codec_context->coded_height)); 111 std::max(size.height(), codec_context->coded_height));
112 112
113 if (!VideoFrame::IsValidConfig(format, VideoFrame::STORAGE_UNKNOWN, 113 if (!VideoFrame::IsValidConfig(format, VideoFrame::STORAGE_UNKNOWN,
114 coded_size, gfx::Rect(size), natural_size)) { 114 coded_size, gfx::Rect(size), natural_size)) {
115 return AVERROR(EINVAL); 115 return AVERROR(EINVAL);
116 } 116 }
117 117
118 // FFmpeg expects the initialize allocation to be zero-initialized. Failure
119 // to do so can lead to unitialized value usage. See http://crbug.com/390941
118 scoped_refptr<VideoFrame> video_frame = frame_pool_.CreateFrame( 120 scoped_refptr<VideoFrame> video_frame = frame_pool_.CreateFrame(
119 format, coded_size, gfx::Rect(size), natural_size, kNoTimestamp()); 121 format, coded_size, gfx::Rect(size), natural_size, kNoTimestamp());
120 #if defined(MEMORY_SANITIZER)
121 MSAN_UNPOISON(video_frame->data(0),
122 VideoFrame::AllocationSize(format, coded_size));
123 #endif
124 122
125 // Prefer the color space from the codec context. If it's not specified (or is 123 // Prefer the color space from the codec context. If it's not specified (or is
126 // set to an unsupported value), fall back on the value from the config. 124 // set to an unsupported value), fall back on the value from the config.
127 ColorSpace color_space = AVColorSpaceToColorSpace(codec_context->colorspace, 125 ColorSpace color_space = AVColorSpaceToColorSpace(codec_context->colorspace,
128 codec_context->color_range); 126 codec_context->color_range);
129 if (color_space == COLOR_SPACE_UNSPECIFIED) 127 if (color_space == COLOR_SPACE_UNSPECIFIED)
130 color_space = config_.color_space(); 128 color_space = config_.color_space();
131 video_frame->metadata()->SetInteger(VideoFrameMetadata::COLOR_SPACE, 129 video_frame->metadata()->SetInteger(VideoFrameMetadata::COLOR_SPACE,
132 color_space); 130 color_space);
133 131
134 for (int i = 0; i < 3; i++) { 132 for (size_t i = 0; i < VideoFrame::NumPlanes(video_frame->format()); i++) {
135 frame->data[i] = video_frame->data(i); 133 frame->data[i] = video_frame->data(i);
136 frame->linesize[i] = video_frame->stride(i); 134 frame->linesize[i] = video_frame->stride(i);
137 } 135 }
138 136
139 frame->width = coded_size.width(); 137 frame->width = coded_size.width();
140 frame->height = coded_size.height(); 138 frame->height = coded_size.height();
141 frame->format = codec_context->pix_fmt; 139 frame->format = codec_context->pix_fmt;
142 frame->reordered_opaque = codec_context->reordered_opaque; 140 frame->reordered_opaque = codec_context->reordered_opaque;
143 141
144 // Now create an AVBufferRef for the data just allocated. It will own the 142 // Now create an AVBufferRef for the data just allocated. It will own the
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 if (!codec || avcodec_open2(codec_context_.get(), codec, NULL) < 0) { 350 if (!codec || avcodec_open2(codec_context_.get(), codec, NULL) < 0) {
353 ReleaseFFmpegResources(); 351 ReleaseFFmpegResources();
354 return false; 352 return false;
355 } 353 }
356 354
357 av_frame_.reset(av_frame_alloc()); 355 av_frame_.reset(av_frame_alloc());
358 return true; 356 return true;
359 } 357 }
360 358
361 } // namespace media 359 } // namespace media
OLDNEW
« no previous file with comments | « media/base/video_frame_pool_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698