BogdanovKirill / RtspClientSharp

Pure C# RTSP client for .NET Standard without external dependencies and with true async nature. I welcome contributions.
MIT License
706 stars 284 forks source link

Timeout #52

Open norcino opened 4 years ago

norcino commented 4 years ago

I am not an expert of video streaming nor rtsp protocol, but I keep receiving timeout error when trying to access my cctv cameras, more specifically I can connect and receive frames but then I fail to create a decoder to view them. The same devices can be streamed from other tools including VLC.

To Reproduce I tried the SimpleRtspPlayer, I add the device address as whole and I tried to set username and password in the fields but this seems to be irrelevant. Once I click on "Start" and once connected I can see the message "Receiving frames...", after a bit "RtspClientSharp.Rtsp.RtspClientException: Receive timeout ---> System.TimeoutException: The operation has timed out.".

Other information Address format I use (same as VLC): rtsp://192.168.0.201:554/user=X_password=Y_channel=1_stream=0.sdp?real_stream

I tried to debug and it fails after invoking int resultCode = FFmpegVideoPInvoke.CreateVideoDecoder(videoCodecId, out IntPtr decoderPtr); in FFmpegVideoDecoder.cs. The codec id is H264.

Other applications I tried using "ONVIF Device Manager" and VLC, in both cases I could access the camera stream.

What can I do to try to fix the issue? What kind of information can I provide to you?

BogdanovKirill commented 4 years ago

Hello

Could you provide direct access to your camera?

norcino commented 4 years ago

I am trying to setup the firewall to expose the camera to the Internet but it looks like that TCP/UDP on 554 port is not enough (or maybe I am doing something wrong). I will update you as soon as I fix this.

norcino commented 4 years ago

@BogdanovKirill I failed to expose the camera to the internet, I even tried with DMZ, is there anything else we can do to investigate the issue?

BogdanovKirill commented 4 years ago

May be I could try to connect to your developer machine via teamviewer and help you. Write me bogdanov.kv@bk.ru

BogdanovKirill commented 4 years ago

Hello,

Please try RTSP over TCP

norcino commented 4 years ago

Hi

I tried, but I get the same result, this is the snippet of code I changed in MainWindowViewModel.cs

        connectionParameters.RtpTransport = RtpTransportProtocol.TCP;
        connectionParameters.CancelTimeout = TimeSpan.FromSeconds(15);
        connectionParameters.ConnectTimeout = TimeSpan.FromSeconds(15);

Url and credentials I used are the same above.

Debugging the code below:

fixed (byte* initDataPtr = &_extraData[0])
{
    resultCode = FFmpegVideoPInvoke.SetVideoDecoderExtraData(_decoderHandle.Value,
        (IntPtr)initDataPtr, _extraData.Length);

    if (resultCode != 0)
        throw new DecoderException(
            $"An error occurred while setting video extra data, {_videoCodecId} codec, code: {resultCode}");
}

The line "resultCode = FFmpegVideo...." is causing the following error:

System.InvalidOperationException HResult=0x80131509 Message=Nullable object must have a value. Source=mscorlib StackTrace: at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource) at System.Nullable1.get_Value() at SimpleRtspPlayer.RawFramesDecoding.FFmpeg.FFmpegVideoDecoder.TryDecode(RawVideoFrame rawVideoFrame) in C:\Users\manue\Desktop\RTSP\RtspClientSharp-master\Examples\SimpleRtspPlayer\RawFramesDecoding\FFmpeg\FFmpegVideoDecoder.cs:line 78 at SimpleRtspPlayer.GUI.RealtimeVideoSource.OnFrameReceived(Object sender, RawFrame rawFrame) in C:\Users\manue\Desktop\RTSP\RtspClientSharp-master\Examples\SimpleRtspPlayer\GUI\RealtimeVideoSource.cs:line 56 at System.EventHandler1.Invoke(Object sender, TEventArgs e) at SimpleRtspPlayer.RawFramesReceiving.RawFramesSource.RtspClientOnFrameReceived(Object sender, RawFrame rawFrame) in C:\Users\manue\Desktop\RTSP\RtspClientSharp-master\Examples\SimpleRtspPlayer\RawFramesReceiving\RawFramesSource.cs:line 94 at RtspClientSharp.RtspClient.b__16_0(RawFrame frame) at RtspClientSharp.Rtsp.RtspClientInternal.OnFrameGeneratedLockfree(RawFrame frame) at RtspClientSharp.MediaParsers.MediaPayloadParser.OnFrameGenerated(RawFrame e) at RtspClientSharp.MediaParsers.H264Parser.TryGenerateFrame(ArraySegment1 frameBytes) at RtspClientSharp.MediaParsers.H264Parser.TryGenerateFrame() at RtspClientSharp.MediaParsers.H264Parser.Parse(ArraySegment1 byteSegment, Boolean generateFrame) at RtspClientSharp.MediaParsers.H264VideoPayloadParser.ParseFU(ArraySegment1 byteSegment, Int32 donFieldSize, Boolean markerBit) at RtspClientSharp.MediaParsers.H264VideoPayloadParser.Parse(TimeSpan timeOffset, ArraySegment1 byteSegment, Boolean markerBit) at RtspClientSharp.Rtp.RtpStream.ProcessImmediately(RtpPacket& rtpPacket) at RtspClientSharp.Rtp.RtpStream.Process(ArraySegment`1 payloadSegment) at RtspClientSharp.Rtsp.RtspClientInternal.d__34.MoveNext()

Am I doing something wrong? Does this help you? Thanks

Dauskardt commented 4 years ago

I have the same Problem.