audin_u.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // Copyright 2018 yuzu emulator team
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include "common/logging/log.h"
  5. #include "core/hle/ipc_helpers.h"
  6. #include "core/hle/kernel/hle_ipc.h"
  7. #include "core/hle/service/audio/audin_u.h"
  8. namespace Service::Audio {
  9. class IAudioIn final : public ServiceFramework<IAudioIn> {
  10. public:
  11. IAudioIn() : ServiceFramework("IAudioIn") {
  12. // clang-format off
  13. static const FunctionInfo functions[] = {
  14. {0, nullptr, "GetAudioInState"},
  15. {1, nullptr, "StartAudioIn"},
  16. {2, nullptr, "StopAudioIn"},
  17. {3, nullptr, "AppendAudioInBuffer"},
  18. {4, nullptr, "RegisterBufferEvent"},
  19. {5, nullptr, "GetReleasedAudioInBuffer"},
  20. {6, nullptr, "ContainsAudioInBuffer"},
  21. {7, nullptr, "AppendAudioInBufferWithUserEvent"},
  22. {8, nullptr, "AppendAudioInBufferAuto"},
  23. {9, nullptr, "GetReleasedAudioInBufferAuto"},
  24. {10, nullptr, "AppendAudioInBufferWithUserEventAuto"},
  25. {11, nullptr, "GetAudioInBufferCount"},
  26. {12, nullptr, "SetAudioInDeviceGain"},
  27. {13, nullptr, "GetAudioInDeviceGain"},
  28. {14, nullptr, "FlushAudioInBuffers"},
  29. };
  30. // clang-format on
  31. RegisterHandlers(functions);
  32. }
  33. };
  34. AudInU::AudInU() : ServiceFramework("audin:u") {
  35. // clang-format off
  36. static const FunctionInfo functions[] = {
  37. {0, &AudInU::ListAudioIns, "ListAudioIns"},
  38. {1, &AudInU::OpenAudioIn, "OpenAudioIn"},
  39. {2, &AudInU::ListAudioIns, "ListAudioInsAuto"},
  40. {3, &AudInU::OpenAudioIn, "OpenAudioInAuto"},
  41. {4, &AudInU::ListAudioInsAutoFiltered, "ListAudioInsAutoFiltered"},
  42. {5, &AudInU::OpenAudioInProtocolSpecified, "OpenAudioInProtocolSpecified"},
  43. };
  44. // clang-format on
  45. RegisterHandlers(functions);
  46. }
  47. AudInU::~AudInU() = default;
  48. void AudInU::ListAudioIns(Kernel::HLERequestContext& ctx) {
  49. LOG_DEBUG(Service_Audio, "called");
  50. const std::size_t count = ctx.GetWriteBufferSize() / sizeof(AudioInDeviceName);
  51. const std::size_t device_count = std::min(count, audio_device_names.size());
  52. std::vector<AudioInDeviceName> device_names;
  53. device_names.reserve(device_count);
  54. for (std::size_t i = 0; i < device_count; i++) {
  55. const auto& device_name = audio_device_names[i];
  56. auto& entry = device_names.emplace_back();
  57. device_name.copy(entry.data(), device_name.size());
  58. }
  59. ctx.WriteBuffer(device_names);
  60. IPC::ResponseBuilder rb{ctx, 3};
  61. rb.Push(RESULT_SUCCESS);
  62. rb.Push(static_cast<u32>(device_names.size()));
  63. }
  64. void AudInU::ListAudioInsAutoFiltered(Kernel::HLERequestContext& ctx) {
  65. LOG_DEBUG(Service_Audio, "called");
  66. constexpr u32 device_count = 0;
  67. // Since we don't actually use any other audio input devices, we return 0 devices. Filtered
  68. // device listing just omits the default input device
  69. IPC::ResponseBuilder rb{ctx, 3};
  70. rb.Push(RESULT_SUCCESS);
  71. rb.Push(static_cast<u32>(device_count));
  72. }
  73. void AudInU::OpenInOutImpl(Kernel::HLERequestContext& ctx) {
  74. AudInOutParams params{};
  75. params.channel_count = 2;
  76. params.sample_format = SampleFormat::PCM16;
  77. params.sample_rate = 48000;
  78. params.state = State::Started;
  79. IPC::ResponseBuilder rb{ctx, 6, 0, 1};
  80. rb.Push(RESULT_SUCCESS);
  81. rb.PushRaw<AudInOutParams>(params);
  82. rb.PushIpcInterface<IAudioIn>();
  83. }
  84. void AudInU::OpenAudioIn(Kernel::HLERequestContext& ctx) {
  85. LOG_WARNING(Service_Audio, "(STUBBED) called");
  86. OpenInOutImpl(ctx);
  87. }
  88. void AudInU::OpenAudioInProtocolSpecified(Kernel::HLERequestContext& ctx) {
  89. LOG_WARNING(Service_Audio, "(STUBBED) called");
  90. OpenInOutImpl(ctx);
  91. }
  92. } // namespace Service::Audio