shout_plugin.c 14 KB
Newer Older
1
/* the Music Player Daemon (MPD)
2
 * Copyright (C) 2003-2007 by Warren Dukes (warren.dukes@gmail.com)
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
 * This project's homepage is: http://www.musicpd.org
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

19
#include "shout_plugin.h"
Warren Dukes's avatar
Warren Dukes committed
20 21 22

#ifdef HAVE_SHOUT

23
#include "../utils.h"
24

25 26
#include <assert.h>

27
#define CONN_ATTEMPT_INTERVAL 60
28
#define DEFAULT_CONN_TIMEOUT  2
29

Max Kellermann's avatar
Max Kellermann committed
30
static int shout_init_count;
31

32
static const struct shout_encoder_plugin *const shout_encoder_plugins[] = {
33
#ifdef HAVE_SHOUT_MP3
34
	&shout_mp3_encoder,
35 36
#endif
#ifdef HAVE_SHOUT_OGG
37
	&shout_ogg_encoder,
38
#endif
39 40
	NULL
};
41

42
static const struct shout_encoder_plugin *
43
shout_encoder_plugin_get(const char *name)
44
{
45
	unsigned i;
46

47 48 49
	for (i = 0; shout_encoder_plugins[i] != NULL; ++i)
		if (strcmp(shout_encoder_plugins[i]->name, name) == 0)
			return shout_encoder_plugins[i];
50

51
	return NULL;
52
}
53

Max Kellermann's avatar
Max Kellermann committed
54
static struct shout_data *new_shout_data(void)
Avuton Olrich's avatar
Avuton Olrich committed
55
{
Max Kellermann's avatar
Max Kellermann committed
56
	struct shout_data *ret = xmalloc(sizeof(*ret));
57

Max Kellermann's avatar
Max Kellermann committed
58
	ret->shout_conn = shout_new();
59
	ret->shout_meta = shout_metadata_new();
60
	ret->opened = 0;
61
	ret->tag = NULL;
Max Kellermann's avatar
Max Kellermann committed
62
	ret->tag_to_send = 0;
63
	ret->bitrate = -1;
64
	ret->quality = -2.0;
65
	ret->timeout = DEFAULT_CONN_TIMEOUT;
Max Kellermann's avatar
Max Kellermann committed
66 67
	ret->conn_attempts = 0;
	ret->last_attempt = 0;
68
	ret->timer = NULL;
69
	ret->buf.len = 0;
70

71 72 73
	return ret;
}

Max Kellermann's avatar
Max Kellermann committed
74
static void free_shout_data(struct shout_data *sd)
Avuton Olrich's avatar
Avuton Olrich committed
75
{
76 77
	if (sd->shout_meta)
		shout_metadata_free(sd->shout_meta);
Max Kellermann's avatar
Max Kellermann committed
78 79
	if (sd->shout_conn)
		shout_free(sd->shout_conn);
Avuton Olrich's avatar
Avuton Olrich committed
80
	if (sd->tag)
81
		tag_free(sd->tag);
82 83
	if (sd->timer)
		timer_free(sd->timer);
84

85 86 87
	free(sd);
}

Max Kellermann's avatar
Max Kellermann committed
88 89 90 91 92 93 94
#define check_block_param(name) {		  \
		block_param = getBlockParam(param, name);	\
		if (!block_param) {					\
			FATAL("no \"%s\" defined for shout device defined at line " \
			      "%i\n", name, param->line);		\
		}							\
	}
95

96
static void *my_shout_init_driver(struct audio_output *audio_output,
97 98
				  const struct audio_format *audio_format,
				  ConfigParam *param)
Avuton Olrich's avatar
Avuton Olrich committed
99
{
Max Kellermann's avatar
Max Kellermann committed
100
	struct shout_data *sd;
Avuton Olrich's avatar
Avuton Olrich committed
101
	char *test;
102
	int port;
Avuton Olrich's avatar
Avuton Olrich committed
103 104 105
	char *host;
	char *mount;
	char *passwd;
106
	const char *encoding;
107
	unsigned protocol;
Max Kellermann's avatar
Max Kellermann committed
108
	const char *user;
Avuton Olrich's avatar
Avuton Olrich committed
109
	char *name;
Max Kellermann's avatar
Max Kellermann committed
110
	BlockParam *block_param;
111
	int public;
112

Max Kellermann's avatar
Max Kellermann committed
113
	sd = new_shout_data();
114
	sd->audio_output = audio_output;
115

Max Kellermann's avatar
Max Kellermann committed
116
	if (shout_init_count == 0)
Avuton Olrich's avatar
Avuton Olrich committed
117
		shout_init();
118

Max Kellermann's avatar
Max Kellermann committed
119
	shout_init_count++;
120

Max Kellermann's avatar
Max Kellermann committed
121 122
	check_block_param("host");
	host = block_param->value;
123

Max Kellermann's avatar
Max Kellermann committed
124 125
	check_block_param("mount");
	mount = block_param->value;
126

Max Kellermann's avatar
Max Kellermann committed
127
	check_block_param("port");
128

Max Kellermann's avatar
Max Kellermann committed
129
	port = strtol(block_param->value, &test, 10);
130

Avuton Olrich's avatar
Avuton Olrich committed
131
	if (*test != '\0' || port <= 0) {
132
		FATAL("shout port \"%s\" is not a positive integer, line %i\n",
Max Kellermann's avatar
Max Kellermann committed
133
		      block_param->value, block_param->line);
134 135
	}

Max Kellermann's avatar
Max Kellermann committed
136 137
	check_block_param("password");
	passwd = block_param->value;
138

Max Kellermann's avatar
Max Kellermann committed
139 140
	check_block_param("name");
	name = block_param->value;
141

142 143 144
	public = getBoolBlockParam(param, "public", 1);
	if (public == CONF_BOOL_UNSET)
		public = 0;
145

Max Kellermann's avatar
Max Kellermann committed
146 147 148
	block_param = getBlockParam(param, "user");
	if (block_param)
		user = block_param->value;
Avuton Olrich's avatar
Avuton Olrich committed
149 150
	else
		user = "source";
151

Max Kellermann's avatar
Max Kellermann committed
152
	block_param = getBlockParam(param, "quality");
153

Max Kellermann's avatar
Max Kellermann committed
154 155
	if (block_param) {
		int line = block_param->line;
156

Max Kellermann's avatar
Max Kellermann committed
157
		sd->quality = strtod(block_param->value, &test);
158

159
		if (*test != '\0' || sd->quality < -1.0 || sd->quality > 10.0) {
160
			FATAL("shout quality \"%s\" is not a number in the "
Max Kellermann's avatar
Max Kellermann committed
161 162
			      "range -1 to 10, line %i\n", block_param->value,
			      block_param->line);
163 164
		}

Max Kellermann's avatar
Max Kellermann committed
165
		block_param = getBlockParam(param, "bitrate");
166

Max Kellermann's avatar
Max Kellermann committed
167
		if (block_param) {
168
			FATAL("quality (line %i) and bitrate (line %i) are "
Avuton Olrich's avatar
Avuton Olrich committed
169
			      "both defined for shout output\n", line,
Max Kellermann's avatar
Max Kellermann committed
170
			      block_param->line);
171
		}
Avuton Olrich's avatar
Avuton Olrich committed
172
	} else {
Max Kellermann's avatar
Max Kellermann committed
173
		block_param = getBlockParam(param, "bitrate");
174

Max Kellermann's avatar
Max Kellermann committed
175
		if (!block_param) {
176
			FATAL("neither bitrate nor quality defined for shout "
Avuton Olrich's avatar
Avuton Olrich committed
177
			      "output at line %i\n", param->line);
178 179
		}

Max Kellermann's avatar
Max Kellermann committed
180
		sd->bitrate = strtol(block_param->value, &test, 10);
181

Avuton Olrich's avatar
Avuton Olrich committed
182
		if (*test != '\0' || sd->bitrate <= 0) {
183
			FATAL("bitrate at line %i should be a positive integer "
Max Kellermann's avatar
Max Kellermann committed
184
			      "\n", block_param->line);
185
		}
186 187
	}

Max Kellermann's avatar
Max Kellermann committed
188
	check_block_param("format");
189 190 191

	assert(audio_format != NULL);
	sd->audio_format = *audio_format;
Max Kellermann's avatar
Max Kellermann committed
192

193 194
	block_param = getBlockParam(param, "encoding");
	if (block_param) {
195
		if (0 == strcmp(block_param->value, "mp3"))
196
			encoding = block_param->value;
197
		else if (0 == strcmp(block_param->value, "ogg"))
198 199 200 201 202 203 204 205
			encoding = block_param->value;
		else
			FATAL("shout encoding \"%s\" is not \"ogg\" or "
			      "\"mp3\", line %i\n", block_param->value,
			      block_param->line);
	} else {
		encoding = "ogg";
	}
206 207 208

	sd->encoder = shout_encoder_plugin_get(encoding);
	if (sd->encoder == NULL)
209 210 211
		FATAL("couldn't find shout encoder plugin for \"%s\" "
		      "at line %i\n", encoding, block_param->line);

212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
	block_param = getBlockParam(param, "protocol");
	if (block_param) {
		if (0 == strcmp(block_param->value, "shoutcast") &&
		    0 != strcmp(encoding, "mp3"))
			FATAL("you cannot stream \"%s\" to shoutcast, use mp3\n",
			      encoding);
		else if (0 == strcmp(block_param->value, "shoutcast"))
			protocol = SHOUT_PROTOCOL_ICY;
		else if (0 == strcmp(block_param->value, "icecast1"))
			protocol = SHOUT_PROTOCOL_XAUDIOCAST;
		else if (0 == strcmp(block_param->value, "icecast2"))
			protocol = SHOUT_PROTOCOL_HTTP;
		else
			FATAL("shout protocol \"%s\" is not \"shoutcast\" or "
			      "\"icecast1\"or "
			      "\"icecast2\", line %i\n", block_param->value,
			      block_param->line);
	} else {
		protocol = SHOUT_PROTOCOL_HTTP;
	}

Max Kellermann's avatar
Max Kellermann committed
233 234 235 236 237 238 239 240
	if (shout_set_host(sd->shout_conn, host) != SHOUTERR_SUCCESS ||
	    shout_set_port(sd->shout_conn, port) != SHOUTERR_SUCCESS ||
	    shout_set_password(sd->shout_conn, passwd) != SHOUTERR_SUCCESS ||
	    shout_set_mount(sd->shout_conn, mount) != SHOUTERR_SUCCESS ||
	    shout_set_name(sd->shout_conn, name) != SHOUTERR_SUCCESS ||
	    shout_set_user(sd->shout_conn, user) != SHOUTERR_SUCCESS ||
	    shout_set_public(sd->shout_conn, public) != SHOUTERR_SUCCESS ||
	    shout_set_nonblocking(sd->shout_conn, 1) != SHOUTERR_SUCCESS ||
241
	    shout_set_format(sd->shout_conn, sd->encoder->shout_format)
Avuton Olrich's avatar
Avuton Olrich committed
242
	    != SHOUTERR_SUCCESS ||
243
	    shout_set_protocol(sd->shout_conn, protocol) != SHOUTERR_SUCCESS ||
Max Kellermann's avatar
Max Kellermann committed
244
	    shout_set_agent(sd->shout_conn, "MPD") != SHOUTERR_SUCCESS) {
245
		FATAL("error configuring shout defined at line %i: %s\n",
Max Kellermann's avatar
Max Kellermann committed
246
		      param->line, shout_get_error(sd->shout_conn));
247
	}
248

249
	/* optional paramters */
