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_
|
@ -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
|
@ -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
|
@ -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_
|
Loading…
Reference in new issue