From 180944fe282fb57be4d8f986f7fcb0a209f943d5 Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 10 Dec 2012 01:28:20 +0100 Subject: stream_lavf/demux_lavf: export/use HTTP MIME type This is a fix for web radio streams that send raw AAC [1]. libavformat's AAC demuxer probe is picky enough to request hundreds of KBs data, which makes for a slow startup. To speed up stream startup, try use the HTTP MIME type to identify the format. The webstream in question sends an AAC specific MIME type, for which demux_lavf will force the AAC demuxer, without probing anything. ffmpeg/ffplay do the same thing. Note that as of ffmpeg commit 76d851b, av_probe_input_buffer() does the mapping from MIME type to demuxer. The actual mapping is not publicly accessible, and can only be used by calling that function. This will hopefully be rectified, and ideally ffmpeg would provide a function like find_demuxer_from_mime_type(). [1] http://lr2mp0.latvijasradio.lv:8000 --- demux/demux_lavf.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'demux/demux_lavf.c') diff --git a/demux/demux_lavf.c b/demux/demux_lavf.c index 7fa849f3a1..b3ae1d6315 100644 --- a/demux/demux_lavf.c +++ b/demux/demux_lavf.c @@ -83,8 +83,23 @@ typedef struct lavf_priv { bool use_dts; bool seek_by_bytes; int bitrate; + char *mime_type; } lavf_priv_t; +static const char *map_demuxer_mime_type[][2] = { + {"audio/aacp", "aac"}, + {0} +}; + +static const char *find_demuxer_from_mime_type(char *mime_type) +{ + for (int n = 0; map_demuxer_mime_type[n][0]; n++) { + if (strcasecmp(map_demuxer_mime_type[n][0], mime_type) == 0) + return map_demuxer_mime_type[n][1]; + } + return NULL; +} + static int mp_read(void *opaque, uint8_t *buf, int size) { struct demuxer *demuxer = opaque; @@ -207,6 +222,8 @@ static int lavf_check_file(demuxer_t *demuxer) format = demuxer->stream->lavf_type; if (!format) format = avdevice_format; + if (!format && demuxer->stream->mime_type) + format = (char *)find_demuxer_from_mime_type(demuxer->stream->mime_type); if (format) { if (strcmp(format, "help") == 0) { list_formats(); -- cgit v1.2.3