]> git.alsa-project.org Git - alsa-lib.git/commitdiff
Initialize all fields of slave PCM instance of direct plugins
authorTakashi Iwai <tiwai@suse.de>
Fri, 16 Jun 2006 16:52:12 +0000 (18:52 +0200)
committerTakashi Iwai <tiwai@suse.de>
Fri, 16 Jun 2006 16:52:12 +0000 (18:52 +0200)
Initialize all fields of slave PCM instance of direct plugins.
Some fields were not initialized properly.

src/pcm/pcm_direct.c
src/pcm/pcm_direct.h

index 4e2f36cd275bfda1bc3453e569cf7fb44c317ef3..c67ae8b9045bd76b5a6a24efc9cfe6bdead6403a 100644 (file)
@@ -82,7 +82,7 @@ int snd_pcm_direct_semaphore_create_or_connect(snd_pcm_direct_t *dmix)
        return 0;
 }
 
-#define SND_PCM_DIRECT_MAGIC   0xa15ad319
+#define SND_PCM_DIRECT_MAGIC   (0xa15ad300 + sizeof(snd_pcm_direct_share_t))
 
 /*
  *  global shared memory area 
@@ -800,6 +800,44 @@ int snd_pcm_direct_resume(snd_pcm_t *pcm)
        return err;
 }
 
+#define COPY_SLAVE(field) (dmix->shmptr->s.field = spcm->field)
+
+/* copy the slave setting */
+static void save_slave_setting(snd_pcm_direct_t *dmix, snd_pcm_t *spcm)
+{
+       COPY_SLAVE(access);
+       COPY_SLAVE(format);
+       COPY_SLAVE(subformat);
+       COPY_SLAVE(channels);
+       COPY_SLAVE(rate);
+       COPY_SLAVE(period_size);
+       COPY_SLAVE(period_time);
+       COPY_SLAVE(periods);
+       COPY_SLAVE(tick_time);
+       COPY_SLAVE(tstamp_mode);
+       COPY_SLAVE(period_step);
+       COPY_SLAVE(sleep_min);
+       COPY_SLAVE(avail_min);
+       COPY_SLAVE(start_threshold);
+       COPY_SLAVE(stop_threshold);
+       COPY_SLAVE(silence_threshold);
+       COPY_SLAVE(silence_size);
+       COPY_SLAVE(xfer_align);
+       COPY_SLAVE(boundary);
+       COPY_SLAVE(info);
+       COPY_SLAVE(msbits);
+       COPY_SLAVE(rate_num);
+       COPY_SLAVE(rate_den);
+       COPY_SLAVE(hw_flags);
+       COPY_SLAVE(fifo_size);
+       COPY_SLAVE(buffer_size);
+       COPY_SLAVE(buffer_time);
+       COPY_SLAVE(sample_bits);
+       COPY_SLAVE(frame_bits);
+}
+
+#undef COPY_SLAVE
+
 /*
  * this function initializes hardware and starts playback operation with
  * no stop threshold (it operates all time without xrun checking)
@@ -1014,15 +1052,7 @@ int snd_pcm_direct_initialize_slave(snd_pcm_direct_t *dmix, snd_pcm_t *spcm, str
        snd_pcm_poll_descriptors(spcm, &fd, 1);
        dmix->hw_fd = fd.fd;
        
-       dmix->shmptr->s.boundary = spcm->boundary;
-       dmix->shmptr->s.buffer_size = spcm->buffer_size;
-       dmix->shmptr->s.period_size = spcm->period_size;
-       dmix->shmptr->s.sample_bits = spcm->sample_bits;
-       dmix->shmptr->s.channels = spcm->channels;
-       dmix->shmptr->s.rate = spcm->rate;
-       dmix->shmptr->s.format = spcm->format;
-       dmix->shmptr->s.info = spcm->info & ~SND_PCM_INFO_PAUSE;
-       dmix->shmptr->s.msbits = spcm->msbits;
+       save_slave_setting(dmix, spcm);
 
        /* Currently, we assume that each dmix client has the same
         * hw_params setting.
@@ -1126,6 +1156,48 @@ static snd_pcm_uframes_t recalc_boundary_size(unsigned long long bsize, snd_pcm_
        return (snd_pcm_uframes_t)bsize;
 }
 
+#define COPY_SLAVE(field) (spcm->field = dmix->shmptr->s.field)
+
+/* copy the slave setting */
+static void copy_slave_setting(snd_pcm_direct_t *dmix, snd_pcm_t *spcm)
+{
+       COPY_SLAVE(access);
+       COPY_SLAVE(format);
+       COPY_SLAVE(subformat);
+       COPY_SLAVE(channels);
+       COPY_SLAVE(rate);
+       COPY_SLAVE(period_size);
+       COPY_SLAVE(period_time);
+       COPY_SLAVE(periods);
+       COPY_SLAVE(tick_time);
+       COPY_SLAVE(tstamp_mode);
+       COPY_SLAVE(period_step);
+       COPY_SLAVE(sleep_min);
+       COPY_SLAVE(avail_min);
+       COPY_SLAVE(start_threshold);
+       COPY_SLAVE(stop_threshold);
+       COPY_SLAVE(silence_threshold);
+       COPY_SLAVE(silence_size);
+       COPY_SLAVE(xfer_align);
+       COPY_SLAVE(boundary);
+       COPY_SLAVE(info);
+       COPY_SLAVE(msbits);
+       COPY_SLAVE(rate_num);
+       COPY_SLAVE(rate_den);
+       COPY_SLAVE(hw_flags);
+       COPY_SLAVE(fifo_size);
+       COPY_SLAVE(buffer_size);
+       COPY_SLAVE(buffer_time);
+       COPY_SLAVE(sample_bits);
+       COPY_SLAVE(frame_bits);
+
+       spcm->info &= ~SND_PCM_INFO_PAUSE;
+       spcm->boundary = recalc_boundary_size(dmix->shmptr->s.boundary, spcm->buffer_size);
+}
+
+#undef COPY_SLAVE
+
+
 /*
  * open a slave PCM as secondary client (dup'ed fd)
  */
