📄 dc1394.c
字号:
/***************************************************************************** * dc1394.c: firewire input module ***************************************************************************** * Copyright (C) 2006, the VideoLAN team * * Authors: Xant Majere <xant@xant.net> * ***************************************************************************** * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2 of the License. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * *****************************************************************************//***************************************************************************** * Preamble *****************************************************************************/#include <vlc/vlc.h>#include <vlc/input.h>#include <vlc/vout.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#ifdef HAVE_FCNTL_H# include <fcntl.h>#endif#ifdef HAVE_UNISTD_H# include <unistd.h>#elif defined( WIN32 ) && !defined( UNDER_CE )# include <io.h>#endif#include <sys/ioctl.h>#include <sys/soundcard.h>#include <libraw1394/raw1394.h>#include <libdc1394/dc1394_control.h>#define MAX_IEEE1394_HOSTS 32#define MAX_CAMERA_NODES 32/***************************************************************************** * Module descriptor *****************************************************************************/static int Open ( vlc_object_t * );static void Close( vlc_object_t * );static void OpenAudioDev( demux_t *p_demux );static inline void CloseAudioDev( demux_t *p_demux );vlc_module_begin(); set_description( _("dc1394 input") ); set_capability( "access_demux", 10 ); add_shortcut( "dc1394" ); set_callbacks( Open, Close );vlc_module_end();typedef struct __dc_camera{ int port; nodeid_t node; u_int64_t uid;} dc_camera;typedef struct demux_sys_t{ dc1394_cameracapture camera; picture_t pic; int dma_capture;#define DMA_OFF 0#define DMA_ON 1 int num_ports; int num_cameras; int selected_camera; u_int64_t selected_uid; dc_camera *camera_nodes; dc1394_camerainfo camera_info; dc1394_miscinfo misc_info; raw1394handle_t fd_video; quadlet_t supported_framerates; int width; int height; int frame_size; int frame_rate; unsigned int brightness; unsigned int focus; char *dma_device; es_out_id_t *p_es_video; /* audio stuff */ int i_sample_rate; int channels; int i_audio_max_frame_size; int fd_audio; char *audio_device; int rotate;#define NO_ROTATION 0#define ROTATION_LEFT 1#define ROTATION_RIGHT 2 es_out_id_t *p_es_audio;} dc1394_sys;/***************************************************************************** * Local prototypes *****************************************************************************/static int Demux( demux_t *p_demux );static int Control( demux_t *, int, va_list );static block_t *GrabVideo( demux_t *p_demux );static block_t *GrabAudio( demux_t *p_demux );static int process_options( demux_t *p_demux);/***************************************************************************** * ScanCameras *****************************************************************************/static int ScanCameras( dc1394_sys *sys, demux_t *p_demux ){ struct raw1394_portinfo portinfo[MAX_IEEE1394_HOSTS]; raw1394handle_t tempFd; dc1394_camerainfo info; dc_camera *node_list = NULL; nodeid_t *nodes = NULL; int num_ports = 0; int num_cameras = 0; int nodecount; int i, n; memset( &portinfo, 0, sizeof(portinfo) ); msg_Dbg( p_demux, "Scanning for ieee1394 ports ..." ); tempFd = raw1394_new_handle(); if( !tempFd ) return VLC_EGENERIC; raw1394_get_port_info( tempFd, portinfo, MAX_IEEE1394_HOSTS); raw1394_destroy_handle( tempFd ); for( i=0; i < MAX_IEEE1394_HOSTS; i++ ) { /* check if port exists and has at least one node*/ if( !portinfo[i].nodes ) continue; nodes = NULL; nodecount = 0; tempFd = dc1394_create_handle( i ); /* skip this port if we can't obtain a valid handle */ if(!tempFd) continue; msg_Dbg( p_demux, "Found ieee1394 port %d (%s) ... " "checking for camera nodes", i, portinfo[i].name ); num_ports++; nodes = dc1394_get_camera_nodes( tempFd, &nodecount, 0 ); if( nodecount ) { msg_Dbg( p_demux, "Found %d dc1394 cameras on port %d (%s)", nodecount, i, portinfo[i].name ); if(node_list) node_list = realloc( node_list, sizeof(dc_camera) * (num_cameras+nodecount) ); else node_list = malloc( sizeof(dc_camera) * nodecount); for( n = 0; n < nodecount; n++ ) { int result = 0; result = dc1394_get_camera_info( tempFd, nodes[n], &info ); if( result == DC1394_SUCCESS ) { node_list[num_cameras+n].uid = info.euid_64; } node_list[num_cameras+n].node = nodes[n]; node_list[num_cameras+n].port = i; } num_cameras += nodecount; } else msg_Dbg( p_demux, "no cameras found on port %d (%s)", i, portinfo[i].name); if(tempFd) dc1394_destroy_handle( tempFd ); } sys->num_ports = num_ports; sys->num_cameras = num_cameras; sys->camera_nodes = node_list; return VLC_SUCCESS;}/***************************************************************************** * Open: *****************************************************************************/static int Open( vlc_object_t *p_this ){ demux_t *p_demux = (demux_t*)p_this; demux_sys_t *p_sys; es_format_t fmt; int i; int i_width; int i_height; int i_aspect; int result = 0; /* Set up p_demux */ p_demux->pf_demux = Demux; p_demux->pf_control = Control; p_demux->info.i_update = 0; p_demux->info.i_title = 0; p_demux->info.i_seekpoint = 0; p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) ); if( !p_sys ) { msg_Err( p_demux, "not enough memory available" ); return VLC_ENOMEM; } memset( p_sys, 0, sizeof( demux_sys_t ) ); memset( &fmt, 0, sizeof( es_format_t ) ); /* DEFAULTS */ p_sys->frame_size = MODE_640x480_YUV422; p_sys->width = 640; p_sys->height = 480; p_sys->frame_rate = FRAMERATE_30; p_sys->brightness = 200; p_sys->focus = 0; p_sys->dma_capture = DMA_ON; /* defaults to VIDEO1394 capture mode */ p_sys->fd_audio = -1; p_sys->fd_video = NULL; p_sys->camera_nodes = NULL; p_sys->selected_camera = 0; p_sys->dma_device = NULL; p_sys->selected_uid = 0; p_sys->rotate = NO_ROTATION; /* PROCESS INPUT OPTIONS */ if( process_options(p_demux) != VLC_SUCCESS ) { msg_Err( p_demux, "Bad MRL, please check the option line " "(MRL was: %s)", p_demux->psz_path ); free( p_sys ); p_demux->p_sys = NULL; return VLC_EGENERIC; } msg_Dbg( p_demux, "Selected camera %d", p_sys->selected_camera ); msg_Dbg( p_demux, "Selected uid 0x%llx", p_sys->selected_uid ); ScanCameras( p_sys, p_demux ); if( !p_sys->camera_nodes ) { msg_Err( p_demux, "No camera found !!" ); Close( p_this ); return VLC_EGENERIC; } if( p_sys->selected_uid ) { int found = 0; for( i=0; i < p_sys->num_cameras; i++ ) { if( p_sys->camera_nodes[i].uid == p_sys->selected_uid ) { p_sys->selected_camera = i; found++; break; } } if( !found ) { msg_Err( p_demux, "Can't find camera with uid : 0x%llx.", p_sys->selected_uid ); Close( p_this ); return VLC_EGENERIC; } } else if( p_sys->selected_camera >= p_sys->num_cameras ) { msg_Err( p_demux, "there are not this many cameras. (%d/%d)", p_sys->selected_camera, p_sys->num_cameras ); Close( p_this ); return VLC_EGENERIC; } p_sys->fd_video = dc1394_create_handle( p_sys->camera_nodes[p_sys->selected_camera].port ); if( (int)p_sys->fd_video < 0 ) { msg_Err( p_demux, "Can't init dc1394 handle" ); Close( p_this ); return VLC_EGENERIC; } /* get camera info */ result = dc1394_get_camera_info( p_sys->fd_video, p_sys->camera_nodes[p_sys->selected_camera].node, &p_sys->camera_info ); if( result != DC1394_SUCCESS ) { msg_Err( p_demux ,"unable to get camera info" ); Close( p_this ); return VLC_EGENERIC; } dc1394_print_camera_info( &p_sys->camera_info ); result = dc1394_get_camera_misc_info( p_sys->fd_video, p_sys->camera_nodes[p_sys->selected_camera].node, &p_sys->misc_info ); if( result != DC1394_SUCCESS ) { msg_Err( p_demux, "unable to get camera misc info" ); Close( p_this ); return VLC_EGENERIC; } /* init camera and set some video options */ result = dc1394_init_camera( p_sys->camera_info.handle, p_sys->camera_info.id ); if( result != DC1394_SUCCESS ) { msg_Err( p_demux, "unable to get init dc1394 camera" ); Close( p_this ); return VLC_EGENERIC; } if( p_sys->focus ) { result = dc1394_set_focus( p_sys->camera_info.handle, p_sys->camera_nodes[p_sys->selected_camera].node, p_sys->focus ); if( result != DC1394_SUCCESS ) { msg_Err( p_demux, "unable to set initial focus to %u", p_sys->focus ); } msg_Dbg( p_demux, "Initial focus set to %u", p_sys->focus ); } result = dc1394_set_brightness( p_sys->camera_info.handle, p_sys->camera_nodes[p_sys->selected_camera].node, p_sys->brightness ); if( result != DC1394_SUCCESS ) { msg_Err( p_demux, "unable to set init brightness to %d", p_sys->brightness);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -