Skip to content

Latest commit

 

History

History
116 lines (85 loc) · 4.14 KB

File metadata and controls

116 lines (85 loc) · 4.14 KB

SIPSorceryMedia.Windows

NuGet NuGet downloads

Windows-specific audio capture, audio playback, and video capture end-points for the SIPSorcery real-time communications library. Built on NAudio for audio and Windows Media Foundation for video.

Use this package when:

  • You're targeting Windows and want microphone / speaker / webcam access without pulling in FFmpeg.
  • You need a quick way to give a SIPSorcery RTPSession something to send audio from and play received audio into.

For cross-platform audio + video, use SIPSorceryMedia.FFmpeg instead.

Platform support

  • Target: net10.0-windows10.0.17763.0 (Windows 10 1809+).
  • Runtime: Windows only -- the package PInvokes Windows-specific audio and video APIs.

Installation

dotnet add package SIPSorcery
dotnet add package SIPSorceryMedia.Windows

The SIPSorceryMedia.Abstractions interfaces this package implements come in transitively.

What is in here

Class Implements Purpose
WindowsAudioEndPoint IAudioEndPoint (source + sink) Microphone capture and speaker playback. Wraps NAudio's WaveInEvent and WaveOutEvent.
WindowsVideoEndPoint IVideoSource Webcam capture via Windows Media Foundation. Surfaces enumerated formats and resolutions.
WindowsAudioSession IAudioSession Convenience pairing of audio source + sink + encoder.

The audio end-point automatically resamples between the device's native sample rate and the codec's sample rate (e.g. 48 kHz device, 8 kHz G.711 codec).

Quickstart -- VoIP audio call

The simplest possible example: place an outbound SIP audio call and hear the audio through Windows speakers.

dotnet new console --name SIPGetStarted --framework net10.0-windows10.0.17763.0
cd SIPGetStarted
dotnet add package SIPSorcery
dotnet add package SIPSorceryMedia.Windows

Paste into Program.cs:

using SIPSorcery.Media;
using SIPSorcery.SIP.App;
using SIPSorceryMedia.Windows;

const string DESTINATION = "music@iptel.org";

var userAgent = new SIPUserAgent();
var winAudio  = new WindowsAudioEndPoint(new AudioEncoder());
var session   = new VoIPMediaSession(winAudio.ToMediaEndPoints());

bool ok = await userAgent.Call(DESTINATION, null, null, session);
Console.WriteLine($"Call result: {(ok ? "success" : "failure")}");

Console.WriteLine("Press any key to hangup.");
Console.ReadLine();

dotnet run -- you should hear the test audio.

Quickstart -- WebRTC video to a browser

The full sample lives at examples/WebRTCExamples/WebRTCGetStarted. Pair WindowsVideoEndPoint with a video encoder (SIPSorceryMedia.FFmpeg's FFmpegVideoEncoder, SIPSorcery.VP8, or a custom IVideoEncoder) and feed the encoded samples into RTCPeerConnection.SendVideo.

Audio sample rate notes

  • WindowsAudioEndPoint defaults to 8 kHz internal processing -- fine for narrow-band G.711 / G.722 codecs which are the most common in VoIP.
  • For wide-band Opus or 48 kHz codecs, construct the end-point with the higher sample rate so internal resampling is minimised: new WindowsAudioEndPoint(new AudioEncoder(), audioSampleRate: 48000).

Related packages

License

BSD 3-Clause License. See LICENSE at the repo root.