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

Side by Side Diff: content/renderer/media/rtc_video_decoder.cc

Issue 1476523005: Verify returned frames from media::VideoFrame::Wrap*() methods (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: LOG in video_Frame and CHECK/return outside. Created 5 years 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "content/renderer/media/rtc_video_decoder.h" 5 #include "content/renderer/media/rtc_video_decoder.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 const media::PictureBuffer& pb = it->second; 363 const media::PictureBuffer& pb = it->second;
364 if (visible_rect.IsEmpty() || !gfx::Rect(pb.size()).Contains(visible_rect)) { 364 if (visible_rect.IsEmpty() || !gfx::Rect(pb.size()).Contains(visible_rect)) {
365 LOG(ERROR) << "Invalid picture size: " << visible_rect.ToString() 365 LOG(ERROR) << "Invalid picture size: " << visible_rect.ToString()
366 << " should fit in " << pb.size().ToString(); 366 << " should fit in " << pb.size().ToString();
367 NotifyError(media::VideoDecodeAccelerator::PLATFORM_FAILURE); 367 NotifyError(media::VideoDecodeAccelerator::PLATFORM_FAILURE);
368 return; 368 return;
369 } 369 }
370 370
371 scoped_refptr<media::VideoFrame> frame = 371 scoped_refptr<media::VideoFrame> frame =
372 CreateVideoFrame(picture, pb, timestamp, visible_rect); 372 CreateVideoFrame(picture, pb, timestamp, visible_rect);
373 if (!frame) {
374 NotifyError(media::VideoDecodeAccelerator::PLATFORM_FAILURE);
375 return;
376 }
373 bool inserted = 377 bool inserted =
374 picture_buffers_at_display_.insert(std::make_pair( 378 picture_buffers_at_display_.insert(std::make_pair(
375 picture.picture_buffer_id(), 379 picture.picture_buffer_id(),
376 pb.texture_id())).second; 380 pb.texture_id())).second;
377 DCHECK(inserted); 381 DCHECK(inserted);
378 382
379 // Create a WebRTC video frame. 383 // Create a WebRTC video frame.
380 webrtc::VideoFrame decoded_image( 384 webrtc::VideoFrame decoded_image(
381 new rtc::RefCountedObject<WebRtcVideoFrameAdapter>(frame), timestamp, 0, 385 new rtc::RefCountedObject<WebRtcVideoFrameAdapter>(frame), timestamp, 0,
382 webrtc::kVideoRotation_0); 386 webrtc::kVideoRotation_0);
(...skipping 15 matching lines...) Expand all
398 uint32_t timestamp, 402 uint32_t timestamp,
399 const gfx::Rect& visible_rect) { 403 const gfx::Rect& visible_rect) {
400 DCHECK(decoder_texture_target_); 404 DCHECK(decoder_texture_target_);
401 // Convert timestamp from 90KHz to ms. 405 // Convert timestamp from 90KHz to ms.
402 base::TimeDelta timestamp_ms = base::TimeDelta::FromInternalValue( 406 base::TimeDelta timestamp_ms = base::TimeDelta::FromInternalValue(
403 base::checked_cast<uint64_t>(timestamp) * 1000 / 90); 407 base::checked_cast<uint64_t>(timestamp) * 1000 / 90);
404 // TODO(mcasas): The incoming data is actually a YUV format, but is labelled 408 // TODO(mcasas): The incoming data is actually a YUV format, but is labelled
405 // as ARGB. This prevents the compositor from messing with it, since the 409 // as ARGB. This prevents the compositor from messing with it, since the
406 // underlying platform can handle the former format natively. Make sure the 410 // underlying platform can handle the former format natively. Make sure the
407 // correct format is used and everyone down the line understands it. 411 // correct format is used and everyone down the line understands it.
408 scoped_refptr<media::VideoFrame> frame(media::VideoFrame::WrapNativeTexture( 412 scoped_refptr<media::VideoFrame> frame = media::VideoFrame::WrapNativeTexture(
409 media::PIXEL_FORMAT_ARGB, 413 media::PIXEL_FORMAT_ARGB,
410 gpu::MailboxHolder(pb.texture_mailbox(), gpu::SyncToken(), 414 gpu::MailboxHolder(pb.texture_mailbox(), gpu::SyncToken(),
411 decoder_texture_target_), 415 decoder_texture_target_),
412 media::BindToCurrentLoop(base::Bind( 416 media::BindToCurrentLoop(base::Bind(
413 &RTCVideoDecoder::ReleaseMailbox, weak_factory_.GetWeakPtr(), 417 &RTCVideoDecoder::ReleaseMailbox, weak_factory_.GetWeakPtr(),
414 factories_, picture.picture_buffer_id(), pb.texture_id())), 418 factories_, picture.picture_buffer_id(), pb.texture_id())),
415 pb.size(), visible_rect, visible_rect.size(), timestamp_ms)); 419 pb.size(), visible_rect, visible_rect.size(), timestamp_ms);
416 if (picture.allow_overlay()) { 420 if (frame && picture.allow_overlay()) {
417 frame->metadata()->SetBoolean(media::VideoFrameMetadata::ALLOW_OVERLAY, 421 frame->metadata()->SetBoolean(media::VideoFrameMetadata::ALLOW_OVERLAY,
418 true); 422 true);
419 } 423 }
420 return frame; 424 return frame;
421 } 425 }
422 426
423 void RTCVideoDecoder::NotifyEndOfBitstreamBuffer(int32 id) { 427 void RTCVideoDecoder::NotifyEndOfBitstreamBuffer(int32 id) {
424 DVLOG(3) << "NotifyEndOfBitstreamBuffer. id=" << id; 428 DVLOG(3) << "NotifyEndOfBitstreamBuffer. id=" << id;
425 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); 429 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent();
426 430
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
805 } 809 }
806 810
807 void RTCVideoDecoder::ClearPendingBuffers() { 811 void RTCVideoDecoder::ClearPendingBuffers() {
808 // Delete WebRTC input buffers. 812 // Delete WebRTC input buffers.
809 for (const auto& pending_buffer : pending_buffers_) 813 for (const auto& pending_buffer : pending_buffers_)
810 delete[] pending_buffer.first._buffer; 814 delete[] pending_buffer.first._buffer;
811 pending_buffers_.clear(); 815 pending_buffers_.clear();
812 } 816 }
813 817
814 } // namespace content 818 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698