Skip to content

Commit e061625

Browse files
committed
F Added nugets, API improvements
1 parent b4245cd commit e061625

8 files changed

Lines changed: 89 additions & 51 deletions

File tree

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
1-
# SharpRealTimeStreaming
1+
# SharpRealTimeStreaming
2+
This is just a thin wrapper around the fantastic SharpRTSP, mostly made of their sample code with some API enhancements to make it easier to use.
3+
4+
## SharpRTSPClient
5+
Simple RTSP client that supports H264, H265 for video and AAC for audio.
6+
7+
## SharpRTSPServer
8+
Simple RTSP server that supports H264, H265 for video and AAC, PCMU and PCMA for audio.

src/RTSPClientApp/Program.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-

2-
using SharpRTSPClient;
1+
using SharpRTSPClient;
32
using System;
43

54
const string rtspUri = "rtsp://127.0.0.1:8554";
@@ -13,7 +12,7 @@
1312
client.NewAudioStream += (sender, e) => Console.WriteLine(e.ToString());
1413
client.ReceivedAudioData += (sender, e) => Console.Write("+");
1514

16-
client.Connect(rtspUri, RTSPClient.RtpTransport.TCP, userName, password);
15+
client.Connect(rtspUri, RTPTransport.TCP, userName, password);
1716

1817
Console.WriteLine("Press any key to exit");
1918
while (!Console.KeyAvailable)

src/RTSPServerApp/Program.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-

2-
using SharpMp4;
1+
using SharpMp4;
32
using SharpRTSPServer;
43
using System;
54
using System.Collections.Generic;

src/SharpRTSPClient/H264StreamConfigurationData.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
using System.Collections.Generic;
2-
3-
namespace SharpRTSPClient
1+
namespace SharpRTSPClient
42
{
5-
public class H264StreamConfigurationData : IVideoStreamConfigurationData
3+
public class H264StreamConfigurationData : IStreamConfigurationData
64
{
75
public byte[] SPS { get; set; }
86
public byte[] PPS { get; set; }
@@ -20,10 +18,5 @@ public override string ToString()
2018
{
2119
return $"SPS: {Utilities.ToHexString(SPS)}\r\nPPS: {Utilities.ToHexString(PPS)}";
2220
}
23-
24-
public IEnumerable<byte[]> GetNALUs()
25-
{
26-
return new byte[][] { SPS, PPS };
27-
}
2821
}
2922
}

src/SharpRTSPClient/H265StreamConfigurationData.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
using System.Collections.Generic;
2-
3-
namespace SharpRTSPClient
1+
namespace SharpRTSPClient
42
{
5-
public class H265StreamConfigurationData : IVideoStreamConfigurationData
3+
public class H265StreamConfigurationData : IStreamConfigurationData
64
{
75
public byte[] VPS { get; set; }
86
public byte[] SPS { get; set; }
@@ -22,10 +20,5 @@ public override string ToString()
2220
{
2321
return $"VPS: {Utilities.ToHexString(VPS)}\r\nSPS: {Utilities.ToHexString(SPS)}\r\nPPS: {Utilities.ToHexString(PPS)}";
2422
}
25-
26-
public IEnumerable<byte[]> GetNALUs()
27-
{
28-
return new byte[][] { VPS, SPS, PPS };
29-
}
3023
}
3124
}

src/SharpRTSPClient/RTSPClient.cs

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,20 @@
1414