@@ -1143,13 +1215,8 @@ int snd_pcm_direct_open_secondary_client(snd_pcm_t **spcmp, snd_pcm_direct_t *dm
        spcm = *spcmp;
        spcm->donot_close = 1;
        spcm->setup = 1;
-       /* we copy the slave setting */
-       spcm->buffer_size = dmix->shmptr->s.buffer_size;
-       spcm->sample_bits = dmix->shmptr->s.sample_bits;
-       spcm->channels = dmix->shmptr->s.channels;
-       spcm->format = dmix->shmptr->s.format;
-       spcm->boundary = recalc_boundary_size(dmix->shmptr->s.boundary, spcm->buffer_size);
-       spcm->info = dmix->shmptr->s.info;
+
+       copy_slave_setting(dmix, spcm);
 
        /* Use the slave setting as SPCM, so far */
        dmix->slave_buffer_size = spcm->buffer_size;
@@ -1173,13 +1240,8 @@ int snd_pcm_direct_initialize_secondary_slave(snd_pcm_direct_t *dmix, snd_pcm_t
 
        spcm->donot_close = 1;
        spcm->setup = 1;
-       /* we copy the slave setting */
-       spcm->buffer_size = dmix->shmptr->s.buffer_size;
-       spcm->sample_bits = dmix->shmptr->s.sample_bits;
-       spcm->channels = dmix->shmptr->s.channels;
-       spcm->format = dmix->shmptr->s.format;
-       spcm->boundary = recalc_boundary_size(dmix->shmptr->s.boundary, spcm->buffer_size);
-       spcm->info = dmix->shmptr->s.info;
+
+       copy_slave_setting(dmix, spcm);
 
        /* Use the slave setting as SPCM, so far */
        dmix->slave_buffer_size = spcm->buffer_size;
index 7cf4b9d5624ef36d7dc2f47600aeff9d6d43a832..e8d1a0bdd80039c42e363e2390748c92783a3cfd 100644 (file)
@@ -50,6 +50,7 @@ struct slave_params {
        unsigned int periods;
 };
 
+/* shared among direct plugin clients - be careful to be 32/64bit compatible! */
 typedef struct {
        unsigned int magic;                     /* magic number */
        char socket_name[256];                  /* name of communication socket */
@@ -65,15 +66,36 @@ typedef struct {
                snd_interval_t periods;
        } hw;
        struct {
-               unsigned int buffer_size;
-               unsigned int period_size;
-               unsigned long long boundary;
+               /* copied to slave PCMs */
+               snd_pcm_access_t access;
+               snd_pcm_format_t format;
+               snd_pcm_subformat_t subformat;
                unsigned int channels;
-               unsigned int sample_bits;
                unsigned int rate;
-               snd_pcm_format_t format;
+               unsigned int period_size;
+               unsigned int period_time;
+               snd_interval_t periods;
+               unsigned int tick_time;
+               snd_pcm_tstamp_t tstamp_mode;
+               unsigned int period_step;
+               unsigned int sleep_min;
+               unsigned int avail_min;
+               unsigned int start_threshold;   
+               unsigned int stop_threshold;    
+               unsigned int silence_threshold;
+               unsigned int silence_size;
+               unsigned int xfer_align;
+               unsigned long long boundary;
                unsigned int info;
                unsigned int msbits;
+               unsigned int rate_num;
+               unsigned int rate_den;
+               unsigned int hw_flags;
+               unsigned int fifo_size;
+               unsigned int buffer_size;
+               snd_interval_t buffer_time;
+               unsigned int sample_bits;
+               unsigned int frame_bits;
        } s;
        union {
                struct {