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

Side by Side Diff: media/audio/pulse/pulse_output.cc

Issue 2469023002: Support floating-point audio output for Linux (Closed)
Patch Set: Address review comments Created 4 years, 1 month 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
« no previous file with comments | « no previous file | media/audio/pulse/pulse_util.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "media/audio/pulse/pulse_output.h" 5 #include "media/audio/pulse/pulse_output.h"
6 6
7 #include <pulse/pulseaudio.h> 7 #include <pulse/pulseaudio.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
11 #include "base/time/time.h" 11 #include "base/time/time.h"
12 #include "media/audio/audio_device_description.h" 12 #include "media/audio/audio_device_description.h"
13 #include "media/audio/audio_manager_base.h" 13 #include "media/audio/audio_manager_base.h"
14 #include "media/audio/pulse/pulse_util.h" 14 #include "media/audio/pulse/pulse_util.h"
15 #include "media/base/audio_sample_types.h"
15 16
16 namespace media { 17 namespace media {
17 18
18 using pulse::AutoPulseLock; 19 using pulse::AutoPulseLock;
19 using pulse::WaitForOperationCompletion; 20 using pulse::WaitForOperationCompletion;
20 21
21 // static, pa_stream_notify_cb 22 // static, pa_stream_notify_cb
22 void PulseAudioOutputStream::StreamNotifyCallback(pa_stream* s, void* p_this) { 23 void PulseAudioOutputStream::StreamNotifyCallback(pa_stream* s, void* p_this) {
23 PulseAudioOutputStream* stream = static_cast<PulseAudioOutputStream*>(p_this); 24 PulseAudioOutputStream* stream = static_cast<PulseAudioOutputStream*>(p_this);
24 25
(...skipping 11 matching lines...) Expand all
36 // static, pa_stream_request_cb_t 37 // static, pa_stream_request_cb_t
37 void PulseAudioOutputStream::StreamRequestCallback(pa_stream* s, size_t len, 38 void PulseAudioOutputStream::StreamRequestCallback(pa_stream* s, size_t len,
38 void* p_this) { 39 void* p_this) {
39 // Fulfill write request; must always result in a pa_stream_write() call. 40 // Fulfill write request; must always result in a pa_stream_write() call.
40 static_cast<PulseAudioOutputStream*>(p_this)->FulfillWriteRequest(len); 41 static_cast<PulseAudioOutputStream*>(p_this)->FulfillWriteRequest(len);
41 } 42 }
42 43
43 PulseAudioOutputStream::PulseAudioOutputStream(const AudioParameters& params, 44 PulseAudioOutputStream::PulseAudioOutputStream(const AudioParameters& params,
44 const std::string& device_id, 45 const std::string& device_id,
45 AudioManagerBase* manager) 46 AudioManagerBase* manager)
46 : params_(params), 47 : params_(AudioParameters(params.format(),
48 params.channel_layout(),
49 params.sample_rate(),
50 // Ignore the given bits per sample. We
51 // want 32 because we're outputting
52 // floats.
53 32,
54 params.frames_per_buffer())),
47 device_id_(device_id), 55 device_id_(device_id),
48 manager_(manager), 56 manager_(manager),
49 pa_context_(NULL), 57 pa_context_(NULL),
50 pa_mainloop_(NULL), 58 pa_mainloop_(NULL),
51 pa_stream_(NULL), 59 pa_stream_(NULL),
52 volume_(1.0f), 60 volume_(1.0f),
53 source_callback_(NULL) { 61 source_callback_(NULL) {
54 CHECK(params_.IsValid()); 62 CHECK(params_.IsValid());
55 audio_bus_ = AudioBus::Create(params_); 63 audio_bus_ = AudioBus::Create(params_);
56 } 64 }
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 const base::TimeDelta delay = pulse::GetHardwareLatency(pa_stream_); 144 const base::TimeDelta delay = pulse::GetHardwareLatency(pa_stream_);
137 frames_filled = source_callback_->OnMoreData( 145 frames_filled = source_callback_->OnMoreData(
138 delay, base::TimeTicks::Now(), 0, audio_bus_.get()); 146 delay, base::TimeTicks::Now(), 0, audio_bus_.get());
139 147
140 // Zero any unfilled data so it plays back as silence. 148 // Zero any unfilled data so it plays back as silence.
141 if (frames_filled < audio_bus_->frames()) { 149 if (frames_filled < audio_bus_->frames()) {
142 audio_bus_->ZeroFramesPartial( 150 audio_bus_->ZeroFramesPartial(
143 frames_filled, audio_bus_->frames() - frames_filled); 151 frames_filled, audio_bus_->frames() - frames_filled);
144 } 152 }
145 153
146 // Note: If this ever changes to output raw float the data must be clipped
147 // and sanitized since it may come from an untrusted source such as NaCl.
148 audio_bus_->Scale(volume_); 154 audio_bus_->Scale(volume_);
149 audio_bus_->ToInterleaved( 155 audio_bus_->ToInterleaved<Float32SampleTypeTraits>(
150 audio_bus_->frames(), params_.bits_per_sample() / 8, buffer); 156 audio_bus_->frames(), reinterpret_cast<float*>(buffer));
151 } else { 157 } else {
152 memset(buffer, 0, bytes_to_fill); 158 memset(buffer, 0, bytes_to_fill);
153 } 159 }
154 160
155 if (pa_stream_write(pa_stream_, buffer, bytes_to_fill, NULL, 0LL, 161 if (pa_stream_write(pa_stream_, buffer, bytes_to_fill, NULL, 0LL,
156 PA_SEEK_RELATIVE) < 0) { 162 PA_SEEK_RELATIVE) < 0) {
157 if (source_callback_) { 163 if (source_callback_) {
158 source_callback_->OnError(this); 164 source_callback_->OnError(this);
159 } 165 }
160 } 166 }
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 volume_ = static_cast<float>(volume); 239 volume_ = static_cast<float>(volume);
234 } 240 }
235 241
236 void PulseAudioOutputStream::GetVolume(double* volume) { 242 void PulseAudioOutputStream::GetVolume(double* volume) {
237 DCHECK(thread_checker_.CalledOnValidThread()); 243 DCHECK(thread_checker_.CalledOnValidThread());
238 244
239 *volume = volume_; 245 *volume = volume_;
240 } 246 }
241 247
242 } // namespace media 248 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | media/audio/pulse/pulse_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698