Skip to content

Commit 6f18122

Browse files
author
Paulo Morgado
committed
Enhance audio source interface and project configurations
- Added new using directives and an event for handling encoded audio samples in `MediaEndPoints.cs`. - Updated `SIPSorceryMedia.Abstractions.csproj` to set the language version to 12.0. - Modified `SIPSorceryMedia.Abstractions.UnitTest.csproj` to support multi-targeting for `net462` and `net8.0`, with conditional xUnit runner package references based on the target framework.
1 parent 808d9ce commit 6f18122

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-8
lines changed

src/MediaEndPoints.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System;
2+
using System.Buffers;
23
using System.Collections.Generic;
4+
using System.ComponentModel;
35
using System.Net;
46
using System.Runtime.InteropServices;
57
using System.Threading.Tasks;
@@ -164,7 +166,7 @@ public struct AudioFormat
164166
public const int DEFAULT_CHANNEL_COUNT = 1;
165167

166168
public static readonly AudioFormat Empty = new AudioFormat()
167-
{ _isNonEmpty = false, ClockRate = DEFAULT_CLOCK_RATE, ChannelCount = DEFAULT_CHANNEL_COUNT };
169+
{ _isNonEmpty = false, ClockRate = DEFAULT_CLOCK_RATE, ChannelCount = DEFAULT_CHANNEL_COUNT };
168170

169171
public AudioCodecsEnum Codec { get; set; }
170172

@@ -288,7 +290,7 @@ public AudioFormat(int formatID, string formatName, int clockRate, int rtpClockR
288290
{
289291
throw new ApplicationException($"The format name must be provided for an AudioFormat.");
290292
}
291-
else if(clockRate <= 0)
293+
else if (clockRate <= 0)
292294
{
293295
throw new ApplicationException($"The clock rate for an AudioFormat must be greater than 0.");
294296
}
@@ -329,7 +331,7 @@ public struct VideoFormat
329331
public const int DEFAULT_CLOCK_RATE = 90000;
330332

331333
public static readonly VideoFormat Empty = new VideoFormat()
332-
{ _isNonEmpty = false, ClockRate = DEFAULT_CLOCK_RATE };
334+
{ _isNonEmpty = false, ClockRate = DEFAULT_CLOCK_RATE };
333335

334336
public VideoCodecsEnum Codec { get; set; }
335337

@@ -544,6 +546,14 @@ public interface IAudioEncoder
544546
/// <returns>A byte array containing the encoded sample.</returns>
545547
byte[] EncodeAudio(short[] pcm, AudioFormat format);
546548

549+
/// <summary>
550+
/// Encodes 16bit signed PCM samples.
551+
/// </summary>
552+
/// <param name="pcm">An array of 16 bit signed audio samples.</param>
553+
/// <param name="format">The audio format to encode the PCM sample to.</param>
554+
/// <param name="destination">A <see cref="IBufferWriter{T}"/> of <see langword="byte"/> to receieve the encoded sample.</param>
555+
void EncodeAudio(ReadOnlySpan<short> pcm, AudioFormat format, IBufferWriter<byte> destination);
556+
547557
/// <summary>
548558
/// Decodes to 16bit signed PCM samples.
549559
/// </summary>
@@ -649,6 +659,8 @@ public interface IAudioSource
649659
{
650660
event EncodedSampleDelegate OnAudioSourceEncodedSample;
651661

662+
event Action<uint, ReadOnlyMemory<byte>> OnAudioSourceEncodedSampleEx;
663+
652664
event RawAudioSampleDelegate OnAudioSourceRawSample;
653665

654666
event SourceErrorDelegate OnAudioSourceError;

src/SIPSorceryMedia.Abstractions.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<PropertyGroup>
44
<PackageId>SIPSorceryMedia.Abstractions</PackageId>
55
<TargetFrameworks>netstandard2.0;netstandard2.1;netcoreapp3.1;net5.0;net8.0</TargetFrameworks>
6+
<LangVersion>12.0</LangVersion>
67
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
78
<GenerateDocumentationFile>true</GenerateDocumentationFile>
89
<!-- Disable warning for missing XML doc comments. -->

test/SIPSorceryMedia.Abstractions.UnitTest/SIPSorceryMedia.Abstractions.UnitTest.csproj

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net8</TargetFramework>
4+
<TargetFrameworks>net462;net8.0</TargetFrameworks>
55
<IsPackable>false</IsPackable>
66
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
77
</PropertyGroup>
@@ -11,10 +11,6 @@
1111
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
1212
<PackageReference Include="System.Drawing.Common" Version="9.0.0" />
1313
<PackageReference Include="xunit" Version="2.9.2" />
14-
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0">
15-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
16-
<PrivateAssets>all</PrivateAssets>
17-
</PackageReference>
1814
<PackageReference Include="coverlet.collector" Version="6.0.3">
1915
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2016
<PrivateAssets>all</PrivateAssets>
@@ -24,6 +20,20 @@
2420
<PackageReference Include="Serilog.Sinks.XUnit" Version="3.0.19" />
2521
</ItemGroup>
2622

23+
<ItemGroup Condition="'$(TargetFramework)' == 'net462'">
24+
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
25+
<PrivateAssets>all</PrivateAssets>
26+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
27+
</PackageReference>
28+
</ItemGroup>
29+
30+
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
31+
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0">
32+
<PrivateAssets>all</PrivateAssets>
33+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
34+
</PackageReference>
35+
</ItemGroup>
36+
2737
<ItemGroup>
2838
<ProjectReference Include="..\..\src\SIPSorceryMedia.Abstractions.csproj" />
2939
</ItemGroup>

0 commit comments

Comments
 (0)