summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/hle/service/audio/hwopus.cpp49
-rw-r--r--src/core/hle/service/audio/hwopus.h5
2 files changed, 51 insertions, 3 deletions
diff --git a/src/core/hle/service/audio/hwopus.cpp b/src/core/hle/service/audio/hwopus.cpp
index fa77007f3..4a8276ed1 100644
--- a/src/core/hle/service/audio/hwopus.cpp
+++ b/src/core/hle/service/audio/hwopus.cpp
@@ -174,7 +174,7 @@ public:
174 {6, &IHardwareOpusDecoderManager::DecodeInterleaved, "DecodeInterleavedWithPerfAndResetOld"}, 174 {6, &IHardwareOpusDecoderManager::DecodeInterleaved, "DecodeInterleavedWithPerfAndResetOld"},
175 {7, nullptr, "DecodeInterleavedForMultiStreamWithPerfAndResetOld"}, 175 {7, nullptr, "DecodeInterleavedForMultiStreamWithPerfAndResetOld"},
176 {8, &IHardwareOpusDecoderManager::DecodeInterleaved, "DecodeInterleaved"}, 176 {8, &IHardwareOpusDecoderManager::DecodeInterleaved, "DecodeInterleaved"},
177 {9, nullptr, "DecodeInterleavedForMultiStream"}, 177 {9, &IHardwareOpusDecoderManager::DecodeInterleavedForMultiStream, "DecodeInterleavedForMultiStream"},
178 }; 178 };
179 // clang-format on 179 // clang-format on
180 180
@@ -206,6 +206,16 @@ private:
206 decoder_state.DecodeInterleaved(ctx, OpusDecoderState::PerfTime::Enabled, extra_behavior); 206 decoder_state.DecodeInterleaved(ctx, OpusDecoderState::PerfTime::Enabled, extra_behavior);
207 } 207 }
208 208
209 void DecodeInterleavedForMultiStream(HLERequestContext& ctx) {
210 LOG_DEBUG(Audio, "called");
211
212 IPC::RequestParser rp{ctx};
213 const auto extra_behavior = rp.Pop<bool>() ? OpusDecoderState::ExtraBehavior::ResetContext
214 : OpusDecoderState::ExtraBehavior::None;
215
216 decoder_state.DecodeInterleaved(ctx, OpusDecoderState::PerfTime::Enabled, extra_behavior);
217 }
218
209 OpusDecoderState decoder_state; 219 OpusDecoderState decoder_state;
210}; 220};
211 221
@@ -354,6 +364,40 @@ void HwOpus::OpenHardwareOpusDecoderEx(HLERequestContext& ctx) {
354 system, OpusDecoderState{std::move(decoder), sample_rate, channel_count}); 364 system, OpusDecoderState{std::move(decoder), sample_rate, channel_count});
355} 365}
356 366
367void HwOpus::OpenHardwareOpusDecoderForMultiStreamEx(HLERequestContext& ctx) {
368 OpusMultiStreamParametersEx params;
369 std::memcpy(&params, ctx.ReadBuffer().data(), ctx.GetReadBufferSize());
370
371 const auto& sample_rate = params.sample_rate;
372 const auto& channel_count = params.channel_count;
373
374 LOG_INFO(
375 Audio,
376 "called with sample_rate={}, channel_count={}, number_streams={}, number_stereo_streams={}",
377 sample_rate, channel_count, params.number_streams, params.number_stereo_streams);
378
379 ASSERT_MSG(sample_rate == 48000 || sample_rate == 24000 || sample_rate == 16000 ||
380 sample_rate == 12000 || sample_rate == 8000,
381 "Invalid sample rate");
382
383 int error = 0;
384 OpusDecoderPtr decoder{opus_multistream_decoder_create(
385 sample_rate, static_cast<int>(channel_count), params.number_streams,
386 params.number_stereo_streams, params.channel_mappings.data(), &error)};
387 if (error != OPUS_OK || decoder == nullptr) {
388 LOG_ERROR(Audio, "Failed to create Opus decoder (error={}).", error);
389 IPC::ResponseBuilder rb{ctx, 2};
390 // TODO(ogniK): Use correct error code
391 rb.Push(ResultUnknown);
392 return;
393 }
394
395 IPC::ResponseBuilder rb{ctx, 2, 0, 1};
396 rb.Push(ResultSuccess);
397 rb.PushIpcInterface<IHardwareOpusDecoderManager>(
398 system, OpusDecoderState{std::move(decoder), sample_rate, channel_count});
399}
400
357HwOpus::HwOpus(Core::System& system_) : ServiceFramework{system_, "hwopus"} { 401HwOpus::HwOpus(Core::System& system_) : ServiceFramework{system_, "hwopus"} {
358 static const FunctionInfo functions[] = { 402 static const FunctionInfo functions[] = {
359 {0, &HwOpus::OpenHardwareOpusDecoder, "OpenHardwareOpusDecoder"}, 403 {0, &HwOpus::OpenHardwareOpusDecoder, "OpenHardwareOpusDecoder"},
@@ -362,7 +406,8 @@ HwOpus::HwOpus(Core::System& system_) : ServiceFramework{system_, "hwopus"} {
362 {3, nullptr, "GetWorkBufferSizeForMultiStream"}, 406 {3, nullptr, "GetWorkBufferSizeForMultiStream"},
363 {4, &HwOpus::OpenHardwareOpusDecoderEx, "OpenHardwareOpusDecoderEx"}, 407 {4, &HwOpus::OpenHardwareOpusDecoderEx, "OpenHardwareOpusDecoderEx"},
364 {5, &HwOpus::GetWorkBufferSizeEx, "GetWorkBufferSizeEx"}, 408 {5, &HwOpus::GetWorkBufferSizeEx, "GetWorkBufferSizeEx"},
365 {6, nullptr, "OpenHardwareOpusDecoderForMultiStreamEx"}, 409 {6, &HwOpus::OpenHardwareOpusDecoderForMultiStreamEx,
410 "OpenHardwareOpusDecoderForMultiStreamEx"},
366 {7, &HwOpus::GetWorkBufferSizeForMultiStreamEx, "GetWorkBufferSizeForMultiStreamEx"}, 411 {7, &HwOpus::GetWorkBufferSizeForMultiStreamEx, "GetWorkBufferSizeForMultiStreamEx"},
367 {8, nullptr, "GetWorkBufferSizeExEx"}, 412 {8, nullptr, "GetWorkBufferSizeExEx"},
368 {9, nullptr, "GetWorkBufferSizeForMultiStreamExEx"}, 413 {9, nullptr, "GetWorkBufferSizeForMultiStreamExEx"},
diff --git a/src/core/hle/service/audio/hwopus.h b/src/core/hle/service/audio/hwopus.h
index ece65c02c..91d9998ac 100644
--- a/src/core/hle/service/audio/hwopus.h
+++ b/src/core/hle/service/audio/hwopus.h
@@ -18,8 +18,10 @@ struct OpusMultiStreamParametersEx {
18 u32 number_stereo_streams; 18 u32 number_stereo_streams;
19 u32 use_large_frame_size; 19 u32 use_large_frame_size;
20 u32 padding; 20 u32 padding;
21 std::array<u32, 64> channel_mappings; 21 std::array<u8, 0x100> channel_mappings;
22}; 22};
23static_assert(sizeof(OpusMultiStreamParametersEx) == 0x118,
24 "OpusMultiStreamParametersEx has incorrect size");
23 25
24class HwOpus final : public ServiceFramework<HwOpus> { 26class HwOpus final : public ServiceFramework<HwOpus> {
25public: 27public:
@@ -29,6 +31,7 @@ public:
29private: 31private:
30 void OpenHardwareOpusDecoder(HLERequestContext& ctx); 32 void OpenHardwareOpusDecoder(HLERequestContext& ctx);
31 void OpenHardwareOpusDecoderEx(HLERequestContext& ctx); 33 void OpenHardwareOpusDecoderEx(HLERequestContext& ctx);
34 void OpenHardwareOpusDecoderForMultiStreamEx(HLERequestContext& ctx);
32 void GetWorkBufferSize(HLERequestContext& ctx); 35 void GetWorkBufferSize(HLERequestContext& ctx);
33 void GetWorkBufferSizeEx(HLERequestContext& ctx); 36 void GetWorkBufferSizeEx(HLERequestContext& ctx);
34 void GetWorkBufferSizeForMultiStreamEx(HLERequestContext& ctx); 37 void GetWorkBufferSizeForMultiStreamEx(HLERequestContext& ctx);