Make compatible with libevent 2.0 by crippling streaming and ICY metadata (see issue #30)

This commit is contained in:
ejurgensen
2014-05-30 23:39:03 +02:00
parent 5b4ef31758
commit c740e6e3b0
5 changed files with 1879 additions and 9 deletions

View File

@@ -31,13 +31,21 @@ else
FFURL_SRC=ffmpeg_url_evbuffer.c ffmpeg_url_evbuffer.h
endif
if COND_LIBEVENT2
RTSP_SRC=evrtsp/rtsp.c evrtp/evrtsp.h evrtsp/rtsp-internal.h evrtsp/log.h
else
if COND_LIBEVENT1
EVHTTP_SRC=evhttp/http.c evhttp/evhttp.h evhttp/evhttp_compat.c evhttp/evhttp_compat.h evhttp/http-internal.h evhttp/log.h
RTSP_SRC=evrtsp/rtsp-libevent1.c evrtp/evrtsp.h evrtsp/rtsp-internal.h evrtsp/log.h
endif
if COND_LIBEVENT20
EVHTTP_SRC=
RTSP_SRC=evrtsp/rtsp-libevent20.c evrtp/evrtsp.h evrtsp/rtsp-internal.h evrtsp/log.h
endif
if COND_LIBEVENT21
EVHTTP_SRC=
RTSP_SRC=evrtsp/rtsp.c evrtp/evrtsp.h evrtsp/rtsp-internal.h evrtsp/log.h
endif
GPERF_FILES = \
daap_query.gperf \
rsp_query.gperf \

1808
src/evrtsp/rtsp-libevent20.c Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -110,6 +110,7 @@ resolve_address(char *hostname, char *s, size_t maxlen)
}
#endif
#ifndef HAVE_LIBEVENT2_OLD
static void
scan_icy_request_cb(struct evhttp_request *req, void *arg)
{
@@ -157,15 +158,18 @@ scan_icy_header_cb(struct evhttp_request *req, void *arg)
return -1;
}
#endif
int
scan_metadata_icy(char *url, struct media_file_info *mfi)
{
struct icy_ctx *ctx;
struct evhttp_connection *evcon;
#ifndef HAVE_LIBEVENT2_OLD
struct evhttp_request *req;
struct evkeyvalq *headers;
struct icy_ctx *ctx;
char s[PATH_MAX];
#endif
time_t start;
time_t end;
int ret;
@@ -239,6 +243,9 @@ scan_metadata_icy(char *url, struct media_file_info *mfi)
evhttp_connection_set_base(evcon, evbase_main);
#endif
#ifdef HAVE_LIBEVENT2_OLD
DPRINTF(E_LOG, L_SCAN, "Skipping Shoutcast metadata request for %s (requires libevent>=2.1.4)\n", ctx->hostname);
#else
evhttp_connection_set_timeout(evcon, ICY_TIMEOUT);
/* Set up request */
@@ -269,6 +276,7 @@ scan_metadata_icy(char *url, struct media_file_info *mfi)
status = ICY_DONE;
goto no_icy;
}
#endif
/* Can't count on server support for ICY metadata, so
* while waiting for a reply make a parallel call to scan_metadata_ffmpeg.

View File

@@ -122,6 +122,9 @@ static struct event exitev;
static struct evhttp *evhttpd;
static pthread_t tid_httpd;
#ifdef HAVE_LIBEVENT2_OLD
struct stream_ctx *g_st;
#endif
static void
stream_end(struct stream_ctx *st, int failed)
@@ -146,6 +149,11 @@ stream_end(struct stream_ctx *st, int failed)
close(st->fd);
}
#ifdef HAVE_LIBEVENT2_OLD
if (g_st == st)
g_st = NULL;
#endif
free(st);
}
@@ -180,6 +188,15 @@ stream_chunk_resched_cb(struct evhttp_connection *evcon, void *arg)
}
}
#ifdef HAVE_LIBEVENT2_OLD
static void
stream_chunk_resched_cb_wrapper(struct bufferevent *bufev, void *arg)
{
if (g_st)
stream_chunk_resched_cb(NULL, g_st);
}
#endif
static void
stream_chunk_xcode_cb(int fd, short event, void *arg)
{
@@ -227,7 +244,17 @@ stream_chunk_xcode_cb(int fd, short event, void *arg)
else
ret = xcoded;
#ifdef HAVE_LIBEVENT2_OLD
evhttp_send_reply_chunk(st->req, st->evbuf);
struct evhttp_connection *evcon = evhttp_request_get_connection(st->req);
struct bufferevent *bufev = evhttp_connection_get_bufferevent(evcon);
g_st = st; // Can't pass st to callback so use global - limits libevent 2.0 to a single stream
bufev->writecb = stream_chunk_resched_cb_wrapper;
#else
evhttp_send_reply_chunk_with_cb(st->req, st->evbuf, stream_chunk_resched_cb, st);
#endif
st->offset += ret;
@@ -283,7 +310,17 @@ stream_chunk_raw_cb(int fd, short event, void *arg)
evbuffer_add(st->evbuf, st->buf, ret);
#ifdef HAVE_LIBEVENT2_OLD
evhttp_send_reply_chunk(st->req, st->evbuf);
struct evhttp_connection *evcon = evhttp_request_get_connection(st->req);
struct bufferevent *bufev = evhttp_connection_get_bufferevent(evcon);
g_st = st; // Can't pass st to callback so use global - limits libevent 2.0 to a single stream
bufev->writecb = stream_chunk_resched_cb_wrapper;
#else
evhttp_send_reply_chunk_with_cb(st->req, st->evbuf, stream_chunk_resched_cb, st);
#endif
st->offset += ret;