mirror of
https://github.com/ericonr/sndio.git
synced 2024-02-18 04:45:21 -06:00
align writes to block size
This commit is contained in:
parent
759c751cfd
commit
9ca454512a
@ -43,6 +43,8 @@ struct sio_aucat_hdl {
|
|||||||
#define PSTATE_INIT 0
|
#define PSTATE_INIT 0
|
||||||
#define PSTATE_RUN 1
|
#define PSTATE_RUN 1
|
||||||
int pstate;
|
int pstate;
|
||||||
|
size_t round; /* write block size */
|
||||||
|
size_t walign; /* align write packets size to this */
|
||||||
};
|
};
|
||||||
|
|
||||||
static void sio_aucat_close(struct sio_hdl *);
|
static void sio_aucat_close(struct sio_hdl *);
|
||||||
@ -165,6 +167,8 @@ sio_aucat_open(const char *str, unsigned int mode, int nbio)
|
|||||||
hdl->curvol = SIO_MAXVOL;
|
hdl->curvol = SIO_MAXVOL;
|
||||||
hdl->reqvol = SIO_MAXVOL;
|
hdl->reqvol = SIO_MAXVOL;
|
||||||
hdl->pstate = PSTATE_INIT;
|
hdl->pstate = PSTATE_INIT;
|
||||||
|
hdl->round = 0xdeadbeef;
|
||||||
|
hdl->walign = 0xdeadbeef;
|
||||||
return (struct sio_hdl *)hdl;
|
return (struct sio_hdl *)hdl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,6 +197,7 @@ sio_aucat_start(struct sio_hdl *sh)
|
|||||||
hdl->wbpf = par.bps * par.pchan;
|
hdl->wbpf = par.bps * par.pchan;
|
||||||
hdl->rbpf = par.bps * par.rchan;
|
hdl->rbpf = par.bps * par.rchan;
|
||||||
hdl->maxwrite = hdl->wbpf * par.bufsz;
|
hdl->maxwrite = hdl->wbpf * par.bufsz;
|
||||||
|
hdl->round = par.round;
|
||||||
hdl->delta = 0;
|
hdl->delta = 0;
|
||||||
DPRINTF("aucat: start, maxwrite = %d\n", hdl->maxwrite);
|
DPRINTF("aucat: start, maxwrite = %d\n", hdl->maxwrite);
|
||||||
|
|
||||||
@ -205,6 +210,7 @@ sio_aucat_start(struct sio_hdl *sh)
|
|||||||
hdl->aucat.rtodo = sizeof(struct amsg);
|
hdl->aucat.rtodo = sizeof(struct amsg);
|
||||||
if (!aucat_setfl(&hdl->aucat, 1, &hdl->sio.eof))
|
if (!aucat_setfl(&hdl->aucat, 1, &hdl->sio.eof))
|
||||||
return 0;
|
return 0;
|
||||||
|
hdl->walign = hdl->round * hdl->wbpf;
|
||||||
hdl->pstate = PSTATE_RUN;
|
hdl->pstate = PSTATE_RUN;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -425,8 +431,13 @@ sio_aucat_write(struct sio_hdl *sh, const void *buf, size_t len)
|
|||||||
return 0;
|
return 0;
|
||||||
if (len > hdl->maxwrite)
|
if (len > hdl->maxwrite)
|
||||||
len = hdl->maxwrite;
|
len = hdl->maxwrite;
|
||||||
|
if (len > hdl->walign)
|
||||||
|
len = hdl->walign;
|
||||||
n = aucat_wdata(&hdl->aucat, buf, len, hdl->wbpf, &hdl->sio.eof);
|
n = aucat_wdata(&hdl->aucat, buf, len, hdl->wbpf, &hdl->sio.eof);
|
||||||
hdl->maxwrite -= n;
|
hdl->maxwrite -= n;
|
||||||
|
hdl->walign -= n;
|
||||||
|
if (hdl->walign == 0)
|
||||||
|
hdl->walign = hdl->round * hdl->wbpf;
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user