]> git.alsa-project.org Git - alsa-lib.git/commitdiff
Removed ptrs from status. Some cleaning for alsa-lib
authorAbramo Bagnara <abramo@alsa-project.org>
Thu, 5 Oct 2000 10:26:07 +0000 (10:26 +0000)
committerAbramo Bagnara <abramo@alsa-project.org>
Thu, 5 Oct 2000 10:26:07 +0000 (10:26 +0000)
src/pcm/pcm.c
src/pcm/pcm_hw.c
src/pcm/pcm_local.h
src/pcm/pcm_mmap.c
src/pcm/pcm_plugin.c

index 00e45cfe9ef557b4ffd5b657cc21108625a8eb94..9c1b5bd4c61649ff9d6f72b637c8a983267187d7 100644 (file)
@@ -170,36 +170,42 @@ int snd_pcm_state(snd_pcm_t *pcm)
 int snd_pcm_delay(snd_pcm_t *pcm, ssize_t *delayp)
 {
        assert(pcm);
+       assert(pcm->valid_setup);
        return pcm->fast_ops->delay(pcm->fast_op_arg, delayp);
 }
 
 int snd_pcm_prepare(snd_pcm_t *pcm)
 {
        assert(pcm);
+       assert(pcm->valid_setup);
        return pcm->fast_ops->prepare(pcm->fast_op_arg);
 }
 
 int snd_pcm_start(snd_pcm_t *pcm)
 {
        assert(pcm);
+       assert(pcm->valid_setup);
        return pcm->fast_ops->start(pcm->fast_op_arg);
 }
 
 int snd_pcm_drop(snd_pcm_t *pcm)
 {
        assert(pcm);
+       assert(pcm->valid_setup);
        return pcm->fast_ops->drop(pcm->fast_op_arg);
 }
 
 int snd_pcm_drain(snd_pcm_t *pcm)
 {
        assert(pcm);
+       assert(pcm->valid_setup);
        return pcm->fast_ops->drain(pcm->fast_op_arg);
 }
 
 int snd_pcm_pause(snd_pcm_t *pcm, int enable)
 {
        assert(pcm);
+       assert(pcm->valid_setup);
        return pcm->fast_ops->pause(pcm->fast_op_arg, enable);
 }
 
@@ -451,10 +457,8 @@ int snd_pcm_dump_status(snd_pcm_status_t *status, FILE *fp)
        fprintf(fp, "tstamp      : %ld.%06ld\n",
                status->tstamp.tv_sec, status->tstamp.tv_usec);
        fprintf(fp, "delay       : %ld\n", (long)status->delay);
-       fprintf(fp, "avail_max   : %ld\n", (long)status->avail_max);
-       fprintf(fp, "appl_ptr    : %ld\n", (long)status->appl_ptr);
-       fprintf(fp, "hw_ptr      : %ld\n", (long)status->hw_ptr);
        fprintf(fp, "avail       : %ld\n", (long)status->avail);
+       fprintf(fp, "avail_max   : %ld\n", (long)status->avail_max);
        return 0;
 }
 
index 37e47bc297360a77956accf6ee9cfde03615cbd8..91f2e5b6f01733bbaf9da7c4bac6d93291114f89 100644 (file)
@@ -161,14 +161,7 @@ static int snd_pcm_hw_status(snd_pcm_t *pcm, snd_pcm_status_t * status)
 
 static int snd_pcm_hw_state(snd_pcm_t *pcm)
 {
-       snd_pcm_hw_t *hw = pcm->private;
-       int fd = hw->fd;
-       snd_pcm_status_t status;
-       if (pcm->mmap_status)
-               return pcm->mmap_status->state;
-       if (ioctl(fd, SND_PCM_IOCTL_STATUS, &status) < 0)
-               return -errno;
-       return status.state;
+       return pcm->mmap_status->state;
 }
 
 static int snd_pcm_hw_delay(snd_pcm_t *pcm, ssize_t *delayp)
@@ -390,14 +383,17 @@ static ssize_t snd_pcm_hw_avail_update(snd_pcm_t *pcm)
                if (err < 0)
                        return -errno;
        }
-       avail = snd_pcm_mmap_avail(pcm);
-       if (avail > 0 && hw->mmap_emulation && 
-           pcm->stream == SND_PCM_STREAM_CAPTURE) {
-               err = snd_pcm_read_mmap(pcm, avail);
-               if (err < 0)
+       if (pcm->stream == SND_PCM_STREAM_PLAYBACK) {
+               avail = snd_pcm_mmap_playback_avail(pcm);
+       } else {
+               avail = snd_pcm_mmap_capture_avail(pcm);
+               if (avail > 0 && hw->mmap_emulation) {
+                       err = snd_pcm_read_mmap(pcm, avail);
+                       if (err < 0)
+                               return err;
+                       assert((size_t)err == avail);
                        return err;
-               assert((size_t)err == avail);
-               return err;
+               }
        }
        return avail;
 }
