Test: atest CtsMediaTestCases -- --module-arg CtsMediaTestCases:size:small Bug: 136283874 Change-Id: I7562c7770750baa733bca83a7f65f5ac0bd1b887gugelfrei
parent
1bd7d37742
commit
155d5cbd00
@ -1,206 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2012 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
|
||||
#define LOG_TAG "SkipCutBuffer"
|
||||
#include <utils/Log.h>
|
||||
|
||||
#include <media/stagefright/foundation/ADebug.h>
|
||||
#include <media/stagefright/MediaBuffer.h>
|
||||
#include "SkipCutBuffer.h"
|
||||
|
||||
namespace android {
|
||||
|
||||
SkipCutBuffer::SkipCutBuffer(size_t skip, size_t cut, size_t num16BitChannels) {
|
||||
|
||||
mWriteHead = 0;
|
||||
mReadHead = 0;
|
||||
mCapacity = 0;
|
||||
mCutBuffer = nullptr;
|
||||
|
||||
if (num16BitChannels == 0 || num16BitChannels > INT32_MAX / 2) {
|
||||
ALOGW("# channels out of range: %zu, using passthrough instead", num16BitChannels);
|
||||
return;
|
||||
}
|
||||
size_t frameSize = num16BitChannels * 2;
|
||||
if (skip > INT32_MAX / frameSize || cut > INT32_MAX / frameSize
|
||||
|| cut * frameSize > INT32_MAX - 4096) {
|
||||
ALOGW("out of range skip/cut: %zu/%zu, using passthrough instead",
|
||||
skip, cut);
|
||||
return;
|
||||
}
|
||||
skip *= frameSize;
|
||||
cut *= frameSize;
|
||||
|
||||
mFrontPadding = mSkip = skip;
|
||||
mBackPadding = cut;
|
||||
mCapacity = cut + 4096;
|
||||
mCutBuffer = new (std::nothrow) char[mCapacity];
|
||||
ALOGV("skipcutbuffer %zu %zu %d", skip, cut, mCapacity);
|
||||
}
|
||||
|
||||
SkipCutBuffer::~SkipCutBuffer() {
|
||||
delete[] mCutBuffer;
|
||||
}
|
||||
|
||||
void SkipCutBuffer::submit(MediaBuffer *buffer) {
|
||||
if (mCutBuffer == nullptr) {
|
||||
// passthrough mode
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t offset = buffer->range_offset();
|
||||
int32_t buflen = buffer->range_length();
|
||||
|
||||
// drop the initial data from the buffer if needed
|
||||
if (mFrontPadding > 0) {
|
||||
// still data left to drop
|
||||
int32_t to_drop = (buflen < mFrontPadding) ? buflen : mFrontPadding;
|
||||
offset += to_drop;
|
||||
buflen -= to_drop;
|
||||
buffer->set_range(offset, buflen);
|
||||
mFrontPadding -= to_drop;
|
||||
}
|
||||
|
||||
|
||||
// append data to cutbuffer
|
||||
char *src = ((char*) buffer->data()) + offset;
|
||||
write(src, buflen);
|
||||
|
||||
|
||||
// the mediabuffer is now empty. Fill it from cutbuffer, always leaving
|
||||
// at least mBackPadding bytes in the cutbuffer
|
||||
char *dst = (char*) buffer->data();
|
||||
size_t copied = read(dst, buffer->size());
|
||||
buffer->set_range(0, copied);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void SkipCutBuffer::submitInternal(const sp<T>& buffer) {
|
||||
if (mCutBuffer == nullptr) {
|
||||
// passthrough mode
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t offset = buffer->offset();
|
||||
int32_t buflen = buffer->size();
|
||||
|
||||
// drop the initial data from the buffer if needed
|
||||
if (mFrontPadding > 0) {
|
||||
// still data left to drop
|
||||
int32_t to_drop = (buflen < mFrontPadding) ? buflen : mFrontPadding;
|
||||
offset += to_drop;
|
||||
buflen -= to_drop;
|
||||
buffer->setRange(offset, buflen);
|
||||
mFrontPadding -= to_drop;
|
||||
}
|
||||
|
||||
|
||||
// append data to cutbuffer
|
||||
char *src = (char*) buffer->data();
|
||||
write(src, buflen);
|
||||
|
||||
|
||||
// the mediabuffer is now empty. Fill it from cutbuffer, always leaving
|
||||
// at least mBackPadding bytes in the cutbuffer
|
||||
char *dst = (char*) buffer->base();
|
||||
size_t copied = read(dst, buffer->capacity());
|
||||
buffer->setRange(0, copied);
|
||||
}
|
||||
|
||||
void SkipCutBuffer::submit(const sp<ABuffer>& buffer) {
|
||||
submitInternal(buffer);
|
||||
}
|
||||
|
||||
void SkipCutBuffer::submit(const sp<MediaCodecBuffer>& buffer) {
|
||||
submitInternal(buffer);
|
||||
}
|
||||
|
||||
void SkipCutBuffer::clear() {
|
||||
mWriteHead = mReadHead = 0;
|
||||
mFrontPadding = mSkip;
|
||||
}
|
||||
|
||||
void SkipCutBuffer::write(const char *src, size_t num) {
|
||||
int32_t sizeused = (mWriteHead - mReadHead);
|
||||
if (sizeused < 0) sizeused += mCapacity;
|
||||
|
||||
// Everything must fit. Make sure the buffer is a little larger than needed,
|
||||
// so there is no ambiguity as to whether mWriteHead == mReadHead means buffer
|
||||
// full or empty
|
||||
size_t available = mCapacity - sizeused - 32;
|
||||
if (available < num) {
|
||||
int32_t newcapacity = mCapacity + (num - available);
|
||||
char * newbuffer = new char[newcapacity];
|
||||
memcpy(newbuffer, mCutBuffer, mCapacity);
|
||||
delete [] mCutBuffer;
|
||||
mCapacity = newcapacity;
|
||||
mCutBuffer = newbuffer;
|
||||
ALOGV("reallocated buffer at size %d", newcapacity);
|
||||
}
|
||||
|
||||
size_t copyfirst = (mCapacity - mWriteHead);
|
||||
if (copyfirst > num) copyfirst = num;
|
||||
if (copyfirst) {
|
||||
memcpy(mCutBuffer + mWriteHead, src, copyfirst);
|
||||
num -= copyfirst;
|
||||
src += copyfirst;
|
||||
mWriteHead += copyfirst;
|
||||
CHECK_LE(mWriteHead, mCapacity);
|
||||
if (mWriteHead == mCapacity) mWriteHead = 0;
|
||||
if (num) {
|
||||
memcpy(mCutBuffer, src, num);
|
||||
mWriteHead += num;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
size_t SkipCutBuffer::read(char *dst, size_t num) {
|
||||
int32_t available = (mWriteHead - mReadHead);
|
||||
if (available < 0) available += mCapacity;
|
||||
|
||||
available -= mBackPadding;
|
||||
if (available <=0) {
|
||||
return 0;
|
||||
}
|
||||
if (available < int32_t(num)) {
|
||||
num = available;
|
||||
}
|
||||
|
||||
size_t copyfirst = (mCapacity - mReadHead);
|
||||
if (copyfirst > num) copyfirst = num;
|
||||
if (copyfirst) {
|
||||
memcpy(dst, mCutBuffer + mReadHead, copyfirst);
|
||||
num -= copyfirst;
|
||||
dst += copyfirst;
|
||||
mReadHead += copyfirst;
|
||||
CHECK_LE(mReadHead, mCapacity);
|
||||
if (mReadHead == mCapacity) mReadHead = 0;
|
||||
if (num) {
|
||||
memcpy(dst, mCutBuffer, num);
|
||||
mReadHead += num;
|
||||
}
|
||||
}
|
||||
return available;
|
||||
}
|
||||
|
||||
size_t SkipCutBuffer::size() {
|
||||
int32_t available = (mWriteHead - mReadHead);
|
||||
if (available < 0) available += mCapacity;
|
||||
return available;
|
||||
}
|
||||
|
||||
} // namespace android
|
@ -1,67 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2012 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 SKIP_CUT_BUFFER_H_
|
||||
|
||||
#define SKIP_CUT_BUFFER_H_
|
||||
|
||||
#include <media/MediaCodecBuffer.h>
|
||||
#include <media/stagefright/MediaBuffer.h>
|
||||
#include <media/stagefright/foundation/ABuffer.h>
|
||||
|
||||
namespace android {
|
||||
|
||||
/**
|
||||
* utility class to cut the start and end off a stream of data in MediaBuffers
|
||||
*
|
||||
*/
|
||||
class SkipCutBuffer: public RefBase {
|
||||
public:
|
||||
// 'skip' is the number of frames to skip from the beginning
|
||||
// 'cut' is the number of frames to cut from the end
|
||||
// 'num16BitChannels' is the number of channels, which are assumed to be 16 bit wide each
|
||||
SkipCutBuffer(size_t skip, size_t cut, size_t num16Channels);
|
||||
|
||||
// Submit one MediaBuffer for skipping and cutting. This may consume all or
|
||||
// some of the data in the buffer, or it may add data to it.
|
||||
// After this, the caller should continue processing the buffer as usual.
|
||||
void submit(MediaBuffer *buffer);
|
||||
void submit(const sp<ABuffer>& buffer); // same as above, but with an ABuffer
|
||||
void submit(const sp<MediaCodecBuffer>& buffer); // same as above, but with an ABuffer
|
||||
void clear();
|
||||
size_t size(); // how many bytes are currently stored in the buffer
|
||||
|
||||
protected:
|
||||
virtual ~SkipCutBuffer();
|
||||
|
||||
private:
|
||||
void write(const char *src, size_t num);
|
||||
size_t read(char *dst, size_t num);
|
||||
template <typename T>
|
||||
void submitInternal(const sp<T>& buffer);
|
||||
int32_t mSkip;
|
||||
int32_t mFrontPadding;
|
||||
int32_t mBackPadding;
|
||||
int32_t mWriteHead;
|
||||
int32_t mReadHead;
|
||||
int32_t mCapacity;
|
||||
char* mCutBuffer;
|
||||
DISALLOW_EVIL_CONSTRUCTORS(SkipCutBuffer);
|
||||
};
|
||||
|
||||
} // namespace android
|
||||
|
||||
#endif // OMX_CODEC_H_
|
@ -1,104 +0,0 @@
|
||||
/*
|
||||
* Copyright 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
|
||||
#define LOG_TAG "StagefrightPluginLoader"
|
||||
#include <utils/Log.h>
|
||||
|
||||
#include <android-base/properties.h>
|
||||
#include <dlfcn.h>
|
||||
|
||||
#include "StagefrightPluginLoader.h"
|
||||
|
||||
namespace android {
|
||||
|
||||
/* static */ Mutex StagefrightPluginLoader::sMutex;
|
||||
/* static */ std::unique_ptr<StagefrightPluginLoader> StagefrightPluginLoader::sInstance;
|
||||
|
||||
namespace /* unnamed */ {
|
||||
|
||||
constexpr const char kCCodecPluginPath[] = "libsfplugin_ccodec.so";
|
||||
|
||||
} // unnamed namespace
|
||||
|
||||
StagefrightPluginLoader::StagefrightPluginLoader(const char *libPath) {
|
||||
if (android::base::GetIntProperty("debug.stagefright.ccodec", 1) == 0) {
|
||||
ALOGD("CCodec is disabled.");
|
||||
return;
|
||||
}
|
||||
mLibHandle = dlopen(libPath, RTLD_NOW | RTLD_NODELETE);
|
||||
if (mLibHandle == nullptr) {
|
||||
ALOGD("Failed to load library: %s (%s)", libPath, dlerror());
|
||||
return;
|
||||
}
|
||||
mCreateCodec = (CodecBase::CreateCodecFunc)dlsym(mLibHandle, "CreateCodec");
|
||||
if (mCreateCodec == nullptr) {
|
||||
ALOGD("Failed to find symbol: CreateCodec (%s)", dlerror());
|
||||
}
|
||||
mCreateBuilder = (MediaCodecListBuilderBase::CreateBuilderFunc)dlsym(
|
||||
mLibHandle, "CreateBuilder");
|
||||
if (mCreateBuilder == nullptr) {
|
||||
ALOGD("Failed to find symbol: CreateBuilder (%s)", dlerror());
|
||||
}
|
||||
mCreateInputSurface = (CodecBase::CreateInputSurfaceFunc)dlsym(
|
||||
mLibHandle, "CreateInputSurface");
|
||||
if (mCreateInputSurface == nullptr) {
|
||||
ALOGD("Failed to find symbol: CreateInputSurface (%s)", dlerror());
|
||||
}
|
||||
}
|
||||
|
||||
StagefrightPluginLoader::~StagefrightPluginLoader() {
|
||||
if (mLibHandle != nullptr) {
|
||||
ALOGV("Closing handle");
|
||||
dlclose(mLibHandle);
|
||||
}
|
||||
}
|
||||
|
||||
CodecBase *StagefrightPluginLoader::createCodec() {
|
||||
if (mLibHandle == nullptr || mCreateCodec == nullptr) {
|
||||
ALOGD("Handle or CreateCodec symbol is null");
|
||||
return nullptr;
|
||||
}
|
||||
return mCreateCodec();
|
||||
}
|
||||
|
||||
MediaCodecListBuilderBase *StagefrightPluginLoader::createBuilder() {
|
||||
if (mLibHandle == nullptr || mCreateBuilder == nullptr) {
|
||||
ALOGD("Handle or CreateBuilder symbol is null");
|
||||
return nullptr;
|
||||
}
|
||||
return mCreateBuilder();
|
||||
}
|
||||
|
||||
PersistentSurface *StagefrightPluginLoader::createInputSurface() {
|
||||
if (mLibHandle == nullptr || mCreateInputSurface == nullptr) {
|
||||
ALOGD("Handle or CreateInputSurface symbol is null");
|
||||
return nullptr;
|
||||
}
|
||||
return mCreateInputSurface();
|
||||
}
|
||||
|
||||
//static
|
||||
const std::unique_ptr<StagefrightPluginLoader> &StagefrightPluginLoader::GetCCodecInstance() {
|
||||
Mutex::Autolock _l(sMutex);
|
||||
if (!sInstance) {
|
||||
ALOGV("Loading library");
|
||||
sInstance.reset(new StagefrightPluginLoader(kCCodecPluginPath));
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
} // namespace android
|
@ -1,51 +0,0 @@
|
||||
/*
|
||||
* Copyright 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 STAGEFRIGHT_PLUGIN_LOADER_H_
|
||||
|
||||
#define STAGEFRIGHT_PLUGIN_LOADER_H_
|
||||
|
||||
#include <media/stagefright/CodecBase.h>
|
||||
#include <media/stagefright/MediaCodecListWriter.h>
|
||||
#include <media/stagefright/PersistentSurface.h>
|
||||
#include <utils/Mutex.h>
|
||||
|
||||
namespace android {
|
||||
|
||||
class StagefrightPluginLoader {
|
||||
public:
|
||||
static const std::unique_ptr<StagefrightPluginLoader> &GetCCodecInstance();
|
||||
~StagefrightPluginLoader();
|
||||
|
||||
CodecBase *createCodec();
|
||||
MediaCodecListBuilderBase *createBuilder();
|
||||
PersistentSurface *createInputSurface();
|
||||
|
||||
private:
|
||||
explicit StagefrightPluginLoader(const char *libPath);
|
||||
|
||||
static Mutex sMutex;
|
||||
static std::unique_ptr<StagefrightPluginLoader> sInstance;
|
||||
|
||||
void *mLibHandle{nullptr};
|
||||
CodecBase::CreateCodecFunc mCreateCodec{nullptr};
|
||||
MediaCodecListBuilderBase::CreateBuilderFunc mCreateBuilder{nullptr};
|
||||
CodecBase::CreateInputSurfaceFunc mCreateInputSurface{nullptr};
|
||||
};
|
||||
|
||||
} // namespace android
|
||||
|
||||
#endif // STAGEFRIGHT_PLUGIN_LOADER_H_
|
Loading…
Reference in new issue