diff options
author | Lajos Molnar <lajos@google.com> | 2014-05-09 01:24:04 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2014-05-09 01:24:04 +0000 |
commit | e99703920adb8037c506bfc6d0159a1b9aa8cf7c (patch) | |
tree | 70497eb056881065be0c4e7a0f23dbf07f63d599 /media | |
parent | d283f68057204fcde95e6c9ba79a59f27ae58fe3 (diff) | |
parent | 7d8e3ccfbf326b5e190b416590e956c2fc3021f7 (diff) | |
download | frameworks_av-e99703920adb8037c506bfc6d0159a1b9aa8cf7c.zip frameworks_av-e99703920adb8037c506bfc6d0159a1b9aa8cf7c.tar.gz frameworks_av-e99703920adb8037c506bfc6d0159a1b9aa8cf7c.tar.bz2 |
Merge "Allow BOM and space in WebVTT files"
Diffstat (limited to 'media')
-rw-r--r-- | media/libstagefright/httplive/PlaylistFetcher.cpp | 28 | ||||
-rw-r--r-- | media/libstagefright/httplive/PlaylistFetcher.h | 1 |
2 files changed, 28 insertions, 1 deletions
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<ABuffer> &bu return OK; } +/* static */ +bool PlaylistFetcher::bufferStartsWithWebVTTMagicSequence( + const sp<ABuffer> &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<ABuffer> &buffer, const sp<AMessage> &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<ABuffer>& buffer); + static bool bufferStartsWithWebVTTMagicSequence(const sp<ABuffer>& buffer); // notifications to mSession sp<AMessage> mNotify; |