summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/CMakeLists.txt2
-rw-r--r--src/core/hle/kernel/kernel.cpp42
-rw-r--r--src/core/hle/kernel/kernel.h11
-rw-r--r--src/core/hle/kernel/object.cpp1
-rw-r--r--src/core/hle/kernel/object.h1
-rw-r--r--src/core/hle/kernel/timer.cpp84
-rw-r--r--src/core/hle/kernel/timer.h88
-rw-r--r--src/core/hle/service/audio/hwopus.cpp117
8 files changed, 75 insertions, 271 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt
index 965c28787..f61bcd40d 100644
--- a/src/core/CMakeLists.txt
+++ b/src/core/CMakeLists.txt
@@ -140,8 +140,6 @@ add_library(core STATIC
hle/kernel/svc_wrap.h
hle/kernel/thread.cpp
hle/kernel/thread.h
- hle/kernel/timer.cpp
- hle/kernel/timer.h
hle/kernel/vm_manager.cpp
hle/kernel/vm_manager.h
hle/kernel/wait_object.cpp
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp
index 67674cd47..7a524ce5a 100644
--- a/src/core/hle/kernel/kernel.cpp
+++ b/src/core/hle/kernel/kernel.cpp
@@ -18,7 +18,6 @@
#include "core/hle/kernel/process.h"
#include "core/hle/kernel/resource_limit.h"
#include "core/hle/kernel/thread.h"
-#include "core/hle/kernel/timer.h"
#include "core/hle/lock.h"
#include "core/hle/result.h"
@@ -86,27 +85,12 @@ static void ThreadWakeupCallback(u64 thread_handle, [[maybe_unused]] int cycles_
}
}
-/// The timer callback event, called when a timer is fired
-static void TimerCallback(u64 timer_handle, int cycles_late) {
- const auto proper_handle = static_cast<Handle>(timer_handle);
- const auto& system = Core::System::GetInstance();
- SharedPtr<Timer> timer = system.Kernel().RetrieveTimerFromCallbackHandleTable(proper_handle);
-
- if (timer == nullptr) {
- LOG_CRITICAL(Kernel, "Callback fired for invalid timer {:016X}", timer_handle);
- return;
- }
-
- timer->Signal(cycles_late);
-}
-
struct KernelCore::Impl {
void Initialize(KernelCore& kernel) {
Shutdown();
InitializeSystemResourceLimit(kernel);
InitializeThreads();
- InitializeTimers();
}
void Shutdown() {
@@ -122,9 +106,6 @@ struct KernelCore::Impl {
thread_wakeup_callback_handle_table.Clear();
thread_wakeup_event_type = nullptr;
- timer_callback_handle_table.Clear();
- timer_callback_event_type = nullptr;
-
named_ports.clear();
}
@@ -146,11 +127,6 @@ struct KernelCore::Impl {
CoreTiming::RegisterEvent("ThreadWakeupCallback", ThreadWakeupCallback);
}
- void InitializeTimers() {
- timer_callback_handle_table.Clear();
- timer_callback_event_type = CoreTiming::RegisterEvent("TimerCallback", TimerCallback);
- }
-
std::atomic<u32> next_object_id{0};
std::atomic<u64> next_process_id{Process::ProcessIDMin};
std::atomic<u64> next_thread_id{1};
@@ -161,12 +137,6 @@ struct KernelCore::Impl {
SharedPtr<ResourceLimit> system_resource_limit;
- /// The event type of the generic timer callback event
- CoreTiming::EventType* timer_callback_event_type = nullptr;
- // TODO(yuriks): This can be removed if Timer objects are explicitly pooled in the future,
- // allowing us to simply use a pool index or similar.
- Kernel::HandleTable timer_callback_handle_table;
-
CoreTiming::EventType* thread_wakeup_event_type = nullptr;
// TODO(yuriks): This can be removed if Thread objects are explicitly pooled in the future,
// allowing us to simply use a pool index or similar.
@@ -198,10 +168,6 @@ SharedPtr<Thread> KernelCore::RetrieveThreadFromWakeupCallbackHandleTable(Handle
return impl->thread_wakeup_callback_handle_table.Get<Thread>(handle);
}
-SharedPtr<Timer> KernelCore::RetrieveTimerFromCallbackHandleTable(Handle handle) const {
- return impl->timer_callback_handle_table.Get<Timer>(handle);
-}
-
void KernelCore::AppendNewProcess(SharedPtr<Process> process) {
impl->process_list.push_back(std::move(process));
}
@@ -247,18 +213,10 @@ u64 KernelCore::CreateNewProcessID() {
return impl->next_process_id++;
}
-ResultVal<Handle> KernelCore::CreateTimerCallbackHandle(const SharedPtr<Timer>& timer) {
- return impl->timer_callback_handle_table.Create(timer);
-}
-
CoreTiming::EventType* KernelCore::ThreadWakeupCallbackEventType() const {
return impl->thread_wakeup_event_type;
}
-CoreTiming::EventType* KernelCore::TimerCallbackEventType() const {
- return impl->timer_callback_event_type;
-}
-
Kernel::HandleTable& KernelCore::ThreadWakeupCallbackHandleTable() {
return impl->thread_wakeup_callback_handle_table;
}
diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h
index 58c9d108b..c643a6401 100644
--- a/src/core/hle/kernel/kernel.h
+++ b/src/core/hle/kernel/kernel.h
@@ -22,7 +22,6 @@ class HandleTable;
class Process;
class ResourceLimit;
class Thread;
-class Timer;
/// Represents a single instance of the kernel.
class KernelCore {
@@ -51,9 +50,6 @@ public:
/// Retrieves a shared pointer to a Thread instance within the thread wakeup handle table.
SharedPtr<Thread> RetrieveThreadFromWakeupCallbackHandleTable(Handle handle) const;
- /// Retrieves a shared pointer to a Timer instance within the timer callback handle table.
- SharedPtr<Timer> RetrieveTimerFromCallbackHandleTable(Handle handle) const;
-
/// Adds the given shared pointer to an internal list of active processes.
void AppendNewProcess(SharedPtr<Process> process);
@@ -82,7 +78,6 @@ private:
friend class Object;
friend class Process;
friend class Thread;
- friend class Timer;
/// Creates a new object ID, incrementing the internal object ID counter.
u32 CreateNewObjectID();
@@ -93,15 +88,9 @@ private:
/// Creates a new thread ID, incrementing the internal thread ID counter.
u64 CreateNewThreadID();
- /// Creates a timer callback handle for the given timer.
- ResultVal<Handle> CreateTimerCallbackHandle(const SharedPtr<Timer>& timer);
-
/// Retrieves the event type used for thread wakeup callbacks.
CoreTiming::EventType* ThreadWakeupCallbackEventType() const;
- /// Retrieves the event type used for timer callbacks.
- CoreTiming::EventType* TimerCallbackEventType() const;
-
/// Provides a reference to the thread wakeup callback handle table.
Kernel::HandleTable& ThreadWakeupCallbackHandleTable();
diff --git a/src/core/hle/kernel/object.cpp b/src/core/hle/kernel/object.cpp
index 806078638..8870463d0 100644
--- a/src/core/hle/kernel/object.cpp
+++ b/src/core/hle/kernel/object.cpp
@@ -16,7 +16,6 @@ bool Object::IsWaitable() const {
case HandleType::ReadableEvent:
case HandleType::Thread:
case HandleType::Process:
- case HandleType::Timer:
case HandleType::ServerPort:
case HandleType::ServerSession:
return true;
diff --git a/src/core/hle/kernel/object.h b/src/core/hle/kernel/object.h
index 1541b6e3c..4c2505908 100644
--- a/src/core/hle/kernel/object.h
+++ b/src/core/hle/kernel/object.h
@@ -25,7 +25,6 @@ enum class HandleType : u32 {
Thread,
Process,
AddressArbiter,
- Timer,
ResourceLimit,
ClientPort,
ServerPort,
diff --git a/src/core/hle/kernel/timer.cpp b/src/core/hle/kernel/timer.cpp
deleted file mode 100644
index 3afe60469..000000000
--- a/src/core/hle/kernel/timer.cpp
+++ /dev/null
@@ -1,84 +0,0 @@
-// Copyright 2015 Citra Emulator Project
-// Licensed under GPLv2 or any later version
-// Refer to the license.txt file included.
-
-#include "common/assert.h"
-#include "common/logging/log.h"
-#include "core/core.h"
-#include "core/core_timing.h"
-#include "core/core_timing_util.h"
-#include "core/hle/kernel/handle_table.h"
-#include "core/hle/kernel/kernel.h"
-#include "core/hle/kernel/object.h"
-#include "core/hle/kernel/thread.h"
-#include "core/hle/kernel/timer.h"
-
-namespace Kernel {
-
-Timer::Timer(KernelCore& kernel) : WaitObject{kernel} {}
-Timer::~Timer() = default;
-
-SharedPtr<Timer> Timer::Create(KernelCore& kernel, ResetType reset_type, std::string name) {
- SharedPtr<Timer> timer(new Timer(kernel));
-
- timer->reset_type = reset_type;
- timer->signaled = false;
- timer->name = std::move(name);
- timer->initial_delay = 0;
- timer->interval_delay = 0;
- timer->callback_handle = kernel.CreateTimerCallbackHandle(timer).Unwrap();
-
- return timer;
-}
-
-bool Timer::ShouldWait(Thread* thread) const {
- return !signaled;
-}
-
-void Timer::Acquire(Thread* thread) {
- ASSERT_MSG(!ShouldWait(thread), "object unavailable!");
-
- if (reset_type == ResetType::OneShot)
- signaled = false;
-}
-
-void Timer::Set(s64 initial, s64 interval) {
- // Ensure we get rid of any previous scheduled event
- Cancel();
-
- initial_delay = initial;
- interval_delay = interval;
-
- if (initial == 0) {
- // Immediately invoke the callback
- Signal(0);
- } else {
- CoreTiming::ScheduleEvent(CoreTiming::nsToCycles(initial), kernel.TimerCallbackEventType(),
- callback_handle);
- }
-}
-
-void Timer::Cancel() {
- CoreTiming::UnscheduleEvent(kernel.TimerCallbackEventType(), callback_handle);
-}
-
-void Timer::Clear() {
- signaled = false;
-}
-
-void Timer::Signal(int cycles_late) {
- LOG_TRACE(Kernel, "Timer {} fired", GetObjectId());
-
- signaled = true;
-
- // Resume all waiting threads
- WakeupAllWaitingThreads();
-
- if (interval_delay != 0) {
- // Reschedule the timer with the interval delay
- CoreTiming::ScheduleEvent(CoreTiming::nsToCycles(interval_delay) - cycles_late,
- kernel.TimerCallbackEventType(), callback_handle);
- }
-}
-
-} // namespace Kernel
diff --git a/src/core/hle/kernel/timer.h b/src/core/hle/kernel/timer.h
deleted file mode 100644
index ce3e74426..000000000
--- a/src/core/hle/kernel/timer.h
+++ /dev/null
@@ -1,88 +0,0 @@
-// Copyright 2015 Citra Emulator Project
-// Licensed under GPLv2 or any later version
-// Refer to the license.txt file included.
-
-#pragma once
-
-#include "common/common_types.h"
-#include "core/hle/kernel/object.h"
-#include "core/hle/kernel/wait_object.h"
-
-namespace Kernel {
-
-class KernelCore;
-
-class Timer final : public WaitObject {
-public:
- /**
- * Creates a timer
- * @param kernel The kernel instance to create the timer callback handle for.
- * @param reset_type ResetType describing how to create the timer
- * @param name Optional name of timer
- * @return The created Timer
- */
- static SharedPtr<Timer> Create(KernelCore& kernel, ResetType reset_type,
- std::string name = "Unknown");
-
- std::string GetTypeName() const override {
- return "Timer";
- }
- std::string GetName() const override {
- return name;
- }
-
- static const HandleType HANDLE_TYPE = HandleType::Timer;
- HandleType GetHandleType() const override {
- return HANDLE_TYPE;
- }
-
- ResetType GetResetType() const {
- return reset_type;
- }
-
- u64 GetInitialDelay() const {
- return initial_delay;
- }
-
- u64 GetIntervalDelay() const {
- return interval_delay;
- }
-
- bool ShouldWait(Thread* thread) const override;
- void Acquire(Thread* thread) override;
-
- /**
- * Starts the timer, with the specified initial delay and interval.
- * @param initial Delay until the timer is first fired
- * @param interval Delay until the timer is fired after the first time
- */
- void Set(s64 initial, s64 interval);
-
- void Cancel();
- void Clear();
-
- /**
- * Signals the timer, waking up any waiting threads and rescheduling it
- * for the next interval.
- * This method should not be called from outside the timer callback handler,
- * lest multiple callback events get scheduled.
- */
- void Signal(int cycles_late);
-
-private:
- explicit Timer(KernelCore& kernel);
- ~Timer() override;
-
- ResetType reset_type; ///< The ResetType of this timer
-
- u64 initial_delay; ///< The delay until the timer fires for the first time
- u64 interval_delay; ///< The delay until the timer fires after the first time
-
- bool signaled; ///< Whether the timer has been signaled or not
- std::string name; ///< Name of timer (optional)
-
- /// Handle used as userdata to reference this object when inserting into the CoreTiming queue.
- Handle callback_handle;
-};
-
-} // namespace Kernel
diff --git a/src/core/hle/service/audio/hwopus.cpp b/src/core/hle/service/audio/hwopus.cpp
index a850cadc8..11eba4a12 100644
--- a/src/core/hle/service/audio/hwopus.cpp
+++ b/src/core/hle/service/audio/hwopus.cpp
@@ -5,7 +5,6 @@
#include <chrono>
#include <cstring>
#include <memory>
-#include <optional>
#include <vector>
#include <opus.h>
@@ -30,48 +29,66 @@ public:
u32 channel_count)
: ServiceFramework("IHardwareOpusDecoderManager"), decoder(std::move(decoder)),
sample_rate(sample_rate), channel_count(channel_count) {
+ // clang-format off
static const FunctionInfo functions[] = {
- {0, &IHardwareOpusDecoderManager::DecodeInterleaved, "DecodeInterleaved"},
+ {0, &IHardwareOpusDecoderManager::DecodeInterleavedOld, "DecodeInterleavedOld"},
{1, nullptr, "SetContext"},
- {2, nullptr, "DecodeInterleavedForMultiStream"},
+ {2, nullptr, "DecodeInterleavedForMultiStreamOld"},
{3, nullptr, "SetContextForMultiStream"},
- {4, &IHardwareOpusDecoderManager::DecodeInterleavedWithPerformance,
- "DecodeInterleavedWithPerformance"},
- {5, nullptr, "Unknown5"},
- {6, nullptr, "Unknown6"},
- {7, nullptr, "Unknown7"},
+ {4, &IHardwareOpusDecoderManager::DecodeInterleavedWithPerfOld, "DecodeInterleavedWithPerfOld"},
+ {5, nullptr, "DecodeInterleavedForMultiStreamWithPerfOld"},
+ {6, &IHardwareOpusDecoderManager::DecodeInterleaved, "DecodeInterleaved"},
+ {7, nullptr, "DecodeInterleavedForMultiStream"},
};
+ // clang-format on
+
RegisterHandlers(functions);
}
private:
- void DecodeInterleaved(Kernel::HLERequestContext& ctx) {
+ /// Describes extra behavior that may be asked of the decoding context.
+ enum class ExtraBehavior {
+ /// No extra behavior.
+ None,
+
+ /// Resets the decoder context back to a freshly initialized state.
+ ResetContext,
+ };
+
+ void DecodeInterleavedOld(Kernel::HLERequestContext& ctx) {
LOG_DEBUG(Audio, "called");
- u32 consumed = 0;
- u32 sample_count = 0;
- std::vector<opus_int16> samples(ctx.GetWriteBufferSize() / sizeof(opus_int16));
- if (!Decoder_DecodeInterleaved(consumed, sample_count, ctx.ReadBuffer(), samples)) {
- LOG_ERROR(Audio, "Failed to decode opus data");
- IPC::ResponseBuilder rb{ctx, 2};
- // TODO(ogniK): Use correct error code
- rb.Push(ResultCode(-1));
- return;
- }
- IPC::ResponseBuilder rb{ctx, 4};
- rb.Push(RESULT_SUCCESS);
- rb.Push<u32>(consumed);
- rb.Push<u32>(sample_count);
- ctx.WriteBuffer(samples.data(), samples.size() * sizeof(s16));
+ DecodeInterleavedHelper(ctx, nullptr, ExtraBehavior::None);
}
- void DecodeInterleavedWithPerformance(Kernel::HLERequestContext& ctx) {
+ void DecodeInterleavedWithPerfOld(Kernel::HLERequestContext& ctx) {
+ LOG_DEBUG(Audio, "called");
+
+ u64 performance = 0;
+ DecodeInterleavedHelper(ctx, &performance, ExtraBehavior::None);
+ }
+
+ void DecodeInterleaved(Kernel::HLERequestContext& ctx) {
LOG_DEBUG(Audio, "called");
+ IPC::RequestParser rp{ctx};
+ const auto extra_behavior =
+ rp.Pop<bool>() ? ExtraBehavior::ResetContext : ExtraBehavior::None;
+
+ u64 performance = 0;
+ DecodeInterleavedHelper(ctx, &performance, extra_behavior);
+ }
+
+ void DecodeInterleavedHelper(Kernel::HLERequestContext& ctx, u64* performance,
+ ExtraBehavior extra_behavior) {
u32 consumed = 0;
u32 sample_count = 0;
- u64 performance = 0;
std::vector<opus_int16> samples(ctx.GetWriteBufferSize() / sizeof(opus_int16));
+
+ if (extra_behavior == ExtraBehavior::ResetContext) {
+ ResetDecoderContext();
+ }
+
if (!Decoder_DecodeInterleaved(consumed, sample_count, ctx.ReadBuffer(), samples,
performance)) {
LOG_ERROR(Audio, "Failed to decode opus data");
@@ -80,25 +97,28 @@ private:
rb.Push(ResultCode(-1));
return;
}
- IPC::ResponseBuilder rb{ctx, 6};
+
+ const u32 param_size = performance != nullptr ? 6 : 4;
+ IPC::ResponseBuilder rb{ctx, param_size};
rb.Push(RESULT_SUCCESS);
rb.Push<u32>(consumed);
rb.Push<u32>(sample_count);
- rb.Push<u64>(performance);
+ if (performance) {
+ rb.Push<u64>(*performance);
+ }
ctx.WriteBuffer(samples.data(), samples.size() * sizeof(s16));
}
- bool Decoder_DecodeInterleaved(
- u32& consumed, u32& sample_count, const std::vector<u8>& input,
- std::vector<opus_int16>& output,
- std::optional<std::reference_wrapper<u64>> performance_time = std::nullopt) {
+ bool Decoder_DecodeInterleaved(u32& consumed, u32& sample_count, const std::vector<u8>& input,
+ std::vector<opus_int16>& output, u64* out_performance_time) {
const auto start_time = std::chrono::high_resolution_clock::now();
- std::size_t raw_output_sz = output.size() * sizeof(opus_int16);
+ const std::size_t raw_output_sz = output.size() * sizeof(opus_int16);
if (sizeof(OpusHeader) > input.size()) {
LOG_ERROR(Audio, "Input is smaller than the header size, header_sz={}, input_sz={}",
sizeof(OpusHeader), input.size());
return false;
}
+
OpusHeader hdr{};
std::memcpy(&hdr, input.data(), sizeof(OpusHeader));
if (sizeof(OpusHeader) + static_cast<u32>(hdr.sz) > input.size()) {
@@ -106,8 +126,9 @@ private:
sizeof(OpusHeader) + static_cast<u32>(hdr.sz), input.size());
return false;
}
- auto frame = input.data() + sizeof(OpusHeader);
- auto decoded_sample_count = opus_packet_get_nb_samples(
+
+ const auto frame = input.data() + sizeof(OpusHeader);
+ const auto decoded_sample_count = opus_packet_get_nb_samples(
frame, static_cast<opus_int32>(input.size() - sizeof(OpusHeader)),
static_cast<opus_int32>(sample_rate));
if (decoded_sample_count * channel_count * sizeof(u16) > raw_output_sz) {
@@ -117,8 +138,9 @@ private:
decoded_sample_count * channel_count * sizeof(u16), raw_output_sz);
return false;
}
+
const int frame_size = (static_cast<int>(raw_output_sz / sizeof(s16) / channel_count));
- auto out_sample_count =
+ const auto out_sample_count =
opus_decode(decoder.get(), frame, hdr.sz, output.data(), frame_size, 0);
if (out_sample_count < 0) {
LOG_ERROR(Audio,
@@ -127,16 +149,24 @@ private:
out_sample_count, frame_size, static_cast<u32>(hdr.sz));
return false;
}
+
const auto end_time = std::chrono::high_resolution_clock::now() - start_time;
sample_count = out_sample_count;
consumed = static_cast<u32>(sizeof(OpusHeader) + hdr.sz);
- if (performance_time.has_value()) {
- performance_time->get() =
+ if (out_performance_time != nullptr) {
+ *out_performance_time =
std::chrono::duration_cast<std::chrono::milliseconds>(end_time).count();
}
+
return true;
}
+ void ResetDecoderContext() {
+ ASSERT(decoder != nullptr);
+
+ opus_decoder_ctl(decoder.get(), OPUS_RESET_STATE);
+ }
+
struct OpusHeader {
u32_be sz; // Needs to be BE for some odd reason
INSERT_PADDING_WORDS(1);
@@ -157,6 +187,7 @@ void HwOpus::GetWorkBufferSize(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp{ctx};
const auto sample_rate = rp.Pop<u32>();
const auto channel_count = rp.Pop<u32>();
+
LOG_DEBUG(Audio, "called with sample_rate={}, channel_count={}", sample_rate, channel_count);
ASSERT_MSG(sample_rate == 48000 || sample_rate == 24000 || sample_rate == 16000 ||
@@ -174,9 +205,10 @@ void HwOpus::GetWorkBufferSize(Kernel::HLERequestContext& ctx) {
void HwOpus::OpenOpusDecoder(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp{ctx};
- auto sample_rate = rp.Pop<u32>();
- auto channel_count = rp.Pop<u32>();
- auto buffer_sz = rp.Pop<u32>();
+ const auto sample_rate = rp.Pop<u32>();
+ const auto channel_count = rp.Pop<u32>();
+ const auto buffer_sz = rp.Pop<u32>();
+
LOG_DEBUG(Audio, "called sample_rate={}, channel_count={}, buffer_size={}", sample_rate,
channel_count, buffer_sz);
@@ -185,8 +217,9 @@ void HwOpus::OpenOpusDecoder(Kernel::HLERequestContext& ctx) {
"Invalid sample rate");
ASSERT_MSG(channel_count == 1 || channel_count == 2, "Invalid channel count");
- std::size_t worker_sz = WorkerBufferSize(channel_count);
+ const std::size_t worker_sz = WorkerBufferSize(channel_count);
ASSERT_MSG(buffer_sz >= worker_sz, "Worker buffer too large");
+
std::unique_ptr<OpusDecoder, OpusDeleter> decoder{
static_cast<OpusDecoder*>(operator new(worker_sz))};
if (const int err = opus_decoder_init(decoder.get(), sample_rate, channel_count)) {