summaryrefslogtreecommitdiff
path: root/www/chromium/patches/patch-media_audio_sndio_sndio_output_cc
diff options
context:
space:
mode:
Diffstat (limited to 'www/chromium/patches/patch-media_audio_sndio_sndio_output_cc')
-rw-r--r--www/chromium/patches/patch-media_audio_sndio_sndio_output_cc191
1 files changed, 0 insertions, 191 deletions
diff --git a/www/chromium/patches/patch-media_audio_sndio_sndio_output_cc b/www/chromium/patches/patch-media_audio_sndio_sndio_output_cc
deleted file mode 100644
index f8b7317..0000000
--- a/www/chromium/patches/patch-media_audio_sndio_sndio_output_cc
+++ /dev/null
@@ -1,191 +0,0 @@
1Index: media/audio/sndio/sndio_output.cc
2--- media/audio/sndio/sndio_output.cc.orig
3+++ media/audio/sndio/sndio_output.cc
4@@ -0,0 +1,187 @@
5+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
6+// Use of this source code is governed by a BSD-style license that can be
7+// found in the LICENSE file.
8+
9+#include "base/logging.h"
10+#include "base/time/time.h"
11+#include "base/time/default_tick_clock.h"
12+#include "media/audio/audio_manager_base.h"
13+#include "media/base/audio_timestamp_helper.h"
14+#include "media/audio/sndio/sndio_output.h"
15+
16+namespace media {
17+
18+static const SampleFormat kSampleFormat = kSampleFormatS16;
19+
20+void SndioAudioOutputStream::OnMoveCallback(void *arg, int delta) {
21+ SndioAudioOutputStream* self = static_cast<SndioAudioOutputStream*>(arg);
22+
23+ self->hw_delay -= delta;
24+}
25+
26+void SndioAudioOutputStream::OnVolCallback(void *arg, unsigned int vol) {
27+ SndioAudioOutputStream* self = static_cast<SndioAudioOutputStream*>(arg);
28+
29+ self->vol = vol;
30+}
31+
32+void *SndioAudioOutputStream::ThreadEntry(void *arg) {
33+ SndioAudioOutputStream* self = static_cast<SndioAudioOutputStream*>(arg);
34+
35+ self->ThreadLoop();
36+ return NULL;
37+}
38+
39+SndioAudioOutputStream::SndioAudioOutputStream(const AudioParameters& params,
40+ AudioManagerBase* manager)
41+ : manager(manager),
42+ params(params),
43+ audio_bus(AudioBus::Create(params)),
44+ state(kClosed),
45+ mutex(PTHREAD_MUTEX_INITIALIZER) {
46+}
47+
48+SndioAudioOutputStream::~SndioAudioOutputStream() {
49+ if (state != kClosed)
50+ Close();
51+}
52+
53+bool SndioAudioOutputStream::Open() {
54+ if (params.format() != AudioParameters::AUDIO_PCM_LINEAR &&
55+ params.format() != AudioParameters::AUDIO_PCM_LOW_LATENCY) {
56+ LOG(WARNING) << "Unsupported audio format.";
57+ return false;
58+ }
59+ state = kStopped;
60+ volpending = 0;
61+ vol = SIO_MAXVOL;
62+ buffer = new char[audio_bus->frames() * params.GetBytesPerFrame(kSampleFormat)];
63+ return true;
64+}
65+
66+void SndioAudioOutputStream::Close() {
67+ if (state == kClosed)
68+ goto release;
69+ if (state == kRunning)
70+ Stop();
71+ state = kClosed;
72+ delete [] buffer;
73+release:
74+ manager->ReleaseOutputStream(this); // Calls the destructor
75+}
76+
77+void SndioAudioOutputStream::Start(AudioSourceCallback* callback) {
78+ struct sio_par par;
79+ int sig;
80+
81+ sio_initpar(&par);
82+ par.rate = params.sample_rate();
83+ par.pchan = params.channels();
84+ par.bits = SampleFormatToBitsPerChannel(kSampleFormat);
85+ par.bps = par.bits / 8;
86+ par.sig = sig = par.bits != 8 ? 1 : 0;
87+ par.le = SIO_LE_NATIVE;
88+ par.appbufsz = params.frames_per_buffer();
89+
90+ hdl = sio_open(SIO_DEVANY, SIO_PLAY, 0);
91+ if (hdl == NULL) {
92+ LOG(ERROR) << "Couldn't open audio device.";
93+ return;
94+ }
95+ if (!sio_setpar(hdl, &par) || !sio_getpar(hdl, &par)) {
96+ LOG(ERROR) << "Couldn't set audio parameters.";
97+ sio_close(hdl);
98+ return;
99+ }
100+ if (par.rate != (unsigned int)params.sample_rate() ||
101+ par.pchan != (unsigned int)params.channels() ||
102+ par.bits != (unsigned int)SampleFormatToBitsPerChannel(kSampleFormat) ||
103+ par.sig != (unsigned int)sig ||
104+ (par.bps > 1 && par.le != SIO_LE_NATIVE) ||
105+ (par.bits != par.bps * 8)) {
106+ LOG(ERROR) << "Unsupported audio parameters.";
107+ sio_close(hdl);
108+ return;
109+ }
110+
111+ sio_onmove(hdl, &OnMoveCallback, this);
112+ sio_onvol(hdl, &OnVolCallback, this);
113+
114+ state = kRunning;
115+ hw_delay = 0;
116+ source = callback;
117+ sio_start(hdl);
118+
119+ if (pthread_create(&thread, NULL, &ThreadEntry, this) != 0) {
120+ LOG(ERROR) << "Failed to create real-time thread.";
121+ sio_stop(hdl);
122+ sio_close(hdl);
123+ state = kStopped;
124+ }
125+}
126+
127+void SndioAudioOutputStream::Stop() {
128+ if (state == kStopped)
129+ return;
130+ state = kStopWait;
131+ pthread_join(thread, NULL);
132+ sio_stop(hdl);
133+ sio_close(hdl);
134+ state = kStopped;
135+}
136+
137+void SndioAudioOutputStream::SetVolume(double v) {
138+ pthread_mutex_lock(&mutex);
139+ vol = v * SIO_MAXVOL;
140+ volpending = 1;
141+ pthread_mutex_unlock(&mutex);
142+}
143+
144+void SndioAudioOutputStream::GetVolume(double* v) {
145+ pthread_mutex_lock(&mutex);
146+ *v = vol * (1. / SIO_MAXVOL);
147+ pthread_mutex_unlock(&mutex);
148+}
149+
150+// This stream is always used with sub second buffer sizes, where it's
151+// sufficient to simply always flush upon Start().
152+void SndioAudioOutputStream::Flush() {}
153+
154+void SndioAudioOutputStream::ThreadLoop(void) {
155+ int avail, count, result;
156+
157+ while (state == kRunning) {
158+ // Update volume if needed
159+ pthread_mutex_lock(&mutex);
160+ if (volpending) {
161+ volpending = 0;
162+ sio_setvol(hdl, vol);
163+ }
164+ pthread_mutex_unlock(&mutex);
165+
166+ // Get data to play
167+ const base::TimeDelta delay = AudioTimestampHelper::FramesToTime(hw_delay,
168+ params.sample_rate());
169+ count = source->OnMoreData(delay, base::TimeTicks::Now(), 0, audio_bus.get());
170+ audio_bus->ToInterleaved<SignedInt16SampleTypeTraits>(count, reinterpret_cast<int16_t*>(buffer));
171+ if (count == 0) {
172+ // We have to submit something to the device
173+ count = audio_bus->frames();
174+ memset(buffer, 0, count * params.GetBytesPerFrame(kSampleFormat));
175+ LOG(WARNING) << "No data to play, running empty cycle.";
176+ }
177+
178+ // Submit data to the device
179+ avail = count * params.GetBytesPerFrame(kSampleFormat);
180+ result = sio_write(hdl, buffer, avail);
181+ if (result == 0) {
182+ LOG(WARNING) << "Audio device disconnected.";
183+ break;
184+ }
185+
186+ // Update hardware pointer
187+ hw_delay += count;
188+ }
189+}
190+
191+} // namespace media