From 6769586029891c240afe04dec96f7c554e3803bd Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Thu, 9 Jun 2016 10:11:19 +0200 Subject: [PATCH] src/io/source_avcodec.c: check if the uri is a network stream using av_url_split, call avformat_network_init() if needed --- src/io/source_avcodec.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/io/source_avcodec.c b/src/io/source_avcodec.c index 1a0a47b5..a4cbf6d4 100644 --- a/src/io/source_avcodec.c +++ b/src/io/source_avcodec.c @@ -72,6 +72,21 @@ struct _aubio_source_avcodec_t { void aubio_source_avcodec_reset_resampler(aubio_source_avcodec_t * s, uint_t multi); void aubio_source_avcodec_readframe(aubio_source_avcodec_t *s, uint_t * read_samples); +uint_t aubio_source_avcodec_has_network_url(aubio_source_avcodec_t *s); + +uint_t aubio_source_avcodec_has_network_url(aubio_source_avcodec_t *s) { + char proto[20], authorization[256], hostname[128], uripath[256]; + int proto_size = 20, authorization_size = 256, hostname_size = 128, + *port_ptr = 0, path_size = 256; + av_url_split(proto, proto_size, authorization, authorization_size, hostname, + hostname_size, port_ptr, uripath, path_size, s->path); + if (strlen(proto)) { + return 1; + } + return 0; +} + + aubio_source_avcodec_t * new_aubio_source_avcodec(const char_t * path, uint_t samplerate, uint_t hop_size) { aubio_source_avcodec_t * s = AUBIO_NEW(aubio_source_avcodec_t); int err; @@ -98,8 +113,9 @@ aubio_source_avcodec_t * new_aubio_source_avcodec(const char_t * path, uint_t sa // register all formats and codecs av_register_all(); - // if path[0] != '/' - //avformat_network_init(); + if (aubio_source_avcodec_has_network_url(s)) { + avformat_network_init(); + } // try opening the file and get some info about it AVFormatContext *avFormatCtx = s->avFormatCtx; -- 2.11.0