Skip to content

Commit 8674677

Browse files
author
Davide Galli
committed
Merging Pull Request BogdanovKirill#64, BogdanovKirill#87 and BogdanovKirill#125 from BogdanovKirill/RtspClientSharp repository
1 parent cd7170f commit 8674677

28 files changed

+760
-173
lines changed

Examples/SimpleRtspPlayer/RawFramesDecoding/FFmpeg/FFmpegVideoPInvoke.cs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ namespace SimpleRtspPlayer.RawFramesDecoding.FFmpeg
66
enum FFmpegVideoCodecId
77
{
88
MJPEG = 7,
9-
H264 = 27
9+
MPEG4 = 12,
10+
H264 = 27,
11+
MXPEG = 145,
12+
HVEC = 173,
1013
}
1114

1215
[Flags]
@@ -22,8 +25,37 @@ enum FFmpegScalingQuality
2225
enum FFmpegPixelFormat
2326
{
2427
None = -1,
28+
/// <summary>
29+
/// planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
30+
/// </summary>
31+
YUV420P = 0,
32+
/// <summary>
33+
/// packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
34+
/// </summary>
35+
YUYV422 = 1,
36+
/// <summary>
37+
/// packed RGB 8:8:8, 24bpp, RGBRGB...
38+
/// </summary>
39+
RGB24 = 2,
40+
/// <summary>
41+
/// packed RGB 8:8:8, 24bpp, BGRBGR...
42+
/// </summary>
2543
BGR24 = 3,
44+
/// <summary>
45+
/// planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
46+
/// </summary>
47+
YUV422P = 4,
48+
/// <summary>
49+
/// planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
50+
/// </summary>
51+
YUV444P = 5,
52+
/// <summary>
53+
/// Y , 8bpp
54+
/// </summary>
2655
GRAY8 = 8,
56+
/// <summary>
57+
/// packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
58+
/// </summary>
2759
BGRA = 28
2860
}
2961

Examples/libffmpeghelper/libffmpeghelper.vcxproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,32 +39,32 @@
3939
<ProjectGuid>{3C96BD24-3212-4CD8-86E3-63D1E3E38155}</ProjectGuid>
4040
<Keyword>Win32Proj</Keyword>
4141
<RootNamespace>libffmpeghelper</RootNamespace>
42-
<WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
42+
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
4343
</PropertyGroup>
4444
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
4545
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
4646
<ConfigurationType>DynamicLibrary</ConfigurationType>
4747
<UseDebugLibraries>true</UseDebugLibraries>
48-
<PlatformToolset>v141</PlatformToolset>
48+
<PlatformToolset>v143</PlatformToolset>
4949
<CharacterSet>Unicode</CharacterSet>
5050
</PropertyGroup>
5151
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
5252
<ConfigurationType>DynamicLibrary</ConfigurationType>
5353
<UseDebugLibraries>true</UseDebugLibraries>
54-
<PlatformToolset>v141</PlatformToolset>
54+
<PlatformToolset>v143</PlatformToolset>
5555
<CharacterSet>Unicode</CharacterSet>
5656
</PropertyGroup>
5757
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
5858
<ConfigurationType>DynamicLibrary</ConfigurationType>
5959
<UseDebugLibraries>false</UseDebugLibraries>
60-
<PlatformToolset>v141</PlatformToolset>
60+
<PlatformToolset>v143</PlatformToolset>
6161
<WholeProgramOptimization>true</WholeProgramOptimization>
6262
<CharacterSet>Unicode</CharacterSet>
6363
</PropertyGroup>
6464
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
6565
<ConfigurationType>DynamicLibrary</ConfigurationType>
6666
<UseDebugLibraries>false</UseDebugLibraries>
67-
<PlatformToolset>v141</PlatformToolset>
67+
<PlatformToolset>v143</PlatformToolset>
6868
<WholeProgramOptimization>true</WholeProgramOptimization>
6969
<CharacterSet>Unicode</CharacterSet>
7070
</PropertyGroup>

