| 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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 | 98 |
| 99 static bool IsCodedSizeSupported(const gfx::Size& coded_size, | 99 static bool IsCodedSizeSupported(const gfx::Size& coded_size, |
| 100 const gfx::Size& min_resolution, | 100 const gfx::Size& min_resolution, |
| 101 const gfx::Size& max_resolution) { | 101 const gfx::Size& max_resolution) { |
| 102 return (coded_size.width() <= max_resolution.width() && | 102 return (coded_size.width() <= max_resolution.width() && |
| 103 coded_size.height() <= max_resolution.height() && | 103 coded_size.height() <= max_resolution.height() && |
| 104 coded_size.width() >= min_resolution.width() && | 104 coded_size.width() >= min_resolution.width() && |
| 105 coded_size.height() >= min_resolution.height()); | 105 coded_size.height() >= min_resolution.height()); |
| 106 } | 106 } |
| 107 | 107 |
| 108 // Report |status| to UMA and run |cb| with it. This is super-specific to the | 108 // Report |success| to UMA and run |cb| with it. This is super-specific to the |
| 109 // UMA stat reported because the UMA_HISTOGRAM_ENUMERATION API requires a | 109 // UMA stat reported because the UMA_HISTOGRAM_ENUMERATION API requires a |
| 110 // callsite to always be called with the same stat name (can't parameterize it). | 110 // callsite to always be called with the same stat name (can't parameterize it). |
| 111 static void ReportGpuVideoDecoderInitializeStatusToUMAAndRunCB( | 111 static void ReportGpuVideoDecoderInitializeStatusToUMAAndRunCB( |
| 112 const PipelineStatusCB& cb, | 112 const VideoDecoder::InitCB& cb, |
| 113 PipelineStatus status) { | 113 bool success) { |
| 114 // TODO(xhwang): Report |success| directly. |
| 115 PipelineStatus status = success ? PIPELINE_OK : DECODER_ERROR_NOT_SUPPORTED; |
| 114 UMA_HISTOGRAM_ENUMERATION( | 116 UMA_HISTOGRAM_ENUMERATION( |
| 115 "Media.GpuVideoDecoderInitializeStatus", status, PIPELINE_STATUS_MAX + 1); | 117 "Media.GpuVideoDecoderInitializeStatus", status, PIPELINE_STATUS_MAX + 1); |
| 116 cb.Run(status); | 118 cb.Run(success); |
| 117 } | 119 } |
| 118 | 120 |
| 119 std::string GpuVideoDecoder::GetDisplayName() const { | 121 std::string GpuVideoDecoder::GetDisplayName() const { |
| 120 return kDecoderName; | 122 return kDecoderName; |
| 121 } | 123 } |
| 122 | 124 |
| 123 void GpuVideoDecoder::Initialize(const VideoDecoderConfig& config, | 125 void GpuVideoDecoder::Initialize(const VideoDecoderConfig& config, |
| 124 bool /* low_delay */, | 126 bool /* low_delay */, |
| 125 const PipelineStatusCB& orig_status_cb, | 127 const InitCB& init_cb, |
| 126 const OutputCB& output_cb) { | 128 const OutputCB& output_cb) { |
| 127 DVLOG(3) << "Initialize()"; | 129 DVLOG(3) << "Initialize()"; |
| 128 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); | 130 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); |
| 129 DCHECK(config.IsValidConfig()); | 131 DCHECK(config.IsValidConfig()); |
| 130 DCHECK(!config.is_encrypted()); | 132 DCHECK(!config.is_encrypted()); |
| 131 | 133 |
| 132 PipelineStatusCB status_cb = | 134 InitCB bound_init_cb = |
| 133 base::Bind(&ReportGpuVideoDecoderInitializeStatusToUMAAndRunCB, | 135 base::Bind(&ReportGpuVideoDecoderInitializeStatusToUMAAndRunCB, |
| 134 BindToCurrentLoop(orig_status_cb)); | 136 BindToCurrentLoop(init_cb)); |
| 135 | 137 |
| 136 bool previously_initialized = config_.IsValidConfig(); | 138 bool previously_initialized = config_.IsValidConfig(); |
| 137 DVLOG(1) << "(Re)initializing GVD with config: " | 139 DVLOG(1) << "(Re)initializing GVD with config: " |
| 138 << config.AsHumanReadableString(); | 140 << config.AsHumanReadableString(); |
| 139 | 141 |
| 140 // TODO(posciak): destroy and create a new VDA on codec/profile change | 142 // TODO(posciak): destroy and create a new VDA on codec/profile change |
| 141 // (http://crbug.com/260224). | 143 // (http://crbug.com/260224). |
| 142 if (previously_initialized && (config_.profile() != config.profile())) { | 144 if (previously_initialized && (config_.profile() != config.profile())) { |
| 143 DVLOG(1) << "Codec or profile changed, cannot reinitialize."; | 145 DVLOG(1) << "Codec or profile changed, cannot reinitialize."; |
| 144 status_cb.Run(DECODER_ERROR_NOT_SUPPORTED); | 146 bound_init_cb.Run(false); |
| 145 return; | 147 return; |
| 146 } | 148 } |
| 147 | 149 |
| 148 if (!IsProfileSupported(config.profile(), config.coded_size())) { | 150 if (!IsProfileSupported(config.profile(), config.coded_size())) { |
| 149 status_cb.Run(DECODER_ERROR_NOT_SUPPORTED); | 151 bound_init_cb.Run(false); |
| 150 return; | 152 return; |
| 151 } | 153 } |
| 152 | 154 |
| 153 config_ = config; | 155 config_ = config; |
| 154 needs_bitstream_conversion_ = (config.codec() == kCodecH264); | 156 needs_bitstream_conversion_ = (config.codec() == kCodecH264); |
| 155 output_cb_ = BindToCurrentLoop(output_cb); | 157 output_cb_ = BindToCurrentLoop(output_cb); |
| 156 | 158 |
| 157 if (previously_initialized) { | 159 if (previously_initialized) { |
| 158 // Reinitialization with a different config (but same codec and profile). | 160 // Reinitialization with a different config (but same codec and profile). |
| 159 // VDA should handle it by detecting this in-stream by itself, | 161 // VDA should handle it by detecting this in-stream by itself, |
| 160 // no need to notify it. | 162 // no need to notify it. |
| 161 status_cb.Run(PIPELINE_OK); | 163 bound_init_cb.Run(true); |
| 162 return; | 164 return; |
| 163 } | 165 } |
| 164 | 166 |
| 165 vda_ = factories_->CreateVideoDecodeAccelerator().Pass(); | 167 vda_ = factories_->CreateVideoDecodeAccelerator().Pass(); |
| 166 if (!vda_ || !vda_->Initialize(config.profile(), this)) { | 168 if (!vda_ || !vda_->Initialize(config.profile(), this)) { |
| 167 status_cb.Run(DECODER_ERROR_NOT_SUPPORTED); | 169 bound_init_cb.Run(false); |
| 168 return; | 170 return; |
| 169 } | 171 } |
| 170 | 172 |
| 171 DVLOG(3) << "GpuVideoDecoder::Initialize() succeeded."; | 173 DVLOG(3) << "GpuVideoDecoder::Initialize() succeeded."; |
| 172 status_cb.Run(PIPELINE_OK); | 174 bound_init_cb.Run(true); |
| 173 } | 175 } |
| 174 | 176 |
| 175 void GpuVideoDecoder::DestroyPictureBuffers(PictureBufferMap* buffers) { | 177 void GpuVideoDecoder::DestroyPictureBuffers(PictureBufferMap* buffers) { |
| 176 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); | 178 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); |
| 177 for (PictureBufferMap::iterator it = buffers->begin(); it != buffers->end(); | 179 for (PictureBufferMap::iterator it = buffers->begin(); it != buffers->end(); |
| 178 ++it) { | 180 ++it) { |
| 179 factories_->DeleteTexture(it->second.texture_id()); | 181 factories_->DeleteTexture(it->second.texture_id()); |
| 180 } | 182 } |
| 181 | 183 |
| 182 buffers->clear(); | 184 buffers->clear(); |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 583 } | 585 } |
| 584 return false; | 586 return false; |
| 585 } | 587 } |
| 586 | 588 |
| 587 void GpuVideoDecoder::DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent() | 589 void GpuVideoDecoder::DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent() |
| 588 const { | 590 const { |
| 589 DCHECK(factories_->GetTaskRunner()->BelongsToCurrentThread()); | 591 DCHECK(factories_->GetTaskRunner()->BelongsToCurrentThread()); |
| 590 } | 592 } |
| 591 | 593 |
| 592 } // namespace media | 594 } // namespace media |
| OLD | NEW |