index 3ca52f82d436310dc97f41ab7512bb60b38563a7..0409abc8cb4ed591e1d77a659f49a2d2b68adfc7 100644 (file)
@@ -98,6 +98,7 @@ int snd_pcm_mmap_ready(snd_pcm_t *pcm);
 ssize_t snd_pcm_mmap_appl_ptr(snd_pcm_t *pcm, off_t offset);
 void snd_pcm_mmap_appl_backward(snd_pcm_t *pcm, size_t frames);
 void snd_pcm_mmap_appl_forward(snd_pcm_t *pcm, size_t frames);
+void snd_pcm_mmap_hw_backward(snd_pcm_t *pcm, size_t frames);
 void snd_pcm_mmap_hw_forward(snd_pcm_t *pcm, size_t frames);
 size_t snd_pcm_mmap_hw_offset(snd_pcm_t *pcm);
 size_t snd_pcm_mmap_avail(snd_pcm_t *pcm);
index 654732b40ea949a57880af0cba6a253e61d67651..3264f6486c547587908aadff551d215020a91882 100644 (file)
@@ -86,60 +86,6 @@ size_t snd_pcm_mmap_hw_offset(snd_pcm_t *pcm)
        return pcm->mmap_status->hw_ptr % pcm->setup.buffer_size;
 }
 
-int snd_pcm_mmap_state(snd_pcm_t *pcm)
-{
-       assert(pcm);
-       assert(pcm->mmap_status);
-       return pcm->mmap_status->state;
-}
-
-ssize_t snd_pcm_mmap_hw_ptr(snd_pcm_t *pcm)
-{
-       assert(pcm);
-       assert(pcm->mmap_status);
-       return pcm->mmap_status->hw_ptr;
-}
-
-ssize_t snd_pcm_mmap_appl_ptr(snd_pcm_t *pcm, off_t offset)
-{
-       ssize_t appl_ptr;
-       assert(pcm);
-       assert(pcm->mmap_status && pcm->mmap_control);
-       assert(offset == 0 || pcm->type == SND_PCM_TYPE_HW);
-       appl_ptr = pcm->mmap_control->appl_ptr;
-       if (offset == 0)
-               return appl_ptr;
-       switch (pcm->mmap_status->state) {
-       case SND_PCM_STATE_RUNNING:
-               if (pcm->setup.xrun_mode == SND_PCM_XRUN_ASAP)
-                       snd_pcm_avail_update(pcm);
-               break;
-       case SND_PCM_STATE_READY:
-       case SND_PCM_STATE_NOTREADY:
-               return -EBADFD;
-       }
-       if (offset < 0) {
-               if (offset < -(ssize_t)pcm->setup.buffer_size)
-                       offset = -(ssize_t)pcm->setup.buffer_size;
-               appl_ptr += offset;
-               if (appl_ptr < 0)
-                       appl_ptr += pcm->setup.boundary;
-       } else {
-               size_t avail;
-               if (pcm->stream == SND_PCM_STREAM_PLAYBACK)
-                       avail = snd_pcm_mmap_playback_avail(pcm);
-               else
-                       avail = snd_pcm_mmap_capture_avail(pcm);
-               if ((size_t)offset > avail)
-                       offset = avail;
-               appl_ptr += offset;
-               if ((size_t)appl_ptr >= pcm->setup.boundary)
-                       appl_ptr -= pcm->setup.boundary;
-       }
-       pcm->mmap_control->appl_ptr = appl_ptr;
-       return appl_ptr;
-}
-
 void snd_pcm_mmap_appl_backward(snd_pcm_t *pcm, size_t frames)
 {
        ssize_t appl_ptr = pcm->mmap_control->appl_ptr;
@@ -158,6 +104,15 @@ void snd_pcm_mmap_appl_forward(snd_pcm_t *pcm, size_t frames)
        pcm->mmap_control->appl_ptr = appl_ptr;
 }
 
