Loading include/media/stagefright/HTTPDataSource.h +1 −0 Original line number Diff line number Diff line Loading @@ -91,6 +91,7 @@ private: void initHeaders(const KeyedVector<String8, String8> *overrides); status_t connectWithRedirectsAndRange(off_t rangeStart); void applyTimeoutResponse(); HTTPDataSource(const HTTPDataSource &); HTTPDataSource &operator=(const HTTPDataSource &); Loading media/libstagefright/HTTPDataSource.cpp +17 −0 Original line number Diff line number Diff line Loading @@ -84,6 +84,7 @@ status_t HTTPDataSource::connectWithRedirectsAndRange(off_t rangeStart) { } if (httpStatus >= 200 && httpStatus < 300) { applyTimeoutResponse(); return OK; } Loading Loading @@ -133,6 +134,22 @@ status_t HTTPDataSource::connectWithRedirectsAndRange(off_t rangeStart) { return ERROR_IO; } void HTTPDataSource::applyTimeoutResponse() { string timeout; if (mHttp->find_header_value("X-SocketTimeout", &timeout)) { const char *s = timeout.c_str(); char *end; long tmp = strtol(s, &end, 10); if (end == s || *end != '\0') { LOGW("Illegal X-SocketTimeout value given."); return; } LOGI("overriding default timeout, new timeout is %ld seconds", tmp); mHttp->setReceiveTimeout(tmp); } } HTTPDataSource::HTTPDataSource( const char *uri, const KeyedVector<String8, String8> *headers) { CHECK(!strncasecmp("http://", uri, 7)); Loading media/libstagefright/HTTPStream.cpp +13 −4 Original line number Diff line number Diff line Loading @@ -68,10 +68,7 @@ status_t HTTPStream::connect(const char *server, int port) { return UNKNOWN_ERROR; } struct timeval tv; tv.tv_usec = 0; tv.tv_sec = 5; CHECK_EQ(0, setsockopt(mSocket, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv))); setReceiveTimeout(5); // Time out reads after 5 secs by default mState = CONNECTING; Loading Loading @@ -329,5 +326,17 @@ bool HTTPStream::find_header_value(const string &key, string *value) const { return true; } void HTTPStream::setReceiveTimeout(int seconds) { if (seconds < 0) { // Disable the timeout. seconds = 0; } struct timeval tv; tv.tv_usec = 0; tv.tv_sec = seconds; CHECK_EQ(0, setsockopt(mSocket, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv))); } } // namespace android media/libstagefright/include/HTTPStream.h +3 −0 Original line number Diff line number Diff line Loading @@ -52,6 +52,9 @@ public: bool find_header_value( const string &key, string *value) const; // Pass a negative value to disable the timeout. void setReceiveTimeout(int seconds); private: enum State { READY, Loading Loading
include/media/stagefright/HTTPDataSource.h +1 −0 Original line number Diff line number Diff line Loading @@ -91,6 +91,7 @@ private: void initHeaders(const KeyedVector<String8, String8> *overrides); status_t connectWithRedirectsAndRange(off_t rangeStart); void applyTimeoutResponse(); HTTPDataSource(const HTTPDataSource &); HTTPDataSource &operator=(const HTTPDataSource &); Loading
media/libstagefright/HTTPDataSource.cpp +17 −0 Original line number Diff line number Diff line Loading @@ -84,6 +84,7 @@ status_t HTTPDataSource::connectWithRedirectsAndRange(off_t rangeStart) { } if (httpStatus >= 200 && httpStatus < 300) { applyTimeoutResponse(); return OK; } Loading Loading @@ -133,6 +134,22 @@ status_t HTTPDataSource::connectWithRedirectsAndRange(off_t rangeStart) { return ERROR_IO; } void HTTPDataSource::applyTimeoutResponse() { string timeout; if (mHttp->find_header_value("X-SocketTimeout", &timeout)) { const char *s = timeout.c_str(); char *end; long tmp = strtol(s, &end, 10); if (end == s || *end != '\0') { LOGW("Illegal X-SocketTimeout value given."); return; } LOGI("overriding default timeout, new timeout is %ld seconds", tmp); mHttp->setReceiveTimeout(tmp); } } HTTPDataSource::HTTPDataSource( const char *uri, const KeyedVector<String8, String8> *headers) { CHECK(!strncasecmp("http://", uri, 7)); Loading
media/libstagefright/HTTPStream.cpp +13 −4 Original line number Diff line number Diff line Loading @@ -68,10 +68,7 @@ status_t HTTPStream::connect(const char *server, int port) { return UNKNOWN_ERROR; } struct timeval tv; tv.tv_usec = 0; tv.tv_sec = 5; CHECK_EQ(0, setsockopt(mSocket, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv))); setReceiveTimeout(5); // Time out reads after 5 secs by default mState = CONNECTING; Loading Loading @@ -329,5 +326,17 @@ bool HTTPStream::find_header_value(const string &key, string *value) const { return true; } void HTTPStream::setReceiveTimeout(int seconds) { if (seconds < 0) { // Disable the timeout. seconds = 0; } struct timeval tv; tv.tv_usec = 0; tv.tv_sec = seconds; CHECK_EQ(0, setsockopt(mSocket, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv))); } } // namespace android
media/libstagefright/include/HTTPStream.h +3 −0 Original line number Diff line number Diff line Loading @@ -52,6 +52,9 @@ public: bool find_header_value( const string &key, string *value) const; // Pass a negative value to disable the timeout. void setReceiveTimeout(int seconds); private: enum State { READY, Loading