forked from ArduPilot/MissionPlanner
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathVideoBuffer.cs
132 lines (117 loc) · 4.36 KB
/
VideoBuffer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
////////////////////////////////////////////////////////////////////////////////
//
// VideoBuffer.cs - This file is part of LibVLC.NET.
//
// Copyright (C) 2011 Boris Richter <himself@boris-richter.net>
//
// --------------------------------------------------------------------------
//
// LibVLC.NET is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// LibVLC.NET is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with LibVLC.NET. If not, see <http://www.gnu.org/licenses/>.
//
// --------------------------------------------------------------------------
//
// $LastChangedRevision$
// $LastChangedDate$
// $LastChangedBy$
//
////////////////////////////////////////////////////////////////////////////////
using System;
using System.Runtime.InteropServices;
namespace LibVLC.NET
{
//****************************************************************************
/// <summary>
/// Represents the video buffer of a media player.
/// </summary>
public class VideoBuffer
{
//==========================================================================
/// <summary>
/// Create a new instance of the class <see cref="VideoBuffer"/>.
/// </summary>
/// <param name="width">
/// The width of the video.
/// </param>
/// <param name="height">
/// The height of the video.
/// </param>
/// <param name="pixelFormat">
/// The pixel format of the video.
/// </param>
public VideoBuffer(uint width, uint height, PixelFormat pixelFormat)
{
Width = width;
Height = height;
PixelFormat = pixelFormat;
Stride = Width * 4;
Lines = Height;
FrameBuffer = new byte[Stride * Lines];
}
//==========================================================================
private GCHandle m_GCHandle = default(GCHandle);
//==========================================================================
internal IntPtr Lock()
{
return (m_GCHandle = GCHandle.Alloc(FrameBuffer, GCHandleType.Pinned)).AddrOfPinnedObject();
}
//==========================================================================
internal void Unlock()
{
m_GCHandle.Free();
}
//==========================================================================
/// <summary>
/// Gets or sets the width of the video in pixels.
/// </summary>
public readonly uint Width;
//==========================================================================
/// <summary>
/// Gets the height of the video in pixels.
/// </summary>
public readonly uint Height;
//==========================================================================
/// <summary>
/// Gets or sets the pixel format of the video frame.
/// </summary>
public readonly PixelFormat PixelFormat;
//==========================================================================
/// <summary>
/// Gets or sets the stride of a video frame which is the width
/// multiplied by the bytes per pixel.
/// </summary>
public readonly uint Stride;
//==========================================================================
/// <summary>
/// Gets or sets the number of scan lines.
/// </summary>
public readonly uint Lines;
//==========================================================================
/// <summary>
/// Gets or sets the video frame buffer.
/// </summary>
public readonly byte[] FrameBuffer;
//==========================================================================
/// <summary>
/// Override <see cref="Object.ToString"/> and returns a string
/// representation of the video size.
/// </summary>
/// <returns>
/// A string representing the video format.
/// </returns>
public override string ToString()
{
return String.Format("{0}x{1}@{2}", Width, Height, PixelFormat);
}
} // class VideoFrame
}