Remove player metadata event timer (use the existing instead)

This commit is contained in:
ejurgensen 2015-04-11 20:30:31 +02:00
parent 0397b824a5
commit 99cda05dab
4 changed files with 22 additions and 49 deletions

View File

@ -204,10 +204,11 @@ stream_chunk_xcode_cb(int fd, short event, void *arg)
struct timeval tv;
int xcoded;
int ret;
int dummy;
st = (struct stream_ctx *)arg;
xcoded = transcode(st->xcode, st->evbuf, STREAM_CHUNK_SIZE);
xcoded = transcode(st->xcode, st->evbuf, STREAM_CHUNK_SIZE, &dummy);
if (xcoded <= 0)
{
if (xcoded == 0)

View File

@ -79,9 +79,6 @@
#define MAX(a, b) ((a > b) ? a : b)
#endif
/* Interval between ICY metadata polls for streams, in seconds */
#define METADATA_ICY_POLL 5
enum player_sync_source
{
PLAYER_SYNC_CLOCK,
@ -203,7 +200,6 @@ static int cmd_pipe[2];
static int player_exit;
static struct event *exitev;
static struct event *cmdev;
static struct event *metaev;
static pthread_t tid_player;
/* Player status */
@ -725,26 +721,16 @@ metadata_trigger(struct player_source *ps, int startup)
worker_execute(metadata_prepare_cb, &pmd, sizeof(struct player_metadata), 0);
}
static void
metadata_icy_poll_cb(int fd, short what, void *arg)
/* Checks if there is new HTTP ICY metadata, and if so sends updates to clients */
void
metadata_check_icy(void)
{
struct timeval tv = { METADATA_ICY_POLL, 0 };
struct http_icy_metadata *metadata;
int changed;
/* Playback of stream has stopped, so stop polling */
if (!cur_streaming || cur_streaming->type != SOURCE_HTTP || !cur_streaming->ctx)
{
if (metaev)
event_free(metaev);
metaev = NULL;
return;
}
transcode_metadata(cur_streaming->ctx, &metadata, &changed);
if (!metadata)
goto no_metadata;
return;
if (!changed)
goto no_update;
@ -754,38 +740,18 @@ metadata_icy_poll_cb(int fd, short what, void *arg)
/* Defer the database update to the worker thread */
worker_execute(update_icy_cb, metadata, sizeof(struct http_icy_metadata), 0);
status_update(player_state);
/* Triggers preparing and sending RAOP metadata */
metadata_trigger(cur_streaming, 0);
/* Only free the struct, the content must be preserved for update_icy_cb */
free(metadata);
evtimer_add(metaev, &tv);
status_update(player_state);
return;
no_update:
http_icy_metadata_free(metadata, 0);
no_metadata:
evtimer_add(metaev, &tv);
}
static void
metadata_icy_poll_start(void)
{
struct timeval tv = { METADATA_ICY_POLL, 0 };
DPRINTF(E_DBG, L_PLAYER, "Starting ICY polling\n");
if (metaev)
return;
metaev = evtimer_new(evbase_player, metadata_icy_poll_cb, NULL);
if (!metaev)
return;
evtimer_add(metaev, &tv);
}
/* Audio sources */
@ -1415,10 +1381,6 @@ source_open(struct player_source *ps, int no_md)
mfi->path = url;
ret = transcode_setup(&ps->ctx, mfi, NULL, 0);
if (ret < 0)
break;
metadata_icy_poll_start();
break;
case 2:
@ -1849,6 +1811,7 @@ source_read(uint8_t *buf, int len, uint64_t rtptime)
int new;
int ret;
int nbytes;
int icy_timer;
if (!cur_streaming)
return 0;
@ -1875,9 +1838,15 @@ source_read(uint8_t *buf, int len, uint64_t rtptime)
{
switch (cur_streaming->type)
{
case SOURCE_FILE:
case SOURCE_HTTP:
ret = transcode(cur_streaming->ctx, audio_buf, len - nbytes);
ret = transcode(cur_streaming->ctx, audio_buf, len - nbytes, &icy_timer);
if (icy_timer)
metadata_check_icy();
break;
case SOURCE_FILE:
ret = transcode(cur_streaming->ctx, audio_buf, len - nbytes, &icy_timer);
break;
#ifdef HAVE_SPOTIFY_H

View File

@ -63,6 +63,8 @@
# define XCODE_BUFFER_SIZE ((AVCODEC_MAX_AUDIO_FRAME_SIZE * 3) / 2)
#endif
/* Interval between ICY metadata checks for streams, in seconds */
#define METADATA_ICY_INTERVAL 5
struct transcode_ctx {
AVFormatContext *fmtctx;
@ -153,7 +155,7 @@ make_wav_header(struct transcode_ctx *ctx, off_t *est_size)
int
transcode(struct transcode_ctx *ctx, struct evbuffer *evbuf, int wanted)
transcode(struct transcode_ctx *ctx, struct evbuffer *evbuf, int wanted, int *icy_timer)
{
int16_t *buf;
int buflen;
@ -393,6 +395,7 @@ transcode(struct transcode_ctx *ctx, struct evbuffer *evbuf, int wanted)
av_free(frame);
#endif
*icy_timer = (ctx->offset % (METADATA_ICY_INTERVAL * 2 * 2 * 44100) < processed);
return processed;
}

View File

@ -12,7 +12,7 @@
struct transcode_ctx;
int
transcode(struct transcode_ctx *ctx, struct evbuffer *evbuf, int wanted);
transcode(struct transcode_ctx *ctx, struct evbuffer *evbuf, int wanted, int *icy_timer);
int
transcode_seek(struct transcode_ctx *ctx, int ms);