Merge "AIDLize MediaExtractorService"

gugelfrei
Marco Nelissen 5 years ago committed by Android (Google) Code Review
commit 817fc5bbbe

@ -1 +0,0 @@
stagefright/DataSource.h

@ -0,0 +1,103 @@
/*
* Copyright (C) 2009 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef DATA_SOURCE_H_
#define DATA_SOURCE_H_
#include <sys/types.h>
#include <android/IDataSource.h>
#include <media/stagefright/MediaErrors.h>
#include <media/DataSourceBase.h>
#include <media/MediaExtractorPluginApi.h>
#include <utils/Errors.h>
#include <utils/RefBase.h>
#include <utils/threads.h>
namespace android {
class String8;
class DataSource : public DataSourceBase, public virtual RefBase {
public:
DataSource() : mWrapper(NULL) {}
// returns a pointer to IDataSource if it is wrapped.
virtual sp<IDataSource> getIDataSource() const {
return nullptr;
}
virtual String8 toString() {
return String8("<unspecified>");
}
virtual status_t reconnectAtOffset(off64_t /*offset*/) {
return ERROR_UNSUPPORTED;
}
////////////////////////////////////////////////////////////////////////////
virtual String8 getUri() {
return String8();
}
virtual bool getUri(char *uriString, size_t bufferSize) final {
int ret = snprintf(uriString, bufferSize, "%s", getUri().c_str());
return ret >= 0 && static_cast<size_t>(ret) < bufferSize;
}
virtual String8 getMIMEType() const {
return String8("application/octet-stream");
}
CDataSource *wrap() {
if (mWrapper) {
return mWrapper;
}
mWrapper = new CDataSource();
mWrapper->handle = this;
mWrapper->readAt = [](void *handle, off64_t offset, void *data, size_t size) -> ssize_t {
return ((DataSource*)handle)->readAt(offset, data, size);
};
mWrapper->getSize = [](void *handle, off64_t *size) -> status_t {
return ((DataSource*)handle)->getSize(size);
};
mWrapper->flags = [](void *handle) -> uint32_t {
return ((DataSource*)handle)->flags();
};
mWrapper->getUri = [](void *handle, char *uriString, size_t bufferSize) -> bool {
return ((DataSource*)handle)->getUri(uriString, bufferSize);
};
return mWrapper;
}
protected:
virtual ~DataSource() {
delete mWrapper;
}
private:
CDataSource *mWrapper;
DataSource(const DataSource &);
DataSource &operator=(const DataSource &);
};
} // namespace android
#endif // DATA_SOURCE_H_

@ -21,6 +21,7 @@
#include <media/DataSource.h>
#include <media/stagefright/foundation/ABase.h>
#include <media/stagefright/MediaErrors.h>
#include <utils/KeyedVector.h>
#include <utils/List.h>
#include <utils/threads.h>

@ -21,10 +21,10 @@
#include <stdio.h>
#include <android/IDataSource.h>
#include <binder/IMemory.h>
#include <binder/MemoryDealer.h>
#include <drm/drm_framework_common.h>
#include <media/IDataSource.h>
#include <media/mediametadataretriever.h>
#include <media/MediaSource.h>
#include <media/stagefright/foundation/ADebug.h>