+void snd_pcm_mmap_hw_backward(snd_pcm_t *pcm, size_t frames)
+{
+       ssize_t hw_ptr = pcm->mmap_status->hw_ptr;
+       hw_ptr -= frames;
+       if (hw_ptr < 0)
+               hw_ptr += pcm->setup.boundary;
+       pcm->mmap_status->hw_ptr = hw_ptr;
+}
+
 void snd_pcm_mmap_hw_forward(snd_pcm_t *pcm, size_t frames)
 {
        size_t hw_ptr = pcm->mmap_status->hw_ptr;
index facc3fec0278312170369f12808e1c6f91838185..15894576d03af1255cd8e3dc40c83fae1668eb59 100644 (file)
@@ -82,11 +82,7 @@ int snd_pcm_plugin_status(snd_pcm_t *pcm, snd_pcm_status_t * status)
        int err = snd_pcm_status(plugin->slave, status);
        if (err < 0)
                return err;
-       status->hw_ptr = plugin->mmap_status.hw_ptr;
-       status->appl_ptr = plugin->mmap_control.appl_ptr;
-       status->avail = (pcm->stream == SND_PCM_STREAM_PLAYBACK ?
-                        snd_pcm_mmap_playback_avail(pcm) :
-                        snd_pcm_mmap_capture_avail(pcm));
+       status->avail = snd_pcm_avail_update(pcm);
        return 0;
 }
 
@@ -99,9 +95,8 @@ int snd_pcm_plugin_state(snd_pcm_t *pcm)
 int snd_pcm_plugin_delay(snd_pcm_t *pcm, ssize_t *delayp)
 {
        snd_pcm_plugin_t *plugin = pcm->private;
-       ssize_t sd;
+       ssize_t sd, d;
        int err = snd_pcm_delay(plugin->slave, &sd);
-       int d;
        if (err < 0)
                return err;
        if (plugin->client_frames)
@@ -158,23 +153,26 @@ ssize_t snd_pcm_plugin_rewind(snd_pcm_t *pcm, size_t frames)
 {
        snd_pcm_plugin_t *plugin = pcm->private;
        ssize_t n = pcm->setup.buffer_size - snd_pcm_mmap_avail(pcm);
+       assert(n >= 0);
        if (n > 0) {
                if ((size_t)n > frames)
                        n = frames;
-               snd_pcm_mmap_appl_backward(pcm, n);
                frames -= n;
        }
        if (frames > 0) {
                ssize_t err = snd_pcm_rewind(plugin->slave, frames);
                if (err < 0) {
-                       if (n > 0)
-                               return n;
-                       return err;
+                       if (n <= 0)
+                               return err;
+                       goto _end;
                }
                if (plugin->client_frames)
                        err = plugin->client_frames(pcm, err);
+               snd_pcm_mmap_hw_backward(pcm, err);
                n += err;
        }
+ _end:
+       snd_pcm_mmap_appl_backward(pcm, n);
        return n;
 }
 
@@ -236,6 +234,7 @@ ssize_t snd_pcm_plugin_mmap_forward(snd_pcm_t *pcm, size_t client_size)
        ssize_t slave_size;
        if (pcm->stream == SND_PCM_STREAM_CAPTURE) {
                snd_pcm_mmap_appl_forward(pcm, client_size);
+               // snd_pcm_plugin_avail_update(pcm);
                return client_size;
        }
        slave_size = snd_pcm_avail_update(slave);
@@ -245,11 +244,11 @@ ssize_t snd_pcm_plugin_mmap_forward(snd_pcm_t *pcm, size_t client_size)
               slave_xfer < (size_t)slave_size) {
                size_t slave_frames = slave_size - slave_xfer;
                size_t client_frames = client_size - client_xfer;
-               size_t cont = pcm->setup.buffer_size - snd_pcm_mmap_hw_offset(pcm);
+               size_t offset = snd_pcm_mmap_hw_offset(pcm);
+               size_t cont = pcm->setup.buffer_size - offset;
                if (cont < client_frames)
                        client_frames = cont;
-               err = plugin->write(pcm, pcm->mmap_areas, 
-                                   snd_pcm_mmap_hw_offset(pcm),
+               err = plugin->write(pcm, pcm->mmap_areas, offset,
                                    client_frames, &slave_frames);
                if (err < 0)
                        break;
@@ -283,11 +282,11 @@ ssize_t snd_pcm_plugin_avail_update(snd_pcm_t *pcm)
               client_xfer < client_size) {
                size_t slave_frames = slave_size - slave_xfer;
                size_t client_frames = client_size - client_xfer;
-               size_t cont = pcm->setup.buffer_size - snd_pcm_mmap_hw_offset(pcm);
+               size_t offset = snd_pcm_mmap_hw_offset(pcm);
+               size_t cont = pcm->setup.buffer_size - offset;
                if (cont < client_frames)
                        client_frames = cont;
-               err = plugin->read(pcm, pcm->mmap_areas, 
-                                  snd_pcm_mmap_hw_offset(pcm),
+               err = plugin->read(pcm, pcm->mmap_areas, offset,
                                   client_frames, &slave_frames);
                if (err < 0)
                        break;