X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Faccess%2Fdv.c;h=372bf74653301345775aab0310b5e47d92a71d30;hb=bc09c365ab435fda0185e60a423f69d6dfa348c8;hp=ab3dde62fc6f60abaf2e407521d24d77ff69d007;hpb=2cb472dba008f7d877ffe6bae9c5575253365282;p=vlc diff --git a/modules/access/dv.c b/modules/access/dv.c index ab3dde62fc..372bf74653 100644 --- a/modules/access/dv.c +++ b/modules/access/dv.c @@ -16,33 +16,24 @@ * 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. *****************************************************************************/ /***************************************************************************** * Preamble *****************************************************************************/ -#include -#include - -#include -#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 +#ifdef HAVE_CONFIG_H +# include "config.h" #endif +#include +#include +#include + +#include +#include #ifdef HAVE_UNISTD_H # include #elif defined( WIN32 ) && !defined( UNDER_CE ) @@ -67,21 +58,20 @@ static int Control( access_t *, int, va_list ); #define CACHING_TEXT N_("Caching value in ms") #define CACHING_LONGTEXT N_( \ - "Allows you to modify the default caching value for file streams. This " \ - "value should be set in millisecond units." ) - -vlc_module_begin(); - set_description( _("Digital Video (Firewire/ieee1394) input") ); - set_shortname( _("dv") ); - set_category( CAT_INPUT ); - set_subcategory( SUBCAT_INPUT_ACCESS ); - add_integer( "dv-caching", 60000 / 1000, NULL, CACHING_TEXT, CACHING_LONGTEXT, VLC_TRUE ); - set_capability( "access2", 0 ); - add_shortcut( "dv" ); - add_shortcut( "dv1394" ); - add_shortcut( "raw1394" ); - set_callbacks( Open, Close ); -vlc_module_end(); + "Caching value for DV streams. This " \ + "value should be set in milliseconds." ) + +vlc_module_begin () + set_description( N_("Digital Video (Firewire/ieee1394) input") ) + set_shortname( N_("DV") ) + set_category( CAT_INPUT ) + set_subcategory( SUBCAT_INPUT_ACCESS ) + add_integer( "dv-caching", 60000 / 1000, NULL, CACHING_TEXT, CACHING_LONGTEXT, true ) + change_safe() + set_capability( "access", 0 ) + add_shortcut( "dv", "dv1394", "raw1394" ) + set_callbacks( Open, Close ) +vlc_module_end () typedef struct { @@ -94,8 +84,12 @@ typedef struct } event_thread_t; -static int Raw1394EventThread( vlc_object_t * ); -static int Raw1394Handler( raw1394handle_t, int, size_t, quadlet_t * ); +static void* Raw1394EventThread( vlc_object_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 ); @@ -127,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 *****************************************************************************/ @@ -134,32 +131,18 @@ 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 */ - p_access->pf_read = NULL; - p_access->pf_block = Block; - p_access->pf_control = Control; - p_access->pf_seek = NULL; - p_access->info.i_update = 0; - p_access->info.i_size = 0; - p_access->info.i_pos = 0; - p_access->info.b_eof = VLC_FALSE; - p_access->info.b_prebuffered = VLC_FALSE; - p_access->info.i_title = 0; - p_access->info.i_seekpoint = 0; + access_InitFields( p_access ); + ACCESS_SET_CALLBACKS( NULL, Block, Control, NULL ); 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; @@ -169,74 +152,83 @@ static int Open( vlc_object_t *p_this ) p_sys->p_raw1394 = NULL; p_sys->p_avc1394 = NULL; p_sys->p_frame = NULL; + p_sys->p_ev = NULL; - vlc_mutex_init( p_access, &p_sys->lock ); + vlc_mutex_init( &p_sys->lock ); p_sys->i_node = DiscoverAVC( p_access, &p_sys->i_port, p_sys->i_guid ); if( p_sys->i_node < 0 ) { 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 | POLLERR | POLLHUP | POLLPRI; + p_sys->raw1394_poll.events = POLLIN | POLLPRI; /* Update default_pts to a suitable value for udp access */ var_Create( p_access, "dv-caching", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT ); /* Now create our event thread catcher */ 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" ); + Close( p_this ); + return VLC_EGENERIC; + } + p_sys->p_ev->p_frame = NULL; p_sys->p_ev->pp_last = &p_sys->p_ev->p_frame; p_sys->p_ev->p_access = p_access; - vlc_mutex_init( p_access, &p_sys->p_ev->lock ); - vlc_thread_create( p_sys->p_ev, "dv event thread handler", Raw1394EventThread, - VLC_THREAD_PRIORITY_OUTPUT, VLC_FALSE ); + vlc_mutex_init( &p_sys->p_ev->lock ); + vlc_thread_create( p_sys->p_ev, "dv event thread handler", + Raw1394EventThread, VLC_THREAD_PRIORITY_OUTPUT ); - free( psz_name ); return VLC_SUCCESS; } @@ -251,24 +243,22 @@ static void Close( vlc_object_t *p_this ) if( p_sys->p_ev ) { /* stop the event handler */ - p_sys->p_ev->b_die = VLC_TRUE; + 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_destroy( p_sys->p_ev ); + vlc_object_release( p_sys->p_ev ); } if( p_sys->p_frame ) @@ -287,39 +277,34 @@ 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; - vlc_bool_t *pb_bool; - int64_t *pi_64; - switch( i_query ) { /* */ - case ACCESS_CAN_SEEK: - case ACCESS_CAN_FASTSEEK: case ACCESS_CAN_PAUSE: - pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* ); - *pb_bool = VLC_TRUE; + *va_arg( args, bool* ) = true; break; - case ACCESS_CAN_CONTROL_PACE: - pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* ); - *pb_bool = VLC_FALSE; + case ACCESS_CAN_SEEK: + case ACCESS_CAN_FASTSEEK: + case ACCESS_CAN_CONTROL_PACE: + *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: case ACCESS_SET_TITLE: case ACCESS_SET_SEEKPOINT: case ACCESS_SET_PRIVATE_ID_STATE: + case ACCESS_GET_CONTENT_TYPE: return VLC_EGENERIC; default: @@ -335,9 +320,6 @@ static block_t *Block( access_t *p_access ) access_sys_t *p_sys = p_access->p_sys; block_t *p_block = NULL; -// if( !p_access->psz_demux ) -// p_access->psz_demux = strdup( "rawdv" ); - vlc_mutex_lock( &p_sys->lock ); p_block = p_sys->p_frame; //msg_Dbg( p_access, "sending frame %p",p_block ); @@ -347,18 +329,17 @@ static block_t *Block( access_t *p_access ) return p_block; } -static int Raw1394EventThread( vlc_object_t *p_this ) +static void* Raw1394EventThread( vlc_object_t *p_this ) { event_thread_t *p_ev = (event_thread_t *) p_this; access_t *p_access = (access_t *) p_ev->p_access; access_sys_t *p_sys = (access_sys_t *) p_access->p_sys; int result = 0; + int canc = vlc_savecancel (); AVCPlay( p_access, p_sys->i_node ); - vlc_thread_ready( p_this ); - - while( !p_sys->p_ev->b_die ) + while( vlc_object_alive (p_sys->p_ev) ) { while( ( result = poll( &(p_sys->raw1394_poll), 1, 200 ) ) < 0 ) { @@ -367,10 +348,8 @@ static int Raw1394EventThread( vlc_object_t *p_this ) perror( "error: raw1394 poll" ); msg_Err( p_access, "retrying device raw1394" ); } - if( p_sys->p_ev->b_die ) - break; } - if( p_sys->p_ev->b_die ) + if( !vlc_object_alive (p_sys->p_ev) ) break; if( result > 0 && ( ( p_sys->raw1394_poll.revents & POLLIN ) || ( p_sys->raw1394_poll.revents & POLLPRI ) ) ) @@ -378,14 +357,21 @@ static int Raw1394EventThread( vlc_object_t *p_this ) } AVCStop( p_access, p_sys->i_node ); - return VLC_SUCCESS; + vlc_restorecancel (canc); + 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; @@ -393,9 +379,9 @@ static int Raw1394Handler( raw1394handle_t handle, int channel, size_t length, q p_sys = p_access->p_sys; /* skip empty packets */ - if ( length > 16 ) + 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; @@ -468,15 +455,15 @@ static int Raw1394GetNumPorts( access_t *p_access ) raw1394handle_t handle; /* get a raw1394 handle */ - if ( !( handle = raw1394_new_handle() ) ) + if( !( handle = raw1394_new_handle() ) ) { - msg_Err( p_access, "raw1394 - failed to get handle: %s.\n", strerror( errno ) ); + msg_Err( p_access, "raw1394 - failed to get handle: %m." ); return VLC_EGENERIC; } - if ( ( n_ports = raw1394_get_port_info( handle, pinf, 16 ) ) < 0 ) + if( ( n_ports = raw1394_get_port_info( handle, pinf, 16 ) ) < 0 ) { - msg_Err( p_access, "raw1394 - failed to get port info: %s.\n", strerror( errno ) ); + msg_Err( p_access, "raw1394 - failed to get port info: %m." ); raw1394_destroy_handle( handle ); return VLC_EGENERIC; } @@ -492,31 +479,24 @@ static raw1394handle_t Raw1394Open( access_t *p_access, int port ) raw1394handle_t handle; /* get a raw1394 handle */ -#ifdef RAW1394_V_0_8 - - handle = raw1394_get_handle(); -#else - handle = raw1394_new_handle(); -#endif - - if ( !handle ) + if( !handle ) { - msg_Err( p_access, "raw1394 - failed to get handle: %s.\n", strerror( errno ) ); + msg_Err( p_access, "raw1394 - failed to get handle: %m." ); return NULL; } - if ( ( n_ports = raw1394_get_port_info( handle, pinf, 16 ) ) < 0 ) + if( ( n_ports = raw1394_get_port_info( handle, pinf, 16 ) ) < 0 ) { - msg_Err( p_access, "raw1394 - failed to get port info: %s.\n", strerror( errno ) ); + msg_Err( p_access, "raw1394 - failed to get port info: %m." ); raw1394_destroy_handle( handle ); return NULL; } /* tell raw1394 which host adapter to use */ - if ( raw1394_set_port( handle, port ) < 0 ) + if( raw1394_set_port( handle, port ) < 0 ) { - msg_Err( p_access, "raw1394 - failed to set set port: %s.\n", strerror( errno ) ); + msg_Err( p_access, "raw1394 - failed to set set port: %m." ); return NULL; } @@ -566,7 +546,7 @@ static int DiscoverAVC( access_t *p_access, int* port, uint64_t guid ) /* select first AV/C Tape Reccorder Player node */ if( rom1394_get_directory( handle, i, &rom_dir ) < 0 ) { - msg_Err( p_access, "error reading config rom directory for node %d\n", i ); + msg_Err( p_access, "error reading config rom directory for node %d", i ); continue; } if( ( rom1394_get_node_type( &rom_dir ) == ROM1394_NODE_TYPE_AVC ) && @@ -590,8 +570,8 @@ static int DiscoverAVC( access_t *p_access, int* port, uint64_t guid ) static raw1394handle_t AVCOpen( access_t *p_access, int port ) { access_sys_t *p_sys = p_access->p_sys; - int numcards; struct raw1394_portinfo pinf[ 16 ]; + int numcards; p_sys->p_avc1394 = raw1394_new_handle(); if( !p_sys->p_avc1394 ) @@ -619,7 +599,6 @@ static void AVCClose( access_t *p_access ) } } - static int AVCResetHandler( raw1394handle_t handle, unsigned int generation ) { raw1394_update_generation( handle, generation ); @@ -631,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 ) @@ -647,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 ) ) @@ -665,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;