output/oss: remember the real OSS format

Improving oss_reopen() by using the very same value that was used
initially.
This commit is contained in:
Max Kellermann 2012-03-21 23:47:29 +01:00
parent 51dce3d161
commit 921cc3e5db

View File

@ -71,6 +71,12 @@ struct oss_data {
* the device after cancel(). * the device after cancel().
*/ */
struct audio_format audio_format; struct audio_format audio_format;
/**
* The current OSS audio format. This is needed to reopen the
* device after cancel().
*/
int oss_format;
}; };
/** /**
@ -504,6 +510,7 @@ sample_format_from_oss(int format)
static enum oss_setup_result static enum oss_setup_result
oss_probe_sample_format(int fd, enum sample_format sample_format, oss_probe_sample_format(int fd, enum sample_format sample_format,
enum sample_format *sample_format_r, enum sample_format *sample_format_r,
int *oss_format_r,
#ifdef AFMT_S24_PACKED #ifdef AFMT_S24_PACKED
struct pcm_export_state *export, struct pcm_export_state *export,
#endif #endif
@ -525,6 +532,7 @@ oss_probe_sample_format(int fd, enum sample_format sample_format,
return UNSUPPORTED; return UNSUPPORTED;
*sample_format_r = sample_format; *sample_format_r = sample_format;
*oss_format_r = oss_format;
#ifdef AFMT_S24_PACKED #ifdef AFMT_S24_PACKED
pcm_export_open(export, sample_format, pcm_export_open(export, sample_format,
@ -541,6 +549,7 @@ oss_probe_sample_format(int fd, enum sample_format sample_format,
*/ */
static bool static bool
oss_setup_sample_format(int fd, struct audio_format *audio_format, oss_setup_sample_format(int fd, struct audio_format *audio_format,
int *oss_format_r,
#ifdef AFMT_S24_PACKED #ifdef AFMT_S24_PACKED
struct pcm_export_state *export, struct pcm_export_state *export,
#endif #endif
@ -549,7 +558,7 @@ oss_setup_sample_format(int fd, struct audio_format *audio_format,
enum sample_format mpd_format; enum sample_format mpd_format;
enum oss_setup_result result = enum oss_setup_result result =
oss_probe_sample_format(fd, audio_format->format, oss_probe_sample_format(fd, audio_format->format,
&mpd_format, &mpd_format, oss_format_r,
#ifdef AFMT_S24_PACKED #ifdef AFMT_S24_PACKED
export, export,
#endif #endif
@ -588,7 +597,7 @@ oss_setup_sample_format(int fd, struct audio_format *audio_format,
continue; continue;
result = oss_probe_sample_format(fd, mpd_format, result = oss_probe_sample_format(fd, mpd_format,
&mpd_format, &mpd_format, oss_format_r,
#ifdef AFMT_S24_PACKED #ifdef AFMT_S24_PACKED
export, export,
#endif #endif
@ -620,7 +629,7 @@ oss_setup(struct oss_data *od, struct audio_format *audio_format,
{ {
return oss_setup_channels(od->fd, audio_format, error_r) && return oss_setup_channels(od->fd, audio_format, error_r) &&
oss_setup_sample_rate(od->fd, audio_format, error_r) && oss_setup_sample_rate(od->fd, audio_format, error_r) &&
oss_setup_sample_format(od->fd, audio_format, oss_setup_sample_format(od->fd, audio_format, &od->oss_format,
#ifdef AFMT_S24_PACKED #ifdef AFMT_S24_PACKED
&od->export, &od->export,
#endif #endif
@ -668,9 +677,8 @@ oss_reopen(struct oss_data *od, GError **error_r)
} }
const char *const msg3 = "Failed to set sample format"; const char *const msg3 = "Failed to set sample format";
assert(sample_format_to_oss(od->audio_format.format) != AFMT_QUERY);
result = oss_try_ioctl(od->fd, SNDCTL_DSP_SAMPLESIZE, result = oss_try_ioctl(od->fd, SNDCTL_DSP_SAMPLESIZE,
sample_format_to_oss(od->audio_format.format), od->oss_format,
msg3, error_r); msg3, error_r);
if (result != SUCCESS) { if (result != SUCCESS) {
oss_close(od); oss_close(od);