player: pass callback directly to sync_update
sync_update is the only code-path that can end up calling any of the callbacks, so there's no need to store it in the device. This is a breaking change, so all users needs to update their code accordingly.
This commit is contained in:
parent
a3da5fe361
commit
5bfd04f55b
@ -164,7 +164,6 @@ int main(int argc, char *argv[])
|
|||||||
die("out of memory?");
|
die("out of memory?");
|
||||||
|
|
||||||
#ifndef SYNC_PLAYER
|
#ifndef SYNC_PLAYER
|
||||||
sync_set_callbacks(rocket, &bass_cb, (void *)stream);
|
|
||||||
if (sync_connect(rocket, "localhost", SYNC_DEFAULT_PORT))
|
if (sync_connect(rocket, "localhost", SYNC_DEFAULT_PORT))
|
||||||
die("failed to connect to host");
|
die("failed to connect to host");
|
||||||
#endif
|
#endif
|
||||||
@ -184,7 +183,7 @@ int main(int argc, char *argv[])
|
|||||||
while (!done) {
|
while (!done) {
|
||||||
double row = bass_get_row(stream);
|
double row = bass_get_row(stream);
|
||||||
#ifndef SYNC_PLAYER
|
#ifndef SYNC_PLAYER
|
||||||
if (sync_update(rocket, (int)floor(row)))
|
if (sync_update(rocket, (int)floor(row), &bass_cb, (void *)stream))
|
||||||
sync_connect(rocket, "localhost", SYNC_DEFAULT_PORT);
|
sync_connect(rocket, "localhost", SYNC_DEFAULT_PORT);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@ -88,7 +88,6 @@ struct sync_device *sync_create_device(const char *base)
|
|||||||
d->data.num_tracks = 0;
|
d->data.num_tracks = 0;
|
||||||
|
|
||||||
#ifndef SYNC_PLAYER
|
#ifndef SYNC_PLAYER
|
||||||
d->cb = d->cb_param = NULL;
|
|
||||||
d->row = -1;
|
d->row = -1;
|
||||||
d->sock = INVALID_SOCKET;
|
d->sock = INVALID_SOCKET;
|
||||||
#endif
|
#endif
|
||||||
@ -130,12 +129,6 @@ static int load_track_data(struct sync_track *t, const char *path)
|
|||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
void sync_set_callbacks(struct sync_device *d, struct sync_cb *cb, void *cb_param)
|
|
||||||
{
|
|
||||||
d->cb = cb;
|
|
||||||
d->cb_param = cb_param;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int save_track(const struct sync_track *t, const char *path)
|
static int save_track(const struct sync_track *t, const char *path)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
@ -248,7 +241,8 @@ int sync_connect(struct sync_device *d, const char *host, unsigned short port)
|
|||||||
return purge_and_rerequest(d);
|
return purge_and_rerequest(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
int sync_update(struct sync_device *d, int row)
|
int sync_update(struct sync_device *d, int row, struct sync_cb *cb,
|
||||||
|
void *cb_param)
|
||||||
{
|
{
|
||||||
if (d->sock == INVALID_SOCKET)
|
if (d->sock == INVALID_SOCKET)
|
||||||
return 1;
|
return 1;
|
||||||
@ -272,14 +266,14 @@ int sync_update(struct sync_device *d, int row)
|
|||||||
case SET_ROW:
|
case SET_ROW:
|
||||||
if (xrecv(d->sock, (char *)&row, sizeof(row), 0))
|
if (xrecv(d->sock, (char *)&row, sizeof(row), 0))
|
||||||
goto sockerr;
|
goto sockerr;
|
||||||
if (d->cb && d->cb->set_row)
|
if (cb && cb->set_row)
|
||||||
d->cb->set_row(d->cb_param, ntohl(row));
|
cb->set_row(cb_param, ntohl(row));
|
||||||
break;
|
break;
|
||||||
case PAUSE:
|
case PAUSE:
|
||||||
if (xrecv(d->sock, (char *)&flag, 1, 0))
|
if (xrecv(d->sock, (char *)&flag, 1, 0))
|
||||||
goto sockerr;
|
goto sockerr;
|
||||||
if (d->cb && d->cb->pause)
|
if (cb && cb->pause)
|
||||||
d->cb->pause(d->cb_param, flag);
|
cb->pause(cb_param, flag);
|
||||||
break;
|
break;
|
||||||
case SAVE_TRACKS:
|
case SAVE_TRACKS:
|
||||||
sync_save_tracks(d);
|
sync_save_tracks(d);
|
||||||
@ -290,7 +284,7 @@ int sync_update(struct sync_device *d, int row)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (d->cb && d->cb->is_playing && d->cb->is_playing(d->cb_param)) {
|
if (cb && cb->is_playing && cb->is_playing(cb_param)) {
|
||||||
if (d->row != row && d->sock != INVALID_SOCKET) {
|
if (d->row != row && d->sock != INVALID_SOCKET) {
|
||||||
unsigned char cmd = SET_ROW;
|
unsigned char cmd = SET_ROW;
|
||||||
uint32_t nrow = htonl(row);
|
uint32_t nrow = htonl(row);
|
||||||
|
|||||||
@ -13,8 +13,6 @@ struct sync_device {
|
|||||||
struct sync_data data;
|
struct sync_data data;
|
||||||
|
|
||||||
#ifndef SYNC_PLAYER
|
#ifndef SYNC_PLAYER
|
||||||
struct sync_cb *cb;
|
|
||||||
void *cb_param;
|
|
||||||
int row;
|
int row;
|
||||||
SOCKET sock;
|
SOCKET sock;
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -21,10 +21,9 @@ struct sync_cb {
|
|||||||
void (*set_row)(void *, int);
|
void (*set_row)(void *, int);
|
||||||
int (*is_playing)(void *);
|
int (*is_playing)(void *);
|
||||||
};
|
};
|
||||||
void sync_set_callbacks(struct sync_device *, struct sync_cb *, void *);
|
|
||||||
#define SYNC_DEFAULT_PORT 1338
|
#define SYNC_DEFAULT_PORT 1338
|
||||||
int sync_connect(struct sync_device *, const char *, unsigned short);
|
int sync_connect(struct sync_device *, const char *, unsigned short);
|
||||||
int sync_update(struct sync_device *, int);
|
int sync_update(struct sync_device *, int, struct sync_cb *, void *);
|
||||||
void sync_save_tracks(const struct sync_device *);
|
void sync_save_tracks(const struct sync_device *);
|
||||||
#endif /* !defined(SYNC_PLAYER) */
|
#endif /* !defined(SYNC_PLAYER) */
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user