move siofile structure into struct dev

This commit is contained in:
Alexandre Ratchov 2012-11-02 12:43:43 +01:00
parent ad00f359cc
commit e22f44cdfa
5 changed files with 48 additions and 57 deletions

View File

@ -55,20 +55,20 @@ sndiod: ${OBJS}
abuf.o: abuf.c abuf.h defs.h utils.h
dev.o: dev.c ../bsd-compat/bsd-compat.h abuf.h defs.h dev.h \
dsp.h miofile.h siofile.h midi.h opt.h sysex.h utils.h
dsp.h siofile.h miofile.h midi.h opt.h sysex.h utils.h
dsp.o: dsp.c defs.h dsp.h utils.h
file.o: file.c defs.h file.h utils.h
listen.o: listen.c listen.h file.h sock.h ../libsndio/amsg.h \
utils.h ../bsd-compat/bsd-compat.h
midi.o: midi.c abuf.h defs.h dev.h dsp.h file.h midi.h miofile.h \
sysex.h utils.h ../bsd-compat/bsd-compat.h
midi.o: midi.c abuf.h defs.h dev.h dsp.h siofile.h file.h midi.h \
miofile.h sysex.h utils.h ../bsd-compat/bsd-compat.h
miofile.o: miofile.c defs.h file.h midi.h abuf.h miofile.h utils.h
opt.o: opt.c dev.h abuf.h dsp.h defs.h opt.h utils.h
siofile.o: siofile.c abuf.h defs.h dev.h dsp.h file.h siofile.h \
opt.o: opt.c dev.h abuf.h dsp.h defs.h siofile.h opt.h utils.h
siofile.o: siofile.c abuf.h defs.h dev.h dsp.h siofile.h file.h \
utils.h
sndiod.o: sndiod.c ../libsndio/amsg.h defs.h dev.h abuf.h dsp.h \
file.h listen.h midi.h opt.h sock.h utils.h \
siofile.h file.h listen.h midi.h opt.h sock.h utils.h \
../bsd-compat/bsd-compat.h
sock.o: sock.c abuf.h defs.h dev.h dsp.h file.h midi.h opt.h \
sock.h ../libsndio/amsg.h utils.h
sock.o: sock.c abuf.h defs.h dev.h dsp.h siofile.h file.h midi.h \
opt.h sock.h ../libsndio/amsg.h utils.h
utils.o: utils.c utils.h

View File

@ -917,7 +917,7 @@ dev_cycle(struct dev *d)
dev_log(d);
log_puts(": device stopped\n");
}
siofile_stop(d->sio);
siofile_stop(&d->sio);
d->pstate = DEV_INIT;
if (d->refcnt == 0)
dev_close(d);
@ -1039,8 +1039,7 @@ dev_open(struct dev *d)
d->pchan = 2;
if (d->rchan == 0)
d->rchan = 2;
d->sio = siofile_new(d);
if (d->sio == NULL) {
if (!siofile_open(&d->sio, d)) {
if (log_level >= 1) {
dev_log(d);
log_puts(": ");
@ -1127,8 +1126,7 @@ dev_close(struct dev *d)
s->ops = NULL;
d->slot_list = snext;
}
siofile_del(d->sio);
d->sio = NULL;
siofile_close(&d->sio);
if (d->mode & MODE_PLAY) {
if (d->encbuf != NULL)
xfree(d->encbuf);
@ -1277,7 +1275,7 @@ dev_wakeup(struct dev *d)
d->prime = 0;
}
d->pstate = DEV_RUN;
siofile_start(d->sio);
siofile_start(&d->sio);
}
}

View File

@ -19,8 +19,7 @@
#include "abuf.h"
#include "dsp.h"
struct siofile;
#include "siofile.h"
/*
* audio stream state structure
@ -111,7 +110,7 @@ struct dev {
/*
* audio device (while opened)
*/
struct siofile *sio;
struct siofile sio;
struct aparams par; /* encoding */
int pchan, rchan; /* play & rec channels */
adata_t *rbuf; /* rec buffer */

