Page 1 of 1

RTSP correct sequence

Posted: Mon Jun 25, 2012 9:11 am
by element
Hi everybody, I'm trying to set up my ZoneMinder (installed from sources, v.1.25.0) with a CNB camera, but without success. This is my configuration:

Code: Select all

Source Type: Remote
Function: Monitor

Remote Protocol: RTSP
Remote Method: RTP/Unicast
Remote Host Name: 192.168.101.142
Remote Host Port: 554
Remote Host Path: live 
Capture width: 640
Capture height: 480
Before testing ZM on the CNB camera, I tried with an Axis cam and everything went ok both http and rtsp (unicast) modes. Regarding the CNB, I tried some different settings and I found, helped by Wireshark, that the SETUP url was not well constructed. Also, the PLAY message was not working. So I decided to modify the code so that it emulates the VLC trace from Wireshark.
After correcting the headers from the SETUP and PLAY messages, I realized that in Unicast mode, ZoneMinder expects in the answer of the PLAY message, a "RTP-info" header with the sequence number and timestamp from the first packet of the RTP sequence. What I have done is to comment this secction of code (zm_rtsp.cpp) and in the zm_rtp_data.cpp, capture this values from the headers of the first RTP data packet (after line 51):

Code: Select all

    
if( mFirstPacket ) {
   mRtpSource.updateSeq( ntohs(rtpHeader->seqN) );
   mRtpSource.updateJitter( rtpHeader );
   mFirstPacket = false;
}
The result of all this is that I get a correct sequence of RTSP messages between ZM and the camera, but I can't see any image, only a black screen. Wireshark tells me that I am receiving RTP packets, but the sequence is interrupted by a unexpected TEARDOWN message. Then the sequence restarts (describe, setup, play and rtp packets).

Some times I receive a PORT UNREACHABLE message from the server, which means that ZoneMinder was unable to decode a packet maybe due a timeout.

I have seen to many people complaining about RTSP implementation, because it doesn't work. Is there a more elegant way to set the seq and the rtptime values without to do it by hand (commenting that slice of code)? Maybe ZoneMinder fails buffering the data or it is unable to decode the H264 format?

I will really appreciate any help configuring the camera with the ZoneMinder or any code change.

Re: RTSP correct sequence

Posted: Thu Sep 06, 2012 11:43 pm
by flq06
Hi have the exact same problem
VLC works fine but not zoneminder

Re: RTSP correct sequence

Posted: Fri Sep 07, 2012 7:41 pm
by Garyio
We have had the same issue for some time. I had it working at one point but that was a few months ago and I don't remember what I did to make it work. I think it was something I changed in the camera. I can get an image if I use HTTP simple instead of RTSP but the image flashes back and forth with black frames. I can see my video in VLC just fine using RTSP. I get errors in the log file that say "Unable to get picture from frame". These errors are from line 258 in the zm_remote_camera_rtsp.cpp file. What has anyone else attempt to try to get this working? Anyone else have any ideas.

Re: RTSP correct sequence

Posted: Fri Sep 07, 2012 7:50 pm
by Garyio
I just got mine to work again. I changed the camera output format from mjpeg to mpeg4. Now I am able to capture and do live view of my camera with an image size of 640 X 480. Hope this helps.

Re: RTSP correct sequence

Posted: Fri Sep 07, 2012 8:32 pm
by element
I remember that, indeed, using HTTP protocol worked to start receiving images. But, in my case, I really needed to use the RTSP/RTP protocols, so what I have finally done it's to modify to my purposes one of the subclasses of Camera, such as RemoteCameraRtsp or FfmpegCamera (which are responsible for capturing frames and in fact, they represent the methods of capture you can choose from the web interface) and then I used live555 libraries to connect and capture the h.264 stream (see how OpenRTSP does the work).

I also managed to control the CNB camera, by modifying a simple Perl script (a simple GET HTTP method with parameters is what you need) that I found on the web.

I hope that helps, but bear in mind that the best way to do this it is creating a new class and inheriting from "Camera", overriding methods, modifying database to add a new mode of capture, etc.

Re: RTSP correct sequence

Posted: Wed Dec 11, 2013 5:35 am
by Bpar
Hello,
I have same problem with my сhinese IP camera. And same Zoneminder error message.
In VLC Media Player all work perfect.
Could you share your source code and sql-scripts to help me? :)
Thanks.

Re: RTSP correct sequence

Posted: Fri Dec 13, 2013 7:19 pm
by ralph179
Bpar - I have a HIKVision & IPSCam (Chinese) working without code changes, is it one of these?

Ralph

Re: RTSP correct sequence

Posted: Sat Dec 14, 2013 5:36 am
by Bpar
ralph179, my is TI700HD.

And I already fix Zoneminder (1.26.4) code (zm_rtsp.cpp) to work with it.
Just assign seq = 3 and rtpTime = 0, if no RTP Info received.

Re: RTSP correct sequence

Posted: Sat Dec 14, 2013 6:32 pm
by Garyio
So what did you change? Maybe that fixed your camera but it seems to have broken mine. I had my RTSP camera working just fine and then I upgrade from ZM 1.25.0 to ZM 1.26.4 and now I can not get it to work at all.

