New FreeBSD port for 1.22.3.

If you've made a patch to quick fix a bug or to add a new feature not yet in the main tree then post it here so others can try it out.
achix
Posts: 146
Joined: Tue Oct 02, 2007 9:38 am
Location: Greece

Post by achix »

Well, adding

Code: Select all

int VIDformat=METEOR_FMT_PAL;
ioctl(m_videohandle, METEORSFMT, &VIDformat);
in zm_fbsd_camera.cpp:

Did the trick!!!

Also i added

Code: Select all

c = bktr_dev[channel];
(The fbsd code (zm_fbsd_camera.cpp) is extremely alpha i'd say)

Anyways, now the problem is i cant access at the same time /dev/bktr0 from
two zmc instances.

Anyway, asis, for me, its a great step forward!
achix
Posts: 146
Joined: Tue Oct 02, 2007 9:38 am
Location: Greece

Solved

Post by achix »

It works for single chip/multi input, switched boards, like the LMLBT4M.
It uses "Memory mapped single capture" method of meteor(4).
Here is the patch (for PAL).
===========

Code: Select all


--- ../../../files/zm_fbsd_camera.cpp	Sun Jan 14 23:12:18 2007
+++ zm_fbsd_camera.cpp	Mon Oct  8 22:41:16 2007
@@ -24,8 +24,10 @@
 #include <sys/shm.h>
 #include <sys/mman.h>
 #include <signal.h>
-#include <machine/ioctl_bt848.h>
-#include <machine/ioctl_meteor.h>
+//#include <machine/ioctl_bt848.h>
+//#include <machine/ioctl_meteor.h>
+#include <dev/bktr/ioctl_bt848.h>
+#include <dev/bktr/ioctl_meteor.h>
 
 #include "zm.h"
 #include "zm_local_camera.h"
@@ -93,7 +95,7 @@
         if (idev < 0 || idev > 4)
 		idev = 0;
 		
-	Debug( 1, ( "using Meteor device: %d", idev ));
+//	Debug( 1, ( "using Meteor device: %d", idev ));
                         	 
 	if ( (m_videohandle=open(device, O_RDONLY)) < 0 )
 	{
@@ -101,14 +103,16 @@
 		exit(-1);
 	}
 	
-	
-        c = bktr_dev[idev];
+	//Debug( 1, ( "using Meteor device: %d", channel ));
+	Info(("Initialize: using Meteor device: %d", channel));
+	c = bktr_dev[channel];
         if (ioctl(m_videohandle, METEORSINPUT, &c) < 0) {
 		Error(( "Failed to set video input : %s", strerror(errno) ));
 		if ( (bool)config.Item( ZM_STRICT_VIDEO_CONFIG ) ) exit(-1);
-
         }
-        	
+
+        int VIDformat=METEOR_FMT_PAL;
+	ioctl(m_videohandle, METEORSFMT, &VIDformat);	
 	
         // Setup Pixel Format
         
@@ -186,7 +190,8 @@
         
 
         
-        c = METEOR_CAP_CONTINOUS;
+        //c = METEOR_CAP_CONTINOUS;
+        c = METEOR_CAP_SINGLE;
         ioctl(m_videohandle, METEORCAPTUR, &c);
         
    
@@ -535,6 +540,7 @@
 int LocalCamera::PreCapture()
 {
 
+	static int bktr_dev[] = { METEOR_DEV0, METEOR_DEV1, METEOR_DEV2, METEOR_DEV3, METEOR_DEV_SVIDEO };
 	if ( camera_count > 1 )
 	{
 		//Info(( "Switching" ));
@@ -544,11 +550,16 @@
 		vid_src.norm = format;
 		vid_src.flags = 0;
 		vid_src.type = VIDEO_TYPE_CAMERA;
-		if ( ioctl( m_videohandle, VIDIOCSCHAN, &vid_src ) < 0 )
-		{
-			Error(( "Failed to set camera source %d: %s", channel, strerror(errno) ));
+		unsigned int tmpchannel= (unsigned)channel;
+		Info(("CHANNEL = %d",tmpchannel));
+		int tmpint=bktr_dev[tmpchannel];
+        	if (ioctl(m_videohandle, METEORSINPUT, &tmpint) < 0) {
+			Error(( "Funk2!! Failed to set camera source %d: %s", tmpchannel, strerror(errno) ));
 			return( -1 );
-		}
+        	}
+
+        	int tmpc = METEOR_CAP_SINGLE;
+        	ioctl(m_videohandle, METEORCAPTUR, &tmpc);
 	}
 	/*
 	if ( ioctl( m_videohandle, METEORCAPFRM, &m_vmm[m_cap_frame] ) < 0 )

achix
Posts: 146
Joined: Tue Oct 02, 2007 9:38 am
Location: Greece

FORMAT corrected

Post by achix »

here is the new Format-gnostic patch + the ability to correctly handle
single camera/board or multiple cameras/board switched to the *same* bktr chip.

Code: Select all

--- ../../../files/zm_fbsd_camera.cpp	Sun Jan 14 23:12:18 2007
+++ zm_fbsd_camera.cpp	Wed Oct 10 20:15:46 2007
@@ -24,8 +24,10 @@
 #include <sys/shm.h>
 #include <sys/mman.h>
 #include <signal.h>
-#include <machine/ioctl_bt848.h>
-#include <machine/ioctl_meteor.h>
+//#include <machine/ioctl_bt848.h>
+//#include <machine/ioctl_meteor.h>
+#include <dev/bktr/ioctl_bt848.h>
+#include <dev/bktr/ioctl_meteor.h>
 
 #include "zm.h"
 #include "zm_local_camera.h"
@@ -93,7 +95,7 @@
         if (idev < 0 || idev > 4)
 		idev = 0;
 		
-	Debug( 1, ( "using Meteor device: %d", idev ));
+//	Debug( 1, ( "using Meteor device: %d", idev ));
                         	 
 	if ( (m_videohandle=open(device, O_RDONLY)) < 0 )
 	{
@@ -101,14 +103,19 @@
 		exit(-1);
 	}
 	
-	
-        c = bktr_dev[idev];
+	//Debug( 1, ( "using Meteor device: %d", channel ));
+	Info(("Initialize: using Meteor device: %d", channel));
+	c = bktr_dev[channel];
         if (ioctl(m_videohandle, METEORSINPUT, &c) < 0) {
 		Error(( "Failed to set video input : %s", strerror(errno) ));
 		if ( (bool)config.Item( ZM_STRICT_VIDEO_CONFIG ) ) exit(-1);
-
         }
-        	
+
+
+	static int meteor_formats[] = { METEOR_FMT_PAL, METEOR_FMT_NTSC, METEOR_FMT_SECAM, METEOR_FMT_AUTOMODE, METEOR_FMT_AUTOMODE,METEOR_FMT_AUTOMODE,METEOR_FMT_AUTOMODE,METEOR_FMT_AUTOMODE };
+
+        int VIDformat=meteor_formats[format];
+	ioctl(m_videohandle, METEORSFMT, &VIDformat);	
 	
         // Setup Pixel Format
         
@@ -184,9 +191,8 @@
 	
 	}
         
-
-        
-        c = METEOR_CAP_CONTINOUS;
+	
+       	c = METEOR_CAP_CONTINOUS;
         ioctl(m_videohandle, METEORCAPTUR, &c);
         
    
@@ -535,6 +541,7 @@
 int LocalCamera::PreCapture()
 {
 
+	static int bktr_dev[] = { METEOR_DEV0, METEOR_DEV1, METEOR_DEV2, METEOR_DEV3, METEOR_DEV_SVIDEO };
 	if ( camera_count > 1 )
 	{
 		//Info(( "Switching" ));
@@ -544,11 +551,24 @@
 		vid_src.norm = format;
 		vid_src.flags = 0;
 		vid_src.type = VIDEO_TYPE_CAMERA;
-		if ( ioctl( m_videohandle, VIDIOCSCHAN, &vid_src ) < 0 )
-		{
-			Error(( "Failed to set camera source %d: %s", channel, strerror(errno) ));
+		unsigned int tmpchannel= (unsigned)channel;
+		//Info(("CHANNEL = %d",tmpchannel));
+		static int meteor_formats[] = { METEOR_FMT_PAL, METEOR_FMT_NTSC, METEOR_FMT_SECAM, METEOR_FMT_AUTOMODE, METEOR_FMT_AUTOMODE,METEOR_FMT_AUTOMODE,METEOR_FMT_AUTOMODE,METEOR_FMT_AUTOMODE };
+
+        	int tmpc = METEOR_CAP_STOP_CONT;
+        	ioctl(m_videohandle, METEORCAPTUR, &tmpc);
+
+        	int VIDformat=meteor_formats[format];
+		ioctl(m_videohandle, METEORSFMT, &VIDformat);	
+
+		int tmpint=bktr_dev[tmpchannel];
+        	if (ioctl(m_videohandle, METEORSINPUT, &tmpint) < 0) {
+			Error(( "Funk2!! Failed to set camera source %d: %s", tmpchannel, strerror(errno) ));
 			return( -1 );
-		}
+        	}
+
+        	tmpc = METEOR_CAP_SINGLE;
+        	ioctl(m_videohandle, METEORCAPTUR, &tmpc);
 	}
 	/*
 	if ( ioctl( m_videohandle, METEORCAPFRM, &m_vmm[m_cap_frame] ) < 0 )
zero1eye
Posts: 3
Joined: Mon Mar 31, 2008 3:45 pm

Post by zero1eye »

I got this working pretty nicely in FreeBSD 7.0. Thanks for the port!
achix
Posts: 146
Joined: Tue Oct 02, 2007 9:38 am
Location: Greece

Post by achix »

zero1eye wrote:I got this working pretty nicely in FreeBSD 7.0. Thanks for the port!
Great, do you have a net (IP) camera(s) or analogue?
zero1eye
Posts: 3
Joined: Mon Mar 31, 2008 3:45 pm

Post by zero1eye »

I got it working with 8 analog cameras. Apparently the Bktr driver has issues with shared chips and multiple cards, or I don't know what I'm doing, so the most I could get was 8 cameras working, but they work well.
zero1eye
Posts: 3
Joined: Mon Mar 31, 2008 3:45 pm

Post by zero1eye »

Here are my build notes. I ultimately needed more than 8 cameras, so I went with the Mandriva live cd solution. However it was pretty fun getting this working in FreeBSD.

-------------

Updating with Csup

csup -L 2 /usr/share/examples/cvsup/stable-supfile
csup -L 2 /usr/share/examples/cvsup/ports-supfile

Net-snmp

cd /usr/ports/net-mgmt/net-snmp
make install clean
/usr/local/bin/snmpconf -i
(This procedure is documented in net-snmp.doc)
echo 'snmpd_enable="YES"' >> /etc/rc.conf
echo 'snmpd_conffile="/usr/local/share/snmp/snmpd.conf"' >> /etc/rc.conf

Recompiling the Kernel

We need to make a copy of the base configuration, and then compile in camera support.

cd /usr/src/sys/i386/conf
cp GENERIC CUSTOM
echo 'device pf' >> CUSTOM
echo 'device pflog' >> CUSTOM
echo 'device pfsync' >> CUSTOM
echo 'options ALTQ' >> CUSTOM
echo 'options ALTQ_CBQ' >> CUSTOM
echo 'options ALTQ_RED' >> CUSTOM
echo 'options ALTQ_RIO' >> CUSTOM
echo 'options ALTQ_HFSC' >> CUSTOM
echo 'options ALTQ_PRIQ' >> CUSTOM
echo 'options ALTQ_NOPCC' >> CUSTOM
echo 'device smbus' >> CUSTOM
echo 'device iicbus' >> CUSTOM
echo 'device iicbb' >> CUSTOM
echo 'device bktr' >> CUSTOM
cd /usr/src
make buildkernel KERNCONF=CUSTOM
make installkernel KERNCONF=CUSTOM

PF

Since we compiled in ALTQ support in the previous step, we mind as well setup the PF firewall for this box.

echo 'pf_enable="YES"' >> /etc/rc.conf
echo 'pf_rules="/etc/firewall.conf"' >> /etc/rc.conf
echo 'pf_flags=""' >> /etc/rc.conf
echo 'pflog_enable="YES"' >> /etc/rc.conf
echo 'pflog_logfile="/var/log/pflog"' >> /etc/rc.conf
echo 'pflog_flags=""' >> /etc/rc.conf
reboot

Apache22

cd /usr/ports/www/apache22
make install clean
echo 'apache22_enable="YES"' >> /etc/rc.conf
touch /usr/local/www/apache22/data/favicon.ico

Setup the http.conf file, which is located at /usr/local/etc/apache22/http.conf. The following lines should be added to the AddType section:

AddType application/x-httpd-php .php .php3 .php4 .phtml
AddType application/x-httpd-php-source .phps

We also need to add the .php extension to the default startup pages:

DirectoryIndex index.html index.php

PHP5

We are going to let the Zoneminder port invoke the PHP5 installation but we want to make sure that when it does, it also builds the Apache module.

cd /usr/ports/lang/php5
make config
Select "Build Apache Module"
cd /usr/ports/lang/php5-extensions
make config
Select "Mysql support"
Select "PCRE support"
Select "Session support"

Zoneminder

If you haven't already, you need to download the latest FreeBSD port of Zoneminder from: http://catsspat.dyndns.org:2080/zoneminder/ . Upload it to your home folder via scp and then continue.

cd /home/admin
tar xvfz zoneminder.tar.gz
mv zoneminder /usr/ports/multimedia
cd /usr/ports/multimedia/zoneminder

You will need to open up the Makefile in the vi editor and verify the proper dependencies and paths. At the time of this document, version 5.1 is the latest mysql version. You will need to edit the line that reads:

BUILD_DEPENDS= ${LOCALBASE}/bin/mysqld_safe:${PORTSDIR}/databases/mysql51-server:install

Also the web base is different for Apache 2.2.

WEBBASE= ${LOCALBASE}/www/apache22

Once you are happy with the Makefile, time to run make.

make
make install
echo 'zm_enable="YES"' >> /etc/rc.conf

Double-check the configuration settings in /usr/local/etc/zm.conf, however they are probably already correct or the installation would have failed.

Mysql5.1

The Zoneminder port above already installed mysql5, but we still need to setup the databases for Zoneminder.

echo 'mysql_enable="YES"' >> /etc/rc.conf
/usr/local/etc/rc.d/mysql-server start
/usr/local/bin/mysql -u root -p
<enter>
SET PASSWORD FOR root@your.hostname.com = PASSWORD('password');
SET PASSWORD FOR root@"localhost" = PASSWORD('password');
source work/ZoneMinder-1.22.3/db/zm_create.sql
grant select,insert,update,delete on zm.* to 'zmuser'@localhost identified by 'zmpass';
flush privileges;
quit;

Rsync (for backing up)

cd /usr/ports/net/rsync
make install clean

Php5

Now that PHP5 has been installed, we need to configure it.

cd /usr/local/etc
cp php.ini-recommended php.ini
Edit the php.ini to ensure short_open_tag = On

Configuring Zoneminder

Open a browser to http://localhost/zm/index.php

If all has gone well, you will see the screen above. Click on the "Options" link in the top right corner to get started with configuration. Make sure that if you are running a pop-up blocker, to shut it off or the site will not work properly.

To add a camera and begin testing, click on the "Add New Monitor" button.

1) Give the new camera a name (ex. "Camera01")
2) Change the Function to "Monitor" for testing purposes.
3) Cap the Maximum FPS at 5, which is good enough for our purposes.
4) Click on the "Source" tab.
5) Enter "/dev/bktr" for your Device Path
6) Select NTSC for the Device Format
7) Set the Capture Width and Height to 320x240.
8) Click Save.

Now you can start up Zoneminder by clicking the link at the top of the main page. Watch your logs, specifically /var/log/messages for errors.

Mpeg Support

Compile in optional Mpeg support for display in Xorg.

cd /usr/ports/multimedia/mpeg_encode/
make install clean

Configuring Shared Memory Allocation

This is where it gets a little grey. We need to allocate enough shared memory for each camera without crashing the system at the same time. Add the followup to the /etc/sysctl.conf.

kern.ipc.shmmax=536870912
kern.ipc.shm_use_phys=1
kern.ipc.shmall=524288

Xorg

cd /usr/ports/x11/xorg/
make install clean
cd /usr/ports/x11-fonts/urwfonts
make install clean

Nvidia

cd /usr/ports/x11/nvidia-driver
make install clean
cd /usr/ports/x11/nvidia-settings
make install clean
cd /usr/ports/x11/nvidia-xconfig
make install clean

The rest was configuring the web interface to look how you want it. Hope this helps someone.
Post Reply