Skip to content

Feature/ffmpeg video endpoint source#1694

Merged
sipsorcery merged 6 commits into
masterfrom
feature/ffmpeg-video-endpoint-source
Jun 8, 2026
Merged

Feature/ffmpeg video endpoint source#1694
sipsorcery merged 6 commits into
masterfrom
feature/ffmpeg-video-endpoint-source

Conversation

@sipsorcery

Copy link
Copy Markdown
Member

No description provided.

sipsorcery and others added 4 commits June 8, 2026 16:29
FFmpegVideoEndPoint was declared IVideoSink only, with the source/encode
half left commented out - inconsistent with the other video endpoints
(Vp8NetVideoEncoderEndPoint and WindowsVideoEndPoint), which implement
both IVideoSource and IVideoSink so one class encodes outgoing and decodes
incoming media for the same codec.

This completes the source half:
 - declares IVideoSource as well as IVideoSink;
 - ExternalVideoSourceRawSample / ExternalVideoSourceRawSampleFaster now
   encode the supplied raw frame via the encoder's managed EncodeVideo /
   EncodeVideoFaster and raise OnVideoSourceEncodedSample (with a shared
   RaiseEncodedSample helper computing the RTP duration from the selected
   format's clock rate);
 - adds the source events (OnVideoSourceEncodedSample raised; the raw and
   error events are part of the contract but not produced by an encoder);
 - ForceKeyFrame now delegates to the encoder's own ForceKeyFrame (which
   the encode path honours) instead of a dead local flag;
 - HasEncodedVideoSubscribers reports OnVideoSourceEncodedSample
   subscribers (it previously, incorrectly, reported the sink event);
 - ToMediaEndPoints now exposes VideoSource = this.

The single FFmpegVideoEncoder instance handles both directions (separate
encode/decode contexts internally). The change is additive; existing
sink-only consumers are unaffected. WebRTCDaemon already wires the
endpoint's ExternalVideoSourceRawSample, confirming the intended usage.

Builds across all target frameworks. Not unit-tested here as the encode
path requires the native FFmpeg libraries at runtime.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
_videoDecoder?.Pause();
if (_videoDecoder != null)
{
_videoDecoder?.Pause();

double firts_dpts = 0;
bool canContinue = true;
bool managePacket = true;
if (firts_dpts == 0)
firts_dpts = dpts;
dpts = _audioTimebase * avFrame->pts;
original_dpts = dpts;
if (ffmpeg.avformat_seek_file(_fmtCtx, _audioStreamIndex, 0, 0, _fmtCtx->streams[_audioStreamIndex]->duration, ffmpeg.AVSEEK_FLAG_ANY) < 0)
{
// We can't easily go back to the beginning of the file ...
canContinue = false;
}
catch { }
}
catch { }
}
catch { }
}
catch { }
private Task? _sourceTask;
private string _sourceUrl;
private bool _repeat;
private bool _isMicrophone;
public class FFmpegAudioDecoder : IDisposable
{
private ILogger logger = SIPSorcery.LogFactory.CreateLogger<FFmpegAudioDecoder>();
private ILogger logger = SIPSorcery.LogFactory.CreateLogger<FFmpegAudioDecoder>();
private ILogger logger = SIPSorcery.LogFactory.CreateLogger<FFmpegAudioDecoder>();

unsafe private AVInputFormat* _inputFormat = null;
unsafe private AVInputFormat* _inputFormat = null;
sipsorcery and others added 2 commits June 8, 2026 22:37
# Conflicts:
#	src/SIPSorceryMedia.FFmpeg/FFmpegAudioDecoder.cs
#	src/SIPSorceryMedia.FFmpeg/FFmpegFileSource.cs
#	src/SIPSorceryMedia.FFmpeg/FFmpegVideoEndPoint.cs
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
@sipsorcery sipsorcery merged commit 8023d2f into master Jun 8, 2026
8 checks passed
@sipsorcery sipsorcery deleted the feature/ffmpeg-video-endpoint-source branch June 8, 2026 21:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant