output_api: moved the command check out of method pause()
Move the "while" loop which checks for commands to the caller ao_pause(). This simplifies the pause() method, and lets us remove audio_output_is_pending().
This commit is contained in:
		| @@ -506,19 +506,12 @@ my_shout_play(void *data, const char *chunk, size_t size) | |||||||
| 	return true; | 	return true; | ||||||
| } | } | ||||||
|  |  | ||||||
| static void my_shout_pause(void *data) | static bool | ||||||
|  | my_shout_pause(void *data) | ||||||
| { | { | ||||||
| 	struct shout_data *sd = (struct shout_data *)data; |  | ||||||
| 	static const char silence[1020]; | 	static const char silence[1020]; | ||||||
| 	int ret; |  | ||||||
|  |  | ||||||
| 	/* play silence until the player thread sends us a command */ | 	return my_shout_play(data, silence, sizeof(silence)); | ||||||
|  |  | ||||||
| 	while (sd->opened && !audio_output_is_pending(sd->audio_output)) { |  | ||||||
| 		ret = my_shout_play(data, silence, sizeof(silence)); |  | ||||||
| 		if (ret != 0) |  | ||||||
| 			break; |  | ||||||
| 	} |  | ||||||
| } | } | ||||||
|  |  | ||||||
| static void my_shout_set_tag(void *data, | static void my_shout_set_tag(void *data, | ||||||
|   | |||||||
| @@ -19,14 +19,7 @@ | |||||||
| #include "output_api.h" | #include "output_api.h" | ||||||
| #include "output_internal.h" | #include "output_internal.h" | ||||||
|  |  | ||||||
| #include <assert.h> |  | ||||||
|  |  | ||||||
| const char *audio_output_get_name(const struct audio_output *ao) | const char *audio_output_get_name(const struct audio_output *ao) | ||||||
| { | { | ||||||
| 	return ao->name; | 	return ao->name; | ||||||
| } | } | ||||||
|  |  | ||||||
| bool audio_output_is_pending(const struct audio_output *ao) |  | ||||||
| { |  | ||||||
| 	return ao->command != AO_COMMAND_NONE; |  | ||||||
| } |  | ||||||
|   | |||||||
| @@ -84,8 +84,11 @@ struct audio_output_plugin { | |||||||
| 	 * silence during pause, so their clients won't be | 	 * silence during pause, so their clients won't be | ||||||
| 	 * disconnected.  Plugins which do not support pausing will | 	 * disconnected.  Plugins which do not support pausing will | ||||||
| 	 * simply be closed, and have to be reopened when unpaused. | 	 * simply be closed, and have to be reopened when unpaused. | ||||||
|  | 	 * | ||||||
|  | 	 * @return false on error (output will be closed then), true | ||||||
|  | 	 * for continue to pause | ||||||
| 	 */ | 	 */ | ||||||
| 	void (*pause)(void *data); | 	bool (*pause)(void *data); | ||||||
|  |  | ||||||
| 	/** | 	/** | ||||||
| 	 * Try to cancel data which may still be in the device's | 	 * Try to cancel data which may still be in the device's | ||||||
| @@ -131,9 +134,4 @@ struct audio_output; | |||||||
|  |  | ||||||
| const char *audio_output_get_name(const struct audio_output *ao); | const char *audio_output_get_name(const struct audio_output *ao); | ||||||
|  |  | ||||||
| /** |  | ||||||
|  * Returns true if there is a command pending. |  | ||||||
|  */ |  | ||||||
| bool audio_output_is_pending(const struct audio_output *ao); |  | ||||||
|  |  | ||||||
| #endif | #endif | ||||||
|   | |||||||
| @@ -77,7 +77,17 @@ static void ao_pause(struct audio_output *ao) | |||||||
| 	if (ao->plugin->pause != NULL) { | 	if (ao->plugin->pause != NULL) { | ||||||
| 		/* pause is supported */ | 		/* pause is supported */ | ||||||
| 		ao_command_finished(ao); | 		ao_command_finished(ao); | ||||||
| 		ao->plugin->pause(ao->data); |  | ||||||
|  | 		do { | ||||||
|  | 			bool ret; | ||||||
|  |  | ||||||
|  | 			ret = ao->plugin->pause(ao->data); | ||||||
|  | 			if (!ret) { | ||||||
|  | 				ao->plugin->close(ao->data); | ||||||
|  | 				pcm_convert_deinit(&ao->convState); | ||||||
|  | 				ao->open = false; | ||||||
|  | 			} | ||||||
|  | 		} while (ao->command == AO_COMMAND_NONE); | ||||||
| 	} else { | 	} else { | ||||||
| 		/* pause is not supported - simply close the device */ | 		/* pause is not supported - simply close the device */ | ||||||
| 		ao->plugin->close(ao->data); | 		ao->plugin->close(ao->data); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Max Kellermann
					Max Kellermann