Skip to content

Commit ddfa197

Browse files
authored
Merge pull request #22 from jimm98y/features/multiple-streams
F Added support for multiple streams
2 parents 1befb68 + 17c3613 commit ddfa197

File tree

14 files changed

+420
-241
lines changed

14 files changed

+420
-241
lines changed

src/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<Nullable>disable</Nullable>
66
<ImplicitUsings>disable</ImplicitUsings>
77
<Title>$(ProjectName)</Title>
8-
<Version>0.1.5</Version>
8+
<Version>0.2.0</Version>
99
<Authors>Lukas Volf</Authors>
1010
<Copyright>MIT</Copyright>
1111
<PackageProjectUrl>https://github.com/jimm98y/SharpRealTimeStreaming</PackageProjectUrl>

src/RTSPClientApp/appsettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"Uri": "rtsp://127.0.0.1:8554",
2+
"Uri": "rtsp://127.0.0.1:8554/stream1",
33
"UserName": "admin",
44
"Password": "password"
55
}

src/RTSPServerApp/RTSPServerWorker.cs

Lines changed: 177 additions & 123 deletions
Large diffs are not rendered by default.

src/RTSPServerApp/appsettings.json

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,22 @@
22
"RTSPServerApp": {
33
"HostName": "127.0.0.1",
44
"Port": 8554,
5-
"FilePath": "frag_bunny.mp4",
65
"UserName": "admin",
7-
"Password": "password"
6+
"Password": "password",
7+
"Media": [
8+
{
9+
"StreamID": "stream1",
10+
"FilePath": "frag_bunny.mp4"
11+
},
12+
{
13+
"StreamID": "stream2",
14+
"FilePath": "testV300.mp4"
15+
},
16+
{
17+
"StreamID": "stream3",
18+
"FilePath": "Images"
19+
}
20+
]
821
},
922
"Logging": {
1023
"LogLevel": {

src/RTSPServerFFmpeg/Program.cs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,33 +60,35 @@
6060
if (string.IsNullOrEmpty(videoUri) && string.IsNullOrEmpty(audioUri))
6161
throw new Exception("Invalid configuration! Either VideoUri, AudioUri or both must be specified!");
6262

63+
const string STREAM_ID = "stream1";
64+
6365
using (var server = new RTSPServer(port, userName, password))
6466
{
6567
using (CancellationTokenSource cts = new CancellationTokenSource())
6668
{
67-
ProxyTrack videoTrack = null;
68-
ProxyTrack audioTrack = null;
69+
ProxyTrack rtspVideoTrack = null;
70+
ProxyTrack rtspAudioTrack = null;
6971
Task videoTask = null;
7072
Task audioTask = null;
7173

7274
if (!string.IsNullOrEmpty(videoUri))
7375
{
74-
videoTrack = new ProxyTrack(TrackType.Video);
75-
videoTask = RunUdpClient(videoTrack, new Uri(videoUri, UriKind.Absolute), cts.Token);
76-
server.AddVideoTrack(videoTrack);
76+
rtspVideoTrack = new ProxyTrack(TrackType.Video);
77+
videoTask = RunUdpClient(rtspVideoTrack, new Uri(videoUri, UriKind.Absolute), cts.Token);
7778
}
7879

7980
if (!string.IsNullOrEmpty(audioUri))
8081
{
81-
audioTrack = new ProxyTrack(TrackType.Audio);
82-
audioTask = RunUdpClient(audioTrack, new Uri(audioUri, UriKind.Absolute), cts.Token);
83-
server.AddAudioTrack(audioTrack);
82+
rtspAudioTrack = new ProxyTrack(TrackType.Audio);
83+
audioTask = RunUdpClient(rtspAudioTrack, new Uri(audioUri, UriKind.Absolute), cts.Token);
8484
}
8585

86-
server.OverrideSDP(sdp, true);
86+
var streamSource = new RTSPStreamSource(STREAM_ID, rtspVideoTrack, rtspAudioTrack);
87+
streamSource.OverrideSDP(sdp, true);
88+
server.AddStreamSource(streamSource);
8789

88-
videoTrack?.Start();
89-
audioTrack?.Start();
90+
rtspVideoTrack?.Start();
91+
rtspAudioTrack?.Start();
9092

9193
try
9294
{
@@ -97,7 +99,7 @@
9799
Console.WriteLine(ex.ToString());
98100
}
99101

100-
Console.WriteLine($"RTSP URL is rtsp://{userName}:{password}@{hostName}:{port}");
102+
Console.WriteLine($"RTSP URL is rtsp://{userName}:{password}@{hostName}:{port}/{STREAM_ID}");
101103

102104
Console.WriteLine("Press any key to exit");
103105
while (!Console.KeyAvailable)

src/RTSPServerPcap/Program.cs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727

2828
bool _readNext = false;
2929
Stopwatch _stopwatch = new Stopwatch();
30-
ProxyTrack videoTrack = null;
31-
ProxyTrack audioTrack = null;
30+
ProxyTrack rtspVideoTrack = null;
31+
ProxyTrack rtspAudioTrack = null;
3232
var rtspProtocolParser = new RtspProtocolParser();
3333

3434
var sdpTask = Task.Run(() =>
@@ -48,20 +48,21 @@
4848
}
4949
});
5050

51+
const string STREAM_ID = "stream1";
52+
5153
using (var server = new RTSPServer(port, userName, password))
5254
{
5355
await rtspProtocolParser.Sempahore.WaitAsync();
5456

55-
server.OverrideSDP(rtspProtocolParser.SDP, true);
56-
57-
videoTrack = new ProxyTrack(TrackType.Video);
58-
server.AddVideoTrack(videoTrack);
57+
rtspVideoTrack = new ProxyTrack(TrackType.Video);
58+
rtspAudioTrack = new ProxyTrack(TrackType.Audio);
5959

60-
audioTrack = new ProxyTrack(TrackType.Audio);
61-
server.AddAudioTrack(audioTrack);
60+
var streamSource = new RTSPStreamSource(STREAM_ID, rtspVideoTrack, rtspAudioTrack);
61+
streamSource.OverrideSDP(rtspProtocolParser.SDP, true);
62+
server.AddStreamSource(streamSource);
6263

63-
videoTrack?.Start();
64-
audioTrack?.Start();
64+
rtspVideoTrack?.Start();
65+
rtspAudioTrack?.Start();
6566

6667
try
6768
{
@@ -72,7 +73,7 @@
7273
Console.WriteLine(ex.ToString());
7374
}
7475

75-
Console.WriteLine($"RTSP URL is rtsp://{userName}:{password}@{hostName}:{port}");
76+
Console.WriteLine($"RTSP URL is rtsp://{userName}:{password}@{hostName}:{port}/{STREAM_ID}");
7677

7778
Console.WriteLine("Press any key to exit");
7879
while (!Console.KeyAvailable)
@@ -132,7 +133,7 @@ void ParseData(byte[] data, object header, uint seconds, uint microseconds)
132133
{
133134
Thread.Sleep(sleep);
134135
}
135-
videoTrack?.FeedInRawSamples(RTPPacketUtil.ReadTS(data), new List<byte[]> { data });
136+
rtspVideoTrack?.FeedInRawSamples(RTPPacketUtil.ReadTS(data), new List<byte[]> { data });
136137
}
137138
else if(rtspProtocolParser.Ports.Count > 1 && rtspProtocolParser.Ports[1].Contains(udp.SourcePort) && rtspProtocolParser.Ports[1].Contains(udp.DestinationPort))
138139
{
@@ -149,7 +150,7 @@ void ParseData(byte[] data, object header, uint seconds, uint microseconds)
149150
Thread.Sleep(sleep);
150151
}
151152

152-
audioTrack?.FeedInRawSamples(RTPPacketUtil.ReadTS(data), new List<byte[]> { data });
153+
rtspAudioTrack?.FeedInRawSamples(RTPPacketUtil.ReadTS(data), new List<byte[]> { data });
153154
}
154155
}
155156
}

