예제 #1
0
파일: output_control.c 프로젝트: ion1/mpd
void audio_output_finish(struct audio_output *ao)
{
	audio_output_close(ao);

	assert(ao->fail_timer == NULL);

	if (ao->thread != NULL) {
		g_mutex_lock(ao->mutex);
		ao_command(ao, AO_COMMAND_KILL);
		g_mutex_unlock(ao->mutex);
		g_thread_join(ao->thread);
	}

	if (ao->mixer != NULL)
		mixer_free(ao->mixer);

	ao_plugin_finish(ao->plugin, ao->data);

	g_cond_free(ao->cond);
	g_mutex_free(ao->mutex);

	if (ao->replay_gain_filter != NULL)
		filter_free(ao->replay_gain_filter);

	if (ao->other_replay_gain_filter != NULL)
		filter_free(ao->other_replay_gain_filter);

	filter_free(ao->filter);

	pcm_buffer_deinit(&ao->cross_fade_buffer);
}
예제 #2
0
void
audio_output_free(struct audio_output *ao)
{
	assert(!ao->open);
	assert(ao->fail_timer == NULL);
	assert(ao->thread == NULL);

	ao_plugin_finish(ao);
}
예제 #3
0
int main(int argc, char **argv)
{
	struct audio_output ao;
	struct audio_format audio_format;
	struct audio_format_string af_string;
	bool success;
	GError *error = NULL;
	char buffer[4096];
	ssize_t nbytes;
	size_t frame_size, length = 0, play_length, consumed;

	if (argc < 3 || argc > 4) {
		g_printerr("Usage: run_output CONFIG NAME [FORMAT] <IN\n");
		return 1;
	}

	audio_format_init(&audio_format, 44100, SAMPLE_FORMAT_S16, 2);

	g_thread_init(NULL);

	/* read configuration file (mpd.conf) */

	config_global_init();
	success = config_read_file(argv[1], &error);
	if (!success) {
		g_printerr("%s:", error->message);
		g_error_free(error);
		return 1;
	}

	/* initialize the audio output */

	if (!load_audio_output(&ao, argv[2]))
		return 1;

	/* parse the audio format */

	if (argc > 3) {
		success = audio_format_parse(&audio_format, argv[3],
					     false, &error);
		if (!success) {
			g_printerr("Failed to parse audio format: %s\n",
				   error->message);
			g_error_free(error);
			return 1;
		}
	}

	/* open the audio output */

	success = ao_plugin_open(ao.plugin, ao.data, &audio_format, &error);
	if (!success) {
		g_printerr("Failed to open audio output: %s\n",
			   error->message);
		g_error_free(error);
		return 1;
	}

	g_printerr("audio_format=%s\n",
		   audio_format_to_string(&audio_format, &af_string));

	frame_size = audio_format_frame_size(&audio_format);

	/* play */

	while (true) {
		if (length < sizeof(buffer)) {
			nbytes = read(0, buffer + length, sizeof(buffer) - length);
			if (nbytes <= 0)
				break;

			length += (size_t)nbytes;
		}

		play_length = (length / frame_size) * frame_size;
		if (play_length > 0) {
			consumed = ao_plugin_play(ao.plugin, ao.data,
						  buffer, play_length,
						  &error);
			if (consumed == 0) {
				g_printerr("Failed to play: %s\n",
					   error->message);
				g_error_free(error);
				return 1;
			}

			assert(consumed <= length);
			assert(consumed % frame_size == 0);

			length -= consumed;
			memmove(buffer, buffer + consumed, length);
		}
	}

	/* cleanup and exit */

	ao_plugin_close(ao.plugin, ao.data);
	ao_plugin_finish(ao.plugin, ao.data);
	g_mutex_free(ao.mutex);

	config_global_finish();

	return 0;
}