Upload upstream chromium 120.0.6099.5
[platform/framework/web/chromium-efl.git] / media / renderers / default_decoder_factory.cc
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.
4
5 #include "media/renderers/default_decoder_factory.h"
6
7 #include <memory>
8
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"
20
21 #if !BUILDFLAG(IS_ANDROID)
22 #include "media/filters/decrypting_audio_decoder.h"
23 #include "media/filters/decrypting_video_decoder.h"
24 #endif
25
26 #if BUILDFLAG(ENABLE_DAV1D_DECODER)
27 #include "media/filters/dav1d_video_decoder.h"
28 #endif
29
30 #if BUILDFLAG(ENABLE_FFMPEG)
31 #include "media/filters/ffmpeg_audio_decoder.h"
32 #endif
33
34 #if BUILDFLAG(ENABLE_PLATFORM_DTS_AUDIO)
35 #include "media/filters/passthrough_dts_audio_decoder.h"
36 #endif  // BUILDFLAG(ENABLE_PLATFORM_DTS_AUDIO)
37
38 #if BUILDFLAG(ENABLE_FFMPEG_VIDEO_DECODERS)
39 #include "media/filters/ffmpeg_video_decoder.h"
40 #endif
41
42 #if BUILDFLAG(ENABLE_LIBVPX)
43 #include "media/filters/vpx_video_decoder.h"
44 #endif
45
46 namespace media {
47
48 DefaultDecoderFactory::DefaultDecoderFactory(
49     std::unique_ptr<DecoderFactory> external_decoder_factory)
50     : external_decoder_factory_(std::move(external_decoder_factory)) {}
51
52 DefaultDecoderFactory::~DefaultDecoderFactory() = default;
53
54 void DefaultDecoderFactory::CreateAudioDecoders(
55     scoped_refptr<base::SequencedTaskRunner> task_runner,
56     MediaLog* media_log,
57     std::vector<std::unique_ptr<AudioDecoder>>* audio_decoders) {
58   base::AutoLock auto_lock(shutdown_lock_);
59   if (is_shutdown_)
60     return;
61
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));
68   }
69 #endif
70
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)
75
76 #if BUILDFLAG(ENABLE_FFMPEG)
77   audio_decoders->push_back(
78       std::make_unique<FFmpegAudioDecoder>(task_runner, media_log));
79 #endif
80
81   if (external_decoder_factory_) {
82     external_decoder_factory_->CreateAudioDecoders(task_runner, media_log,
83                                                    audio_decoders);
84   }
85 }
86
87 void DefaultDecoderFactory::CreateVideoDecoders(
88     scoped_refptr<base::SequencedTaskRunner> task_runner,
89     GpuVideoAcceleratorFactories* gpu_factories,
90     MediaLog* media_log,
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_);
95   if (is_shutdown_) {
96     return;
97   }
98
99 #if !BUILDFLAG(IS_ANDROID)
100   video_decoders->push_back(
101       std::make_unique<DecryptingVideoDecoder>(task_runner, media_log));
102 #endif
103
104   // Perfer an external decoder since one will only exist if it is hardware
105   // accelerated.
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);
112
113     external_decoder_factory_->CreateVideoDecoders(
114         task_runner, gpu_factories, media_log,
115         std::move(request_overlay_info_cb), target_color_space, video_decoders);
116   }
117
118 #if BUILDFLAG(ENABLE_LIBVPX)
119   video_decoders->push_back(std::make_unique<OffloadingVpxVideoDecoder>());
120 #endif
121
122 #if BUILDFLAG(ENABLE_DAV1D_DECODER)
123   video_decoders->push_back(
124       std::make_unique<OffloadingDav1dVideoDecoder>(media_log->Clone()));
125 #endif
126
127 #if BUILDFLAG(ENABLE_FFMPEG_VIDEO_DECODERS)
128   video_decoders->push_back(std::make_unique<FFmpegVideoDecoder>(media_log));
129 #endif
130 }
131
132 base::WeakPtr<DecoderFactory> DefaultDecoderFactory::GetWeakPtr() {
133   return weak_factory_.GetWeakPtr();
134 }
135
136 void DefaultDecoderFactory::Shutdown() {
137   base::AutoLock auto_lock(shutdown_lock_);
138   external_decoder_factory_.reset();
139   is_shutdown_ = true;
140 }
141
142 }  // namespace media