Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 604c0371 authored by Andreas Huber's avatar Andreas Huber Committed by Android Git Automerger
Browse files

am c63c6e97: am d06c435c: am c6c8a1e9: Merge "Increase the size of the pages...

am c63c6e97: am d06c435c: am c6c8a1e9: Merge "Increase the size of the pages used in CachingDataSource (total amount of memory used remains the same) to compensate for reduced locality of audio/video data requests. Also fixes a mistaken trailing "\r\n" in the range he
parents aed9d41b c63c6e97
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -54,7 +54,7 @@ protected:


private:
private:
    enum {
    enum {
        kBufferSize = 32 * 1024,
        kBufferSize = 64 * 1024,


        // If we encounter a socket-read error we'll try reconnecting
        // If we encounter a socket-read error we'll try reconnecting
        // and restarting the read for at most this many times.
        // and restarting the read for at most this many times.
+1 −1
Original line number Original line Diff line number Diff line
@@ -1091,7 +1091,7 @@ status_t AwesomePlayer::finishSetDataSource_l() {
        }
        }


        dataSource = new CachingDataSource(
        dataSource = new CachingDataSource(
                mConnectingDataSource, 32 * 1024, 20);
                mConnectingDataSource, 64 * 1024, 10);


        mConnectingDataSource.clear();
        mConnectingDataSource.clear();
    } else {
    } else {
+1 −1
Original line number Original line Diff line number Diff line
@@ -105,7 +105,7 @@ sp<DataSource> DataSource::CreateFromURI(
        if (httpSource->connect() != OK) {
        if (httpSource->connect() != OK) {
            return NULL;
            return NULL;
        }
        }
        source = new CachingDataSource(httpSource, 32 * 1024, 20);
        source = new CachingDataSource(httpSource, 64 * 1024, 10);
    } else {
    } else {
        // Assume it's a filename.
        // Assume it's a filename.
        source = new FileSource(uri);
        source = new FileSource(uri);
+22 −3
Original line number Original line Diff line number Diff line
@@ -35,7 +35,8 @@ namespace android {
// connected.
// connected.
static bool PerformRedirectIfNecessary(
static bool PerformRedirectIfNecessary(
        HTTPStream *http, const String8 &headers,
        HTTPStream *http, const String8 &headers,
        string *host, string *path, int *port) {
        string *host, string *path, int *port,
        status_t *result) {
    String8 request;
    String8 request;
    request.append("GET ");
    request.append("GET ");
    request.append(path->c_str());
    request.append(path->c_str());
@@ -52,6 +53,8 @@ static bool PerformRedirectIfNecessary(
        err = http->receive_header(&http_status);
        err = http->receive_header(&http_status);
    }
    }


    *result = err;

    if (err != OK) {
    if (err != OK) {
        return false;
        return false;
    }
    }
@@ -181,6 +184,7 @@ status_t HTTPDataSource::connect() {
         host.c_str(), port, path.c_str());
         host.c_str(), port, path.c_str());


    int numRedirectsRemaining = 5;
    int numRedirectsRemaining = 5;
    status_t result;
    do {
    do {
        status_t err = mHttp->connect(host.c_str(), port);
        status_t err = mHttp->connect(host.c_str(), port);


@@ -194,9 +198,19 @@ status_t HTTPDataSource::connect() {


            return err;
            return err;
        }
        }
    } while (PerformRedirectIfNecessary(mHttp, mHeaders, &host, &path, &port)
    } while (PerformRedirectIfNecessary(
                mHttp, mHeaders, &host, &path, &port, &result)
             && numRedirectsRemaining-- > 0);
             && numRedirectsRemaining-- > 0);


    if (result != OK) {
        // An error occurred while attempting to follow redirections/connect.
        Mutex::Autolock autoLock(mStateLock);

        mState = DISCONNECTED;

        return result;
    }

    string value;
    string value;
    if (mHttp->find_header_value("Content-Length", &value)) {
    if (mHttp->find_header_value("Content-Length", &value)) {
        char *end;
        char *end;
@@ -282,7 +296,7 @@ ssize_t HTTPDataSource::sendRangeRequest(size_t offset) {


    char range[128];
    char range[128];
    if (offset > 0) {
    if (offset > 0) {
        sprintf(range, "Range: bytes=%d-\r\n\r\n", offset);
        sprintf(range, "Range: bytes=%d-\r\n", offset);
    } else {
    } else {
        range[0] = '\0';
        range[0] = '\0';
    }
    }
@@ -313,6 +327,7 @@ ssize_t HTTPDataSource::sendRangeRequest(size_t offset) {
    }
    }


    if ((http_status / 100) != 2) {
    if ((http_status / 100) != 2) {
        LOGE("HTTP request failed, http status = %d", http_status);
        return UNKNOWN_ERROR;
        return UNKNOWN_ERROR;
    }
    }


@@ -349,6 +364,10 @@ rinse_repeat:


        memcpy(data, (const char *)mBuffer + (offset - mBufferOffset), copy);
        memcpy(data, (const char *)mBuffer + (offset - mBufferOffset), copy);


        if (copy < size) {
            LOGV("short read (1), returning %d vs. %d requested", copy, size);
        }

        return copy;
        return copy;
    }
    }