Max Kellermann's avatar
Max Kellermann committed
250 251 252
	block_param = getBlockParam(param, "timeout");
	if (block_param) {
		sd->timeout = (int)strtol(block_param->value, &test, 10);
253 254
		if (*test != '\0' || sd->timeout <= 0) {
			FATAL("shout timeout is not a positive integer, "
Max Kellermann's avatar
Max Kellermann committed
255
			      "line %i\n", block_param->line);
256 257 258
		}
	}

Max Kellermann's avatar
Max Kellermann committed
259 260
	block_param = getBlockParam(param, "genre");
	if (block_param && shout_set_genre(sd->shout_conn, block_param->value)) {
261
		FATAL("error configuring shout defined at line %i: %s\n",
Max Kellermann's avatar
Max Kellermann committed
262
		      param->line, shout_get_error(sd->shout_conn));
263 264
	}

Max Kellermann's avatar
Max Kellermann committed
265 266 267
	block_param = getBlockParam(param, "description");
	if (block_param && shout_set_description(sd->shout_conn,
						 block_param->value)) {
268
		FATAL("error configuring shout defined at line %i: %s\n",
Max Kellermann's avatar
Max Kellermann committed
269
		      param->line, shout_get_error(sd->shout_conn));
270 271
	}

272 273 274
	{
		char temp[11];
		memset(temp, 0, sizeof(temp));
Avuton Olrich's avatar
Avuton Olrich committed
275

276
		snprintf(temp, sizeof(temp), "%u", sd->audio_format.channels);
Max Kellermann's avatar
Max Kellermann committed
277
		shout_set_audio_info(sd->shout_conn, SHOUT_AI_CHANNELS, temp);
278

279
		snprintf(temp, sizeof(temp), "%u", sd->audio_format.sample_rate);
Avuton Olrich's avatar
Avuton Olrich committed
280

Max Kellermann's avatar
Max Kellermann committed
281
		shout_set_audio_info(sd->shout_conn, SHOUT_AI_SAMPLERATE, temp);
282

283
		if (sd->quality >= -1.0) {
284
			snprintf(temp, sizeof(temp), "%2.2f", sd->quality);
Max Kellermann's avatar
Max Kellermann committed
285
			shout_set_audio_info(sd->shout_conn, SHOUT_AI_QUALITY,
Avuton Olrich's avatar
Avuton Olrich committed
286 287
					     temp);
		} else {
288
			snprintf(temp, sizeof(temp), "%d", sd->bitrate);
Max Kellermann's avatar
Max Kellermann committed
289
			shout_set_audio_info(sd->shout_conn, SHOUT_AI_BITRATE,
Avuton Olrich's avatar
Avuton Olrich committed
290
					     temp);
291 292 293
		}
	}

