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

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

Issue 1227383003: Remove memset from VideoFrame and mark buffer as unpoisoned (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: dalecurtis@ comments. Created 5 years, 5 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
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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 DCHECK_EQ(codec_context->lowres, 0); 118 DCHECK_EQ(codec_context->lowres, 0);
119 gfx::Size coded_size( 119 gfx::Size coded_size(
120 RoundUp(std::max(size.width(), codec_context->coded_width), 2), 120 RoundUp(std::max(size.width(), codec_context->coded_width), 2),
121 RoundUp(std::max(size.height(), codec_context->coded_height), 2)); 121 RoundUp(std::max(size.height(), codec_context->coded_height), 2));
122 122
123 if (!VideoFrame::IsValidConfig(format, VideoFrame::STORAGE_UNKNOWN, 123 if (!VideoFrame::IsValidConfig(format, VideoFrame::STORAGE_UNKNOWN,
124 coded_size, gfx::Rect(size), natural_size)) { 124 coded_size, gfx::Rect(size), natural_size)) {
125 return AVERROR(EINVAL); 125 return AVERROR(EINVAL);
126 } 126 }
127 127
128 // FFmpeg expects the initialize allocation to be zero-initialized. Failure
129 // to do so can lead to unitialized value usage. See http://crbug.com/390941
128 scoped_refptr<VideoFrame> video_frame = frame_pool_.CreateFrame( 130 scoped_refptr<VideoFrame> video_frame = frame_pool_.CreateFrame(
129 format, coded_size, gfx::Rect(size), natural_size, kNoTimestamp()); 131 format, coded_size, gfx::Rect(size), natural_size, kNoTimestamp(), true);
132
130 if (codec_context->colorspace == AVCOL_SPC_BT709) { 133 if (codec_context->colorspace == AVCOL_SPC_BT709) {
131 video_frame->metadata()->SetInteger(VideoFrameMetadata::COLOR_SPACE, 134 video_frame->metadata()->SetInteger(VideoFrameMetadata::COLOR_SPACE,
132 VideoFrame::COLOR_SPACE_HD_REC709); 135 VideoFrame::COLOR_SPACE_HD_REC709);
133 } 136 }
134 137
135 for (int i = 0; i < 3; i++) { 138 for (size_t i = 0; i < VideoFrame::NumPlanes(video_frame->format()); i++) {
136 frame->data[i] = video_frame->data(i); 139 frame->data[i] = video_frame->data(i);
137 frame->linesize[i] = video_frame->stride(i); 140 frame->linesize[i] = video_frame->stride(i);
138 } 141 }
139 142
140 frame->width = coded_size.width(); 143 frame->width = coded_size.width();
141 frame->height = coded_size.height(); 144 frame->height = coded_size.height();
142 frame->format = codec_context->pix_fmt; 145 frame->format = codec_context->pix_fmt;
143 frame->reordered_opaque = codec_context->reordered_opaque; 146 frame->reordered_opaque = codec_context->reordered_opaque;
144 147
145 // Now create an AVBufferRef for the data just allocated. It will own the 148 // Now create an AVBufferRef for the data just allocated. It will own the
146 // reference to the VideoFrame object. 149 // reference to the VideoFrame object.
147 void* opaque = NULL; 150 void* opaque = NULL;
148 video_frame.swap(reinterpret_cast<VideoFrame**>(&opaque)); 151 video_frame.swap(reinterpret_cast<VideoFrame**>(&opaque));
149 frame->buf[0] = 152 frame->buf[0] =
150 av_buffer_create(frame->data[0], 153 av_buffer_create(frame->data[0],
151 VideoFrame::AllocationSize(format, coded_size), 154 VideoFrame::AlignedAllocationSize(video_frame),
152 ReleaseVideoBufferImpl, 155 ReleaseVideoBufferImpl,
153 opaque, 156 opaque,
154 0); 157 0);
155 return 0; 158 return 0;
156 } 159 }
157 160
158 std::string FFmpegVideoDecoder::GetDisplayName() const { 161 std::string FFmpegVideoDecoder::GetDisplayName() const {
159 return "FFmpegVideoDecoder"; 162 return "FFmpegVideoDecoder";
160 } 163 }
161 164
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 if (!codec || avcodec_open2(codec_context_.get(), codec, NULL) < 0) { 356 if (!codec || avcodec_open2(codec_context_.get(), codec, NULL) < 0) {
354 ReleaseFFmpegResources(); 357 ReleaseFFmpegResources();
355 return false; 358 return false;
356 } 359 }
357 360
358 av_frame_.reset(av_frame_alloc()); 361 av_frame_.reset(av_frame_alloc());
359 return true; 362 return true;
360 } 363 }
361 364
362 } // namespace media 365 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698