1 // Copyright 2018 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "media/renderers/default_decoder_factory.h"
9 #include "base/command_line.h"
10 #include "base/feature_list.h"
11 #include "base/task/sequenced_task_runner.h"
12 #include "build/build_config.h"
13 #include "build/buildflag.h"
14 #include "components/viz/common/gpu/raster_context_provider.h"
15 #include "media/base/decoder_factory.h"
16 #include "media/base/media_log.h"
17 #include "media/base/media_switches.h"
18 #include "media/media_buildflags.h"
19 #include "media/video/gpu_video_accelerator_factories.h"
21 #if !BUILDFLAG(IS_ANDROID)
22 #include "media/filters/decrypting_audio_decoder.h"
23 #include "media/filters/decrypting_video_decoder.h"
26 #if BUILDFLAG(ENABLE_DAV1D_DECODER)
27 #include "media/filters/dav1d_video_decoder.h"
30 #if BUILDFLAG(ENABLE_FFMPEG)
31 #include "media/filters/ffmpeg_audio_decoder.h"
34 #if BUILDFLAG(ENABLE_PLATFORM_DTS_AUDIO)
35 #include "media/filters/passthrough_dts_audio_decoder.h"
36 #endif // BUILDFLAG(ENABLE_PLATFORM_DTS_AUDIO)
38 #if BUILDFLAG(ENABLE_FFMPEG_VIDEO_DECODERS)
39 #include "media/filters/ffmpeg_video_decoder.h"
42 #if BUILDFLAG(ENABLE_LIBVPX)
43 #include "media/filters/vpx_video_decoder.h"
48 DefaultDecoderFactory::DefaultDecoderFactory(
49 std::unique_ptr<DecoderFactory> external_decoder_factory)
50 : external_decoder_factory_(std::move(external_decoder_factory)) {}
52 DefaultDecoderFactory::~DefaultDecoderFactory() = default;
54 void DefaultDecoderFactory::CreateAudioDecoders(
55 scoped_refptr<base::SequencedTaskRunner> task_runner,
57 std::vector<std::unique_ptr<AudioDecoder>>* audio_decoders) {
58 base::AutoLock auto_lock(shutdown_lock_);
62 #if !BUILDFLAG(IS_ANDROID)
63 // DecryptingAudioDecoder is only needed in External Clear Key testing to
64 // cover the audio decrypt-and-decode path.
65 if (base::FeatureList::IsEnabled(kExternalClearKeyForTesting)) {
66 audio_decoders->push_back(
67 std::make_unique<DecryptingAudioDecoder>(task_runner, media_log));
71 #if BUILDFLAG(ENABLE_PLATFORM_DTS_AUDIO) && BUILDFLAG(IS_WIN)
72 audio_decoders->push_back(
73 std::make_unique<PassthroughDTSAudioDecoder>(task_runner, media_log));
74 #endif // BUILDFLAG(ENABLE_PLATFORM_DTS_AUDIO) && BUILDFLAG(IS_WIN)
76 #if BUILDFLAG(ENABLE_FFMPEG)
77 audio_decoders->push_back(
78 std::make_unique<FFmpegAudioDecoder>(task_runner, media_log));
81 if (external_decoder_factory_) {
82 external_decoder_factory_->CreateAudioDecoders(task_runner, media_log,
87 void DefaultDecoderFactory::CreateVideoDecoders(
88 scoped_refptr<base::SequencedTaskRunner> task_runner,
89 GpuVideoAcceleratorFactories* gpu_factories,
91 RequestOverlayInfoCB request_overlay_info_cb,
92 const gfx::ColorSpace& target_color_space,
93 std::vector<std::unique_ptr<VideoDecoder>>* video_decoders) {
94 base::AutoLock auto_lock(shutdown_lock_);
99 #if !BUILDFLAG(IS_ANDROID)
100 video_decoders->push_back(
101 std::make_unique<DecryptingVideoDecoder>(task_runner, media_log));
104 // Perfer an external decoder since one will only exist if it is hardware
106 if (external_decoder_factory_ && gpu_factories &&
107 gpu_factories->IsGpuVideoDecodeAcceleratorEnabled()) {
108 // |gpu_factories_| requires that its entry points be called on its
109 // |GetTaskRunner()|. Since |pipeline_| will own decoders created from the
110 // factories, require that their message loops are identical.
111 DCHECK_EQ(gpu_factories->GetTaskRunner(), task_runner);
113 external_decoder_factory_->CreateVideoDecoders(
114 task_runner, gpu_factories, media_log,
115 std::move(request_overlay_info_cb), target_color_space, video_decoders);
118 #if BUILDFLAG(ENABLE_LIBVPX)
119 video_decoders->push_back(std::make_unique<OffloadingVpxVideoDecoder>());
122 #if BUILDFLAG(ENABLE_DAV1D_DECODER)
123 video_decoders->push_back(
124 std::make_unique<OffloadingDav1dVideoDecoder>(media_log->Clone()));
127 #if BUILDFLAG(ENABLE_FFMPEG_VIDEO_DECODERS)
128 video_decoders->push_back(std::make_unique<FFmpegVideoDecoder>(media_log));
132 base::WeakPtr<DecoderFactory> DefaultDecoderFactory::GetWeakPtr() {
133 return weak_factory_.GetWeakPtr();
136 void DefaultDecoderFactory::Shutdown() {
137 base::AutoLock auto_lock(shutdown_lock_);
138 external_decoder_factory_.reset();