src/SharpRTSPClient/Payloads/AV1Payload.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class AV1Payload : IPayloadProcessor
2626
private DateTime _timestamp;
2727

2828
// Constructor
29-
public AV1Payload(ILogger<AV1Payload>? logger, MemoryPool<byte>? memoryPool = null)
29+
public AV1Payload(ILogger<AV1Payload> logger, MemoryPool<byte> memoryPool = null)
3030
{
3131
_logger = logger as ILogger ?? NullLogger.Instance;
3232
_memoryPool = memoryPool ?? MemoryPool<byte>.Shared;

src/SharpRTSPClient/Payloads/H266Payload.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class H266Payload : IPayloadProcessor
3333
private DateTime _timestamp;
3434

3535
// Constructor
36-
public H266Payload(bool hasDonl, ILogger<H266Payload>? logger, MemoryPool<byte>? memoryPool = null)
36+
public H266Payload(bool hasDonl, ILogger<H266Payload> logger, MemoryPool<byte> memoryPool = null)
3737
{
3838
this.hasDonl = hasDonl;
3939

src/SharpRTSPClient/Payloads/OpusPayload.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Rtsp.Rtp
88

99
public class OpusPayload : RawPayload
1010
{
11-
public OpusPayload(MemoryPool<byte>? memoryPool = null)
11+
public OpusPayload(MemoryPool<byte> memoryPool = null)
1212
: base(memoryPool)
1313
{
1414
}

src/SharpRTSPServer/IRtpSender.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace SharpRTSPServer
55
{
66
public interface IRtpSender
77
{
8-
void FeedInRawRTP(int streamType, uint rtpTimestamp, List<Memory<byte>> rtpPackets);
9-
bool CanAcceptNewSamples();
8+
void FeedInRawRTP(string streamID, int streamType, uint rtpTimestamp, List<Memory<byte>> rtpPackets);
9+
bool CanAcceptNewSamples(string streamID);
1010
}
1111
}

0 commit comments

Comments
 (0)