SIPSorceryMedia.FFmpeg icon indicating copy to clipboard operation
SIPSorceryMedia.FFmpeg copied to clipboard

Attempted to read or write protected memory. This is often an indication that other memory is corrupt.”

Open wobushiafa opened this issue 2 years ago • 1 comments

异常信息: 由于线程退出或应用程序请求,已中止 I/O 操作。 Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. at SIPSorceryMedia.FFmpeg.FFmpegVideoEncoder.DecodeFaster(FFmpeg.AutoGen.AVCodecID, FFmpeg.AutoGen.AVPacket*, Int32 ByRef, Int32 ByRef) at SIPSorceryMedia.FFmpeg.FFmpegVideoEncoder.DecodeFaster(FFmpeg.AutoGen.AVCodecID, Byte[], Int32 ByRef, Int32 ByRef) at SIPSorceryMedia.FFmpeg.FFmpegVideoEndPoint.GotVideoFrame(System.Net.IPEndPoint, UInt32, Byte[], SIPSorceryMedia.Abstractions.VideoFormat) at SIPSorcery.Net.RTPSession.RaisedOnOnVideoFrameReceived(Int32, System.Net.IPEndPoint, UInt32, Byte[], SIPSorceryMedia.Abstractions.VideoFormat) at SIPSorcery.net.RTP.VideoStream.ProcessVideoRtpFrame(System.Net.IPEndPoint, SIPSorcery.Net.RTPPacket, SIPSorcery.Net.SDPAudioVideoMediaFormat) at SIPSorcery.net.RTP.MediaStream.OnReceiveRTPPacket(SIPSorcery.Net.RTPHeader, Int32, System.Net.IPEndPoint, Byte[], SIPSorcery.net.RTP.VideoStream) at SIPSorcery.Net.RTPSession.OnReceiveRTPPacket(Int32, System.Net.IPEndPoint, Byte[]) at SIPSorcery.Net.RTPSession.OnReceive(Int32, System.Net.IPEndPoint, Byte[]) at SIPSorcery.Net.RTCPeerConnection.OnRTPDataReceived(Int32, System.Net.IPEndPoint, Byte[]) at SIPSorcery.Net.RtpIceChannel.OnRTPPacketReceived(SIPSorcery.Net.UdpReceiver, Int32, System.Net.IPEndPoint, Byte[]) at SIPSorcery.Net.UdpReceiver.CallOnPacketReceivedCallback(Int32, System.Net.IPEndPoint, Byte[]) at SIPSorcery.Net.UdpReceiver.EndReceiveFrom(System.IAsyncResult) at System.Runtime.CompilerServices.TaskAwaiter+<>c.<OutputWaitEtwEvents>b__12_0(System.Action, System.Threading.Tasks.Task) at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object) at System.Threading.Tasks.AwaitTaskContinuation.RunCallback(System.Threading.ContextCallback, System.Object, System.Threading.Tasks.Task ByRef) at System.Threading.Tasks.Task.RunContinuations(System.Object) at System.Threading.Tasks.ValueTask1+ValueTaskSourceAsTask+<>c[[System.Net.Sockets.SocketReceiveFromResult, System.Net.Sockets, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]].<.cctor>b__4_0(System.Object) at System.Net.Sockets.Socket+AwaitableSocketAsyncEventArgs.InvokeContinuation(System.Action1<System.Object>, System.Object, Boolean, Boolean) at System.Net.Sockets.Socket+AwaitableSocketAsyncEventArgs.OnCompleted(System.Net.Sockets.SocketAsyncEventArgs) at System.Net.Sockets.SocketAsyncEventArgs+<>c.<.cctor>b__176_0(UInt32, UInt32, System.Threading.NativeOverlapped*) at System.Threading.ThreadPoolTypedWorkItemQueue`2[[System.Threading.PortableThreadPool+IOCompletionPoller+Event, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Threading.PortableThreadPool+IOCompletionPoller+Callback, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].System.Threading.IThreadPoolWorkItem.Execute() at System.Threading.ThreadPoolWorkQueue.Dispatch() at System.Threading.PortableThreadPool+WorkerThread.WorkerThreadStart()

wobushiafa avatar Feb 06 '23 08:02 wobushiafa

I get the same error when calling VideoSource.StartVideo(). My code replicates this example from SipSorcery: https://github.com/sipsorcery-org/SIPSorceryMedia.FFmpeg/blob/master/test/FFmpegFileAndDevicesTest/Program.cs

Tried it with having VideoSource file at different locations on my local computer but all give the same System.AccessViolationException: "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

EDIT: was able to fix this issue by also including:

AudioSource.OnAudioSourceEncodedSample += AudioSource_OnAudioSourceEncodedSample;
RTCPeer.OnAudioFormatsNegotiated += (audioFormats) =>
{
    AudioSource.SetAudioSourceFormat(audioFormats.First());
};

This was necessary even without calling AudioSource.StartAudio()

maticcavalleri avatar Mar 17 '23 14:03 maticcavalleri