View File

@ -31,22 +31,6 @@
#include "siofile.h"
#include "utils.h"
struct siofile {
struct sio_hdl *hdl;
unsigned int todo;
#ifdef DEBUG
long long wtime, utime;
long long sum_wtime, sum_utime;
int pused, rused, events;
#endif
struct dev *dev;
struct file *file;
#define STATE_REC 0
#define STATE_CYCLE 1
#define STATE_PLAY 2
int state;
};
int siofile_pollfd(void *, struct pollfd *);
int siofile_revents(void *, struct pollfd *);
void siofile_run(void *);
@ -186,27 +170,25 @@ siofile_play(struct siofile *f)
/*
* open the device.
*/
struct siofile *
siofile_new(struct dev *d)
int
siofile_open(struct siofile *f, struct dev *d)
{
struct sio_par par;
struct sio_hdl *hdl;
struct siofile *f;
unsigned int mode = d->mode & (MODE_PLAY | MODE_REC);
hdl = sio_open(d->path, mode, 1);
if (hdl == NULL) {
f->hdl = sio_open(d->path, mode, 1);
if (f->hdl == NULL) {
if (mode != (SIO_PLAY | SIO_REC))
return NULL;
hdl = sio_open(d->path, SIO_PLAY, 1);
if (hdl != NULL)
return 0;
f->hdl = sio_open(d->path, SIO_PLAY, 1);
if (f->hdl != NULL)
mode = SIO_PLAY;
else {
hdl = sio_open(d->path, SIO_REC, 1);
if (hdl != NULL)
f->hdl = sio_open(d->path, SIO_REC, 1);
if (f->hdl != NULL)
mode = SIO_REC;
else
return NULL;
return 0;
}
if (log_level >= 1) {
log_puts("warning, device opened in ");
@ -230,9 +212,9 @@ siofile_new(struct dev *d)
par.round = d->round;
if (d->rate)
par.rate = d->rate;
if (!sio_setpar(hdl, &par))
if (!sio_setpar(f->hdl, &par))
goto bad_close;
if (!sio_getpar(hdl, &par))
if (!sio_getpar(f->hdl, &par))
goto bad_close;
d->par.bits = par.bits;
d->par.bps = par.bps;
@ -243,9 +225,7 @@ siofile_new(struct dev *d)
d->pchan = par.pchan;
if (mode & SIO_REC)
d->rchan = par.rchan;
f = xmalloc(sizeof(struct siofile));
f->dev = d;
f->hdl = hdl;
d->bufsz = par.bufsz;
d->round = par.round;
d->rate = par.rate;
@ -255,14 +235,14 @@ siofile_new(struct dev *d)
d->mode &= ~MODE_REC;
sio_onmove(f->hdl, siofile_onmove, f);
f->file = file_new(&siofile_ops, f, d->path, sio_nfds(f->hdl));
return f;
return 1;
bad_close:
sio_close(hdl);
return NULL;
sio_close(f->hdl);
return 0;
}
void
siofile_del(struct siofile *f)
siofile_close(struct siofile *f)
{
#ifdef DEBUG
if (log_level >= 3) {
@ -272,7 +252,6 @@ siofile_del(struct siofile *f)
#endif
file_del(f->file);
sio_close(f->hdl);
xfree(f);
}
void

View File

@ -18,10 +18,25 @@
#define SIOFILE_H
struct dev;
struct siofile;
struct siofile *siofile_new(struct dev *);
void siofile_del(struct siofile *);
struct siofile {
struct sio_hdl *hdl;
unsigned int todo;
#ifdef DEBUG
long long wtime, utime;
long long sum_wtime, sum_utime;
int pused, rused, events;
#endif
struct dev *dev;
struct file *file;
#define STATE_REC 0
#define STATE_CYCLE 1
#define STATE_PLAY 2
int state;
};
int siofile_open(struct siofile *, struct dev *);
void siofile_close(struct siofile *);
void siofile_log(struct siofile *);
void siofile_start(struct siofile *);
void siofile_stop(struct siofile *);