several bugs found in zm_rtsp + help request with AV201 RTSP

Forum for questions and support relating to the 1.24.x releases only.
Locked
aNt1X
Posts: 10
Joined: Wed Apr 02, 2008 10:55 am

several bugs found in zm_rtsp + help request with AV201 RTSP

Post by aNt1X »

Hi all,

i am working at the following setup:

Camera type: AVTECH AV201
OS: Ubuntu 8.04.2
Zoneminder: 1.24.1 revision 2806 from svn
FFMpeg: SVN-r18021 from svn

I was trying to use RTSP with the AV201 camera without success.

After several analyses with tcpdump and wireshark, now i am able to use that camera with the following settings:

Code: Select all

Source type: Remote
Remote Protocol: RTSP
Remote Method: RTP/Unicast
Remote Host Name: admin:admin@192.168.X.Y
Remote Host Port: 554
Remote Host Path: /live/m.peg4
Remote Host SubPath: /track
Remote Image Colours: 24 bit colour
Capture Width (pixels): 320
Capture Height (pixels): 240
Please notice that i found the following bugs in zm_rtsp.cpp:

1- mUrl is used instead of tempUrl, so path is not correctly used.

Code: Select all

@@ -296,9 +296,9 @@ int RtspThread::run()
         if ( !mPath.empty() )
         {
             if ( mPath[0] == '/' )
-                mUrl += mPath;
+                tempUrl += mPath;
             else
-                mUrl += '/'+mPath;
+                tempUrl += '/'+mPath;
         }
     }
     if ( av_open_input_file( &mFormatContext, tempUrl.c_str(), NULL, 0, NULL ) != 0 )
2- session is badly interpreted. only digits are accepted, while session is an HEX value.

Code: Select all

@@ -363,7 +363,7 @@ int RtspThread::run()

     for ( size_t i = 0; i < lines.size(); i++ )
     {
-        sscanf( lines[i].c_str(), "Session: %a[0-9]; timeout=%d", &session, &timeout );
+        sscanf( lines[i].c_str(), "Session: %a[0-9;A-F]; timeout=%d", &session, &timeout );
         sscanf( lines[i].c_str(), "Transport: %s", transport );
     }


Now, perhaps that next changes are camera dependent. i mean, i had to apply also these changes to make my avtech AV201 camera work. i'm not an RTSP/RTP expert, so perhaps that these changes will break other cameras compatibility ... ?


3- my camera subpath has to be "track0" and not "track1". so i changed i+1 to i in sprintf...

Code: Select all

@@ -315,7 +315,7 @@ int RtspThread::run()
         {
             if ( mFormatContext->streams[i]->codec->codec_type == CODEC_TYPE_VIDEO )
             {
-                trackUrl += mSubpath+stringtf( "%d", i+1 );
+                trackUrl += mSubpath+stringtf( "%d", i );
                 // Hackery pokery
                 rtpClock = mFormatContext->streams[i]->codec->sample_rate;
                 break;
4- i had to add the "Range" value to PLAY method. without Range value, camera will not send the Rtp-info back, so RTP session can't be initiated... dunno if it is camera dependent ...

Code: Select all

@@ -431,7 +431,7 @@ int RtspThread::run()
     Debug( 2, "RTSP Remote Ports are %d/%d", remotePorts[0], remotePorts[1] );
     Debug( 2, "RTSP Remote Channels are %d/%d", remoteChannels[0], remoteChannels[1] );

-    message = "PLAY "+trackUrl+" RTSP/1.0\r\nSession: "+session+"\r\n";
+    message = "PLAY "+trackUrl+" RTSP/1.0\r\nSession: "+session+"\r\nRange: npt=0.000-\r\n";
     if ( !sendCommand( message ) )
         return( -1 );
     if ( !recvResponse( response ) )

How can i attach a diff patch? :P

Now, Zoneminder can see the camera, but the images is broken: it is splitted by two (the images is duplicated intwo horizontal splits), with the bottom part broken with a black banner.

I know that this appened on several cameras. Suggestions ?
maciekc
Posts: 150
Joined: Wed Feb 23, 2005 9:21 pm
Location: Czestochowa, POLAND

Post by maciekc »

Hi I used avi201 with ffmpeg monitor type
Url - rtsp://admin:admin@192.168.0.222/live/mpeg4
You need to patch ffmpeg with authorization patch
I also prefer to use tcp, udp sometimes give broken images(the data is sent twice)
You need to change rtsp_read_header function because setting protocol in url is f^@#ed up(maybe they already fixed it)

After line:
int lower_transport = ff_log2_tab[lower_transport_mask & ~(lower_transport_mask - 1)];

Add:
lower_transport=RTSP_LOWER_TRANSPORT_TCP;

I know this hack is stupid but works, I didn't have time to look harder why choosing protocol doesn't work.
User avatar
Normando
Posts: 219
Joined: Sun Aug 17, 2008 5:34 am
Location: Rosario - Argentina

Post by Normando »

Thanks aNt1X!

I was have the same issue (the screen splitted horizontally) with ZM 1.23.3 using the RTSP patch from http://www.zoneminder.com/forums/viewtopic.php?t=12583

This happens only with mpeg4, and not with h264 (like AVI203)

So, I think AVI201 has an special RTSP requirement.
User avatar
zoneminder
Site Admin
Posts: 5215
Joined: Wed Jul 09, 2003 2:07 pm
Location: Bristol, UK
Contact:

Post by zoneminder »

Thanks for the patches. I have applied them, or similar, locally except the trackUrl one and will have a play. I need to think of a generic way to do the track urls. Unfortunately the ffmpeg libraries have become more closed and although it extracts the track info from the SDP there is no way to get hold of that information and use it to automatically get the right url. The only alternative is to define your cam as a ffmpeg monitor in which case it should do just about everything.
Phil
aNt1X
Posts: 10
Joined: Wed Apr 02, 2008 10:55 am

Post by aNt1X »

what about implementing rtsp directly into zoneminder? i mean, at least basic features...

i see that my camera exchanges no more than few rtsp packets with some sdp descriptions.

it could be an idea ? so that we natively support RTSP, without ffmpeg aid. and we could extract track information and others directly into

if you think that it is a good idea i think i could help and try to write some code.
User avatar
zoneminder
Site Admin
Posts: 5215
Joined: Wed Jul 09, 2003 2:07 pm
Location: Bristol, UK
Contact:

Post by zoneminder »

The RTSP and RDP dialogs are already in ZM. However the SDP parsing into a nice ffmpeg format that it can use for video decoding is tucked away in the ffmpeg libraries and they keep what they have discovered secret.
Phil
Locked