summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorAndreas Huber <andih@google.com>2010-05-12 07:55:48 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2010-05-12 07:55:48 -0700
commit8229dabcc36a015a6cf11a9b0b2e948ac0476552 (patch)
treee3e1b775d2e5340dbfce10cfbdb606ef6fa8ad60 /media
parentf5ef7f22bbf73ba5c3910096f8f7f84cc6e21039 (diff)
parentd2333bda49f9d76f1b30b81dfc093d407bc6dbf0 (diff)
downloadframeworks_av-8229dabcc36a015a6cf11a9b0b2e948ac0476552.zip
frameworks_av-8229dabcc36a015a6cf11a9b0b2e948ac0476552.tar.gz
frameworks_av-8229dabcc36a015a6cf11a9b0b2e948ac0476552.tar.bz2
am b003ad17: am e0dc80f8: Merge "Support for customizable socket-read timeouts through the HTTP response." into froyo
Merge commit 'b003ad17bffeba7875b9708ffeef2300ef28c916' into kraken * commit 'b003ad17bffeba7875b9708ffeef2300ef28c916': Support for customizable socket-read timeouts through the HTTP response.
Diffstat (limited to 'media')
-rw-r--r--media/libstagefright/HTTPDataSource.cpp17
-rw-r--r--media/libstagefright/HTTPStream.cpp17
-rw-r--r--media/libstagefright/include/HTTPStream.h3
3 files changed, 33 insertions, 4 deletions
diff --git a/media/libstagefright/HTTPDataSource.cpp b/media/libstagefright/HTTPDataSource.cpp
index 8e26c37..f72a6cc 100644
--- a/media/libstagefright/HTTPDataSource.cpp
+++ b/media/libstagefright/HTTPDataSource.cpp
@@ -84,6 +84,7 @@ status_t HTTPDataSource::connectWithRedirectsAndRange(off_t rangeStart) {
}
if (httpStatus >= 200 && httpStatus < 300) {
+ applyTimeoutResponse();
return OK;
}
@@ -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));
diff --git a/media/libstagefright/HTTPStream.cpp b/media/libstagefright/HTTPStream.cpp
index 6145ec2..9c99866 100644
--- a/media/libstagefright/HTTPStream.cpp
+++ b/media/libstagefright/HTTPStream.cpp
@@ -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;
@@ -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
diff --git a/media/libstagefright/include/HTTPStream.h b/media/libstagefright/include/HTTPStream.h
index 5d638f3..35b0865 100644
--- a/media/libstagefright/include/HTTPStream.h
+++ b/media/libstagefright/include/HTTPStream.h
@@ -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,