Commit d63b800e authored by Francois Cartegnie's avatar Francois Cartegnie

demux: hls: move probing to manager

parent e017b611
...@@ -46,6 +46,62 @@ HLSManager::~HLSManager() ...@@ -46,6 +46,62 @@ HLSManager::~HLSManager()
{ {
} }
bool HLSManager::isHTTPLiveStreaming(stream_t *s)
{
const uint8_t *peek;
int size = stream_Peek(s, &peek, 7);
if (size < 7 || memcmp(peek, "#EXTM3U", 7))
return false;
size = stream_Peek(s, &peek, 512);
if (size < 7)
return false;
peek += 7;
size -= 7;
/* Parse stream and search for
* EXT-X-TARGETDURATION or EXT-X-STREAM-INF tag, see
* http://tools.ietf.org/html/draft-pantos-http-live-streaming-04#page-8 */
while (size--)
{
static const char *const ext[] = {
"TARGETDURATION",
"MEDIA-SEQUENCE",
"KEY",
"ALLOW-CACHE",
"ENDLIST",
"STREAM-INF",
"DISCONTINUITY",
"VERSION"
};
if (*peek++ != '#')
continue;
if (size < 6)
continue;
if (memcmp(peek, "EXT-X-", 6))
continue;
peek += 6;
size -= 6;
for (size_t i = 0; i < ARRAY_SIZE(ext); i++)
{
size_t len = strlen(ext[i]);
if (size < 0 || (size_t)size < len)
continue;
if (!memcmp(peek, ext[i], len))
return true;
}
}
return false;
}
AbstractAdaptationLogic *HLSManager::createLogic(AbstractAdaptationLogic::LogicType type) AbstractAdaptationLogic *HLSManager::createLogic(AbstractAdaptationLogic::LogicType type)
{ {
switch(type) switch(type)
......
...@@ -37,6 +37,8 @@ namespace hls ...@@ -37,6 +37,8 @@ namespace hls
virtual ~HLSManager(); virtual ~HLSManager();
virtual AbstractAdaptationLogic *createLogic(AbstractAdaptationLogic::LogicType); virtual AbstractAdaptationLogic *createLogic(AbstractAdaptationLogic::LogicType);
virtual bool updatePlaylist(); virtual bool updatePlaylist();
static bool isHTTPLiveStreaming(stream_t *);
}; };
} }
......
...@@ -94,67 +94,11 @@ vlc_module_end () ...@@ -94,67 +94,11 @@ vlc_module_end ()
/***************************************************************************** /*****************************************************************************
* Open: * Open:
*****************************************************************************/ *****************************************************************************/
static bool isHTTPLiveStreaming(stream_t *s)
{
const uint8_t *peek;
int size = stream_Peek(s, &peek, 7);
if (size < 7 || memcmp(peek, "#EXTM3U", 7))
return false;
size = stream_Peek(s, &peek, 512);
if (size < 7)
return false;
peek += 7;
size -= 7;
/* Parse stream and search for
* EXT-X-TARGETDURATION or EXT-X-STREAM-INF tag, see
* http://tools.ietf.org/html/draft-pantos-http-live-streaming-04#page-8 */
while (size--)
{
static const char *const ext[] = {
"TARGETDURATION",
"MEDIA-SEQUENCE",
"KEY",
"ALLOW-CACHE",
"ENDLIST",
"STREAM-INF",
"DISCONTINUITY",
"VERSION"
};
if (*peek++ != '#')
continue;
if (size < 6)
continue;
if (memcmp(peek, "EXT-X-", 6))
continue;
peek += 6;
size -= 6;
for (size_t i = 0; i < ARRAY_SIZE(ext); i++)
{
size_t len = strlen(ext[i]);
if (size < 0 || (size_t)size < len)
continue;
if (!memcmp(peek, ext[i], len))
return true;
}
}
return false;
}
static int Open(vlc_object_t *p_obj) static int Open(vlc_object_t *p_obj)
{ {
demux_t *p_demux = (demux_t*) p_obj; demux_t *p_demux = (demux_t*) p_obj;
if(!isHTTPLiveStreaming(p_demux->s)) if(!HLSManager::isHTTPLiveStreaming(p_demux->s))
return VLC_EGENERIC; return VLC_EGENERIC;
Parser parser(p_demux->s); Parser parser(p_demux->s);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment