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

Commit 360d6d09 authored by Robert Shih's avatar Robert Shih
Browse files

GenericSource: support disconnect before NuCachedSource2 is created

Bug: 17672488
Change-Id: I96776c9679fdcfbe9a442c86447c59802b1465ac
parent 992626cf
Loading
Loading
Loading
Loading
+5 −1
Original line number Original line Diff line number Diff line
@@ -34,6 +34,7 @@ struct AMessage;
struct AString;
struct AString;
struct IMediaHTTPService;
struct IMediaHTTPService;
class String8;
class String8;
struct HTTPBase;


class DataSource : public RefBase {
class DataSource : public RefBase {
public:
public:
@@ -48,7 +49,10 @@ public:
            const sp<IMediaHTTPService> &httpService,
            const sp<IMediaHTTPService> &httpService,
            const char *uri,
            const char *uri,
            const KeyedVector<String8, String8> *headers = NULL,
            const KeyedVector<String8, String8> *headers = NULL,
            String8 *contentType = NULL);
            String8 *contentType = NULL,
            HTTPBase *httpSource = NULL);

    static sp<DataSource> CreateMediaHTTP(const sp<IMediaHTTPService> &httpService);


    DataSource() {}
    DataSource() {}


+20 −2
Original line number Original line Diff line number Diff line
@@ -36,6 +36,7 @@
#include "../../libstagefright/include/DRMExtractor.h"
#include "../../libstagefright/include/DRMExtractor.h"
#include "../../libstagefright/include/NuCachedSource2.h"
#include "../../libstagefright/include/NuCachedSource2.h"
#include "../../libstagefright/include/WVMExtractor.h"
#include "../../libstagefright/include/WVMExtractor.h"
#include "../../libstagefright/include/HTTPBase.h"


namespace android {
namespace android {


@@ -64,6 +65,7 @@ void NuPlayer::GenericSource::resetDataSource() {
    mAudioTimeUs = 0;
    mAudioTimeUs = 0;
    mVideoTimeUs = 0;
    mVideoTimeUs = 0;
    mHTTPService.clear();
    mHTTPService.clear();
    mHttpSource.clear();
    mUri.clear();
    mUri.clear();
    mUriHeaders.clear();
    mUriHeaders.clear();
    mFd = -1;
    mFd = -1;
@@ -284,10 +286,23 @@ void NuPlayer::GenericSource::onPrepareAsync() {
    // delayed data source creation
    // delayed data source creation
    if (mDataSource == NULL) {
    if (mDataSource == NULL) {
        if (!mUri.empty()) {
        if (!mUri.empty()) {
            mIsWidevine = !strncasecmp(mUri.c_str(), "widevine://", 11);
            const char* uri = mUri.c_str();
            mIsWidevine = !strncasecmp(uri, "widevine://", 11);

            if (!strncasecmp("http://", uri, 7)
                    || !strncasecmp("https://", uri, 8)
                    || mIsWidevine) {
                mHttpSource = DataSource::CreateMediaHTTP(mHTTPService);
                if (mHttpSource == NULL) {
                    ALOGE("Failed to create http source!");
                    notifyPreparedAndCleanup(UNKNOWN_ERROR);
                    return;
                }
            }


            mDataSource = DataSource::CreateFromURI(
            mDataSource = DataSource::CreateFromURI(
                   mHTTPService, mUri.c_str(), &mUriHeaders, &mContentType);
                   mHTTPService, uri, &mUriHeaders, &mContentType,
                   static_cast<HTTPBase *>(mHttpSource.get()));
        } else {
        } else {
            // set to false first, if the extractor
            // set to false first, if the extractor
            // comes back as secure, set it to true then.
            // comes back as secure, set it to true then.
@@ -360,6 +375,7 @@ void NuPlayer::GenericSource::notifyPreparedAndCleanup(status_t err) {
        mSniffedMIME = "";
        mSniffedMIME = "";
        mDataSource.clear();
        mDataSource.clear();
        mCachedSource.clear();
        mCachedSource.clear();
        mHttpSource.clear();


        cancelPollBuffering();
        cancelPollBuffering();
    }
    }
@@ -479,6 +495,8 @@ void NuPlayer::GenericSource::disconnect() {
        if (mDataSource->flags() & DataSource::kIsCachingDataSource) {
        if (mDataSource->flags() & DataSource::kIsCachingDataSource) {
            static_cast<NuCachedSource2 *>(mDataSource.get())->disconnect();
            static_cast<NuCachedSource2 *>(mDataSource.get())->disconnect();
        }
        }
    } else if (mHttpSource != NULL) {
        static_cast<HTTPBase *>(mHttpSource.get())->disconnect();
    }
    }
}
}


+1 −0
Original line number Original line Diff line number Diff line
@@ -126,6 +126,7 @@ private:


    sp<DataSource> mDataSource;
    sp<DataSource> mDataSource;
    sp<NuCachedSource2> mCachedSource;
    sp<NuCachedSource2> mCachedSource;
    sp<DataSource> mHttpSource;
    sp<WVMExtractor> mWVMExtractor;
    sp<WVMExtractor> mWVMExtractor;
    sp<MetaData> mFileMeta;
    sp<MetaData> mFileMeta;
    DrmManagerClient *mDrmManagerClient;
    DrmManagerClient *mDrmManagerClient;
+22 −7
Original line number Original line Diff line number Diff line
@@ -186,7 +186,8 @@ sp<DataSource> DataSource::CreateFromURI(
        const sp<IMediaHTTPService> &httpService,
        const sp<IMediaHTTPService> &httpService,
        const char *uri,
        const char *uri,
        const KeyedVector<String8, String8> *headers,
        const KeyedVector<String8, String8> *headers,
        String8 *contentType) {
        String8 *contentType,
        HTTPBase *httpSource) {
    if (contentType != NULL) {
    if (contentType != NULL) {
        *contentType = "";
        *contentType = "";
    }
    }
@@ -204,13 +205,14 @@ sp<DataSource> DataSource::CreateFromURI(
            return NULL;
            return NULL;
        }
        }


        if (httpSource == NULL) {
            sp<IMediaHTTPConnection> conn = httpService->makeHTTPConnection();
            sp<IMediaHTTPConnection> conn = httpService->makeHTTPConnection();
            if (conn == NULL) {
            if (conn == NULL) {
                ALOGE("Failed to make http connection from http service!");
                ALOGE("Failed to make http connection from http service!");
                return NULL;
                return NULL;
            }
            }

            httpSource = new MediaHTTP(conn);
        sp<HTTPBase> httpSource = new MediaHTTP(conn);
        }


        String8 tmp;
        String8 tmp;
        if (isWidevine) {
        if (isWidevine) {
@@ -264,6 +266,19 @@ sp<DataSource> DataSource::CreateFromURI(
    return source;
    return source;
}
}


sp<DataSource> DataSource::CreateMediaHTTP(const sp<IMediaHTTPService> &httpService) {
    if (httpService == NULL) {
        return NULL;
    }

    sp<IMediaHTTPConnection> conn = httpService->makeHTTPConnection();
    if (conn == NULL) {
        return NULL;
    } else {
        return new MediaHTTP(conn);
    }
}

String8 DataSource::getMIMEType() const {
String8 DataSource::getMIMEType() const {
    return String8("application/octet-stream");
    return String8("application/octet-stream");
}
}