summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar waker <wakeroid@gmail.com>2010-11-28 13:40:15 +0100
committerGravatar waker <wakeroid@gmail.com>2010-11-28 13:40:15 +0100
commit78cebdb0a267effe32fe196c04124692b04ec9db (patch)
tree4c4af33a04db4a3e0440240b9ad4d60a927c2c0d
parentaebe97dea65cbd451246d6fe71f362eef91ef2ac (diff)
optimized output format setting in streamer (also fixes gapless)
-rw-r--r--plugins/alsa/alsa.c20
-rw-r--r--streamer.c35
2 files changed, 26 insertions, 29 deletions
diff --git a/plugins/alsa/alsa.c b/plugins/alsa/alsa.c
index 2a36b015..15b8a539 100644
--- a/plugins/alsa/alsa.c
+++ b/plugins/alsa/alsa.c
@@ -182,7 +182,7 @@ palsa_set_hw_params (ddb_waveformat_t *fmt) {
}
snd_pcm_hw_params_get_format (hw_params, &sample_fmt);
- trace ("chosen sample format: %04Xh\n", (int)fmt);
+ trace ("chosen sample format: %04Xh\n", (int)sample_fmt);
int val = fmt->samplerate;
int ret = 0;
@@ -398,6 +398,24 @@ palsa_setformat (ddb_waveformat_t *fmt) {
trace ("palsa_setformat ignored\n");
return;
}
+#if 0
+ else {
+ trace ("switching format:\n"
+ "bps %d -> %d\n"
+ "is_float %d -> %d\n"
+ "is_multichannel %d -> %d\n"
+ "channels %d -> %d\n"
+ "samplerate %d -> %d\n"
+ "channelmask %d -> %d\n"
+ , fmt->bps, plugin.fmt.bps
+ , fmt->is_float, plugin.fmt.is_float
+ , fmt->is_multichannel, plugin.fmt.is_multichannel
+ , fmt->channels, plugin.fmt.channels
+ , fmt->samplerate, plugin.fmt.samplerate
+ , fmt->channelmask, plugin.fmt.channelmask
+ );
+ }
+#endif
state = OUTPUT_STATE_STOPPED;
LOCK;
snd_pcm_drop (audio);
diff --git a/streamer.c b/streamer.c
index 7aa747e6..0f315860 100644
--- a/streamer.c
+++ b/streamer.c
@@ -80,6 +80,7 @@ static playlist_t *streamer_playlist;
static playItem_t *playing_track;
static playItem_t *streaming_track;
static playItem_t *playlist_track;
+static ddb_waveformat_t prevformat;
static DB_fileinfo_t *fileinfo;
@@ -98,18 +99,6 @@ streamer_unlock (void) {
mutex_unlock (mutex);
}
-void
-adjust_waveformat (ddb_waveformat_t *fmt) {
- if (!fmt->is_multichannel) {
- if (fmt->channels == 1) {
- fmt->channelmask = DDB_SPEAKER_FRONT_LEFT;
- }
- else if (fmt->channelmask == 2) {
- fmt->channelmask = DDB_SPEAKER_FRONT_LEFT | DDB_SPEAKER_FRONT_RIGHT;
- }
- }
-}
-
static void
streamer_abort_files (void) {
if (fileinfo && fileinfo->file) {
@@ -632,10 +621,6 @@ streamer_set_current (playItem_t *it) {
dec->free (fileinfo);
fileinfo = NULL;
}
- else {
- adjust_waveformat (&fileinfo->fmt);
- }
-
}
if (!dec || !fileinfo) {
@@ -815,8 +800,8 @@ streamer_start_new_song (void) {
if (output->state () != OUTPUT_STATE_PLAYING) {
streamer_reset (1);
if (fileinfo) {
+ memcpy (&prevformat, &fileinfo->fmt, sizeof (ddb_waveformat_t));
plug_get_output ()->setformat (&fileinfo->fmt);
- adjust_waveformat (&plug_get_output ()->fmt);
}
if (output->play () < 0) {
fprintf (stderr, "streamer: failed to start playback; output plugin doesn't work\n");
@@ -830,8 +815,8 @@ streamer_start_new_song (void) {
avg_bitrate = -1;
streamer_reset (1);
if (fileinfo) {
+ memcpy (&prevformat, &fileinfo->fmt, sizeof (ddb_waveformat_t));
plug_get_output ()->setformat (&fileinfo->fmt);
- adjust_waveformat (&plug_get_output ()->fmt);
}
if (output->play () < 0) {
fprintf (stderr, "streamer: failed to start playback; output plugin doesn't work\n");
@@ -927,9 +912,9 @@ streamer_thread (void *ctx) {
// don't switch if unchanged
ddb_waveformat_t prevfmt;
memcpy (&prevfmt, &output->fmt, sizeof (ddb_waveformat_t));
- if (memcmp (&output->fmt, &fileinfo->fmt, sizeof (ddb_waveformat_t))) {
+ if (memcmp (&prevformat, &fileinfo->fmt, sizeof (ddb_waveformat_t))) {
+ memcpy (&prevformat, &fileinfo->fmt, sizeof (ddb_waveformat_t));
output->setformat (&fileinfo->fmt);
- adjust_waveformat (&output->fmt);
// check if the format actually changed
if (memcmp (&output->fmt, &prevfmt, sizeof (ddb_waveformat_t))) {
// restart streaming of current track
@@ -945,9 +930,6 @@ streamer_thread (void *ctx) {
dec->free (fileinfo);
fileinfo = NULL;
}
- else {
- adjust_waveformat (&fileinfo->fmt);
- }
}
if (!dec || !fileinfo) {
// FIXME: handle error
@@ -962,8 +944,8 @@ streamer_thread (void *ctx) {
// output plugin may stop playback before switching samplerate
if (output->state () != OUTPUT_STATE_PLAYING) {
if (fileinfo) {
+ memcpy (&prevformat, &fileinfo->fmt, sizeof (ddb_waveformat_t));
plug_get_output ()->setformat (&fileinfo->fmt);
- adjust_waveformat (&plug_get_output ()->fmt);
}
if (output->play () < 0) {
fprintf (stderr, "streamer: failed to start playback after samplerate change; output plugin doesn't work\n");
@@ -1015,9 +997,6 @@ streamer_thread (void *ctx) {
dec->free (fileinfo);
fileinfo = NULL;
}
- else {
- adjust_waveformat (&fileinfo->fmt);
- }
}
mutex_unlock (decodemutex);
@@ -1332,7 +1311,7 @@ streamer_read_async (char *bytes, int size) {
DB_dsp_t **dsp = deadbeef->plug_get_dsp_list ();
int outputsamplesize = (output->fmt.bps>>3)*output->fmt.channels;
int inputsamplesize = (fileinfo->fmt.bps>>3)*fileinfo->fmt.channels;
- if (!memcmp (&fileinfo->fmt, &output->fmt, sizeof (ddb_waveformat_t))) {
+ if (!memcmp (&fileinfo->fmt, &output->fmt, sizeof (ddb_waveformat_t)), 1) {
// pass through from input to output
bytesread = fileinfo->plugin->read (fileinfo, bytes, size);
if (bytesread != size) {