-
Notifications
You must be signed in to change notification settings - Fork 0
/
media_context.cc
82 lines (67 loc) · 2.79 KB
/
media_context.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Copyright (c) 2017 YuTeh Shen
//
#include "chromium_media_lib/media_context.h"
#include "base/lazy_instance.h"
#include "base/memory/ptr_util.h"
#include "base/sys_info.h"
#include "base/threading/thread_local.h"
#include "chromium_media_lib/media_internals.h"
#include "media/audio/audio_system_impl.h"
#include "media/audio/audio_thread_impl.h"
namespace media {
namespace {
static base::LazyInstance<MediaContext>::DestructorAtExit g_context =
LAZY_INSTANCE_INITIALIZER;
}
MediaContext* MediaContext::Get() {
return g_context.Pointer();
}
MediaContext::MediaContext() : io_thread_(new base::Thread("Media IO")) {
io_thread_->Start();
audio_message_filter_ = new AudioMessageFilter(io_thread_->task_runner());
decoder_factory_.reset(new DecoderFactory());
audio_manager_ = AudioManager::Create(
base::MakeUnique<media::AudioThreadImpl>(),
MediaInternals::GetInstance());
CHECK(audio_manager_);
audio_system_ = media::AudioSystemImpl::Create(audio_manager_.get());
audio_renderer_host_ = base::MakeUnique<AudioRendererHost>(
audio_manager_.get(), audio_system_.get(), audio_message_filter_.get());
CHECK(audio_system_);
}
MediaContext::~MediaContext() {}
DecoderFactory* MediaContext::GetDecoderFactory() {
return decoder_factory_.get();
}
AudioRendererMixerManager* MediaContext::GetAudioRendererMixerManager() {
if (!audio_renderer_mixer_manager_) {
audio_renderer_mixer_manager_ = AudioRendererMixerManager::Create();
}
return audio_renderer_mixer_manager_.get();
}
std::unique_ptr<base::TaskScheduler::InitParams>
MediaContext::GetDefaultTaskSchedulerInitParams() {
// Reference GetDefaultTaskSchedulerInitParams
// from content/renderer/render_process_impl.cc
constexpr int kMaxNumThreadsInBackgroundPool = 1;
constexpr int kMaxNumThreadsInBackgroundBlockingPool = 1;
constexpr int kMaxNumThreadsInForegroundPoolLowerBound = 2;
constexpr int kMaxNumThreadsInForegroundBlockingPool = 1;
constexpr auto kSuggestedReclaimTime = base::TimeDelta::FromSeconds(30);
return base::MakeUnique<base::TaskScheduler::InitParams>(
base::SchedulerWorkerPoolParams(kMaxNumThreadsInBackgroundPool,
kSuggestedReclaimTime),
base::SchedulerWorkerPoolParams(kMaxNumThreadsInBackgroundBlockingPool,
kSuggestedReclaimTime),
base::SchedulerWorkerPoolParams(
std::max(
kMaxNumThreadsInForegroundPoolLowerBound,
base::SysInfo::NumberOfProcessors()),
kSuggestedReclaimTime),
base::SchedulerWorkerPoolParams(kMaxNumThreadsInForegroundBlockingPool,
kSuggestedReclaimTime));
}
base::SingleThreadTaskRunner* MediaContext::io_task_runner() const {
return io_thread_->task_runner().get();
}
} // namespace media