| 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/bind_to_current_loop.h" |
| 10 #include "base/callback_helpers.h" | 11 #include "base/callback_helpers.h" |
| 11 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 12 #include "base/cpu.h" | 13 #include "base/cpu.h" |
| 13 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 14 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
| 15 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
| 16 #include "base/task_runner_util.h" | 17 #include "base/task_runner_util.h" |
| 17 #include "gpu/command_buffer/common/mailbox_holder.h" | 18 #include "gpu/command_buffer/common/mailbox_holder.h" |
| 18 #include "media/base/bind_to_current_loop.h" | |
| 19 #include "media/base/decoder_buffer.h" | 19 #include "media/base/decoder_buffer.h" |
| 20 #include "media/base/media_switches.h" | 20 #include "media/base/media_switches.h" |
| 21 #include "media/base/pipeline.h" | 21 #include "media/base/pipeline.h" |
| 22 #include "media/base/pipeline_status.h" | 22 #include "media/base/pipeline_status.h" |
| 23 #include "media/base/video_decoder_config.h" | 23 #include "media/base/video_decoder_config.h" |
| 24 #include "media/renderers/gpu_video_accelerator_factories.h" | 24 #include "media/renderers/gpu_video_accelerator_factories.h" |
| 25 #include "third_party/skia/include/core/SkBitmap.h" | 25 #include "third_party/skia/include/core/SkBitmap.h" |
| 26 | 26 |
| 27 namespace media { | 27 namespace media { |
| 28 | 28 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 &GpuVideoDecoder::Reset, weak_factory_.GetWeakPtr(), closure)); | 85 &GpuVideoDecoder::Reset, weak_factory_.GetWeakPtr(), closure)); |
| 86 return; | 86 return; |
| 87 } | 87 } |
| 88 | 88 |
| 89 if (!vda_) { | 89 if (!vda_) { |
| 90 base::MessageLoop::current()->PostTask(FROM_HERE, closure); | 90 base::MessageLoop::current()->PostTask(FROM_HERE, closure); |
| 91 return; | 91 return; |
| 92 } | 92 } |
| 93 | 93 |
| 94 DCHECK(pending_reset_cb_.is_null()); | 94 DCHECK(pending_reset_cb_.is_null()); |
| 95 pending_reset_cb_ = BindToCurrentLoop(closure); | 95 pending_reset_cb_ = base::BindToCurrentLoop(closure); |
| 96 | 96 |
| 97 vda_->Reset(); | 97 vda_->Reset(); |
| 98 } | 98 } |
| 99 | 99 |
| 100 static bool IsCodedSizeSupported(const gfx::Size& coded_size, | 100 static bool IsCodedSizeSupported(const gfx::Size& coded_size, |
| 101 const gfx::Size& min_resolution, | 101 const gfx::Size& min_resolution, |
| 102 const gfx::Size& max_resolution) { | 102 const gfx::Size& max_resolution) { |
| 103 return (coded_size.width() <= max_resolution.width() && | 103 return (coded_size.width() <= max_resolution.width() && |
| 104 coded_size.height() <= max_resolution.height() && | 104 coded_size.height() <= max_resolution.height() && |
| 105 coded_size.width() >= min_resolution.width() && | 105 coded_size.width() >= min_resolution.width() && |
| (...skipping 19 matching lines...) Expand all Loading... |
| 125 bool /* low_delay */, | 125 bool /* low_delay */, |
| 126 const PipelineStatusCB& orig_status_cb, | 126 const PipelineStatusCB& orig_status_cb, |
| 127 const OutputCB& output_cb) { | 127 const OutputCB& output_cb) { |
| 128 DVLOG(3) << "Initialize()"; | 128 DVLOG(3) << "Initialize()"; |
| 129 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); | 129 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); |
| 130 DCHECK(config.IsValidConfig()); | 130 DCHECK(config.IsValidConfig()); |
| 131 DCHECK(!config.is_encrypted()); | 131 DCHECK(!config.is_encrypted()); |
| 132 | 132 |
| 133 PipelineStatusCB status_cb = | 133 PipelineStatusCB status_cb = |
| 134 base::Bind(&ReportGpuVideoDecoderInitializeStatusToUMAAndRunCB, | 134 base::Bind(&ReportGpuVideoDecoderInitializeStatusToUMAAndRunCB, |
| 135 BindToCurrentLoop(orig_status_cb)); | 135 base::BindToCurrentLoop(orig_status_cb)); |
| 136 | 136 |
| 137 bool previously_initialized = config_.IsValidConfig(); | 137 bool previously_initialized = config_.IsValidConfig(); |
| 138 DVLOG(1) << "(Re)initializing GVD with config: " | 138 DVLOG(1) << "(Re)initializing GVD with config: " |
| 139 << config.AsHumanReadableString(); | 139 << config.AsHumanReadableString(); |
| 140 | 140 |
| 141 // TODO(posciak): destroy and create a new VDA on codec/profile change | 141 // TODO(posciak): destroy and create a new VDA on codec/profile change |
| 142 // (http://crbug.com/260224). | 142 // (http://crbug.com/260224). |
| 143 if (previously_initialized && (config_.profile() != config.profile())) { | 143 if (previously_initialized && (config_.profile() != config.profile())) { |
| 144 DVLOG(1) << "Codec or profile changed, cannot reinitialize."; | 144 DVLOG(1) << "Codec or profile changed, cannot reinitialize."; |
| 145 status_cb.Run(DECODER_ERROR_NOT_SUPPORTED); | 145 status_cb.Run(DECODER_ERROR_NOT_SUPPORTED); |
| 146 return; | 146 return; |
| 147 } | 147 } |
| 148 | 148 |
| 149 if (!IsProfileSupported(config.profile(), config.coded_size())) { | 149 if (!IsProfileSupported(config.profile(), config.coded_size())) { |
| 150 status_cb.Run(DECODER_ERROR_NOT_SUPPORTED); | 150 status_cb.Run(DECODER_ERROR_NOT_SUPPORTED); |
| 151 return; | 151 return; |
| 152 } | 152 } |
| 153 | 153 |
| 154 config_ = config; | 154 config_ = config; |
| 155 needs_bitstream_conversion_ = (config.codec() == kCodecH264); | 155 needs_bitstream_conversion_ = (config.codec() == kCodecH264); |
| 156 output_cb_ = BindToCurrentLoop(output_cb); | 156 output_cb_ = base::BindToCurrentLoop(output_cb); |
| 157 | 157 |
| 158 if (previously_initialized) { | 158 if (previously_initialized) { |
| 159 // Reinitialization with a different config (but same codec and profile). | 159 // Reinitialization with a different config (but same codec and profile). |
| 160 // VDA should handle it by detecting this in-stream by itself, | 160 // VDA should handle it by detecting this in-stream by itself, |
| 161 // no need to notify it. | 161 // no need to notify it. |
| 162 status_cb.Run(PIPELINE_OK); | 162 status_cb.Run(PIPELINE_OK); |
| 163 return; | 163 return; |
| 164 } | 164 } |
| 165 | 165 |
| 166 vda_ = factories_->CreateVideoDecodeAccelerator().Pass(); | 166 vda_ = factories_->CreateVideoDecodeAccelerator().Pass(); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 197 assigned_picture_buffers_.erase(it->first); | 197 assigned_picture_buffers_.erase(it->first); |
| 198 } | 198 } |
| 199 DestroyPictureBuffers(&assigned_picture_buffers_); | 199 DestroyPictureBuffers(&assigned_picture_buffers_); |
| 200 } | 200 } |
| 201 | 201 |
| 202 void GpuVideoDecoder::Decode(const scoped_refptr<DecoderBuffer>& buffer, | 202 void GpuVideoDecoder::Decode(const scoped_refptr<DecoderBuffer>& buffer, |
| 203 const DecodeCB& decode_cb) { | 203 const DecodeCB& decode_cb) { |
| 204 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); | 204 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); |
| 205 DCHECK(pending_reset_cb_.is_null()); | 205 DCHECK(pending_reset_cb_.is_null()); |
| 206 | 206 |
| 207 DecodeCB bound_decode_cb = BindToCurrentLoop(decode_cb); | 207 DecodeCB bound_decode_cb = base::BindToCurrentLoop(decode_cb); |
| 208 | 208 |
| 209 if (state_ == kError || !vda_) { | 209 if (state_ == kError || !vda_) { |
| 210 bound_decode_cb.Run(kDecodeError); | 210 bound_decode_cb.Run(kDecodeError); |
| 211 return; | 211 return; |
| 212 } | 212 } |
| 213 | 213 |
| 214 switch (state_) { | 214 switch (state_) { |
| 215 case kDecoderDrained: | 215 case kDecoderDrained: |
| 216 state_ = kNormal; | 216 state_ = kNormal; |
| 217 // Fall-through. | 217 // Fall-through. |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 // use config information instead. | 395 // use config information instead. |
| 396 gfx::Rect visible_rect; | 396 gfx::Rect visible_rect; |
| 397 gfx::Size natural_size; | 397 gfx::Size natural_size; |
| 398 GetBufferData(picture.bitstream_buffer_id(), ×tamp, &visible_rect, | 398 GetBufferData(picture.bitstream_buffer_id(), ×tamp, &visible_rect, |
| 399 &natural_size); | 399 &natural_size); |
| 400 DCHECK(decoder_texture_target_); | 400 DCHECK(decoder_texture_target_); |
| 401 | 401 |
| 402 scoped_refptr<VideoFrame> frame(VideoFrame::WrapNativeTexture( | 402 scoped_refptr<VideoFrame> frame(VideoFrame::WrapNativeTexture( |
| 403 make_scoped_ptr(new gpu::MailboxHolder( | 403 make_scoped_ptr(new gpu::MailboxHolder( |
| 404 pb.texture_mailbox(), decoder_texture_target_, 0 /* sync_point */)), | 404 pb.texture_mailbox(), decoder_texture_target_, 0 /* sync_point */)), |
| 405 BindToCurrentLoop(base::Bind( | 405 base::BindToCurrentLoop(base::Bind( |
| 406 &GpuVideoDecoder::ReleaseMailbox, weak_factory_.GetWeakPtr(), | 406 &GpuVideoDecoder::ReleaseMailbox, weak_factory_.GetWeakPtr(), |
| 407 factories_, picture.picture_buffer_id(), pb.texture_id())), | 407 factories_, picture.picture_buffer_id(), pb.texture_id())), |
| 408 pb.size(), visible_rect, natural_size, timestamp, | 408 pb.size(), visible_rect, natural_size, timestamp, |
| 409 picture.allow_overlay())); | 409 picture.allow_overlay())); |
| 410 CHECK_GT(available_pictures_, 0); | 410 CHECK_GT(available_pictures_, 0); |
| 411 --available_pictures_; | 411 --available_pictures_; |
| 412 bool inserted = | 412 bool inserted = |
| 413 picture_buffers_at_display_.insert(std::make_pair( | 413 picture_buffers_at_display_.insert(std::make_pair( |
| 414 picture.picture_buffer_id(), | 414 picture.picture_buffer_id(), |
| 415 pb.texture_id())).second; | 415 pb.texture_id())).second; |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 } | 584 } |
| 585 return false; | 585 return false; |
| 586 } | 586 } |
| 587 | 587 |
| 588 void GpuVideoDecoder::DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent() | 588 void GpuVideoDecoder::DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent() |
| 589 const { | 589 const { |
| 590 DCHECK(factories_->GetTaskRunner()->BelongsToCurrentThread()); | 590 DCHECK(factories_->GetTaskRunner()->BelongsToCurrentThread()); |
| 591 } | 591 } |
| 592 | 592 |
| 593 } // namespace media | 593 } // namespace media |
| OLD | NEW |