*
* Authors: Jean-Paul Saman <jpsaman at m2x dot nl>
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * This program 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; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
+ * 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 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 Lesser 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.
*****************************************************************************/
/*****************************************************************************
#include <errno.h>
#include <sys/types.h>
-#ifdef HAVE_UNISTD_H
-# include <unistd.h>
-#elif defined( WIN32 ) && !defined( UNDER_CE )
-# include <io.h>
-#endif
-
+#include <unistd.h>
#include <sys/poll.h>
#include <libraw1394/raw1394.h>
static block_t *Block( access_t * );
static int Control( access_t *, int, va_list );
-#define CACHING_TEXT N_("Caching value in ms")
-#define CACHING_LONGTEXT N_( \
- "Caching value for DV streams. This " \
- "value should be set in milliseconds." )
-
vlc_module_begin ()
- set_description( N_("Digital Video (Firewire/ieee1394) input") )
+ 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, CACHING_TEXT, CACHING_LONGTEXT, true )
- change_safe()
set_capability( "access", 0 )
- add_shortcut( "dv", "dv1394", "raw1394" )
+ add_shortcut( "dv", "raw1394" )
set_callbacks( Open, Close )
vlc_module_end ()
typedef struct
{
- VLC_COMMON_MEMBERS
-
+ vlc_thread_t thread;
access_t *p_access;
vlc_mutex_t lock;
block_t *p_frame;
} event_thread_t;
-static void* Raw1394EventThread( vlc_object_t * );
+static void* Raw1394EventThread( void * );
static enum raw1394_iso_disposition
Raw1394Handler(raw1394handle_t, unsigned char *,
unsigned int, unsigned char,
p_sys->raw1394_poll.fd = raw1394_get_fd( p_sys->p_raw1394 );
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 ) );
+ p_sys->p_ev = calloc( 1, sizeof( *p_sys->p_ev ) );
if( !p_sys->p_ev )
{
- msg_Err( p_access, "failed to create event thread" );
+ msg_Err( p_access, "failed to create event thread struct" );
Close( p_this );
- return VLC_EGENERIC;
+ return VLC_ENOMEM;
}
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_sys->p_ev->lock );
- vlc_thread_create( p_sys->p_ev, "dv event thread handler",
- Raw1394EventThread, VLC_THREAD_PRIORITY_OUTPUT );
+ if( vlc_clone( &p_sys->p_ev->thread, Raw1394EventThread,
+ p_sys->p_ev, VLC_THREAD_PRIORITY_OUTPUT ) )
+ {
+ msg_Err( p_access, "failed to clone event thread" );
+ Close( p_this );
+ return VLC_EGENERIC;
+ }
return VLC_SUCCESS;
}
if( p_sys->p_ev )
{
/* stop the event handler */
- vlc_object_kill( p_sys->p_ev );
+ vlc_cancel( p_sys->p_ev->thread );
if( p_sys->p_raw1394 )
raw1394_iso_shutdown( p_sys->p_raw1394 );
- vlc_thread_join( p_sys->p_ev );
+ vlc_join( p_sys->p_ev->thread, NULL );
vlc_mutex_destroy( &p_sys->p_ev->lock );
/* Cleanup frame data */
p_sys->p_ev->p_frame = NULL;
p_sys->p_ev->pp_last = &p_sys->p_frame;
}
- vlc_object_release( p_sys->p_ev );
+ free( p_sys->p_ev );
}
if( p_sys->p_frame )
break;
case ACCESS_GET_PTS_DELAY:
- *va_arg( args, int64_t * )
- = var_GetInteger( p_access, "dv-caching" ) * 1000;
+ *va_arg( args, int64_t * ) =
+ INT64_C(1000) * var_InheritInteger( p_access, "live-caching" );
break;
/* */
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:
- msg_Warn( p_access, "unimplemented query in control" );
return VLC_EGENERIC;
}
return p_block;
}
-static void* Raw1394EventThread( vlc_object_t *p_this )
+static void Raw1394EventThreadCleanup( void *obj )
+{
+ event_thread_t *p_ev = (event_thread_t *)obj;
+
+ AVCStop( p_ev->p_access, p_ev->p_access->p_sys->i_node );
+}
+
+static void* Raw1394EventThread( void *obj )
{
- event_thread_t *p_ev = (event_thread_t *) p_this;
+ event_thread_t *p_ev = (event_thread_t *)obj;
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 ();
+ int canc = vlc_savecancel();
AVCPlay( p_access, p_sys->i_node );
+ vlc_cleanup_push( Raw1394EventThreadCleanup, p_ev );
+ vlc_restorecancel( canc );
- while( vlc_object_alive (p_sys->p_ev) )
+ for( ;; )
{
- while( ( result = poll( &(p_sys->raw1394_poll), 1, 200 ) ) < 0 )
+ while( ( result = poll( &p_sys->raw1394_poll, 1, -1 ) ) < 0 )
{
- if( !( errno == EAGAIN || errno == EINTR ) )
- {
- perror( "error: raw1394 poll" );
- msg_Err( p_access, "retrying device raw1394" );
- }
+ if( errno != EINTR )
+ msg_Err( p_access, "poll error: %s", vlc_strerror_c(errno) );
}
- if( !vlc_object_alive (p_sys->p_ev) )
- break;
+
if( result > 0 && ( ( p_sys->raw1394_poll.revents & POLLIN )
- || ( p_sys->raw1394_poll.revents & POLLPRI ) ) )
+ || ( p_sys->raw1394_poll.revents & POLLPRI ) ) )
+ {
+ canc = vlc_savecancel();
result = raw1394_loop_iterate( p_sys->p_raw1394 );
+ vlc_restorecancel( canc );
+ }
}
- AVCStop( p_access, p_sys->i_node );
- vlc_restorecancel (canc);
+ vlc_cleanup_run();
return NULL;
}
block_ChainAppend( &p_sys->p_frame, p_sys->p_ev->p_frame );
}
/* reset list */
- p_sys->p_ev->p_frame = block_New( p_access, 144000 );
+ p_sys->p_ev->p_frame = block_Alloc( 144000 );
p_sys->p_ev->pp_last = &p_sys->p_frame;
vlc_mutex_unlock( &p_sys->lock );
}
/* get a raw1394 handle */
if( !( handle = raw1394_new_handle() ) )
{
- msg_Err( p_access, "raw1394 - failed to get handle: %m." );
+ msg_Err( p_access, "raw1394 - failed to get handle: %s",
+ vlc_strerror_c(errno) );
return VLC_EGENERIC;
}
if( ( n_ports = raw1394_get_port_info( handle, pinf, 16 ) ) < 0 )
{
- msg_Err( p_access, "raw1394 - failed to get port info: %m." );
+ msg_Err( p_access, "raw1394 - failed to get port info: %s",
+ vlc_strerror_c(errno) );
raw1394_destroy_handle( handle );
return VLC_EGENERIC;
}
handle = raw1394_new_handle();
if( !handle )
{
- msg_Err( p_access, "raw1394 - failed to get handle: %m." );
+ msg_Err( p_access, "raw1394 - failed to get handle: %s",
+ vlc_strerror_c(errno) );
return NULL;
}
if( ( n_ports = raw1394_get_port_info( handle, pinf, 16 ) ) < 0 )
{
- msg_Err( p_access, "raw1394 - failed to get port info: %m." );
+ msg_Err( p_access, "raw1394 - failed to get port info: %s",
+ vlc_strerror_c(errno) );
raw1394_destroy_handle( handle );
return NULL;
}
/* tell raw1394 which host adapter to use */
if( raw1394_set_port( handle, port ) < 0 )
{
- msg_Err( p_access, "raw1394 - failed to set set port: %m." );
+ msg_Err( p_access, "raw1394 - failed to set set port: %s",
+ vlc_strerror_c(errno) );
return NULL;
}