294 295 296
	if (sd->encoder->init_func(sd) != 0)
		FATAL("shout: encoder plugin '%s' failed to initialize\n",
		      sd->encoder->name);
297

298
	return sd;
299 300
}

Max Kellermann's avatar
Max Kellermann committed
301
static int handle_shout_error(struct shout_data *sd, int err)
Avuton Olrich's avatar
Avuton Olrich committed
302 303
{
	switch (err) {
304 305 306 307
	case SHOUTERR_SUCCESS:
		break;
	case SHOUTERR_UNCONNECTED:
	case SHOUTERR_SOCKET:
308
		ERROR("Lost shout connection to %s:%i: %s\n",
Max Kellermann's avatar
Max Kellermann committed
309 310 311 312
		      shout_get_host(sd->shout_conn),
		      shout_get_port(sd->shout_conn),
		      shout_get_error(sd->shout_conn));
		sd->shout_error = 1;
313 314
		return -1;
	default:
315
		ERROR("shout: connection to %s:%i error: %s\n",
Max Kellermann's avatar
Max Kellermann committed
316 317 318 319
		      shout_get_host(sd->shout_conn),
		      shout_get_port(sd->shout_conn),
		      shout_get_error(sd->shout_conn));
		sd->shout_error = 1;
320 321 322 323 324 325
		return -1;
	}

	return 0;
}

