diff options
author | waker <wakeroid@gmail.com> | 2011-01-10 20:31:54 +0100 |
---|---|---|
committer | waker <wakeroid@gmail.com> | 2011-01-10 21:02:40 +0100 |
commit | bad68f332469178ffb81a0dd2ac74ae62301af72 (patch) | |
tree | c6b2d0387a145511d12198e9035368cb8b178f3b | |
parent | 822c99debf259c6648654143abc9d772ea447f73 (diff) |
fixed resume in paused state;
changed output plugin setformat method to return error code
changed setformat to restore state before the call
-rw-r--r-- | deadbeef.h | 4 | ||||
-rw-r--r-- | plugins/alsa/alsa.c | 29 | ||||
-rw-r--r-- | plugins/nullout/nullout.c | 5 | ||||
-rw-r--r-- | plugins/oss/oss.c | 51 | ||||
-rw-r--r-- | streamer.c | 6 |
5 files changed, 69 insertions, 26 deletions
@@ -734,8 +734,8 @@ typedef struct DB_output_s { int (*init) (void); // free is called if output plugin was changed to another, or unload is about to happen int (*free) (void); - // reconfigure output to another format, if supported - void (*setformat) (ddb_waveformat_t *fmt); + // reconfigure output to another format + int (*setformat) (ddb_waveformat_t *fmt); // play, stop, pause, unpause are called by deadbeef in response to user // events, or as part of streaming process int (*play) (void); diff --git a/plugins/alsa/alsa.c b/plugins/alsa/alsa.c index 7a4d12ef..d76d821f 100644 --- a/plugins/alsa/alsa.c +++ b/plugins/alsa/alsa.c @@ -88,7 +88,7 @@ palsa_init (void); static int palsa_free (void); -static void +static int palsa_setformat (ddb_waveformat_t *fmt); static int @@ -403,16 +403,16 @@ open_error: return -1; } -void +int palsa_setformat (ddb_waveformat_t *fmt) { memcpy (&requested_fmt, fmt, sizeof (ddb_waveformat_t)); trace ("palsa_setformat %dbit %s %dch %dHz channelmask=%X\n", fmt->bps, fmt->is_float ? "float" : "int", fmt->channels, fmt->samplerate, fmt->channelmask); if (!audio) { - return; + return -1; } if (!memcmp (fmt, &plugin.fmt, sizeof (ddb_waveformat_t))) { trace ("palsa_setformat ignored\n"); - return; + return 0; } #if 0 else { @@ -432,16 +432,33 @@ palsa_setformat (ddb_waveformat_t *fmt) { ); } #endif - state = OUTPUT_STATE_STOPPED; LOCK; + int s = state; + state = OUTPUT_STATE_STOPPED; snd_pcm_drop (audio); int ret = palsa_set_hw_params (fmt); UNLOCK; if (ret < 0) { trace ("palsa_change_rate: impossible to set requested format\n"); - return; + return -1; } trace ("new format %dbit %s %dch %dHz channelmask=%X\n", plugin.fmt.bps, plugin.fmt.is_float ? "float" : "int", plugin.fmt.channels, plugin.fmt.samplerate, plugin.fmt.channelmask); + + switch (s) { + case OUTPUT_STATE_STOPPED: + return palsa_stop (); + case OUTPUT_STATE_PLAYING: + return palsa_play (); + case OUTPUT_STATE_PAUSED: + if (0 != palsa_play ()) { + return -1; + } + if (0 != palsa_pause ()) { + return -1; + } + break; + } + return 0; } int diff --git a/plugins/nullout/nullout.c b/plugins/nullout/nullout.c index fa9ef5ed..4fbd6a0c 100644 --- a/plugins/nullout/nullout.c +++ b/plugins/nullout/nullout.c @@ -46,7 +46,7 @@ pnull_init (void); static int pnull_free (void); -void +int pnull_setformat (ddb_waveformat_t *fmt); static int @@ -70,9 +70,10 @@ pnull_init (void) { return 0; } -void +int pnull_setformat (ddb_waveformat_t *fmt) { memcpy (&plugin.fmt, fmt, sizeof (ddb_waveformat_t)); + return 0; } int diff --git a/plugins/oss/oss.c b/plugins/oss/oss.c index ccc0d32c..d9e99f96 100644 --- a/plugins/oss/oss.c +++ b/plugins/oss/oss.c @@ -147,22 +147,6 @@ oss_init (void) { return 0; } -static void -oss_setformat (ddb_waveformat_t *fmt) { - trace ("oss_setformat\n"); - if (!fd) { - memcpy (&plugin.fmt, fmt, sizeof (ddb_waveformat_t)); - } - if (!memcmp (fmt, &plugin.fmt, sizeof (ddb_waveformat_t))) { - return; - } - deadbeef->mutex_lock (mutex); - - oss_set_hwparams (fmt); - - deadbeef->mutex_unlock (mutex); -} - static int oss_free (void) { trace ("oss_free\n"); @@ -215,6 +199,41 @@ oss_pause (void) { return 0; } + +static int +oss_setformat (ddb_waveformat_t *fmt) { + trace ("oss_setformat\n"); + if (!fd) { + memcpy (&plugin.fmt, fmt, sizeof (ddb_waveformat_t)); + } + if (!memcmp (fmt, &plugin.fmt, sizeof (ddb_waveformat_t))) { + return 0; + } + deadbeef->mutex_lock (mutex); + + if (0 != oss_set_hwparams (fmt)) { + return -1; + } + + deadbeef->mutex_unlock (mutex); + + switch (state) { + case OUTPUT_STATE_STOPPED: + return oss_stop (); + case OUTPUT_STATE_PLAYING: + return oss_play (); + case OUTPUT_STATE_PAUSED: + if (0 != oss_play ()) { + return -1; + } + if (0 != oss_pause ()) { + return -1; + } + break; + } + return 0; +} + static int oss_unpause (void) { oss_play (); @@ -857,6 +857,12 @@ streamer_start_new_song (void) { memcpy (&output_format, &fileinfo->fmt, sizeof (ddb_waveformat_t)); formatchanged = 1; } + // we need to start playback before we can pause it + if (0 != output->play ()) { + memset (&output_format, 0, sizeof (output_format)); + fprintf (stderr, "streamer: failed to start playback (start track)\n"); + streamer_set_nextsong (-2, 0); + } } output->pause (); } |