]> git.alsa-project.org Git - alsa-lib.git/commitdiff
Added rewind to API in place of appl_ptr(). Moved aserver to a better place
authorAbramo Bagnara <abramo@alsa-project.org>
Tue, 26 Sep 2000 09:46:05 +0000 (09:46 +0000)
committerAbramo Bagnara <abramo@alsa-project.org>
Tue, 26 Sep 2000 09:46:05 +0000 (09:46 +0000)
17 files changed:
Makefile.am
acinclude.m4
aserver/Makefile.am [moved from src/aserver/Makefile.am with 63% similarity]
aserver/aserver.c [moved from src/aserver/aserver.c with 99% similarity]
configure.in
include/aserver.h
include/pcm.h
src/Makefile.am
src/pcm/pcm.c
src/pcm/pcm_client.c
src/pcm/pcm_file.c
src/pcm/pcm_hw.c
src/pcm/pcm_local.h
src/pcm/pcm_mmap.c
src/pcm/pcm_multi.c
src/pcm/pcm_plugin.c
src/pcm/pcm_plugin.h

index 48fcacec51437cd2b8772df269b7b772425f056d..7bff906b9a29eb063768bd8625669b658228d852 100644 (file)
@@ -1,4 +1,4 @@
-SUBDIRS=doc include src test utils
+SUBDIRS=doc include src aserver test utils
 EXTRA_DIST=ChangeLog INSTALL TODO configure cvscompile libtool version
 
 INCLUDES=-I$(top_srcdir)/include
index 1bf50ad9e79e9c2eaf15255173be1aa952ba1e35..6857c8b81d43e5c088a8d469aaa4689c080c4bfe 100644 (file)
@@ -10,7 +10,7 @@ void main(void)
 #if !defined(SND_PROTOCOL_VERSION) || !defined(SND_PROTOCOL_INCOMPATIBLE)
 #error not found
 #else
-#if !defined(SND_PCM_IOCTL_APPL_PTR)
+#if !defined(SND_PCM_IOCTL_REWIND)
 #error wrong version
 #endif
   exit(0);
similarity index 63%
rename from src/aserver/Makefile.am
rename to aserver/Makefile.am
index 4568805dabcb41036ebf94e16a96013c6c7e2c1c..5b88a747cf89ad2a958c10d9b30d3661bd08a7d3 100644 (file)
@@ -2,12 +2,12 @@
 bin_PROGRAMS = aserver
 aserver_SOURCES = aserver.c
 # aserver_LDADD = -lasound
-aserver_LDADD = ../libasound.la
+aserver_LDADD = ../src/libasound.la
 
 all: aserver
 
 INCLUDES=-I$(top_srcdir)/include -I$(top_srcdir)/src/pcm
 
-../libasound.la:
-       $(MAKE) -C .. libasound.la
+../src/libasound.la:
+       $(MAKE) -C ../src libasound.la
 
similarity index 99%
rename from src/aserver/aserver.c
rename to aserver/aserver.c
index 4a77a95203e4f9846e8c395acb1fda6e4467d015..6c637f257ea2451514f29546e50ceff104db97c0 100644 (file)
@@ -401,8 +401,8 @@ int pcm_shm_cmd(client_t *client)
        case SND_PCM_IOCTL_CHANNEL_SETUP:
                ctrl->result = snd_pcm_channel_setup(pcm, &ctrl->u.channel_setup);
                break;
