3 * Copyright (C) 2002-2003 Ushodaya Enterprises Limited
4 * Author: Dan Dennedy <dan@dennedy.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 #include <sys/types.h>
33 #include "global_commands.h"
35 #include "dvframepool.h"
38 int dv1394d_load( command_argument cmd_arg )
40 dv_unit unit = dv1394d_get_unit(cmd_arg->unit);
41 char *filename = (char*) cmd_arg->argument;
45 if ( filename[0] == '!' )
51 if ( filename[0] == '/' )
54 snprintf( fullname, 1023, "%s%s", cmd_arg->root_dir, filename );
57 return RESPONSE_INVALID_UNIT;
60 long in = -1, out = -1;
61 if ( dv_tokeniser_count( cmd_arg->tokeniser ) == 5 )
63 in = atoi( dv_tokeniser_get_string( cmd_arg->tokeniser, 3 ) );
64 out = atoi( dv_tokeniser_get_string( cmd_arg->tokeniser, 4 ) );
66 if ( dv_unit_load( unit, fullname, in, out, flush ) != dv_pump_ok )
67 return RESPONSE_BAD_FILE;
69 return RESPONSE_SUCCESS;
72 int dv1394d_list( command_argument cmd_arg )
75 dv_unit unit = dv1394d_get_unit( cmd_arg->unit );
76 dv_player player = dv_unit_get_dv_player( unit );
80 dv_response_printf( cmd_arg->response, 1024, "%d\n", player->generation );
82 for ( i = 0; i < dv_player_get_clip_count( player ); i ++ )
84 dv_clip clip = dv_player_get_clip( player, i );
86 dv_response_printf( cmd_arg->response, 10240,
87 "%d \"%s\" %d %d %d %d %.2f\n",
89 dv_clip_get_resource( clip, cmd_arg->root_dir ),
90 dv_clip_get_in( clip ),
91 ( !dv_clip_is_seekable( clip ) && clip->out_frame == -1 ? -1 : dv_clip_get_out( clip ) ),
92 dv_clip_get_max_frames( clip ),
93 ( !dv_clip_is_seekable( clip ) && clip->out_frame == -1 ? -1 : dv_player_get_length_of_clip( player, i ) ),
94 dv_clip_frames_per_second( clip ) );
97 dv_response_printf( cmd_arg->response, 2, "\n" );
99 return RESPONSE_SUCCESS;
101 return RESPONSE_INVALID_UNIT;
104 static int parse_clip( command_argument cmd_arg, int arg )
106 dv_unit unit = dv1394d_get_unit(cmd_arg->unit);
107 int clip = dv_unit_get_current_clip( unit );
109 if ( dv_tokeniser_count( cmd_arg->tokeniser ) > arg )
111 dv_player player = dv_unit_get_dv_player( unit );
112 char *token = dv_tokeniser_get_string( cmd_arg->tokeniser, arg );
113 if ( token[ 0 ] == '+' )
114 clip += atoi( token + 1 );
115 else if ( token[ 0 ] == '-' )
116 clip -= atoi( token + 1 );
118 clip = atoi( token );
121 if ( clip >= player->size )
122 clip = player->size - 1;
128 int dv1394d_insert( command_argument cmd_arg )
130 dv_unit unit = dv1394d_get_unit(cmd_arg->unit);
131 char *filename = (char*) cmd_arg->argument;
134 if ( filename[0] == '/' )
137 snprintf( fullname, 1023, "%s%s", cmd_arg->root_dir, filename );
140 return RESPONSE_INVALID_UNIT;
143 long in = -1, out = -1;
144 int index = parse_clip( cmd_arg, 3 );
146 if ( dv_tokeniser_count( cmd_arg->tokeniser ) == 6 )
148 in = atoi( dv_tokeniser_get_string( cmd_arg->tokeniser, 4 ) );
149 out = atoi( dv_tokeniser_get_string( cmd_arg->tokeniser, 5 ) );
152 switch( dv_unit_insert( unit, fullname, index, in, out ) )
155 return RESPONSE_SUCCESS;
156 case dv_pump_too_many_files_open:
157 return RESPONSE_TOO_MANY_FILES;
159 return RESPONSE_BAD_FILE;
162 return RESPONSE_SUCCESS;
165 int dv1394d_remove( command_argument cmd_arg )
167 dv_unit unit = dv1394d_get_unit(cmd_arg->unit);
170 return RESPONSE_INVALID_UNIT;
173 int index = parse_clip( cmd_arg, 2 );
175 if ( dv_unit_remove( unit, index ) != dv_pump_ok )
176 return RESPONSE_BAD_FILE;
178 return RESPONSE_SUCCESS;
181 int dv1394d_clean( command_argument cmd_arg )
183 dv_unit unit = dv1394d_get_unit(cmd_arg->unit);
186 return RESPONSE_INVALID_UNIT;
189 if ( dv_unit_clean( unit ) != dv_pump_ok )
190 return RESPONSE_BAD_FILE;
192 return RESPONSE_SUCCESS;
195 int dv1394d_move( command_argument cmd_arg )
197 dv_unit unit = dv1394d_get_unit(cmd_arg->unit);
201 if ( dv_tokeniser_count( cmd_arg->tokeniser ) > 2 )
203 int src = parse_clip( cmd_arg, 2 );
204 int dest = parse_clip( cmd_arg, 3 );
206 if ( dv_unit_move( unit, src, dest ) != dv_pump_ok )
207 return RESPONSE_BAD_FILE;
211 return RESPONSE_MISSING_ARG;
216 return RESPONSE_INVALID_UNIT;
219 return RESPONSE_SUCCESS;
222 int dv1394d_append( command_argument cmd_arg )
224 dv_unit unit = dv1394d_get_unit(cmd_arg->unit);
225 char *filename = (char*) cmd_arg->argument;
228 if ( filename[0] == '/' )
230 snprintf( fullname, 1023, "%s%s", cmd_arg->root_dir, filename );
233 return RESPONSE_INVALID_UNIT;
236 long in = -1, out = -1;
237 if ( dv_tokeniser_count( cmd_arg->tokeniser ) == 5 )
239 in = atoi( dv_tokeniser_get_string( cmd_arg->tokeniser, 3 ) );
240 out = atoi( dv_tokeniser_get_string( cmd_arg->tokeniser, 4 ) );
242 switch ( dv_unit_append( unit, fullname, in, out ) )
245 return RESPONSE_SUCCESS;
246 case dv_pump_too_many_files_open:
247 return RESPONSE_TOO_MANY_FILES;
249 return RESPONSE_BAD_FILE;
252 return RESPONSE_SUCCESS;
255 int dv1394d_play( command_argument cmd_arg )
257 dv_unit unit = dv1394d_get_unit(cmd_arg->unit);
259 if (unit == NULL || dv_unit_is_offline(unit))
260 return RESPONSE_INVALID_UNIT;
264 if ( dv_tokeniser_count( cmd_arg->tokeniser ) == 3 )
265 speed = atoi( dv_tokeniser_get_string( cmd_arg->tokeniser, 2 ) );
266 dv_unit_play( unit, speed );
269 return RESPONSE_SUCCESS;
272 int dv1394d_stop( command_argument cmd_arg )
274 dv_unit unit = dv1394d_get_unit(cmd_arg->unit);
276 if (unit == NULL || dv_unit_is_offline(unit))
277 return RESPONSE_INVALID_UNIT;
279 dv_unit_terminate( unit );
281 return RESPONSE_SUCCESS;
284 int dv1394d_pause( command_argument cmd_arg )
286 dv_unit unit = dv1394d_get_unit(cmd_arg->unit);
288 if (unit == NULL || dv_unit_is_offline(unit))
289 return RESPONSE_INVALID_UNIT;
291 dv_unit_play( unit, 0 );
293 return RESPONSE_SUCCESS;
296 int dv1394d_rewind( command_argument cmd_arg )
298 dv_unit unit = dv1394d_get_unit(cmd_arg->unit);
300 if (unit == NULL || dv_unit_is_offline(unit))
301 return RESPONSE_INVALID_UNIT;
303 dv_unit_change_speed( unit, -2000 );
305 return RESPONSE_SUCCESS;
308 int dv1394d_step( command_argument cmd_arg )
310 dv_unit unit = dv1394d_get_unit(cmd_arg->unit);
312 if (unit == NULL || dv_unit_is_offline(unit))
313 return RESPONSE_INVALID_UNIT;
316 dv_unit_play( unit, 0 );
317 dv_unit_step( unit, *(int*) cmd_arg->argument );
320 return RESPONSE_SUCCESS;
323 int dv1394d_goto( command_argument cmd_arg )
325 dv_unit unit = dv1394d_get_unit(cmd_arg->unit);
326 int clip = parse_clip( cmd_arg, 3 );
328 if (unit == NULL || dv_unit_is_offline(unit))
329 return RESPONSE_INVALID_UNIT;
331 dv_unit_change_position( unit, clip, *(int*) cmd_arg->argument );
333 return RESPONSE_SUCCESS;
336 int dv1394d_ff( command_argument cmd_arg )
338 dv_unit unit = dv1394d_get_unit(cmd_arg->unit);
340 if (unit == NULL || dv_unit_is_offline(unit))
341 return RESPONSE_INVALID_UNIT;
343 dv_unit_change_speed( unit, 2000 );
345 return RESPONSE_SUCCESS;
348 int dv1394d_set_in_point( command_argument cmd_arg )
350 dv_unit unit = dv1394d_get_unit(cmd_arg->unit);
351 int clip = parse_clip( cmd_arg, 3 );
353 if (unit == NULL || dv_unit_is_offline(unit))
354 return RESPONSE_INVALID_UNIT;
357 int position = *(int *) cmd_arg->argument;
359 switch( dv_unit_set_clip_in( unit, clip, position ) )
362 return RESPONSE_BAD_FILE;
364 return RESPONSE_OUT_OF_RANGE;
368 return RESPONSE_SUCCESS;
371 int dv1394d_set_out_point( command_argument cmd_arg )
373 dv_unit unit = dv1394d_get_unit(cmd_arg->unit);
374 int clip = parse_clip( cmd_arg, 3 );
376 if (unit == NULL || dv_unit_is_offline(unit))
377 return RESPONSE_INVALID_UNIT;
380 int position = *(int *) cmd_arg->argument;
382 switch( dv_unit_set_clip_out( unit, clip, position ) )
385 return RESPONSE_BAD_FILE;
387 return RESPONSE_OUT_OF_RANGE;
391 return RESPONSE_SUCCESS;
394 int dv1394d_get_unit_status( command_argument cmd_arg )
396 dv1394_status_t status;
397 int error = dv_unit_get_status( dv1394d_get_unit( cmd_arg->unit ), &status );
400 return RESPONSE_INVALID_UNIT;
405 dv_response_printf( cmd_arg->response,
407 dv1394_status_serialise( &status, text, sizeof( text ) ) );
409 return RESPONSE_SUCCESS_1;
416 int dv1394d_set_unit_property( command_argument cmd_arg )
418 dv_unit unit = dv1394d_get_unit(cmd_arg->unit);
421 return RESPONSE_INVALID_UNIT;
424 char *key = (char*) cmd_arg->argument;
427 value = strchr( key, '=' );
429 return RESPONSE_OUT_OF_RANGE;
432 dv1394d_log( LOG_DEBUG, "USET %s = %s", key, value );
433 if ( strncasecmp( key, "eof", 1024) == 0 )
435 if ( strncasecmp( value, "pause", 1024) == 0)
436 dv_unit_set_eof_action( unit, dv_player_pause );
437 else if ( strncasecmp( value, "loop", 1024) == 0)
438 dv_unit_set_eof_action( unit, dv_player_loop );
439 else if ( strncasecmp( value, "stop", 1024) == 0)
440 dv_unit_set_eof_action( unit, dv_player_terminate );
441 else if ( strncasecmp( value, "clean", 1024) == 0)
442 dv_unit_set_eof_action( unit, dv_player_clean_loop );
444 return RESPONSE_OUT_OF_RANGE;
446 else if ( strncasecmp( key, "points", 1024) == 0 )
448 if ( strncasecmp( value, "use", 1024) == 0)
449 dv_unit_set_mode( unit, dv_clip_mode_restricted );
450 else if ( strncasecmp( value, "ignore", 1024) == 0)
451 dv_unit_set_mode( unit, dv_clip_mode_unrestricted );
453 return RESPONSE_OUT_OF_RANGE;
455 else if ( strncasecmp( key, "syt_offset", 1024) == 0 )
457 dv_unit_set_syt_offset( unit, atoi( value ) );
459 else if ( strncasecmp( key, "cip_n", 1024) == 0 )
461 dv_unit_set_cip_n( unit, atoi( value ) );
463 else if ( strncasecmp( key, "cip_d", 1024) == 0 )
465 dv_unit_set_cip_d( unit, atoi( value ) );
467 else if ( strncasecmp( key, "size", 1024) == 0 )
469 dv_unit_set_buffer_size( unit, atoi( value ) );
471 else if ( strncasecmp( key, "n_frames", 1024) == 0 )
473 dv_unit_set_n_frames( unit, atoi( value ) );
475 else if ( strncasecmp( key, "n_fill", 1024) == 0 )
477 dv_unit_set_n_fill( unit, atoi( value ) );
480 return RESPONSE_OUT_OF_RANGE;
483 return RESPONSE_SUCCESS;
486 int dv1394d_get_unit_property( command_argument cmd_arg )
488 dv_unit unit = dv1394d_get_unit(cmd_arg->unit);
491 return RESPONSE_INVALID_UNIT;
494 char *key = (char*) cmd_arg->argument;
496 if ( strncasecmp( key, "eof", 1024) == 0 )
498 switch ( dv_unit_get_eof_action( unit ) )
500 case dv_player_pause:
501 dv_response_write( cmd_arg->response, "pause", strlen("pause") );
504 dv_response_write( cmd_arg->response, "loop", strlen("loop") );
506 case dv_player_terminate:
507 dv_response_write( cmd_arg->response, "stop", strlen("stop") );
509 case dv_player_clean_loop:
510 dv_response_write( cmd_arg->response, "clean", strlen("clean") );
513 return RESPONSE_SUCCESS_1;
515 else if ( strncasecmp( key, "points", 1024) == 0 )
517 if ( dv_unit_get_mode( unit ) == dv_clip_mode_restricted )
518 dv_response_write( cmd_arg->response, "use", strlen("use") );
520 dv_response_write( cmd_arg->response, "ignore", strlen("ignore") );
521 return RESPONSE_SUCCESS_1;
523 else if ( strncasecmp( key, "syt_offset", 1024) == 0 )
525 dv_response_printf( cmd_arg->response, 1024, "%d\n",
526 dv_unit_get_syt_offset( unit ) );
527 return RESPONSE_SUCCESS_1;
529 else if ( strncasecmp( key, "cip_n", 1024) == 0 )
531 dv_response_printf( cmd_arg->response, 1024, "%d\n",
532 dv_unit_get_cip_n( unit ) );
533 return RESPONSE_SUCCESS_1;
535 else if ( strncasecmp( key, "cip_d", 1024) == 0 )
537 dv_response_printf( cmd_arg->response, 1024, "%d\n",
538 dv_unit_get_cip_d( unit ) );
539 return RESPONSE_SUCCESS_1;
541 else if ( strncasecmp( key, "size", 1024) == 0 )
543 dv_response_printf( cmd_arg->response, 1024, "%d\n",
544 dv_unit_get_buffer_size( unit ) );
545 return RESPONSE_SUCCESS_1;
547 else if ( strncasecmp( key, "n_frames", 1024) == 0 )
549 dv_response_printf( cmd_arg->response, 1024, "%d\n",
550 dv_unit_get_n_frames( unit ) );
551 return RESPONSE_SUCCESS_1;
553 else if ( strncasecmp( key, "n_fill", 1024) == 0 )
555 dv_response_printf( cmd_arg->response, 1024, "%d\n",
556 dv_unit_get_n_fill( unit ) );
557 return RESPONSE_SUCCESS_1;
559 else if ( strncasecmp( key, "all", 1024 ) == 0 )
561 switch ( dv_unit_get_eof_action( unit ) )
563 case dv_player_pause:
564 dv_response_write( cmd_arg->response, "eof=pause\n", strlen("pause") );
567 dv_response_write( cmd_arg->response, "eof=loop\n", strlen("loop") );
569 case dv_player_terminate:
570 dv_response_write( cmd_arg->response, "eof=stop\n", strlen("stop") );
572 case dv_player_clean_loop:
573 dv_response_write( cmd_arg->response, "eof=clean\n", strlen("clean") );
576 if ( dv_unit_get_mode( unit ) == dv_clip_mode_restricted )
577 dv_response_write( cmd_arg->response, "points=use\n", strlen("use") );
579 dv_response_write( cmd_arg->response, "points=ignore\n", strlen("ignore") );
580 dv_response_printf( cmd_arg->response, 1024, "syt_offset=%d\n", dv_unit_get_syt_offset( unit ) );
581 dv_response_printf( cmd_arg->response, 1024, "cip_n=%d\n", dv_unit_get_cip_n( unit ) );
582 dv_response_printf( cmd_arg->response, 1024, "cip_d=%d\n", dv_unit_get_cip_d( unit ) );
583 dv_response_printf( cmd_arg->response, 1024, "size=%d\n", dv_unit_get_buffer_size( unit ) );
584 dv_response_printf( cmd_arg->response, 1024, "n_frames=%d\n", dv_unit_get_n_frames( unit ) );
585 dv_response_printf( cmd_arg->response, 1024, "n_fill=%d\n", dv_unit_get_n_fill( unit ) );
589 return RESPONSE_SUCCESS;
593 int dv1394d_transfer( command_argument cmd_arg )
595 dv_unit src_unit = dv1394d_get_unit(cmd_arg->unit);
596 int dest_unit_id = -1;
597 char *string = (char*) cmd_arg->argument;
598 if ( string != NULL && ( string[ 0 ] == 'U' || string[ 0 ] == 'u' ) && strlen( string ) > 1 )
599 dest_unit_id = atoi( string + 1 );
601 if ( src_unit != NULL && dest_unit_id != -1 )
603 dv_unit dest_unit = dv1394d_get_unit( dest_unit_id );
604 if ( dest_unit != NULL && !dv_unit_is_offline(dest_unit) && dest_unit != src_unit )
606 dv_unit_transfer( dest_unit, src_unit );
607 return RESPONSE_SUCCESS;
611 return RESPONSE_INVALID_UNIT;