diff options
author | Andreas Huber <andih@google.com> | 2011-06-21 11:55:34 -0700 |
---|---|---|
committer | Andreas Huber <andih@google.com> | 2011-06-21 11:55:34 -0700 |
commit | 467bc257556a02a71164bcd03fec8b1ec99e460b (patch) | |
tree | 51072c2aa94adf2cc572836d6bfa2d4c58595c06 /media | |
parent | e2b801e5a437d75151d70a90e73f5f110d8732dd (diff) | |
download | frameworks_base-467bc257556a02a71164bcd03fec8b1ec99e460b.zip frameworks_base-467bc257556a02a71164bcd03fec8b1ec99e460b.tar.gz frameworks_base-467bc257556a02a71164bcd03fec8b1ec99e460b.tar.bz2 |
Parse the individual segment's duration as a floating point number which is now
allowed in later HLS specs.
Change-Id: I7c8296acb4e9b0f80022f3057769de0eea9ee0c6
related-to-bug: 4779022
Diffstat (limited to 'media')
-rw-r--r-- | media/libstagefright/httplive/LiveSession.cpp | 2 | ||||
-rw-r--r-- | media/libstagefright/httplive/M3UParser.cpp | 44 | ||||
-rw-r--r-- | media/libstagefright/include/M3UParser.h | 4 |
3 files changed, 47 insertions, 3 deletions
diff --git a/media/libstagefright/httplive/LiveSession.cpp b/media/libstagefright/httplive/LiveSession.cpp index 012d9ad..165683e 100644 --- a/media/libstagefright/httplive/LiveSession.cpp +++ b/media/libstagefright/httplive/LiveSession.cpp @@ -296,6 +296,8 @@ sp<M3UParser> LiveSession::fetchPlaylist(const char *url) { new M3UParser(url, buffer->data(), buffer->size()); if (playlist->initCheck() != OK) { + LOGE("failed to parse .m3u8 playlist"); + return NULL; } diff --git a/media/libstagefright/httplive/M3UParser.cpp b/media/libstagefright/httplive/M3UParser.cpp index 2eb180a..765f795 100644 --- a/media/libstagefright/httplive/M3UParser.cpp +++ b/media/libstagefright/httplive/M3UParser.cpp @@ -179,7 +179,7 @@ status_t M3UParser::parse(const void *_data, size_t size) { if (mIsVariantPlaylist) { return ERROR_MALFORMED; } - err = parseMetaData(line, &itemMeta, "duration"); + err = parseMetaDataDuration(line, &itemMeta, "durationUs"); } else if (line.startsWith("#EXT-X-DISCONTINUITY")) { if (mIsVariantPlaylist) { return ERROR_MALFORMED; @@ -203,9 +203,9 @@ status_t M3UParser::parse(const void *_data, size_t size) { if (!line.startsWith("#")) { if (!mIsVariantPlaylist) { - int32_t durationSecs; + int64_t durationUs; if (itemMeta == NULL - || !itemMeta->findInt32("duration", &durationSecs)) { + || !itemMeta->findInt64("durationUs", &durationUs)) { return ERROR_MALFORMED; } } @@ -252,6 +252,30 @@ status_t M3UParser::parseMetaData( } // static +status_t M3UParser::parseMetaDataDuration( + const AString &line, sp<AMessage> *meta, const char *key) { + ssize_t colonPos = line.find(":"); + + if (colonPos < 0) { + return ERROR_MALFORMED; + } + + double x; + status_t err = ParseDouble(line.c_str() + colonPos + 1, &x); + + if (err != OK) { + return err; + } + + if (meta->get() == NULL) { + *meta = new AMessage; + } + (*meta)->setInt64(key, (int64_t)x * 1E6); + + return OK; +} + +// static status_t M3UParser::parseStreamInf( const AString &line, sp<AMessage> *meta) { ssize_t colonPos = line.find(":"); @@ -412,4 +436,18 @@ status_t M3UParser::ParseInt32(const char *s, int32_t *x) { return OK; } +// static +status_t M3UParser::ParseDouble(const char *s, double *x) { + char *end; + double dval = strtod(s, &end); + + if (end == s || (*end != '\0' && *end != ',')) { + return ERROR_MALFORMED; + } + + *x = dval; + + return OK; +} + } // namespace android diff --git a/media/libstagefright/include/M3UParser.h b/media/libstagefright/include/M3UParser.h index 63895b4..478582d 100644 --- a/media/libstagefright/include/M3UParser.h +++ b/media/libstagefright/include/M3UParser.h @@ -63,6 +63,9 @@ private: static status_t parseMetaData( const AString &line, sp<AMessage> *meta, const char *key); + static status_t parseMetaDataDuration( + const AString &line, sp<AMessage> *meta, const char *key); + static status_t parseStreamInf( const AString &line, sp<AMessage> *meta); @@ -70,6 +73,7 @@ private: const AString &line, sp<AMessage> *meta, const AString &baseURI); static status_t ParseInt32(const char *s, int32_t *x); + static status_t ParseDouble(const char *s, double *x); DISALLOW_EVIL_CONSTRUCTORS(M3UParser); }; |