A game framework written with osu! in mind.
1// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
2// See the LICENCE file in the repository root for full licence text.
3
4using System;
5using osu.Framework.Graphics.Textures;
6using osuTK.Graphics.ES30;
7using FFmpeg.AutoGen;
8using osu.Framework.Graphics.Primitives;
9using SixLabors.ImageSharp.PixelFormats;
10
11namespace osu.Framework.Graphics.Video
12{
13 public sealed unsafe class VideoTextureUpload : ITextureUpload
14 {
15 public readonly AVFrame* Frame;
16
17 private readonly FFmpegFuncs.AvFrameFreeDelegate freeFrameDelegate;
18
19 public ReadOnlySpan<Rgba32> Data => ReadOnlySpan<Rgba32>.Empty;
20
21 public int Level => 0;
22
23 public RectangleI Bounds { get; set; }
24
25 public PixelFormat Format => PixelFormat.Red;
26
27 /// <summary>
28 /// Sets the frame containing the data to be uploaded.
29 /// </summary>
30 /// <param name="frame">The frame to upload.</param>
31 /// <param name="freeFrameDelegate">A function to free the frame on disposal.</param>
32 internal VideoTextureUpload(AVFrame* frame, FFmpegFuncs.AvFrameFreeDelegate freeFrameDelegate)
33 {
34 Frame = frame;
35 this.freeFrameDelegate = freeFrameDelegate;
36 }
37
38 #region IDisposable Support
39
40 public void Dispose()
41 {
42 fixed (AVFrame** ptr = &Frame)
43 freeFrameDelegate(ptr);
44 }
45
46 #endregion
47 }
48}