1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- using System;
- using System.Runtime.InteropServices;
- namespace MediaUtil
- {
- public partial class VideoPacket : IDisposable
- {
- private readonly IntPtr _packetHandle;
- private bool _disposed;
- public IntPtr Handle => _packetHandle;
- /// <summary>
- /// Gets the index of this packet.
- /// </summary>
- public int Index { get; }
- /// <summary>
- /// Gets the data size of this packet.
- /// </summary>
- public int Size { get; }
- /// <summary>
- /// Gets the data of this packet.
- /// </summary>
- public byte[] Data
- {
- get
- {
- IntPtr dataPtr = Environment.Is64BitProcess ?
- Interop64.GetPacketData(_packetHandle) :
- Interop32.GetPacketData(_packetHandle);
- var data = new byte[Size];
- Marshal.Copy(dataPtr, data, 0, Size);
- return data;
- }
- }
- public VideoPacket(IntPtr packetHandle)
- {
- _packetHandle = packetHandle;
- Index = Environment.Is64BitProcess ?
- Interop64.GetPacketIndex(_packetHandle) :
- Interop32.GetPacketIndex(_packetHandle);
- Size = Environment.Is64BitProcess ?
- Interop64.GetPacketSize(_packetHandle) :
- Interop32.GetPacketSize(_packetHandle);
- }
- ~VideoPacket()
- {
- DoDispose();
- }
- private void DoDispose()
- {
- if (!_disposed)
- {
- var result = Environment.Is64BitProcess ?
- Interop64.DestroyPacket(_packetHandle) :
- Interop32.DestroyPacket(_packetHandle);
- if (result != 0)
- {
- throw new MediaException(result);
- }
- _disposed = true;
- }
- }
- public void Dispose()
- {
- DoDispose();
- GC.SuppressFinalize(this);
- }
- }
- }
|