WwiseMockMediaManager.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. #pragma once
  16. #include "AkInclude.h"
  17. #include "WwiseMockFileState.h"
  18. #include "Wwise/WwiseMediaManager.h"
  19. #include "Wwise/WwiseFileHandlerBase.h"
  20. #include "Wwise/CookedData/WwiseMediaCookedData.h"
  21. #include "Wwise/Stats/FileHandler.h"
  22. class FWwiseMockMediaManager : public IWwiseMediaManager, public FWwiseFileHandlerBase
  23. {
  24. public:
  25. FWwiseMockMediaManager() {}
  26. ~FWwiseMockMediaManager() override {}
  27. const TCHAR* GetManagingTypeName() const override { return TEXT("MockMedia"); }
  28. void LoadMedia(const FWwiseMediaCookedData& InMediaCookedData, const FString& InRootPath, FLoadMediaCallback&& InCallback) override
  29. {
  30. SCOPED_WWISEFILEHANDLER_EVENT_4(TEXT("FWwiseMockMediaManager::LoadMedia"));
  31. IncrementFileStateUseAsync(InMediaCookedData.MediaId, EWwiseFileStateOperationOrigin::Loading, [this, InMediaCookedData, InRootPath]() mutable
  32. {
  33. return CreateOp(InMediaCookedData, InRootPath);
  34. }, [InCallback = MoveTemp(InCallback)](const FWwiseFileStateSharedPtr, bool bInResult)
  35. {
  36. InCallback(bInResult);
  37. });
  38. }
  39. void UnloadMedia(const FWwiseMediaCookedData& InMediaCookedData, const FString& InRootPath, FUnloadMediaCallback&& InCallback) override
  40. {
  41. SCOPED_WWISEFILEHANDLER_EVENT_4(TEXT("FWwiseMockMediaManager::UnloadMedia"));
  42. DecrementFileStateUseAsync(InMediaCookedData.MediaId, nullptr, EWwiseFileStateOperationOrigin::Loading, MoveTemp(InCallback));
  43. }
  44. void SetGranularity(AkUInt32 InStreamingGranularity) override {}
  45. IWwiseStreamingManagerHooks& GetStreamingHooks() override final { return *this; }
  46. bool IsMediaLoaded(int32 mediaId)
  47. {
  48. for (const auto& pair : FileStatesById) {
  49. const FWwiseFileStateSharedPtr& fileState = pair.Value;
  50. if (fileState->GetShortId() == mediaId) {
  51. return true;
  52. }
  53. }
  54. return false;
  55. }
  56. bool IsEmpty()
  57. {
  58. FRWScopeLock Lock(FileStatesByIdLock, FRWScopeLockType::SLT_ReadOnly);
  59. return FileStatesById.Num() == 0;
  60. }
  61. protected:
  62. virtual FWwiseFileStateSharedPtr CreateOp(const FWwiseMediaCookedData& InMediaCookedData, const FString& InRootPath)
  63. {
  64. auto* FileState = new FWwiseMockFileState(InMediaCookedData.MediaId);
  65. if (InMediaCookedData.bStreaming)
  66. {
  67. FileState->bIsStreamedState = FWwiseMockFileState::OptionalBool::True;
  68. }
  69. else
  70. {
  71. FileState->bIsStreamedState = FWwiseMockFileState::OptionalBool::False;
  72. }
  73. return FWwiseFileStateSharedPtr(FileState);
  74. }
  75. };