Created
October 27, 2020 12:09
-
-
Save sipsorcery/c0b0d03b1c830471131a456a35d33458 to your computer and use it in GitHub Desktop.
SIPSorcery: Manually connect RTPSession to Audio Source
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Threading; | |
using System.Threading.Tasks; | |
using SIPSorcery.Media; | |
using SIPSorcery.Net; | |
using SIPSorcery.SIP; | |
using SIPSorcery.SIP.App; | |
using SIPSorceryMedia.Abstractions.V1; | |
namespace CustomAudioSession | |
{ | |
class Program | |
{ | |
static async Task Main() | |
{ | |
CancellationTokenSource exitCts = new CancellationTokenSource(); | |
var sipTransport = new SIPTransport(); | |
var userAgent = new SIPUserAgent(sipTransport, null); | |
userAgent.ClientCallFailed += (uac, error, sipResponse) => Console.WriteLine($"Call failed {error}."); | |
userAgent.OnCallHungup += (dialog) => exitCts.Cancel(); | |
RTPSession rtpSession = new RTPSession(false, false, false); | |
var audioTrack = new MediaStreamTrack(new AudioFormat(SDPWellKnownMediaFormatsEnum.PCMA)); | |
rtpSession.addTrack(audioTrack); | |
var callResult = await userAgent.Call("[email protected]:6060", null, null, rtpSession); | |
if (callResult) | |
{ | |
Console.WriteLine("Call Answered."); | |
AudioExtrasSource dummySource = new AudioExtrasSource(); | |
dummySource.SetAudioSourceFormat(rtpSession.GetSendingFormat(SDPMediaTypesEnum.audio).ToAudioFormat()); | |
dummySource.OnAudioSourceEncodedSample += rtpSession.SendAudio; | |
dummySource.SetSource(AudioSourcesEnum.Music); | |
Console.WriteLine("press ctrl-c to exit..."); | |
exitCts.Token.WaitHandle.WaitOne(); | |
} | |
else | |
{ | |
Console.WriteLine("Call Failed."); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment