Skip to content

Commit

Permalink
Update style and solve some warning
Browse files Browse the repository at this point in the history
  • Loading branch information
ngraziano committed Nov 15, 2024
1 parent 3d96c13 commit f9373ae
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 23 deletions.
4 changes: 2 additions & 2 deletions RTSP/Messages/RTSPMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static RtspMessage GetRtspMessage(string aRequestLine)
// We can't determine the message
if (string.IsNullOrEmpty(aRequestLine))
return new RtspMessage();

var requestParts = aRequestLine.Split(' ', 3);
RtspMessage returnValue;
if (requestParts.Length == 3)
Expand Down Expand Up @@ -253,7 +253,7 @@ public override string ToString()

return stringBuilder.ToString();
}

public override object Clone()
{
RtspMessage returnValue = GetRtspMessage(Command);
Expand Down
12 changes: 6 additions & 6 deletions RtspCameraExample/RtspServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public class RtspServer : IDisposable
private readonly NetworkCredential credential;
private readonly Authentication? auth;

private bool _useRTSPS = false;
private string _pfxFile = "";
private readonly bool _useRTSPS = false;
private readonly string _pfxFile = "";

/// <summary>
/// Initializes a new instance of the <see cref="RTSPServer"/> class.
Expand Down Expand Up @@ -100,7 +100,7 @@ public RtspServer(int portNumber, string username, string password, string pfxFi
{
if (string.IsNullOrEmpty(pfxFile))
{
throw new ArgumentOutOfRangeException("PFX File must not be null or empty for RTSPS mode");
throw new ArgumentOutOfRangeException(nameof(pfxFile), "PFX File must not be null or empty for RTSPS mode");
}
_useRTSPS = true;
_pfxFile = pfxFile;
Expand Down Expand Up @@ -139,7 +139,7 @@ private void AcceptConnection()
}
else
{
var certificate = new X509Certificate2(_pfxFile);
var certificate = X509CertificateLoader.LoadPkcs12FromFile(_pfxFile, "");
rtsp_socket = new RtspTcpTlsTransport(oneClient, certificate); // NOTE - we can add a callback where we can validate the TLS Certificates here
}

Expand Down Expand Up @@ -594,10 +594,10 @@ public void FeedInRawNAL(uint timestamp_ms, List<byte[]> nal_array)
// ToArray makes a temp copy of the list.
// This lets us delete items in the foreach
// eg when there is Write Error
rtspConnectionListCopy = rtspConnectionList.ToArray();
rtspConnectionListCopy = [.. rtspConnectionList];
}
// Go through each RTSP connection and output the NAL on the Video Session
var tasks = rtspConnectionList.Select(async (connection) =>
var tasks = rtspConnectionListCopy.Select(async (connection) =>
{
// Only process Sessions in Play Mode
if (!connection.play) return;
Expand Down
33 changes: 18 additions & 15 deletions RtspCameraExample/TestCard.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
using System;
namespace RtspCameraExample;

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Globalization;
using System.Threading;

// (c) Roger Hardiman 2016, 2021

Expand All @@ -21,19 +24,18 @@ public class TestCard
public delegate void ReceivedAudioFrameHandler(uint timestamp, short[] data);

// Local variables
private Stopwatch stopwatch;
private System.Timers.Timer frame_timer;
private readonly Stopwatch stopwatch;
private readonly System.Timers.Timer frame_timer;
private readonly byte[] yuv_frame;
private int x_position = 0;
private int y_position = 0;
private int fps = 0;
private int width = 0;
private int height = 0;
private readonly object generate_lock = new();
private readonly int width = 0;
private readonly int height = 0;
private readonly Lock generate_lock = new();
private long frame_count = 0;

private System.Timers.Timer audio_timer;
private int audio_duration_ms = 20; // duration of sound samples for mono PCM audio. Hinted at in origial RTP standard from 1996 that mentions 160 audio samples
private readonly System.Timers.Timer audio_timer;
private readonly int audio_duration_ms = 20; // duration of sound samples for mono PCM audio. Hinted at in origial RTP standard from 1996 that mentions 160 audio samples
private long audio_count = 0;

// ASCII Font
Expand Down Expand Up @@ -61,7 +63,6 @@ public TestCard(int width, int height, int fps)
{
this.width = width;
this.height = height;
this.fps = fps;

// YUV size
int y_size = width * height;
Expand Down Expand Up @@ -98,9 +99,11 @@ public TestCard(int width, int height, int fps)
frame_timer.Start();

// Start timer. The Timer will generate each Audio frame
audio_timer = new System.Timers.Timer();
audio_timer.Interval = 1; // on first pass timer will fire straight away (cannot have zero interval)
audio_timer.AutoReset = false; // do not restart timer after the time has elapsed
audio_timer = new System.Timers.Timer
{
Interval = 1, // on first pass timer will fire straight away (cannot have zero interval)
AutoReset = false // do not restart timer after the time has elapsed
};
audio_timer.Elapsed += (object? sender, System.Timers.ElapsedEventArgs e) =>
{
// send an audio frame
Expand Down Expand Up @@ -243,11 +246,11 @@ private void Send_Audio_Frame()
long currentSeconds = (timestamp_ms / 1000);
long currentMilliSeconds = timestamp_ms % 1000;

int soundToPlay = 0; // 0 = silence
int soundToPlay;
if (((currentSeconds % 60) == 0) && (currentMilliSeconds < 300)) soundToPlay = 1;
else if (((currentSeconds % 10) == 0) && (currentMilliSeconds < 100)) soundToPlay = 1;
else if (((currentSeconds % 10) != 0) && (currentMilliSeconds < 100)) soundToPlay = 2;
else soundToPlay = 0;
else soundToPlay = 0; // 0 = silence

// Add the sound
for (int i = 0; i < audio_frame.Length; i++)
Expand Down

0 comments on commit f9373ae

Please sign in to comment.