326
static int write_page(struct shout_data *sd)
Avuton Olrich's avatar
Avuton Olrich committed
327
{
328
	int err;
329

330 331 332
	if (sd->buf.len == 0)
		return 0;

Max Kellermann's avatar
Max Kellermann committed
333
	shout_sync(sd->shout_conn);
334
	err = shout_send(sd->shout_conn, sd->buf.data, sd->buf.len);
Max Kellermann's avatar
Max Kellermann committed
335
	if (handle_shout_error(sd, err) < 0)
Avuton Olrich's avatar
Avuton Olrich committed
336
		return -1;
337
	sd->buf.len = 0;
338 339 340 341

	return 0;
}

342
static void close_shout_conn(struct shout_data * sd)
Avuton Olrich's avatar
Avuton Olrich committed
343
{
344
	if (sd->opened) {
345
		if (sd->encoder->clear_encoder_func(sd))
346 347
			write_page(sd);
	}
348

Max Kellermann's avatar
Max Kellermann committed
349 350
	if (shout_get_connected(sd->shout_conn) != SHOUTERR_UNCONNECTED &&
	    shout_close(sd->shout_conn) != SHOUTERR_SUCCESS) {
351
		ERROR("problem closing connection to shout server: %s\n",
Max Kellermann's avatar
Max Kellermann committed
352
		      shout_get_error(sd->shout_conn));
353 354
	}

355
	sd->opened = false;
356 357
}

