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/gpu_video_decoder.h" | 5 #include "media/filters/gpu_video_decoder.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 : bitstream_buffer_id(bbid), timestamp(ts), visible_rect(vr), | 53 : bitstream_buffer_id(bbid), timestamp(ts), visible_rect(vr), |
54 natural_size(ns) { | 54 natural_size(ns) { |
55 } | 55 } |
56 | 56 |
57 GpuVideoDecoder::BufferData::~BufferData() {} | 57 GpuVideoDecoder::BufferData::~BufferData() {} |
58 | 58 |
59 GpuVideoDecoder::GpuVideoDecoder( | 59 GpuVideoDecoder::GpuVideoDecoder( |
60 const scoped_refptr<GpuVideoAcceleratorFactories>& factories, | 60 const scoped_refptr<GpuVideoAcceleratorFactories>& factories, |
61 const scoped_refptr<MediaLog>& media_log) | 61 const scoped_refptr<MediaLog>& media_log) |
62 : needs_bitstream_conversion_(false), | 62 : needs_bitstream_conversion_(false), |
63 weak_factory_(this), | |
64 factories_(factories), | 63 factories_(factories), |
65 state_(kNormal), | 64 state_(kNormal), |
66 media_log_(media_log), | 65 media_log_(media_log), |
67 decoder_texture_target_(0), | 66 decoder_texture_target_(0), |
68 next_picture_buffer_id_(0), | 67 next_picture_buffer_id_(0), |
69 next_bitstream_buffer_id_(0), | 68 next_bitstream_buffer_id_(0), |
70 available_pictures_(0) { | 69 available_pictures_(0), |
| 70 weak_factory_(this) { |
71 DCHECK(factories_.get()); | 71 DCHECK(factories_.get()); |
72 } | 72 } |
73 | 73 |
74 void GpuVideoDecoder::Reset(const base::Closure& closure) { | 74 void GpuVideoDecoder::Reset(const base::Closure& closure) { |
75 DVLOG(3) << "Reset()"; | 75 DVLOG(3) << "Reset()"; |
76 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); | 76 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); |
77 | 77 |
78 if (state_ == kDrainingDecoder) { | 78 if (state_ == kDrainingDecoder) { |
79 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind( | 79 base::MessageLoop::current()->PostTask( |
80 &GpuVideoDecoder::Reset, weak_this_, closure)); | 80 FROM_HERE, |
| 81 base::Bind( |
| 82 &GpuVideoDecoder::Reset, weak_factory_.GetWeakPtr(), closure)); |
81 // NOTE: if we're deferring Reset() until a Flush() completes, return | 83 // NOTE: if we're deferring Reset() until a Flush() completes, return |
82 // queued pictures to the VDA so they can be used to finish that Flush(). | 84 // queued pictures to the VDA so they can be used to finish that Flush(). |
83 if (pending_decode_cb_.is_null()) | 85 if (pending_decode_cb_.is_null()) |
84 ready_video_frames_.clear(); | 86 ready_video_frames_.clear(); |
85 return; | 87 return; |
86 } | 88 } |
87 | 89 |
88 // Throw away any already-decoded, not-yet-delivered frames. | 90 // Throw away any already-decoded, not-yet-delivered frames. |
89 ready_video_frames_.clear(); | 91 ready_video_frames_.clear(); |
90 | 92 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 cb.Run(status); | 142 cb.Run(status); |
141 } | 143 } |
142 | 144 |
143 void GpuVideoDecoder::Initialize(const VideoDecoderConfig& config, | 145 void GpuVideoDecoder::Initialize(const VideoDecoderConfig& config, |
144 const PipelineStatusCB& orig_status_cb) { | 146 const PipelineStatusCB& orig_status_cb) { |
145 DVLOG(3) << "Initialize()"; | 147 DVLOG(3) << "Initialize()"; |
146 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); | 148 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); |
147 DCHECK(config.IsValidConfig()); | 149 DCHECK(config.IsValidConfig()); |
148 DCHECK(!config.is_encrypted()); | 150 DCHECK(!config.is_encrypted()); |
149 | 151 |
150 weak_this_ = weak_factory_.GetWeakPtr(); | |
151 | |
152 PipelineStatusCB status_cb = | 152 PipelineStatusCB status_cb = |
153 base::Bind(&ReportGpuVideoDecoderInitializeStatusToUMAAndRunCB, | 153 base::Bind(&ReportGpuVideoDecoderInitializeStatusToUMAAndRunCB, |
154 BindToCurrentLoop(orig_status_cb)); | 154 BindToCurrentLoop(orig_status_cb)); |
155 | 155 |
156 bool previously_initialized = config_.IsValidConfig(); | 156 bool previously_initialized = config_.IsValidConfig(); |
157 DVLOG(1) << "(Re)initializing GVD with config: " | 157 DVLOG(1) << "(Re)initializing GVD with config: " |
158 << config.AsHumanReadableString(); | 158 << config.AsHumanReadableString(); |
159 | 159 |
160 // TODO(posciak): destroy and create a new VDA on codec/profile change | 160 // TODO(posciak): destroy and create a new VDA on codec/profile change |
161 // (http://crbug.com/260224). | 161 // (http://crbug.com/260224). |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
456 gfx::Rect visible_rect; | 456 gfx::Rect visible_rect; |
457 gfx::Size natural_size; | 457 gfx::Size natural_size; |
458 GetBufferData(picture.bitstream_buffer_id(), ×tamp, &visible_rect, | 458 GetBufferData(picture.bitstream_buffer_id(), ×tamp, &visible_rect, |
459 &natural_size); | 459 &natural_size); |
460 DCHECK(decoder_texture_target_); | 460 DCHECK(decoder_texture_target_); |
461 | 461 |
462 scoped_refptr<VideoFrame> frame(VideoFrame::WrapNativeTexture( | 462 scoped_refptr<VideoFrame> frame(VideoFrame::WrapNativeTexture( |
463 make_scoped_ptr(new gpu::MailboxHolder( | 463 make_scoped_ptr(new gpu::MailboxHolder( |
464 pb.texture_mailbox(), decoder_texture_target_, 0 /* sync_point */)), | 464 pb.texture_mailbox(), decoder_texture_target_, 0 /* sync_point */)), |
465 BindToCurrentLoop(base::Bind(&GpuVideoDecoder::ReusePictureBuffer, | 465 BindToCurrentLoop(base::Bind(&GpuVideoDecoder::ReusePictureBuffer, |
466 weak_this_, | 466 weak_factory_.GetWeakPtr(), |
467 picture.picture_buffer_id())), | 467 picture.picture_buffer_id())), |
468 pb.size(), | 468 pb.size(), |
469 visible_rect, | 469 visible_rect, |
470 natural_size, | 470 natural_size, |
471 timestamp, | 471 timestamp, |
472 base::Bind(&ReadPixelsSync, factories_, pb.texture_id(), visible_rect))); | 472 base::Bind(&ReadPixelsSync, factories_, pb.texture_id(), visible_rect))); |
473 CHECK_GT(available_pictures_, 0); | 473 CHECK_GT(available_pictures_, 0); |
474 --available_pictures_; | 474 --available_pictures_; |
475 bool inserted = | 475 bool inserted = |
476 picture_buffers_at_display_.insert(picture.picture_buffer_id()).second; | 476 picture_buffers_at_display_.insert(picture.picture_buffer_id()).second; |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
634 return; | 634 return; |
635 } | 635 } |
636 } | 636 } |
637 | 637 |
638 void GpuVideoDecoder::DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent() | 638 void GpuVideoDecoder::DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent() |
639 const { | 639 const { |
640 DCHECK(factories_->GetTaskRunner()->BelongsToCurrentThread()); | 640 DCHECK(factories_->GetTaskRunner()->BelongsToCurrentThread()); |
641 } | 641 } |
642 | 642 |
643 } // namespace media | 643 } // namespace media |
OLD | NEW |