mirror of
https://git.eden-emu.dev/eden-emu/eden
synced 2026-05-14 17:16:58 +02:00
Move dead submodules in-tree
Signed-off-by: swurl <swurl@swurl.xyz>
This commit is contained in:
parent
c0cceff365
commit
6c655321e6
4081 changed files with 1185566 additions and 45 deletions
178
externals/oboe/src/fifo/FifoBuffer.cpp
vendored
Normal file
178
externals/oboe/src/fifo/FifoBuffer.cpp
vendored
Normal file
|
|
@ -0,0 +1,178 @@
|
|||
/*
|
||||
* Copyright 2015 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.
|
||||
*/
|
||||
|
||||
#include <algorithm>
|
||||
#include <memory.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "oboe/FifoControllerBase.h"
|
||||
#include "fifo/FifoController.h"
|
||||
#include "fifo/FifoControllerIndirect.h"
|
||||
#include "oboe/FifoBuffer.h"
|
||||
|
||||
namespace oboe {
|
||||
|
||||
FifoBuffer::FifoBuffer(uint32_t bytesPerFrame, uint32_t capacityInFrames)
|
||||
: mBytesPerFrame(bytesPerFrame)
|
||||
, mStorage(nullptr)
|
||||
, mFramesReadCount(0)
|
||||
, mFramesUnderrunCount(0)
|
||||
{
|
||||
mFifo = std::make_unique<FifoController>(capacityInFrames);
|
||||
// allocate buffer
|
||||
int32_t bytesPerBuffer = bytesPerFrame * capacityInFrames;
|
||||
mStorage = new uint8_t[bytesPerBuffer];
|
||||
mStorageOwned = true;
|
||||
}
|
||||
|
||||
FifoBuffer::FifoBuffer( uint32_t bytesPerFrame,
|
||||
uint32_t capacityInFrames,
|
||||
std::atomic<uint64_t> *readCounterAddress,
|
||||
std::atomic<uint64_t> *writeCounterAddress,
|
||||
uint8_t *dataStorageAddress
|
||||
)
|
||||
: mBytesPerFrame(bytesPerFrame)
|
||||
, mStorage(dataStorageAddress)
|
||||
, mFramesReadCount(0)
|
||||
, mFramesUnderrunCount(0)
|
||||
{
|
||||
mFifo = std::make_unique<FifoControllerIndirect>(capacityInFrames,
|
||||
readCounterAddress,
|
||||
writeCounterAddress);
|
||||
mStorage = dataStorageAddress;
|
||||
mStorageOwned = false;
|
||||
}
|
||||
|
||||
FifoBuffer::~FifoBuffer() {
|
||||
if (mStorageOwned) {
|
||||
delete[] mStorage;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t FifoBuffer::convertFramesToBytes(int32_t frames) {
|
||||
return frames * mBytesPerFrame;
|
||||
}
|
||||
|
||||
int32_t FifoBuffer::read(void *buffer, int32_t numFrames) {
|
||||
if (numFrames <= 0) {
|
||||
return 0;
|
||||
}
|
||||
// safe because numFrames is guaranteed positive
|
||||
uint32_t framesToRead = static_cast<uint32_t>(numFrames);
|
||||
uint32_t framesAvailable = mFifo->getFullFramesAvailable();
|
||||
framesToRead = std::min(framesToRead, framesAvailable);
|
||||
|
||||
uint32_t readIndex = mFifo->getReadIndex(); // ranges 0 to capacity
|
||||
uint8_t *destination = reinterpret_cast<uint8_t *>(buffer);
|
||||
uint8_t *source = &mStorage[convertFramesToBytes(readIndex)];
|
||||
if ((readIndex + framesToRead) > mFifo->getFrameCapacity()) {
|
||||
// read in two parts, first part here is at the end of the mStorage buffer
|
||||
int32_t frames1 = static_cast<int32_t>(mFifo->getFrameCapacity() - readIndex);
|
||||
int32_t numBytes = convertFramesToBytes(frames1);
|
||||
if (numBytes < 0) {
|
||||
return static_cast<int32_t>(Result::ErrorOutOfRange);
|
||||
}
|
||||
memcpy(destination, source, static_cast<size_t>(numBytes));
|
||||
destination += numBytes;
|
||||
// read second part, which is at the beginning of mStorage
|
||||
source = &mStorage[0];
|
||||
int32_t frames2 = static_cast<uint32_t>(framesToRead - frames1);
|
||||
numBytes = convertFramesToBytes(frames2);
|
||||
if (numBytes < 0) {
|
||||
return static_cast<int32_t>(Result::ErrorOutOfRange);
|
||||
}
|
||||
memcpy(destination, source, static_cast<size_t>(numBytes));
|
||||
} else {
|
||||
// just read in one shot
|
||||
int32_t numBytes = convertFramesToBytes(framesToRead);
|
||||
if (numBytes < 0) {
|
||||
return static_cast<int32_t>(Result::ErrorOutOfRange);
|
||||
}
|
||||
memcpy(destination, source, static_cast<size_t>(numBytes));
|
||||
}
|
||||
mFifo->advanceReadIndex(framesToRead);
|
||||
|
||||
return framesToRead;
|
||||
}
|
||||
|
||||
int32_t FifoBuffer::write(const void *buffer, int32_t numFrames) {
|
||||
if (numFrames <= 0) {
|
||||
return 0;
|
||||
}
|
||||
// Guaranteed positive.
|
||||
uint32_t framesToWrite = static_cast<uint32_t>(numFrames);
|
||||
uint32_t framesAvailable = mFifo->getEmptyFramesAvailable();
|
||||
framesToWrite = std::min(framesToWrite, framesAvailable);
|
||||
|
||||
uint32_t writeIndex = mFifo->getWriteIndex();
|
||||
int byteIndex = convertFramesToBytes(writeIndex);
|
||||
const uint8_t *source = reinterpret_cast<const uint8_t *>(buffer);
|
||||
uint8_t *destination = &mStorage[byteIndex];
|
||||
if ((writeIndex + framesToWrite) > mFifo->getFrameCapacity()) {
|
||||
// write in two parts, first part here
|
||||
int32_t frames1 = static_cast<uint32_t>(mFifo->getFrameCapacity() - writeIndex);
|
||||
int32_t numBytes = convertFramesToBytes(frames1);
|
||||
if (numBytes < 0) {
|
||||
return static_cast<int32_t>(Result::ErrorOutOfRange);
|
||||
}
|
||||
memcpy(destination, source, static_cast<size_t>(numBytes));
|
||||
// read second part
|
||||
source += convertFramesToBytes(frames1);
|
||||
destination = &mStorage[0];
|
||||
int frames2 = static_cast<uint32_t>(framesToWrite - frames1);
|
||||
numBytes = convertFramesToBytes(frames2);
|
||||
if (numBytes < 0) {
|
||||
return static_cast<int32_t>(Result::ErrorOutOfRange);
|
||||
}
|
||||
memcpy(destination, source, static_cast<size_t>(numBytes));
|
||||
} else {
|
||||
// just write in one shot
|
||||
int32_t numBytes = convertFramesToBytes(framesToWrite);
|
||||
if (numBytes < 0) {
|
||||
return static_cast<int32_t>(Result::ErrorOutOfRange);
|
||||
}
|
||||
memcpy(destination, source, static_cast<size_t>(numBytes));
|
||||
}
|
||||
mFifo->advanceWriteIndex(framesToWrite);
|
||||
|
||||
return framesToWrite;
|
||||
}
|
||||
|
||||
int32_t FifoBuffer::readNow(void *buffer, int32_t numFrames) {
|
||||
int32_t framesRead = read(buffer, numFrames);
|
||||
if (framesRead < 0) {
|
||||
return framesRead;
|
||||
}
|
||||
int32_t framesLeft = numFrames - framesRead;
|
||||
mFramesReadCount += framesRead;
|
||||
mFramesUnderrunCount += framesLeft;
|
||||
// Zero out any samples we could not set.
|
||||
if (framesLeft > 0) {
|
||||
uint8_t *destination = reinterpret_cast<uint8_t *>(buffer);
|
||||
destination += convertFramesToBytes(framesRead); // point to first byte not set
|
||||
int32_t bytesToZero = convertFramesToBytes(framesLeft);
|
||||
memset(destination, 0, static_cast<size_t>(bytesToZero));
|
||||
}
|
||||
|
||||
return framesRead;
|
||||
}
|
||||
|
||||
|
||||
uint32_t FifoBuffer::getBufferCapacityInFrames() const {
|
||||
return mFifo->getFrameCapacity();
|
||||
}
|
||||
|
||||
} // namespace oboe
|
||||
30
externals/oboe/src/fifo/FifoController.cpp
vendored
Normal file
30
externals/oboe/src/fifo/FifoController.cpp
vendored
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* Copyright 2015 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.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "FifoController.h"
|
||||
|
||||
namespace oboe {
|
||||
|
||||
FifoController::FifoController(uint32_t numFrames)
|
||||
: FifoControllerBase(numFrames)
|
||||
{
|
||||
setReadCounter(0);
|
||||
setWriteCounter(0);
|
||||
}
|
||||
|
||||
} // namespace oboe
|
||||
62
externals/oboe/src/fifo/FifoController.h
vendored
Normal file
62
externals/oboe/src/fifo/FifoController.h
vendored
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* Copyright 2015 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 NATIVEOBOE_FIFOCONTROLLER_H
|
||||
#define NATIVEOBOE_FIFOCONTROLLER_H
|
||||
|
||||
#include <atomic>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "oboe/FifoControllerBase.h"
|
||||
|
||||
namespace oboe {
|
||||
|
||||
/**
|
||||
* A FifoControllerBase with counters contained in the class.
|
||||
*/
|
||||
class FifoController : public FifoControllerBase
|
||||
{
|
||||
public:
|
||||
FifoController(uint32_t bufferSize);
|
||||
virtual ~FifoController() = default;
|
||||
|
||||
virtual uint64_t getReadCounter() const override {
|
||||
return mReadCounter.load(std::memory_order_acquire);
|
||||
}
|
||||
virtual void setReadCounter(uint64_t n) override {
|
||||
mReadCounter.store(n, std::memory_order_release);
|
||||
}
|
||||
virtual void incrementReadCounter(uint64_t n) override {
|
||||
mReadCounter.fetch_add(n, std::memory_order_acq_rel);
|
||||
}
|
||||
virtual uint64_t getWriteCounter() const override {
|
||||
return mWriteCounter.load(std::memory_order_acquire);
|
||||
}
|
||||
virtual void setWriteCounter(uint64_t n) override {
|
||||
mWriteCounter.store(n, std::memory_order_release);
|
||||
}
|
||||
virtual void incrementWriteCounter(uint64_t n) override {
|
||||
mWriteCounter.fetch_add(n, std::memory_order_acq_rel);
|
||||
}
|
||||
|
||||
private:
|
||||
std::atomic<uint64_t> mReadCounter{};
|
||||
std::atomic<uint64_t> mWriteCounter{};
|
||||
};
|
||||
|
||||
} // namespace oboe
|
||||
|
||||
#endif //NATIVEOBOE_FIFOCONTROLLER_H
|
||||
68
externals/oboe/src/fifo/FifoControllerBase.cpp
vendored
Normal file
68
externals/oboe/src/fifo/FifoControllerBase.cpp
vendored
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* Copyright 2015 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.
|
||||
*/
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "oboe/FifoControllerBase.h"
|
||||
|
||||
namespace oboe {
|
||||
|
||||
FifoControllerBase::FifoControllerBase(uint32_t capacityInFrames)
|
||||
: mTotalFrames(capacityInFrames)
|
||||
{
|
||||
// Avoid ridiculously large buffers and the arithmetic wraparound issues that can follow.
|
||||
assert(capacityInFrames <= (UINT32_MAX / 4));
|
||||
}
|
||||
|
||||
uint32_t FifoControllerBase::getFullFramesAvailable() const {
|
||||
uint64_t writeCounter = getWriteCounter();
|
||||
uint64_t readCounter = getReadCounter();
|
||||
if (readCounter > writeCounter) {
|
||||
return 0;
|
||||
}
|
||||
uint64_t delta = writeCounter - readCounter;
|
||||
if (delta >= mTotalFrames) {
|
||||
return mTotalFrames;
|
||||
}
|
||||
// delta is now guaranteed to fit within the range of a uint32_t
|
||||
return static_cast<uint32_t>(delta);
|
||||
}
|
||||
|
||||
uint32_t FifoControllerBase::getReadIndex() const {
|
||||
// % works with non-power of two sizes
|
||||
return static_cast<uint32_t>(getReadCounter() % mTotalFrames);
|
||||
}
|
||||
|
||||
void FifoControllerBase::advanceReadIndex(uint32_t numFrames) {
|
||||
incrementReadCounter(numFrames);
|
||||
}
|
||||
|
||||
uint32_t FifoControllerBase::getEmptyFramesAvailable() const {
|
||||
return static_cast<uint32_t>(mTotalFrames - getFullFramesAvailable());
|
||||
}
|
||||
|
||||
uint32_t FifoControllerBase::getWriteIndex() const {
|
||||
// % works with non-power of two sizes
|
||||
return static_cast<uint32_t>(getWriteCounter() % mTotalFrames);
|
||||
}
|
||||
|
||||
void FifoControllerBase::advanceWriteIndex(uint32_t numFrames) {
|
||||
incrementWriteCounter(numFrames);
|
||||
}
|
||||
|
||||
} // namespace oboe
|
||||
32
externals/oboe/src/fifo/FifoControllerIndirect.cpp
vendored
Normal file
32
externals/oboe/src/fifo/FifoControllerIndirect.cpp
vendored
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Copyright 2016 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.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "FifoControllerIndirect.h"
|
||||
|
||||
namespace oboe {
|
||||
|
||||
FifoControllerIndirect::FifoControllerIndirect(uint32_t numFrames,
|
||||
std::atomic<uint64_t> *readCounterAddress,
|
||||
std::atomic<uint64_t> *writeCounterAddress)
|
||||
: FifoControllerBase(numFrames)
|
||||
, mReadCounterAddress(readCounterAddress)
|
||||
, mWriteCounterAddress(writeCounterAddress)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
66
externals/oboe/src/fifo/FifoControllerIndirect.h
vendored
Normal file
66
externals/oboe/src/fifo/FifoControllerIndirect.h
vendored
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* Copyright 2016 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 NATIVEOBOE_FIFOCONTROLLERINDIRECT_H
|
||||
#define NATIVEOBOE_FIFOCONTROLLERINDIRECT_H
|
||||
|
||||
#include <atomic>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "oboe/FifoControllerBase.h"
|
||||
|
||||
namespace oboe {
|
||||
|
||||
/**
|
||||
* A FifoControllerBase with counters external to the class.
|
||||
*/
|
||||
class FifoControllerIndirect : public FifoControllerBase {
|
||||
|
||||
public:
|
||||
FifoControllerIndirect(uint32_t bufferSize,
|
||||
std::atomic<uint64_t> *readCounterAddress,
|
||||
std::atomic<uint64_t> *writeCounterAddress);
|
||||
virtual ~FifoControllerIndirect() = default;
|
||||
|
||||
virtual uint64_t getReadCounter() const override {
|
||||
return mReadCounterAddress->load(std::memory_order_acquire);
|
||||
}
|
||||
virtual void setReadCounter(uint64_t n) override {
|
||||
mReadCounterAddress->store(n, std::memory_order_release);
|
||||
}
|
||||
virtual void incrementReadCounter(uint64_t n) override {
|
||||
mReadCounterAddress->fetch_add(n, std::memory_order_acq_rel);
|
||||
}
|
||||
virtual uint64_t getWriteCounter() const override {
|
||||
return mWriteCounterAddress->load(std::memory_order_acquire);
|
||||
}
|
||||
virtual void setWriteCounter(uint64_t n) override {
|
||||
mWriteCounterAddress->store(n, std::memory_order_release);
|
||||
}
|
||||
virtual void incrementWriteCounter(uint64_t n) override {
|
||||
mWriteCounterAddress->fetch_add(n, std::memory_order_acq_rel);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
std::atomic<uint64_t> *mReadCounterAddress;
|
||||
std::atomic<uint64_t> *mWriteCounterAddress;
|
||||
|
||||
};
|
||||
|
||||
} // namespace oboe
|
||||
|
||||
#endif //NATIVEOBOE_FIFOCONTROLLERINDIRECT_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue