VideoPlaybackFrameworkSystemComponent.cpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <AzCore/Serialization/SerializeContext.h>
  9. #include <AzCore/Serialization/EditContext.h>
  10. #include <AzCore/RTTI/BehaviorContext.h>
  11. #include <AzFramework/Asset/SimpleAsset.h>
  12. #include <AzCore/Asset/AssetManagerBus.h>
  13. #include "VideoPlaybackFrameworkSystemComponent.h"
  14. #include "Include/VideoPlaybackFramework/VideoPlaybackAsset.h"
  15. #include "Include/VideoPlaybackFramework/VideoPlaybackBus.h"
  16. namespace VideoPlaybackFramework
  17. {
  18. class BehaviorVideoPlaybackNotificationBusHandler
  19. : public VideoPlaybackNotificationBus::Handler
  20. , public AZ::BehaviorEBusHandler
  21. {
  22. public:
  23. AZ_EBUS_BEHAVIOR_BINDER(BehaviorVideoPlaybackNotificationBusHandler, "{F3116FA1-3F81-4ADE-9941-C5A5C838197B}", AZ::SystemAllocator,
  24. OnPlaybackStarted,
  25. OnPlaybackPaused,
  26. OnPlaybackStopped,
  27. OnPlaybackFinished,
  28. OnFirstFramePresented
  29. );
  30. // Sent when playback starts or resumes
  31. void OnPlaybackStarted() override
  32. {
  33. Call(FN_OnPlaybackStarted);
  34. }
  35. // Sent when the video is paused
  36. void OnPlaybackPaused() override
  37. {
  38. Call(FN_OnPlaybackPaused);
  39. }
  40. // Sent when the video is stopped
  41. void OnPlaybackStopped() override
  42. {
  43. Call(FN_OnPlaybackStopped);
  44. }
  45. // Sent when the video finishes
  46. void OnPlaybackFinished() override
  47. {
  48. Call(FN_OnPlaybackFinished);
  49. }
  50. // Sent when the video decodes first frame
  51. void OnFirstFramePresented() override
  52. {
  53. Call(FN_OnFirstFramePresented);
  54. }
  55. };
  56. void VideoPlaybackFrameworkSystemComponent::Reflect(AZ::ReflectContext* context)
  57. {
  58. if (AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context))
  59. {
  60. AzFramework::SimpleAssetReference<VideoPlaybackAsset>::Register(*serialize);
  61. serialize->Class<VideoPlaybackFrameworkSystemComponent, AZ::Component>()
  62. ->Version(0)
  63. ;
  64. if (AZ::EditContext* ec = serialize->GetEditContext())
  65. {
  66. ec->Class<VideoPlaybackFrameworkSystemComponent>("VideoPlaybackFramework", "Interface framework to play back video during gameplay.")
  67. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  68. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  69. ;
  70. }
  71. }
  72. if (AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
  73. {
  74. behaviorContext->EBus<VideoPlaybackRequestBus>("VideoPlaybackRequestBus")
  75. ->Event("Play", &VideoPlaybackRequestBus::Events::Play)
  76. ->Event("Pause", &VideoPlaybackRequestBus::Events::Pause)
  77. ->Event("Stop", &VideoPlaybackRequestBus::Events::Stop)
  78. ->Event("IsPlaying", &VideoPlaybackRequestBus::Events::IsPlaying)
  79. ->Event("GetQueueAheadCount", &VideoPlaybackRequestBus::Events::GetQueueAheadCount)
  80. ->Event("SetQueueAheadCount", &VideoPlaybackRequestBus::Events::SetQueueAheadCount)
  81. ->Event("GetIsLooping", &VideoPlaybackRequestBus::Events::GetIsLooping)
  82. ->Event("SetIsLooping", &VideoPlaybackRequestBus::Events::SetIsLooping)
  83. ->Event("GetIsAutoPlay", &VideoPlaybackRequestBus::Events::GetIsAutoPlay)
  84. ->Event("SetIsAutoPlay", &VideoPlaybackRequestBus::Events::SetIsAutoPlay)
  85. ->Event("GetPlaybackSpeed", &VideoPlaybackRequestBus::Events::GetPlaybackSpeed)
  86. ->Event("SetPlaybackSpeed", &VideoPlaybackRequestBus::Events::SetPlaybackSpeed)
  87. ->Event("GetVideoPathname", &VideoPlaybackRequestBus::Events::GetVideoPathname)
  88. ->Event("SetVideoPathname", &VideoPlaybackRequestBus::Events::SetVideoPathname)
  89. ->Event("GetDestinationTextureName", &VideoPlaybackRequestBus::Events::GetDestinationTextureName)
  90. ->Event("SetDestinationTextureName", &VideoPlaybackRequestBus::Events::SetDestinationTextureName)
  91. ;
  92. behaviorContext->EBus<VideoPlaybackNotificationBus>("VideoPlaybackNotificationBus")
  93. ->Handler<BehaviorVideoPlaybackNotificationBusHandler>()
  94. ;
  95. }
  96. }
  97. void VideoPlaybackFrameworkSystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  98. {
  99. provided.push_back(AZ_CRC("VideoPlaybackFrameworkService"));
  100. }
  101. void VideoPlaybackFrameworkSystemComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  102. {
  103. incompatible.push_back(AZ_CRC("VideoPlaybackFrameworkService"));
  104. }
  105. void VideoPlaybackFrameworkSystemComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
  106. {
  107. (void)required;
  108. }
  109. void VideoPlaybackFrameworkSystemComponent::GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent)
  110. {
  111. (void)dependent;
  112. }
  113. void VideoPlaybackFrameworkSystemComponent::Init()
  114. {
  115. }
  116. void VideoPlaybackFrameworkSystemComponent::Activate()
  117. {
  118. VideoPlaybackFrameworkRequestBus::Handler::BusConnect();
  119. AZ::Data::AssetCatalogRequestBus::Broadcast(
  120. [](AZ::Data::AssetCatalogRequests* handler)
  121. {
  122. handler->EnableCatalogForAsset(azrtti_typeid<VideoPlaybackAsset>());
  123. handler->AddExtension("mp4");
  124. handler->AddExtension("mkv");
  125. handler->AddExtension("webm");
  126. handler->AddExtension("mov");
  127. });
  128. }
  129. void VideoPlaybackFrameworkSystemComponent::Deactivate()
  130. {
  131. VideoPlaybackFrameworkRequestBus::Handler::BusDisconnect();
  132. }
  133. }