diff options
author | Andreas Huber <andih@google.com> | 2010-02-02 10:38:40 -0800 |
---|---|---|
committer | Andreas Huber <andih@google.com> | 2010-02-02 10:38:40 -0800 |
commit | 4cf04b1bf703522b37a60427ef02f2a18b218c19 (patch) | |
tree | c3d70abe405618da6dcbdf9dfa79aa6414c9f34b /media | |
parent | a62aad3d3313f02a759ab2fcb92e160272badd5b (diff) | |
download | frameworks_av-4cf04b1bf703522b37a60427ef02f2a18b218c19.zip frameworks_av-4cf04b1bf703522b37a60427ef02f2a18b218c19.tar.gz frameworks_av-4cf04b1bf703522b37a60427ef02f2a18b218c19.tar.bz2 |
Properly advertise the content length of the HTTP stream if available.
related-to-bug: 2312941
Diffstat (limited to 'media')
-rw-r--r-- | media/libstagefright/CachingDataSource.cpp | 4 | ||||
-rw-r--r-- | media/libstagefright/HTTPDataSource.cpp | 78 |
2 files changed, 47 insertions, 35 deletions
diff --git a/media/libstagefright/CachingDataSource.cpp b/media/libstagefright/CachingDataSource.cpp index 8d04ead..1ca463e 100644 --- a/media/libstagefright/CachingDataSource.cpp +++ b/media/libstagefright/CachingDataSource.cpp @@ -65,6 +65,10 @@ status_t CachingDataSource::initCheck() const { return mSource->initCheck(); } +status_t CachingDataSource::getSize(off_t *size) { + return mSource->getSize(size); +} + uint32_t CachingDataSource::flags() { return mSource->flags(); } diff --git a/media/libstagefright/HTTPDataSource.cpp b/media/libstagefright/HTTPDataSource.cpp index e1ddfef..bb3b43c 100644 --- a/media/libstagefright/HTTPDataSource.cpp +++ b/media/libstagefright/HTTPDataSource.cpp @@ -94,19 +94,9 @@ static bool PerformRedirectIfNecessary( } HTTPDataSource::HTTPDataSource( - const char *uri, const KeyedVector<String8, String8> *headers) - : mHttp(new HTTPStream), - mHost(NULL), - mPort(0), - mPath(NULL), - mBuffer(malloc(kBufferSize)), - mBufferLength(0), - mBufferOffset(0), - mFirstRequest(true) { + const char *uri, const KeyedVector<String8, String8> *headers) { CHECK(!strncasecmp("http://", uri, 7)); - initHeaders(headers); - string host; string path; int port; @@ -133,33 +123,28 @@ HTTPDataSource::HTTPDataSource( host = string(host, 0, colon - host.c_str()); } - do { - LOGI("Connecting to host '%s', port %d, path '%s'", - host.c_str(), port, path.c_str()); - - mInitCheck = mHttp->connect(host.c_str(), port); - - if (mInitCheck != OK) { - return; - } - } while (PerformRedirectIfNecessary(mHttp, mHeaders, &host, &path, &port)); - - mHost = strdup(host.c_str()); - mPort = port; - mPath = strdup(path.c_str()); + init(host.c_str(), port, path.c_str(), headers); } HTTPDataSource::HTTPDataSource( const char *_host, int port, const char *_path, - const KeyedVector<String8, String8> *headers) - : mHttp(new HTTPStream), - mHost(NULL), - mPort(0), - mPath(NULL), - mBuffer(malloc(kBufferSize)), - mBufferLength(0), - mBufferOffset(0), - mFirstRequest(true) { + const KeyedVector<String8, String8> *headers) { + init(_host, port, _path, headers); +} + +void HTTPDataSource::init( + const char *_host, int port, const char *_path, + const KeyedVector<String8, String8> *headers) { + mHttp = new HTTPStream; + mHost = NULL; + mPort = 0; + mPath = NULL, + mBuffer = malloc(kBufferSize); + mBufferLength = 0; + mBufferOffset = 0; + mFirstRequest = true; + mContentLengthValid = false; + initHeaders(headers); string host = _host; @@ -176,6 +161,13 @@ HTTPDataSource::HTTPDataSource( } } while (PerformRedirectIfNecessary(mHttp, mHeaders, &host, &path, &port)); + string value; + if (mHttp->find_header_value("Content-Length", &value)) { + char *end; + mContentLength = strtoull(value.c_str(), &end, 10); + mContentLengthValid = true; + } + mHost = strdup(host.c_str()); mPort = port; mPath = strdup(path.c_str()); @@ -185,6 +177,22 @@ status_t HTTPDataSource::initCheck() const { return mInitCheck; } +status_t HTTPDataSource::getSize(off_t *size) { + *size = 0; + + if (mInitCheck != OK) { + return mInitCheck; + } + + if (!mContentLengthValid) { + return ERROR_UNSUPPORTED; + } + + *size = mContentLength; + + return OK; +} + HTTPDataSource::~HTTPDataSource() { mHttp->disconnect(); @@ -272,7 +280,7 @@ ssize_t HTTPDataSource::readAt(off_t offset, void *data, size_t size) { } ssize_t contentLength = 0; - if (mFirstRequest || offset != mBufferOffset + mBufferLength) { + if (mFirstRequest || offset != (off_t)(mBufferOffset + mBufferLength)) { if (!mFirstRequest) { LOGV("new range offset=%ld (old=%ld)", offset, mBufferOffset + mBufferLength); |