From 7d8e3ccfbf326b5e190b416590e956c2fc3021f7 Mon Sep 17 00:00:00 2001 From: Lajos Molnar Date: Thu, 8 May 2014 16:13:54 -0700 Subject: Allow BOM and space in WebVTT files Bug: 10900755 Change-Id: I47a7a33f749ea2470ce7d9d36d33c7484637d61c --- media/libstagefright/httplive/PlaylistFetcher.cpp | 28 ++++++++++++++++++++++- media/libstagefright/httplive/PlaylistFetcher.h | 1 + 2 files changed, 28 insertions(+), 1 deletion(-) (limited to 'media/libstagefright') diff --git a/media/libstagefright/httplive/PlaylistFetcher.cpp b/media/libstagefright/httplive/PlaylistFetcher.cpp index c34f3cb..6160009 100644 --- a/media/libstagefright/httplive/PlaylistFetcher.cpp +++ b/media/libstagefright/httplive/PlaylistFetcher.cpp @@ -1183,9 +1183,35 @@ status_t PlaylistFetcher::extractAndQueueAccessUnitsFromTs(const sp &bu return OK; } +/* static */ +bool PlaylistFetcher::bufferStartsWithWebVTTMagicSequence( + const sp &buffer) { + size_t pos = 0; + + // skip possible BOM + if (buffer->size() >= pos + 3 && + !memcmp("\xef\xbb\xbf", buffer->data() + pos, 3)) { + pos += 3; + } + + // accept WEBVTT followed by SPACE, TAB or (CR) LF + if (buffer->size() < pos + 6 || + memcmp("WEBVTT", buffer->data() + pos, 6)) { + return false; + } + pos += 6; + + if (buffer->size() == pos) { + return true; + } + + uint8_t sep = buffer->data()[pos]; + return sep == ' ' || sep == '\t' || sep == '\n' || sep == '\r'; +} + status_t PlaylistFetcher::extractAndQueueAccessUnits( const sp &buffer, const sp &itemMeta) { - if (buffer->size() >= 7 && !memcmp("WEBVTT\n", buffer->data(), 7)) { + if (bufferStartsWithWebVTTMagicSequence(buffer)) { if (mStreamTypeMask != LiveSession::STREAMTYPE_SUBTITLES) { ALOGE("This stream only contains subtitles."); return ERROR_MALFORMED; diff --git a/media/libstagefright/httplive/PlaylistFetcher.h b/media/libstagefright/httplive/PlaylistFetcher.h index 7e21523..6af82c4 100644 --- a/media/libstagefright/httplive/PlaylistFetcher.h +++ b/media/libstagefright/httplive/PlaylistFetcher.h @@ -91,6 +91,7 @@ private: static const int32_t kNumSkipFrames; static bool bufferStartsWithTsSyncByte(const sp& buffer); + static bool bufferStartsWithWebVTTMagicSequence(const sp& buffer); // notifications to mSession sp mNotify; -- cgit v1.1