using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace fis.media.Library.Players { public class VideoFrameData : IDisposable { private readonly Action _dispose; private bool _disposed; public int Width { get; set; } public int Height { get; set; } public byte[] Data { get; set; } public object? ImageData { get; set; } public string? Key { get; set; } public VideoFrameData(int width, int height, byte[] data, Action dispose = null!) { Width = width; Height = height; Data = data; _dispose = dispose; } public string ToBase64() { return Convert.ToBase64String(Data, 0, Data.Length); } ~VideoFrameData() { Dispose(); } public void Dispose() { if (!_disposed) { _dispose?.Invoke(ImageData!); _disposed = true; } } } public class ImageDataBuffer : IDisposable { private uint _width; private uint _height; private int _dataSize; private byte[]? _buffer; public void SetBufferSize(uint width, uint height, int dataSize) { if (width != _width || height != _height || dataSize != _dataSize) { _buffer = new byte[width * height * dataSize]; _width = width; _height = height; _dataSize = dataSize; } } public void SetBuffer(byte[] image) { if (_buffer != null) { _buffer = image; } } public byte[]? GetBuffer() { return _buffer; } public void Dispose() { _buffer = null; } } public class RemoteVideoFrameData { public string UserId { get; } public VideoFrameData? Data { get; set; } public ImageDataBuffer ImageDataBuffer { get; } public RemoteVideoFrameData(string userId) { UserId = userId; ImageDataBuffer = new ImageDataBuffer(); } } public class LocalPreviewVideoFrameData { public string UserId { get; } public VideoFrameData? Data { get; set; } public LocalPreviewVideoFrameData(string userId) { UserId = userId; } } }