1515
namespace SharpRTSPClient
1616
{
17+
public enum RTPTransport
18+
{
19+
UDP,
20+
TCP,
21+
MULTICAST
22+
}
23+
24+
public enum MediaRequest
25+
{
26+
VIDEO_ONLY,
27+
AUDIO_ONLY,
28+
VIDEO_AND_AUDIO
29+
}
30+
1731
/// <summary>
1832
/// RTSP client.
1933
/// </summary>
@@ -40,28 +54,14 @@ public class RTSPClient : IDisposable
4054

4155
public bool AutoPlay { get; set; } = true;
4256

43-
public enum RtpTransport
44-
{
45-
UDP,
46-
TCP,
47-
MULTICAST
48-
};
49-
50-
public enum MediaRequest
51-
{
52-
VIDEO_ONLY,
53-
AUDIO_ONLY,
54-
VIDEO_AND_AUDIO
55-
};
56-
5757
private enum RtspStatus { WaitingToConnect, Connecting, ConnectFailed, Connected };
5858

5959
private IRtspTransport _rtspSocket; // RTSP connection
6060
private RtspStatus _rtspSocketStatus = RtspStatus.WaitingToConnect;
6161

6262
// this wraps around a the RTSP tcpSocket stream
6363
private RtspListener _rtspClient;
64-
private RtpTransport _rtpTransport = RtpTransport.UDP; // Mode, either RTP over UDP or RTP over TCP using the RTSP socket
64+
private RTPTransport _rtpTransport = RTPTransport.UDP; // Mode, either RTP over UDP or RTP over TCP using the RTSP socket
6565

6666
private IRtpTransport _videoRtpTransport;
6767
private IRtpTransport _audioRtpTransport;
@@ -131,12 +131,12 @@ public RTSPClient(ILoggerFactory loggerFactory)
131131
/// Connect.
132132
/// </summary>
133133
/// <param name="url">URL to connect to.</param>
134-
/// <param name="rtpTransport">Type of the RTP transport <see cref="RtpTransport"/>.</param>
134+
/// <param name="rtpTransport">Type of the RTP transport <see cref="RTPTransport"/>.</param>
135135
/// <param name="username">User name.</param>
136136
/// <param name="password">Password.</param>
137137
/// <param name="mediaRequest">Media request type <see cref="MediaRequest>."/></param>
138138
/// <param name="playbackSession">Playback session.</param>
139-
public void Connect(string url, RtpTransport rtpTransport, string username = null, string password = null, MediaRequest mediaRequest = MediaRequest.VIDEO_AND_AUDIO, bool playbackSession = false)
139+
public void Connect(string url, RTPTransport rtpTransport, string username = null, string password = null, MediaRequest mediaRequest = MediaRequest.VIDEO_AND_AUDIO, bool playbackSession = false)
140140
{
141141
RtspUtils.RegisterUri();
142142

@@ -213,14 +213,14 @@ public void Connect(string url, RtpTransport rtpTransport, string username = nul
213213
// If the RTP transport is MULTICAST, we have to wait for the SETUP message to get the Multicast Address from the RTSP server
214214
this._rtpTransport = rtpTransport;
215215

216-
if (rtpTransport == RtpTransport.UDP)
216+
if (rtpTransport == RTPTransport.UDP)
217217
{
218218
// give a range of 500 pairs (1000 addresses) to try incase some address are in use
219219
_videoRtpTransport = new UDPSocket(50000, 51000);
220220
_audioRtpTransport = new UDPSocket(50000, 51000);
221221
}
222222

223-
if (rtpTransport == RtpTransport.TCP)
223+
if (rtpTransport == RTPTransport.TCP)
224224
{
225225
int nextFreeRtpChannel = 0;
226226
_videoRtpTransport = new RtpTcpTransport(_rtspClient)
@@ -1118,14 +1118,14 @@ private RtspTransport CalculateTransport(IRtpTransport transport)
11181118
{
11191119
// Server interleaves the RTP packets over the RTSP connection
11201120
// Example for TCP mode (RTP over RTSP) Transport: RTP/AVP/TCP;interleaved=0-1
1121-
case RtpTransport.TCP:
1121+
case RTPTransport.TCP:
11221122
return new RtspTransport()
11231123
{
11241124
LowerTransport = RtspTransport.LowerTransportType.TCP,
11251125
// Eg Channel 0 for RTP video data. Channel 1 for RTCP status reports
11261126
Interleaved = (transport as RtpTcpTransport)?.Channels ?? throw new ApplicationException("TCP transport asked and no tcp channel allocated"),
11271127
};
1128-
case RtpTransport.UDP:
1128+
case RTPTransport.UDP:
11291129
return new RtspTransport()
11301130
{
11311131
LowerTransport = RtspTransport.LowerTransportType.UDP,
@@ -1135,7 +1135,7 @@ private RtspTransport CalculateTransport(IRtpTransport transport)
11351135
// Server sends the RTP packets to a Pair of UDP ports (one for data, one for rtcp control messages)
11361136
// using Multicast Address and Ports that are in the reply to the SETUP message
11371137
// Example for MULTICAST mode Transport: RTP/AVP;multicast
1138-
case RtpTransport.MULTICAST:
1138+
case RTPTransport.MULTICAST:
11391139
return new RtspTransport()
11401140
{
11411141
LowerTransport = RtspTransport.LowerTransportType.UDP,
@@ -1222,11 +1222,6 @@ public override string ToString()
12221222
public interface IStreamConfigurationData
12231223
{ }
12241224

1225-
public interface IVideoStreamConfigurationData : IStreamConfigurationData
1226-
{
1227-
IEnumerable<byte[]> GetNALUs();
1228-
}
1229-
12301225
public class SimpleDataEventArgs : EventArgs
12311226
{
12321227
public SimpleDataEventArgs(IEnumerable<ReadOnlyMemory<byte>> data, DateTime timeStamp)

src/SharpRTSPClient/SharpRTSPClient.csproj

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,30 @@
88
<PackageReference Include="SharpRTSP" Version="1.4.3" />
99
</ItemGroup>
1010

11+
<PropertyGroup>
12+
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
13+
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
14+
<Nullable>disable</Nullable>
15+
<Title>$(ProjectName)</Title>
16+
<Version>0.0.1</Version>
17+
<Authors>Lukas Volf</Authors>
18+
<Copyright>MIT</Copyright>
19+
<PackageProjectUrl>https://github.com/jimm98y/SharpRealTimeStreaming</PackageProjectUrl>
20+
<PackageReadmeFile>README.md</PackageReadmeFile>
21+
<RepositoryUrl>https://github.com/jimm98y/SharpRealTimeStreaming</RepositoryUrl>
22+
<RepositoryType>git</RepositoryType>
23+
<PackageTags>rtsp;rtp;video;streaming;h264;h265;aac;netstandard20</PackageTags>
24+
<NeutralLanguage>en-US</NeutralLanguage>
25+
<AssemblyVersion>1.0.0</AssemblyVersion>
26+
<FileVersion>$(Version)</FileVersion>
27+
<PackageLicenseExpression>MIT</PackageLicenseExpression>
28+
<Description>Simple RTSP client. Supports H264, H265 and AAC.</Description>
29+
</PropertyGroup>
30+
<ItemGroup>
31+
<None Include="..\..\README.md">
32+
<Pack>True</Pack>
33+
<PackagePath>\</PackagePath>
34+
</None>
35+
</ItemGroup>
36+
1137
</Project>

src/SharpRTSPServer/SharpRTSPServer.csproj

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,30 @@
88
<PackageReference Include="SharpRTSP" Version="1.4.3" />
99
</ItemGroup>
1010

11+
<PropertyGroup>
12+
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
13+
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
14+
<Nullable>disable</Nullable>
15+
<Title>$(ProjectName)</Title>
16+
<Version>0.0.1</Version>
17+
<Authors>Lukas Volf</Authors>
18+
<Copyright>MIT</Copyright>
19+
<PackageProjectUrl>https://github.com/jimm98y/SharpRealTimeStreaming</PackageProjectUrl>
20+
<PackageReadmeFile>README.md</PackageReadmeFile>
21+
<RepositoryUrl>https://github.com/jimm98y/SharpRealTimeStreaming</RepositoryUrl>
22+
<RepositoryType>git</RepositoryType>
23+
<PackageTags>rtsp;rtp;video;streaming;h264;h265;aac;netstandard20</PackageTags>
24+
<NeutralLanguage>en-US</NeutralLanguage>
25+
<AssemblyVersion>1.0.0</AssemblyVersion>
26+
<FileVersion>$(Version)</FileVersion>
27+
<PackageLicenseExpression>MIT</PackageLicenseExpression>
28+
<Description>Simple RTSP server. Supports H264, H265 and AAC.</Description>
29+
</PropertyGroup>
30+
<ItemGroup>
31+
<None Include="..\..\README.md">
32+
<Pack>True</Pack>
33+
<PackagePath>\</PackagePath>
34+
</None>
35+
</ItemGroup>
36+
1137
</Project>

0 commit comments

Comments
 (0)