| 311 | } |
| 312 | |
| 313 | void VideoBackendPlayer::UpdateVideoFrame(Span<byte> data, TimeSpan time, TimeSpan duration) |
| 314 | { |
| 315 | PROFILE_CPU(); |
| 316 | PROFILE_MEM(Video); |
| 317 | ZoneText(DebugUrl, DebugUrlLen); |
| 318 | VideoFrameTime = time; |
| 319 | VideoFrameDuration = duration; |
| 320 | if (!GPUDevice::Instance || GPUDevice::Instance->GetRendererType() == RendererType::Null) |
| 321 | return; |
| 322 | |
| 323 | // Ensure that sampled frame data matches the target texture size |
| 324 | uint32 rowPitch, slicePitch; |
| 325 | RenderTools::ComputePitch(Format, VideoFrameWidth, VideoFrameHeight, rowPitch, slicePitch); |
| 326 | if (slicePitch != data.Length()) |
| 327 | { |
| 328 | LOG(Warning, "Incorrect video frame stride {}, doesn't match stride {} of video {}x{} in format {}", data.Length(), slicePitch, Width, Height, ScriptingEnum::ToString(Format)); |
| 329 | return; |
| 330 | } |
| 331 | |
| 332 | // Copy frame into buffer for video frames uploading |
| 333 | if (VideoFrameMemory.Length() < (int32)slicePitch) |
| 334 | { |
| 335 | VideoFrameMemory.Allocate(slicePitch); |
| 336 | } |
| 337 | Platform::MemoryCopy(VideoFrameMemory.Get(), data.Get(), slicePitch); |
| 338 | |
| 339 | // Update output frame texture |
| 340 | InitVideoFrame(); |
| 341 | auto desc = GPUTextureDescription::New2D(Width, Height, PixelFormat::R8G8B8A8_UNorm, GPUTextureFlags::ShaderResource | GPUTextureFlags::RenderTarget); |
| 342 | if (!PixelFormatExtensions::IsVideo(Format)) |
| 343 | desc.Format = Format; // Use raw format reported by the backend (eg. BGRA) |
| 344 | if (Frame->GetDescription() != desc) |
| 345 | { |
| 346 | if (Frame->Init(desc)) |
| 347 | { |
| 348 | LOG(Error, "Failed to allocate video frame texture"); |
| 349 | return; |
| 350 | } |
| 351 | } |
| 352 | |
| 353 | // Start texture upload task (if not already - only one is needed to upload the latest frame) |
| 354 | if (!UploadVideoFrameTask) |
| 355 | { |
| 356 | UploadVideoFrameTask = New<GPUUploadVideoFrameTask>(this); |
| 357 | UploadVideoFrameTask->Start(); |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | void VideoBackendPlayer::UpdateAudioBuffer(Span<byte> data, TimeSpan time, TimeSpan duration) |
| 362 | { |