Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 scoped_refptr<VideoFrame> video_frame = frame_pool_.CreateFrame( | 128 scoped_refptr<VideoFrame> video_frame = frame_pool_.CreateFrame( |
| 129 format, coded_size, gfx::Rect(size), natural_size, kNoTimestamp()); | 129 format, coded_size, gfx::Rect(size), natural_size, kNoTimestamp()); |
| 130 // FFmpeg expects the initialize allocation to be zero-initialized. Failure | |
| 131 // to do so can lead to unitialized value usage. See http://crbug.com/390941 | |
| 132 const size_t data_size = VideoFrame::AlignedAllocationSize(video_frame); | |
| 133 memset(video_frame->data(0), 0, data_size); | |
|
DaleCurtis
2015/07/09 21:35:11
We don't want to do this here actually, as now mem
emircan
2015/07/09 22:12:18
Done. I added |zero_out_memory| bool to carry that
| |
| 134 | |
| 130 if (codec_context->colorspace == AVCOL_SPC_BT709) { | 135 if (codec_context->colorspace == AVCOL_SPC_BT709) { |
| 131 video_frame->metadata()->SetInteger(VideoFrameMetadata::COLOR_SPACE, | 136 video_frame->metadata()->SetInteger(VideoFrameMetadata::COLOR_SPACE, |
| 132 VideoFrame::COLOR_SPACE_HD_REC709); | 137 VideoFrame::COLOR_SPACE_HD_REC709); |
| 133 } | 138 } |
| 134 | 139 |
| 135 for (int i = 0; i < 3; i++) { | 140 for (size_t i = 0; i < VideoFrame::NumPlanes(video_frame->format()); i++) { |
| 136 frame->data[i] = video_frame->data(i); | 141 frame->data[i] = video_frame->data(i); |
| 137 frame->linesize[i] = video_frame->stride(i); | 142 frame->linesize[i] = video_frame->stride(i); |
| 138 } | 143 } |
| 139 | 144 |
| 140 frame->width = coded_size.width(); | 145 frame->width = coded_size.width(); |
| 141 frame->height = coded_size.height(); | 146 frame->height = coded_size.height(); |
| 142 frame->format = codec_context->pix_fmt; | 147 frame->format = codec_context->pix_fmt; |
| 143 frame->reordered_opaque = codec_context->reordered_opaque; | 148 frame->reordered_opaque = codec_context->reordered_opaque; |
| 144 | 149 |
| 145 // Now create an AVBufferRef for the data just allocated. It will own the | 150 // Now create an AVBufferRef for the data just allocated. It will own the |
| 146 // reference to the VideoFrame object. | 151 // reference to the VideoFrame object. |
| 147 void* opaque = NULL; | 152 void* opaque = NULL; |
| 148 video_frame.swap(reinterpret_cast<VideoFrame**>(&opaque)); | 153 video_frame.swap(reinterpret_cast<VideoFrame**>(&opaque)); |
| 149 frame->buf[0] = | 154 frame->buf[0] = |
| 150 av_buffer_create(frame->data[0], | 155 av_buffer_create(frame->data[0], |
| 151 VideoFrame::AllocationSize(format, coded_size), | 156 data_size, |
|
DaleCurtis
2015/07/09 21:36:22
Hmm, I think we were intentionally using the lower
emircan
2015/07/09 22:12:17
I see. It looked like a mistake to me in the begin
DaleCurtis
2015/07/09 22:21:16
Hmm, I see, we can try it your way and see what fa
emircan
2015/07/09 23:16:27
Done.
emircan
2015/07/10 18:43:40
Well, bots showed that it didn't work out. Reverti
| |
| 152 ReleaseVideoBufferImpl, | 157 ReleaseVideoBufferImpl, |
| 153 opaque, | 158 opaque, |
| 154 0); | 159 0); |
| 155 return 0; | 160 return 0; |
| 156 } | 161 } |
| 157 | 162 |
| 158 std::string FFmpegVideoDecoder::GetDisplayName() const { | 163 std::string FFmpegVideoDecoder::GetDisplayName() const { |
| 159 return "FFmpegVideoDecoder"; | 164 return "FFmpegVideoDecoder"; |
| 160 } | 165 } |
| 161 | 166 |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 353 if (!codec || avcodec_open2(codec_context_.get(), codec, NULL) < 0) { | 358 if (!codec || avcodec_open2(codec_context_.get(), codec, NULL) < 0) { |
| 354 ReleaseFFmpegResources(); | 359 ReleaseFFmpegResources(); |
| 355 return false; | 360 return false; |
| 356 } | 361 } |
| 357 | 362 |
| 358 av_frame_.reset(av_frame_alloc()); | 363 av_frame_.reset(av_frame_alloc()); |
| 359 return true; | 364 return true; |
| 360 } | 365 } |
| 361 | 366 |
| 362 } // namespace media | 367 } // namespace media |
| OLD | NEW |