1
/*
2
 * Copyright 2008-2011 Various Authors
3
 * Copyright 2004-2005 Timo Hirvonen
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License as
7
 * published by the Free Software Foundation; either version 2 of the
8
 * License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful, but
11
 * WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 * General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17
 */
18
19
#include "op.h"
20
#include "xmalloc.h"
21
#include "debug.h"
22
23
#include <artsc.h>
24
25
static arts_stream_t arts_stream;
26
static sample_format_t arts_sf;
27
static int arts_buffer_size;
28
29
static int op_arts_init(void)
30
{
31
	int rc;
32
33
	rc = arts_init();
34
	if (rc < 0) {
35
		return -1;
36
	}
37
	return 0;
38
}
39
40
static int op_arts_exit(void)
41
{
42
	arts_free();
43
	return 0;
44
}
45
46
static int op_arts_open(sample_format_t sf, const channel_position_t *channel_map)
47
{
48
	int buffer_time, server_latency, total_latency;
49
	int blocking;
50
51
	arts_sf = sf;
52
	arts_stream = arts_play_stream(sf_get_rate(arts_sf), sf_get_bits(arts_sf),
53
			sf_get_channels(arts_sf), "cmus");
54
	blocking = arts_stream_set(arts_stream, ARTS_P_BLOCKING, 0);
55
	if (blocking) {
56
	}
57
	arts_buffer_size = arts_stream_get(arts_stream, ARTS_P_BUFFER_SIZE);
58
	if (arts_buffer_size < 0) {
59
	}
60
	buffer_time = arts_stream_get(arts_stream, ARTS_P_BUFFER_TIME);
61
	server_latency = arts_stream_get(arts_stream, ARTS_P_SERVER_LATENCY);
62
	total_latency = arts_stream_get(arts_stream, ARTS_P_TOTAL_LATENCY);
63
	d_print("buffer_time: %d\n", buffer_time);
64
	d_print("server_latency: %d\n", server_latency);
65
	d_print("total_latency: %d\n", total_latency);
66
	return 0;
67
}
68
69
static int op_arts_close(void)
70
{
71
	arts_close_stream(arts_stream);
72
	return 0;
73
}
74
75
static int op_arts_write(const char *buffer, int count)
76
{
77
	int rc;
78
79
	rc = arts_write(arts_stream, buffer, count);
80
	if (rc < 0) {
81
		d_print("rc = %d, count = %d\n", rc, count);
82
		return -1;
83
	}
84
	return rc;
85
}
86
87
static int op_arts_pause(void)
88
{
89
	return 0;
90
}
91
92
static int op_arts_unpause(void)
93
{
94
	return 0;
95
}
96
97
static int op_arts_buffer_space(void)
98
{
99
	int space;
100
101
	space = arts_stream_get(arts_stream, ARTS_P_BUFFER_SPACE);
102
	if (space < 0)
103
		return -1;
104
	return space;
105
}
106
107
static int op_arts_set_option(int key, const char *val)
108
{
109
	return -OP_ERROR_NOT_OPTION;
110
}
111
112
static int op_arts_get_option(int key, char **val)
113
{
114
	return -OP_ERROR_NOT_OPTION;
115
}
116
117
const struct output_plugin_ops op_pcm_ops = {
118
	.init = op_arts_init,
119
	.exit = op_arts_exit,
120
	.open = op_arts_open,
121
	.close = op_arts_close,
122
	.write = op_arts_write,
123
	.pause = op_arts_pause,
124
	.unpause = op_arts_unpause,
125
	.buffer_space = op_arts_buffer_space,
126
	.set_option = op_arts_set_option,
127
	.get_option = op_arts_get_option
128
};
129
130
const char * const op_pcm_options[] = {
131
	NULL
132
};
133
134
const int op_priority = 2;