RtspClientSharp/MediaParsers/H264Parser.cs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
namespace RtspClientSharp.MediaParsers
1111
{
12-
class H264Parser
12+
class H264Parser(Func<DateTime> frameTimestampProvider)
1313
{
1414
private enum FrameType
1515
{
@@ -18,27 +18,21 @@ private enum FrameType
1818
PredictionFrame
1919
}
2020

21-
public static readonly ArraySegment<byte> StartMarkerSegment = new ArraySegment<byte>(RawH264Frame.StartMarker);
21+
public static readonly ArraySegment<byte> StartMarkerSegment = new(RawH264Frame.StartMarker);
2222

23-
private readonly Func<DateTime> _frameTimestampProvider;
24-
private readonly BitStreamReader _bitStreamReader = new BitStreamReader();
25-
private readonly Dictionary<int, byte[]> _spsMap = new Dictionary<int, byte[]>();
26-
private readonly Dictionary<int, byte[]> _ppsMap = new Dictionary<int, byte[]>();
23+
private readonly Func<DateTime> _frameTimestampProvider = frameTimestampProvider ?? throw new ArgumentNullException(nameof(frameTimestampProvider));
24+
private readonly BitStreamReader _bitStreamReader = new();
25+
private readonly Dictionary<int, byte[]> _spsMap = [];
26+
private readonly Dictionary<int, byte[]> _ppsMap = [];
2727
private bool _waitForIFrame = true;
2828
private byte[] _spsPpsBytes = new byte[0];
2929
private bool _updateSpsPpsBytes;
3030
private int _sliceType = -1;
3131

32-
private readonly MemoryStream _frameStream;
32+
private readonly MemoryStream _frameStream = new(8 * 1024);
3333

3434
public Action<RawFrame> FrameGenerated;
3535

36-
public H264Parser(Func<DateTime> frameTimestampProvider)
37-
{
38-
_frameTimestampProvider = frameTimestampProvider ?? throw new ArgumentNullException(nameof(frameTimestampProvider));
39-
_frameStream = new MemoryStream(8 * 1024);
40-
}
41-
4236
public void Parse(ArraySegment<byte> byteSegment, bool generateFrame)
4337
{
4438
Debug.Assert(byteSegment.Array != null, "byteSegment.Array != null");
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
//using RtspClientSharp.RawFrames;
2+
//using RtspClientSharp.RawFrames.Video;
3+
//using RtspClientSharp.Utils;
4+
//using System;
5+
//using System.Collections.Generic;
6+
//using System.Diagnostics;
7+
//using System.IO;
8+
9+
//namespace RtspClientSharp.MediaParsers;
10+
//class H265Parser(Func<DateTime> frameTimestampProvider)
11+
//{
12+
// private enum FrameType
13+
// {
14+
// Unknown,
15+
// IntraFrame,
16+
// PredictionFrame
17+
// }
18+
19+
20+
// public enum NalUnitType : byte
21+
// {
22+
// TRAIL_N = 0,
23+
// TRAIL_R = 1,
24+
// TSA_N = 2,
25+
// TSA_R = 3,
26+
// STSA_N = 4,
27+
// STSA_R = 5,
28+
// RADL_N = 6,
29+
// RADL_R = 7,
30+
// RASL_N = 8,
31+
// RASL_R = 9,
32+
// RSV_VCL_N10 = 10,
33+
// RSV_VCL_R11 = 11,
34+
// RSV_VCL_N12 = 12,
35+
// RSV_VCL_R13 = 13,
36+
// RSV_VCL_N14 = 14,
37+
// RSV_VCL_R15 = 15,
38+
// BLA_W_LP = 16,
39+
// BLA_W_RADL = 17,
40+
// BLA_N_LP = 18,
41+
// IDR_W_RADL = 19,
42+
// IDR_N_LP = 20,
43+
// CRA_NUT = 21,
44+
// RSV_IRAP_VCL22 = 22,
45+
// RSV_IRAP_VCL23 = 23,
46+
// RSV_VCL24 = 24,
47+
// RSV_VCL25 = 25,
48+
// RSV_VCL26 = 26,
49+
// RSV_VCL27 = 27,
50+
// RSV_VCL28 = 28,
51+
// RSV_VCL29 = 29,
52+
// RSV_VCL30 = 30,
53+
// RSV_VCL31 = 31,
54+
// VPS_NUT = 32,
55+
// SPS_NUT = 33,
56+
// PPS_NUT = 34,
57+
// AUD_NUT = 35,
58+
// EOS_NUT = 36,
59+
// EOB_NUT = 37,
60+
// FD_NUT = 38,
61+
// PREFIX_SEI_NUT = 39,
62+
// SUFFIX_SEI_NUT = 40,
63+
// RSV_NVCL41 = 41,
64+
// RSV_NVCL42 = 42,
65+
// RSV_NVCL43 = 43,
66+
// RSV_NVCL44 = 44,
67+
// RSV_NVCL45 = 45,
68+
// RSV_NVCL46 = 46,
69+
// RSV_NVCL47 = 47,
70+
// // 48-63: unspecified
71+
// AP = 48,
72+
// FU = 49,
73+
// UNSPEC50 = 50,
74+
// UNSPEC51 = 51,
75+
// UNSPEC52 = 52,
76+
// UNSPEC53 = 53,
77+
// UNSPEC54 = 54,
78+
// UNSPEC55 = 55,
79+
// UNSPEC56 = 56,
80+
// UNSPEC57 = 57,
81+
// UNSPEC58 = 58,
82+
// UNSPEC59 = 59,
83+
// UNSPEC60 = 60,
84+
// UNSPEC61 = 61,
85+
// UNSPEC62 = 62,
86+
// UNSPEC63 = 63,
87+
// }
88+
89+
// public static readonly ArraySegment<byte> StartMarkerSegment = new(RawH265Frame.StartMarker);
90+
91+
// private readonly Func<DateTime> _frameTimestampProvider = frameTimestampProvider ?? throw new ArgumentNullException(nameof(frameTimestampProvider));
92+
// private readonly BitStreamReader _bitStreamReader = new();
93+
// private readonly Dictionary<int, byte[]> _spsMap = [];
94+
// private readonly Dictionary<int, byte[]> _ppsMap = [];
95+
// private bool _waitForIFrame = true;
96+
// private byte[] _spsPpsBytes = new byte[0];
97+
// private bool _updateSpsPpsBytes;
98+
// private int _sliceType = -1;
99+
100+
// private readonly MemoryStream _frameStream = new(8 * 1024);
101+
102+
// public Action<RawFrame> FrameGenerated;
103+
104+
105+
// public void Parse(ArraySegment<byte> byteSegment, bool generateFrame)
106+
// {
107+
// Debug.Assert(byteSegment.Array != null, "byteSegment.Array != null");
108+
109+
// if (ArrayUtils.StartsWith(byteSegment.Array, byteSegment.Offset, byteSegment.Count,
110+
// RawH264Frame.StartMarker))
111+
// H264Slicer.Slice(byteSegment, SlicerOnNalUnitFound);
112+
// else
113+
// ProcessNalUnit(byteSegment, false, ref generateFrame);
114+
115+
// if (generateFrame)
116+
// TryGenerateFrame();
117+
// }
118+
119+
// public void TryGenerateFrame()
120+
// {
121+
// if (_frameStream.Position == 0)
122+
// return;
123+
124+
// var frameBytes = new ArraySegment<byte>(_frameStream.GetBuffer(), 0, (int)_frameStream.Position);
125+
// _frameStream.Position = 0;
126+
// TryGenerateFrame(frameBytes);
127+
// }
128+
129+
// private void TryGenerateFrame(ArraySegment<byte> frameBytes)
130+
// {
131+
// if (_updateSpsPpsBytes)
132+
// {
133+
// UpdateSpsPpsBytes();
134+
// _updateSpsPpsBytes = false;
135+
// }
136+
137+
// if (_sliceType == -1 || _spsPpsBytes.Length == 0)
138+
// return;
139+
140+
// FrameType frameType = GetFrameType(_sliceType);
141+
// _sliceType = -1;
142+
// DateTime frameTimestamp;
143+
144+
// if (frameType == FrameType.PredictionFrame && !_waitForIFrame)
145+
// {
146+
// frameTimestamp = _frameTimestampProvider();
147+
// FrameGenerated?.Invoke(new RawH264PFrame(frameTimestamp, frameBytes));
148+
// return;
149+
// }
150+
151+
// if (frameType != FrameType.IntraFrame)
152+
// return;
153+
154+
// _waitForIFrame = false;
155+
// var byteSegment = new ArraySegment<byte>(_spsPpsBytes);
156+
157+
// frameTimestamp = _frameTimestampProvider();
158+
// FrameGenerated?.Invoke(new RawH264IFrame(frameTimestamp, frameBytes, byteSegment));
159+
// }
160+
161+
// public void ResetState()
162+
// {
163+
// _frameStream.Position = 0;
164+
// _sliceType = -1;
165+
// _waitForIFrame = true;
166+
// }
167+
168+
// private void SlicerOnNalUnitFound(ArraySegment<byte> byteSegment)
169+
// {
170+
// bool generateFrame = false;
171+
// ProcessNalUnit(byteSegment, true, ref generateFrame);
172+
// }
173+
174+
// private void ProcessNalUnit(ArraySegment<byte> byteSegment, bool hasStartMarker, ref bool generateFrame)
175+
// {
176+
// Debug.Assert(byteSegment.Array != null, "byteSegment.Array != null");
177+
178+
// int offset = byteSegment.Offset;
179+
180+
// if (hasStartMarker)
181+
// offset += RawH264Frame.StartMarker.Length;
182+
183+
184+
// }
185+
//}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
using System.Runtime.Serialization;
3+
4+
namespace RtspClientSharp.MediaParsers;
5+
[Serializable]
6+
public class H265ParserException : Exception
7+
{
8+
public H265ParserException()
9+
{
10+
}
11+
12+
public H265ParserException(string message) : base(message)
13+
{
14+
}
15+
16+
public H265ParserException(string message, Exception inner) : base(message, inner)
17+
{
18+
}
19+
20+
protected H265ParserException(SerializationInfo info, StreamingContext context) : base(info, context)
21+
{
22+
}
23+
}

0 commit comments

Comments
 (0)