358
static void my_shout_finish_driver(void *data)
Avuton Olrich's avatar
Avuton Olrich committed
359
{
360
	struct shout_data *sd = (struct shout_data *)data;
361

Max Kellermann's avatar
Max Kellermann committed
362
	close_shout_conn(sd);
363

364
	sd->encoder->finish_func(sd);
Max Kellermann's avatar
Max Kellermann committed
365
	free_shout_data(sd);
366

Max Kellermann's avatar
Max Kellermann committed
367
	shout_init_count--;
368

Max Kellermann's avatar
Max Kellermann committed
369
	if (shout_init_count == 0)
Avuton Olrich's avatar
Avuton Olrich committed
370
		shout_shutdown();
371 372
}

373
static void my_shout_drop_buffered_audio(void *data)
Avuton Olrich's avatar
Avuton Olrich committed
374
{
375
	struct shout_data *sd = (struct shout_data *)data;
376 377 378
	timer_reset(sd->timer);

	/* needs to be implemented for shout */
379 380
}

381
static void my_shout_close_device(void *data)
Avuton Olrich's avatar
Avuton Olrich committed
382
{
383
	struct shout_data *sd = (struct shout_data *)data;
384

Max Kellermann's avatar
Max Kellermann committed
385
	close_shout_conn(sd);
386

Max Kellermann's avatar
Max Kellermann committed
387
	if (sd->timer) {
388 389 390
		timer_free(sd->timer);
		sd->timer = NULL;
	}
391
}
392

Max Kellermann's avatar
Max Kellermann committed
393
static int shout_connect(struct shout_data *sd)
Avuton Olrich's avatar
Avuton Olrich committed
394
{
395
	time_t t = time(NULL);
Max Kellermann's avatar
Max Kellermann committed
396
	int state = shout_get_connected(sd->shout_conn);
397 398 399 400 401 402

	/* already connected */
	if (state == SHOUTERR_CONNECTED)
		return 0;

	/* waiting to connect */
Max Kellermann's avatar
Max Kellermann committed
403
	if (state == SHOUTERR_BUSY && sd->conn_attempts != 0) {
404
		/* timeout waiting to connect */
Max Kellermann's avatar
Max Kellermann committed
405
		if ((t - sd->last_attempt) > sd->timeout) {
406 407
			ERROR("timeout connecting to shout server %s:%i "
			      "(attempt %i)\n",
Max Kellermann's avatar
Max Kellermann committed
408 409 410
			      shout_get_host(sd->shout_conn),
			      shout_get_port(sd->shout_conn),
			      sd->conn_attempts);
411 412 413 414 415 416 417 418
			return -1;
		}

		return 1;
	}

	/* we're in some funky state, so just reset it to unconnected */
	if (state != SHOUTERR_UNCONNECTED)
Max Kellermann's avatar
Max Kellermann committed
419
		shout_close(sd->shout_conn);
420

421
	/* throttle new connection attempts */
Max Kellermann's avatar
Max Kellermann committed
422 423
	if (sd->conn_attempts != 0 &&
	    (t - sd->last_attempt) <= CONN_ATTEMPT_INTERVAL) {
424 425 426
		return -1;
	}

427 428
	/* initiate a new connection */

Max Kellermann's avatar
Max Kellermann committed
429 430
	sd->conn_attempts++;
	sd->last_attempt = t;
431

Max Kellermann's avatar
Max Kellermann committed
432
	state = shout_open(sd->shout_conn);
433
	switch (state) {
434 435
	case SHOUTERR_SUCCESS:
	case SHOUTERR_CONNECTED:
436
		return 0;
437
	case SHOUTERR_BUSY:
438
		return 1;
439
	default:
440
		ERROR("problem opening connection to shout server %s:%i "
Avuton Olrich's avatar
Avuton Olrich committed
441
		      "(attempt %i): %s\n",
Max Kellermann's avatar
Max Kellermann committed
442 443 444
		      shout_get_host(sd->shout_conn),
		      shout_get_port(sd->shout_conn),
		      sd->conn_attempts, shout_get_error(sd->shout_conn));
445 446
		return -1;
	}
447 448
}

449
static int open_shout_conn(void *data)
450
{
451
	struct shout_data *sd = (struct shout_data *)data;
452 453
	int status;

Max Kellermann's avatar
Max Kellermann committed
454
	status = shout_connect(sd);
455 456
	if (status != 0)
		return status;
457

458
	if (sd->encoder->init_encoder_func(sd) < 0) {
Max Kellermann's avatar
Max Kellermann committed
459
		shout_close(sd->shout_conn);
460 461 462
		return -1;
	}

463
	write_page(sd);
464

465
	sd->shout_error = 0;
466
	sd->opened = true;
467
	sd->tag_to_send = 1;
Max Kellermann's avatar
Max Kellermann committed
468
	sd->conn_attempts = 0;
469

470 471 472
	return 0;
}

