Mercurial > audlegacy-plugins
annotate src/alsa-ng/alsa-core.c @ 3165:087abc78516e
alsa-ng: implement pause stuff. not perfect yet.
author | William Pitcock <nenolod@atheme.org> |
---|---|
date | Thu, 14 May 2009 23:14:50 -0500 |
parents | adec82db531c |
children | 8cbf077ba5d0 |
rev | line source |
---|---|
3162
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
1 /* |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
2 * Audacious ALSA Plugin (-ng) |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
3 * Copyright (c) 2009 William Pitcock <nenolod@dereferenced.org> |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
4 * |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
5 * This program is free software; you can redistribute it and/or modify |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
6 * it under the terms of the GNU General Public License as published by |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
7 * the Free Software Foundation; either version 2 of the License, or |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
8 * (at your option) any later version. |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
9 * |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
10 * This program is distributed in the hope that it will be useful, |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
13 * GNU General Public License for more details. |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
14 * |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
16 * along with this program; if not, write to the Free Software |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
18 */ |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
19 |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
20 #define ALSA_DEBUG |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
21 #include "alsa-stdinc.h" |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
22 |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
23 static snd_pcm_t *pcm_handle = NULL; |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
24 static alsaplug_ringbuf_t pcm_ringbuf; |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
25 static gboolean pcm_going = FALSE; |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
26 static GThread *audio_thread = NULL; |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
27 static gint bps; |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
28 |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
29 static gsize wr_total = 0; |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
30 static gsize wr_hwframes = 0; |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
31 |
3165
087abc78516e
alsa-ng: implement pause stuff. not perfect yet.
William Pitcock <nenolod@atheme.org>
parents:
3164
diff
changeset
|
32 static gint flush_request, pause_request, paused; |
087abc78516e
alsa-ng: implement pause stuff. not perfect yet.
William Pitcock <nenolod@atheme.org>
parents:
3164
diff
changeset
|
33 static gboolean can_pause; |
3162
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
34 |
3164
adec82db531c
alsa-ng: Everything but mixer (and custom output settings) should be working now.
William Pitcock <nenolod@atheme.org>
parents:
3163
diff
changeset
|
35 /******************************************************************************** |
adec82db531c
alsa-ng: Everything but mixer (and custom output settings) should be working now.
William Pitcock <nenolod@atheme.org>
parents:
3163
diff
changeset
|
36 * ALSA Mixer setting functions. * |
adec82db531c
alsa-ng: Everything but mixer (and custom output settings) should be working now.
William Pitcock <nenolod@atheme.org>
parents:
3163
diff
changeset
|
37 ********************************************************************************/ |
adec82db531c
alsa-ng: Everything but mixer (and custom output settings) should be working now.
William Pitcock <nenolod@atheme.org>
parents:
3163
diff
changeset
|
38 |
adec82db531c
alsa-ng: Everything but mixer (and custom output settings) should be working now.
William Pitcock <nenolod@atheme.org>
parents:
3163
diff
changeset
|
39 /******************************************************************************** |
adec82db531c
alsa-ng: Everything but mixer (and custom output settings) should be working now.
William Pitcock <nenolod@atheme.org>
parents:
3163
diff
changeset
|
40 * ALSA PCM I/O functions. * |
adec82db531c
alsa-ng: Everything but mixer (and custom output settings) should be working now.
William Pitcock <nenolod@atheme.org>
parents:
3163
diff
changeset
|
41 ********************************************************************************/ |
adec82db531c
alsa-ng: Everything but mixer (and custom output settings) should be working now.
William Pitcock <nenolod@atheme.org>
parents:
3163
diff
changeset
|
42 |
3162
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
43 static void |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
44 alsaplug_write_buffer(gpointer data, gint length) |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
45 { |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
46 snd_pcm_sframes_t wr_frames; |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
47 |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
48 while (length > 0) |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
49 { |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
50 gint frames = snd_pcm_bytes_to_frames(pcm_handle, length); |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
51 wr_frames = snd_pcm_writei(pcm_handle, data, frames); |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
52 |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
53 if (wr_frames > 0) |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
54 { |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
55 gint written = snd_pcm_frames_to_bytes(pcm_handle, wr_frames); |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
56 length -= written; |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
57 data += written; |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
58 } |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
59 else |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
60 { |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
61 gint err = snd_pcm_recover(pcm_handle, wr_frames, 1); |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
62 if (err < 0) |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
63 _ERROR("(write) snd_pcm_recover: %s", snd_strerror(err)); |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
64 |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
65 return; |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
66 } |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
67 } |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
68 } |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
69 |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
70 static gpointer |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
71 alsaplug_loop(gpointer unused) |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
72 { |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
73 gchar buf[2048]; |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
74 |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
75 while (pcm_going) |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
76 { |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
77 if (flush_request != -1) |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
78 { |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
79 snd_pcm_drop(pcm_handle); |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
80 snd_pcm_prepare(pcm_handle); |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
81 wr_total = flush_request * (bps / 1000); |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
82 flush_request = -1; |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
83 } |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
84 |
3165
087abc78516e
alsa-ng: implement pause stuff. not perfect yet.
William Pitcock <nenolod@atheme.org>
parents:
3164
diff
changeset
|
85 if (pause_request != paused) |
087abc78516e
alsa-ng: implement pause stuff. not perfect yet.
William Pitcock <nenolod@atheme.org>
parents:
3164
diff
changeset
|
86 { |
087abc78516e
alsa-ng: implement pause stuff. not perfect yet.
William Pitcock <nenolod@atheme.org>
parents:
3164
diff
changeset
|
87 snd_pcm_pause(pcm_handle, pause_request); |
087abc78516e
alsa-ng: implement pause stuff. not perfect yet.
William Pitcock <nenolod@atheme.org>
parents:
3164
diff
changeset
|
88 paused = pause_request; |
087abc78516e
alsa-ng: implement pause stuff. not perfect yet.
William Pitcock <nenolod@atheme.org>
parents:
3164
diff
changeset
|
89 continue; |
087abc78516e
alsa-ng: implement pause stuff. not perfect yet.
William Pitcock <nenolod@atheme.org>
parents:
3164
diff
changeset
|
90 } |
087abc78516e
alsa-ng: implement pause stuff. not perfect yet.
William Pitcock <nenolod@atheme.org>
parents:
3164
diff
changeset
|
91 |
3162
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
92 if (alsaplug_ringbuffer_read(&pcm_ringbuf, buf, 2048) == -1) |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
93 { |
3164
adec82db531c
alsa-ng: Everything but mixer (and custom output settings) should be working now.
William Pitcock <nenolod@atheme.org>
parents:
3163
diff
changeset
|
94 /* less than 2048 bytes to go...? */ |
adec82db531c
alsa-ng: Everything but mixer (and custom output settings) should be working now.
William Pitcock <nenolod@atheme.org>
parents:
3163
diff
changeset
|
95 gint remain = alsaplug_ringbuffer_used(&pcm_ringbuf); |
adec82db531c
alsa-ng: Everything but mixer (and custom output settings) should be working now.
William Pitcock <nenolod@atheme.org>
parents:
3163
diff
changeset
|
96 if (remain <= 2048) |
adec82db531c
alsa-ng: Everything but mixer (and custom output settings) should be working now.
William Pitcock <nenolod@atheme.org>
parents:
3163
diff
changeset
|
97 { |
adec82db531c
alsa-ng: Everything but mixer (and custom output settings) should be working now.
William Pitcock <nenolod@atheme.org>
parents:
3163
diff
changeset
|
98 alsaplug_ringbuffer_read(&pcm_ringbuf, buf, remain); |
adec82db531c
alsa-ng: Everything but mixer (and custom output settings) should be working now.
William Pitcock <nenolod@atheme.org>
parents:
3163
diff
changeset
|
99 alsaplug_write_buffer(buf, remain); |
adec82db531c
alsa-ng: Everything but mixer (and custom output settings) should be working now.
William Pitcock <nenolod@atheme.org>
parents:
3163
diff
changeset
|
100 } |
3162
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
101 |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
102 continue; |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
103 } |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
104 |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
105 alsaplug_write_buffer(buf, 2048); |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
106 } |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
107 |
3164
adec82db531c
alsa-ng: Everything but mixer (and custom output settings) should be working now.
William Pitcock <nenolod@atheme.org>
parents:
3163
diff
changeset
|
108 snd_pcm_drain(pcm_handle); |
3162
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
109 snd_pcm_close(pcm_handle); |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
110 pcm_handle = NULL; |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
111 |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
112 return NULL; |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
113 } |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
114 |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
115 /******************************************************************************** |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
116 * Output Plugin API implementation. * |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
117 ********************************************************************************/ |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
118 |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
119 static OutputPluginInitStatus |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
120 alsaplug_init(void) |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
121 { |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
122 gint card = -1; |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
123 |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
124 if (snd_card_next(&card) != 0) |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
125 return OUTPUT_PLUGIN_INIT_NO_DEVICES; |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
126 |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
127 return OUTPUT_PLUGIN_INIT_FOUND_DEVICES; |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
128 } |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
129 |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
130 static gint |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
131 alsaplug_open_audio(AFormat fmt, gint rate, gint nch) |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
132 { |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
133 gint err, bitwidth, ringbuf_size; |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
134 snd_pcm_format_t afmt; |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
135 snd_pcm_hw_params_t *hwparams = NULL; |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
136 |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
137 afmt = alsaplug_format_convert(fmt); |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
138 |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
139 if ((err = snd_pcm_open(&pcm_handle, "default", SND_PCM_STREAM_PLAYBACK, 0)) < 0) |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
140 { |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
141 _ERROR("snd_pcm_open: %s", snd_strerror(err)); |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
142 pcm_handle = NULL; |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
143 return -1; |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
144 } |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
145 |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
146 snd_pcm_hw_params_alloca(&hwparams); |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
147 snd_pcm_hw_params_any(pcm_handle, hwparams); |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
148 snd_pcm_hw_params_set_access(pcm_handle, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED); |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
149 snd_pcm_hw_params_set_format(pcm_handle, hwparams, afmt); |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
150 snd_pcm_hw_params_set_channels(pcm_handle, hwparams, nch); |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
151 snd_pcm_hw_params_set_rate(pcm_handle, hwparams, rate, 0); |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
152 |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
153 err = snd_pcm_hw_params(pcm_handle, hwparams); |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
154 if (err < 0) |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
155 { |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
156 _ERROR("snd_pcm_hw_params failed: %s", snd_strerror(err)); |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
157 return -1; |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
158 } |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
159 |
3165
087abc78516e
alsa-ng: implement pause stuff. not perfect yet.
William Pitcock <nenolod@atheme.org>
parents:
3164
diff
changeset
|
160 can_pause = snd_pcm_hw_params_can_pause(hwparams); |
3162
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
161 bitwidth = snd_pcm_format_physical_width(afmt); |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
162 bps = (rate * bitwidth * nch) >> 3; |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
163 ringbuf_size = aud_cfg->output_buffer_size * bps / 1000; |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
164 alsaplug_ringbuffer_init(&pcm_ringbuf, ringbuf_size); |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
165 pcm_going = TRUE; |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
166 flush_request = -1; |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
167 |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
168 audio_thread = g_thread_create(alsaplug_loop, NULL, TRUE, NULL); |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
169 return 1; |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
170 } |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
171 |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
172 static void |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
173 alsaplug_close_audio(void) |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
174 { |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
175 pcm_going = FALSE; |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
176 |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
177 g_thread_join(audio_thread); |
3164
adec82db531c
alsa-ng: Everything but mixer (and custom output settings) should be working now.
William Pitcock <nenolod@atheme.org>
parents:
3163
diff
changeset
|
178 audio_thread = NULL; |
3162
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
179 |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
180 wr_total = 0; |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
181 wr_hwframes = 0; |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
182 bps = 0; |
3163
26a2c237ef53
alsa-ng: Destroy the ringbuffer when the plugin closes.
William Pitcock <nenolod@atheme.org>
parents:
3162
diff
changeset
|
183 alsaplug_ringbuffer_destroy(&pcm_ringbuf); |
3162
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
184 } |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
185 |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
186 static void |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
187 alsaplug_write_audio(gpointer data, gint length) |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
188 { |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
189 wr_total += length; |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
190 alsaplug_ringbuffer_write(&pcm_ringbuf, data, length); |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
191 } |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
192 |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
193 static gint |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
194 alsaplug_output_time(void) |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
195 { |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
196 snd_pcm_sframes_t delay; |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
197 gsize bytes = wr_total; |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
198 |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
199 if (pcm_going && pcm_handle != NULL) |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
200 { |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
201 if (!snd_pcm_delay(pcm_handle, &delay)) |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
202 { |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
203 guint d = snd_pcm_frames_to_bytes(pcm_handle, delay); |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
204 if (bytes < d) |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
205 bytes = 0; |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
206 else |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
207 bytes -= d; |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
208 } |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
209 |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
210 return (bytes * 1000) / bps; |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
211 } |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
212 |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
213 return 0; |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
214 } |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
215 |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
216 static gint |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
217 alsaplug_written_time(void) |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
218 { |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
219 if (pcm_going) |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
220 return (wr_total * 1000) / bps; |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
221 |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
222 return 0; |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
223 } |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
224 |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
225 static gint |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
226 alsaplug_buffer_free(void) |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
227 { |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
228 return alsaplug_ringbuffer_free(&pcm_ringbuf); |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
229 } |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
230 |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
231 static void |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
232 alsaplug_flush(gint time) |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
233 { |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
234 flush_request = time; |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
235 while (flush_request != -1 && pcm_going) |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
236 g_usleep(10000); |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
237 } |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
238 |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
239 static gint |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
240 alsaplug_buffer_playing(void) |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
241 { |
3164
adec82db531c
alsa-ng: Everything but mixer (and custom output settings) should be working now.
William Pitcock <nenolod@atheme.org>
parents:
3163
diff
changeset
|
242 return alsaplug_ringbuffer_used(&pcm_ringbuf) != 0; |
3162
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
243 } |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
244 |
3165
087abc78516e
alsa-ng: implement pause stuff. not perfect yet.
William Pitcock <nenolod@atheme.org>
parents:
3164
diff
changeset
|
245 static void |
087abc78516e
alsa-ng: implement pause stuff. not perfect yet.
William Pitcock <nenolod@atheme.org>
parents:
3164
diff
changeset
|
246 alsaplug_pause(short p) |
087abc78516e
alsa-ng: implement pause stuff. not perfect yet.
William Pitcock <nenolod@atheme.org>
parents:
3164
diff
changeset
|
247 { |
087abc78516e
alsa-ng: implement pause stuff. not perfect yet.
William Pitcock <nenolod@atheme.org>
parents:
3164
diff
changeset
|
248 pause_request = p; |
087abc78516e
alsa-ng: implement pause stuff. not perfect yet.
William Pitcock <nenolod@atheme.org>
parents:
3164
diff
changeset
|
249 } |
087abc78516e
alsa-ng: implement pause stuff. not perfect yet.
William Pitcock <nenolod@atheme.org>
parents:
3164
diff
changeset
|
250 |
3162
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
251 /******************************************************************************** |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
252 * Plugin glue. * |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
253 ********************************************************************************/ |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
254 |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
255 static OutputPlugin alsa_op = { |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
256 .description = "ALSA Output Plugin (-ng)", |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
257 .probe_priority = 1, |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
258 .init = alsaplug_init, |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
259 .open_audio = alsaplug_open_audio, |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
260 .close_audio = alsaplug_close_audio, |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
261 .write_audio = alsaplug_write_audio, |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
262 .output_time = alsaplug_output_time, |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
263 .written_time = alsaplug_written_time, |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
264 .buffer_free = alsaplug_buffer_free, |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
265 .buffer_playing = alsaplug_buffer_playing, |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
266 .flush = alsaplug_flush, |
3165
087abc78516e
alsa-ng: implement pause stuff. not perfect yet.
William Pitcock <nenolod@atheme.org>
parents:
3164
diff
changeset
|
267 .pause = alsaplug_pause, |
3162
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
268 }; |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
269 |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
270 OutputPlugin *alsa_oplist[] = { &alsa_op, NULL }; |
e387614b9be9
alsa-ng: Import rewritten ALSA plugin. This is still woefully incomplete, but supports basic playback.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
271 SIMPLE_OUTPUT_PLUGIN(alsa, alsa_oplist); |