Skip to content

Commit 6cae27d

Browse files
author
Paulo Morgado
committed
Implement turns
1 parent b1963c2 commit 6cae27d

File tree

1,654 files changed

+23011
-233109
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,654 files changed

+23011
-233109
lines changed

.editorconfig

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,28 @@ csharp_preserve_single_line_statements = true
2424
csharp_preserve_single_line_blocks = true
2525

2626
# Don't allow single line if/else blocks without braces.
27-
csharp_prefer_braces = true:error
27+
csharp_prefer_braces = true:error
28+
29+
# IDE0007: Use implicit type
30+
dotnet_diagnostic.IDE0007.severity = suggestion
31+
32+
# IDE0019: Use pattern matching
33+
dotnet_diagnostic.IDE0019.severity = suggestion
34+
35+
# IDE0030: Use coalesce expression
36+
dotnet_diagnostic.IDE0030.severity = suggestion
37+
38+
# IDE0031: Use null propagation
39+
dotnet_diagnostic.IDE0031.severity = suggestion
40+
41+
# IDE0078: Use pattern matching
42+
dotnet_diagnostic.IDE0078.severity = suggestion
43+
44+
# IDE0083: Use pattern matching
45+
dotnet_diagnostic.IDE0083.severity = suggestion
46+
47+
# Default severity for analyzer diagnostics with category 'Performance'
48+
dotnet_analyzer_diagnostic.category-Style.severity = suggestion
49+
50+
# Default severity for analyzer diagnostics with category 'Style'
51+
dotnet_analyzer_diagnostic.category-Performance.severity = suggestion
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# License
2+
3+
## 1. BSD 3-Clause "New" or "Revised" License
4+
5+
Copyright (c) 2020–2025 Aaron Clauson
6+
All rights reserved.
7+
8+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
9+
10+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
11+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
12+
3. Neither the name “SIP Sorcery,” nor “Aaron Clauson,” nor the names of any contributors may be used to endorse or promote products derived from this software without specific prior written permission.
13+
14+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15+
16+
---
17+
18+
## 2. Additional Restriction: Boycott, Divestment, Sanctions (BDS) – Attribution-NonCommercial-ShareAlike
19+
20+
**Boycott Divestment Sanctions – Attribution-NonCommercial-ShareAlike (BDS BY-NC-SA)**
21+
22+
This software **must not be used** to further the Apartheid policies of Israel. Use, modification, or distribution **inside** Israel and the Occupied Territories is strictly forbidden until the demands of the Boycott, Divestment and Sanctions movement have been met:
23+
24+
* Israel has ended the occupation and colonization of all Arab lands occupied in 1967 and dismantled the Wall;
25+
* Arab-Palestinian citizens of Israel have been granted full equality; and
26+
* Palestinian refugees have obtained the right to return to their homes and properties as stipulated in UN Resolution 194.
27+
28+
For all other geographic regions **outside** of Israel and the Occupied Territories, use, modification, and distribution are permitted under the terms of the **BSD 3-Clause "New" or "Revised" License** above (Section 1), provided that any future use, modification, or distribution carries the above BDS restriction and abides by the ShareAlike and NonCommercial principles.
29+
30+
This restriction is **not** intended to limit the rights of Israelis or any other people residing outside of Israel and the Occupied Territories.
31+
32+
In any instance where the BSD 3-Clause License conflicts with the above restriction, the above restriction shall be interpreted as superior, and all other non-conflicting provisions of the BSD 3-Clause license shall remain in effect.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# SIPSorceryMedia.Abstractions
2+
3+
This project provides the logic for the interfaces required by the [SIPSorcery](https://github.com/sipsorcery-org/sipsorcery) real-time communications library and the components that provide functions such as:
4+
5+
- Access to audio or video devices (example [SIPSorceryMedia.Windows](https://github.com/sipsorcery-org/SIPSorceryMedia.Windows)).
6+
- Access to codecs from native libraries (examples [SIPSorceryMedia.Encoders](https://github.com/sipsorcery-org/SIPSorceryMedia.Encoders) and [SIPSorceryMedia.FFmpeg](https://github.com/sipsorcery-org/SIPSorceryMedia.FFmpeg)).
7+
8+
# Important Interfaces
9+
10+
The most important interfacs contained in this library are:
11+
12+
- IAudioEncoder: Needs to be implemented by classes that provide audio decoding and/or encoding. An example is the [AudioEncoder](https://github.com/sipsorcery-org/sipsorcery/blob/master/src/app/Media/Codecs/AudioEncoder.cs) class.
13+
14+
- IVideoEncoder: Needs to be implemented by classes that provide video decoding and/or encoding. An example is the [VpxVideoEncoder](https://github.com/sipsorcery-org/SIPSorceryMedia.Encoders/blob/master/src/VpxVideoEncoder.cs#L25) class.
15+
16+
- IAudioSource: Needs to be implemented by classes that act as a source of raw audio samples. Typically a microphone. An example is the [WindowsAudioEndPoint](https://github.com/sipsorcery-org/SIPSorceryMedia.Windows/blob/master/src/WindowsAudioEndPoint.cs#L32) class.
17+
18+
- IAudioSink: Needs to be implemented by classes that act as a sink for raw audio samples. Typically an audio speaker. An example is the [WindowsAudioEndPoint](https://github.com/sipsorcery-org/SIPSorceryMedia.Windows/blob/master/src/WindowsAudioEndPoint.cs#L32) class.
19+
20+
- IVideoSource: Needs to be implemented by classes that act as a source of raw video frames. Typically a webcam. An examples is the [WindowsVideoEndPoint](https://github.com/sipsorcery-org/SIPSorceryMedia.Windows/blob/master/src/WindowsVideoEndPoint.cs#L48).
21+
22+
- IVideoSink: Needs to be implemented by classes that act as a sink for raw video frames. The video sink is usually a bitmap or some kind of graphics surface. An examples is the [WindowsVideoEndPoint](https://github.com/sipsorcery-org/SIPSorceryMedia.Windows/blob/master/src/WindowsVideoEndPoint.cs#L48).
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//-----------------------------------------------------------------------------
2+
// Filename: IAudioEncoder.cs
3+
//
4+
// Description: Common interface for an audio codec.
5+
//
6+
// Author(s):
7+
// Aaron Clauson ([email protected])
8+
//
9+
// History:
10+
// 20 May 2025 Aaron Clauson Refactored from MediaEndPoints.
11+
//
12+
// License:
13+
// BSD 3-Clause "New" or "Revised" License and the additional
14+
// BDS BY-NC-SA restriction, see included LICENSE.md file.
15+
//-----------------------------------------------------------------------------
16+
17+
using System;
18+
using System.Buffers;
19+
using System.Collections.Generic;
20+
21+
namespace SIPSorceryMedia.Abstractions;
22+
23+
public interface IAudioEncoder
24+
{
25+
/// <summary>
26+
/// Needs to be set with the list of audio formats that the encoder supports.
27+
/// </summary>
28+
List<AudioFormat> SupportedFormats { get; }
29+
30+
/// <summary>
31+
/// Encodes 16bit signed PCM samples.
32+
/// </summary>
33+
/// <param name="pcm">An array of 16 bit signed audio samples.</param>
34+
/// <param name="format">The audio format to encode the PCM sample to.</param>
35+
/// <returns>A byte array containing the encoded sample.</returns>
36+
byte[] EncodeAudio(short[] pcm, AudioFormat format);
37+
38+
/// <summary>
39+
/// Encodes 16bit signed PCM samples.
40+
/// </summary>
41+
/// <param name="pcm">An array of 16 bit signed audio samples.</param>
42+
/// <param name="format">The audio format to encode the PCM sample to.</param>
43+
/// <param name="destination">A <see cref="IBufferWriter{T}"/> of <see langword="byte"/> to receieve the encoded sample.</param>
44+
void EncodeAudio(ReadOnlySpan<short> pcm, AudioFormat format, IBufferWriter<byte> destination);
45+
46+
/// <summary>
47+
/// Decodes to 16bit signed PCM samples.
48+
/// </summary>
49+
/// <param name="encodedSample">The byte array containing the encoded sample.</param>
50+
/// <param name="format">The audio format of the encoded sample.</param>
51+
/// <returns>An array containing the 16 bit signed PCM samples.</returns>
52+
short[] DecodeAudio(byte[] encodedSample, AudioFormat format);
53+
54+
/// <summary>
55+
/// Decodes to 16bit signed PCM samples.
56+
/// </summary>
57+
/// <param name="encodedSample">The span containing the encoded sample.</param>
58+
/// <param name="format">The audio format of the encoded sample.</param>
59+
/// <param name="destination">A <see cref="IBufferWriter{T}"/> of <see langword="short"/> to receive the decoded PCM samples.</param>
60+
void DecodeAudio(ReadOnlySpan<byte> encodedSample, AudioFormat format, IBufferWriter<short> destination);
61+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//-----------------------------------------------------------------------------
2+
// Filename: ITextEncoder.cs
3+
//
4+
// Description: Common interface for a text codec.
5+
//
6+
// Author(s):
7+
// Aaron Clauson ([email protected])
8+
//
9+
// History:
10+
// 20 May 2025 Aaron Clauson Refactored from MediaEndPoints.
11+
//
12+
// License:
13+
// BSD 3-Clause "New" or "Revised" License and the additional
14+
// BDS BY-NC-SA restriction, see included LICENSE.md file.
15+
//-----------------------------------------------------------------------------
16+
17+
namespace SIPSorceryMedia.Abstractions;
18+
19+
public interface ITextEncoder
20+
{
21+
/// <summary>
22+
/// Encode a text into a byte array.
23+
/// </summary>
24+
/// <param name="text">A symbol or text to be transmitted</param>
25+
/// <param name="format">The text format of the sample.</param>
26+
/// <returns>A byte array containing the encoded text sample</returns>
27+
byte[] EncodeText(char[] text, TextFormat format);
28+
29+
/// <summary>
30+
/// Decode a byte array into a string type text.
31+
/// </summary>
32+
/// <param name="encodedSample">A symbol or text that was received</param>
33+
/// <param name="format">The text format of the sample.</param>
34+
/// <returns></returns>
35+
char[] DecodeText(byte[] encodedSample, TextFormat format);
36+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//-----------------------------------------------------------------------------
2+
// Filename: IVideoEncoder.cs
3+
//
4+
// Description: Common interface for a video codec.
5+
//
6+
// Author(s):
7+
// Aaron Clauson ([email protected])
8+
//
9+
// History:
10+
// 20 May 2025 Aaron Clauson Refactored from MediaEndPoints.
11+
//
12+
// License:
13+
// BSD 3-Clause "New" or "Revised" License and the additional
14+
// BDS BY-NC-SA restriction, see included LICENSE.md file.
15+
//-----------------------------------------------------------------------------
16+
17+
using System;
18+
using System.Collections.Generic;
19+
20+
namespace SIPSorceryMedia.Abstractions;
21+
22+
public interface IVideoEncoder : IDisposable
23+
{
24+
/// <summary>
25+
/// Needs to be set with the list of video formats that the encoder supports.
26+
/// </summary>
27+
List<VideoFormat> SupportedFormats { get; }
28+
29+
byte[] EncodeVideo(int width, int height, byte[] sample, VideoPixelFormatsEnum pixelFormat, VideoCodecsEnum codec);
30+
31+
byte[] EncodeVideoFaster(RawImage rawImage, VideoCodecsEnum codec); // Avoid to use byte[] to improve performance
32+
33+
void ForceKeyFrame();
34+
35+
IEnumerable<VideoSample> DecodeVideo(byte[] encodedSample, VideoPixelFormatsEnum pixelFormat, VideoCodecsEnum codec);
36+
37+
IEnumerable<RawImage> DecodeVideoFaster(byte[] encodedSample, VideoPixelFormatsEnum pixelFormat, VideoCodecsEnum codec); // Avoid to use byte[] to improve performance
38+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
//-----------------------------------------------------------------------------
2+
// Filename: RawImage.cs
3+
//
4+
// Description: A raw image for use with a video codec.
5+
//
6+
// Author(s):
7+
// Aaron Clauson ([email protected])
8+
//
9+
// History:
10+
// 20 May 2025 Aaron Clauson Refactored from MediaEndPoints.
11+
//
12+
// License:
13+
// BSD 3-Clause "New" or "Revised" License and the additional
14+
// BDS BY-NC-SA restriction, see included LICENSE.md file.
15+
//-----------------------------------------------------------------------------
16+
17+
using System;
18+
using System.Runtime.InteropServices;
19+
20+
namespace SIPSorceryMedia.Abstractions;
21+
22+
public class RawImage
23+
{
24+
/// <summary>
25+
/// The width, in pixels, of the image
26+
/// </summary>
27+
public int Width { get; set; }
28+
29+
/// <summary>
30+
/// The height, in pixels, of the image
31+
/// </summary>
32+
public int Height { get; set; }
33+
34+
/// <summary>
35+
/// Integer that specifies the byte offset between the beginning of one scan line and the next.
36+
/// </summary>
37+
public int Stride { get; set; }
38+
39+
/// <summary>
40+
/// Pointer to an array of bytes that contains the pixel data.
41+
/// </summary>
42+
public nint Sample { get; set; }
43+
44+
/// <summary>
45+
/// The pixel format of the image
46+
/// </summary>
47+
public VideoPixelFormatsEnum PixelFormat { get; set; }
48+
49+
/// <summary>
50+
/// Get bytes array of the image.
51+
///
52+
/// For performance reasons it's better to use directly Sample
53+
/// </summary>
54+
/// <returns></returns>
55+
public byte[] GetBuffer()
56+
{
57+
byte[] result = null;
58+
59+
if ((Height > 0) && (Stride > 0))
60+
{
61+
var bufferSize = Height * Stride;
62+
63+
result = new byte[bufferSize];
64+
Marshal.Copy(Sample, result, 0, bufferSize);
65+
}
66+
return result;
67+
}
68+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//-----------------------------------------------------------------------------
2+
// Filename: VideoSample.cs
3+
//
4+
// Description: Representation of an unencoded video sample.
5+
//
6+
// Author(s):
7+
// Aaron Clauson ([email protected])
8+
//
9+
// History:
10+
// 20 May 2025 Aaron Clauson Refactored from MediaEndPoints.
11+
//
12+
// License:
13+
// BSD 3-Clause "New" or "Revised" License and the additional
14+
// BDS BY-NC-SA restriction, see included LICENSE.md file.
15+
//-----------------------------------------------------------------------------
16+
17+
namespace SIPSorceryMedia.Abstractions;
18+
19+
public struct VideoSample
20+
{
21+
public uint Width;
22+
public uint Height;
23+
public byte[] Sample;
24+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[assembly: global::NetEscapades.EnumGenerators.EnumExtensions<global::SIPSorceryMedia.Abstractions.AudioSamplingRatesEnum>()]
2+
[assembly: global::NetEscapades.EnumGenerators.EnumExtensions<global::SIPSorceryMedia.Abstractions.VideoPixelFormatsEnum>()]
3+
[assembly: global::NetEscapades.EnumGenerators.EnumExtensions<global::SIPSorceryMedia.Abstractions.SDPWellKnownMediaFormatsEnum>()]
4+
[assembly: global::NetEscapades.EnumGenerators.EnumExtensions<global::SIPSorceryMedia.Abstractions.AudioCodecsEnum>()]
5+
[assembly: global::NetEscapades.EnumGenerators.EnumExtensions<global::SIPSorceryMedia.Abstractions.VideoCodecsEnum>()]
6+
[assembly: global::NetEscapades.EnumGenerators.EnumExtensions<global::SIPSorceryMedia.Abstractions.TextCodecsEnum>()]
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//-----------------------------------------------------------------------------
2+
// Filename: AudioCodecsEnum.cs
3+
//
4+
// Description: Enum for common audio codecs.
5+
//
6+
// Author(s):
7+
// Aaron Clauson ([email protected])
8+
//
9+
// History:
10+
// 20 May 2025 Aaron Clauson Refactored from MediaEndPoints.
11+
//
12+
// License:
13+
// BSD 3-Clause "New" or "Revised" License and the additional
14+
// BDS BY-NC-SA restriction, see included LICENSE.md file.
15+
//-----------------------------------------------------------------------------
16+
17+
namespace SIPSorceryMedia.Abstractions;
18+
19+
public enum AudioCodecsEnum
20+
{
21+
Unknown,
22+
23+
PCMU,
24+
GSM,
25+
G723,
26+
DVI4,
27+
LPC,
28+
PCMA,
29+
G722,
30+
L16,
31+
QCELP,
32+
CN,
33+
MPA,
34+
G728,
35+
G729,
36+
OPUS,
37+
38+
PCM_S16LE, // PCM signed 16-bit little-endian (equivalent to FFmpeg s16le). For use with Azure, not likely to be supported in VoIP/WebRTC.
39+
}

0 commit comments

Comments
 (0)