473
static bool my_shout_open_device(void *data,
474
				struct audio_format *audio_format)
Avuton Olrich's avatar
Avuton Olrich committed
475
{
476
	struct shout_data *sd = (struct shout_data *)data;
477

478
	if (!sd->opened && open_shout_conn(sd) < 0)
479
		return false;
480

481 482 483
	if (sd->timer)
		timer_free(sd->timer);

484
	sd->timer = timer_new(audio_format);
485

486
	return true;
487 488
}

Max Kellermann's avatar
Max Kellermann committed
489
static void send_metadata(struct shout_data * sd)
Avuton Olrich's avatar
Avuton Olrich committed
490
{
491 492 493
	static const int size = 1024;
	char song[size];

Avuton Olrich's avatar
Avuton Olrich committed
494 495
	if (!sd->opened || !sd->tag)
		return;
496

497
	if (sd->encoder->send_metadata_func(sd, song, size)) {
498 499 500 501 502 503
		shout_metadata_add(sd->shout_meta, "song", song);
		if (SHOUTERR_SUCCESS != shout_set_metadata(sd->shout_conn,
							   sd->shout_meta)) {
			ERROR("error setting shout metadata\n");
			return;
		}
504 505
	}

Max Kellermann's avatar
Max Kellermann committed
506
	sd->tag_to_send = 0;
507 508
}

509 510
static bool
my_shout_play(void *data, const char *chunk, size_t size)
Avuton Olrich's avatar
Avuton Olrich committed
511
{
512
	struct shout_data *sd = (struct shout_data *)data;
513 514 515 516 517 518
	int status;

	if (!sd->timer->started)
		timer_start(sd->timer);

	timer_add(sd->timer, size);
519

Max Kellermann's avatar
Max Kellermann committed
520 521
	if (sd->opened && sd->tag_to_send)
		send_metadata(sd);
522

523
	if (!sd->opened) {
524
		status = open_shout_conn(sd);
525
		if (status < 0) {
526
			return false;
527 528
		} else if (status > 0) {
			timer_sync(sd->timer);
529
			return true;
530
		}
531 532
	}

533
	if (sd->encoder->encode_func(sd, chunk, size))
534
		return false;
535

536
	if (write_page(sd) < 0)
537
		return false;
Warren Dukes's avatar
Warren Dukes committed
538

539
	return true;
540 541
}

542 543 544 545 546 547 548 549 550 551 552 553 554 555 556
static void my_shout_pause(void *data)
{
	struct shout_data *sd = (struct shout_data *)data;
	static const char silence[1020];
	int ret;

	/* play silence until the player thread sends us a command */

	while (sd->opened && !audio_output_is_pending(sd->audio_output)) {
		ret = my_shout_play(data, silence, sizeof(silence));
		if (ret != 0)
			break;
	}
}

557
static void my_shout_set_tag(void *data,
Max Kellermann's avatar
Max Kellermann committed
558
			     const struct tag *tag)
Avuton Olrich's avatar
Avuton Olrich committed
559
{
560
	struct shout_data *sd = (struct shout_data *)data;
561

Avuton Olrich's avatar
Avuton Olrich committed
562
	if (sd->tag)
563
		tag_free(sd->tag);
564
	sd->tag = NULL;
Max Kellermann's avatar
Max Kellermann committed
565
	sd->tag_to_send = 0;
566

Avuton Olrich's avatar
Avuton Olrich committed
567 568
	if (!tag)
		return;
569

570
	sd->tag = tag_dup(tag);
Max Kellermann's avatar
Max Kellermann committed
571
	sd->tag_to_send = 1;
572 573
}

574
const struct audio_output_plugin shoutPlugin = {
575 576 577 578 579
	.name = "shout",
	.init = my_shout_init_driver,
	.finish = my_shout_finish_driver,
	.open = my_shout_open_device,
	.play = my_shout_play,
580
	.pause = my_shout_pause,
581 582 583
	.cancel = my_shout_drop_buffered_audio,
	.close = my_shout_close_device,
	.send_tag = my_shout_set_tag,
584
};
Warren Dukes's avatar
Warren Dukes committed
585 586 587

#else

588
DISABLED_AUDIO_OUTPUT_PLUGIN(shoutPlugin)
Warren Dukes's avatar
Warren Dukes committed
589
#endif