diff options
Diffstat (limited to 'src')
28 files changed, 938 insertions, 114 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 85354f43e..a88551fbc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt | |||
| @@ -3,6 +3,7 @@ include_directories(.) | |||
| 3 | 3 | ||
| 4 | add_subdirectory(common) | 4 | add_subdirectory(common) |
| 5 | add_subdirectory(core) | 5 | add_subdirectory(core) |
| 6 | add_subdirectory(audio_core) | ||
| 6 | add_subdirectory(video_core) | 7 | add_subdirectory(video_core) |
| 7 | add_subdirectory(input_common) | 8 | add_subdirectory(input_common) |
| 8 | add_subdirectory(tests) | 9 | add_subdirectory(tests) |
diff --git a/src/audio_core/CMakeLists.txt b/src/audio_core/CMakeLists.txt new file mode 100644 index 000000000..f00a55994 --- /dev/null +++ b/src/audio_core/CMakeLists.txt | |||
| @@ -0,0 +1,11 @@ | |||
| 1 | add_library(audio_core STATIC | ||
| 2 | audio_out.cpp | ||
| 3 | audio_out.h | ||
| 4 | buffer.h | ||
| 5 | stream.cpp | ||
| 6 | stream.h | ||
| 7 | ) | ||
| 8 | |||
| 9 | create_target_directory_groups(audio_core) | ||
| 10 | |||
| 11 | target_link_libraries(audio_core PUBLIC common core) | ||
diff --git a/src/audio_core/audio_out.cpp b/src/audio_core/audio_out.cpp new file mode 100644 index 000000000..6d418a05b --- /dev/null +++ b/src/audio_core/audio_out.cpp | |||
| @@ -0,0 +1,50 @@ | |||
| 1 | // Copyright 2018 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include "audio_core/audio_out.h" | ||
| 6 | #include "common/assert.h" | ||
| 7 | #include "common/logging/log.h" | ||
| 8 | |||
| 9 | namespace AudioCore { | ||
| 10 | |||
| 11 | /// Returns the stream format from the specified number of channels | ||
| 12 | static Stream::Format ChannelsToStreamFormat(int num_channels) { | ||
| 13 | switch (num_channels) { | ||
| 14 | case 1: | ||
| 15 | return Stream::Format::Mono16; | ||
| 16 | case 2: | ||
| 17 | return Stream::Format::Stereo16; | ||
| 18 | case 6: | ||
| 19 | return Stream::Format::Multi51Channel16; | ||
| 20 | } | ||
| 21 | |||
| 22 | LOG_CRITICAL(Audio, "Unimplemented num_channels={}", num_channels); | ||
| 23 | UNREACHABLE(); | ||
| 24 | return {}; | ||
| 25 | } | ||
| 26 | |||
| 27 | StreamPtr AudioOut::OpenStream(int sample_rate, int num_channels, | ||
| 28 | Stream::ReleaseCallback&& release_callback) { | ||
| 29 | streams.push_back(std::make_shared<Stream>(sample_rate, ChannelsToStreamFormat(num_channels), | ||
| 30 | std::move(release_callback))); | ||
| 31 | return streams.back(); | ||
| 32 | } | ||
| 33 | |||
| 34 | std::vector<u64> AudioOut::GetTagsAndReleaseBuffers(StreamPtr stream, size_t max_count) { | ||
| 35 | return stream->GetTagsAndReleaseBuffers(max_count); | ||
| 36 | } | ||
| 37 | |||
| 38 | void AudioOut::StartStream(StreamPtr stream) { | ||
| 39 | stream->Play(); | ||
| 40 | } | ||
| 41 | |||
| 42 | void AudioOut::StopStream(StreamPtr stream) { | ||
| 43 | stream->Stop(); | ||
| 44 | } | ||
| 45 | |||
| 46 | bool AudioOut::QueueBuffer(StreamPtr stream, Buffer::Tag tag, std::vector<u8>&& data) { | ||
| 47 | return stream->QueueBuffer(std::make_shared<Buffer>(tag, std::move(data))); | ||
| 48 | } | ||
| 49 | |||
| 50 | } // namespace AudioCore | ||
diff --git a/src/audio_core/audio_out.h b/src/audio_core/audio_out.h new file mode 100644 index 000000000..a86499d10 --- /dev/null +++ b/src/audio_core/audio_out.h | |||
| @@ -0,0 +1,44 @@ | |||
| 1 | // Copyright 2018 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <memory> | ||
| 8 | #include <vector> | ||
| 9 | |||
| 10 | #include "audio_core/buffer.h" | ||
| 11 | #include "audio_core/stream.h" | ||
| 12 | #include "common/common_types.h" | ||
| 13 | |||
| 14 | namespace AudioCore { | ||
| 15 | |||
| 16 | using StreamPtr = std::shared_ptr<Stream>; | ||
| 17 | |||
| 18 | /** | ||
| 19 | * Represents an audio playback interface, used to open and play audio streams | ||
| 20 | */ | ||
| 21 | class AudioOut { | ||
| 22 | public: | ||
| 23 | /// Opens a new audio stream | ||
| 24 | StreamPtr OpenStream(int sample_rate, int num_channels, | ||
| 25 | Stream::ReleaseCallback&& release_callback); | ||
| 26 | |||
| 27 | /// Returns a vector of recently released buffers specified by tag for the specified stream | ||
| 28 | std::vector<u64> GetTagsAndReleaseBuffers(StreamPtr stream, size_t max_count); | ||
| 29 | |||
| 30 | /// Starts an audio stream for playback | ||
| 31 | void StartStream(StreamPtr stream); | ||
| 32 | |||
| 33 | /// Stops an audio stream that is currently playing | ||
| 34 | void StopStream(StreamPtr stream); | ||
| 35 | |||
| 36 | /// Queues a buffer into the specified audio stream, returns true on success | ||
| 37 | bool QueueBuffer(StreamPtr stream, Buffer::Tag tag, std::vector<u8>&& data); | ||
| 38 | |||
| 39 | private: | ||
| 40 | /// Active audio streams on the interface | ||
| 41 | std::vector<StreamPtr> streams; | ||
| 42 | }; | ||
| 43 | |||
| 44 | } // namespace AudioCore | ||
diff --git a/src/audio_core/buffer.h b/src/audio_core/buffer.h new file mode 100644 index 000000000..874ec787e --- /dev/null +++ b/src/audio_core/buffer.h | |||
| @@ -0,0 +1,37 @@ | |||
| 1 | // Copyright 2018 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <vector> | ||
| 8 | |||
| 9 | #include "common/common_types.h" | ||
| 10 | |||
| 11 | namespace AudioCore { | ||
| 12 | |||
| 13 | /** | ||
| 14 | * Represents a buffer of audio samples to be played in an audio stream | ||
| 15 | */ | ||
| 16 | class Buffer { | ||
| 17 | public: | ||
| 18 | using Tag = u64; | ||
| 19 | |||
| 20 | Buffer(Tag tag, std::vector<u8>&& data) : tag{tag}, data{std::move(data)} {} | ||
| 21 | |||
| 22 | /// Returns the raw audio data for the buffer | ||
| 23 | const std::vector<u8>& GetData() const { | ||
| 24 | return data; | ||
| 25 | } | ||
| 26 | |||
| 27 | /// Returns the buffer tag, this is provided by the game to the audout service | ||
| 28 | Tag GetTag() const { | ||
| 29 | return tag; | ||
| 30 | } | ||
| 31 | |||
| 32 | private: | ||
| 33 | Tag tag; | ||
| 34 | std::vector<u8> data; | ||
| 35 | }; | ||
| 36 | |||
| 37 | } // namespace AudioCore | ||
diff --git a/src/audio_core/stream.cpp b/src/audio_core/stream.cpp new file mode 100644 index 000000000..82bff4b9e --- /dev/null +++ b/src/audio_core/stream.cpp | |||
| @@ -0,0 +1,103 @@ | |||
| 1 | // Copyright 2018 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include "common/assert.h" | ||
| 6 | #include "common/logging/log.h" | ||
| 7 | #include "core/core_timing.h" | ||
| 8 | #include "core/core_timing_util.h" | ||
| 9 | |||
| 10 | #include "audio_core/stream.h" | ||
| 11 | |||
| 12 | namespace AudioCore { | ||
| 13 | |||
| 14 | constexpr size_t MaxAudioBufferCount{32}; | ||
| 15 | |||
| 16 | /// Returns the sample size for the specified audio stream format | ||
| 17 | static size_t SampleSizeFromFormat(Stream::Format format) { | ||
| 18 | switch (format) { | ||
| 19 | case Stream::Format::Mono16: | ||
| 20 | return 2; | ||
| 21 | case Stream::Format::Stereo16: | ||
| 22 | return 4; | ||
| 23 | case Stream::Format::Multi51Channel16: | ||
| 24 | return 12; | ||
| 25 | }; | ||
| 26 | |||
| 27 | LOG_CRITICAL(Audio, "Unimplemented format={}", static_cast<u32>(format)); | ||
| 28 | UNREACHABLE(); | ||
| 29 | return {}; | ||
| 30 | } | ||
| 31 | |||
| 32 | Stream::Stream(int sample_rate, Format format, ReleaseCallback&& release_callback) | ||
| 33 | : sample_rate{sample_rate}, format{format}, release_callback{std::move(release_callback)} { | ||
| 34 | release_event = CoreTiming::RegisterEvent( | ||
| 35 | "Stream::Release", [this](u64 userdata, int cycles_late) { ReleaseActiveBuffer(); }); | ||
| 36 | } | ||
| 37 | |||
| 38 | void Stream::Play() { | ||
| 39 | state = State::Playing; | ||
| 40 | PlayNextBuffer(); | ||
| 41 | } | ||
| 42 | |||
| 43 | void Stream::Stop() { | ||
| 44 | ASSERT_MSG(false, "Unimplemented"); | ||
| 45 | } | ||
| 46 | |||
| 47 | s64 Stream::GetBufferReleaseCycles(const Buffer& buffer) const { | ||
| 48 | const size_t num_samples{buffer.GetData().size() / SampleSizeFromFormat(format)}; | ||
| 49 | return CoreTiming::usToCycles((static_cast<u64>(num_samples) * 1000000) / sample_rate); | ||
| 50 | } | ||
| 51 | |||
| 52 | void Stream::PlayNextBuffer() { | ||
| 53 | if (!IsPlaying()) { | ||
| 54 | // Ensure we are in playing state before playing the next buffer | ||
| 55 | return; | ||
| 56 | } | ||
| 57 | |||
| 58 | if (active_buffer) { | ||
| 59 | // Do not queue a new buffer if we are already playing a buffer | ||
| 60 | return; | ||
| 61 | } | ||
| 62 | |||
| 63 | if (queued_buffers.empty()) { | ||
| 64 | // No queued buffers - we are effectively paused | ||
| 65 | return; | ||
| 66 | } | ||
| 67 | |||
| 68 | active_buffer = queued_buffers.front(); | ||
| 69 | queued_buffers.pop(); | ||
| 70 | |||
| 71 | CoreTiming::ScheduleEventThreadsafe(GetBufferReleaseCycles(*active_buffer), release_event, {}); | ||
| 72 | } | ||
| 73 | |||
| 74 | void Stream::ReleaseActiveBuffer() { | ||
| 75 | released_buffers.push(std::move(active_buffer)); | ||
| 76 | release_callback(); | ||
| 77 | PlayNextBuffer(); | ||
| 78 | } | ||
| 79 | |||
| 80 | bool Stream::QueueBuffer(BufferPtr&& buffer) { | ||
| 81 | if (queued_buffers.size() < MaxAudioBufferCount) { | ||
| 82 | queued_buffers.push(std::move(buffer)); | ||
| 83 | PlayNextBuffer(); | ||
| 84 | return true; | ||
| 85 | } | ||
| 86 | return false; | ||
| 87 | } | ||
| 88 | |||
| 89 | bool Stream::ContainsBuffer(Buffer::Tag tag) const { | ||
| 90 | ASSERT_MSG(false, "Unimplemented"); | ||
| 91 | return {}; | ||
| 92 | } | ||
| 93 | |||
| 94 | std::vector<Buffer::Tag> Stream::GetTagsAndReleaseBuffers(size_t max_count) { | ||
| 95 | std::vector<Buffer::Tag> tags; | ||
| 96 | for (size_t count = 0; count < max_count && !released_buffers.empty(); ++count) { | ||
| 97 | tags.push_back(released_buffers.front()->GetTag()); | ||
| 98 | released_buffers.pop(); | ||
| 99 | } | ||
| 100 | return tags; | ||
| 101 | } | ||
| 102 | |||
| 103 | } // namespace AudioCore | ||
diff --git a/src/audio_core/stream.h b/src/audio_core/stream.h new file mode 100644 index 000000000..5f43b0798 --- /dev/null +++ b/src/audio_core/stream.h | |||
| @@ -0,0 +1,89 @@ | |||
| 1 | // Copyright 2018 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <functional> | ||
| 8 | #include <memory> | ||
| 9 | #include <vector> | ||
| 10 | #include <queue> | ||
| 11 | |||
| 12 | #include "audio_core/buffer.h" | ||
| 13 | #include "common/assert.h" | ||
| 14 | #include "common/common_types.h" | ||
| 15 | #include "core/core_timing.h" | ||
| 16 | |||
| 17 | namespace AudioCore { | ||
| 18 | |||
| 19 | using BufferPtr = std::shared_ptr<Buffer>; | ||
| 20 | |||
| 21 | /** | ||
| 22 | * Represents an audio stream, which is a sequence of queued buffers, to be outputed by AudioOut | ||
| 23 | */ | ||
| 24 | class Stream { | ||
| 25 | public: | ||
| 26 | /// Audio format of the stream | ||
| 27 | enum class Format { | ||
| 28 | Mono16, | ||
| 29 | Stereo16, | ||
| 30 | Multi51Channel16, | ||
| 31 | }; | ||
| 32 | |||
| 33 | /// Callback function type, used to change guest state on a buffer being released | ||
| 34 | using ReleaseCallback = std::function<void()>; | ||
| 35 | |||
| 36 | Stream(int sample_rate, Format format, ReleaseCallback&& release_callback); | ||
| 37 | |||
| 38 | /// Plays the audio stream | ||
| 39 | void Play(); | ||
| 40 | |||
| 41 | /// Stops the audio stream | ||
| 42 | void Stop(); | ||
| 43 | |||
| 44 | /// Queues a buffer into the audio stream, returns true on success | ||
| 45 | bool QueueBuffer(BufferPtr&& buffer); | ||
| 46 | |||
| 47 | /// Returns true if the audio stream contains a buffer with the specified tag | ||
| 48 | bool ContainsBuffer(Buffer::Tag tag) const; | ||
| 49 | |||
| 50 | /// Returns a vector of recently released buffers specified by tag | ||
| 51 | std::vector<Buffer::Tag> GetTagsAndReleaseBuffers(size_t max_count); | ||
| 52 | |||
| 53 | /// Returns true if the stream is currently playing | ||
| 54 | bool IsPlaying() const { | ||
| 55 | return state == State::Playing; | ||
| 56 | } | ||
| 57 | |||
| 58 | /// Returns the number of queued buffers | ||
| 59 | size_t GetQueueSize() const { | ||
| 60 | return queued_buffers.size(); | ||
| 61 | } | ||
| 62 | |||
| 63 | private: | ||
| 64 | /// Current state of the stream | ||
| 65 | enum class State { | ||
| 66 | Stopped, | ||
| 67 | Playing, | ||
| 68 | }; | ||
| 69 | |||
| 70 | /// Plays the next queued buffer in the audio stream, starting playback if necessary | ||
| 71 | void PlayNextBuffer(); | ||
| 72 | |||
| 73 | /// Releases the actively playing buffer, signalling that it has been completed | ||
| 74 | void ReleaseActiveBuffer(); | ||
| 75 | |||
| 76 | /// Gets the number of core cycles when the specified buffer will be released | ||
| 77 | s64 GetBufferReleaseCycles(const Buffer& buffer) const; | ||
| 78 | |||
| 79 | int sample_rate; ///< Sample rate of the stream | ||
| 80 | Format format; ///< Format of the stream | ||
| 81 | ReleaseCallback release_callback; ///< Buffer release callback for the stream | ||
| 82 | State state{State::Stopped}; ///< Playback state of the stream | ||
| 83 | CoreTiming::EventType* release_event{}; ///< Core timing release event for the stream | ||
| 84 | BufferPtr active_buffer; ///< Actively playing buffer in the stream | ||
| 85 | std::queue<BufferPtr> queued_buffers; ///< Buffers queued to be played in the stream | ||
| 86 | std::queue<BufferPtr> released_buffers; ///< Buffers recently released from the stream | ||
| 87 | }; | ||
| 88 | |||
| 89 | } // namespace AudioCore | ||
diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp index 67a803e23..38cc85e23 100644 --- a/src/common/logging/backend.cpp +++ b/src/common/logging/backend.cpp | |||
| @@ -176,6 +176,7 @@ void FileBackend::Write(const Entry& entry) { | |||
| 176 | SUB(Service, LBL) \ | 176 | SUB(Service, LBL) \ |
| 177 | SUB(Service, LDN) \ | 177 | SUB(Service, LDN) \ |
| 178 | SUB(Service, LM) \ | 178 | SUB(Service, LM) \ |
| 179 | SUB(Service, Mii) \ | ||
| 179 | SUB(Service, MM) \ | 180 | SUB(Service, MM) \ |
| 180 | SUB(Service, NCM) \ | 181 | SUB(Service, NCM) \ |
| 181 | SUB(Service, NFC) \ | 182 | SUB(Service, NFC) \ |
diff --git a/src/common/logging/log.h b/src/common/logging/log.h index a3e805794..db4a80d0a 100644 --- a/src/common/logging/log.h +++ b/src/common/logging/log.h | |||
| @@ -63,6 +63,7 @@ enum class Class : ClassType { | |||
| 63 | Service_LBL, ///< The LBL (LCD backlight) service | 63 | Service_LBL, ///< The LBL (LCD backlight) service |
| 64 | Service_LDN, ///< The LDN (Local domain network) service | 64 | Service_LDN, ///< The LDN (Local domain network) service |
| 65 | Service_LM, ///< The LM (Logger) service | 65 | Service_LM, ///< The LM (Logger) service |
| 66 | Service_Mii, ///< The Mii service | ||
| 66 | Service_MM, ///< The MM (Multimedia) service | 67 | Service_MM, ///< The MM (Multimedia) service |
| 67 | Service_NCM, ///< The NCM service | 68 | Service_NCM, ///< The NCM service |
| 68 | Service_NFC, ///< The NFC (Near-field communication) service | 69 | Service_NFC, ///< The NFC (Near-field communication) service |
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 7b60f9163..f1e7e2593 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt | |||
| @@ -23,6 +23,8 @@ add_library(core STATIC | |||
| 23 | file_sys/partition_filesystem.h | 23 | file_sys/partition_filesystem.h |
| 24 | file_sys/program_metadata.cpp | 24 | file_sys/program_metadata.cpp |
| 25 | file_sys/program_metadata.h | 25 | file_sys/program_metadata.h |
| 26 | file_sys/romfs.cpp | ||
| 27 | file_sys/romfs.h | ||
| 26 | file_sys/romfs_factory.cpp | 28 | file_sys/romfs_factory.cpp |
| 27 | file_sys/romfs_factory.h | 29 | file_sys/romfs_factory.h |
| 28 | file_sys/savedata_factory.cpp | 30 | file_sys/savedata_factory.cpp |
| @@ -35,6 +37,8 @@ add_library(core STATIC | |||
| 35 | file_sys/vfs_offset.h | 37 | file_sys/vfs_offset.h |
| 36 | file_sys/vfs_real.cpp | 38 | file_sys/vfs_real.cpp |
| 37 | file_sys/vfs_real.h | 39 | file_sys/vfs_real.h |
| 40 | file_sys/vfs_vector.cpp | ||
| 41 | file_sys/vfs_vector.h | ||
| 38 | frontend/emu_window.cpp | 42 | frontend/emu_window.cpp |
| 39 | frontend/emu_window.h | 43 | frontend/emu_window.h |
| 40 | frontend/framebuffer_layout.cpp | 44 | frontend/framebuffer_layout.cpp |
| @@ -174,6 +178,8 @@ add_library(core STATIC | |||
| 174 | hle/service/ldr/ldr.h | 178 | hle/service/ldr/ldr.h |
| 175 | hle/service/lm/lm.cpp | 179 | hle/service/lm/lm.cpp |
| 176 | hle/service/lm/lm.h | 180 | hle/service/lm/lm.h |
| 181 | hle/service/mii/mii.cpp | ||
| 182 | hle/service/mii/mii.h | ||
| 177 | hle/service/mm/mm_u.cpp | 183 | hle/service/mm/mm_u.cpp |
| 178 | hle/service/mm/mm_u.h | 184 | hle/service/mm/mm_u.h |
| 179 | hle/service/ncm/ncm.cpp | 185 | hle/service/ncm/ncm.cpp |
| @@ -307,7 +313,7 @@ add_library(core STATIC | |||
| 307 | 313 | ||
| 308 | create_target_directory_groups(core) | 314 | create_target_directory_groups(core) |
| 309 | 315 | ||
| 310 | target_link_libraries(core PUBLIC common PRIVATE video_core) | 316 | target_link_libraries(core PUBLIC common PRIVATE audio_core video_core) |
| 311 | target_link_libraries(core PUBLIC Boost::boost PRIVATE fmt lz4_static unicorn) | 317 | target_link_libraries(core PUBLIC Boost::boost PRIVATE fmt lz4_static unicorn) |
| 312 | 318 | ||
| 313 | if (ARCHITECTURE_x86_64) | 319 | if (ARCHITECTURE_x86_64) |
diff --git a/src/core/core.cpp b/src/core/core.cpp index b7f4b4532..186fa46df 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp | |||
| @@ -177,6 +177,7 @@ System::ResultStatus System::Init(EmuWindow* emu_window, u32 system_mode) { | |||
| 177 | } | 177 | } |
| 178 | 178 | ||
| 179 | gpu_core = std::make_unique<Tegra::GPU>(); | 179 | gpu_core = std::make_unique<Tegra::GPU>(); |
| 180 | audio_core = std::make_unique<AudioCore::AudioOut>(); | ||
| 180 | telemetry_session = std::make_unique<Core::TelemetrySession>(); | 181 | telemetry_session = std::make_unique<Core::TelemetrySession>(); |
| 181 | service_manager = std::make_shared<Service::SM::ServiceManager>(); | 182 | service_manager = std::make_shared<Service::SM::ServiceManager>(); |
| 182 | 183 | ||
| @@ -228,6 +229,7 @@ void System::Shutdown() { | |||
| 228 | service_manager.reset(); | 229 | service_manager.reset(); |
| 229 | telemetry_session.reset(); | 230 | telemetry_session.reset(); |
| 230 | gpu_core.reset(); | 231 | gpu_core.reset(); |
| 232 | audio_core.reset(); | ||
| 231 | 233 | ||
| 232 | // Close all CPU/threading state | 234 | // Close all CPU/threading state |
| 233 | cpu_barrier->NotifyEnd(); | 235 | cpu_barrier->NotifyEnd(); |
diff --git a/src/core/core.h b/src/core/core.h index c123fe401..6f4df775f 100644 --- a/src/core/core.h +++ b/src/core/core.h | |||
| @@ -8,6 +8,7 @@ | |||
| 8 | #include <memory> | 8 | #include <memory> |
| 9 | #include <string> | 9 | #include <string> |
| 10 | #include <thread> | 10 | #include <thread> |
| 11 | #include "audio_core/audio_out.h" | ||
| 11 | #include "common/common_types.h" | 12 | #include "common/common_types.h" |
| 12 | #include "core/arm/exclusive_monitor.h" | 13 | #include "core/arm/exclusive_monitor.h" |
| 13 | #include "core/core_cpu.h" | 14 | #include "core/core_cpu.h" |
| @@ -131,6 +132,11 @@ public: | |||
| 131 | return *gpu_core; | 132 | return *gpu_core; |
| 132 | } | 133 | } |
| 133 | 134 | ||
| 135 | /// Gets the AudioCore interface | ||
| 136 | AudioCore::AudioOut& AudioCore() { | ||
| 137 | return *audio_core; | ||
| 138 | } | ||
| 139 | |||
| 134 | /// Gets the scheduler for the CPU core that is currently running | 140 | /// Gets the scheduler for the CPU core that is currently running |
| 135 | Kernel::Scheduler& CurrentScheduler() { | 141 | Kernel::Scheduler& CurrentScheduler() { |
| 136 | return *CurrentCpuCore().Scheduler(); | 142 | return *CurrentCpuCore().Scheduler(); |
| @@ -195,6 +201,7 @@ private: | |||
| 195 | /// AppLoader used to load the current executing application | 201 | /// AppLoader used to load the current executing application |
| 196 | std::unique_ptr<Loader::AppLoader> app_loader; | 202 | std::unique_ptr<Loader::AppLoader> app_loader; |
| 197 | std::unique_ptr<Tegra::GPU> gpu_core; | 203 | std::unique_ptr<Tegra::GPU> gpu_core; |
| 204 | std::unique_ptr<AudioCore::AudioOut> audio_core; | ||
| 198 | std::shared_ptr<Tegra::DebugContext> debug_context; | 205 | std::shared_ptr<Tegra::DebugContext> debug_context; |
| 199 | Kernel::SharedPtr<Kernel::Process> current_process; | 206 | Kernel::SharedPtr<Kernel::Process> current_process; |
| 200 | std::shared_ptr<ExclusiveMonitor> cpu_exclusive_monitor; | 207 | std::shared_ptr<ExclusiveMonitor> cpu_exclusive_monitor; |
diff --git a/src/core/file_sys/content_archive.cpp b/src/core/file_sys/content_archive.cpp index d6b20c047..61cb0bbe3 100644 --- a/src/core/file_sys/content_archive.cpp +++ b/src/core/file_sys/content_archive.cpp | |||
| @@ -9,6 +9,7 @@ | |||
| 9 | #include "core/file_sys/content_archive.h" | 9 | #include "core/file_sys/content_archive.h" |
| 10 | #include "core/file_sys/vfs_offset.h" | 10 | #include "core/file_sys/vfs_offset.h" |
| 11 | #include "core/loader/loader.h" | 11 | #include "core/loader/loader.h" |
| 12 | #include "romfs.h" | ||
| 12 | 13 | ||
| 13 | namespace FileSys { | 14 | namespace FileSys { |
| 14 | 15 | ||
| @@ -46,21 +47,9 @@ struct PFS0Superblock { | |||
| 46 | }; | 47 | }; |
| 47 | static_assert(sizeof(PFS0Superblock) == 0x200, "PFS0Superblock has incorrect size."); | 48 | static_assert(sizeof(PFS0Superblock) == 0x200, "PFS0Superblock has incorrect size."); |
| 48 | 49 | ||
| 49 | struct IVFCLevel { | ||
| 50 | u64_le offset; | ||
| 51 | u64_le size; | ||
| 52 | u32_le block_size; | ||
| 53 | u32_le reserved; | ||
| 54 | }; | ||
| 55 | static_assert(sizeof(IVFCLevel) == 0x18, "IVFCLevel has incorrect size."); | ||
| 56 | |||
| 57 | struct RomFSSuperblock { | 50 | struct RomFSSuperblock { |
| 58 | NCASectionHeaderBlock header_block; | 51 | NCASectionHeaderBlock header_block; |
| 59 | u32_le magic; | 52 | IVFCHeader ivfc; |
| 60 | u32_le magic_number; | ||
| 61 | INSERT_PADDING_BYTES(8); | ||
| 62 | std::array<IVFCLevel, 6> levels; | ||
| 63 | INSERT_PADDING_BYTES(64); | ||
| 64 | }; | 53 | }; |
| 65 | static_assert(sizeof(RomFSSuperblock) == 0xE8, "RomFSSuperblock has incorrect size."); | 54 | static_assert(sizeof(RomFSSuperblock) == 0xE8, "RomFSSuperblock has incorrect size."); |
| 66 | 55 | ||
| @@ -92,8 +81,8 @@ NCA::NCA(VirtualFile file_) : file(std::move(file_)) { | |||
| 92 | 81 | ||
| 93 | const size_t romfs_offset = | 82 | const size_t romfs_offset = |
| 94 | header.section_tables[i].media_offset * MEDIA_OFFSET_MULTIPLIER + | 83 | header.section_tables[i].media_offset * MEDIA_OFFSET_MULTIPLIER + |
| 95 | sb.levels[IVFC_MAX_LEVEL - 1].offset; | 84 | sb.ivfc.levels[IVFC_MAX_LEVEL - 1].offset; |
| 96 | const size_t romfs_size = sb.levels[IVFC_MAX_LEVEL - 1].size; | 85 | const size_t romfs_size = sb.ivfc.levels[IVFC_MAX_LEVEL - 1].size; |
| 97 | files.emplace_back(std::make_shared<OffsetVfsFile>(file, romfs_size, romfs_offset)); | 86 | files.emplace_back(std::make_shared<OffsetVfsFile>(file, romfs_size, romfs_offset)); |
| 98 | romfs = files.back(); | 87 | romfs = files.back(); |
| 99 | } else if (block.filesystem_type == NCASectionFilesystemType::PFS0) { | 88 | } else if (block.filesystem_type == NCASectionFilesystemType::PFS0) { |
diff --git a/src/core/file_sys/romfs.cpp b/src/core/file_sys/romfs.cpp new file mode 100644 index 000000000..ff3ddb29c --- /dev/null +++ b/src/core/file_sys/romfs.cpp | |||
| @@ -0,0 +1,124 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include "common/common_types.h" | ||
| 6 | #include "common/swap.h" | ||
| 7 | #include "core/file_sys/romfs.h" | ||
| 8 | #include "core/file_sys/vfs.h" | ||
| 9 | #include "core/file_sys/vfs_offset.h" | ||
| 10 | #include "core/file_sys/vfs_vector.h" | ||
| 11 | |||
| 12 | namespace FileSys { | ||
| 13 | |||
| 14 | constexpr u32 ROMFS_ENTRY_EMPTY = 0xFFFFFFFF; | ||
| 15 | |||
| 16 | struct TableLocation { | ||
| 17 | u64_le offset; | ||
| 18 | u64_le size; | ||
| 19 | }; | ||
| 20 | static_assert(sizeof(TableLocation) == 0x10, "TableLocation has incorrect size."); | ||
| 21 | |||
| 22 | struct RomFSHeader { | ||
| 23 | u64_le header_size; | ||
| 24 | TableLocation directory_hash; | ||
| 25 | TableLocation directory_meta; | ||
| 26 | TableLocation file_hash; | ||
| 27 | TableLocation file_meta; | ||
| 28 | u64_le data_offset; | ||
| 29 | }; | ||
| 30 | static_assert(sizeof(RomFSHeader) == 0x50, "RomFSHeader has incorrect size."); | ||
| 31 | |||
| 32 | struct DirectoryEntry { | ||
| 33 | u32_le sibling; | ||
| 34 | u32_le child_dir; | ||
| 35 | u32_le child_file; | ||
| 36 | u32_le hash; | ||
| 37 | u32_le name_length; | ||
| 38 | }; | ||
| 39 | static_assert(sizeof(DirectoryEntry) == 0x14, "DirectoryEntry has incorrect size."); | ||
| 40 | |||
| 41 | struct FileEntry { | ||
| 42 | u32_le parent; | ||
| 43 | u32_le sibling; | ||
| 44 | u64_le offset; | ||
| 45 | u64_le size; | ||
| 46 | u32_le hash; | ||
| 47 | u32_le name_length; | ||
| 48 | }; | ||
| 49 | static_assert(sizeof(FileEntry) == 0x20, "FileEntry has incorrect size."); | ||
| 50 | |||
| 51 | template <typename Entry> | ||
| 52 | static std::pair<Entry, std::string> GetEntry(const VirtualFile& file, size_t offset) { | ||
| 53 | Entry entry{}; | ||
| 54 | if (file->ReadObject(&entry, offset) != sizeof(Entry)) | ||
| 55 | return {}; | ||
| 56 | std::string string(entry.name_length, '\0'); | ||
| 57 | if (file->ReadArray(&string[0], string.size(), offset + sizeof(Entry)) != string.size()) | ||
| 58 | return {}; | ||
| 59 | return {entry, string}; | ||
| 60 | } | ||
| 61 | |||
| 62 | void ProcessFile(VirtualFile file, size_t file_offset, size_t data_offset, u32 this_file_offset, | ||
| 63 | std::shared_ptr<VectorVfsDirectory> parent) { | ||
| 64 | while (true) { | ||
| 65 | auto entry = GetEntry<FileEntry>(file, file_offset + this_file_offset); | ||
| 66 | |||
| 67 | parent->AddFile(std::make_shared<OffsetVfsFile>( | ||
| 68 | file, entry.first.size, entry.first.offset + data_offset, entry.second, parent)); | ||
| 69 | |||
| 70 | if (entry.first.sibling == ROMFS_ENTRY_EMPTY) | ||
| 71 | break; | ||
| 72 | |||
| 73 | this_file_offset = entry.first.sibling; | ||
| 74 | } | ||
| 75 | } | ||
| 76 | |||
| 77 | void ProcessDirectory(VirtualFile file, size_t dir_offset, size_t file_offset, size_t data_offset, | ||
| 78 | u32 this_dir_offset, std::shared_ptr<VectorVfsDirectory> parent) { | ||
| 79 | while (true) { | ||
| 80 | auto entry = GetEntry<DirectoryEntry>(file, dir_offset + this_dir_offset); | ||
| 81 | auto current = std::make_shared<VectorVfsDirectory>( | ||
| 82 | std::vector<VirtualFile>{}, std::vector<VirtualDir>{}, parent, entry.second); | ||
| 83 | |||
| 84 | if (entry.first.child_file != ROMFS_ENTRY_EMPTY) { | ||
| 85 | ProcessFile(file, file_offset, data_offset, entry.first.child_file, current); | ||
| 86 | } | ||
| 87 | |||
| 88 | if (entry.first.child_dir != ROMFS_ENTRY_EMPTY) { | ||
| 89 | ProcessDirectory(file, dir_offset, file_offset, data_offset, entry.first.child_dir, | ||
| 90 | current); | ||
| 91 | } | ||
| 92 | |||
| 93 | parent->AddDirectory(current); | ||
| 94 | if (entry.first.sibling == ROMFS_ENTRY_EMPTY) | ||
| 95 | break; | ||
| 96 | this_dir_offset = entry.first.sibling; | ||
| 97 | } | ||
| 98 | } | ||
| 99 | |||
| 100 | VirtualDir ExtractRomFS(VirtualFile file) { | ||
| 101 | RomFSHeader header{}; | ||
| 102 | if (file->ReadObject(&header) != sizeof(RomFSHeader)) | ||
| 103 | return nullptr; | ||
| 104 | |||
| 105 | if (header.header_size != sizeof(RomFSHeader)) | ||
| 106 | return nullptr; | ||
| 107 | |||
| 108 | const u64 file_offset = header.file_meta.offset; | ||
| 109 | const u64 dir_offset = header.directory_meta.offset + 4; | ||
| 110 | |||
| 111 | const auto root = | ||
| 112 | std::make_shared<VectorVfsDirectory>(std::vector<VirtualFile>{}, std::vector<VirtualDir>{}, | ||
| 113 | file->GetContainingDirectory(), file->GetName()); | ||
| 114 | |||
| 115 | ProcessDirectory(file, dir_offset, file_offset, header.data_offset, 0, root); | ||
| 116 | |||
| 117 | VirtualDir out = std::move(root); | ||
| 118 | |||
| 119 | while (out->GetSubdirectory("") != nullptr) | ||
| 120 | out = out->GetSubdirectory(""); | ||
| 121 | |||
| 122 | return out; | ||
| 123 | } | ||
| 124 | } // namespace FileSys | ||
diff --git a/src/core/file_sys/romfs.h b/src/core/file_sys/romfs.h new file mode 100644 index 000000000..03a876d22 --- /dev/null +++ b/src/core/file_sys/romfs.h | |||
| @@ -0,0 +1,35 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <array> | ||
| 8 | #include "common/common_funcs.h" | ||
| 9 | #include "common/swap.h" | ||
| 10 | #include "core/file_sys/vfs.h" | ||
| 11 | |||
| 12 | namespace FileSys { | ||
| 13 | |||
| 14 | struct IVFCLevel { | ||
| 15 | u64_le offset; | ||
| 16 | u64_le size; | ||
| 17 | u32_le block_size; | ||
| 18 | u32_le reserved; | ||
| 19 | }; | ||
| 20 | static_assert(sizeof(IVFCLevel) == 0x18, "IVFCLevel has incorrect size."); | ||
| 21 | |||
| 22 | struct IVFCHeader { | ||
| 23 | u32_le magic; | ||
| 24 | u32_le magic_number; | ||
| 25 | INSERT_PADDING_BYTES(8); | ||
| 26 | std::array<IVFCLevel, 6> levels; | ||
| 27 | INSERT_PADDING_BYTES(64); | ||
| 28 | }; | ||
| 29 | static_assert(sizeof(IVFCHeader) == 0xE0, "IVFCHeader has incorrect size."); | ||
| 30 | |||
| 31 | // Converts a RomFS binary blob to VFS Filesystem | ||
| 32 | // Returns nullptr on failure | ||
| 33 | VirtualDir ExtractRomFS(VirtualFile file); | ||
| 34 | |||
| 35 | } // namespace FileSys | ||
diff --git a/src/core/file_sys/vfs.cpp b/src/core/file_sys/vfs.cpp index b99a4fd5b..84a6a7397 100644 --- a/src/core/file_sys/vfs.cpp +++ b/src/core/file_sys/vfs.cpp | |||
| @@ -46,6 +46,13 @@ size_t VfsFile::WriteBytes(const std::vector<u8>& data, size_t offset) { | |||
| 46 | return Write(data.data(), data.size(), offset); | 46 | return Write(data.data(), data.size(), offset); |
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | std::string VfsFile::GetFullPath() const { | ||
| 50 | if (GetContainingDirectory() == nullptr) | ||
| 51 | return "/" + GetName(); | ||
| 52 | |||
| 53 | return GetContainingDirectory()->GetFullPath() + "/" + GetName(); | ||
| 54 | } | ||
| 55 | |||
| 49 | std::shared_ptr<VfsFile> VfsDirectory::GetFileRelative(std::string_view path) const { | 56 | std::shared_ptr<VfsFile> VfsDirectory::GetFileRelative(std::string_view path) const { |
| 50 | auto vec = FileUtil::SplitPathComponents(path); | 57 | auto vec = FileUtil::SplitPathComponents(path); |
| 51 | vec.erase(std::remove_if(vec.begin(), vec.end(), [](const auto& str) { return str.empty(); }), | 58 | vec.erase(std::remove_if(vec.begin(), vec.end(), [](const auto& str) { return str.empty(); }), |
| @@ -243,6 +250,13 @@ bool VfsDirectory::Copy(std::string_view src, std::string_view dest) { | |||
| 243 | return f2->WriteBytes(f1->ReadAllBytes()) == f1->GetSize(); | 250 | return f2->WriteBytes(f1->ReadAllBytes()) == f1->GetSize(); |
| 244 | } | 251 | } |
| 245 | 252 | ||
| 253 | std::string VfsDirectory::GetFullPath() const { | ||
| 254 | if (IsRoot()) | ||
| 255 | return GetName(); | ||
| 256 | |||
| 257 | return GetParentDirectory()->GetFullPath() + "/" + GetName(); | ||
| 258 | } | ||
| 259 | |||
| 246 | bool ReadOnlyVfsDirectory::IsWritable() const { | 260 | bool ReadOnlyVfsDirectory::IsWritable() const { |
| 247 | return false; | 261 | return false; |
| 248 | } | 262 | } |
| @@ -270,4 +284,13 @@ bool ReadOnlyVfsDirectory::DeleteFile(std::string_view name) { | |||
| 270 | bool ReadOnlyVfsDirectory::Rename(std::string_view name) { | 284 | bool ReadOnlyVfsDirectory::Rename(std::string_view name) { |
| 271 | return false; | 285 | return false; |
| 272 | } | 286 | } |
| 287 | |||
| 288 | bool VfsRawCopy(VirtualFile src, VirtualFile dest) { | ||
| 289 | if (src == nullptr || dest == nullptr) | ||
| 290 | return false; | ||
| 291 | if (!dest->Resize(src->GetSize())) | ||
| 292 | return false; | ||
| 293 | std::vector<u8> data = src->ReadAllBytes(); | ||
| 294 | return dest->WriteBytes(data, 0) == data.size(); | ||
| 295 | } | ||
| 273 | } // namespace FileSys | 296 | } // namespace FileSys |
diff --git a/src/core/file_sys/vfs.h b/src/core/file_sys/vfs.h index 4a13b8378..cf871edd6 100644 --- a/src/core/file_sys/vfs.h +++ b/src/core/file_sys/vfs.h | |||
| @@ -113,6 +113,9 @@ struct VfsFile : NonCopyable { | |||
| 113 | 113 | ||
| 114 | // Renames the file to name. Returns whether or not the operation was successsful. | 114 | // Renames the file to name. Returns whether or not the operation was successsful. |
| 115 | virtual bool Rename(std::string_view name) = 0; | 115 | virtual bool Rename(std::string_view name) = 0; |
| 116 | |||
| 117 | // Returns the full path of this file as a string, recursively | ||
| 118 | virtual std::string GetFullPath() const; | ||
| 116 | }; | 119 | }; |
| 117 | 120 | ||
| 118 | // A class representing a directory in an abstract filesystem. | 121 | // A class representing a directory in an abstract filesystem. |
| @@ -213,6 +216,17 @@ struct VfsDirectory : NonCopyable { | |||
| 213 | return ReplaceFileWithSubdirectory(file_p, std::make_shared<Directory>(file_p)); | 216 | return ReplaceFileWithSubdirectory(file_p, std::make_shared<Directory>(file_p)); |
| 214 | } | 217 | } |
| 215 | 218 | ||
| 219 | bool InterpretAsDirectory(const std::function<VirtualDir(VirtualFile)>& function, | ||
| 220 | const std::string& file) { | ||
| 221 | auto file_p = GetFile(file); | ||
| 222 | if (file_p == nullptr) | ||
| 223 | return false; | ||
| 224 | return ReplaceFileWithSubdirectory(file_p, function(file_p)); | ||
| 225 | } | ||
| 226 | |||
| 227 | // Returns the full path of this directory as a string, recursively | ||
| 228 | virtual std::string GetFullPath() const; | ||
| 229 | |||
| 216 | protected: | 230 | protected: |
| 217 | // Backend for InterpretAsDirectory. | 231 | // Backend for InterpretAsDirectory. |
| 218 | // Removes all references to file and adds a reference to dir in the directory's implementation. | 232 | // Removes all references to file and adds a reference to dir in the directory's implementation. |
| @@ -230,4 +244,10 @@ struct ReadOnlyVfsDirectory : public VfsDirectory { | |||
| 230 | bool DeleteFile(std::string_view name) override; | 244 | bool DeleteFile(std::string_view name) override; |
| 231 | bool Rename(std::string_view name) override; | 245 | bool Rename(std::string_view name) override; |
| 232 | }; | 246 | }; |
| 247 | |||
| 248 | // A method that copies the raw data between two different implementations of VirtualFile. If you | ||
| 249 | // are using the same implementation, it is probably better to use the Copy method in the parent | ||
| 250 | // directory of src/dest. | ||
| 251 | bool VfsRawCopy(VirtualFile src, VirtualFile dest); | ||
| 252 | |||
| 233 | } // namespace FileSys | 253 | } // namespace FileSys |
diff --git a/src/core/file_sys/vfs_offset.cpp b/src/core/file_sys/vfs_offset.cpp index a40331cef..847cde2f5 100644 --- a/src/core/file_sys/vfs_offset.cpp +++ b/src/core/file_sys/vfs_offset.cpp | |||
| @@ -10,8 +10,9 @@ | |||
| 10 | namespace FileSys { | 10 | namespace FileSys { |
| 11 | 11 | ||
| 12 | OffsetVfsFile::OffsetVfsFile(std::shared_ptr<VfsFile> file_, size_t size_, size_t offset_, | 12 | OffsetVfsFile::OffsetVfsFile(std::shared_ptr<VfsFile> file_, size_t size_, size_t offset_, |
| 13 | std::string name_) | 13 | std::string name_, VirtualDir parent_) |
| 14 | : file(std::move(file_)), offset(offset_), size(size_), name(std::move(name_)) {} | 14 | : file(file_), offset(offset_), size(size_), name(std::move(name_)), |
| 15 | parent(parent_ == nullptr ? file->GetContainingDirectory() : std::move(parent_)) {} | ||
| 15 | 16 | ||
| 16 | std::string OffsetVfsFile::GetName() const { | 17 | std::string OffsetVfsFile::GetName() const { |
| 17 | return name.empty() ? file->GetName() : name; | 18 | return name.empty() ? file->GetName() : name; |
| @@ -35,7 +36,7 @@ bool OffsetVfsFile::Resize(size_t new_size) { | |||
| 35 | } | 36 | } |
| 36 | 37 | ||
| 37 | std::shared_ptr<VfsDirectory> OffsetVfsFile::GetContainingDirectory() const { | 38 | std::shared_ptr<VfsDirectory> OffsetVfsFile::GetContainingDirectory() const { |
| 38 | return file->GetContainingDirectory(); | 39 | return parent; |
| 39 | } | 40 | } |
| 40 | 41 | ||
| 41 | bool OffsetVfsFile::IsWritable() const { | 42 | bool OffsetVfsFile::IsWritable() const { |
diff --git a/src/core/file_sys/vfs_offset.h b/src/core/file_sys/vfs_offset.h index 4f471e3ba..235970dc5 100644 --- a/src/core/file_sys/vfs_offset.h +++ b/src/core/file_sys/vfs_offset.h | |||
| @@ -17,7 +17,7 @@ namespace FileSys { | |||
| 17 | // the size of this wrapper. | 17 | // the size of this wrapper. |
| 18 | struct OffsetVfsFile : public VfsFile { | 18 | struct OffsetVfsFile : public VfsFile { |
| 19 | OffsetVfsFile(std::shared_ptr<VfsFile> file, size_t size, size_t offset = 0, | 19 | OffsetVfsFile(std::shared_ptr<VfsFile> file, size_t size, size_t offset = 0, |
| 20 | std::string new_name = ""); | 20 | std::string new_name = "", VirtualDir new_parent = nullptr); |
| 21 | 21 | ||
| 22 | std::string GetName() const override; | 22 | std::string GetName() const override; |
| 23 | size_t GetSize() const override; | 23 | size_t GetSize() const override; |
| @@ -44,6 +44,7 @@ private: | |||
| 44 | size_t offset; | 44 | size_t offset; |
| 45 | size_t size; | 45 | size_t size; |
| 46 | std::string name; | 46 | std::string name; |
| 47 | VirtualDir parent; | ||
| 47 | }; | 48 | }; |
| 48 | 49 | ||
| 49 | } // namespace FileSys | 50 | } // namespace FileSys |
diff --git a/src/core/file_sys/vfs_real.cpp b/src/core/file_sys/vfs_real.cpp index 9ce2e1efa..82d54da4a 100644 --- a/src/core/file_sys/vfs_real.cpp +++ b/src/core/file_sys/vfs_real.cpp | |||
| @@ -195,6 +195,12 @@ bool RealVfsDirectory::Rename(std::string_view name) { | |||
| 195 | return FileUtil::Rename(path, new_name); | 195 | return FileUtil::Rename(path, new_name); |
| 196 | } | 196 | } |
| 197 | 197 | ||
| 198 | std::string RealVfsDirectory::GetFullPath() const { | ||
| 199 | auto out = path; | ||
| 200 | std::replace(out.begin(), out.end(), '\\', '/'); | ||
| 201 | return out; | ||
| 202 | } | ||
| 203 | |||
| 198 | bool RealVfsDirectory::ReplaceFileWithSubdirectory(VirtualFile file, VirtualDir dir) { | 204 | bool RealVfsDirectory::ReplaceFileWithSubdirectory(VirtualFile file, VirtualDir dir) { |
| 199 | const auto iter = std::find(files.begin(), files.end(), file); | 205 | const auto iter = std::find(files.begin(), files.end(), file); |
| 200 | if (iter == files.end()) | 206 | if (iter == files.end()) |
diff --git a/src/core/file_sys/vfs_real.h b/src/core/file_sys/vfs_real.h index 2151211c9..243d58576 100644 --- a/src/core/file_sys/vfs_real.h +++ b/src/core/file_sys/vfs_real.h | |||
| @@ -41,7 +41,7 @@ private: | |||
| 41 | 41 | ||
| 42 | // An implementation of VfsDirectory that represents a directory on the user's computer. | 42 | // An implementation of VfsDirectory that represents a directory on the user's computer. |
| 43 | struct RealVfsDirectory : public VfsDirectory { | 43 | struct RealVfsDirectory : public VfsDirectory { |
| 44 | RealVfsDirectory(const std::string& path, Mode perms); | 44 | RealVfsDirectory(const std::string& path, Mode perms = Mode::Read); |
| 45 | 45 | ||
| 46 | std::vector<std::shared_ptr<VfsFile>> GetFiles() const override; | 46 | std::vector<std::shared_ptr<VfsFile>> GetFiles() const override; |
| 47 | std::vector<std::shared_ptr<VfsDirectory>> GetSubdirectories() const override; | 47 | std::vector<std::shared_ptr<VfsDirectory>> GetSubdirectories() const override; |
| @@ -54,6 +54,7 @@ struct RealVfsDirectory : public VfsDirectory { | |||
| 54 | bool DeleteSubdirectory(std::string_view name) override; | 54 | bool DeleteSubdirectory(std::string_view name) override; |
| 55 | bool DeleteFile(std::string_view name) override; | 55 | bool DeleteFile(std::string_view name) override; |
| 56 | bool Rename(std::string_view name) override; | 56 | bool Rename(std::string_view name) override; |
| 57 | std::string GetFullPath() const override; | ||
| 57 | 58 | ||
| 58 | protected: | 59 | protected: |
| 59 | bool ReplaceFileWithSubdirectory(VirtualFile file, VirtualDir dir) override; | 60 | bool ReplaceFileWithSubdirectory(VirtualFile file, VirtualDir dir) override; |
diff --git a/src/core/file_sys/vfs_vector.cpp b/src/core/file_sys/vfs_vector.cpp new file mode 100644 index 000000000..4c6337e3a --- /dev/null +++ b/src/core/file_sys/vfs_vector.cpp | |||
| @@ -0,0 +1,83 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <algorithm> | ||
| 6 | #include "core/file_sys/vfs_vector.h" | ||
| 7 | |||
| 8 | namespace FileSys { | ||
| 9 | VectorVfsDirectory::VectorVfsDirectory(std::vector<VirtualFile> files_, | ||
| 10 | std::vector<VirtualDir> dirs_, VirtualDir parent_, | ||
| 11 | std::string name_) | ||
| 12 | : files(std::move(files_)), dirs(std::move(dirs_)), parent(std::move(parent_)), | ||
| 13 | name(std::move(name_)) {} | ||
| 14 | |||
| 15 | std::vector<std::shared_ptr<VfsFile>> VectorVfsDirectory::GetFiles() const { | ||
| 16 | return files; | ||
| 17 | } | ||
| 18 | |||
| 19 | std::vector<std::shared_ptr<VfsDirectory>> VectorVfsDirectory::GetSubdirectories() const { | ||
| 20 | return dirs; | ||
| 21 | } | ||
| 22 | |||
| 23 | bool VectorVfsDirectory::IsWritable() const { | ||
| 24 | return false; | ||
| 25 | } | ||
| 26 | |||
| 27 | bool VectorVfsDirectory::IsReadable() const { | ||
| 28 | return true; | ||
| 29 | } | ||
| 30 | |||
| 31 | std::string VectorVfsDirectory::GetName() const { | ||
| 32 | return name; | ||
| 33 | } | ||
| 34 | std::shared_ptr<VfsDirectory> VectorVfsDirectory::GetParentDirectory() const { | ||
| 35 | return parent; | ||
| 36 | } | ||
| 37 | |||
| 38 | template <typename T> | ||
| 39 | static bool FindAndRemoveVectorElement(std::vector<T>& vec, std::string_view name) { | ||
| 40 | auto iter = std::find_if(vec.begin(), vec.end(), [name](T e) { return e->GetName() == name; }); | ||
| 41 | if (iter == vec.end()) | ||
| 42 | return false; | ||
| 43 | auto old_size = vec.size(); | ||
| 44 | vec.erase(iter); | ||
| 45 | return true; | ||
| 46 | } | ||
| 47 | |||
| 48 | bool VectorVfsDirectory::DeleteSubdirectory(std::string_view name) { | ||
| 49 | return FindAndRemoveVectorElement(dirs, name); | ||
| 50 | } | ||
| 51 | |||
| 52 | bool VectorVfsDirectory::DeleteFile(std::string_view name) { | ||
| 53 | return FindAndRemoveVectorElement(files, name); | ||
| 54 | } | ||
| 55 | |||
| 56 | bool VectorVfsDirectory::Rename(std::string_view name_) { | ||
| 57 | name = name_; | ||
| 58 | return true; | ||
| 59 | } | ||
| 60 | |||
| 61 | std::shared_ptr<VfsDirectory> VectorVfsDirectory::CreateSubdirectory(std::string_view name) { | ||
| 62 | return nullptr; | ||
| 63 | } | ||
| 64 | |||
| 65 | std::shared_ptr<VfsFile> VectorVfsDirectory::CreateFile(std::string_view name) { | ||
| 66 | return nullptr; | ||
| 67 | } | ||
| 68 | |||
| 69 | void VectorVfsDirectory::AddFile(VirtualFile file) { | ||
| 70 | files.push_back(std::move(file)); | ||
| 71 | } | ||
| 72 | |||
| 73 | void VectorVfsDirectory::AddDirectory(VirtualDir dir) { | ||
| 74 | dirs.push_back(std::move(dir)); | ||
| 75 | } | ||
| 76 | |||
| 77 | bool VectorVfsDirectory::ReplaceFileWithSubdirectory(VirtualFile file, VirtualDir dir) { | ||
| 78 | if (!DeleteFile(file->GetName())) | ||
| 79 | return false; | ||
| 80 | dirs.emplace_back(dir); | ||
| 81 | return true; | ||
| 82 | } | ||
| 83 | } // namespace FileSys | ||
diff --git a/src/core/file_sys/vfs_vector.h b/src/core/file_sys/vfs_vector.h new file mode 100644 index 000000000..ba469647b --- /dev/null +++ b/src/core/file_sys/vfs_vector.h | |||
| @@ -0,0 +1,44 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include "core/file_sys/vfs.h" | ||
| 8 | |||
| 9 | namespace FileSys { | ||
| 10 | |||
| 11 | // An implementation of VfsDirectory that maintains two vectors for subdirectories and files. | ||
| 12 | // Vector data is supplied upon construction. | ||
| 13 | struct VectorVfsDirectory : public VfsDirectory { | ||
| 14 | explicit VectorVfsDirectory(std::vector<VirtualFile> files = {}, | ||
| 15 | std::vector<VirtualDir> dirs = {}, VirtualDir parent = nullptr, | ||
| 16 | std::string name = ""); | ||
| 17 | |||
| 18 | std::vector<std::shared_ptr<VfsFile>> GetFiles() const override; | ||
| 19 | std::vector<std::shared_ptr<VfsDirectory>> GetSubdirectories() const override; | ||
| 20 | bool IsWritable() const override; | ||
| 21 | bool IsReadable() const override; | ||
| 22 | std::string GetName() const override; | ||
| 23 | std::shared_ptr<VfsDirectory> GetParentDirectory() const override; | ||
| 24 | bool DeleteSubdirectory(std::string_view name) override; | ||
| 25 | bool DeleteFile(std::string_view name) override; | ||
| 26 | bool Rename(std::string_view name) override; | ||
| 27 | std::shared_ptr<VfsDirectory> CreateSubdirectory(std::string_view name) override; | ||
| 28 | std::shared_ptr<VfsFile> CreateFile(std::string_view name) override; | ||
| 29 | |||
| 30 | virtual void AddFile(VirtualFile file); | ||
| 31 | virtual void AddDirectory(VirtualDir dir); | ||
| 32 | |||
| 33 | protected: | ||
| 34 | bool ReplaceFileWithSubdirectory(VirtualFile file, VirtualDir dir) override; | ||
| 35 | |||
| 36 | private: | ||
| 37 | std::vector<VirtualFile> files; | ||
| 38 | std::vector<VirtualDir> dirs; | ||
| 39 | |||
| 40 | VirtualDir parent; | ||
| 41 | std::string name; | ||
| 42 | }; | ||
| 43 | |||
| 44 | } // namespace FileSys | ||
diff --git a/src/core/hle/service/audio/audout_u.cpp b/src/core/hle/service/audio/audout_u.cpp index 1dcd84d98..a15d53ff8 100644 --- a/src/core/hle/service/audio/audout_u.cpp +++ b/src/core/hle/service/audio/audout_u.cpp | |||
| @@ -5,8 +5,7 @@ | |||
| 5 | #include <array> | 5 | #include <array> |
| 6 | #include <vector> | 6 | #include <vector> |
| 7 | #include "common/logging/log.h" | 7 | #include "common/logging/log.h" |
| 8 | #include "core/core_timing.h" | 8 | #include "core/core.h" |
| 9 | #include "core/core_timing_util.h" | ||
| 10 | #include "core/hle/ipc_helpers.h" | 9 | #include "core/hle/ipc_helpers.h" |
| 11 | #include "core/hle/kernel/event.h" | 10 | #include "core/hle/kernel/event.h" |
| 12 | #include "core/hle/kernel/hle_ipc.h" | 11 | #include "core/hle/kernel/hle_ipc.h" |
| @@ -14,17 +13,22 @@ | |||
| 14 | 13 | ||
| 15 | namespace Service::Audio { | 14 | namespace Service::Audio { |
| 16 | 15 | ||
| 17 | /// Switch sample rate frequency | 16 | namespace ErrCodes { |
| 18 | constexpr u32 sample_rate{48000}; | 17 | enum { |
| 19 | /// TODO(st4rk): dynamic number of channels, as I think Switch has support | 18 | ErrorUnknown = 2, |
| 20 | /// to more audio channels (probably when Docked I guess) | 19 | BufferCountExceeded = 8, |
| 21 | constexpr u32 audio_channels{2}; | 20 | }; |
| 22 | /// TODO(st4rk): find a proper value for the audio_ticks | 21 | } |
| 23 | constexpr u64 audio_ticks{static_cast<u64>(CoreTiming::BASE_CLOCK_RATE / 500)}; | 22 | |
| 23 | constexpr std::array<char, 10> DefaultDevice{{"DeviceOut"}}; | ||
| 24 | constexpr int DefaultSampleRate{48000}; | ||
| 24 | 25 | ||
| 25 | class IAudioOut final : public ServiceFramework<IAudioOut> { | 26 | class IAudioOut final : public ServiceFramework<IAudioOut> { |
| 26 | public: | 27 | public: |
| 27 | IAudioOut() : ServiceFramework("IAudioOut"), audio_out_state(AudioState::Stopped) { | 28 | IAudioOut(AudoutParams audio_params) |
| 29 | : ServiceFramework("IAudioOut"), audio_params(audio_params), | ||
| 30 | audio_core(Core::System::GetInstance().AudioCore()) { | ||
| 31 | |||
| 28 | static const FunctionInfo functions[] = { | 32 | static const FunctionInfo functions[] = { |
| 29 | {0, &IAudioOut::GetAudioOutState, "GetAudioOutState"}, | 33 | {0, &IAudioOut::GetAudioOutState, "GetAudioOutState"}, |
| 30 | {1, &IAudioOut::StartAudioOut, "StartAudioOut"}, | 34 | {1, &IAudioOut::StartAudioOut, "StartAudioOut"}, |
| @@ -32,66 +36,65 @@ public: | |||
| 32 | {3, &IAudioOut::AppendAudioOutBufferImpl, "AppendAudioOutBuffer"}, | 36 | {3, &IAudioOut::AppendAudioOutBufferImpl, "AppendAudioOutBuffer"}, |
| 33 | {4, &IAudioOut::RegisterBufferEvent, "RegisterBufferEvent"}, | 37 | {4, &IAudioOut::RegisterBufferEvent, "RegisterBufferEvent"}, |
| 34 | {5, &IAudioOut::GetReleasedAudioOutBufferImpl, "GetReleasedAudioOutBuffer"}, | 38 | {5, &IAudioOut::GetReleasedAudioOutBufferImpl, "GetReleasedAudioOutBuffer"}, |
| 35 | {6, nullptr, "ContainsAudioOutBuffer"}, | 39 | {6, &IAudioOut::ContainsAudioOutBuffer, "ContainsAudioOutBuffer"}, |
| 36 | {7, &IAudioOut::AppendAudioOutBufferImpl, "AppendAudioOutBufferAuto"}, | 40 | {7, &IAudioOut::AppendAudioOutBufferImpl, "AppendAudioOutBufferAuto"}, |
| 37 | {8, &IAudioOut::GetReleasedAudioOutBufferImpl, "GetReleasedAudioOutBufferAuto"}, | 41 | {8, &IAudioOut::GetReleasedAudioOutBufferImpl, "GetReleasedAudioOutBufferAuto"}, |
| 38 | {9, nullptr, "GetAudioOutBufferCount"}, | 42 | {9, &IAudioOut::GetAudioOutBufferCount, "GetAudioOutBufferCount"}, |
| 39 | {10, nullptr, "GetAudioOutPlayedSampleCount"}, | 43 | {10, nullptr, "GetAudioOutPlayedSampleCount"}, |
| 40 | {11, nullptr, "FlushAudioOutBuffers"}, | 44 | {11, nullptr, "FlushAudioOutBuffers"}, |
| 41 | }; | 45 | }; |
| 42 | RegisterHandlers(functions); | 46 | RegisterHandlers(functions); |
| 43 | 47 | ||
| 44 | // This is the event handle used to check if the audio buffer was released | 48 | // This is the event handle used to check if the audio buffer was released |
| 45 | buffer_event = | 49 | buffer_event = Kernel::Event::Create(Kernel::ResetType::Sticky, "IAudioOutBufferReleased"); |
| 46 | Kernel::Event::Create(Kernel::ResetType::OneShot, "IAudioOutBufferReleasedEvent"); | ||
| 47 | |||
| 48 | // Register event callback to update the Audio Buffer | ||
| 49 | audio_event = CoreTiming::RegisterEvent( | ||
| 50 | "IAudioOut::UpdateAudioBuffersCallback", [this](u64 userdata, int cycles_late) { | ||
| 51 | UpdateAudioBuffersCallback(); | ||
| 52 | CoreTiming::ScheduleEvent(audio_ticks - cycles_late, audio_event); | ||
| 53 | }); | ||
| 54 | |||
| 55 | // Start the audio event | ||
| 56 | CoreTiming::ScheduleEvent(audio_ticks, audio_event); | ||
| 57 | } | ||
| 58 | 50 | ||
| 59 | ~IAudioOut() { | 51 | stream = audio_core.OpenStream(audio_params.sample_rate, audio_params.channel_count, |
| 60 | CoreTiming::UnscheduleEvent(audio_event, 0); | 52 | [=]() { buffer_event->Signal(); }); |
| 61 | } | 53 | } |
| 62 | 54 | ||
| 63 | private: | 55 | private: |
| 56 | struct AudioBuffer { | ||
| 57 | u64_le next; | ||
| 58 | u64_le buffer; | ||
| 59 | u64_le buffer_capacity; | ||
| 60 | u64_le buffer_size; | ||
| 61 | u64_le offset; | ||
| 62 | }; | ||
| 63 | static_assert(sizeof(AudioBuffer) == 0x28, "AudioBuffer is an invalid size"); | ||
| 64 | |||
| 64 | void GetAudioOutState(Kernel::HLERequestContext& ctx) { | 65 | void GetAudioOutState(Kernel::HLERequestContext& ctx) { |
| 65 | LOG_DEBUG(Service_Audio, "called"); | 66 | LOG_DEBUG(Service_Audio, "called"); |
| 66 | IPC::ResponseBuilder rb{ctx, 3}; | 67 | IPC::ResponseBuilder rb{ctx, 3}; |
| 67 | rb.Push(RESULT_SUCCESS); | 68 | rb.Push(RESULT_SUCCESS); |
| 68 | rb.Push(static_cast<u32>(audio_out_state)); | 69 | rb.Push(static_cast<u32>(stream->IsPlaying() ? AudioState::Started : AudioState::Stopped)); |
| 69 | } | 70 | } |
| 70 | 71 | ||
| 71 | void StartAudioOut(Kernel::HLERequestContext& ctx) { | 72 | void StartAudioOut(Kernel::HLERequestContext& ctx) { |
| 72 | LOG_WARNING(Service_Audio, "(STUBBED) called"); | 73 | LOG_DEBUG(Service_Audio, "called"); |
| 74 | |||
| 75 | if (stream->IsPlaying()) { | ||
| 76 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 77 | rb.Push(ResultCode(ErrorModule::Audio, ErrCodes::ErrorUnknown)); | ||
| 78 | return; | ||
| 79 | } | ||
| 73 | 80 | ||
| 74 | // Start audio | 81 | audio_core.StartStream(stream); |
| 75 | audio_out_state = AudioState::Started; | ||
| 76 | 82 | ||
| 77 | IPC::ResponseBuilder rb{ctx, 2}; | 83 | IPC::ResponseBuilder rb{ctx, 2}; |
| 78 | rb.Push(RESULT_SUCCESS); | 84 | rb.Push(RESULT_SUCCESS); |
| 79 | } | 85 | } |
| 80 | 86 | ||
| 81 | void StopAudioOut(Kernel::HLERequestContext& ctx) { | 87 | void StopAudioOut(Kernel::HLERequestContext& ctx) { |
| 82 | LOG_WARNING(Service_Audio, "(STUBBED) called"); | 88 | LOG_DEBUG(Service_Audio, "called"); |
| 83 | |||
| 84 | // Stop audio | ||
| 85 | audio_out_state = AudioState::Stopped; | ||
| 86 | 89 | ||
| 87 | queue_keys.clear(); | 90 | audio_core.StopStream(stream); |
| 88 | 91 | ||
| 89 | IPC::ResponseBuilder rb{ctx, 2}; | 92 | IPC::ResponseBuilder rb{ctx, 2}; |
| 90 | rb.Push(RESULT_SUCCESS); | 93 | rb.Push(RESULT_SUCCESS); |
| 91 | } | 94 | } |
| 92 | 95 | ||
| 93 | void RegisterBufferEvent(Kernel::HLERequestContext& ctx) { | 96 | void RegisterBufferEvent(Kernel::HLERequestContext& ctx) { |
| 94 | LOG_WARNING(Service_Audio, "(STUBBED) called"); | 97 | LOG_DEBUG(Service_Audio, "called"); |
| 95 | 98 | ||
| 96 | IPC::ResponseBuilder rb{ctx, 2, 1}; | 99 | IPC::ResponseBuilder rb{ctx, 2, 1}; |
| 97 | rb.Push(RESULT_SUCCESS); | 100 | rb.Push(RESULT_SUCCESS); |
| @@ -99,101 +102,107 @@ private: | |||
| 99 | } | 102 | } |
| 100 | 103 | ||
| 101 | void AppendAudioOutBufferImpl(Kernel::HLERequestContext& ctx) { | 104 | void AppendAudioOutBufferImpl(Kernel::HLERequestContext& ctx) { |
| 102 | LOG_WARNING(Service_Audio, "(STUBBED) called"); | 105 | LOG_DEBUG(Service_Audio, "(STUBBED) called {}", ctx.Description()); |
| 103 | IPC::RequestParser rp{ctx}; | 106 | IPC::RequestParser rp{ctx}; |
| 104 | 107 | ||
| 105 | const u64 key{rp.Pop<u64>()}; | 108 | const auto& input_buffer{ctx.ReadBuffer()}; |
| 106 | queue_keys.insert(queue_keys.begin(), key); | 109 | ASSERT_MSG(input_buffer.size() == sizeof(AudioBuffer), |
| 110 | "AudioBuffer input is an invalid size!"); | ||
| 111 | AudioBuffer audio_buffer{}; | ||
| 112 | std::memcpy(&audio_buffer, input_buffer.data(), sizeof(AudioBuffer)); | ||
| 113 | const u64 tag{rp.Pop<u64>()}; | ||
| 114 | |||
| 115 | std::vector<u8> data(audio_buffer.buffer_size); | ||
| 116 | Memory::ReadBlock(audio_buffer.buffer, data.data(), data.size()); | ||
| 117 | |||
| 118 | if (!audio_core.QueueBuffer(stream, tag, std::move(data))) { | ||
| 119 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 120 | rb.Push(ResultCode(ErrorModule::Audio, ErrCodes::BufferCountExceeded)); | ||
| 121 | } | ||
| 107 | 122 | ||
| 108 | IPC::ResponseBuilder rb{ctx, 2}; | 123 | IPC::ResponseBuilder rb{ctx, 2}; |
| 109 | rb.Push(RESULT_SUCCESS); | 124 | rb.Push(RESULT_SUCCESS); |
| 110 | } | 125 | } |
| 111 | 126 | ||
| 112 | void GetReleasedAudioOutBufferImpl(Kernel::HLERequestContext& ctx) { | 127 | void GetReleasedAudioOutBufferImpl(Kernel::HLERequestContext& ctx) { |
| 113 | LOG_WARNING(Service_Audio, "(STUBBED) called"); | 128 | LOG_DEBUG(Service_Audio, "called {}", ctx.Description()); |
| 114 | 129 | IPC::RequestParser rp{ctx}; | |
| 115 | // TODO(st4rk): This is how libtransistor currently implements the | 130 | const u64 max_count{ctx.GetWriteBufferSize() / sizeof(u64)}; |
| 116 | // GetReleasedAudioOutBuffer, it should return the key (a VAddr) to the app and this address | 131 | const auto released_buffers{audio_core.GetTagsAndReleaseBuffers(stream, max_count)}; |
| 117 | // is used to know which buffer should be filled with data and send again to the service | ||
| 118 | // through AppendAudioOutBuffer. Check if this is the proper way to do it. | ||
| 119 | u64 key{0}; | ||
| 120 | |||
| 121 | if (queue_keys.size()) { | ||
| 122 | key = queue_keys.back(); | ||
| 123 | queue_keys.pop_back(); | ||
| 124 | } | ||
| 125 | 132 | ||
| 126 | ctx.WriteBuffer(&key, sizeof(u64)); | 133 | std::vector<u64> tags{released_buffers}; |
| 134 | tags.resize(max_count); | ||
| 135 | ctx.WriteBuffer(tags); | ||
| 127 | 136 | ||
| 128 | IPC::ResponseBuilder rb{ctx, 3}; | 137 | IPC::ResponseBuilder rb{ctx, 3}; |
| 129 | rb.Push(RESULT_SUCCESS); | 138 | rb.Push(RESULT_SUCCESS); |
| 130 | // TODO(st4rk): This might be the total of released buffers, needs to be verified on | 139 | rb.Push<u32>(static_cast<u32>(released_buffers.size())); |
| 131 | // hardware | ||
| 132 | rb.Push<u32>(static_cast<u32>(queue_keys.size())); | ||
| 133 | } | 140 | } |
| 134 | 141 | ||
| 135 | void UpdateAudioBuffersCallback() { | 142 | void ContainsAudioOutBuffer(Kernel::HLERequestContext& ctx) { |
| 136 | if (audio_out_state != AudioState::Started) { | 143 | LOG_DEBUG(Service_Audio, "called"); |
| 137 | return; | 144 | IPC::RequestParser rp{ctx}; |
| 138 | } | 145 | const u64 tag{rp.Pop<u64>()}; |
| 139 | 146 | IPC::ResponseBuilder rb{ctx, 3}; | |
| 140 | if (queue_keys.empty()) { | 147 | rb.Push(RESULT_SUCCESS); |
| 141 | return; | 148 | rb.Push(stream->ContainsBuffer(tag)); |
| 142 | } | 149 | } |
| 143 | 150 | ||
| 144 | buffer_event->Signal(); | 151 | void GetAudioOutBufferCount(Kernel::HLERequestContext& ctx) { |
| 152 | LOG_DEBUG(Service_Audio, "called"); | ||
| 153 | IPC::ResponseBuilder rb{ctx, 3}; | ||
| 154 | rb.Push(RESULT_SUCCESS); | ||
| 155 | rb.Push(static_cast<u32>(stream->GetQueueSize())); | ||
| 145 | } | 156 | } |
| 146 | 157 | ||
| 147 | enum class AudioState : u32 { | 158 | AudioCore::AudioOut& audio_core; |
| 148 | Started, | 159 | AudioCore::StreamPtr stream; |
| 149 | Stopped, | ||
| 150 | }; | ||
| 151 | 160 | ||
| 152 | /// This is used to trigger the audio event callback that is going to read the samples from the | 161 | AudoutParams audio_params{}; |
| 153 | /// audio_buffer list and enqueue the samples using the sink (audio_core). | ||
| 154 | CoreTiming::EventType* audio_event; | ||
| 155 | 162 | ||
| 156 | /// This is the evend handle used to check if the audio buffer was released | 163 | /// This is the evend handle used to check if the audio buffer was released |
| 157 | Kernel::SharedPtr<Kernel::Event> buffer_event; | 164 | Kernel::SharedPtr<Kernel::Event> buffer_event; |
| 158 | |||
| 159 | /// (st4rk): This is just a temporary workaround for the future implementation. Libtransistor | ||
| 160 | /// uses the key as an address in the App, so we need to return when the | ||
| 161 | /// GetReleasedAudioOutBuffer_1 is called, otherwise we'll run in problems, because | ||
| 162 | /// libtransistor uses the key returned as an pointer. | ||
| 163 | std::vector<u64> queue_keys; | ||
| 164 | |||
| 165 | AudioState audio_out_state; | ||
| 166 | }; | 165 | }; |
| 167 | 166 | ||
| 168 | void AudOutU::ListAudioOutsImpl(Kernel::HLERequestContext& ctx) { | 167 | void AudOutU::ListAudioOutsImpl(Kernel::HLERequestContext& ctx) { |
| 169 | LOG_WARNING(Service_Audio, "(STUBBED) called"); | 168 | LOG_DEBUG(Service_Audio, "called"); |
| 170 | IPC::RequestParser rp{ctx}; | 169 | IPC::RequestParser rp{ctx}; |
| 171 | 170 | ||
| 172 | constexpr std::array<char, 15> audio_interface{{"AudioInterface"}}; | 171 | ctx.WriteBuffer(DefaultDevice); |
| 173 | ctx.WriteBuffer(audio_interface); | ||
| 174 | 172 | ||
| 175 | IPC::ResponseBuilder rb = rp.MakeBuilder(3, 0, 0); | 173 | IPC::ResponseBuilder rb = rp.MakeBuilder(3, 0, 0); |
| 176 | 174 | ||
| 177 | rb.Push(RESULT_SUCCESS); | 175 | rb.Push(RESULT_SUCCESS); |
| 178 | // TODO(st4rk): We're currently returning only one audio interface (stringlist size). However, | 176 | rb.Push<u32>(1); // Amount of audio devices |
| 179 | // it's highly possible to have more than one interface (despite that libtransistor requires | ||
| 180 | // only one). | ||
| 181 | rb.Push<u32>(1); | ||
| 182 | } | 177 | } |
| 183 | 178 | ||
| 184 | void AudOutU::OpenAudioOutImpl(Kernel::HLERequestContext& ctx) { | 179 | void AudOutU::OpenAudioOutImpl(Kernel::HLERequestContext& ctx) { |
| 185 | LOG_WARNING(Service_Audio, "(STUBBED) called"); | 180 | LOG_DEBUG(Service_Audio, "called"); |
| 186 | 181 | ||
| 187 | if (!audio_out_interface) { | 182 | ctx.WriteBuffer(DefaultDevice); |
| 188 | audio_out_interface = std::make_shared<IAudioOut>(); | 183 | IPC::RequestParser rp{ctx}; |
| 184 | auto params{rp.PopRaw<AudoutParams>()}; | ||
| 185 | if (params.channel_count <= 2) { | ||
| 186 | // Mono does not exist for audout | ||
| 187 | params.channel_count = 2; | ||
| 188 | } else { | ||
| 189 | params.channel_count = 6; | ||
| 189 | } | 190 | } |
| 191 | if (!params.sample_rate) { | ||
| 192 | params.sample_rate = DefaultSampleRate; | ||
| 193 | } | ||
| 194 | |||
| 195 | // TODO(bunnei): Support more than one IAudioOut interface. When we add this, ListAudioOutsImpl | ||
| 196 | // will likely need to be updated as well. | ||
| 197 | ASSERT_MSG(!audio_out_interface, "Unimplemented"); | ||
| 198 | audio_out_interface = std::make_shared<IAudioOut>(std::move(params)); | ||
| 190 | 199 | ||
| 191 | IPC::ResponseBuilder rb{ctx, 6, 0, 1}; | 200 | IPC::ResponseBuilder rb{ctx, 6, 0, 1}; |
| 192 | rb.Push(RESULT_SUCCESS); | 201 | rb.Push(RESULT_SUCCESS); |
| 193 | rb.Push<u32>(sample_rate); | 202 | rb.Push<u32>(DefaultSampleRate); |
| 194 | rb.Push<u32>(audio_channels); | 203 | rb.Push<u32>(params.channel_count); |
| 195 | rb.Push<u32>(static_cast<u32>(PcmFormat::Int16)); | 204 | rb.Push<u32>(static_cast<u32>(PcmFormat::Int16)); |
| 196 | rb.Push<u32>(0); // This field is unknown | 205 | rb.Push<u32>(static_cast<u32>(AudioState::Stopped)); |
| 197 | rb.PushIpcInterface<Audio::IAudioOut>(audio_out_interface); | 206 | rb.PushIpcInterface<Audio::IAudioOut>(audio_out_interface); |
| 198 | } | 207 | } |
| 199 | 208 | ||
diff --git a/src/core/hle/service/audio/audout_u.h b/src/core/hle/service/audio/audout_u.h index 847d86aa6..bc43f1f44 100644 --- a/src/core/hle/service/audio/audout_u.h +++ b/src/core/hle/service/audio/audout_u.h | |||
| @@ -12,6 +12,18 @@ class HLERequestContext; | |||
| 12 | 12 | ||
| 13 | namespace Service::Audio { | 13 | namespace Service::Audio { |
| 14 | 14 | ||
| 15 | struct AudoutParams { | ||
| 16 | s32_le sample_rate; | ||
| 17 | u16_le channel_count; | ||
| 18 | INSERT_PADDING_BYTES(2); | ||
| 19 | }; | ||
| 20 | static_assert(sizeof(AudoutParams) == 0x8, "AudoutParams is an invalid size"); | ||
| 21 | |||
| 22 | enum class AudioState : u32 { | ||
| 23 | Started, | ||
| 24 | Stopped, | ||
| 25 | }; | ||
| 26 | |||
| 15 | class IAudioOut; | 27 | class IAudioOut; |
| 16 | 28 | ||
| 17 | class AudOutU final : public ServiceFramework<AudOutU> { | 29 | class AudOutU final : public ServiceFramework<AudOutU> { |
diff --git a/src/core/hle/service/mii/mii.cpp b/src/core/hle/service/mii/mii.cpp new file mode 100644 index 000000000..a6197124a --- /dev/null +++ b/src/core/hle/service/mii/mii.cpp | |||
| @@ -0,0 +1,107 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <memory> | ||
| 6 | |||
| 7 | #include "common/logging/log.h" | ||
| 8 | #include "core/hle/ipc_helpers.h" | ||
| 9 | #include "core/hle/kernel/hle_ipc.h" | ||
| 10 | #include "core/hle/service/mii/mii.h" | ||
| 11 | #include "core/hle/service/service.h" | ||
| 12 | #include "core/hle/service/sm/sm.h" | ||
| 13 | |||
| 14 | namespace Service::Mii { | ||
| 15 | |||
| 16 | class IDatabaseService final : public ServiceFramework<IDatabaseService> { | ||
| 17 | public: | ||
| 18 | explicit IDatabaseService() : ServiceFramework{"IDatabaseService"} { | ||
| 19 | // clang-format off | ||
| 20 | static const FunctionInfo functions[] = { | ||
| 21 | {0, nullptr, "IsUpdated"}, | ||
| 22 | {1, nullptr, "IsFullDatabase"}, | ||
| 23 | {2, nullptr, "GetCount"}, | ||
| 24 | {3, nullptr, "Get"}, | ||
| 25 | {4, nullptr, "Get1"}, | ||
| 26 | {5, nullptr, "UpdateLatest"}, | ||
| 27 | {6, nullptr, "BuildRandom"}, | ||
| 28 | {7, nullptr, "BuildDefault"}, | ||
| 29 | {8, nullptr, "Get2"}, | ||
| 30 | {9, nullptr, "Get3"}, | ||
| 31 | {10, nullptr, "UpdateLatest1"}, | ||
| 32 | {11, nullptr, "FindIndex"}, | ||
| 33 | {12, nullptr, "Move"}, | ||
| 34 | {13, nullptr, "AddOrReplace"}, | ||
| 35 | {14, nullptr, "Delete"}, | ||
| 36 | {15, nullptr, "DestroyFile"}, | ||
| 37 | {16, nullptr, "DeleteFile"}, | ||
| 38 | {17, nullptr, "Format"}, | ||
| 39 | {18, nullptr, "Import"}, | ||
| 40 | {19, nullptr, "Export"}, | ||
| 41 | {20, nullptr, "IsBrokenDatabaseWithClearFlag"}, | ||
| 42 | {21, nullptr, "GetIndex"}, | ||
| 43 | {22, nullptr, "SetInterfaceVersion"}, | ||
| 44 | {23, nullptr, "Convert"}, | ||
| 45 | }; | ||
| 46 | // clang-format on | ||
| 47 | |||
| 48 | RegisterHandlers(functions); | ||
| 49 | } | ||
| 50 | }; | ||
| 51 | |||
| 52 | class MiiDBModule final : public ServiceFramework<MiiDBModule> { | ||
| 53 | public: | ||
| 54 | explicit MiiDBModule(const char* name) : ServiceFramework{name} { | ||
| 55 | // clang-format off | ||
| 56 | static const FunctionInfo functions[] = { | ||
| 57 | {0, &MiiDBModule::GetDatabaseService, "GetDatabaseService"}, | ||
| 58 | }; | ||
| 59 | // clang-format on | ||
| 60 | |||
| 61 | RegisterHandlers(functions); | ||
| 62 | } | ||
| 63 | |||
| 64 | private: | ||
| 65 | void GetDatabaseService(Kernel::HLERequestContext& ctx) { | ||
| 66 | IPC::ResponseBuilder rb{ctx, 2, 0, 1}; | ||
| 67 | rb.Push(RESULT_SUCCESS); | ||
| 68 | rb.PushIpcInterface<IDatabaseService>(); | ||
| 69 | |||
| 70 | LOG_DEBUG(Service_Mii, "called"); | ||
| 71 | } | ||
| 72 | }; | ||
| 73 | |||
| 74 | class MiiImg final : public ServiceFramework<MiiImg> { | ||
| 75 | public: | ||
| 76 | explicit MiiImg() : ServiceFramework{"miiimg"} { | ||
| 77 | // clang-format off | ||
| 78 | static const FunctionInfo functions[] = { | ||
| 79 | {0, nullptr, "Initialize"}, | ||
| 80 | {10, nullptr, "Reload"}, | ||
| 81 | {11, nullptr, "GetCount"}, | ||
| 82 | {12, nullptr, "IsEmpty"}, | ||
| 83 | {13, nullptr, "IsFull"}, | ||
| 84 | {14, nullptr, "GetAttribute"}, | ||
| 85 | {15, nullptr, "LoadImage"}, | ||
| 86 | {16, nullptr, "AddOrUpdateImage"}, | ||
| 87 | {17, nullptr, "DeleteImages"}, | ||
| 88 | {100, nullptr, "DeleteFile"}, | ||
| 89 | {101, nullptr, "DestroyFile"}, | ||
| 90 | {102, nullptr, "ImportFile"}, | ||
| 91 | {103, nullptr, "ExportFile"}, | ||
| 92 | {104, nullptr, "ForceInitialize"}, | ||
| 93 | }; | ||
| 94 | // clang-format on | ||
| 95 | |||
| 96 | RegisterHandlers(functions); | ||
| 97 | } | ||
| 98 | }; | ||
| 99 | |||
| 100 | void InstallInterfaces(SM::ServiceManager& sm) { | ||
| 101 | std::make_shared<MiiDBModule>("mii:e")->InstallAsService(sm); | ||
| 102 | std::make_shared<MiiDBModule>("mii:u")->InstallAsService(sm); | ||
| 103 | |||
| 104 | std::make_shared<MiiImg>()->InstallAsService(sm); | ||
| 105 | } | ||
| 106 | |||
| 107 | } // namespace Service::Mii | ||
diff --git a/src/core/hle/service/mii/mii.h b/src/core/hle/service/mii/mii.h new file mode 100644 index 000000000..7ce9be50e --- /dev/null +++ b/src/core/hle/service/mii/mii.h | |||
| @@ -0,0 +1,15 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | namespace Service::SM { | ||
| 8 | class ServiceManager; | ||
| 9 | } | ||
| 10 | |||
| 11 | namespace Service::Mii { | ||
| 12 | |||
| 13 | void InstallInterfaces(SM::ServiceManager& sm); | ||
| 14 | |||
| 15 | } // namespace Service::Mii | ||
diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp index de3723980..5180a0c93 100644 --- a/src/core/hle/service/service.cpp +++ b/src/core/hle/service/service.cpp | |||
| @@ -34,6 +34,7 @@ | |||
| 34 | #include "core/hle/service/ldn/ldn.h" | 34 | #include "core/hle/service/ldn/ldn.h" |
| 35 | #include "core/hle/service/ldr/ldr.h" | 35 | #include "core/hle/service/ldr/ldr.h" |
| 36 | #include "core/hle/service/lm/lm.h" | 36 | #include "core/hle/service/lm/lm.h" |
| 37 | #include "core/hle/service/mii/mii.h" | ||
| 37 | #include "core/hle/service/mm/mm_u.h" | 38 | #include "core/hle/service/mm/mm_u.h" |
| 38 | #include "core/hle/service/ncm/ncm.h" | 39 | #include "core/hle/service/ncm/ncm.h" |
| 39 | #include "core/hle/service/nfc/nfc.h" | 40 | #include "core/hle/service/nfc/nfc.h" |
| @@ -212,6 +213,7 @@ void Init(std::shared_ptr<SM::ServiceManager>& sm) { | |||
| 212 | LDN::InstallInterfaces(*sm); | 213 | LDN::InstallInterfaces(*sm); |
| 213 | LDR::InstallInterfaces(*sm); | 214 | LDR::InstallInterfaces(*sm); |
| 214 | LM::InstallInterfaces(*sm); | 215 | LM::InstallInterfaces(*sm); |
| 216 | Mii::InstallInterfaces(*sm); | ||
| 215 | MM::InstallInterfaces(*sm); | 217 | MM::InstallInterfaces(*sm); |
| 216 | NCM::InstallInterfaces(*sm); | 218 | NCM::InstallInterfaces(*sm); |
| 217 | NFC::InstallInterfaces(*sm); | 219 | NFC::InstallInterfaces(*sm); |