diff options
Diffstat (limited to 'media/libstagefright/httplive/LiveSession.cpp')
-rw-r--r-- | media/libstagefright/httplive/LiveSession.cpp | 51 |
1 files changed, 41 insertions, 10 deletions
diff --git a/media/libstagefright/httplive/LiveSession.cpp b/media/libstagefright/httplive/LiveSession.cpp index f67cdac..6f4b875 100644 --- a/media/libstagefright/httplive/LiveSession.cpp +++ b/media/libstagefright/httplive/LiveSession.cpp @@ -215,7 +215,9 @@ void LiveSession::onDisconnect() { mDisconnectPending = false; } -status_t LiveSession::fetchFile(const char *url, sp<ABuffer> *out) { +status_t LiveSession::fetchFile( + const char *url, sp<ABuffer> *out, + int64_t range_offset, int64_t range_length) { *out = NULL; sp<DataSource> source; @@ -234,8 +236,18 @@ status_t LiveSession::fetchFile(const char *url, sp<ABuffer> *out) { } } - status_t err = mHTTPDataSource->connect( - url, mExtraHeaders.isEmpty() ? NULL : &mExtraHeaders); + KeyedVector<String8, String8> headers = mExtraHeaders; + if (range_offset > 0 || range_length >= 0) { + headers.add( + String8("Range"), + String8( + StringPrintf( + "bytes=%lld-%s", + range_offset, + range_length < 0 + ? "" : StringPrintf("%lld", range_offset + range_length - 1).c_str()).c_str())); + } + status_t err = mHTTPDataSource->connect(url, &headers); if (err != OK) { return err; @@ -260,7 +272,7 @@ status_t LiveSession::fetchFile(const char *url, sp<ABuffer> *out) { if (bufferRemaining == 0) { bufferRemaining = 32768; - LOGV("increasing download buffer to %d bytes", + ALOGV("increasing download buffer to %d bytes", buffer->size() + bufferRemaining); sp<ABuffer> copy = new ABuffer(buffer->size() + bufferRemaining); @@ -270,9 +282,21 @@ status_t LiveSession::fetchFile(const char *url, sp<ABuffer> *out) { buffer = copy; } + size_t maxBytesToRead = bufferRemaining; + if (range_length >= 0) { + int64_t bytesLeftInRange = range_length - buffer->size(); + if (bytesLeftInRange < maxBytesToRead) { + maxBytesToRead = bytesLeftInRange; + + if (bytesLeftInRange == 0) { + break; + } + } + } + ssize_t n = source->readAt( buffer->size(), buffer->data() + buffer->size(), - bufferRemaining); + maxBytesToRead); if (n < 0) { return n; @@ -321,7 +345,7 @@ sp<M3UParser> LiveSession::fetchPlaylist(const char *url, bool *unchanged) { *unchanged = true; - LOGV("Playlist unchanged, refresh state is now %d", + ALOGV("Playlist unchanged, refresh state is now %d", (int)mRefreshState); return NULL; @@ -357,9 +381,9 @@ size_t LiveSession::getBandwidthIndex() { int32_t bandwidthBps; if (mHTTPDataSource != NULL && mHTTPDataSource->estimateBandwidth(&bandwidthBps)) { - LOGV("bandwidth estimated at %.2f kbps", bandwidthBps / 1024.0f); + ALOGV("bandwidth estimated at %.2f kbps", bandwidthBps / 1024.0f); } else { - LOGV("no bandwidth estimate."); + ALOGV("no bandwidth estimate."); return 0; // Pick the lowest bandwidth stream by default. } @@ -369,7 +393,7 @@ size_t LiveSession::getBandwidthIndex() { long maxBw = strtoul(value, &end, 10); if (end > value && *end == '\0') { if (maxBw > 0 && bandwidthBps > maxBw) { - LOGV("bandwidth capped to %ld bps", maxBw); + ALOGV("bandwidth capped to %ld bps", maxBw); bandwidthBps = maxBw; } } @@ -659,8 +683,15 @@ rinse_repeat: explicitDiscontinuity = true; } + int64_t range_offset, range_length; + if (!itemMeta->findInt64("range-offset", &range_offset) + || !itemMeta->findInt64("range-length", &range_length)) { + range_offset = 0; + range_length = -1; + } + sp<ABuffer> buffer; - status_t err = fetchFile(uri.c_str(), &buffer); + status_t err = fetchFile(uri.c_str(), &buffer, range_offset, range_length); if (err != OK) { LOGE("failed to fetch .ts segment at url '%s'", uri.c_str()); mDataSource->queueEOS(err); |