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

Side by Side Diff: media/audio/audio_output_stream_sink.cc

Issue 651373003: Add support for real audio output to mojo. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mojo_ari
Patch Set: Comments. Created 6 years, 2 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
« no previous file with comments | « media/audio/audio_output_stream_sink.h ('k') | media/media.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 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 "media/audio/audio_output_stream_sink.h"
6
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
9 #include "base/location.h"
10 #include "media/audio/audio_manager.h"
11
12 namespace media {
13
14 AudioOutputStreamSink::AudioOutputStreamSink()
15 : render_callback_(NULL),
16 audio_task_runner_(AudioManager::Get()->GetTaskRunner()),
17 stream_(NULL),
18 active_render_callback_(NULL) {
19 }
20
21 AudioOutputStreamSink::~AudioOutputStreamSink() {
22 }
23
24 void AudioOutputStreamSink::Initialize(const AudioParameters& params,
25 RenderCallback* callback) {
26 DCHECK(callback);
27 DCHECK(!render_callback_);
28 params_ = params;
29 render_callback_ = callback;
30 }
31
32 void AudioOutputStreamSink::Start() {
33 audio_task_runner_->PostTask(
34 FROM_HERE, base::Bind(&AudioOutputStreamSink::DoStart, this));
35 }
36
37 void AudioOutputStreamSink::Stop() {
38 ClearCallback();
39 audio_task_runner_->PostTask(
40 FROM_HERE, base::Bind(&AudioOutputStreamSink::DoStop, this));
41 }
42
43 void AudioOutputStreamSink::Pause() {
44 ClearCallback();
45 audio_task_runner_->PostTask(
46 FROM_HERE, base::Bind(&AudioOutputStreamSink::DoPause, this));
47 }
48
49 void AudioOutputStreamSink::Play() {
50 base::AutoLock al(callback_lock_);
51 active_render_callback_ = render_callback_;
52 audio_task_runner_->PostTask(
53 FROM_HERE, base::Bind(&AudioOutputStreamSink::DoPlay, this));
54 }
55
56 bool AudioOutputStreamSink::SetVolume(double volume) {
57 audio_task_runner_->PostTask(
58 FROM_HERE, base::Bind(&AudioOutputStreamSink::DoSetVolume, this, volume));
59 return true;
60 };
61
62 int AudioOutputStreamSink::OnMoreData(AudioBus* dest,
63 uint32 total_bytes_delay) {
64 // Note: Runs on the audio thread created by the OS.
65 base::AutoLock al(callback_lock_);
66 if (!active_render_callback_)
67 return 0;
68
69 return active_render_callback_->Render(
70 dest, total_bytes_delay * 1000.0 / params_.GetBytesPerSecond());
71 }
72
73 void AudioOutputStreamSink::OnError(AudioOutputStream* stream) {
74 // Note: Runs on the audio thread created by the OS.
75 base::AutoLock al(callback_lock_);
76 if (active_render_callback_)
77 active_render_callback_->OnRenderError();
78 }
79
80 void AudioOutputStreamSink::DoStart() {
81 DCHECK(audio_task_runner_->BelongsToCurrentThread());
82
83 // Create an AudioOutputStreamProxy which will handle any and all resampling
84 // necessary to generate a low latency output stream.
85 stream_ =
86 AudioManager::Get()->MakeAudioOutputStreamProxy(params_, std::string());
87 if (!stream_ || !stream_->Open()) {
88 render_callback_->OnRenderError();
89 if (stream_)
90 stream_->Close();
91 stream_ = NULL;
92 }
93 }
94
95 void AudioOutputStreamSink::DoStop() {
96 DCHECK(audio_task_runner_->BelongsToCurrentThread());
97
98 if (!stream_)
99 return;
100
101 DoPause();
102 stream_->Close();
103 stream_ = NULL;
104 }
105
106 void AudioOutputStreamSink::DoPause() {
107 DCHECK(audio_task_runner_->BelongsToCurrentThread());
108 stream_->Stop();
109 }
110
111 void AudioOutputStreamSink::DoPlay() {
112 DCHECK(audio_task_runner_->BelongsToCurrentThread());
113 stream_->Start(this);
114 }
115
116 void AudioOutputStreamSink::DoSetVolume(double volume) {
117 DCHECK(audio_task_runner_->BelongsToCurrentThread());
118 stream_->SetVolume(volume);
119 }
120
121 void AudioOutputStreamSink::ClearCallback() {
122 base::AutoLock al(callback_lock_);
123 active_render_callback_ = NULL;
124 }
125
126 } // namepace media
OLDNEW
« no previous file with comments | « media/audio/audio_output_stream_sink.h ('k') | media/media.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698