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

Commit fd1c19c3 authored by Andy Hung's avatar Andy Hung Committed by Android (Google) Code Review
Browse files

Merge "Allow MediaExtractor to create FileSource" into oc-dev

parents 34bc4d97 d49dbd6b
Loading
Loading
Loading
Loading
+35 −1
Original line number Diff line number Diff line
@@ -23,11 +23,13 @@
#include <sys/types.h>
#include <binder/Parcel.h>
#include <media/IMediaExtractorService.h>
#include <media/stagefright/MediaExtractor.h>

namespace android {

enum {
    MAKE_EXTRACTOR = IBinder::FIRST_CALL_TRANSACTION
    MAKE_EXTRACTOR = IBinder::FIRST_CALL_TRANSACTION,
    MAKE_IDATA_SOURCE_FD,
};

class BpMediaExtractorService : public BpInterface<IMediaExtractorService>
@@ -52,6 +54,21 @@ public:
        return NULL;
    }

    virtual sp<IDataSource> makeIDataSource(int fd, int64_t offset, int64_t length)
    {
        Parcel data, reply;
        data.writeInterfaceToken(IMediaExtractorService::getInterfaceDescriptor());
        data.writeFileDescriptor(fd);
        data.writeInt64(offset);
        data.writeInt64(length);
        status_t ret = remote()->transact(MAKE_IDATA_SOURCE_FD, data, &reply);
        ALOGV("fd:%d offset:%lld length:%lld ret:%d",
                fd, (long long)offset, (long long)length, ret);
        if (ret == NO_ERROR) {
            return interface_cast<IDataSource>(reply.readStrongBinder());
        }
        return nullptr;
    }
};

IMPLEMENT_META_INTERFACE(MediaExtractorService, "android.media.IMediaExtractorService");
@@ -80,6 +97,23 @@ status_t BnMediaExtractorService::onTransact(
            reply->writeStrongBinder(IInterface::asBinder(ex));
            return NO_ERROR;
        }

        case MAKE_IDATA_SOURCE_FD: {
            CHECK_INTERFACE(IMediaExtractorService, data, reply);
            const int fd = dup(data.readFileDescriptor()); // -1 fd checked in makeIDataSource
            const int64_t offset = data.readInt64();
            const int64_t length = data.readInt64();
            ALOGV("fd %d  offset%lld  length:%lld", fd, (long long)offset, (long long)length);
            sp<IDataSource> source = makeIDataSource(fd, offset, length);
            reply->writeStrongBinder(IInterface::asBinder(source));
            // The FileSource closes the descriptor, so if it is not created
            // we need to close the descriptor explicitly.
            if (source.get() == nullptr && fd != -1) {
                close(fd);
            }
            return NO_ERROR;
        }

        default:
            return BBinder::onTransact(code, data, reply, flags);
    }
+1 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ public:

    virtual sp<IMediaExtractor> makeExtractor(const sp<IDataSource> &source, const char *mime) = 0;

    virtual sp<IDataSource> makeIDataSource(int fd, int64_t offset, int64_t length) = 0;
};

class BnMediaExtractorService: public BnInterface<IMediaExtractorService>
+29 −2
Original line number Diff line number Diff line
@@ -21,7 +21,9 @@
#include "NuPlayerDrm.h"

#include "AnotherPacketSource.h"

#include <binder/IServiceManager.h>
#include <cutils/properties.h>
#include <media/IMediaExtractorService.h>
#include <media/IMediaHTTPService.h>
#include <media/stagefright/foundation/ABuffer.h>
#include <media/stagefright/foundation/ADebug.h>
@@ -361,7 +363,32 @@ void NuPlayer::GenericSource::onPrepareAsync() {
                   mHTTPService, uri, &mUriHeaders, &contentType,
                   static_cast<HTTPBase *>(mHttpSource.get()));
        } 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 = DataSource::CreateFromIDataSource(source);
                    } 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);
            }

            mFd = -1;
        }

+9 −0
Original line number Diff line number Diff line
@@ -113,6 +113,10 @@ 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());
@@ -190,4 +194,9 @@ sp<DecryptHandle> TinyCacheSource::DrmInitialization(const char *mime) {
    mCachedSize = 0;
    return mSource->DrmInitialization(mime);
}

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

} // namespace android
+15 −2
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
#include "include/HTTPBase.h"
#include "include/NuCachedSource2.h"

#include <media/IDataSource.h>
#include <media/IMediaHTTPConnection.h>
#include <media/IMediaHTTPService.h>
#include <media/stagefright/foundation/ADebug.h>
@@ -29,6 +30,7 @@
#include <media/stagefright/FileSource.h>
#include <media/stagefright/MediaErrors.h>
#include <media/stagefright/MediaHTTP.h>
#include <media/stagefright/RemoteDataSource.h>
#include <media/stagefright/Utils.h>
#include <utils/String8.h>

@@ -36,8 +38,6 @@

#include <private/android_filesystem_config.h>

#include <arpa/inet.h>

namespace android {

bool DataSource::getUInt16(off64_t offset, uint16_t *x) {
@@ -98,6 +98,10 @@ status_t DataSource::getSize(off64_t *size) {
    return ERROR_UNSUPPORTED;
}

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

////////////////////////////////////////////////////////////////////////////////

// static
@@ -167,6 +171,11 @@ sp<DataSource> DataSource::CreateFromURI(
    return source;
}

sp<DataSource> DataSource::CreateFromFd(int fd, int64_t offset, int64_t length) {
    sp<FileSource> source = new FileSource(fd, offset, length);
    return source->initCheck() != OK ? nullptr : source;
}

sp<DataSource> DataSource::CreateMediaHTTP(const sp<IMediaHTTPService> &httpService) {
    if (httpService == NULL) {
        return NULL;
@@ -188,4 +197,8 @@ String8 DataSource::getMIMEType() const {
    return String8("application/octet-stream");
}

sp<IDataSource> DataSource::asIDataSource() {
    return RemoteDataSource::wrap(sp<DataSource>(this));
}

}  // namespace android
Loading