diff options
author | Andreas Huber <andih@google.com> | 2010-10-10 11:25:54 -0700 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2010-10-10 11:25:54 -0700 |
commit | 0e4d896cb9ab813131c45b3b1fcd4cc66d341468 (patch) | |
tree | d06b31cc078a484621958c43c1e098e8696b9c1a /media/libstagefright/httplive/M3UParser.cpp | |
parent | 79e0ac144ca9bb771e2c6b1954c882da12a4bea8 (diff) | |
parent | da91f0b87bded1e4ebc9cc1a1712c7a0d44fba84 (diff) | |
download | frameworks_av-0e4d896cb9ab813131c45b3b1fcd4cc66d341468.tar.gz frameworks_av-0e4d896cb9ab813131c45b3b1fcd4cc66d341468.tar.bz2 frameworks_av-0e4d896cb9ab813131c45b3b1fcd4cc66d341468.zip |
am bb708373: am 949f7d90: Merge "Work to support switching transport streams mid-stream and signalling discontinuities to the decoder." into gingerbread
Merge commit 'bb70837397e3fb437b7b4443b37d7a83c11e6e43'
* commit 'bb70837397e3fb437b7b4443b37d7a83c11e6e43':
Work to support switching transport streams mid-stream and signalling discontinuities to the decoder.
Diffstat (limited to 'media/libstagefright/httplive/M3UParser.cpp')
-rw-r--r-- | media/libstagefright/httplive/M3UParser.cpp | 74 |
1 files changed, 72 insertions, 2 deletions
diff --git a/media/libstagefright/httplive/M3UParser.cpp b/media/libstagefright/httplive/M3UParser.cpp index 17771c4be1..f6f7dbd0e1 100644 --- a/media/libstagefright/httplive/M3UParser.cpp +++ b/media/libstagefright/httplive/M3UParser.cpp @@ -74,7 +74,8 @@ bool M3UParser::itemAt(size_t index, AString *uri, sp<AMessage> *meta) { static bool MakeURL(const char *baseURL, const char *url, AString *out) { out->clear(); - if (strncasecmp("http://", baseURL, 7)) { + if (strncasecmp("http://", baseURL, 7) + && strncasecmp("file://", baseURL, 7)) { // Base URL must be absolute return false; } @@ -128,7 +129,12 @@ status_t M3UParser::parse(const void *_data, size_t size) { line.setTo(&data[offset], offsetLF - offset); } - LOGI("#%s#", line.c_str()); + // LOGI("#%s#", line.c_str()); + + if (line.empty()) { + offset = offsetLF + 1; + continue; + } if (lineNo == 0 && line == "#EXTM3U") { mIsExtM3U = true; @@ -152,11 +158,20 @@ status_t M3UParser::parse(const void *_data, size_t size) { return ERROR_MALFORMED; } err = parseMetaData(line, &itemMeta, "duration"); + } else if (line.startsWith("#EXT-X-DISCONTINUITY")) { + if (mIsVariantPlaylist) { + return ERROR_MALFORMED; + } + if (itemMeta == NULL) { + itemMeta = new AMessage; + } + itemMeta->setInt32("discontinuity", true); } else if (line.startsWith("#EXT-X-STREAM-INF")) { if (mMeta != NULL) { return ERROR_MALFORMED; } mIsVariantPlaylist = true; + err = parseStreamInf(line, &itemMeta); } if (err != OK) { @@ -215,6 +230,61 @@ status_t M3UParser::parseMetaData( } // static +status_t M3UParser::parseStreamInf( + const AString &line, sp<AMessage> *meta) { + ssize_t colonPos = line.find(":"); + + if (colonPos < 0) { + return ERROR_MALFORMED; + } + + size_t offset = colonPos + 1; + + while (offset < line.size()) { + ssize_t end = line.find(",", offset); + if (end < 0) { + end = line.size(); + } + + AString attr(line, offset, end - offset); + attr.trim(); + + offset = end + 1; + + ssize_t equalPos = attr.find("="); + if (equalPos < 0) { + continue; + } + + AString key(attr, 0, equalPos); + key.trim(); + + AString val(attr, equalPos + 1, attr.size() - equalPos - 1); + val.trim(); + + LOGV("key=%s value=%s", key.c_str(), val.c_str()); + + if (!strcasecmp("bandwidth", key.c_str())) { + const char *s = val.c_str(); + char *end; + unsigned long x = strtoul(s, &end, 10); + + if (end == s || *end != '\0') { + // malformed + continue; + } + + if (meta->get() == NULL) { + *meta = new AMessage; + } + (*meta)->setInt32("bandwidth", x); + } + } + + return OK; +} + +// static status_t M3UParser::ParseInt32(const char *s, int32_t *x) { char *end; long lval = strtol(s, &end, 10); |