From 01ec2e8a67999afbacacdb00eb5ed507ac9b1b73 Mon Sep 17 00:00:00 2001 From: Hamish Milne Date: Mon, 30 Dec 2019 16:53:57 +0000 Subject: [PATCH] Serialize MIC service --- TODO | 4 +-- src/core/hle/service/ldr_ro/ldr_ro.cpp | 4 +++ src/core/hle/service/ldr_ro/ldr_ro.h | 18 ++++++++++++ src/core/hle/service/mic_u.cpp | 40 ++++++++++++++++++++++++++ src/core/hle/service/mic_u.h | 7 +++++ 5 files changed, 71 insertions(+), 2 deletions(-) diff --git a/TODO b/TODO index b679a5168..2aff6ae68 100644 --- a/TODO +++ b/TODO @@ -86,8 +86,8 @@ ✔ HID @done(19-12-30 14:46) ✔ HTTP @done(19-12-30 15:18) ✔ IR @done(19-12-30 16:06) - ☐ LDR_RO - ☐ MIC + ✔ LDR_RO @done(19-12-30 16:25) + ✔ MIC @done(19-12-30 16:53) ☐ MVD ☐ NDM ☐ NEWS diff --git a/src/core/hle/service/ldr_ro/ldr_ro.cpp b/src/core/hle/service/ldr_ro/ldr_ro.cpp index caa063593..0a61f4c23 100644 --- a/src/core/hle/service/ldr_ro/ldr_ro.cpp +++ b/src/core/hle/service/ldr_ro/ldr_ro.cpp @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #include "common/alignment.h" +#include "common/archives.h" #include "common/common_types.h" #include "common/logging/log.h" #include "core/arm/arm_interface.h" @@ -12,6 +13,9 @@ #include "core/hle/service/ldr_ro/cro_helper.h" #include "core/hle/service/ldr_ro/ldr_ro.h" +SERVICE_CONSTRUCT_IMPL(Service::LDR::RO) +SERIALIZE_EXPORT_IMPL(Service::LDR::RO) + namespace Service::LDR { static const ResultCode ERROR_ALREADY_INITIALIZED = // 0xD9612FF9 diff --git a/src/core/hle/service/ldr_ro/ldr_ro.h b/src/core/hle/service/ldr_ro/ldr_ro.h index f90005d13..2b6f79f03 100644 --- a/src/core/hle/service/ldr_ro/ldr_ro.h +++ b/src/core/hle/service/ldr_ro/ldr_ro.h @@ -14,6 +14,13 @@ namespace Service::LDR { struct ClientSlot : public Kernel::SessionRequestHandler::SessionDataBase { VAddr loaded_crs = 0; ///< the virtual address of the static module + +private: + template + void serialize(Archive& ar, const unsigned int) { + ar& loaded_crs; + } + friend class boost::serialization::access; }; class RO final : public ServiceFramework { @@ -151,8 +158,19 @@ private: void Shutdown(Kernel::HLERequestContext& self); Core::System& system; + +private: + template + void serialize(Archive& ar, const unsigned int) { + ar& boost::serialization::base_object(*this); + } + friend class boost::serialization::access; }; void InstallInterfaces(Core::System& system); } // namespace Service::LDR + +SERVICE_CONSTRUCT(Service::LDR::RO) +BOOST_CLASS_EXPORT_KEY(Service::LDR::RO) +BOOST_CLASS_EXPORT_KEY(Service::LDR::ClientSlot) diff --git a/src/core/hle/service/mic_u.cpp b/src/core/hle/service/mic_u.cpp index ba3e97807..34b16094a 100644 --- a/src/core/hle/service/mic_u.cpp +++ b/src/core/hle/service/mic_u.cpp @@ -5,6 +5,7 @@ #ifdef HAVE_CUBEB #include "audio_core/cubeb_input.h" #endif +#include "common/archives.h" #include "common/logging/log.h" #include "core/core.h" #include "core/frontend/mic.h" @@ -17,8 +18,17 @@ #include "core/hle/service/mic_u.h" #include "core/settings.h" +SERVICE_CONSTRUCT_IMPL(Service::MIC::MIC_U) +SERIALIZE_EXPORT_IMPL(Service::MIC::MIC_U) + namespace Service::MIC { +template +void MIC_U::serialize(Archive& ar, const unsigned int) { + ar&* impl.get(); +} +SERIALIZE_IMPL(MIC_U) + /// Microphone audio encodings. enum class Encoding : u8 { PCM8 = 0, ///< Unsigned 8-bit PCM. @@ -59,6 +69,7 @@ constexpr u64 GetBufferUpdateRate(SampleRate sample_rate) { // Variables holding the current mic buffer writing state struct State { + std::shared_ptr memory_ref = nullptr; u8* sharedmem_buffer = nullptr; u32 sharedmem_size = 0; std::size_t size = 0; @@ -95,6 +106,20 @@ struct State { std::memcpy(sharedmem_buffer + (sharedmem_size - sizeof(u32)), reinterpret_cast(&off), sizeof(u32)); } + +private: + template + void serialize(Archive& ar, const unsigned int) { + ar& sharedmem_size; + ar& size; + ar& offset; + ar& initial_offset; + ar& looped_buffer; + ar& sample_size; + ar& sample_rate; + sharedmem_buffer = memory_ref ? memory_ref->GetPointer() : nullptr; + } + friend class boost::serialization::access; }; struct MIC_U::Impl { @@ -363,6 +388,21 @@ struct MIC_U::Impl { std::unique_ptr mic; Core::Timing& timing; State state{}; + +private: + template + void serialize(Archive& ar, const unsigned int) { + ar& change_mic_impl_requested; + ar& buffer_full_event; + // buffer_write_event set in constructor + ar& shared_memory; + ar& client_version; + ar& allow_shell_closed; + ar& clamp; + // mic interface set in constructor + ar& state; + } + friend class boost::serialization::access; }; void MIC_U::MapSharedMem(Kernel::HLERequestContext& ctx) { diff --git a/src/core/hle/service/mic_u.h b/src/core/hle/service/mic_u.h index 2e40ed404..2ca95e924 100644 --- a/src/core/hle/service/mic_u.h +++ b/src/core/hle/service/mic_u.h @@ -190,6 +190,10 @@ private: struct Impl; std::unique_ptr impl; + + template + void serialize(Archive& ar, const unsigned int); + friend class boost::serialization::access; }; void ReloadMic(Core::System& system); @@ -197,3 +201,6 @@ void ReloadMic(Core::System& system); void InstallInterfaces(Core::System& system); } // namespace Service::MIC + +SERVICE_CONSTRUCT(Service::MIC::MIC_U) +BOOST_CLASS_EXPORT_KEY(Service::MIC::MIC_U)