| 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 #include <array> | 8 #include <array> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 #include "media/base/surface_manager.h" | 30 #include "media/base/surface_manager.h" |
| 31 #include "media/base/video_decoder_config.h" | 31 #include "media/base/video_decoder_config.h" |
| 32 #include "media/media_features.h" | 32 #include "media/media_features.h" |
| 33 #include "media/renderers/gpu_video_accelerator_factories.h" | 33 #include "media/renderers/gpu_video_accelerator_factories.h" |
| 34 #include "third_party/skia/include/core/SkBitmap.h" | 34 #include "third_party/skia/include/core/SkBitmap.h" |
| 35 | 35 |
| 36 #if BUILDFLAG(USE_PROPRIETARY_CODECS) | 36 #if BUILDFLAG(USE_PROPRIETARY_CODECS) |
| 37 #include "media/formats/mp4/box_definitions.h" | 37 #include "media/formats/mp4/box_definitions.h" |
| 38 #endif | 38 #endif |
| 39 | 39 |
| 40 #if defined(OS_ANDROID) | |
| 41 #include "base/android/build_info.h" | |
| 42 #endif | |
| 43 | |
| 44 namespace media { | 40 namespace media { |
| 45 namespace { | 41 namespace { |
| 46 | 42 |
| 47 // Size of shared-memory segments we allocate. Since we reuse them we let them | 43 // Size of shared-memory segments we allocate. Since we reuse them we let them |
| 48 // be on the beefy side. | 44 // be on the beefy side. |
| 49 static const size_t kSharedMemorySegmentBytes = 100 << 10; | 45 static const size_t kSharedMemorySegmentBytes = 100 << 10; |
| 50 | 46 |
| 51 #if defined(OS_ANDROID) && BUILDFLAG(USE_PROPRIETARY_CODECS) | 47 #if defined(OS_ANDROID) && BUILDFLAG(USE_PROPRIETARY_CODECS) |
| 52 // Extract the SPS and PPS lists from |extra_data|. Each SPS and PPS is prefixed | 48 // Extract the SPS and PPS lists from |extra_data|. Each SPS and PPS is prefixed |
| 53 // with 0x0001, the Annex B framing bytes. The out parameters are not modified | 49 // with 0x0001, the Annex B framing bytes. The out parameters are not modified |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 const InitCB& init_cb, | 208 const InitCB& init_cb, |
| 213 const OutputCB& output_cb) { | 209 const OutputCB& output_cb) { |
| 214 DVLOG(3) << "Initialize()"; | 210 DVLOG(3) << "Initialize()"; |
| 215 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); | 211 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); |
| 216 DCHECK(config.IsValidConfig()); | 212 DCHECK(config.IsValidConfig()); |
| 217 | 213 |
| 218 InitCB bound_init_cb = | 214 InitCB bound_init_cb = |
| 219 base::Bind(&ReportGpuVideoDecoderInitializeStatusToUMAAndRunCB, | 215 base::Bind(&ReportGpuVideoDecoderInitializeStatusToUMAAndRunCB, |
| 220 BindToCurrentLoop(init_cb), media_log_); | 216 BindToCurrentLoop(init_cb), media_log_); |
| 221 | 217 |
| 222 bool requires_restart_for_external_output_surface = false; | |
| 223 #if !defined(OS_ANDROID) | |
| 224 if (config.is_encrypted()) { | |
| 225 DVLOG(1) << "Encrypted stream not supported."; | |
| 226 bound_init_cb.Run(false); | |
| 227 return; | |
| 228 } | |
| 229 #else | |
| 230 requires_restart_for_external_output_surface = | |
| 231 base::android::BuildInfo::GetInstance()->sdk_int() < 23; | |
| 232 #endif | |
| 233 | |
| 234 bool previously_initialized = config_.IsValidConfig(); | 218 bool previously_initialized = config_.IsValidConfig(); |
| 235 DVLOG(1) << (previously_initialized ? "Reinitializing" : "Initializing") | 219 DVLOG(1) << (previously_initialized ? "Reinitializing" : "Initializing") |
| 236 << " GVD with config: " << config.AsHumanReadableString(); | 220 << " GVD with config: " << config.AsHumanReadableString(); |
| 237 | 221 |
| 238 // Disallow codec changes between configuration changes. | 222 // Disallow codec changes between configuration changes. |
| 239 if (previously_initialized && config_.codec() != config.codec()) { | 223 if (previously_initialized && config_.codec() != config.codec()) { |
| 240 DVLOG(1) << "Codec changed, cannot reinitialize."; | 224 DVLOG(1) << "Codec changed, cannot reinitialize."; |
| 241 bound_init_cb.Run(false); | 225 bound_init_cb.Run(false); |
| 242 return; | 226 return; |
| 243 } | 227 } |
| 244 | 228 |
| 245 // TODO(sandersd): This should be moved to capabilities if we ever have a | 229 // TODO(sandersd): This should be moved to capabilities if we ever have a |
| 246 // hardware decoder which supports alpha formats. | 230 // hardware decoder which supports alpha formats. |
| 247 if (config.format() == PIXEL_FORMAT_YV12A) { | 231 if (config.format() == PIXEL_FORMAT_YV12A) { |
| 248 DVLOG(1) << "Alpha transparency formats are not supported."; | 232 DVLOG(1) << "Alpha transparency formats are not supported."; |
| 249 bound_init_cb.Run(false); | 233 bound_init_cb.Run(false); |
| 250 return; | 234 return; |
| 251 } | 235 } |
| 252 | 236 |
| 253 VideoDecodeAccelerator::Capabilities capabilities = | 237 VideoDecodeAccelerator::Capabilities capabilities = |
| 254 factories_->GetVideoDecodeAcceleratorCapabilities(); | 238 factories_->GetVideoDecodeAcceleratorCapabilities(); |
| 239 if (config.is_encrypted() && |
| 240 !(capabilities.flags & |
| 241 VideoDecodeAccelerator::Capabilities::SUPPORTS_ENCRYPTED_STREAMS)) { |
| 242 DVLOG(1) << "Encrypted stream not supported."; |
| 243 bound_init_cb.Run(false); |
| 244 return; |
| 245 } |
| 246 |
| 255 if (!IsProfileSupported(capabilities, config.profile(), config.coded_size(), | 247 if (!IsProfileSupported(capabilities, config.profile(), config.coded_size(), |
| 256 config.is_encrypted())) { | 248 config.is_encrypted())) { |
| 257 DVLOG(1) << "Unsupported profile " << GetProfileName(config.profile()) | 249 DVLOG(1) << "Unsupported profile " << GetProfileName(config.profile()) |
| 258 << ", unsupported coded size " << config.coded_size().ToString() | 250 << ", unsupported coded size " << config.coded_size().ToString() |
| 259 << ", or accelerator should only be used for encrypted content. " | 251 << ", or accelerator should only be used for encrypted content. " |
| 260 << " is_encrypted: " << (config.is_encrypted() ? "yes." : "no."); | 252 << " is_encrypted: " << (config.is_encrypted() ? "yes." : "no."); |
| 261 bound_init_cb.Run(false); | 253 bound_init_cb.Run(false); |
| 262 return; | 254 return; |
| 263 } | 255 } |
| 264 | 256 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 // No need to store |cdm_context| since it's not needed in reinitialization. | 297 // No need to store |cdm_context| since it's not needed in reinitialization. |
| 306 if (cdm_id_ == CdmContext::kInvalidCdmId) { | 298 if (cdm_id_ == CdmContext::kInvalidCdmId) { |
| 307 DVLOG(1) << "CDM ID not available."; | 299 DVLOG(1) << "CDM ID not available."; |
| 308 bound_init_cb.Run(false); | 300 bound_init_cb.Run(false); |
| 309 return; | 301 return; |
| 310 } | 302 } |
| 311 } | 303 } |
| 312 | 304 |
| 313 init_cb_ = bound_init_cb; | 305 init_cb_ = bound_init_cb; |
| 314 | 306 |
| 315 const bool supports_external_output_surface = | 307 const bool supports_external_output_surface = !!( |
| 316 (capabilities.flags & VideoDecodeAccelerator::Capabilities:: | 308 capabilities.flags & |
| 317 SUPPORTS_EXTERNAL_OUTPUT_SURFACE) != 0; | 309 VideoDecodeAccelerator::Capabilities::SUPPORTS_EXTERNAL_OUTPUT_SURFACE); |
| 318 if (supports_external_output_surface && !request_surface_cb_.is_null()) { | 310 if (supports_external_output_surface && !request_surface_cb_.is_null()) { |
| 311 const bool requires_restart_for_external_output_surface = |
| 312 !(capabilities.flags & VideoDecodeAccelerator::Capabilities:: |
| 313 SUPPORTS_SET_EXTERNAL_OUTPUT_SURFACE); |
| 314 |
| 319 // If we have a surface request callback we should call it and complete | 315 // If we have a surface request callback we should call it and complete |
| 320 // initialization with the returned surface. | 316 // initialization with the returned surface. |
| 321 request_surface_cb_.Run( | 317 request_surface_cb_.Run( |
| 322 requires_restart_for_external_output_surface, | 318 requires_restart_for_external_output_surface, |
| 323 BindToCurrentLoop(base::Bind(&GpuVideoDecoder::OnSurfaceAvailable, | 319 BindToCurrentLoop(base::Bind(&GpuVideoDecoder::OnSurfaceAvailable, |
| 324 weak_factory_.GetWeakPtr()))); | 320 weak_factory_.GetWeakPtr()))); |
| 325 return; | 321 return; |
| 326 } | 322 } |
| 327 | 323 |
| 328 // If external surfaces are not supported we can complete initialization now. | 324 // If external surfaces are not supported we can complete initialization now. |
| (...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 912 } | 908 } |
| 913 return false; | 909 return false; |
| 914 } | 910 } |
| 915 | 911 |
| 916 void GpuVideoDecoder::DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent() | 912 void GpuVideoDecoder::DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent() |
| 917 const { | 913 const { |
| 918 DCHECK(factories_->GetTaskRunner()->BelongsToCurrentThread()); | 914 DCHECK(factories_->GetTaskRunner()->BelongsToCurrentThread()); |
| 919 } | 915 } |
| 920 | 916 |
| 921 } // namespace media | 917 } // namespace media |
| OLD | NEW |