OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
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 "chromecast/media/audio/cast_audio_manager.h" | |
6 | |
7 #include "chromecast/base/task_runner_impl.h" | |
8 #include "chromecast/media/audio/cast_audio_output_stream.h" | |
9 #include "chromecast/public/cast_media_shlib.h" | |
10 #include "chromecast/public/media/media_pipeline_backend.h" | |
11 #include "chromecast/public/media/media_pipeline_device_params.h" | |
12 | |
13 namespace { | |
14 const int kDefaultSampleRate = 48000; | |
DaleCurtis
2015/09/18 22:42:36
You'll probably want to tailor this for your whate
alokp
2015/09/19 03:47:10
Added TODO to query from media backend.
| |
15 | |
16 // Define bounds for the output buffer size (in frames). | |
17 // Note: These values are copied from AudioManagerPulse implementation. | |
18 static const int kMinimumOutputBufferSize = 512; | |
DaleCurtis
2015/09/18 22:42:36
Up to you if you need these; again whatever the si
alokp
2015/09/19 03:47:10
Ditto. Thanks for your suggestion.
| |
19 static const int kMaximumOutputBufferSize = 8192; | |
20 static const int kDefaultOutputBufferSize = 2048; | |
21 } // namespace | |
22 | |
23 namespace chromecast { | |
24 namespace media { | |
25 | |
26 CastAudioManager::CastAudioManager(::media::AudioLogFactory* audio_log_factory) | |
27 : AudioManagerBase(audio_log_factory) {} | |
28 | |
29 CastAudioManager::~CastAudioManager() { | |
30 Shutdown(); | |
31 } | |
32 | |
33 bool CastAudioManager::HasAudioOutputDevices() { | |
34 return true; | |
35 } | |
36 | |
37 bool CastAudioManager::HasAudioInputDevices() { | |
38 return false; | |
39 } | |
40 | |
41 void CastAudioManager::ShowAudioInputSettings() { | |
42 LOG(WARNING) << "No support for input audio devices"; | |
43 } | |
44 | |
45 void CastAudioManager::GetAudioInputDeviceNames( | |
46 ::media::AudioDeviceNames* device_names) { | |
47 DCHECK(device_names->empty()); | |
48 LOG(WARNING) << "No support for input audio devices"; | |
49 } | |
50 | |
51 ::media::AudioParameters CastAudioManager::GetInputStreamParameters( | |
52 const std::string& device_id) { | |
53 LOG(WARNING) << "No support for input audio devices"; | |
54 // Need to send a valid AudioParameters object even when it will unused. | |
55 return ::media::AudioParameters( | |
56 ::media::AudioParameters::AUDIO_PCM_LOW_LATENCY, | |
57 ::media::CHANNEL_LAYOUT_STEREO, 48000, 16, 1024); | |
58 } | |
59 | |
60 scoped_ptr<MediaPipelineBackend> | |
61 CastAudioManager::CreateMediaPipelineBackend() { | |
62 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); | |
63 | |
64 if (!audio_task_runner_) | |
65 audio_task_runner_.reset(new TaskRunnerImpl()); | |
66 | |
67 MediaPipelineDeviceParams device_params( | |
68 MediaPipelineDeviceParams::kModeIgnorePts, audio_task_runner_.get()); | |
69 return scoped_ptr<MediaPipelineBackend>( | |
70 CastMediaShlib::CreateMediaPipelineBackend(device_params)); | |
71 } | |
72 | |
73 ::media::AudioOutputStream* CastAudioManager::MakeLinearOutputStream( | |
74 const ::media::AudioParameters& params) { | |
75 DCHECK_EQ(::media::AudioParameters::AUDIO_PCM_LINEAR, params.format()); | |
76 return new CastAudioOutputStream(params, this); | |
77 } | |
78 | |
79 ::media::AudioOutputStream* CastAudioManager::MakeLowLatencyOutputStream( | |
80 const ::media::AudioParameters& params, | |
81 const std::string& device_id) { | |
82 DCHECK_EQ(::media::AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format()); | |
83 return new CastAudioOutputStream(params, this); | |
84 } | |
85 | |
86 ::media::AudioInputStream* CastAudioManager::MakeLinearInputStream( | |
87 const ::media::AudioParameters& params, | |
88 const std::string& device_id) { | |
89 LOG(WARNING) << "No support for input audio devices"; | |
90 return nullptr; | |
91 } | |
92 | |
93 ::media::AudioInputStream* CastAudioManager::MakeLowLatencyInputStream( | |
94 const ::media::AudioParameters& params, | |
95 const std::string& device_id) { | |
96 LOG(WARNING) << "No support for input audio devices"; | |
97 return nullptr; | |
98 } | |
99 | |
100 ::media::AudioParameters CastAudioManager::GetPreferredOutputStreamParameters( | |
101 const std::string& output_device_id, | |
102 const ::media::AudioParameters& input_params) { | |
103 ::media::ChannelLayout channel_layout = ::media::CHANNEL_LAYOUT_STEREO; | |
104 int sample_rate = kDefaultSampleRate; | |
105 int buffer_size = kDefaultOutputBufferSize; | |
106 int bits_per_sample = 16; | |
107 if (input_params.IsValid()) { | |
108 // Do not change: | |
109 // - the channel layout | |
110 // - the number of bits per sample | |
111 // We support stereo only with 16 bits per sample. | |
112 sample_rate = input_params.sample_rate(); | |
113 buffer_size = std::min( | |
114 kMaximumOutputBufferSize, | |
115 std::max(kMinimumOutputBufferSize, input_params.frames_per_buffer())); | |
116 } | |
117 | |
118 ::media::AudioParameters output_params( | |
119 ::media::AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, | |
120 sample_rate, bits_per_sample, buffer_size); | |
121 return output_params; | |
122 } | |
123 | |
124 } // namespace media | |
125 } // namespace chromecast | |
OLD | NEW |