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 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 \ 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 dsp.o: dsp.c defs.h dsp.h utils.h
file.o: file.c defs.h file.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 \ listen.o: listen.c listen.h file.h sock.h ../libsndio/amsg.h \
utils.h ../bsd-compat/bsd-compat.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 \ midi.o: midi.c abuf.h defs.h dev.h dsp.h siofile.h file.h midi.h \
sysex.h utils.h ../bsd-compat/bsd-compat.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 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 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 file.h siofile.h \ siofile.o: siofile.c abuf.h defs.h dev.h dsp.h siofile.h file.h \
utils.h utils.h
sndiod.o: sndiod.c ../libsndio/amsg.h defs.h dev.h abuf.h dsp.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 ../bsd-compat/bsd-compat.h
sock.o: sock.c abuf.h defs.h dev.h dsp.h file.h midi.h opt.h \ sock.o: sock.c abuf.h defs.h dev.h dsp.h siofile.h file.h midi.h \
sock.h ../libsndio/amsg.h utils.h opt.h sock.h ../libsndio/amsg.h utils.h
utils.o: utils.c utils.h utils.o: utils.c utils.h

View File

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

View File

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

View File

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

View File

@ -18,10 +18,25 @@
#define SIOFILE_H #define SIOFILE_H
struct dev; struct dev;
struct siofile;
struct siofile *siofile_new(struct dev *); struct siofile {
void siofile_del(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_log(struct siofile *);
void siofile_start(struct siofile *); void siofile_start(struct siofile *);
void siofile_stop(struct siofile *); void siofile_stop(struct siofile *);