2013-12-14 12:27:41.222546 zmc_m1 16729 ERR Error while decoding frame 1 zm_remote_camera_rtsp.cpp 273
2013-12-14 12:27:41.172068 zmc_m1 16729 ERR 256: 00 00 01 00 00 01 b6 57 d0 0c 06 f6 f0 b9 ac eb 58 2d 10 b0 71 6b 01 88 38 93 ff ff ff ff db c1 dc 16 31 8b b6 b0 71 41 03 18 2d 3f ed 66 bf fd 6c 9b ed e7 05 e7 7c 1c a6 58 bc 4e c1 42 71 60 d8 16 c0 8a 1c 90 8e 12 05 49 e3 82 d0 61 0b 01 56 67 3b c zm_remote_camera_rtsp.cpp 274
2013-12-14 12:27:41.122098 zmc_m1 16729 ERR Error while decoding frame 1 zm_remote_camera_rtsp.cpp 273
2013-12-14 12:27:41.071612 zmc_m1 16729 ERR 256: 00 00 01 00 00 01 b6 56 d6 0c 06 fb 78 38 5d 63 7b 18 2d fd 6c e7 ff ff ff ed e0 e0 b9 8c 1c 2c ea 60 e8 17 94 86 e7 bf ff fe de 73 ff 3a 30 5b 42 9f c0 f8 71 a3 9e 1a 05 72 38 4c b8 70 c0 76 48 92 94 82 c4 dd 2d 68 22 0a 7b 65 21 e1 06 ae 9d ae 82 b zm_remote_camera_rtsp.cpp 274
2013-12-14 12:27:41.021465 zmc_m1 16729 ERR Error while decoding frame 1 zm_remote_camera_rtsp.cpp 273
2013-12-14 12:27:40.971370 zmc_m1 16729 ERR 256: 00 00 01 00 00 01 b6 55 dc 0c 06 fa d8 38 30 1c e0 9c 0e 68 c9 1a 16 0e 78 2b 81 61 b7 bf ff ff 8f df ff f6 f0 7b af ff de c6 02 36 b0 dc 2e 53 10 0a 9c 0e 48 7f ff ff fc 5e 77 ff 57 07 1f 01 f5 b0 7b 7f ff cd ec e0 e4 86 c1 c2 ff 63 05 f7 db c6 96 b zm_remote_camera_rtsp.cpp 274
2013-12-14 12:27:40.921041 zmc_m1 16729 ERR Error while decoding frame 1 zm_remote_camera_rtsp.cpp 273

Re: RTSP correct sequence

Posted: Sat Dec 14, 2013 7:25 pm
by Bpar
Garyio, I also have this errors in log
Capture seems fine for awhile or more %)
Havn't time for check source code to see what it is mean.

Re: RTSP correct sequence

Posted: Sat Dec 14, 2013 8:14 pm
by Garyio
I looked at your source and I was wondering how you determined this to be correct? Did you look at data from your camera? This was not in the older version.

From line 265 in zm_rtp_source.cpp:

if ( ((packet[sizeof(RtpDataHeader)] & 0x1f) == 28 &&
(packet[sizeof(RtpDataHeader)+1] & 0x80)) ||
((packet[sizeof(RtpDataHeader)] & 0x1f) != 28 &&
prevM && rtpHeader->m) )

In version 1.26.4 Starting from line 252 in zm_rtp_source.cpp:

bool RtpSource::handlePacket( const unsigned char *packet, size_t packetLen )
{
const RtpDataHeader *rtpHeader;
rtpHeader = (RtpDataHeader *)packet;
bool fragmentEnd = false;

// Each RTP packet delivers only one NAL. It can be either the Single NAL
// ( in that case it must be in one packet ) or the Fragmentation NALs
// that delivers large single NAL...

if ( updateSeq( ntohs(rtpHeader->seqN) ) )
{
Hexdump( 4, packet+sizeof(RtpDataHeader), 16 );
if ( ((packet[sizeof(RtpDataHeader)] & 0x1f) == 28 &&
(packet[sizeof(RtpDataHeader)+1] & 0x80)) ||
((packet[sizeof(RtpDataHeader)] & 0x1f) != 28 &&
prevM && rtpHeader->m) )
mFrameGood = true; // This means that if packet is in sequence
// and is single NAL with mark set (and prev packet
// was NAL with mark set or it is Fragmentation NAL with
// Start bit set then we assume that sequence
// was restored and we can handle packet

Version 1.25.0 has this started at line 252 in zm_rtp_source.cpp:

bool RtpSource::handlePacket( const unsigned char *packet, size_t packetLen )
{
const RtpDataHeader *rtpHeader;
rtpHeader = (RtpDataHeader *)packet;

if ( updateSeq( ntohs(rtpHeader->seqN) ) )
{
Hexdump( 4, packet+sizeof(RtpDataHeader), 16 );

Re: RTSP correct sequence

Posted: Mon Dec 16, 2013 7:08 am
by Bpar
Ok, you right
RTSP/RTP capture didn't work propertly.
In last version 1.26.5 this errors not logged. But with my camera the "signal lost" meesages are often. Some times several in 1 minute.
So I deside to use ffmpeg so far.

Re: RTSP correct sequence

Posted: Mon Dec 16, 2013 5:01 pm
by Garyio
After updating to 1.26.5 mine works again.