Handle streams separately in tree_add_track()
[cmus.git] / arts.c
blobb1f8afed685c1ccfdca69f90cac3122db087b28d
1 /*
2 * Copyright 2004-2005 Timo Hirvonen
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
17 * 02111-1307, USA.
20 #include "op.h"
21 #include "xmalloc.h"
22 #include "debug.h"
24 #include <artsc.h>
26 static arts_stream_t arts_stream;
27 static sample_format_t arts_sf;
28 static int arts_buffer_size;
30 static int op_arts_init(void)
32 int rc;
34 rc = arts_init();
35 if (rc < 0) {
36 return -1;
38 return 0;
41 static int op_arts_exit(void)
43 arts_free();
44 return 0;
47 static int op_arts_open(sample_format_t sf)
49 int buffer_time, server_latency, total_latency;
50 int blocking;
52 arts_sf = sf;
53 arts_stream = arts_play_stream(sf_get_rate(arts_sf), sf_get_bits(arts_sf),
54 sf_get_channels(arts_sf), "cmus");
55 blocking = arts_stream_set(arts_stream, ARTS_P_BLOCKING, 0);
56 if (blocking) {
58 arts_buffer_size = arts_stream_get(arts_stream, ARTS_P_BUFFER_SIZE);
59 if (arts_buffer_size < 0) {
61 buffer_time = arts_stream_get(arts_stream, ARTS_P_BUFFER_TIME);
62 server_latency = arts_stream_get(arts_stream, ARTS_P_SERVER_LATENCY);
63 total_latency = arts_stream_get(arts_stream, ARTS_P_TOTAL_LATENCY);
64 d_print("buffer_time: %d\n", buffer_time);
65 d_print("server_latency: %d\n", server_latency);
66 d_print("total_latency: %d\n", total_latency);
67 return 0;
70 static int op_arts_close(void)
72 arts_close_stream(arts_stream);
73 return 0;
76 static int op_arts_write(const char *buffer, int count)
78 int rc;
80 rc = arts_write(arts_stream, buffer, count);
81 if (rc < 0) {
82 d_print("rc = %d, count = %d\n", rc, count);
83 return -1;
85 return rc;
88 static int op_arts_pause(void)
90 return 0;
93 static int op_arts_unpause(void)
95 return 0;
98 static int op_arts_buffer_space(void)
100 int space;
102 space = arts_stream_get(arts_stream, ARTS_P_BUFFER_SPACE);
103 if (space < 0)
104 return -1;
105 return space;
108 static int op_arts_set_option(int key, const char *val)
110 return -OP_ERROR_NOT_OPTION;
113 static int op_arts_get_option(int key, char **val)
115 return -OP_ERROR_NOT_OPTION;
118 const struct output_plugin_ops op_pcm_ops = {
119 .init = op_arts_init,
120 .exit = op_arts_exit,
121 .open = op_arts_open,
122 .close = op_arts_close,
123 .write = op_arts_write,
124 .pause = op_arts_pause,
125 .unpause = op_arts_unpause,
126 .buffer_space = op_arts_buffer_space,
127 .set_option = op_arts_set_option,
128 .get_option = op_arts_get_option
131 const char * const op_pcm_options[] = {
132 NULL
135 const int op_priority = 2;