Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: chromecast/media/audio/cast_audio_manager.cc

Issue 2879703003: [chromecast] Moves CastAudioOutputStream::Backend to CMA thread. (Closed)
Patch Set: addressed comments Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 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 "chromecast/media/audio/cast_audio_manager.h" 5 #include "chromecast/media/audio/cast_audio_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/memory/ptr_util.h"
11 #include "chromecast/media/audio/cast_audio_mixer.h" 12 #include "chromecast/media/audio/cast_audio_mixer.h"
12 #include "chromecast/media/audio/cast_audio_output_stream.h" 13 #include "chromecast/media/audio/cast_audio_output_stream.h"
13 #include "chromecast/media/cma/backend/media_pipeline_backend_manager.h" 14 #include "chromecast/media/cma/backend/media_pipeline_backend_factory.h"
15 #include "chromecast/public/media/media_pipeline_backend.h"
14 16
15 namespace { 17 namespace {
16 // TODO(alokp): Query the preferred value from media backend. 18 // TODO(alokp): Query the preferred value from media backend.
17 const int kDefaultSampleRate = 48000; 19 const int kDefaultSampleRate = 48000;
18 20
19 // Define bounds for the output buffer size (in frames). 21 // Define bounds for the output buffer size (in frames).
20 // Note: These values are copied from AudioManagerPulse implementation. 22 // Note: These values are copied from AudioManagerPulse implementation.
21 // TODO(alokp): Query the preferred value from media backend. 23 // TODO(alokp): Query the preferred value from media backend.
22 static const int kMinimumOutputBufferSize = 512; 24 static const int kMinimumOutputBufferSize = 512;
23 static const int kMaximumOutputBufferSize = 8192; 25 static const int kMaximumOutputBufferSize = 8192;
24 static const int kDefaultOutputBufferSize = 2048; 26 static const int kDefaultOutputBufferSize = 2048;
25 } // namespace 27 } // namespace
26 28
27 namespace chromecast { 29 namespace chromecast {
28 namespace media { 30 namespace media {
29 31
30 CastAudioManager::CastAudioManager( 32 CastAudioManager::CastAudioManager(
31 std::unique_ptr<::media::AudioThread> audio_thread, 33 std::unique_ptr<::media::AudioThread> audio_thread,
32 ::media::AudioLogFactory* audio_log_factory, 34 ::media::AudioLogFactory* audio_log_factory,
33 MediaPipelineBackendManager* backend_manager) 35 std::unique_ptr<MediaPipelineBackendFactory> backend_factory,
34 : CastAudioManager(std::move(audio_thread), 36 scoped_refptr<base::SingleThreadTaskRunner> backend_task_runner,
35 audio_log_factory, 37 bool use_mixer)
36 backend_manager,
37 new CastAudioMixer(
38 base::Bind(&CastAudioManager::MakeMixerOutputStream,
39 base::Unretained(this)))) {}
40
41 CastAudioManager::CastAudioManager(
42 std::unique_ptr<::media::AudioThread> audio_thread,
43 ::media::AudioLogFactory* audio_log_factory,
44 MediaPipelineBackendManager* backend_manager,
45 CastAudioMixer* audio_mixer)
46 : AudioManagerBase(std::move(audio_thread), audio_log_factory), 38 : AudioManagerBase(std::move(audio_thread), audio_log_factory),
47 backend_manager_(backend_manager), 39 backend_factory_(std::move(backend_factory)),
48 mixer_(audio_mixer) {} 40 backend_task_runner_(std::move(backend_task_runner)) {
41 if (use_mixer)
42 mixer_ = base::MakeUnique<CastAudioMixer>(this);
43 }
49 44
50 CastAudioManager::~CastAudioManager() = default; 45 CastAudioManager::~CastAudioManager() = default;
51 46
52 bool CastAudioManager::HasAudioOutputDevices() { 47 bool CastAudioManager::HasAudioOutputDevices() {
53 return true; 48 return true;
54 } 49 }
55 50
56 bool CastAudioManager::HasAudioInputDevices() { 51 bool CastAudioManager::HasAudioInputDevices() {
57 return false; 52 return false;
58 } 53 }
(...skipping 14 matching lines...) Expand all
73 // Need to send a valid AudioParameters object even when it will unused. 68 // Need to send a valid AudioParameters object even when it will unused.
74 return ::media::AudioParameters( 69 return ::media::AudioParameters(
75 ::media::AudioParameters::AUDIO_PCM_LOW_LATENCY, 70 ::media::AudioParameters::AUDIO_PCM_LOW_LATENCY,
76 ::media::CHANNEL_LAYOUT_STEREO, 48000, 16, 1024); 71 ::media::CHANNEL_LAYOUT_STEREO, 48000, 16, 1024);
77 } 72 }
78 73
79 const char* CastAudioManager::GetName() { 74 const char* CastAudioManager::GetName() {
80 return "Cast"; 75 return "Cast";
81 } 76 }
82 77
83 std::unique_ptr<MediaPipelineBackend>
84 CastAudioManager::CreateMediaPipelineBackend(
85 const MediaPipelineDeviceParams& params) {
86 return backend_manager_->CreateMediaPipelineBackend(params);
87 }
88
89 void CastAudioManager::ReleaseOutputStream(::media::AudioOutputStream* stream) { 78 void CastAudioManager::ReleaseOutputStream(::media::AudioOutputStream* stream) {
90 // If |stream| is |mixer_output_stream_|, we should not use 79 // If |stream| is |mixer_output_stream_|, we should not use
91 // AudioManagerBase::ReleaseOutputStream as we do not want the release 80 // AudioManagerBase::ReleaseOutputStream as we do not want the release
92 // function to decrement |AudioManagerBase::num_output_streams_|. This is 81 // function to decrement |AudioManagerBase::num_output_streams_|. This is
93 // because the stream generated from MakeMixerOutputStream was not created 82 // because the stream generated from MakeMixerOutputStream was not created
94 // using AudioManagerBase::MakeAudioOutputStream, which appropriately 83 // using AudioManagerBase::MakeAudioOutputStream, which appropriately
95 // increments this variable. 84 // increments this variable.
96 if (mixer_output_stream_.get() == stream) { 85 if (mixer_output_stream_.get() == stream) {
97 DCHECK(mixer_); // Should only occur if |mixer_| exists 86 DCHECK(mixer_); // Should only occur if |mixer_| exists
98 mixer_output_stream_.reset(); 87 mixer_output_stream_.reset();
99 } else { 88 } else {
100 AudioManagerBase::ReleaseOutputStream(stream); 89 AudioManagerBase::ReleaseOutputStream(stream);
101 } 90 }
102 } 91 }
103 92
104 ::media::AudioOutputStream* CastAudioManager::MakeLinearOutputStream( 93 ::media::AudioOutputStream* CastAudioManager::MakeLinearOutputStream(
105 const ::media::AudioParameters& params, 94 const ::media::AudioParameters& params,
106 const ::media::AudioManager::LogCallback& log_callback) { 95 const ::media::AudioManager::LogCallback& log_callback) {
107 DCHECK_EQ(::media::AudioParameters::AUDIO_PCM_LINEAR, params.format()); 96 DCHECK_EQ(::media::AudioParameters::AUDIO_PCM_LINEAR, params.format());
108 97
109 // If |mixer_| exists, return a mixing stream. 98 // If |mixer_| exists, return a mixing stream.
110 if (mixer_) 99 if (mixer_)
111 return mixer_->MakeStream(params, this); 100 return mixer_->MakeStream(params);
112 else 101 else
113 return new CastAudioOutputStream(params, this); 102 return new CastAudioOutputStream(params, this);
114 } 103 }
115 104
116 ::media::AudioOutputStream* CastAudioManager::MakeLowLatencyOutputStream( 105 ::media::AudioOutputStream* CastAudioManager::MakeLowLatencyOutputStream(
117 const ::media::AudioParameters& params, 106 const ::media::AudioParameters& params,
118 const std::string& device_id, 107 const std::string& device_id,
119 const ::media::AudioManager::LogCallback& log_callback) { 108 const ::media::AudioManager::LogCallback& log_callback) {
120 DCHECK_EQ(::media::AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format()); 109 DCHECK_EQ(::media::AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format());
121 110
122 // If |mixer_| exists, return a mixing stream. 111 // If |mixer_| exists, return a mixing stream.
123 if (mixer_) 112 if (mixer_)
124 return mixer_->MakeStream(params, this); 113 return mixer_->MakeStream(params);
125 else 114 else
126 return new CastAudioOutputStream(params, this); 115 return new CastAudioOutputStream(params, this);
127 } 116 }
128 117
129 ::media::AudioInputStream* CastAudioManager::MakeLinearInputStream( 118 ::media::AudioInputStream* CastAudioManager::MakeLinearInputStream(
130 const ::media::AudioParameters& params, 119 const ::media::AudioParameters& params,
131 const std::string& device_id, 120 const std::string& device_id,
132 const ::media::AudioManager::LogCallback& log_callback) { 121 const ::media::AudioManager::LogCallback& log_callback) {
133 LOG(WARNING) << "No support for input audio devices"; 122 LOG(WARNING) << "No support for input audio devices";
134 return nullptr; 123 return nullptr;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 DCHECK(!mixer_output_stream_); // Only allow 1 |mixer_output_stream_|. 161 DCHECK(!mixer_output_stream_); // Only allow 1 |mixer_output_stream_|.
173 162
174 // Keep a reference to this stream for proper behavior on 163 // Keep a reference to this stream for proper behavior on
175 // CastAudioManager::ReleaseOutputStream. 164 // CastAudioManager::ReleaseOutputStream.
176 mixer_output_stream_.reset(new CastAudioOutputStream(params, this)); 165 mixer_output_stream_.reset(new CastAudioOutputStream(params, this));
177 return mixer_output_stream_.get(); 166 return mixer_output_stream_.get();
178 } 167 }
179 168
180 } // namespace media 169 } // namespace media
181 } // namespace chromecast 170 } // namespace chromecast
OLDNEW
« no previous file with comments | « chromecast/media/audio/cast_audio_manager.h ('k') | chromecast/media/audio/cast_audio_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698