service/audren_u: Report proper device names

AudioDevice and AudioInterface aren't valid device names on the Switch.
We should also be returning consistent names in
GetActiveAudioDeviceName().

While we're at it, we can also handle proper name output in
ListAudioDeviceName, by returning all the available devices on the
Switch.
This commit is contained in:
Lioncash 2019-07-19 00:13:57 -04:00
parent 5d369112d9
commit 6ecbc6c557

View file

@ -5,6 +5,7 @@
#include <algorithm> #include <algorithm>
#include <array> #include <array>
#include <memory> #include <memory>
#include <string_view>
#include "audio_core/audio_renderer.h" #include "audio_core/audio_renderer.h"
#include "common/alignment.h" #include "common/alignment.h"
@ -160,7 +161,7 @@ private:
class IAudioDevice final : public ServiceFramework<IAudioDevice> { class IAudioDevice final : public ServiceFramework<IAudioDevice> {
public: public:
IAudioDevice() : ServiceFramework("IAudioDevice") { explicit IAudioDevice() : ServiceFramework("IAudioDevice") {
static const FunctionInfo functions[] = { static const FunctionInfo functions[] = {
{0, &IAudioDevice::ListAudioDeviceName, "ListAudioDeviceName"}, {0, &IAudioDevice::ListAudioDeviceName, "ListAudioDeviceName"},
{1, &IAudioDevice::SetAudioDeviceOutputVolume, "SetAudioDeviceOutputVolume"}, {1, &IAudioDevice::SetAudioDeviceOutputVolume, "SetAudioDeviceOutputVolume"},
@ -189,15 +190,32 @@ public:
} }
private: private:
using AudioDeviceName = std::array<char, 256>;
static constexpr std::array<std::string_view, 4> audio_device_names{{
"AudioStereoJackOutput",
"AudioBuiltInSpeakerOutput",
"AudioTvOutput",
"AudioUsbDeviceOutput",
}};
void ListAudioDeviceName(Kernel::HLERequestContext& ctx) { void ListAudioDeviceName(Kernel::HLERequestContext& ctx) {
LOG_WARNING(Service_Audio, "(STUBBED) called"); LOG_WARNING(Service_Audio, "(STUBBED) called");
constexpr std::array<char, 15> audio_interface{{"AudioInterface"}}; const std::size_t num_names_requested = ctx.GetWriteBufferSize() / sizeof(AudioDeviceName);
ctx.WriteBuffer(audio_interface); const std::size_t num_to_copy = std::min(num_names_requested, audio_device_names.size());
std::vector<AudioDeviceName> name_buffer(num_to_copy);
for (std::size_t i = 0; i < num_to_copy; i++) {
const auto& device_name = audio_device_names[i];
device_name.copy(name_buffer[i].data(), device_name.size());
}
ctx.WriteBuffer(name_buffer);
IPC::ResponseBuilder rb{ctx, 3}; IPC::ResponseBuilder rb{ctx, 3};
rb.Push(RESULT_SUCCESS); rb.Push(RESULT_SUCCESS);
rb.Push<u32>(1); rb.Push(static_cast<u32>(num_to_copy));
} }
void SetAudioDeviceOutputVolume(Kernel::HLERequestContext& ctx) { void SetAudioDeviceOutputVolume(Kernel::HLERequestContext& ctx) {
@ -216,8 +234,13 @@ private:
void GetActiveAudioDeviceName(Kernel::HLERequestContext& ctx) { void GetActiveAudioDeviceName(Kernel::HLERequestContext& ctx) {
LOG_WARNING(Service_Audio, "(STUBBED) called"); LOG_WARNING(Service_Audio, "(STUBBED) called");
constexpr std::array<char, 12> audio_interface{{"AudioDevice"}}; // Currently set to always be TV audio output.
ctx.WriteBuffer(audio_interface); const auto& device_name = audio_device_names[2];
AudioDeviceName out_device_name{};
device_name.copy(out_device_name.data(), device_name.size());
ctx.WriteBuffer(out_device_name);
IPC::ResponseBuilder rb{ctx, 3}; IPC::ResponseBuilder rb{ctx, 3};
rb.Push(RESULT_SUCCESS); rb.Push(RESULT_SUCCESS);