Merge "Ndk wrapper: wrap new Ndk datasource/extractor APIs"

gugelfrei
TreeHugger Robot 6 years ago committed by Android (Google) Code Review
commit c91ac47d24

@ -1057,6 +1057,13 @@ status_t AMediaExtractorWrapper::setDataSource(const char *location) {
return translateErrorCode(AMediaExtractor_setDataSource(mAMediaExtractor, location));
}
status_t AMediaExtractorWrapper::setDataSource(AMediaDataSource *source) {
if (mAMediaExtractor == NULL) {
return DEAD_OBJECT;
}
return translateErrorCode(AMediaExtractor_setDataSourceCustom(mAMediaExtractor, source));
}
size_t AMediaExtractorWrapper::getTrackCount() {
if (mAMediaExtractor == NULL) {
return 0;
@ -1064,6 +1071,13 @@ size_t AMediaExtractorWrapper::getTrackCount() {
return AMediaExtractor_getTrackCount(mAMediaExtractor);
}
sp<AMediaFormatWrapper> AMediaExtractorWrapper::getFormat() {
if (mAMediaExtractor == NULL) {
return NULL;
}
return new AMediaFormatWrapper(AMediaExtractor_getFileFormat(mAMediaExtractor));
}
sp<AMediaFormatWrapper> AMediaExtractorWrapper::getTrackFormat(size_t idx) {
if (mAMediaExtractor == NULL) {
return NULL;
@ -1085,6 +1099,26 @@ status_t AMediaExtractorWrapper::unselectTrack(size_t idx) {
return translateErrorCode(AMediaExtractor_unselectTrack(mAMediaExtractor, idx));
}
status_t AMediaExtractorWrapper::selectSingleTrack(size_t idx) {
if (mAMediaExtractor == NULL) {
return DEAD_OBJECT;
}
for (size_t i = 0; i < AMediaExtractor_getTrackCount(mAMediaExtractor); ++i) {
if (i == idx) {
media_status_t err = AMediaExtractor_selectTrack(mAMediaExtractor, i);
if (err != AMEDIA_OK) {
return translateErrorCode(err);
}
} else {
media_status_t err = AMediaExtractor_unselectTrack(mAMediaExtractor, i);
if (err != AMEDIA_OK) {
return translateErrorCode(err);
}
}
}
return OK;
}
ssize_t AMediaExtractorWrapper::readSampleData(const sp<ABuffer> &buffer) {
if (mAMediaExtractor == NULL) {
return -1;
@ -1092,6 +1126,13 @@ ssize_t AMediaExtractorWrapper::readSampleData(const sp<ABuffer> &buffer) {
return AMediaExtractor_readSampleData(mAMediaExtractor, buffer->data(), buffer->capacity());
}
ssize_t AMediaExtractorWrapper::getSampleSize() {
if (mAMediaExtractor == NULL) {
return 0;
}
return AMediaExtractor_getSampleSize(mAMediaExtractor);
}
uint32_t AMediaExtractorWrapper::getSampleFlags() {
if (mAMediaExtractor == NULL) {
return 0;
@ -1113,6 +1154,13 @@ int64_t AMediaExtractorWrapper::getSampleTime() {
return AMediaExtractor_getSampleTime(mAMediaExtractor);
}
int64_t AMediaExtractorWrapper::getCachedDuration() {
if (mAMediaExtractor == NULL) {
return -1;
}
return AMediaExtractor_getCachedDuration(mAMediaExtractor);
}
bool AMediaExtractorWrapper::advance() {
if (mAMediaExtractor == NULL) {
return false;
@ -1120,11 +1168,27 @@ bool AMediaExtractorWrapper::advance() {
return AMediaExtractor_advance(mAMediaExtractor);
}
status_t AMediaExtractorWrapper::seekTo(int64_t seekPosUs, SeekMode mode) {
status_t AMediaExtractorWrapper::seekTo(int64_t seekPosUs, MediaSource::ReadOptions::SeekMode mode) {
if (mAMediaExtractor == NULL) {
return DEAD_OBJECT;
}
return AMediaExtractor_seekTo(mAMediaExtractor, seekPosUs, mode);
SeekMode aMode;
switch (mode) {
case MediaSource::ReadOptions::SEEK_PREVIOUS_SYNC: {
aMode = AMEDIAEXTRACTOR_SEEK_PREVIOUS_SYNC;
break;
}
case MediaSource::ReadOptions::SEEK_NEXT_SYNC: {
aMode = AMEDIAEXTRACTOR_SEEK_NEXT_SYNC;
break;
}
default: {
aMode = AMEDIAEXTRACTOR_SEEK_CLOSEST_SYNC;
break;
}
}
return AMediaExtractor_seekTo(mAMediaExtractor, seekPosUs, aMode);
}
PsshInfo* AMediaExtractorWrapper::getPsshInfo() {
@ -1141,4 +1205,43 @@ sp<AMediaCodecCryptoInfoWrapper> AMediaExtractorWrapper::getSampleCryptoInfo() {
return new AMediaCodecCryptoInfoWrapper(AMediaExtractor_getSampleCryptoInfo(mAMediaExtractor));
}
ssize_t AMediaDataSourceWrapper::AMediaDataSourceWrapper_getSize(void *userdata) {
DataSource *source = static_cast<DataSource *>(userdata);
off64_t size = -1;
source->getSize(&size);
return size;
}
ssize_t AMediaDataSourceWrapper::AMediaDataSourceWrapper_readAt(void *userdata, off64_t offset, void * buf, size_t size) {
DataSource *source = static_cast<DataSource *>(userdata);
return source->readAt(offset, buf, size);
}
void AMediaDataSourceWrapper::AMediaDataSourceWrapper_close(void *userdata) {
DataSource *source = static_cast<DataSource *>(userdata);
source->close();
}
AMediaDataSourceWrapper::AMediaDataSourceWrapper(const sp<DataSource> &dataSource)
: mDataSource(dataSource),
mAMediaDataSource(AMediaDataSource_new()) {
ALOGV("setDataSource (source: %p)", dataSource.get());
AMediaDataSource_setUserdata(mAMediaDataSource, dataSource.get());
AMediaDataSource_setReadAt(mAMediaDataSource, AMediaDataSourceWrapper_readAt);
AMediaDataSource_setGetSize(mAMediaDataSource, AMediaDataSourceWrapper_getSize);
AMediaDataSource_setClose(mAMediaDataSource, AMediaDataSourceWrapper_close);
}
AMediaDataSourceWrapper::~AMediaDataSourceWrapper() {
if (mAMediaDataSource == NULL) {
return;
}
AMediaDataSource_delete(mAMediaDataSource);
mAMediaDataSource = NULL;
}
AMediaDataSource* AMediaDataSourceWrapper::getAMediaDataSource() {
return mAMediaDataSource;
}
} // namespace android

@ -18,6 +18,9 @@
#define NDK_WRAPPER_H_
#include <media/DataSource.h>
#include <media/MediaSource.h>
#include <media/NdkMediaDataSource.h>
#include <media/NdkMediaError.h>
#include <media/NdkMediaExtractor.h>
#include <media/hardware/CryptoAPI.h>
@ -286,25 +289,35 @@ struct AMediaExtractorWrapper : public RefBase {
status_t setDataSource(const char *location);
status_t setDataSource(AMediaDataSource *);
size_t getTrackCount();
sp<AMediaFormatWrapper> getFormat();
sp<AMediaFormatWrapper> getTrackFormat(size_t idx);
status_t selectTrack(size_t idx);
status_t unselectTrack(size_t idx);
status_t selectSingleTrack(size_t idx);
ssize_t readSampleData(const sp<ABuffer> &buffer);
ssize_t getSampleSize();
uint32_t getSampleFlags();
int getSampleTrackIndex();
int64_t getSampleTime();
int64_t getCachedDuration();
bool advance();
status_t seekTo(int64_t seekPosUs, SeekMode mode);
status_t seekTo(int64_t seekPosUs, MediaSource::ReadOptions::SeekMode mode);
// the returned PsshInfo is still owned by this wrapper.
PsshInfo* getPsshInfo();
@ -320,6 +333,31 @@ private:
DISALLOW_EVIL_CONSTRUCTORS(AMediaExtractorWrapper);
};
struct AMediaDataSourceWrapper : public RefBase {
static status_t translate_error(media_status_t err);
static ssize_t AMediaDataSourceWrapper_getSize(void *userdata);
static ssize_t AMediaDataSourceWrapper_readAt(void *userdata, off64_t offset, void * buf, size_t size);
static void AMediaDataSourceWrapper_close(void *userdata);
AMediaDataSourceWrapper(const sp<DataSource> &dataSource);
AMediaDataSource *getAMediaDataSource();
protected:
virtual ~AMediaDataSourceWrapper();
private:
sp<DataSource> mDataSource;
AMediaDataSource *mAMediaDataSource;
DISALLOW_EVIL_CONSTRUCTORS(AMediaDataSourceWrapper);
};
} // namespace android
#endif // NDK_WRAPPER_H_

@ -215,6 +215,7 @@ cc_library {
"InterfaceUtils.cpp",
"MediaClock.cpp",
"MediaExtractorFactory.cpp",
"NdkUtils.cpp",
"NuCachedSource2.cpp",
"RemoteMediaExtractor.cpp",
"RemoteMediaSource.cpp",

@ -0,0 +1,33 @@
/*
* Copyright (C) 2018 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_NDEBUG 0
#include <media/stagefright/NdkUtils.h>
#include <media/stagefright/Utils.h>
#include <media/stagefright/foundation/AMessage.h>
namespace android {
sp<MetaData> convertMediaFormatWrapperToMetaData(const sp<AMediaFormatWrapper> &fmt) {
sp<AMessage> msg = fmt->toAMessage();
sp<MetaData> meta = new MetaData;
convertMessageToMetaData(msg, meta);
return meta;
}
} // namespace android

@ -0,0 +1,31 @@
/*
* Copyright (C) 2018 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 NDK_UTILS_H_
#define NDK_UTILS_H_
#include <media/stagefright/MetaData.h>
#include <media/NdkWrapper.h>
namespace android {
sp<MetaData> convertMediaFormatWrapperToMetaData(
const sp<AMediaFormatWrapper> &fmt);
} // namespace android
#endif // NDK_UTILS_H_

@ -44,7 +44,15 @@ struct AMediaDataSource {
};
NdkDataSource::NdkDataSource(AMediaDataSource *dataSource)
: mDataSource(dataSource) {
: mDataSource(AMediaDataSource_new()) {
AMediaDataSource_setReadAt(mDataSource, dataSource->readAt);
AMediaDataSource_setGetSize(mDataSource, dataSource->getSize);
AMediaDataSource_setClose(mDataSource, dataSource->close);
AMediaDataSource_setUserdata(mDataSource, dataSource->userdata);
}
NdkDataSource::~NdkDataSource() {
AMediaDataSource_delete(mDataSource);
}
status_t NdkDataSource::initCheck() const {

@ -49,6 +49,9 @@ struct NdkDataSource : public DataSource {
virtual String8 getMIMEType() const;
virtual void close();
protected:
virtual ~NdkDataSource();
private:
Mutex mLock;

Loading…
Cancel
Save