This article covers the OnFrameSafe event of the IMEventsFrame interface, explaining how it is triggered, what parameters it provides, and how to safely handle incoming audio and video frames in MFormats and WebRTC workflows. It includes syntax, parameter descriptions, and practical usage examples for integrating frame-based event handling into real-time applications.
Methods
OnFrameSafe
Event triggered when a new video or audio frame is received safely. This event is raised from the SDK's internal thread and guarantees thread-safe access to the frame.
Syntax
event IMEventsFrame_OnFrameSafeEventHandler OnFrameSafeParameters
| Parameter | Description |
|---|---|
| _bsID | Identifier of the channel or source that produced the frame. |
| _pFrame | The received frame or audio/video buffer, provided as an object. Typically cast MFFrame for further processing. |
Example:
public class FrameReceiver
{
private readonly MCChannelClass _channel;
public FrameReceiver(MCChannelClass channel)
{
_channel = channel;
// Subscribe to safe frame event
_channel.OnFrameSafe += Channel_OnFrameSafe;
}
private void Channel_OnFrameSafe(string bsID, object pFrameObj)
{
if (pFrameObj is MFFrame frame)
{
// Example: display in preview
m_objPreview.ReceiverFramePut(frame, -1);
// Example: forward to WebRTC channel
currentChannel.ChannelSend(-1, frame, "");
// Release COM object
System.Runtime.InteropServices.Marshal.ReleaseComObject(frame);
}
}
}