X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Faccess%2Fdv.c;h=372bf74653301345775aab0310b5e47d92a71d30;hb=bc09c365ab435fda0185e60a423f69d6dfa348c8;hp=f611a04f4423fdfbda47ffb4340cb8520c6bbcd5;hpb=14f37b2101842fa6e427f962f689db74eff6faba;p=vlc diff --git a/modules/access/dv.c b/modules/access/dv.c index f611a04f44..372bf74653 100644 --- a/modules/access/dv.c +++ b/modules/access/dv.c @@ -16,9 +16,9 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ /***************************************************************************** @@ -33,19 +33,7 @@ #include #include -#ifdef HAVE_SYS_TYPES_H -# include -#endif -#ifdef HAVE_SYS_TIME_H -# include -#endif -#ifdef HAVE_SYS_STAT_H -# include -#endif -#ifdef HAVE_FCNTL_H -# include -#endif - +#include #ifdef HAVE_UNISTD_H # include #elif defined( WIN32 ) && !defined( UNDER_CE ) @@ -81,9 +69,7 @@ vlc_module_begin () add_integer( "dv-caching", 60000 / 1000, NULL, CACHING_TEXT, CACHING_LONGTEXT, true ) change_safe() set_capability( "access", 0 ) - add_shortcut( "dv" ) - add_shortcut( "dv1394" ) - add_shortcut( "raw1394" ) + add_shortcut( "dv", "dv1394", "raw1394" ) set_callbacks( Open, Close ) vlc_module_end () @@ -99,7 +85,11 @@ typedef struct } event_thread_t; static void* Raw1394EventThread( vlc_object_t * ); -static int Raw1394Handler( raw1394handle_t, int, size_t, quadlet_t * ); +static enum raw1394_iso_disposition +Raw1394Handler(raw1394handle_t, unsigned char *, + unsigned int, unsigned char, + unsigned char, unsigned char, unsigned int, + unsigned int); static int Raw1394GetNumPorts( access_t *p_access ); static raw1394handle_t Raw1394Open( access_t *, int ); @@ -131,6 +121,9 @@ struct access_sys_t block_t *p_frame; }; +#define ISOCHRONOUS_QUEUE_LENGTH 1000 +#define ISOCHRONOUS_MAX_PACKET_SIZE 4096 + /***************************************************************************** * Open: open the file *****************************************************************************/ @@ -138,12 +131,10 @@ static int Open( vlc_object_t *p_this ) { access_t *p_access = (access_t*)p_this; access_sys_t *p_sys; - char *psz_name = strdup( p_access->psz_path ); struct raw1394_portinfo port_inf[ 16 ]; - iso_handler_t oldhandler; - msg_Dbg( p_access, "opening device %s", psz_name ); + msg_Dbg( p_access, "opening device" ); /* Set up p_access */ access_InitFields( p_access ); @@ -151,10 +142,7 @@ static int Open( vlc_object_t *p_this ) p_access->p_sys = p_sys = malloc( sizeof( access_sys_t ) ); if( !p_sys ) - { - free( psz_name ); return VLC_EGENERIC; - } p_sys->i_cards = 0; p_sys->i_node = 0; @@ -173,49 +161,51 @@ static int Open( vlc_object_t *p_this ) { msg_Err( p_access, "failed to open a Firewire (IEEE1394) connection" ); Close( p_this ); - free( psz_name ); return VLC_EGENERIC; } p_sys->p_avc1394 = AVCOpen( p_access, p_sys->i_port ); if( !p_sys->p_avc1394 ) { - msg_Err( p_access, "no Digital Video Control device found on %s", psz_name ); + msg_Err( p_access, "no Digital Video Control device found" ); Close( p_this ); - free( psz_name ); return VLC_EGENERIC; } p_sys->p_raw1394 = raw1394_new_handle(); if( !p_sys->p_raw1394 ) { - msg_Err( p_access, "no Digital Video device found on %s", psz_name ); + msg_Err( p_access, "no Digital Video device found" ); Close( p_this ); - free( psz_name ); return VLC_EGENERIC; } p_sys->i_cards = raw1394_get_port_info( p_sys->p_raw1394, port_inf, 16 ); if( p_sys->i_cards < 0 ) { - msg_Err( p_access, "failed to get port info for %s", psz_name ); + msg_Err( p_access, "failed to get port info" ); Close( p_this ); - free( psz_name ); return VLC_EGENERIC; } if( raw1394_set_port( p_sys->p_raw1394, p_sys->i_port ) < 0 ) { - msg_Err( p_access, "failed to set port info for %s", psz_name ); + msg_Err( p_access, "failed to set port info" ); + Close( p_this ); + return VLC_EGENERIC; + } + + if ( raw1394_iso_recv_init( p_sys->p_raw1394, Raw1394Handler, + ISOCHRONOUS_QUEUE_LENGTH, ISOCHRONOUS_MAX_PACKET_SIZE, + p_sys->i_channel, RAW1394_DMA_PACKET_PER_BUFFER, -1 ) < 0 ) + { + msg_Err( p_access, "failed to init isochronous recv" ); Close( p_this ); - free( psz_name ); return VLC_EGENERIC; } - oldhandler = raw1394_set_iso_handler( p_sys->p_raw1394, - p_sys->i_channel, Raw1394Handler ); raw1394_set_userdata( p_sys->p_raw1394, p_access ); - raw1394_start_iso_rcv( p_sys->p_raw1394, p_sys->i_channel ); + raw1394_iso_recv_start( p_sys->p_raw1394, -1, -1, 0 ); p_sys->raw1394_poll.fd = raw1394_get_fd( p_sys->p_raw1394 ); p_sys->raw1394_poll.events = POLLIN | POLLPRI; @@ -227,9 +217,8 @@ static int Open( vlc_object_t *p_this ) p_sys->p_ev = vlc_object_create( p_access, sizeof( event_thread_t ) ); if( !p_sys->p_ev ) { - msg_Err( p_access, "failed to create event thread for %s", psz_name ); + msg_Err( p_access, "failed to create event thread" ); Close( p_this ); - free( psz_name ); return VLC_EGENERIC; } @@ -240,7 +229,6 @@ static int Open( vlc_object_t *p_this ) vlc_thread_create( p_sys->p_ev, "dv event thread handler", Raw1394EventThread, VLC_THREAD_PRIORITY_OUTPUT ); - free( psz_name ); return VLC_SUCCESS; } @@ -258,19 +246,17 @@ static void Close( vlc_object_t *p_this ) vlc_object_kill( p_sys->p_ev ); if( p_sys->p_raw1394 ) - raw1394_stop_iso_rcv( p_sys->p_raw1394, p_sys->i_channel ); + raw1394_iso_shutdown( p_sys->p_raw1394 ); - vlc_mutex_destroy( &p_sys->p_ev->lock ); vlc_thread_join( p_sys->p_ev ); + vlc_mutex_destroy( &p_sys->p_ev->lock ); /* Cleanup frame data */ if( p_sys->p_ev->p_frame ) { - vlc_mutex_lock( &p_sys->p_ev->lock ); block_ChainRelease( p_sys->p_ev->p_frame ); p_sys->p_ev->p_frame = NULL; p_sys->p_ev->pp_last = &p_sys->p_frame; - vlc_mutex_unlock( &p_sys->p_ev->lock ); } vlc_object_release( p_sys->p_ev ); } @@ -291,33 +277,27 @@ static void Close( vlc_object_t *p_this ) *****************************************************************************/ static int Control( access_t *p_access, int i_query, va_list args ) { - access_sys_t *p_sys = p_access->p_sys; - bool *pb_bool; - int64_t *pi_64; - switch( i_query ) { /* */ case ACCESS_CAN_PAUSE: - pb_bool = (bool*)va_arg( args, bool* ); - *pb_bool = true; + *va_arg( args, bool* ) = true; break; case ACCESS_CAN_SEEK: case ACCESS_CAN_FASTSEEK: case ACCESS_CAN_CONTROL_PACE: - pb_bool = (bool*)va_arg( args, bool* ); - *pb_bool = false; + *va_arg( args, bool* ) = false; break; case ACCESS_GET_PTS_DELAY: - pi_64 = (int64_t*)va_arg( args, int64_t * ); - *pi_64 = var_GetInteger( p_access, "dv-caching" ) * 1000; + *va_arg( args, int64_t * ) + = var_GetInteger( p_access, "dv-caching" ) * 1000; break; /* */ case ACCESS_SET_PAUSE_STATE: - AVCPause( p_access, p_sys->i_node ); + AVCPause( p_access, p_access->p_sys->i_node ); break; case ACCESS_GET_TITLE_INFO: @@ -381,11 +361,17 @@ static void* Raw1394EventThread( vlc_object_t *p_this ) return NULL; } -static int Raw1394Handler( raw1394handle_t handle, int channel, size_t length, quadlet_t *data ) +static enum raw1394_iso_disposition +Raw1394Handler(raw1394handle_t handle, unsigned char *data, + unsigned int length, unsigned char channel, + unsigned char tag, unsigned char sy, unsigned int cycle, + unsigned int dropped) { access_t *p_access = NULL; access_sys_t *p_sys = NULL; block_t *p_block = NULL; + VLC_UNUSED(channel); VLC_UNUSED(tag); + VLC_UNUSED(sy); VLC_UNUSED(cycle); VLC_UNUSED(dropped); p_access = (access_t *) raw1394_get_userdata( handle ); if( !p_access ) return 0; @@ -395,7 +381,7 @@ static int Raw1394Handler( raw1394handle_t handle, int channel, size_t length, q /* skip empty packets */ if( length > 16 ) { - unsigned char * p = ( unsigned char* ) &data[ 3 ]; + unsigned char * p = data + 8; int section_type = p[ 0 ] >> 5; /* section type is in bits 5 - 7 */ int dif_sequence = p[ 1 ] >> 4; /* dif sequence number is in bits 4 - 7 */ int dif_block = p[ 2 ]; @@ -451,6 +437,7 @@ static int Raw1394Handler( raw1394handle_t handle, int channel, size_t length, q break; } } + vlc_mutex_unlock( &p_sys->p_ev->lock ); } return 0; @@ -623,10 +610,8 @@ static int AVCPlay( access_t *p_access, int phyID ) access_sys_t *p_sys = p_access->p_sys; msg_Dbg( p_access, "send play command over Digital Video control channel" ); - if( !p_sys->p_avc1394 ) - return 0; - if( phyID >= 0 ) + if( p_sys->p_avc1394 && phyID >= 0 ) { if( !avc1394_vcr_is_recording( p_sys->p_avc1394, phyID ) && avc1394_vcr_is_playing( p_sys->p_avc1394, phyID ) != AVC1394_VCR_OPERAND_PLAY_FORWARD ) @@ -639,10 +624,7 @@ static int AVCPause( access_t *p_access, int phyID ) { access_sys_t *p_sys = p_access->p_sys; - if( !p_sys->p_avc1394 ) - return 0; - - if( phyID >= 0 ) + if( p_sys->p_avc1394 && phyID >= 0 ) { if( !avc1394_vcr_is_recording( p_sys->p_avc1394, phyID ) && ( avc1394_vcr_is_playing( p_sys->p_avc1394, phyID ) != AVC1394_VCR_OPERAND_PLAY_FORWARD_PAUSE ) ) @@ -657,10 +639,8 @@ static int AVCStop( access_t *p_access, int phyID ) access_sys_t *p_sys = p_access->p_sys; msg_Dbg( p_access, "closing Digital Video control channel" ); - if( !p_sys->p_avc1394 ) - return 0; - if ( phyID >= 0 ) + if ( p_sys->p_avc1394 && phyID >= 0 ) avc1394_vcr_stop( p_sys->p_avc1394, phyID ); return 0;