123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- 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<object> _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<object> 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;
- }
- }
- }
|