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

Commit d8e1a061 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Remove IDataSource dependency from DataSource."

parents c6696cc0 51467425
Loading
Loading
Loading
Loading
+22 −39
Original line number Diff line number Diff line
@@ -162,15 +162,30 @@ sp<MetaData> NuPlayer2::GenericSource::getFileFormatMeta() const {

status_t NuPlayer2::GenericSource::initFromDataSource() {
    sp<IMediaExtractor> extractor;
    CHECK(mDataSource != NULL);
    CHECK(mDataSource != NULL || mFd != -1);
    sp<DataSource> dataSource = mDataSource;
    const int fd = mFd;
    const int64_t offset = mOffset;
    const int64_t length = mLength;

    mLock.unlock();
    // This might take long time if data source is not reliable.
    extractor = MediaExtractorFactory::Create(dataSource, NULL);
    if (dataSource != nullptr) {
        extractor = MediaExtractorFactory::Create(dataSource, NULL /* mime */);
    } else {
        extractor = MediaExtractorFactory::CreateFromFd(
                fd, offset, length, NULL /* mime */, &dataSource);
    }

    if (dataSource == nullptr) {
        ALOGE("initFromDataSource, failed to create data source!");
        mLock.lock();
        return UNKNOWN_ERROR;
    }

    if (extractor == NULL) {
        ALOGE("initFromDataSource, cannot create extractor!");
        mLock.lock();
        return UNKNOWN_ERROR;
    }

@@ -179,10 +194,13 @@ status_t NuPlayer2::GenericSource::initFromDataSource() {
    size_t numtracks = extractor->countTracks();
    if (numtracks == 0) {
        ALOGE("initFromDataSource, source has no track!");
        mLock.lock();
        return UNKNOWN_ERROR;
    }

    mLock.lock();
    mFd = -1;
    mDataSource = dataSource;
    mFileMeta = fileMeta;
    if (mFileMeta != NULL) {
        int64_t duration;
@@ -395,51 +413,16 @@ void NuPlayer2::GenericSource::onPrepareAsync() {
            if (!mDisconnected) {
                mDataSource = dataSource;
            }
        } else {
            if (property_get_bool("media.stagefright.extractremote", true) &&
                    !FileSource::requiresDrm(mFd, mOffset, mLength, nullptr /* mime */)) {
                sp<IBinder> binder =
                        defaultServiceManager()->getService(String16("media.extractor"));
                if (binder != nullptr) {
                    ALOGD("FileSource remote");
                    sp<IMediaExtractorService> mediaExService(
                            interface_cast<IMediaExtractorService>(binder));
                    sp<IDataSource> source =
                            mediaExService->makeIDataSource(mFd, mOffset, mLength);
                    ALOGV("IDataSource(FileSource): %p %d %lld %lld",
                            source.get(), mFd, (long long)mOffset, (long long)mLength);
                    if (source.get() != nullptr) {
                        mDataSource = CreateDataSourceFromIDataSource(source);
                        if (mDataSource != nullptr) {
                            // Close the local file descriptor as it is not needed anymore.
                            close(mFd);
                            mFd = -1;
                        }
                    } else {
                        ALOGW("extractor service cannot make data source");
                    }
                } else {
                    ALOGW("extractor service not running");
                }
            }
            if (mDataSource == nullptr) {
                ALOGD("FileSource local");
                mDataSource = new FileSource(mFd, mOffset, mLength);
            }
            // TODO: close should always be done on mFd, see the lines following
            // CreateDataSourceFromIDataSource above,
            // and the FileSource constructor should dup the mFd argument as needed.
            mFd = -1;
        }

        if (mDataSource == NULL) {
        if (mFd == -1 && mDataSource == NULL) {
            ALOGE("Failed to create data source!");
            notifyPreparedAndCleanup(UNKNOWN_ERROR);
            return;
        }
    }

    if (mDataSource->flags() & DataSource::kIsCachingDataSource) {
    if (mDataSource != nullptr && mDataSource->flags() & DataSource::kIsCachingDataSource) {
        mCachedSource = static_cast<NuCachedSource2 *>(mDataSource.get());
    }

+0 −5
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@
#define LOG_TAG "DataSource"

#include <media/DataSource.h>
#include <media/IDataSource.h>
#include <media/stagefright/foundation/ByteUtils.h>
#include <media/stagefright/MediaErrors.h>
#include <utils/String8.h>
@@ -124,10 +123,6 @@ status_t DataSource::getSize(off64_t *size) {
    return ERROR_UNSUPPORTED;
}

sp<IDataSource> DataSource::getIDataSource() const {
    return nullptr;
}

String8 DataSource::getMIMEType() const {
    return String8("application/octet-stream");
}
+0 −3
Original line number Diff line number Diff line
@@ -112,9 +112,6 @@ public:

    virtual void close() {};

    // returns a pointer to IDataSource if it is wrapped.
    virtual sp<IDataSource> getIDataSource() const;

protected:
    virtual ~DataSource() {}

+22 −41
Original line number Diff line number Diff line
@@ -26,7 +26,6 @@
#include <media/DataSource.h>
#include <media/MediaExtractor.h>
#include <media/MediaSource.h>
#include <media/IMediaExtractorService.h>
#include <media/IMediaHTTPService.h>
#include <media/stagefright/foundation/ABuffer.h>
#include <media/stagefright/foundation/ADebug.h>
@@ -161,15 +160,30 @@ sp<MetaData> NuPlayer::GenericSource::getFileFormatMeta() const {

status_t NuPlayer::GenericSource::initFromDataSource() {
    sp<IMediaExtractor> extractor;
    CHECK(mDataSource != NULL);
    CHECK(mDataSource != NULL || mFd != -1);
    sp<DataSource> dataSource = mDataSource;
    const int fd = mFd;
    const int64_t offset = mOffset;
    const int64_t length = mLength;

    mLock.unlock();
    // This might take long time if data source is not reliable.
    extractor = MediaExtractorFactory::Create(dataSource, NULL);
    if (dataSource != nullptr) {
        extractor = MediaExtractorFactory::Create(dataSource, NULL /* mime */);
    } else {
        extractor = MediaExtractorFactory::CreateFromFd(
                fd, offset, length, NULL /* mime */, &dataSource);
    }

    if (dataSource == nullptr) {
        ALOGE("initFromDataSource, failed to create data source!");
        mLock.lock();
        return UNKNOWN_ERROR;
    }

    if (extractor == NULL) {
        ALOGE("initFromDataSource, cannot create extractor!");
        mLock.lock();
        return UNKNOWN_ERROR;
    }

@@ -178,10 +192,13 @@ status_t NuPlayer::GenericSource::initFromDataSource() {
    size_t numtracks = extractor->countTracks();
    if (numtracks == 0) {
        ALOGE("initFromDataSource, source has no track!");
        mLock.lock();
        return UNKNOWN_ERROR;
    }

    mLock.lock();
    mFd = -1;
    mDataSource = dataSource;
    mFileMeta = fileMeta;
    if (mFileMeta != NULL) {
        int64_t duration;
@@ -394,51 +411,15 @@ void NuPlayer::GenericSource::onPrepareAsync() {
            if (!mDisconnected) {
                mDataSource = dataSource;
            }
        } else {
            if (property_get_bool("media.stagefright.extractremote", true) &&
                    !FileSource::requiresDrm(mFd, mOffset, mLength, nullptr /* mime */)) {
                sp<IBinder> binder =
                        defaultServiceManager()->getService(String16("media.extractor"));
                if (binder != nullptr) {
                    ALOGD("FileSource remote");
                    sp<IMediaExtractorService> mediaExService(
                            interface_cast<IMediaExtractorService>(binder));
                    sp<IDataSource> source =
                            mediaExService->makeIDataSource(mFd, mOffset, mLength);
                    ALOGV("IDataSource(FileSource): %p %d %lld %lld",
                            source.get(), mFd, (long long)mOffset, (long long)mLength);
                    if (source.get() != nullptr) {
                        mDataSource = CreateDataSourceFromIDataSource(source);
                        if (mDataSource != nullptr) {
                            // Close the local file descriptor as it is not needed anymore.
                            close(mFd);
                            mFd = -1;
                        }
                    } else {
                        ALOGW("extractor service cannot make data source");
                    }
                } else {
                    ALOGW("extractor service not running");
                }
        }
            if (mDataSource == nullptr) {
                ALOGD("FileSource local");
                mDataSource = new FileSource(mFd, mOffset, mLength);
            }
            // TODO: close should always be done on mFd, see the lines following
            // CreateDataSourceFromIDataSource above,
            // and the FileSource constructor should dup the mFd argument as needed.
            mFd = -1;
        }

        if (mDataSource == NULL) {
        if (mFd == -1 && mDataSource == NULL) {
            ALOGE("Failed to create data source!");
            notifyPreparedAndCleanup(UNKNOWN_ERROR);
            return;
        }
    }

    if (mDataSource->flags() & DataSource::kIsCachingDataSource) {
    if (mDataSource != nullptr && mDataSource->flags() & DataSource::kIsCachingDataSource) {
        mCachedSource = static_cast<NuCachedSource2 *>(mDataSource.get());
    }

+0 −8
Original line number Diff line number Diff line
@@ -113,10 +113,6 @@ sp<DecryptHandle> CallbackDataSource::DrmInitialization(const char *mime) {
    return mIDataSource->DrmInitialization(mime);
}

sp<IDataSource> CallbackDataSource::getIDataSource() const {
    return mIDataSource;
}

TinyCacheSource::TinyCacheSource(const sp<DataSource>& source)
    : mSource(source), mCachedOffset(0), mCachedSize(0) {
    mName = String8::format("TinyCacheSource(%s)", mSource->toString().string());
@@ -194,8 +190,4 @@ sp<DecryptHandle> TinyCacheSource::DrmInitialization(const char *mime) {
    return mSource->DrmInitialization(mime);
}

sp<IDataSource> TinyCacheSource::getIDataSource() const {
    return mSource->getIDataSource();
}

} // namespace android
Loading