shadPS4/src/core/libraries/ajm/ajm_context.h
georgemoralis f068f13e4a
Ajm (#1456)
* ajm: Initial ajm implementation

* AJM code improvements (#1453)

* Fix sideband buffer order (#1454)

* ajm: Attempt to add gapless support

* ajm_at9: Return superframes decoded in a single job

* WIP (#1460)

* Fix gapless decode and combine split buffers

* Fixed linux build

* fix number of samples reported with gapless decoding

* fixed number of remaining samples calculation

should fix the small crackling sounds that play every now and again

* refactor half ajm

* refactored most of ajm

* refactored ajm

* clang-format, in-repo libatrac9, removed debug stuff

---------

Co-authored-by: auser1337 <aaravsandhu10@outlook.com>
Co-authored-by: Vladislav Mikhalin <mikhalinvlad@gmail.com>
Co-authored-by: IndecisiveTurtle <geoster3d@gmail.com>
2024-11-05 09:16:57 +02:00

58 lines
1.7 KiB
C++

// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include "common/bounded_threadsafe_queue.h"
#include "common/slot_array.h"
#include "common/types.h"
#include "core/libraries/ajm/ajm.h"
#include "core/libraries/ajm/ajm_batch.h"
#include "core/libraries/ajm/ajm_instance.h"
#include <array>
#include <memory>
#include <shared_mutex>
#include <span>
#include <thread>
#include <utility>
namespace Libraries::Ajm {
class AjmContext {
public:
AjmContext();
s32 InstanceCreate(AjmCodecType codec_type, AjmInstanceFlags flags, u32* out_instance_id);
s32 InstanceDestroy(u32 instance_id);
s32 BatchCancel(const u32 batch_id);
s32 ModuleRegister(AjmCodecType type);
s32 BatchWait(const u32 batch_id, const u32 timeout, AjmBatchError* const p_batch_error);
s32 BatchStartBuffer(u8* p_batch, u32 batch_size, const int priority,
AjmBatchError* p_batch_error, u32* p_batch_id);
void WorkerThread(std::stop_token stop);
void ProcessBatch(u32 id, std::span<AjmJob> jobs);
private:
static constexpr u32 MaxInstances = 0x2fff;
static constexpr u32 MaxBatches = 0x0400;
static constexpr u32 NumAjmCodecs = std::to_underlying(AjmCodecType::Max);
[[nodiscard]] bool IsRegistered(AjmCodecType type) const;
std::array<bool, NumAjmCodecs> registered_codecs{};
std::shared_mutex instances_mutex;
Common::SlotArray<u32, std::shared_ptr<AjmInstance>, MaxInstances, 1> instances;
std::shared_mutex batches_mutex;
Common::SlotArray<u32, std::shared_ptr<AjmBatch>, MaxBatches, 1> batches;
std::jthread worker_thread{};
Common::MPSCQueue<std::shared_ptr<AjmBatch>> batch_queue;
};
} // namespace Libraries::Ajm