| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
#ifdef HAVE_CONFIG_H |
|---|
| 28 |
# include "config.h" |
|---|
| 29 |
#endif |
|---|
| 30 |
|
|---|
| 31 |
#include <vlc_common.h> |
|---|
| 32 |
#include <vlc_plugin.h> |
|---|
| 33 |
#include <vlc_access.h> |
|---|
| 34 |
|
|---|
| 35 |
#include <errno.h> |
|---|
| 36 |
#ifdef HAVE_SYS_TYPES_H |
|---|
| 37 |
# include <sys/types.h> |
|---|
| 38 |
#endif |
|---|
| 39 |
#ifdef HAVE_SYS_TIME_H |
|---|
| 40 |
# include <sys/time.h> |
|---|
| 41 |
#endif |
|---|
| 42 |
#ifdef HAVE_SYS_STAT_H |
|---|
| 43 |
# include <sys/stat.h> |
|---|
| 44 |
#endif |
|---|
| 45 |
#ifdef HAVE_FCNTL_H |
|---|
| 46 |
# include <fcntl.h> |
|---|
| 47 |
#endif |
|---|
| 48 |
|
|---|
| 49 |
#ifdef HAVE_UNISTD_H |
|---|
| 50 |
# include <unistd.h> |
|---|
| 51 |
#elif defined( WIN32 ) && !defined( UNDER_CE ) |
|---|
| 52 |
# include <io.h> |
|---|
| 53 |
#endif |
|---|
| 54 |
|
|---|
| 55 |
#include <sys/poll.h> |
|---|
| 56 |
|
|---|
| 57 |
#include <libraw1394/raw1394.h> |
|---|
| 58 |
#include <libraw1394/csr.h> |
|---|
| 59 |
#include <libavc1394/avc1394.h> |
|---|
| 60 |
#include <libavc1394/avc1394_vcr.h> |
|---|
| 61 |
#include <libavc1394/rom1394.h> |
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
static int Open ( vlc_object_t * ); |
|---|
| 67 |
static void Close( vlc_object_t * ); |
|---|
| 68 |
static block_t *Block( access_t * ); |
|---|
| 69 |
static int Control( access_t *, int, va_list ); |
|---|
| 70 |
|
|---|
| 71 |
#define CACHING_TEXT N_("Caching value in ms") |
|---|
| 72 |
#define CACHING_LONGTEXT N_( \ |
|---|
| 73 |
"Caching value for DV streams. This" \ |
|---|
| 74 |
"value should be set in milliseconds." ) |
|---|
| 75 |
|
|---|
| 76 |
vlc_module_begin(); |
|---|
| 77 |
set_description( N_("Digital Video (Firewire/ieee1394) input") ); |
|---|
| 78 |
set_shortname( N_("dv") ); |
|---|
| 79 |
set_category( CAT_INPUT ); |
|---|
| 80 |
set_subcategory( SUBCAT_INPUT_ACCESS ); |
|---|
| 81 |
add_integer( "dv-caching", 60000 / 1000, NULL, CACHING_TEXT, CACHING_LONGTEXT, true ); |
|---|
| 82 |
set_capability( "access", 0 ); |
|---|
| 83 |
add_shortcut( "dv" ); |
|---|
| 84 |
add_shortcut( "dv1394" ); |
|---|
| 85 |
add_shortcut( "raw1394" ); |
|---|
| 86 |
set_callbacks( Open, Close ); |
|---|
| 87 |
vlc_module_end(); |
|---|
| 88 |
|
|---|
| 89 |
typedef struct |
|---|
| 90 |
{ |
|---|
| 91 |
VLC_COMMON_MEMBERS |
|---|
| 92 |
|
|---|
| 93 |
access_t *p_access; |
|---|
| 94 |
vlc_mutex_t lock; |
|---|
| 95 |
block_t *p_frame; |
|---|
| 96 |
block_t **pp_last; |
|---|
| 97 |
|
|---|
| 98 |
} event_thread_t; |
|---|
| 99 |
|
|---|
| 100 |
static void* Raw1394EventThread( vlc_object_t * ); |
|---|
| 101 |
static int Raw1394Handler( raw1394handle_t, int, size_t, quadlet_t * ); |
|---|
| 102 |
|
|---|
| 103 |
static int Raw1394GetNumPorts( access_t *p_access ); |
|---|
| 104 |
static raw1394handle_t Raw1394Open( access_t *, int ); |
|---|
| 105 |
static void Raw1394Close( raw1394handle_t ); |
|---|
| 106 |
|
|---|
| 107 |
static int DiscoverAVC( access_t *, int *, uint64_t ); |
|---|
| 108 |
static raw1394handle_t AVCOpen( access_t *, int ); |
|---|
| 109 |
static void AVCClose( access_t * ); |
|---|
| 110 |
static int AVCResetHandler( raw1394handle_t, unsigned int ); |
|---|
| 111 |
static int AVCPlay( access_t *, int ); |
|---|
| 112 |
static int AVCPause( access_t *, int ); |
|---|
| 113 |
static int AVCStop( access_t *, int ); |
|---|
| 114 |
|
|---|
| 115 |
struct access_sys_t |
|---|
| 116 |
{ |
|---|
| 117 |
raw1394handle_t p_avc1394; |
|---|
| 118 |
raw1394handle_t p_raw1394; |
|---|
| 119 |
struct pollfd raw1394_poll; |
|---|
| 120 |
|
|---|
| 121 |
int i_cards; |
|---|
| 122 |
int i_node; |
|---|
| 123 |
int i_port; |
|---|
| 124 |
int i_channel; |
|---|
| 125 |
uint64_t i_guid; |
|---|
| 126 |
|
|---|
| 127 |
|
|---|
| 128 |
event_thread_t *p_ev; |
|---|
| 129 |
vlc_mutex_t lock; |
|---|
| 130 |
block_t *p_frame; |
|---|
| 131 |
}; |
|---|
| 132 |
|
|---|
| 133 |
|
|---|
| 134 |
|
|---|
| 135 |
|
|---|
| 136 |
static int Open( vlc_object_t *p_this ) |
|---|
| 137 |
{ |
|---|
| 138 |
access_t *p_access = (access_t*)p_this; |
|---|
| 139 |
access_sys_t *p_sys; |
|---|
| 140 |
char *psz_name = strdup( p_access->psz_path ); |
|---|
| 141 |
|
|---|
| 142 |
struct raw1394_portinfo port_inf[ 16 ]; |
|---|
| 143 |
iso_handler_t oldhandler; |
|---|
| 144 |
|
|---|
| 145 |
msg_Dbg( p_access, "opening device %s", psz_name ); |
|---|
| 146 |
|
|---|
| 147 |
|
|---|
| 148 |
access_InitFields( p_access ); |
|---|
| 149 |
ACCESS_SET_CALLBACKS( NULL, Block, Control, NULL ); |
|---|
| 150 |
p_access->info.b_prebuffered = false; |
|---|
| 151 |
|
|---|
| 152 |
p_access->p_sys = p_sys = malloc( sizeof( access_sys_t ) ); |
|---|
| 153 |
if( !p_sys ) |
|---|
| 154 |
{ |
|---|
| 155 |
free( psz_name ); |
|---|
| 156 |
return VLC_EGENERIC; |
|---|
| 157 |
} |
|---|
| 158 |
|
|---|
| 159 |
p_sys->i_cards = 0; |
|---|
| 160 |
p_sys->i_node = 0; |
|---|
| 161 |
p_sys->i_port = 0; |
|---|
| 162 |
p_sys->i_guid = 0; |
|---|
| 163 |
p_sys->i_channel = 63; |
|---|
| 164 |
p_sys->p_raw1394 = NULL; |
|---|
| 165 |
p_sys->p_avc1394 = NULL; |
|---|
| 166 |
p_sys->p_frame = NULL; |
|---|
| 167 |
p_sys->p_ev = NULL; |
|---|
| 168 |
|
|---|
| 169 |
vlc_mutex_init( &p_sys->lock ); |
|---|
| 170 |
|
|---|
| 171 |
p_sys->i_node = DiscoverAVC( p_access, &p_sys->i_port, p_sys->i_guid ); |
|---|
| 172 |
if( p_sys->i_node < 0 ) |
|---|
| 173 |
{ |
|---|
| 174 |
msg_Err( p_access, "failed to open a Firewire (IEEE1394) connection" ); |
|---|
| 175 |
Close( p_this ); |
|---|
| 176 |
free( psz_name ); |
|---|
| 177 |
return VLC_EGENERIC; |
|---|
| 178 |
} |
|---|
| 179 |
|
|---|
| 180 |
p_sys->p_avc1394 = AVCOpen( p_access, p_sys->i_port ); |
|---|
| 181 |
if( !p_sys->p_avc1394 ) |
|---|
| 182 |
{ |
|---|
| 183 |
msg_Err( p_access, "no Digital Video Control device found on %s", psz_name ); |
|---|
| 184 |
Close( p_this ); |
|---|
| 185 |
free( psz_name ); |
|---|
| 186 |
return VLC_EGENERIC; |
|---|
| 187 |
} |
|---|
| 188 |
|
|---|
| 189 |
p_sys->p_raw1394 = raw1394_new_handle(); |
|---|
| 190 |
if( !p_sys->p_raw1394 ) |
|---|
| 191 |
{ |
|---|
| 192 |
msg_Err( p_access, "no Digital Video device found on %s", psz_name ); |
|---|
| 193 |
Close( p_this ); |
|---|
| 194 |
free( psz_name ); |
|---|
| 195 |
return VLC_EGENERIC; |
|---|
| 196 |
} |
|---|
| 197 |
|
|---|
| 198 |
p_sys->i_cards = raw1394_get_port_info( p_sys->p_raw1394, port_inf, 16 ); |
|---|
| 199 |
if( p_sys->i_cards < 0 ) |
|---|
| 200 |
{ |
|---|
| 201 |
msg_Err( p_access, "failed to get port info for %s", psz_name ); |
|---|
| 202 |
Close( p_this ); |
|---|
| 203 |
free( psz_name ); |
|---|
| 204 |
return VLC_EGENERIC; |
|---|
| 205 |
} |
|---|
| 206 |
|
|---|
| 207 |
if( raw1394_set_port( p_sys->p_raw1394, p_sys->i_port ) < 0 ) |
|---|
| 208 |
{ |
|---|
| 209 |
msg_Err( p_access, "failed to set port info for %s", psz_name ); |
|---|
| 210 |
Close( p_this ); |
|---|
| 211 |
free( psz_name ); |
|---|
| 212 |
return VLC_EGENERIC; |
|---|
| 213 |
} |
|---|
| 214 |
|
|---|
| 215 |
oldhandler = raw1394_set_iso_handler( p_sys->p_raw1394, |
|---|
| 216 |
p_sys->i_channel, Raw1394Handler ); |
|---|
| 217 |
raw1394_set_userdata( p_sys->p_raw1394, p_access ); |
|---|
| 218 |
raw1394_start_iso_rcv( p_sys->p_raw1394, p_sys->i_channel ); |
|---|
| 219 |
|
|---|
| 220 |
p_sys->raw1394_poll.fd = raw1394_get_fd( p_sys->p_raw1394 ); |
|---|
| 221 |
p_sys->raw1394_poll.events = POLLIN | POLLPRI; |
|---|
| 222 |
|
|---|
| 223 |
|
|---|
| 224 |
var_Create( p_access, "dv-caching", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT ); |
|---|
| 225 |
|
|---|
| 226 |
|
|---|
| 227 |
p_sys->p_ev = vlc_object_create( p_access, sizeof( event_thread_t ) ); |
|---|
| 228 |
if( !p_sys->p_ev ) |
|---|
| 229 |
{ |
|---|
| 230 |
msg_Err( p_access, "failed to create event thread for %s", psz_name ); |
|---|
| 231 |
Close( p_this ); |
|---|
| 232 |
free( psz_name ); |
|---|
| 233 |
return VLC_EGENERIC; |
|---|
| 234 |
} |
|---|
| 235 |
|
|---|
| 236 |
p_sys->p_ev->p_frame = NULL; |
|---|
| 237 |
p_sys->p_ev->pp_last = &p_sys->p_ev->p_frame; |
|---|
| 238 |
p_sys->p_ev->p_access = p_access; |
|---|
| 239 |
vlc_mutex_init( &p_sys->p_ev->lock ); |
|---|
| 240 |
vlc_thread_create( p_sys->p_ev, "dv event thread handler", Raw1394EventThread, |
|---|
| 241 |
VLC_THREAD_PRIORITY_OUTPUT, false ); |
|---|
| 242 |
|
|---|
| 243 |
free( psz_name ); |
|---|
| 244 |
return VLC_SUCCESS; |
|---|
| 245 |
} |
|---|
| 246 |
|
|---|
| 247 |
|
|---|
| 248 |
|
|---|
| 249 |
|
|---|
| 250 |
static void Close( vlc_object_t *p_this ) |
|---|
| 251 |
{ |
|---|
| 252 |
access_t *p_access = (access_t*)p_this; |
|---|
| 253 |
access_sys_t *p_sys = p_access->p_sys; |
|---|
| 254 |
|
|---|
| 255 |
if( p_sys->p_ev ) |
|---|
| 256 |
{ |
|---|
| 257 |
|
|---|
| 258 |
vlc_object_kill( p_sys->p_ev ); |
|---|
| 259 |
|
|---|
| 260 |
if( p_sys->p_raw1394 ) |
|---|
| 261 |
raw1394_stop_iso_rcv( p_sys->p_raw1394, p_sys->i_channel ); |
|---|
| 262 |
|
|---|
| 263 |
vlc_mutex_destroy( &p_sys->p_ev->lock ); |
|---|
| 264 |
vlc_thread_join( p_sys->p_ev ); |
|---|
| 265 |
|
|---|
| 266 |
|
|---|
| 267 |
if( p_sys->p_ev->p_frame ) |
|---|
| 268 |
{ |
|---|
| 269 |
vlc_mutex_lock( &p_sys->p_ev->lock ); |
|---|
| 270 |
block_ChainRelease( p_sys->p_ev->p_frame ); |
|---|
| 271 |
p_sys->p_ev->p_frame = NULL; |
|---|
| 272 |
p_sys->p_ev->pp_last = &p_sys->p_frame; |
|---|
| 273 |
vlc_mutex_unlock( &p_sys->p_ev->lock ); |
|---|
| 274 |
} |
|---|
| 275 |
vlc_object_release( p_sys->p_ev ); |
|---|
| 276 |
} |
|---|
| 277 |
|
|---|
| 278 |
if( p_sys->p_frame ) |
|---|
| 279 |
block_ChainRelease( p_sys->p_frame ); |
|---|
| 280 |
if( p_sys->p_raw1394 ) |
|---|
| 281 |
raw1394_destroy_handle( p_sys->p_raw1394 ); |
|---|
| 282 |
|
|---|
| 283 |
AVCClose( p_access ); |
|---|
| 284 |
|
|---|
| 285 |
vlc_mutex_destroy( &p_sys->lock ); |
|---|
| 286 |
free( p_sys ); |
|---|
| 287 |
} |
|---|
| 288 |
|
|---|
| 289 |
|
|---|
| 290 |
|
|---|
| 291 |
|
|---|
| 292 |
static int Control( access_t *p_access, int i_query, va_list args ) |
|---|
| 293 |
{ |
|---|
| 294 |
access_sys_t *p_sys = p_access->p_sys; |
|---|
| 295 |
bool *pb_bool; |
|---|
| 296 |
int64_t *pi_64; |
|---|
| 297 |
|
|---|
| 298 |
switch( i_query ) |
|---|
| 299 |
{ |
|---|
| 300 |
|
|---|
| 301 |
case ACCESS_CAN_PAUSE: |
|---|
| 302 |
pb_bool = (bool*)va_arg( args, bool* ); |
|---|
| 303 |
*pb_bool = true; |
|---|
| 304 |
break; |
|---|
| 305 |
|
|---|
| 306 |
case ACCESS_CAN_SEEK: |
|---|
| 307 |
case ACCESS_CAN_FASTSEEK: |
|---|
| 308 |
case ACCESS_CAN_CONTROL_PACE: |
|---|
| 309 |
pb_bool = (bool*)va_arg( args, bool* ); |
|---|
| 310 |
*pb_bool = false; |
|---|
| 311 |
break; |
|---|
| 312 |
|
|---|
| 313 |
case ACCESS_GET_PTS_DELAY: |
|---|
| 314 |
pi_64 = (int64_t*)va_arg( args, int64_t * ); |
|---|
| 315 |
*pi_64 = var_GetInteger( p_access, "dv-caching" ) * 1000; |
|---|
| 316 |
break; |
|---|
| 317 |
|
|---|
| 318 |
|
|---|
| 319 |
case ACCESS_SET_PAUSE_STATE: |
|---|
| 320 |
AVCPause( p_access, p_sys->i_node ); |
|---|
| 321 |
break; |
|---|
| 322 |
|
|---|
| 323 |
case ACCESS_GET_TITLE_INFO: |
|---|
| 324 |
case ACCESS_SET_TITLE: |
|---|
| 325 |
case ACCESS_SET_SEEKPOINT: |
|---|
| 326 |
case ACCESS_SET_PRIVATE_ID_STATE: |
|---|
| 327 |
case ACCESS_GET_CONTENT_TYPE: |
|---|
| 328 |
return VLC_EGENERIC; |
|---|
| 329 |
|
|---|
| 330 |
default: |
|---|
| 331 |
msg_Warn( p_access, "unimplemented query in control" ); |
|---|
| 332 |
return VLC_EGENERIC; |
|---|
| 333 |
|
|---|
| 334 |
} |
|---|
| 335 |
return VLC_SUCCESS; |
|---|
| 336 |
} |
|---|
| 337 |
|
|---|
| 338 |
static block_t *Block( access_t *p_access ) |
|---|
| 339 |
{ |
|---|
| 340 |
access_sys_t *p_sys = p_access->p_sys; |
|---|
| 341 |
block_t *p_block = NULL; |
|---|
| 342 |
|
|---|
| 343 |
#if 0 |
|---|
| 344 |
if( !p_access->psz_demux ) |
|---|
| 345 |
{ |
|---|
| 346 |
free( p_access->psz_demux ); |
|---|
| 347 |
p_access->psz_demux = strdup( "rawdv" ); |
|---|
| 348 |
} |
|---|
| 349 |
#endif |
|---|
| 350 |
|
|---|
| 351 |
vlc_mutex_lock( &p_sys->lock ); |
|---|
| 352 |
p_block = p_sys->p_frame; |
|---|
| 353 |
|
|---|
| 354 |
p_sys->p_frame = NULL; |
|---|
| 355 |
vlc_mutex_unlock( &p_sys->lock ); |
|---|
| 356 |
|
|---|
| 357 |
return p_block; |
|---|
| 358 |
} |
|---|
| 359 |
|
|---|
| 360 |
static void* Raw1394EventThread( vlc_object_t *p_this ) |
|---|
| 361 |
{ |
|---|
| 362 |
event_thread_t *p_ev = (event_thread_t *) p_this; |
|---|
| 363 |
access_t *p_access = (access_t *) p_ev->p_access; |
|---|
| 364 |
access_sys_t *p_sys = (access_sys_t *) p_access->p_sys; |
|---|
| 365 |
int result = 0; |
|---|
| 366 |
int canc = vlc_savecancel (); |
|---|
| 367 |
|
|---|
| 368 |
AVCPlay( p_access, p_sys->i_node ); |
|---|
| 369 |
|
|---|
| 370 |
vlc_thread_ready( p_this ); |
|---|
| 371 |
|
|---|
| 372 |
while( vlc_object_alive (p_sys->p_ev) ) |
|---|
| 373 |
{ |
|---|
| 374 |
while( ( result = poll( &(p_sys->raw1394_poll), 1, 200 ) ) < 0 ) |
|---|
| 375 |
{ |
|---|
| 376 |
if( !( errno == EAGAIN || errno == EINTR ) ) |
|---|
| 377 |
{ |
|---|
| 378 |
perror( "error: raw1394 poll" ); |
|---|
| 379 |
msg_Err( p_access, "retrying device raw1394" ); |
|---|
| 380 |
} |
|---|
| 381 |
} |
|---|
| 382 |
if( !vlc_object_alive (p_sys->p_ev) ) |
|---|
| 383 |
break; |
|---|
| 384 |
if( result > 0 && ( ( p_sys->raw1394_poll.revents & POLLIN ) |
|---|
| 385 |
|| ( p_sys->raw1394_poll.revents & POLLPRI ) ) ) |
|---|
| 386 |
result = raw1394_loop_iterate( p_sys->p_raw1394 ); |
|---|
| 387 |
} |
|---|
| 388 |
|
|---|
| 389 |
AVCStop( p_access, p_sys->i_node ); |
|---|
| 390 |
vlc_restorecancel (canc); |
|---|
| 391 |
return NULL; |
|---|
| 392 |
} |
|---|
| 393 |
|
|---|
| 394 |
static int Raw1394Handler( raw1394handle_t handle, int channel, size_t length, quadlet_t *data ) |
|---|
| 395 |
{ |
|---|
| 396 |
access_t *p_access = NULL; |
|---|
| 397 |
access_sys_t *p_sys = NULL; |
|---|
| 398 |
block_t *p_block = NULL; |
|---|
| 399 |
|
|---|
| 400 |
p_access = (access_t *) raw1394_get_userdata( handle ); |
|---|
| 401 |
if( !p_access ) return 0; |
|---|
| 402 |
|
|---|
| 403 |
p_sys = p_access->p_sys; |
|---|
| 404 |
|
|---|
| 405 |
|
|---|
| 406 |
if ( length > 16 ) |
|---|
| 407 |
{ |
|---|
| 408 |
unsigned char * p = ( unsigned char* ) &data[ 3 ]; |
|---|
| 409 |
int section_type = p[ 0 ] >> 5; |
|---|
| 410 |
int dif_sequence = p[ 1 ] >> 4; |
|---|
| 411 |
int dif_block = p[ 2 ]; |
|---|
| 412 |
|
|---|
| 413 |
vlc_mutex_lock( &p_sys->p_ev->lock ); |
|---|
| 414 |
|
|---|
| 415 |
|
|---|
| 416 |
|
|---|
| 417 |
if( (section_type == 0) && (dif_sequence == 0) ) |
|---|
| 418 |
{ |
|---|
| 419 |
vlc_mutex_lock( &p_sys->lock ); |
|---|
| 420 |
if( p_sys->p_ev->p_frame ) |
|---|
| 421 |
{ |
|---|
| 422 |
|
|---|
| 423 |
|
|---|
| 424 |
block_ChainAppend( &p_sys->p_frame, p_sys->p_ev->p_frame ); |
|---|
| 425 |
} |
|---|
| 426 |
|
|---|
| 427 |
p_sys->p_ev->p_frame = block_New( p_access, 144000 ); |
|---|
| 428 |
p_sys->p_ev->pp_last = &p_sys->p_frame; |
|---|
| 429 |
vlc_mutex_unlock( &p_sys->lock ); |
|---|
| 430 |
} |
|---|
| 431 |
|
|---|
| 432 |
p_block = p_sys->p_ev->p_frame; |
|---|
| 433 |
if( p_block ) |
|---|
| 434 |
{ |
|---|
| 435 |
switch ( section_type ) |
|---|
| 436 |
{ |
|---|
| 437 |
case 0: |
|---|
| 438 |
|
|---|
| 439 |
memcpy( p_block->p_buffer + dif_sequence * 150 * 80, p, 480 ); |
|---|
| 440 |
break; |
|---|
| 441 |
|
|---|
| 442 |
case 1: |
|---|
| 443 |
memcpy( p_block->p_buffer + dif_sequence * 150 * 80 + ( 1 + dif_block ) * 80, p, 480 ); |
|---|
| 444 |
break; |
|---|
| 445 |
|
|---|
| 446 |
case 2: |
|---|
| 447 |
memcpy( p_block->p_buffer + dif_sequence * 150 * 80 + ( 3 + dif_block ) * 80, p, 480 ); |
|---|
| 448 |
break; |
|---|
| 449 |
|
|---|
| 450 |
case 3: |
|---|
| 451 |
memcpy( p_block->p_buffer + dif_sequence * 150 * 80 + ( 6 + dif_block * 16 ) * 80, p, 480 ); |
|---|
| 452 |
break; |
|---|
| 453 |
|
|---|
| 454 |
case 4: |
|---|
| 455 |
memcpy( p_block->p_buffer + dif_sequence * 150 * 80 + ( 7 + ( dif_block / 15 ) + dif_block ) * 80, p, 480 ); |
|---|
| 456 |
break; |
|---|
| 457 |
|
|---|
| 458 |
default: |
|---|
| 459 |
block_Release( p_block ); |
|---|
| 460 |
p_block = NULL; |
|---|
| 461 |
break; |
|---|
| 462 |
} |
|---|
| 463 |
} |
|---|
| 464 |
vlc_mutex_unlock( &p_sys->p_ev->lock ); |
|---|
| 465 |
} |
|---|
| 466 |
return 0; |
|---|
| 467 |
} |
|---|
| 468 |
|
|---|
| 469 |
|
|---|
| 470 |
|
|---|
| 471 |
|
|---|
| 472 |
|
|---|
| 473 |
|
|---|
| 474 |
static int Raw1394GetNumPorts( access_t *p_access ) |
|---|
| 475 |
{ |
|---|
| 476 |
int n_ports; |
|---|
| 477 |
struct raw1394_portinfo pinf[ 16 ]; |
|---|
| 478 |
raw1394handle_t handle; |
|---|
| 479 |
|
|---|
| 480 |
|
|---|
| 481 |
if ( !( handle = raw1394_new_handle() ) ) |
|---|
| 482 |
{ |
|---|
| 483 |
msg_Err( p_access, "raw1394 - failed to get handle: %m." ); |
|---|
| 484 |
return VLC_EGENERIC; |
|---|
| 485 |
} |
|---|
| 486 |
|
|---|
| 487 |
if ( ( n_ports = raw1394_get_port_info( handle, pinf, 16 ) ) < 0 ) |
|---|
| 488 |
{ |
|---|
| 489 |
msg_Err( p_access, "raw1394 - failed to get port info: %m.\n" ); |
|---|
| 490 |
raw1394_destroy_handle( handle ); |
|---|
| 491 |
return VLC_EGENERIC; |
|---|
| 492 |
} |
|---|
| 493 |
raw1394_destroy_handle( handle ); |
|---|
| 494 |
|
|---|
| 495 |
return n_ports; |
|---|
| 496 |
} |
|---|
| 497 |
|
|---|
| 498 |
static raw1394handle_t Raw1394Open( access_t *p_access, int port ) |
|---|
| 499 |
{ |
|---|
| 500 |
int n_ports; |
|---|
| 501 |
struct raw1394_portinfo pinf[ 16 ]; |
|---|
| 502 |
raw1394handle_t handle; |
|---|
| 503 |
|
|---|
| 504 |
|
|---|
| 505 |
#ifdef RAW1394_V_0_8 |
|---|
| 506 |
|
|---|
| 507 |
handle = raw1394_get_handle(); |
|---|
| 508 |
#else |
|---|
| 509 |
|
|---|
| 510 |
handle = raw1394_new_handle(); |
|---|
| 511 |
#endif |
|---|
| 512 |
|
|---|
| 513 |
if ( !handle ) |
|---|
| 514 |
{ |
|---|
| 515 |
msg_Err( p_access, "raw1394 - failed to get handle: %m." ); |
|---|
| 516 |
return NULL; |
|---|
| 517 |
} |
|---|
| 518 |
|
|---|
| 519 |
if ( ( n_ports = raw1394_get_port_info( handle, pinf, 16 ) ) < 0 ) |
|---|
| 520 |
{ |
|---|
| 521 |
msg_Err( p_access, "raw1394 - failed to get port info: %m." ); |
|---|
| 522 |
raw1394_destroy_handle( handle ); |
|---|
| 523 |
return NULL; |
|---|
| 524 |
} |
|---|
| 525 |
|
|---|
| 526 |
|
|---|
| 527 |
if ( raw1394_set_port( handle, port ) < 0 ) |
|---|
| 528 |
{ |
|---|
| 529 |
msg_Err( p_access, "raw1394 - failed to set set port: %m." ); |
|---|
| 530 |
return NULL; |
|---|
| 531 |
} |
|---|
| 532 |
|
|---|
| 533 |
return handle; |
|---|
| 534 |
} |
|---|
| 535 |
|
|---|
| 536 |
static void Raw1394Close( raw1394handle_t handle ) |
|---|
| 537 |
{ |
|---|
| 538 |
raw1394_destroy_handle( handle ); |
|---|
| 539 |
} |
|---|
| 540 |
|
|---|
| 541 |
static int DiscoverAVC( access_t *p_access, int* port, uint64_t guid ) |
|---|
| 542 |
{ |
|---|
| 543 |
rom1394_directory rom_dir; |
|---|
| 544 |
raw1394handle_t handle = NULL; |
|---|
| 545 |
int device = -1; |
|---|
| 546 |
int i, j = 0; |
|---|
| 547 |
int m = Raw1394GetNumPorts( p_access ); |
|---|
| 548 |
|
|---|
| 549 |
if( *port >= 0 ) |
|---|
| 550 |
{ |
|---|
| 551 |
|
|---|
| 552 |
j = *port; |
|---|
| 553 |
m = *port + 1; |
|---|
| 554 |
} |
|---|
| 555 |
|
|---|
| 556 |
for( ; j < m && device == -1; j++ ) |
|---|
| 557 |
{ |
|---|
| 558 |
handle = Raw1394Open( p_access, j ); |
|---|
| 559 |
if( !handle ) |
|---|
| 560 |
return -1; |
|---|
| 561 |
|
|---|
| 562 |
for( i = 0; i < raw1394_get_nodecount( handle ); ++i ) |
|---|
| 563 |
{ |
|---|
| 564 |
if( guid != 0 ) |
|---|
| 565 |
{ |
|---|
| 566 |
|
|---|
| 567 |
if( guid == rom1394_get_guid( handle, i ) ) |
|---|
| 568 |
{ |
|---|
| 569 |
device = i; |
|---|
| 570 |
*port = j; |
|---|
| 571 |
break; |
|---|
| 572 |
} |
|---|
| 573 |
} |
|---|
| 574 |
else |
|---|
| 575 |
{ |
|---|
| 576 |
|
|---|
| 577 |
if( rom1394_get_directory( handle, i, &rom_dir ) < 0 ) |
|---|
| 578 |
{ |
|---|
| 579 |
msg_Err( p_access, "error reading config rom directory for node %d\n", i ); |
|---|
| 580 |
continue; |
|---|
| 581 |
} |
|---|
| 582 |
if( ( rom1394_get_node_type( &rom_dir ) == ROM1394_NODE_TYPE_AVC ) && |
|---|
| 583 |
avc1394_check_subunit_type( handle, i, AVC1394_SUBUNIT_TYPE_VCR ) ) |
|---|
| 584 |
{ |
|---|
| 585 |
device = i; |
|---|
| 586 |
*port = j; |
|---|
| 587 |
break; |
|---|
| 588 |
} |
|---|
| 589 |
} |
|---|
| 590 |
} |
|---|
| 591 |
Raw1394Close( handle ); |
|---|
| 592 |
} |
|---|
| 593 |
|
|---|
| 594 |
return device; |
|---|
| 595 |
} |
|---|
| 596 |
|
|---|
| 597 |
|
|---|
| 598 |
|
|---|
| 599 |
|
|---|
| 600 |
static raw1394handle_t AVCOpen( access_t *p_access, int port ) |
|---|
| 601 |
{ |
|---|
| 602 |
access_sys_t *p_sys = p_access->p_sys; |
|---|
| 603 |
int numcards; |
|---|
| 604 |
struct raw1394_portinfo pinf[ 16 ]; |
|---|
| 605 |
|
|---|
| 606 |
p_sys->p_avc1394 = raw1394_new_handle(); |
|---|
| 607 |
if( !p_sys->p_avc1394 ) |
|---|
| 608 |
return NULL; |
|---|
| 609 |
|
|---|
| 610 |
numcards = raw1394_get_port_info( p_sys->p_avc1394, pinf, 16 ); |
|---|
| 611 |
if( numcards < -1 ) |
|---|
| 612 |
return NULL; |
|---|
| 613 |
if( raw1394_set_port( p_sys->p_avc1394, port ) < 0 ) |
|---|
| 614 |
return NULL; |
|---|
| 615 |
|
|---|
| 616 |
raw1394_set_bus_reset_handler( p_sys->p_avc1394, AVCResetHandler ); |
|---|
| 617 |
|
|---|
| 618 |
return p_sys->p_avc1394; |
|---|
| 619 |
} |
|---|
| 620 |
|
|---|
| 621 |
static void AVCClose( access_t *p_access ) |
|---|
| 622 |
{ |
|---|
| 623 |
access_sys_t *p_sys = p_access->p_sys; |
|---|
| 624 |
|
|---|
| 625 |
if( p_sys->p_avc1394 ) |
|---|
| 626 |
{ |
|---|
| 627 |
raw1394_destroy_handle( p_sys->p_avc1394 ); |
|---|
| 628 |
p_sys->p_avc1394 = NULL; |
|---|
| 629 |
} |
|---|
| 630 |
} |
|---|
| 631 |
|
|---|
| 632 |
|
|---|
| 633 |
static int AVCResetHandler( raw1394handle_t handle, unsigned int generation ) |
|---|
| 634 |
{ |
|---|
| 635 |
raw1394_update_generation( handle, generation ); |
|---|
| 636 |
return 0; |
|---|
| 637 |
} |
|---|
| 638 |
|
|---|
| 639 |
static int AVCPlay( access_t *p_access, int phyID ) |
|---|
| 640 |
{ |
|---|
| 641 |
access_sys_t *p_sys = p_access->p_sys; |
|---|
| 642 |
|
|---|
| 643 |
msg_Dbg( p_access, "send play command over Digital Video control channel" ); |
|---|
| 644 |
if( !p_sys->p_avc1394 ) |
|---|
| 645 |
return 0; |
|---|
| 646 |
|
|---|
| 647 |
if( phyID >= 0 ) |
|---|
| 648 |
{ |
|---|
| 649 |
if( !avc1394_vcr_is_recording( p_sys->p_avc1394, phyID ) && |
|---|
| 650 |
avc1394_vcr_is_playing( p_sys->p_avc1394, phyID ) != AVC1394_VCR_OPERAND_PLAY_FORWARD ) |
|---|
| 651 |
avc1394_vcr_play( p_sys->p_avc1394, phyID ); |
|---|
| 652 |
} |
|---|
| 653 |
return 0; |
|---|
| 654 |
} |
|---|
| 655 |
|
|---|
| 656 |
static int AVCPause( access_t *p_access, int phyID ) |
|---|
| 657 |
{ |
|---|
| 658 |
access_sys_t *p_sys = p_access->p_sys; |
|---|
| 659 |
|
|---|
| 660 |
if( !p_sys->p_avc1394 ) |
|---|
| 661 |
return 0; |
|---|
| 662 |
|
|---|
| 663 |
if( phyID >= 0 ) |
|---|
| 664 |
{ |
|---|
| 665 |
if( !avc1394_vcr_is_recording( p_sys->p_avc1394, phyID ) && |
|---|
| 666 |
( avc1394_vcr_is_playing( p_sys->p_avc1394, phyID ) != AVC1394_VCR_OPERAND_PLAY_FORWARD_PAUSE ) ) |
|---|
| 667 |
avc1394_vcr_pause( p_sys->p_avc1394, phyID ); |
|---|
| 668 |
} |
|---|
| 669 |
return 0; |
|---|
| 670 |
} |
|---|
| 671 |
|
|---|
| 672 |
|
|---|
| 673 |
static int AVCStop( access_t *p_access, int phyID ) |
|---|
| 674 |
{ |
|---|
| 675 |
access_sys_t *p_sys = p_access->p_sys; |
|---|
| 676 |
|
|---|
| 677 |
msg_Dbg( p_access, "closing Digital Video control channel" ); |
|---|
| 678 |
if( !p_sys->p_avc1394 ) |
|---|
| 679 |
return 0; |
|---|
| 680 |
|
|---|
| 681 |
if ( phyID >= 0 ) |
|---|
| 682 |
avc1394_vcr_stop( p_sys->p_avc1394, phyID ); |
|---|
| 683 |
|
|---|
| 684 |
return 0; |
|---|
| 685 |
} |
|---|