Add AV video backend for macOS and iOS

This commit is contained in:
Wojtek Figat
2024-05-22 11:53:46 +02:00
parent 97be8ee8cc
commit 2af4e8fe10
8 changed files with 346 additions and 9 deletions

View File

@@ -22,6 +22,9 @@
#if VIDEO_API_MF
#include "MF/VideoBackendMF.h"
#endif
#if VIDEO_API_AV
#include "AV/VideoBackendAV.h"
#endif
#if VIDEO_API_ANDROID
#include "Android/VideoBackendAndroid.h"
#endif
@@ -109,13 +112,17 @@ protected:
context->GPU->SetState(pso);
context->GPU->DrawFullscreenTriangle();
}
else
else if (frame->Format() == _player->Format)
{
// Raw texture data upload
uint32 rowPitch, slicePitch;
frame->ComputePitch(0, rowPitch, slicePitch);
context->GPU->UpdateTexture(frame, 0, 0, _player->VideoFrameMemory.Get(), rowPitch, slicePitch);
}
else
{
LOG(Warning, "Incorrect video player data format {} for player texture format {}", ScriptingEnum::ToString(_player->Format), ScriptingEnum::ToString(_player->Frame->Format()));
}
// Frame has been updated
_player->FramesCount++;
@@ -161,7 +168,6 @@ public:
}
bool Init() override;
void Update() override;
void Dispose() override;
};
@@ -187,11 +193,6 @@ bool VideoService::Init()
return false;
}
void VideoService::Update()
{
PROFILE_CPU_NAMED("Video.Update");
}
void VideoService::Dispose()
{
PROFILE_CPU_NAMED("Video.Dispose");
@@ -223,6 +224,9 @@ bool Video::CreatePlayerBackend(const VideoBackendPlayerInfo& info, VideoBackend
#if VIDEO_API_MF
TRY_USE_BACKEND(VideoBackendMF);
#endif
#if VIDEO_API_AV
TRY_USE_BACKEND(VideoBackendAV);
#endif
#if VIDEO_API_ANDROID
TRY_USE_BACKEND(VideoBackendAndroid);
#endif
@@ -335,6 +339,8 @@ void VideoBackendPlayer::UpdateVideoFrame(Span<byte> data, TimeSpan time, TimeSp
// Update output frame texture
InitVideoFrame();
auto desc = GPUTextureDescription::New2D(Width, Height, PixelFormat::R8G8B8A8_UNorm, GPUTextureFlags::ShaderResource | GPUTextureFlags::RenderTarget);
if (!PixelFormatExtensions::IsVideo(Format))
desc.Format = Format; // Use raw format reported by the backend (eg. BGRA)
if (Frame->GetDescription() != desc)
{
if (Frame->Init(desc))