]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - alsa_write.c
configure.ac: para_client needs time.o.
[paraslash.git] / alsa_write.c
index 77621979783955dd09a48464cee6e9d7dceafbbb..658183eacafca7ba9385177185b72392cf78d3d0 100644 (file)
@@ -66,6 +66,7 @@ static int alsa_init(struct private_alsa_write_data *pad,
        snd_pcm_uframes_t period_size;
        int err;
 
+       PARA_INFO_LOG("opening %s\n", conf->device_arg);
        err = snd_pcm_open(&pad->handle, conf->device_arg,
                SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK);
        if (err < 0)
@@ -176,8 +177,8 @@ static int alsa_write_pre_select(struct sched *s, struct writer_node *wn)
                if (ret == 0)
                        return 1;
                if (ret < 0) {
-                       underrun = 10;
-                       goto timeout;
+                       sched_request_timeout_ms(20, s);
+                       return 42;
                }
        } else {
                if (*wng->loaded - wn->written < pad->bytes_per_frame)
@@ -201,7 +202,6 @@ static int alsa_write_pre_select(struct sched *s, struct writer_node *wn)
        if (underrun < 50)
                underrun = 50;
        underrun -= 50;
-timeout:
        ms2tv(underrun, &tv);
        if (tv_diff(&s->timeout, &tv, NULL) > 0)
                s->timeout = tv;
@@ -290,7 +290,6 @@ static void alsa_close(struct writer_node *wn)
                snd_pcm_close(pad->handle);
                snd_config_update_free_global();
        }
-       alsa_cmdline_parser_free(wn->conf);
        free(pad);
 }
 
@@ -312,7 +311,7 @@ again:
                return;
        btr_merge(btrn, wn->min_iqs);
        bytes = btr_next_buffer(btrn, &data);
-       if (bytes < pad->bytes_per_frame) { /* eof */
+       if (ret < 0 || bytes < pad->bytes_per_frame) { /* eof */
                assert(btr_no_parent(btrn));
                ret = -E_ALSA_EOF;
                if (!pad->handle)
@@ -321,13 +320,13 @@ again:
                avail = snd_pcm_avail_update(pad->handle);
                if (avail + 1000 > pad->buffer_frames)
                        goto err;
+               PARA_DEBUG_LOG("waiting for device to drain\n");
                return;
        }
        if (!pad->handle) {
                struct alsa_write_args_info *conf = wn->conf;
                if (bytes == 0) /* no data available */
                        return;
-               PARA_CRIT_LOG("alsa init\n");
                /* defaults */
                pad->samplerate = conf->samplerate_arg;
                pad->channels = conf->channels_arg;
@@ -353,11 +352,6 @@ again:
                wn->min_iqs = pad->bytes_per_frame;
        }
        frames = bytes / pad->bytes_per_frame;
-       avail = snd_pcm_avail_update(pad->handle);
-       if (avail <= 0)
-               return;
-       frames = PARA_MIN(frames, avail);
-       //PARA_CRIT_LOG("writing %ld frames\n", frames);
        frames = snd_pcm_writei(pad->handle, data, frames);
        if (frames >= 0) {
                btr_consume(btrn, frames * pad->bytes_per_frame);
@@ -368,9 +362,9 @@ again:
                snd_pcm_prepare(pad->handle);
                return;
        }
-       PARA_WARNING_LOG("%s\n", snd_strerror(-frames));
        if (frames == -EAGAIN)
                return;
+       PARA_WARNING_LOG("%s\n", snd_strerror(-frames));
        ret = -E_ALSA_WRITE;
 err:
        assert(ret < 0);
@@ -394,12 +388,17 @@ err_out:
        return NULL;
 }
 
+static void alsa_free_config(void *conf)
+{
+       alsa_cmdline_parser_free(conf);
+}
+
 /**
- * the init function of the alsa writer
+ * The init function of the alsa writer.
  *
- * \param w pointer to the writer to initialize
+ * \param w Pointer to the writer to initialize.
  *
- * \sa struct writer
+ * \sa \ref struct writer.
  */
 void alsa_write_init(struct writer *w)
 {
@@ -414,6 +413,7 @@ void alsa_write_init(struct writer *w)
        w->post_select_btr = alsa_write_post_select_btr;
        w->parse_config = alsa_parse_config;
        w->shutdown = NULL; /* nothing to do */
+       w->free_config = alsa_free_config;
        w->help = (struct ggo_help) {
                .short_help = alsa_write_args_info_help,
                .detailed_help = alsa_write_args_info_detailed_help