📄 dc1394.c
字号:
Close( p_this ); return VLC_EGENERIC; } result = dc1394_set_video_framerate( p_sys->camera_info.handle, p_sys->camera_nodes[p_sys->selected_camera].node, p_sys->frame_rate ); if( result != DC1394_SUCCESS ) { msg_Err( p_demux, "unable to set framerate to %d", p_sys->frame_rate ); Close( p_this ); return VLC_EGENERIC; } p_sys->misc_info.framerate = p_sys->frame_rate; result = dc1394_set_video_format( p_sys->camera_info.handle, p_sys->camera_nodes[p_sys->selected_camera].node, FORMAT_VGA_NONCOMPRESSED ); if( result != DC1394_SUCCESS ) { msg_Err( p_demux, "unable to set video format to VGA_NONCOMPRESSED" ); Close( p_this ); return VLC_EGENERIC; } p_sys->misc_info.format = FORMAT_VGA_NONCOMPRESSED; result = dc1394_set_video_mode( p_sys->camera_info.handle, p_sys->camera_nodes[p_sys->selected_camera].node, p_sys->frame_size ); if( result != DC1394_SUCCESS ) { msg_Err( p_demux, "unable to set video mode" ); Close( p_this ); return VLC_EGENERIC; } p_sys->misc_info.mode = p_sys->frame_size; /* reprobe everything */ result = dc1394_get_camera_info( p_sys->camera_info.handle, p_sys->camera_info.id, &p_sys->camera_info ); if( result != DC1394_SUCCESS ) { msg_Err( p_demux, "Could not get camera basic information!" ); Close( p_this ); return VLC_EGENERIC; } result = dc1394_get_camera_misc_info( p_sys->camera_info.handle, p_sys->camera_info.id, &p_sys->misc_info ); if( result != DC1394_SUCCESS ) { msg_Err( p_demux, "Could not get camera misc information!" ); Close( p_this ); return VLC_EGENERIC; } /* set iso_channel */ result = dc1394_set_iso_channel_and_speed( p_sys->camera_info.handle, p_sys->camera_info.id, p_sys->selected_camera, SPEED_400 ); if( result != DC1394_SUCCESS ) { msg_Err( p_demux, "Could not set iso channel!" ); Close( p_this ); return VLC_EGENERIC; } msg_Dbg( p_demux, "Using ISO channel %d", p_sys->misc_info.iso_channel ); p_sys->misc_info.iso_channel = p_sys->selected_camera; /* and setup capture */ if( p_sys->dma_capture ) { result = dc1394_dma_setup_capture( p_sys->camera_info.handle, p_sys->camera_info.id, p_sys->misc_info.iso_channel, p_sys->misc_info.format, p_sys->misc_info.mode, SPEED_400, p_sys->misc_info.framerate, 10, 0, p_sys->dma_device, &p_sys->camera ); if( result != DC1394_SUCCESS ) { msg_Err( p_demux ,"unable to setup camera" ); Close( p_this ); return VLC_EGENERIC; } } else { result = dc1394_setup_capture( p_sys->camera_info.handle, p_sys->camera_info.id, p_sys->misc_info.iso_channel, p_sys->misc_info.format, p_sys->misc_info.mode, SPEED_400, p_sys->misc_info.framerate, &p_sys->camera ); if( result != DC1394_SUCCESS) { msg_Err( p_demux ,"unable to setup camera" ); Close( p_this ); return VLC_EGENERIC; } } /* TODO - UYV444 chroma converter is missing, when it will be available * fourcc will become variable (and not just a fixed value for UYVY) */ if( p_sys->rotate == NO_ROTATION ) { i_width = p_sys->camera.frame_width; i_height = p_sys->camera.frame_height; } else { i_width = p_sys->camera.frame_height; i_height = p_sys->camera.frame_width; } i_aspect = vout_InitPicture( VLC_OBJECT(p_demux), &p_sys->pic, VLC_FOURCC('U', 'Y', 'V', 'Y'), i_width, i_height, i_width * VOUT_ASPECT_FACTOR / i_height ); es_format_Init( &fmt, VIDEO_ES, VLC_FOURCC('U', 'Y', 'V', 'Y') ); fmt.video.i_width = i_width; fmt.video.i_height = i_height; msg_Dbg( p_demux, "added new video es %4.4s %dx%d", (char*)&fmt.i_codec, fmt.video.i_width, fmt.video.i_height ); p_sys->p_es_video = es_out_Add( p_demux->out, &fmt ); if( p_sys->audio_device ) { OpenAudioDev( p_demux ); if( p_sys->fd_audio >= 0 ) { es_format_t fmt; es_format_Init( &fmt, AUDIO_ES, VLC_FOURCC('a','r','a','w') ); fmt.audio.i_channels = p_sys->channels ? p_sys->channels : 1; fmt.audio.i_rate = p_sys->i_sample_rate; fmt.audio.i_bitspersample = 16; /* FIXME: hmm, ?? */ fmt.audio.i_blockalign = fmt.audio.i_channels * fmt.audio.i_bitspersample / 8; fmt.i_bitrate = fmt.audio.i_channels * fmt.audio.i_rate * fmt.audio.i_bitspersample; msg_Dbg( p_demux, "new audio es %d channels %dHz", fmt.audio.i_channels, fmt.audio.i_rate ); p_sys->p_es_audio = es_out_Add( p_demux->out, &fmt ); } } /* have the camera start sending us data */ result = dc1394_start_iso_transmission( p_sys->camera_info.handle, p_sys->camera_info.id ); if( result != DC1394_SUCCESS ) { msg_Err( p_demux, "unable to start camera iso transmission" ); if( p_sys->dma_capture ) { dc1394_dma_release_camera( p_sys->fd_video, &p_sys->camera ); } else { dc1394_release_camera( p_sys->fd_video, &p_sys->camera ); } Close( p_this ); return VLC_EGENERIC; } p_sys->misc_info.is_iso_on = DC1394_TRUE; return VLC_SUCCESS;}static void OpenAudioDev( demux_t *p_demux ){ demux_sys_t *p_sys = p_demux->p_sys; char *psz_device = p_sys->audio_device; int i_format = AFMT_S16_LE; int result; p_sys->fd_audio = open( psz_device, O_RDONLY | O_NONBLOCK ); if( p_sys->fd_audio < 0 ) { msg_Err( p_demux, "cannot open audio device (%s)", psz_device ); CloseAudioDev( p_demux ); } if( !p_sys->i_sample_rate ) p_sys->i_sample_rate = 44100; result = ioctl( p_sys->fd_audio, SNDCTL_DSP_SETFMT, &i_format ); if( (result < 0) || (i_format != AFMT_S16_LE) ) { msg_Err( p_demux, "cannot set audio format (16b little endian) " "(%d)", i_format ); CloseAudioDev( p_demux ); } result = ioctl( p_sys->fd_audio, SNDCTL_DSP_CHANNELS, &p_sys->channels ); if( result < 0 ) { msg_Err( p_demux, "cannot set audio channels count (%d)", p_sys->channels ); CloseAudioDev( p_demux ); } result = ioctl( p_sys->fd_audio, SNDCTL_DSP_SPEED, &p_sys->i_sample_rate ); if( result < 0 ) { msg_Err( p_demux, "cannot set audio sample rate (%d)", p_sys->i_sample_rate ); CloseAudioDev( p_demux ); } msg_Dbg( p_demux, "openened adev=`%s' %s %dHz", psz_device, (p_sys->channels > 1) ? "stereo" : "mono", p_sys->i_sample_rate ); p_sys->i_audio_max_frame_size = 32 * 1024;}static inline void CloseAudioDev( demux_t *p_demux ){ demux_sys_t *p_sys = NULL; if( p_demux ) { p_sys = p_demux->p_sys; if( p_sys->fd_audio >= 0 ) close( p_sys->fd_audio ); }}/***************************************************************************** * Close: *****************************************************************************/static void Close( vlc_object_t *p_this ){ demux_t *p_demux = (demux_t*)p_this; demux_sys_t *p_sys = p_demux->p_sys; int result = 0; /* Stop data transmission */ result = dc1394_stop_iso_transmission( p_sys->fd_video, p_sys->camera.node ); if( result != DC1394_SUCCESS ) { msg_Err( p_demux, "couldn't stop the camera" ); } /* Close camera */ if( p_sys->dma_capture ) { dc1394_dma_unlisten( p_sys->fd_video, &p_sys->camera ); dc1394_dma_release_camera( p_sys->fd_video, &p_sys->camera ); } else { dc1394_release_camera( p_sys->fd_video, &p_sys->camera ); } if( p_sys->fd_video ) dc1394_destroy_handle( p_sys->fd_video ); CloseAudioDev( p_demux ); if( p_sys->camera_nodes ) free( p_sys->camera_nodes ); if( p_sys->audio_device ) free( p_sys->audio_device ); free( p_sys );}static void MovePixelUYVY( void *src, int spos, void *dst, int dpos ){ char u,v,y; u_char *sc; u_char *dc; sc = (u_char *)src + (spos*2); if( spos % 2 ) { v = sc[0]; y = sc[1]; u = *(sc -2); } else { u = sc[0]; y = sc[1]; v = sc[2]; } dc = (u_char *)dst+(dpos*2); if( dpos % 2 ) { dc[0] = v; dc[1] = y; } else { dc[0] = u; dc[1] = y; }}/***************************************************************************** * Demux: *****************************************************************************/static block_t *GrabVideo( demux_t *p_demux ){ demux_sys_t *p_sys = p_demux->p_sys; block_t *p_block = NULL; int result = 0; if( p_sys->dma_capture ) { result = dc1394_dma_single_capture( &p_sys->camera ); if( result != DC1394_SUCCESS ) { msg_Err( p_demux, "unable to capture a frame" ); return NULL; } } else { result = dc1394_single_capture( p_sys->camera_info.handle, &p_sys->camera ); if( result != DC1394_SUCCESS ) { msg_Err( p_demux, "unable to capture a frame" ); return NULL; } } p_block = block_New( p_demux, p_sys->camera.frame_width * p_sys->camera.frame_height * 2 ); if( !p_block ) { msg_Err( p_demux, "cannot get block" ); return NULL; } if( !p_sys->camera.capture_buffer ) { msg_Err (p_demux, "caputer buffer empty"); block_Release( p_block ); return NULL; } if( p_sys->rotate == NO_ROTATION )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -