Loading media/libstagefright/NuHTTPDataSource.cpp +53 −0 Original line number Original line Diff line number Diff line Loading @@ -5,6 +5,7 @@ #include "include/NuHTTPDataSource.h" #include "include/NuHTTPDataSource.h" #include <cutils/properties.h> #include <cutils/properties.h> #include <media/stagefright/foundation/ALooper.h> #include <media/stagefright/MediaDebug.h> #include <media/stagefright/MediaDebug.h> #include <media/stagefright/MediaErrors.h> #include <media/stagefright/MediaErrors.h> Loading Loading @@ -68,6 +69,9 @@ NuHTTPDataSource::NuHTTPDataSource() mOffset(0), mOffset(0), mContentLength(0), mContentLength(0), mContentLengthValid(false), mContentLengthValid(false), mNumBandwidthHistoryItems(0), mTotalTransferTimeUs(0), mTotalTransferBytes(0), mDecryptHandle(NULL), mDecryptHandle(NULL), mDrmManagerClient(NULL) { mDrmManagerClient(NULL) { } } Loading Loading @@ -189,6 +193,20 @@ status_t NuHTTPDataSource::connect( return ERROR_IO; return ERROR_IO; } } { string value; if (mHTTP.find_header_value("Transfer-Encoding", &value)) { // We don't currently support any transfer encodings. mState = DISCONNECTED; mHTTP.disconnect(); LOGE("We don't support '%s' transfer encoding.", value.c_str()); return ERROR_UNSUPPORTED; } } applyTimeoutResponse(); applyTimeoutResponse(); if (offset == 0) { if (offset == 0) { Loading Loading @@ -254,6 +272,8 @@ ssize_t NuHTTPDataSource::readAt(off_t offset, void *data, size_t size) { size_t numBytesRead = 0; size_t numBytesRead = 0; while (numBytesRead < size) { while (numBytesRead < size) { int64_t startTimeUs = ALooper::GetNowUs(); ssize_t n = ssize_t n = mHTTP.receive((uint8_t *)data + numBytesRead, size - numBytesRead); mHTTP.receive((uint8_t *)data + numBytesRead, size - numBytesRead); Loading @@ -261,6 +281,9 @@ ssize_t NuHTTPDataSource::readAt(off_t offset, void *data, size_t size) { return n; return n; } } int64_t delayUs = ALooper::GetNowUs() - startTimeUs; addBandwidthMeasurement_l(n, delayUs); numBytesRead += (size_t)n; numBytesRead += (size_t)n; if (n == 0) { if (n == 0) { Loading Loading @@ -345,6 +368,36 @@ void NuHTTPDataSource::applyTimeoutResponse() { } } } } bool NuHTTPDataSource::estimateBandwidth(int32_t *bandwidth_bps) { Mutex::Autolock autoLock(mLock); if (mNumBandwidthHistoryItems < 10) { return false; } *bandwidth_bps = ((double)mTotalTransferBytes * 8E6 / mTotalTransferTimeUs); return true; } void NuHTTPDataSource::addBandwidthMeasurement_l( size_t numBytes, int64_t delayUs) { BandwidthEntry entry; entry.mDelayUs = delayUs; entry.mNumBytes = numBytes; mTotalTransferTimeUs += delayUs; mTotalTransferBytes += numBytes; mBandwidthHistory.push_back(entry); if (++mNumBandwidthHistoryItems > 100) { BandwidthEntry *entry = &*mBandwidthHistory.begin(); mTotalTransferTimeUs -= entry->mDelayUs; mTotalTransferBytes -= entry->mNumBytes; mBandwidthHistory.erase(mBandwidthHistory.begin()); --mNumBandwidthHistoryItems; } } DecryptHandle* NuHTTPDataSource::DrmInitialization(DrmManagerClient* client) { DecryptHandle* NuHTTPDataSource::DrmInitialization(DrmManagerClient* client) { if (client == NULL) { if (client == NULL) { return NULL; return NULL; Loading media/libstagefright/include/NuHTTPDataSource.h +16 −0 Original line number Original line Diff line number Diff line Loading @@ -3,6 +3,7 @@ #define NU_HTTP_DATA_SOURCE_H_ #define NU_HTTP_DATA_SOURCE_H_ #include <media/stagefright/DataSource.h> #include <media/stagefright/DataSource.h> #include <utils/List.h> #include <utils/String8.h> #include <utils/String8.h> #include <utils/threads.h> #include <utils/threads.h> Loading @@ -26,6 +27,10 @@ struct NuHTTPDataSource : public DataSource { virtual status_t getSize(off_t *size); virtual status_t getSize(off_t *size); virtual uint32_t flags(); virtual uint32_t flags(); // Returns true if bandwidth could successfully be estimated, // false otherwise. bool estimateBandwidth(int32_t *bandwidth_bps); virtual DecryptHandle* DrmInitialization(DrmManagerClient *client); virtual DecryptHandle* DrmInitialization(DrmManagerClient *client); virtual void getDrmInfo(DecryptHandle **handle, DrmManagerClient **client); virtual void getDrmInfo(DecryptHandle **handle, DrmManagerClient **client); Loading @@ -39,6 +44,11 @@ private: CONNECTED CONNECTED }; }; struct BandwidthEntry { int64_t mDelayUs; size_t mNumBytes; }; Mutex mLock; Mutex mLock; State mState; State mState; Loading @@ -54,6 +64,11 @@ private: off_t mContentLength; off_t mContentLength; bool mContentLengthValid; bool mContentLengthValid; List<BandwidthEntry> mBandwidthHistory; size_t mNumBandwidthHistoryItems; int64_t mTotalTransferTimeUs; size_t mTotalTransferBytes; DecryptHandle *mDecryptHandle; DecryptHandle *mDecryptHandle; DrmManagerClient *mDrmManagerClient; DrmManagerClient *mDrmManagerClient; Loading @@ -66,6 +81,7 @@ private: off_t offset); off_t offset); void applyTimeoutResponse(); void applyTimeoutResponse(); void addBandwidthMeasurement_l(size_t numBytes, int64_t delayUs); static void MakeFullHeaders( static void MakeFullHeaders( const KeyedVector<String8, String8> *overrides, const KeyedVector<String8, String8> *overrides, Loading Loading
media/libstagefright/NuHTTPDataSource.cpp +53 −0 Original line number Original line Diff line number Diff line Loading @@ -5,6 +5,7 @@ #include "include/NuHTTPDataSource.h" #include "include/NuHTTPDataSource.h" #include <cutils/properties.h> #include <cutils/properties.h> #include <media/stagefright/foundation/ALooper.h> #include <media/stagefright/MediaDebug.h> #include <media/stagefright/MediaDebug.h> #include <media/stagefright/MediaErrors.h> #include <media/stagefright/MediaErrors.h> Loading Loading @@ -68,6 +69,9 @@ NuHTTPDataSource::NuHTTPDataSource() mOffset(0), mOffset(0), mContentLength(0), mContentLength(0), mContentLengthValid(false), mContentLengthValid(false), mNumBandwidthHistoryItems(0), mTotalTransferTimeUs(0), mTotalTransferBytes(0), mDecryptHandle(NULL), mDecryptHandle(NULL), mDrmManagerClient(NULL) { mDrmManagerClient(NULL) { } } Loading Loading @@ -189,6 +193,20 @@ status_t NuHTTPDataSource::connect( return ERROR_IO; return ERROR_IO; } } { string value; if (mHTTP.find_header_value("Transfer-Encoding", &value)) { // We don't currently support any transfer encodings. mState = DISCONNECTED; mHTTP.disconnect(); LOGE("We don't support '%s' transfer encoding.", value.c_str()); return ERROR_UNSUPPORTED; } } applyTimeoutResponse(); applyTimeoutResponse(); if (offset == 0) { if (offset == 0) { Loading Loading @@ -254,6 +272,8 @@ ssize_t NuHTTPDataSource::readAt(off_t offset, void *data, size_t size) { size_t numBytesRead = 0; size_t numBytesRead = 0; while (numBytesRead < size) { while (numBytesRead < size) { int64_t startTimeUs = ALooper::GetNowUs(); ssize_t n = ssize_t n = mHTTP.receive((uint8_t *)data + numBytesRead, size - numBytesRead); mHTTP.receive((uint8_t *)data + numBytesRead, size - numBytesRead); Loading @@ -261,6 +281,9 @@ ssize_t NuHTTPDataSource::readAt(off_t offset, void *data, size_t size) { return n; return n; } } int64_t delayUs = ALooper::GetNowUs() - startTimeUs; addBandwidthMeasurement_l(n, delayUs); numBytesRead += (size_t)n; numBytesRead += (size_t)n; if (n == 0) { if (n == 0) { Loading Loading @@ -345,6 +368,36 @@ void NuHTTPDataSource::applyTimeoutResponse() { } } } } bool NuHTTPDataSource::estimateBandwidth(int32_t *bandwidth_bps) { Mutex::Autolock autoLock(mLock); if (mNumBandwidthHistoryItems < 10) { return false; } *bandwidth_bps = ((double)mTotalTransferBytes * 8E6 / mTotalTransferTimeUs); return true; } void NuHTTPDataSource::addBandwidthMeasurement_l( size_t numBytes, int64_t delayUs) { BandwidthEntry entry; entry.mDelayUs = delayUs; entry.mNumBytes = numBytes; mTotalTransferTimeUs += delayUs; mTotalTransferBytes += numBytes; mBandwidthHistory.push_back(entry); if (++mNumBandwidthHistoryItems > 100) { BandwidthEntry *entry = &*mBandwidthHistory.begin(); mTotalTransferTimeUs -= entry->mDelayUs; mTotalTransferBytes -= entry->mNumBytes; mBandwidthHistory.erase(mBandwidthHistory.begin()); --mNumBandwidthHistoryItems; } } DecryptHandle* NuHTTPDataSource::DrmInitialization(DrmManagerClient* client) { DecryptHandle* NuHTTPDataSource::DrmInitialization(DrmManagerClient* client) { if (client == NULL) { if (client == NULL) { return NULL; return NULL; Loading
media/libstagefright/include/NuHTTPDataSource.h +16 −0 Original line number Original line Diff line number Diff line Loading @@ -3,6 +3,7 @@ #define NU_HTTP_DATA_SOURCE_H_ #define NU_HTTP_DATA_SOURCE_H_ #include <media/stagefright/DataSource.h> #include <media/stagefright/DataSource.h> #include <utils/List.h> #include <utils/String8.h> #include <utils/String8.h> #include <utils/threads.h> #include <utils/threads.h> Loading @@ -26,6 +27,10 @@ struct NuHTTPDataSource : public DataSource { virtual status_t getSize(off_t *size); virtual status_t getSize(off_t *size); virtual uint32_t flags(); virtual uint32_t flags(); // Returns true if bandwidth could successfully be estimated, // false otherwise. bool estimateBandwidth(int32_t *bandwidth_bps); virtual DecryptHandle* DrmInitialization(DrmManagerClient *client); virtual DecryptHandle* DrmInitialization(DrmManagerClient *client); virtual void getDrmInfo(DecryptHandle **handle, DrmManagerClient **client); virtual void getDrmInfo(DecryptHandle **handle, DrmManagerClient **client); Loading @@ -39,6 +44,11 @@ private: CONNECTED CONNECTED }; }; struct BandwidthEntry { int64_t mDelayUs; size_t mNumBytes; }; Mutex mLock; Mutex mLock; State mState; State mState; Loading @@ -54,6 +64,11 @@ private: off_t mContentLength; off_t mContentLength; bool mContentLengthValid; bool mContentLengthValid; List<BandwidthEntry> mBandwidthHistory; size_t mNumBandwidthHistoryItems; int64_t mTotalTransferTimeUs; size_t mTotalTransferBytes; DecryptHandle *mDecryptHandle; DecryptHandle *mDecryptHandle; DrmManagerClient *mDrmManagerClient; DrmManagerClient *mDrmManagerClient; Loading @@ -66,6 +81,7 @@ private: off_t offset); off_t offset); void applyTimeoutResponse(); void applyTimeoutResponse(); void addBandwidthMeasurement_l(size_t numBytes, int64_t delayUs); static void MakeFullHeaders( static void MakeFullHeaders( const KeyedVector<String8, String8> *overrides, const KeyedVector<String8, String8> *overrides, Loading