WwiseIOHook.cpp 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*******************************************************************************
  2. The content of this file includes portions of the proprietary AUDIOKINETIC Wwise
  3. Technology released in source code form as part of the game integration package.
  4. The content of this file may not be used without valid licenses to the
  5. AUDIOKINETIC Wwise Technology.
  6. Note that the use of the game engine is subject to the Unreal(R) Engine End User
  7. License Agreement at https://www.unrealengine.com/en-US/eula/unreal
  8. License Usage
  9. Licensees holding valid licenses to the AUDIOKINETIC Wwise Technology may use
  10. this file in accordance with the end user license agreement provided with the
  11. software or, alternatively, in accordance with the terms contained
  12. in a written agreement between you and Audiokinetic Inc.
  13. Copyright (c) 2023 Audiokinetic Inc.
  14. *******************************************************************************/
  15. #include "Wwise/WwiseIOHook.h"
  16. #include "Wwise/API/WwiseStreamMgrAPI.h"
  17. #include "Wwise/Stats/FileHandler.h"
  18. #include <inttypes.h>
  19. bool FWwiseIOHook::Init(const AkDeviceSettings& InDeviceSettings)
  20. {
  21. SCOPED_WWISEFILEHANDLER_EVENT_2(TEXT("FWwiseIOHook::Init"));
  22. auto* StreamMgr = IWwiseStreamMgrAPI::Get();
  23. if (UNLIKELY(!StreamMgr))
  24. {
  25. UE_LOG(LogWwiseFileHandler, Error, TEXT("IOHook: Could not retrieve StreamMgr while Init"));
  26. return false;
  27. }
  28. // If the Stream Manager's File Location Resolver was not set yet, set this object as the
  29. // File Location Resolver (this I/O hook is also able to resolve file location).
  30. if (LIKELY(!StreamMgr->GetFileLocationResolver()))
  31. {
  32. UE_LOG(LogWwiseFileHandler, Verbose, TEXT("IOHook: Setting File Location Resolver"));
  33. StreamMgr->SetFileLocationResolver(GetLocationResolver());
  34. }
  35. else
  36. {
  37. UE_LOG(LogWwiseFileHandler, Log, TEXT("IOHook: Existing File Location Resolver. Not updating."));
  38. }
  39. // Create a device in the Stream Manager, specifying this as the hook.
  40. auto Result = StreamMgr->CreateDevice(InDeviceSettings, GetIOHook(), StreamingDevice);
  41. UE_CLOG(UNLIKELY(Result != AK_Success || StreamingDevice == AK_INVALID_DEVICE_ID), LogWwiseFileHandler, Error, TEXT("IOHook: CreateDevice failed."));
  42. UE_CLOG(LIKELY(Result == AK_Success && StreamingDevice != AK_INVALID_DEVICE_ID), LogWwiseFileHandler, Verbose, TEXT("IOHook: CreateDevice = %" PRIu32), StreamingDevice);
  43. return StreamingDevice != AK_INVALID_DEVICE_ID;
  44. }
  45. void FWwiseIOHook::Term()
  46. {
  47. SCOPED_WWISEFILEHANDLER_EVENT_2(TEXT("FWwiseIOHook::Term"));
  48. auto* StreamMgr = IWwiseStreamMgrAPI::Get();
  49. if (UNLIKELY(!StreamMgr))
  50. {
  51. UE_LOG(LogWwiseFileHandler, Log, TEXT("IOHook::Term Could not term StreamMgr"));
  52. return;
  53. }
  54. if (LIKELY(StreamMgr->GetFileLocationResolver() == GetLocationResolver()))
  55. {
  56. UE_LOG(LogWwiseFileHandler, Verbose, TEXT("IOHook::Term Resetting File Location Resolver"));
  57. StreamMgr->SetFileLocationResolver(nullptr);
  58. }
  59. else
  60. {
  61. UE_LOG(LogWwiseFileHandler, Log, TEXT("IOHook::Term Different File Location Resolver. Not setting to null."));
  62. }
  63. if (LIKELY(StreamingDevice != AK_INVALID_DEVICE_ID))
  64. {
  65. StreamMgr->DestroyDevice(StreamingDevice);
  66. StreamingDevice = AK_INVALID_DEVICE_ID;
  67. UE_LOG(LogWwiseFileHandler, Verbose, TEXT("IOHook::Term Device Destroyed."));
  68. }
  69. else
  70. {
  71. UE_LOG(LogWwiseFileHandler, Log, TEXT("IOHook::Term No device to destroy."))
  72. }
  73. }