-       case SND_PCM_IOCTL_APPL_PTR:
-               ctrl->result = snd_pcm_appl_ptr(pcm, ctrl->u.appl_ptr);
+       case SND_PCM_IOCTL_REWIND:
+               ctrl->result = snd_pcm_rewind(pcm, ctrl->u.rewind);
                break;
        case SND_PCM_IOCTL_LINK:
        {
index d7fdedcb3211e649bc20696fd48f1e2a061dce88..e45097755ee1b8336e58c49cd33932106bae6416 100644 (file)
@@ -51,8 +51,8 @@ AC_SUBST(LIBTOOL_VERSION_INFO)
 
 AC_OUTPUT(Makefile doc/Makefile include/Makefile src/Makefile \
           src/control/Makefile src/mixer/Makefile src/pcm/Makefile \
-         src/pcm/plugin/Makefile src/rawmidi/Makefile src/timer/Makefile \
+         src/rawmidi/Makefile src/timer/Makefile \
           src/hwdep/Makefile src/seq/Makefile src/instr/Makefile \
-          src/compat/Makefile src/conf/Makefile src/aserver/Makefile \
+          src/compat/Makefile src/conf/Makefile aserver/Makefile \
           test/Makefile utils/Makefile \
           utils/alsa-lib.spec)
index aef553a861faf9a4a4d1df44fc721b73fd7f3387..138534f59c4cb58e9b9b9f0b407cf192bbc1ea3a 100644 (file)
@@ -31,7 +31,7 @@
 #define SND_PCM_IOCTL_CLOSE            _IO ('A', 0xf9)
 
 typedef struct {
-       int result;
+       long result;
        int cmd;
        union {
                snd_pcm_info_t info;
@@ -44,8 +44,7 @@ typedef struct {
                snd_pcm_channel_info_t channel_info;
                snd_pcm_channel_params_t channel_params;
                snd_pcm_channel_setup_t channel_setup;
-               off_t appl_ptr;
-               int hw_ptr;
+               ssize_t rewind;
                int link;
                size_t mmap_forward;
        } u;
index a559176e5b09cb2f15ab6a27daf41c5794830cdb..3d2c9b9a61d6a6de603cda578552213f55e66392 100644 (file)
@@ -150,8 +150,7 @@ int snd_pcm_flush(snd_pcm_t *handle);
 int snd_pcm_pause(snd_pcm_t *handle, int enable);
 int snd_pcm_state(snd_pcm_t *handle);
 int snd_pcm_delay(snd_pcm_t *handle, ssize_t *delayp);
-size_t snd_pcm_hw_ptr(snd_pcm_t *handle);
-ssize_t snd_pcm_appl_ptr(snd_pcm_t *handle, off_t offset);
+ssize_t snd_pcm_rewind(snd_pcm_t *handle, size_t frames);
 ssize_t snd_pcm_writei(snd_pcm_t *handle, const void *buffer, size_t size);
 ssize_t snd_pcm_readi(snd_pcm_t *handle, void *buffer, size_t size);
 ssize_t snd_pcm_writen(snd_pcm_t *handle, void **bufs, size_t size);
index c6985ed6da725ccf77e5d1376daa08785965b170..b5c29a3f750d3543e2f7fce0754e3e3f66dfef25 100644 (file)
@@ -1,4 +1,4 @@
-SUBDIRS=control mixer pcm rawmidi timer hwdep seq instr compat conf aserver
+SUBDIRS=control mixer pcm rawmidi timer hwdep seq instr compat conf
 COMPATNUM=@LIBTOOL_VERSION_INFO@
 
 lib_LTLIBRARIES = libasound.la
index fbf8bff7a73efc5eb2eeeb864a9d47b43999cbce..2f1c001dfbab5c919e12fc693af5dd33ce2f5df2 100644 (file)
@@ -204,15 +204,12 @@ int snd_pcm_pause(snd_pcm_t *pcm, int enable)
 }
 
 
-ssize_t snd_pcm_appl_ptr(snd_pcm_t *pcm, off_t offset)
+ssize_t snd_pcm_rewind(snd_pcm_t *pcm, size_t frames)
 {
        assert(pcm);
        assert(pcm->valid_setup);
-       if (pcm->mmap_control) {
-               if (offset == 0)
-                       return pcm->mmap_control->appl_ptr;
-       }
-       return pcm->fast_ops->appl_ptr(pcm->fast_op_arg, offset);
+       assert(frames > 0);
+       return pcm->fast_ops->rewind(pcm->fast_op_arg, frames);
 }
 
 ssize_t snd_pcm_writei(snd_pcm_t *pcm, const void *buffer, size_t size)
@@ -659,11 +656,6 @@ ssize_t snd_pcm_mmap_forward(snd_pcm_t *pcm, size_t size)
        return pcm->fast_ops->mmap_forward(pcm->fast_op_arg, size);
 }
 
-size_t snd_pcm_hw_ptr(snd_pcm_t *pcm)
-{
-       return pcm->mmap_status->hw_ptr;
-}
-
 int snd_pcm_area_silence(snd_pcm_channel_area_t *dst_area, size_t dst_offset,
                         size_t samples, int format)
 {
index 7e7799ab59f4dd47f5966fa4209fa56b203eb5c2..dbf4c3389dacfa69d00c6b4bedb09b0122758ee3 100644 (file)
@@ -387,13 +387,13 @@ static int snd_pcm_client_shm_pause(snd_pcm_t *pcm, int enable)
        return ctrl->result;
 }
 
-static ssize_t snd_pcm_client_shm_appl_ptr(snd_pcm_t *pcm, off_t offset)
+static ssize_t snd_pcm_client_shm_rewind(snd_pcm_t *pcm, size_t frames)
 {
        snd_pcm_client_t *client = pcm->private;
        snd_pcm_client_shm_t *ctrl = client->u.shm.ctrl;
        int err;
-       ctrl->cmd = SND_PCM_IOCTL_APPL_PTR;
-       ctrl->u.appl_ptr = offset;
+       ctrl->cmd = SND_PCM_IOCTL_REWIND;
+       ctrl->u.rewind = frames;
        err = snd_pcm_client_shm_action(pcm);
        if (err < 0)
                return err;
@@ -569,7 +569,7 @@ struct snd_pcm_fast_ops snd_pcm_client_fast_ops = {
        stop: snd_pcm_client_shm_stop,
        flush: snd_pcm_client_shm_flush,
        pause: snd_pcm_client_shm_pause,
-       appl_ptr: snd_pcm_client_shm_appl_ptr,
+       rewind: snd_pcm_client_shm_rewind,
        writei: snd_pcm_mmap_writei,
        writen: snd_pcm_mmap_writen,
        readi: snd_pcm_mmap_readi,
index 644aae34e0a1cfdf7603aedfa5b33a0473ebe3e8..316ccd392a6899b6ddd0dff12a91e72b92b64b50 100644 (file)
@@ -122,10 +122,17 @@ static int snd_pcm_file_pause(snd_pcm_t *pcm, int enable)
        return snd_pcm_pause(file->slave, enable);
 }
 
-static ssize_t snd_pcm_file_appl_ptr(snd_pcm_t *pcm, off_t offset)
+static ssize_t snd_pcm_file_rewind(snd_pcm_t *pcm, size_t frames)
 {
        snd_pcm_file_t *file = pcm->private;
-       return snd_pcm_appl_ptr(file->slave, offset);
+       ssize_t f = snd_pcm_rewind(file->slave, frames);
+       off_t err;
+       if (f > 0) {
+               err = lseek(file->fd, -snd_pcm_frames_to_bytes(pcm, f), SEEK_CUR);
+               if (err < 0)
+                       return err;
+       }
+       return f;
 }
 
 static void snd_pcm_file_write_areas(snd_pcm_t *pcm, 
@@ -336,7 +343,7 @@ struct snd_pcm_fast_ops snd_pcm_file_fast_ops = {
        stop: snd_pcm_file_stop,
        flush: snd_pcm_file_flush,
        pause: snd_pcm_file_pause,
-       appl_ptr: snd_pcm_file_appl_ptr,
+       rewind: snd_pcm_file_rewind,
        writei: snd_pcm_file_writei,
        writen: snd_pcm_file_writen,
        readi: snd_pcm_file_readi,
index b4f06b40b87efbb9d7205246580270ee8a7a1a41..bdfb3b655b06b5895f67b8b616b62b3b6a5938ce 100644 (file)
@@ -225,17 +225,22 @@ static int snd_pcm_hw_pause(snd_pcm_t *pcm, int enable)
        return 0;
 }
 
-static ssize_t snd_pcm_hw_appl_ptr(snd_pcm_t *pcm, off_t offset)
+static ssize_t snd_pcm_hw_rewind(snd_pcm_t *pcm, size_t frames)
 {
-       ssize_t result;
-       snd_pcm_hw_t *hw = pcm->private;
-       int fd = hw->fd;
-       if (pcm->mmap_status && pcm->mmap_control)
-               return snd_pcm_mmap_appl_ptr(pcm, offset);
-       result = ioctl(fd, SND_PCM_IOCTL_APPL_PTR, offset);
-       if (result < 0)
-               return -errno;
-       return result;
+       ssize_t used;
+       if (pcm->setup.xrun_mode == SND_PCM_XRUN_ASAP) {
+               ssize_t d;
+               int err = snd_pcm_hw_delay(pcm, &d);
+               if (err < 0)
+                       return 0;
+       }
+       used = pcm->setup.buffer_size - snd_pcm_mmap_avail(pcm);
+       if (used <= 0)
+               return 0;
+       if (frames > (size_t)used)
+               frames = used;
+       snd_pcm_mmap_appl_backward(pcm, frames);
+       return frames;
 }
 
 static ssize_t snd_pcm_hw_writei(snd_pcm_t *pcm, const void *buffer, size_t size)
@@ -451,7 +456,7 @@ struct snd_pcm_fast_ops snd_pcm_hw_fast_ops = {
        stop: snd_pcm_hw_stop,
        flush: snd_pcm_hw_flush,
        pause: snd_pcm_hw_pause,
-       appl_ptr: snd_pcm_hw_appl_ptr,
+       rewind: snd_pcm_hw_rewind,
        writei: snd_pcm_hw_writei,
        writen: snd_pcm_hw_writen,
        readi: snd_pcm_hw_readi,
index 35154c7abda4a50be113e293a4a435cc8ef11d13..7f49e42c47d4bd2d465ac7de8966d0d6fcc17c18 100644 (file)
@@ -54,7 +54,7 @@ struct snd_pcm_fast_ops {
        int (*pause)(snd_pcm_t *pcm, int enable);
        int (*state)(snd_pcm_t *pcm);
        int (*delay)(snd_pcm_t *pcm, ssize_t *delayp);
-       ssize_t (*appl_ptr)(snd_pcm_t *pcm, off_t offset);
+       ssize_t (*rewind)(snd_pcm_t *pcm, size_t frames);
        ssize_t (*writei)(snd_pcm_t *pcm, const void *buffer, size_t size);
        ssize_t (*writen)(snd_pcm_t *pcm, void **bufs, size_t size);
        ssize_t (*readi)(snd_pcm_t *pcm, void *buffer, size_t size);
@@ -96,6 +96,7 @@ int snd_pcm_munmap_control(snd_pcm_t *pcm);
 int snd_pcm_munmap_data(snd_pcm_t *pcm);
 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_forward(snd_pcm_t *pcm, size_t frames);
 size_t snd_pcm_mmap_hw_offset(snd_pcm_t *pcm);
index 2be47c537288d9d5763ddb169ef854dc88fbe394..4f05e93e6cfc9cdd5d41f7d7b0145fd3f8cc9a2d 100644 (file)
@@ -173,6 +173,15 @@ ssize_t snd_pcm_mmap_appl_ptr(snd_pcm_t *pcm, off_t offset)
        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;
+       appl_ptr -= frames;
+       if (appl_ptr < 0)
+               appl_ptr += pcm->setup.boundary;
+       pcm->mmap_control->appl_ptr = appl_ptr;
+}
+
 void snd_pcm_mmap_appl_forward(snd_pcm_t *pcm, size_t frames)
 {
        size_t appl_ptr = pcm->mmap_control->appl_ptr;
index f697bd953cdd46c1d618049a456350fd95028762..daadc52ab25e3b47403e5fe25786b483a610aed7 100644 (file)
@@ -196,7 +196,6 @@ static int snd_pcm_multi_setup(snd_pcm_t *pcm, snd_pcm_setup_t *setup)
                        return err;
                if (setup->format.rate != s.format.rate)
                        return -EINVAL;
-               /* mmap is not feasible */
                if (setup->buffer_size != s.buffer_size)
                        return -EINVAL;
                if (setup->mmap_shape != SND_PCM_MMAP_NONINTERLEAVED ||
@@ -327,31 +326,28 @@ static int snd_pcm_multi_channel_setup(snd_pcm_t *pcm, snd_pcm_channel_setup_t *
        return 0;
 }
 
-static ssize_t snd_pcm_multi_appl_ptr(snd_pcm_t *pcm, off_t offset)
+static ssize_t snd_pcm_multi_rewind(snd_pcm_t *pcm, size_t frames)
 {
        snd_pcm_multi_t *multi = pcm->private;
-       ssize_t pos, newpos;
        unsigned int i;
-       snd_pcm_t *handle_0 = multi->slaves[0].handle;
-
-       pos = snd_pcm_appl_ptr(handle_0, 0);
-       newpos = snd_pcm_appl_ptr(handle_0, offset);
-       if (newpos < 0)
-               return newpos;
-       offset = newpos - pos;
-       if (offset < 0)
-               offset += handle_0->setup.boundary;
-
-       for (i = 1; i < multi->slaves_count; ++i) {
+       size_t pos[multi->slaves_count];
+       memset(pos, 0, sizeof(pos));
+       for (i = 0; i < multi->slaves_count; ++i) {
                snd_pcm_t *handle_i = multi->slaves[i].handle;
-               ssize_t newpos_i;
-               newpos_i = snd_pcm_appl_ptr(handle_i, offset);
-               if (newpos_i < 0)
-                       return newpos_i;
-               if (newpos_i != newpos)
-                       return -EBADFD;
+               ssize_t f = snd_pcm_rewind(handle_i, frames);
+               if (f < 0)
+                       return f;
+               pos[i] = f;
+               frames = f;
+       }
+       /* Realign the pointers */
+       for (i = 0; i < multi->slaves_count; ++i) {
+               snd_pcm_t *handle_i = multi->slaves[i].handle;
+               size_t f = pos[i] - frames;
+               if (f > 0)
+                       snd_pcm_mmap_appl_forward(handle_i, f);
        }
-       return newpos;
+       return frames;
 }
 
 static int snd_pcm_multi_mmap_status(snd_pcm_t *pcm)
@@ -531,7 +527,7 @@ struct snd_pcm_fast_ops snd_pcm_multi_fast_ops = {
        writen: snd_pcm_mmap_writen,
        readi: snd_pcm_mmap_readi,
        readn: snd_pcm_mmap_readn,
-       appl_ptr: snd_pcm_multi_appl_ptr,
+       rewind: snd_pcm_multi_rewind,
        poll_descriptor: snd_pcm_multi_poll_descriptor,
        channels_mask: snd_pcm_multi_channels_mask,
        avail_update: snd_pcm_multi_avail_update,
index 2825703894adb9349eaa7deed330b56b221c822e..1c05ddee3d2ad1117224a7a77f1ca5d14fed26fd 100644 (file)
@@ -154,10 +154,28 @@ int snd_pcm_plugin_pause(snd_pcm_t *pcm, int enable)
        return snd_pcm_pause(plugin->slave, enable);
 }
 
-ssize_t snd_pcm_plugin_appl_ptr(snd_pcm_t *pcm, off_t offset)
+ssize_t snd_pcm_plugin_rewind(snd_pcm_t *pcm, size_t frames)
 {
-       /* FIXME */
-       return -ENOSYS;
+       snd_pcm_plugin_t *plugin = pcm->private;
+       ssize_t n = pcm->setup.buffer_size - snd_pcm_mmap_avail(pcm);
+       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 (plugin->client_frames)
+                       err = plugin->client_frames(pcm, err);
+               n += err;
+       }
+       return n;
 }
 
 ssize_t snd_pcm_plugin_writei(snd_pcm_t *pcm, const void *buffer, size_t size)
@@ -381,7 +399,7 @@ struct snd_pcm_fast_ops snd_pcm_plugin_fast_ops = {
        stop: snd_pcm_plugin_stop,
        flush: snd_pcm_plugin_flush,
        pause: snd_pcm_plugin_pause,
-       appl_ptr: snd_pcm_plugin_appl_ptr,
+       rewind: snd_pcm_plugin_rewind,
        writei: snd_pcm_plugin_writei,
        writen: snd_pcm_plugin_writen,
        readi: snd_pcm_plugin_readi,
index e76993ca0354d01050541845dc7374ac40e9ce6b..3f566158c84cce40547c8007d56a71ae401a0503 100644 (file)
@@ -44,7 +44,7 @@ int snd_pcm_plugin_start(snd_pcm_t *pcm);
 int snd_pcm_plugin_stop(snd_pcm_t *pcm);
 int snd_pcm_plugin_flush(snd_pcm_t *pcm);
 int snd_pcm_plugin_pause(snd_pcm_t *pcm, int enable);
-ssize_t snd_pcm_plugin_appl_ptr(snd_pcm_t *pcm, off_t offset);
+ssize_t snd_pcm_plugin_rewind(snd_pcm_t *pcm, size_t frames);
 ssize_t snd_pcm_plugin_writei(snd_pcm_t *pcm, const void *buffer, size_t size);
 ssize_t snd_pcm_plugin_writen(snd_pcm_t *pcm, void **bufs, size_t size);
 ssize_t snd_pcm_plugin_readi(snd_pcm_t *pcm, void *buffer, size_t size);