@ -23,6 +23,14 @@ filegroup {
path: "aidl",
}
filegroup {
name: "mediaextractorservice_aidl",
srcs: [
"aidl/android/IMediaExtractorService.aidl",
],
path: "aidl",
}
aidl_interface {
name: "resourcemanager_aidl_interface",
local_include_dir: "aidl",
@ -249,13 +257,13 @@ cc_library {
name: "libmedia",
srcs: [
":mediaextractorservice_aidl",
"IDataSource.cpp",
"BufferingSettings.cpp",
"mediaplayer.cpp",
"IMediaHTTPConnection.cpp",
"IMediaHTTPService.cpp",
"IMediaExtractor.cpp",
"IMediaExtractorService.cpp",
"IMediaPlayerService.cpp",
"IMediaPlayerClient.cpp",
"IMediaRecorderClient.cpp",

@ -19,8 +19,7 @@
#include <utils/Log.h>
#include <utils/Timers.h>
#include <media/IDataSource.h>
#include <android/IDataSource.h>
#include <binder/IMemory.h>
#include <binder/Parcel.h>
#include <media/stagefright/foundation/ADebug.h>

@ -25,7 +25,7 @@
#include <binder/IPCThreadState.h>
#include <binder/Parcel.h>
#include <binder/PermissionCache.h>
#include <media/IMediaExtractor.h>
#include <android/IMediaExtractor.h>
#include <media/stagefright/MetaData.h>
namespace android {

@ -1,151 +0,0 @@
/*
**
** Copyright 2007, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
#define LOG_TAG "IMediaExtractorService"
//#define LOG_NDEBUG 0
#include <utils/Log.h>
#include <stdint.h>
#include <sys/types.h>
#include <binder/Parcel.h>
#include <media/IMediaExtractorService.h>
namespace android {
enum {
MAKE_EXTRACTOR = IBinder::FIRST_CALL_TRANSACTION,
MAKE_IDATA_SOURCE_FD,
GET_SUPPORTED_TYPES,
};
class BpMediaExtractorService : public BpInterface<IMediaExtractorService>
{
public:
explicit BpMediaExtractorService(const sp<IBinder>& impl)
: BpInterface<IMediaExtractorService>(impl)
{
}
virtual sp<IMediaExtractor> makeExtractor(const sp<IDataSource> &source, const char *mime) {
Parcel data, reply;
data.writeInterfaceToken(IMediaExtractorService::getInterfaceDescriptor());
data.writeStrongBinder(IInterface::asBinder(source));
if (mime != NULL) {
data.writeCString(mime);
}
status_t ret = remote()->transact(MAKE_EXTRACTOR, data, &reply);
if (ret == NO_ERROR) {
return interface_cast<IMediaExtractor>(reply.readStrongBinder());
}
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;
}
virtual std::unordered_set<std::string> getSupportedTypes() {
std::unordered_set<std::string> supportedTypes;
Parcel data, reply;
data.writeInterfaceToken(IMediaExtractorService::getInterfaceDescriptor());
status_t ret = remote()->transact(GET_SUPPORTED_TYPES, data, &reply);
if (ret == NO_ERROR) {
// process reply
while(true) {
const char *ext = reply.readCString();
if (!ext) {
break;
}
supportedTypes.insert(std::string(ext));
}
}
return supportedTypes;
}
};
IMPLEMENT_META_INTERFACE(MediaExtractorService, "android.media.IMediaExtractorService");
// ----------------------------------------------------------------------
status_t BnMediaExtractorService::onTransact(
uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
{
switch (code) {
case MAKE_EXTRACTOR: {
CHECK_INTERFACE(IMediaExtractorService, data, reply);
sp<IBinder> b;
status_t ret = data.readStrongBinder(&b);
if (ret != NO_ERROR || b == NULL) {
ALOGE("Error reading source from parcel");
return ret;
}
// If we make an extractor through Binder, enabled shared memory
// for MediaBuffers for this process.
MediaBuffer::useSharedMemory();
sp<IDataSource> source = interface_cast<IDataSource>(b);
const char *mime = data.readCString();
sp<IMediaExtractor> ex = makeExtractor(source, mime);
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;
}
case GET_SUPPORTED_TYPES:
{
CHECK_INTERFACE(IMediaExtractorService, data, reply);
std::unordered_set<std::string> supportedTypes = getSupportedTypes();
for (auto it = supportedTypes.begin(); it != supportedTypes.end(); ++it) {
reply->writeCString((*it).c_str());
}
return NO_ERROR;
}
default:
return BBinder::onTransact(code, data, reply, flags);
}
}
// ----------------------------------------------------------------------------
} // namespace android

@ -19,8 +19,8 @@
#include <stdint.h>
#include <sys/types.h>
#include <android/IDataSource.h>
#include <binder/Parcel.h>
#include <media/IDataSource.h>
#include <media/IMediaHTTPService.h>
#include <media/IMediaMetadataRetriever.h>
#include <processgroup/sched_policy.h>

@ -19,18 +19,15 @@
#include <stdint.h>
#include <sys/types.h>
#include <android/IDataSource.h>
#include <binder/Parcel.h>
#include <gui/IGraphicBufferProducer.h>
#include <media/AudioResamplerPublic.h>
#include <media/AVSyncSettings.h>
#include <media/BufferingSettings.h>
#include <media/IDataSource.h>
#include <media/IMediaHTTPService.h>
#include <media/IMediaPlayer.h>
#include <media/IStreamSource.h>
#include <gui/IGraphicBufferProducer.h>
#include <utils/String8.h>
namespace android {

@ -0,0 +1,22 @@
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android;
/** @hide */
interface IDataSource {
// Stub for manual implementation
}

@ -0,0 +1,22 @@
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android;
/** @hide */
interface IMediaExtractor {
// Stub for manual implementation
}

@ -0,0 +1,32 @@
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android;
import android.IDataSource;
import android.IMediaExtractor;
/**
* Binder interface for the media extractor service
*
* @hide
*/
interface IMediaExtractorService {
IMediaExtractor makeExtractor(IDataSource source, @nullable @utf8InCpp String mime);
IDataSource makeIDataSource(in FileDescriptor fd, long offset, long length);
@utf8InCpp String[] getSupportedTypes();
}

@ -1,51 +0,0 @@
/*
* Copyright (C) 2013 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ANDROID_IMEDIAEXTRACTORSERVICE_H
#define ANDROID_IMEDIAEXTRACTORSERVICE_H
#include <unordered_set>
#include <binder/IInterface.h>
#include <binder/IMemory.h>
#include <binder/Parcel.h>
#include <media/IDataSource.h>
#include <media/IMediaExtractor.h>
namespace android {
class IMediaExtractorService: public IInterface
{
public:
DECLARE_META_INTERFACE(MediaExtractorService);
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;
virtual std::unordered_set<std::string> getSupportedTypes() = 0;
};
class BnMediaExtractorService: public BnInterface<IMediaExtractorService>
{
public:
virtual status_t onTransact(uint32_t code, const Parcel& data, Parcel* reply,
uint32_t flags = 0);
};
} // namespace android
#endif // ANDROID_IMEDIAEXTRACTORSERVICE_H

@ -17,6 +17,7 @@
//#define LOG_NDEBUG 0
#define LOG_TAG "MediaPlayerNative"
#include <utils/Log.h>
#include <fcntl.h>
#include <inttypes.h>
@ -24,25 +25,15 @@
#include <sys/types.h>
#include <unistd.h>
#include <utils/Log.h>
#include <binder/IServiceManager.h>
#include <android/IDataSource.h>
#include <binder/IPCThreadState.h>
#include <gui/Surface.h>
#include <media/mediaplayer.h>
#include <media/AudioResamplerPublic.h>
#include <media/AudioSystem.h>
#include <media/AVSyncSettings.h>
#include <media/IDataSource.h>
#include <media/MediaAnalyticsItem.h>
#include <binder/MemoryBase.h>
#include <utils/KeyedVector.h>
#include <utils/String8.h>
#include <system/audio.h>
#include <system/window.h>

@ -18,7 +18,7 @@
#define STAGEFRIGHT_METADATA_RETRIEVER_H_
#include <media/IMediaExtractor.h>
#include <android/IMediaExtractor.h>
#include <media/MediaMetadataRetrieverInterface.h>
#include <utils/KeyedVector.h>

@ -19,6 +19,7 @@
#define PLAYER_SERVICE_MEDIA_HTTP_H_
#include <datasource/MediaHTTP.h>
#include <drm/DrmManagerClient.h>
#include <media/stagefright/foundation/AString.h>
namespace android {

@ -30,12 +30,13 @@
#include <media/DataSource.h>
#include <media/MediaBufferHolder.h>
#include <media/MediaSource.h>
#include <media/IMediaExtractorService.h>
#include <android/IMediaExtractorService.h>
#include <media/IMediaHTTPService.h>
#include <media/stagefright/foundation/ABuffer.h>
#include <media/stagefright/foundation/ADebug.h>
#include <media/stagefright/foundation/AMessage.h>
#include <media/stagefright/InterfaceUtils.h>
#include <media/stagefright/FoundationUtils.h>
#include <media/stagefright/MediaBuffer.h>
#include <media/stagefright/MediaClock.h>
#include <media/stagefright/MediaDefs.h>
@ -75,7 +76,6 @@ NuPlayer::GenericSource::GenericSource(
mUIDValid(uidValid),
mUID(uid),
mMediaClock(mediaClock),
mFd(-1),
mBitrate(-1LL),
mPendingReadBufferTypes(0) {
ALOGV("GenericSource");
@ -98,10 +98,7 @@ void NuPlayer::GenericSource::resetDataSource() {
mUri.clear();
mUriHeaders.clear();
mSources.clear();
if (mFd >= 0) {
close(mFd);
mFd = -1;
}
mFd.reset();
mOffset = 0;
mLength = 0;
mStarted = false;
@ -137,11 +134,11 @@ status_t NuPlayer::GenericSource::setDataSource(
status_t NuPlayer::GenericSource::setDataSource(
int fd, int64_t offset, int64_t length) {
Mutex::Autolock _l(mLock);
ALOGV("setDataSource %d/%lld/%lld", fd, (long long)offset, (long long)length);
ALOGV("setDataSource %d/%lld/%lld (%s)", fd, (long long)offset, (long long)length, nameForFd(fd).c_str());
resetDataSource();
mFd = dup(fd);
mFd.reset(dup(fd));
mOffset = offset;
mLength = length;
@ -413,24 +410,19 @@ void NuPlayer::GenericSource::onPrepareAsync() {
} else {
if (property_get_bool("media.stagefright.extractremote", true) &&
!PlayerServiceFileSource::requiresDrm(
mFd, mOffset, mLength, nullptr /* mime */)) {
mFd.get(), 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);
sp<IDataSource> source;
mediaExService->makeIDataSource(mFd, mOffset, mLength, &source);
ALOGV("IDataSource(FileSource): %p %d %lld %lld",
source.get(), mFd, (long long)mOffset, (long long)mLength);
source.get(), mFd.get(), (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");
}
@ -440,12 +432,8 @@ void NuPlayer::GenericSource::onPrepareAsync() {
}
if (mDataSource == nullptr) {
ALOGD("FileSource local");
mDataSource = new PlayerServiceFileSource(mFd, mOffset, mLength);
mDataSource = new PlayerServiceFileSource(mFd.get(), 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) {

@ -23,6 +23,7 @@
#include "ATSParser.h"
#include <android-base/unique_fd.h>
#include <media/mediaplayer.h>
#include <media/stagefright/MediaBuffer.h>
@ -154,7 +155,7 @@ private:
sp<IMediaHTTPService> mHTTPService;
AString mUri;
KeyedVector<String8, String8> mUriHeaders;
int mFd;
base::unique_fd mFd;
int64_t mOffset;
int64_t mLength;

@ -20,9 +20,9 @@
#include "include/CallbackDataSource.h"
#include <android/IDataSource.h>
#include <binder/IMemory.h>
#include <binder/IPCThreadState.h>
#include <media/IDataSource.h>
#include <media/stagefright/foundation/ADebug.h>
#include <algorithm>

@ -27,8 +27,8 @@
#include <media/stagefright/InterfaceUtils.h>
#include <media/stagefright/MediaExtractor.h>
#include <media/stagefright/MediaExtractorFactory.h>
#include <media/IMediaExtractor.h>
#include <media/IMediaExtractorService.h>
#include <android/IMediaExtractor.h>
#include <android/IMediaExtractorService.h>
#include <nativeloader/dlext_namespaces.h>
#include <private/android_filesystem_config.h>
#include <cutils/properties.h>
@ -54,9 +54,13 @@ sp<IMediaExtractor> MediaExtractorFactory::Create(
sp<IBinder> binder = defaultServiceManager()->getService(String16("media.extractor"));
if (binder != 0) {
sp<IMediaExtractorService> mediaExService(interface_cast<IMediaExtractorService>(binder));
sp<IMediaExtractor> ex = mediaExService->makeExtractor(
CreateIDataSourceFromDataSource(source), mime);
sp<IMediaExtractorService> mediaExService(
interface_cast<IMediaExtractorService>(binder));
sp<IMediaExtractor> ex;
mediaExService->makeExtractor(
CreateIDataSourceFromDataSource(source),
mime ? std::make_unique<std::string>(mime) : nullptr,
&ex);
return ex;
} else {
ALOGE("extractor service not running");
@ -262,7 +266,7 @@ static bool compareFunc(const sp<ExtractorPlugin>& first, const sp<ExtractorPlug
return strcmp(first->def.extractor_name, second->def.extractor_name) < 0;
}
static std::unordered_set<std::string> gSupportedExtensions;
static std::vector<std::string> gSupportedExtensions;
// static
void MediaExtractorFactory::LoadExtractors() {
@ -308,7 +312,7 @@ void MediaExtractorFactory::LoadExtractors() {
if (ext == nullptr) {
break;
}
gSupportedExtensions.insert(std::string(ext));
gSupportedExtensions.push_back(std::string(ext));
}
}
}
@ -317,7 +321,7 @@ void MediaExtractorFactory::LoadExtractors() {
}
// static
std::unordered_set<std::string> MediaExtractorFactory::getSupportedTypes() {
std::vector<std::string> MediaExtractorFactory::getSupportedTypes() {
if (getuid() == AID_MEDIA_EX) {
return gSupportedExtensions;
}
@ -326,9 +330,11 @@ std::unordered_set<std::string> MediaExtractorFactory::getSupportedTypes() {
if (binder != 0) {
sp<IMediaExtractorService> mediaExService(interface_cast<IMediaExtractorService>(binder));
return mediaExService->getSupportedTypes();
std::vector<std::string> supportedTypes;
mediaExService->getSupportedTypes(&supportedTypes);
return supportedTypes;
}
return std::unordered_set<std::string>();
return std::vector<std::string>();
}
status_t MediaExtractorFactory::dump(int fd, const Vector<String16>&) {

@ -35,7 +35,7 @@ StagefrightMediaScanner::StagefrightMediaScanner() {}
StagefrightMediaScanner::~StagefrightMediaScanner() {}
static std::unordered_set<std::string> gSupportedExtensions;
static std::vector<std::string> gSupportedExtensions;
static bool FileHasAcceptableExtension(const char *extension) {
@ -44,7 +44,12 @@ static bool FileHasAcceptableExtension(const char *extension) {
gSupportedExtensions = MediaExtractorFactory::getSupportedTypes();
}
return gSupportedExtensions.count(std::string(extension + 1)) != 0;
for (auto ext: gSupportedExtensions) {
if (ext == (extension + 1)) {
return true;
}
}
return false;
}
MediaScanResult StagefrightMediaScanner::processFile(

@ -1,103 +0,0 @@
/*
* Copyright (C) 2009 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef DATA_SOURCE_H_
#define DATA_SOURCE_H_
#include <sys/types.h>
#include <media/stagefright/MediaErrors.h>
#include <media/DataSourceBase.h>
#include <media/IDataSource.h>
#include <media/MediaExtractorPluginApi.h>
#include <utils/Errors.h>
#include <utils/RefBase.h>
#include <utils/threads.h>
#include <drm/DrmManagerClient.h>
namespace android {
class String8;
class DataSource : public DataSourceBase, public virtual RefBase {
public:
DataSource() : mWrapper(NULL) {}
// returns a pointer to IDataSource if it is wrapped.
virtual sp<IDataSource> getIDataSource() const {
return nullptr;
}
virtual String8 toString() {
return String8("<unspecified>");
}
virtual status_t reconnectAtOffset(off64_t /*offset*/) {
return ERROR_UNSUPPORTED;
}
////////////////////////////////////////////////////////////////////////////
virtual String8 getUri() {
return String8();
}
virtual bool getUri(char *uriString, size_t bufferSize) final {
int ret = snprintf(uriString, bufferSize, "%s", getUri().c_str());
return ret >= 0 && static_cast<size_t>(ret) < bufferSize;
}
virtual String8 getMIMEType() const {
return String8("application/octet-stream");
}
CDataSource *wrap() {
if (mWrapper) {
return mWrapper;
}
mWrapper = new CDataSource();
mWrapper->handle = this;
mWrapper->readAt = [](void *handle, off64_t offset, void *data, size_t size) -> ssize_t {
return ((DataSource*)handle)->readAt(offset, data, size);
};
mWrapper->getSize = [](void *handle, off64_t *size) -> status_t {
return ((DataSource*)handle)->getSize(size);
};
mWrapper->flags = [](void *handle) -> uint32_t {
return ((DataSource*)handle)->flags();
};
mWrapper->getUri = [](void *handle, char *uriString, size_t bufferSize) -> bool {
return ((DataSource*)handle)->getUri(uriString, bufferSize);
};
return mWrapper;
}
protected:
virtual ~DataSource() {
delete mWrapper;
}
private:
CDataSource *mWrapper;
DataSource(const DataSource &);
DataSource &operator=(const DataSource &);
};
} // namespace android
#endif // DATA_SOURCE_H_

@ -20,7 +20,7 @@
#include <utils/RefBase.h>
#include <media/stagefright/RemoteMediaExtractor.h>
#include <media/MediaSource.h>
#include <media/IMediaExtractor.h>
#include <android/IMediaExtractor.h>
#include <media/IMediaSource.h>
namespace android {

@ -22,7 +22,7 @@
#include <unordered_set>
#include <android/dlext.h>
#include <media/IMediaExtractor.h>
#include <android/IMediaExtractor.h>
namespace android {
@ -36,7 +36,7 @@ public:
static sp<IMediaExtractor> CreateFromService(
const sp<DataSource> &source, const char *mime = NULL);
static status_t dump(int fd, const Vector<String16>& args);
static std::unordered_set<std::string> getSupportedTypes();
static std::vector<std::string> getSupportedTypes();
static void LoadExtractors();
private:

@ -21,7 +21,7 @@
#include <media/mediaplayer.h>
#include <media/stagefright/foundation/ABase.h>
#include <media/stagefright/foundation/AudioPresentationInfo.h>
#include <media/IMediaExtractor.h>
#include <android/IMediaExtractor.h>
#include <media/MediaSource.h>
#include <utils/Errors.h>
#include <utils/KeyedVector.h>

@ -17,10 +17,10 @@
#ifndef REMOTE_DATA_SOURCE_H_
#define REMOTE_DATA_SOURCE_H_
#include <android/IDataSource.h>
#include <binder/IMemory.h>
#include <binder/MemoryDealer.h>
#include <media/DataSource.h>
#include <media/IDataSource.h>
namespace android {

@ -17,7 +17,7 @@
#ifndef REMOTE_MEDIA_EXTRACTOR_H_
#define REMOTE_MEDIA_EXTRACTOR_H_
#include <media/IMediaExtractor.h>
#include <android/IMediaExtractor.h>
#include <media/stagefright/MediaExtractor.h>
#include <media/stagefright/foundation/ABase.h>

@ -29,48 +29,57 @@
namespace android {
MediaExtractorService::MediaExtractorService()
: BnMediaExtractorService() {
MediaExtractorService::MediaExtractorService() {
MediaExtractorFactory::LoadExtractors();
}
sp<IMediaExtractor> MediaExtractorService::makeExtractor(
const sp<IDataSource> &remoteSource, const char *mime) {
ALOGV("@@@ MediaExtractorService::makeExtractor for %s", mime);
MediaExtractorService::~MediaExtractorService() {
ALOGE("should not be in ~MediaExtractorService");
}
::android::binder::Status MediaExtractorService::makeExtractor(
const ::android::sp<::android::IDataSource>& remoteSource,
const ::std::unique_ptr< ::std::string> &mime,
::android::sp<::android::IMediaExtractor>* _aidl_return) {
ALOGV("@@@ MediaExtractorService::makeExtractor for %s", mime.get()->c_str());
sp<DataSource> localSource = CreateDataSourceFromIDataSource(remoteSource);
sp<IMediaExtractor> extractor = MediaExtractorFactory::CreateFromService(localSource, mime);
sp<IMediaExtractor> extractor = MediaExtractorFactory::CreateFromService(
localSource,
mime.get() ? mime.get()->c_str() : nullptr);
ALOGV("extractor service created %p (%s)",
extractor.get(),
extractor == nullptr ? "" : extractor->name());
if (extractor != nullptr) {
registerMediaExtractor(extractor, localSource, mime);
return extractor;
registerMediaExtractor(extractor, localSource, mime.get() ? mime.get()->c_str() : nullptr);
}
return nullptr;
*_aidl_return = extractor;
return binder::Status::ok();
}
sp<IDataSource> MediaExtractorService::makeIDataSource(int fd, int64_t offset, int64_t length)
{
sp<DataSource> source = DataSourceFactory::getInstance()->CreateFromFd(fd, offset, length);
return CreateIDataSourceFromDataSource(source);
::android::binder::Status MediaExtractorService::makeIDataSource(
const base::unique_fd &fd,
int64_t offset,
int64_t length,
::android::sp<::android::IDataSource>* _aidl_return) {
// the caller will close the fd owned by the unique_fd upon return of this function,
// so we need to dup() it to retain it.
sp<DataSource> source = DataSourceFactory::getInstance()->CreateFromFd(dup(fd.get()), offset, length);
*_aidl_return = CreateIDataSourceFromDataSource(source);
return binder::Status::ok();
}
std::unordered_set<std::string> MediaExtractorService::getSupportedTypes() {
return MediaExtractorFactory::getSupportedTypes();
::android::binder::Status MediaExtractorService::getSupportedTypes(
::std::vector<::std::string>* _aidl_return) {
*_aidl_return = MediaExtractorFactory::getSupportedTypes();
return binder::Status::ok();
}
status_t MediaExtractorService::dump(int fd, const Vector<String16>& args) {
return MediaExtractorFactory::dump(fd, args) || dumpExtractors(fd, args);
}
status_t MediaExtractorService::onTransact(uint32_t code, const Parcel& data, Parcel* reply,
uint32_t flags)
{
return BnMediaExtractorService::onTransact(code, data, reply, flags);
}
} // namespace android

@ -18,31 +18,33 @@
#define ANDROID_MEDIA_EXTRACTOR_SERVICE_H
#include <binder/BinderService.h>
#include <media/IMediaExtractorService.h>
#include <media/IMediaExtractor.h>
#include <android/BnMediaExtractorService.h>
#include <android/IMediaExtractor.h>
namespace android {
class MediaExtractorService : public BinderService<MediaExtractorService>, public BnMediaExtractorService
{
friend class BinderService<MediaExtractorService>; // for MediaExtractorService()
public:
MediaExtractorService();
virtual ~MediaExtractorService() { }
virtual void onFirstRef() { }
virtual ~MediaExtractorService();
static const char* getServiceName() { return "media.extractor"; }
virtual sp<IMediaExtractor> makeExtractor(const sp<IDataSource> &source, const char *mime);
virtual ::android::binder::Status makeExtractor(
const ::android::sp<::android::IDataSource>& source,
const ::std::unique_ptr< ::std::string> &mime,
::android::sp<::android::IMediaExtractor>* _aidl_return);
virtual sp<IDataSource> makeIDataSource(int fd, int64_t offset, int64_t length);
virtual ::android::binder::Status makeIDataSource(
const base::unique_fd &fd,
int64_t offset,
int64_t length,
::android::sp<::android::IDataSource>* _aidl_return);
virtual std::unordered_set<std::string> getSupportedTypes();
virtual ::android::binder::Status getSupportedTypes(::std::vector<::std::string>* _aidl_return);
virtual status_t dump(int fd, const Vector<String16>& args);
virtual status_t onTransact(uint32_t code, const Parcel& data, Parcel* reply,
uint32_t flags);
virtual status_t dump(int fd, const Vector<String16>& args);
private:
Mutex mLock;

Loading…
Cancel
Save