]> git.sesse.net Git - mlt/blob - mlt/src/miracle/miracle_unit_commands.c
miracle part 1
[mlt] / mlt / src / miracle / miracle_unit_commands.c
1 /*
2  * unit_commands.c
3  * Copyright (C) 2002-2003 Ushodaya Enterprises Limited
4  * Author: Dan Dennedy <dan@dennedy.org>
5  *
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.
10  *
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.
15  *
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.
19  */
20
21 #ifdef HAVE_CONFIG_H
22 #include <config.h>
23 #endif
24
25 #include <sys/types.h>
26 #include <sys/stat.h>
27 #include <fcntl.h>
28 #include <unistd.h>
29 #include <string.h>
30 #include <stdlib.h>
31 #include <stdio.h>
32
33 #include "miracle_unit.h"
34 #include "miracle_commands.h"
35 #include "miracle_log.h"
36
37 int miracle_load( command_argument cmd_arg )
38 {
39         miracle_unit unit = miracle_get_unit(cmd_arg->unit);
40         char *filename = (char*) cmd_arg->argument;
41         char fullname[1024];
42         int flush = 1;
43
44         if ( filename[0] == '!' )
45         {
46                 flush = 0;
47                 filename ++;
48         }
49
50         if ( filename[0] == '/' )
51                 filename++;
52
53         snprintf( fullname, 1023, "%s%s", cmd_arg->root_dir, filename );
54         
55         if (unit == NULL)
56                 return RESPONSE_INVALID_UNIT;
57         else
58         {
59                 double in = -1, out = -1;
60                 if ( valerie_tokeniser_count( cmd_arg->tokeniser ) == 5 )
61                 {
62                         in = atof( valerie_tokeniser_get_string( cmd_arg->tokeniser, 3 ) );
63                         out = atof( valerie_tokeniser_get_string( cmd_arg->tokeniser, 4 ) );
64                 }
65                 if ( miracle_unit_load( unit, fullname, in, out, flush ) != valerie_ok )
66                         return RESPONSE_BAD_FILE;
67         }
68         return RESPONSE_SUCCESS;
69 }
70
71 int miracle_list( command_argument cmd_arg )
72 {
73         miracle_unit unit = miracle_get_unit( cmd_arg->unit );
74
75         if ( unit != NULL )
76         {
77                 miracle_unit_report_list( unit, cmd_arg->response );
78                 return RESPONSE_SUCCESS;
79         }
80
81         return RESPONSE_INVALID_UNIT;
82 }
83 /*
84 static int parse_clip( command_argument cmd_arg, int arg )
85 {
86         dv_unit unit = miracle_get_unit(cmd_arg->unit);
87         int clip = dv_unit_get_current_clip( unit );
88         
89         if ( dv_tokeniser_count( cmd_arg->tokeniser ) > arg )
90         {
91                 dv_player player = dv_unit_get_dv_player( unit );
92                 char *token = dv_tokeniser_get_string( cmd_arg->tokeniser, arg );
93                 if ( token[ 0 ] == '+' )
94                         clip += atoi( token + 1 );
95                 else if ( token[ 0 ] == '-' )
96                         clip -= atoi( token + 1 );
97                 else
98                         clip = atoi( token );
99                 if ( clip < 0 )
100                         clip = 0;
101                 if ( clip >= player->size )
102                         clip = player->size - 1;
103         }
104         
105         return clip;
106 }
107 */
108
109 int miracle_insert( command_argument cmd_arg )
110 {
111         /*
112         dv_unit unit = miracle_get_unit(cmd_arg->unit);
113         char *filename = (char*) cmd_arg->argument;
114         char fullname[1024];
115
116         if ( filename[0] == '/' )
117                 filename++;
118
119         snprintf( fullname, 1023, "%s%s", cmd_arg->root_dir, filename );
120         
121         if (unit == NULL)
122                 return RESPONSE_INVALID_UNIT;
123         else
124         {
125                 long in = -1, out = -1;
126                 int index = parse_clip( cmd_arg, 3 );
127                 
128                 if ( dv_tokeniser_count( cmd_arg->tokeniser ) == 6 )
129                 {
130                         in = atoi( dv_tokeniser_get_string( cmd_arg->tokeniser, 4 ) );
131                         out = atoi( dv_tokeniser_get_string( cmd_arg->tokeniser, 5 ) );
132                 }
133                 
134                 switch( dv_unit_insert( unit, fullname, index, in, out ) )
135                 {
136                         case dv_pump_ok:
137                                 return RESPONSE_SUCCESS;
138                         case dv_pump_too_many_files_open:
139                                 return RESPONSE_TOO_MANY_FILES;
140                         default:
141                                 return RESPONSE_BAD_FILE;
142                 }
143         }
144         */
145         return RESPONSE_SUCCESS;
146 }
147
148 int miracle_remove( command_argument cmd_arg )
149 {
150         /*
151         dv_unit unit = miracle_get_unit(cmd_arg->unit);
152         
153         if (unit == NULL)
154                 return RESPONSE_INVALID_UNIT;
155         else
156         {
157                 int index = parse_clip( cmd_arg, 2 );
158                         
159                 if ( dv_unit_remove( unit, index ) != dv_pump_ok )
160                         return RESPONSE_BAD_FILE;
161         }
162         */
163         return RESPONSE_SUCCESS;
164 }
165
166 int miracle_clean( command_argument cmd_arg )
167 {
168         /*
169         dv_unit unit = miracle_get_unit(cmd_arg->unit);
170         
171         if (unit == NULL)
172                 return RESPONSE_INVALID_UNIT;
173         else
174         {
175                 if ( dv_unit_clean( unit ) != dv_pump_ok )
176                         return RESPONSE_BAD_FILE;
177         }
178         */
179         return RESPONSE_SUCCESS;
180 }
181
182 int miracle_move( command_argument cmd_arg )
183 {
184         /*
185         dv_unit unit = miracle_get_unit(cmd_arg->unit);
186         
187         if ( unit != NULL )
188         {
189                 if ( dv_tokeniser_count( cmd_arg->tokeniser ) > 2 )
190                 {
191                         int src = parse_clip( cmd_arg, 2 );
192                         int dest = parse_clip( cmd_arg, 3 );
193                         
194                         if ( dv_unit_move( unit, src, dest ) != dv_pump_ok )
195                                 return RESPONSE_BAD_FILE;
196                 }
197                 else
198                 {
199                         return RESPONSE_MISSING_ARG;
200                 }
201         }
202         else
203         {
204                 return RESPONSE_INVALID_UNIT;
205         }
206         */
207
208         return RESPONSE_SUCCESS;
209 }
210
211 int miracle_append( command_argument cmd_arg )
212 {
213         miracle_unit unit = miracle_get_unit(cmd_arg->unit);
214         char *filename = (char*) cmd_arg->argument;
215         char fullname[1024];
216
217         if ( filename[0] == '/' )
218                 filename++;
219
220         snprintf( fullname, 1023, "%s%s", cmd_arg->root_dir, filename );
221         
222         if (unit == NULL)
223                 return RESPONSE_INVALID_UNIT;
224         else
225         {
226                 double in = -1, out = -1;
227                 if ( valerie_tokeniser_count( cmd_arg->tokeniser ) == 5 )
228                 {
229                         in = atof( valerie_tokeniser_get_string( cmd_arg->tokeniser, 3 ) );
230                         out = atof( valerie_tokeniser_get_string( cmd_arg->tokeniser, 4 ) );
231                 }
232                 switch ( miracle_unit_append( unit, fullname, in, out ) )
233                 {
234                         case valerie_ok:
235                                 return RESPONSE_SUCCESS;
236                         default:
237                                 return RESPONSE_BAD_FILE;
238                 }
239         }
240         return RESPONSE_SUCCESS;
241 }
242
243 int miracle_play( command_argument cmd_arg )
244 {
245         miracle_unit unit = miracle_get_unit(cmd_arg->unit);
246         
247         if ( unit == NULL )
248         {
249                 return RESPONSE_INVALID_UNIT;
250         }
251         else
252         {
253                 int speed = 1000;
254                 if ( valerie_tokeniser_count( cmd_arg->tokeniser ) == 3 )
255                         speed = atoi( valerie_tokeniser_get_string( cmd_arg->tokeniser, 2 ) );
256                 miracle_unit_play( unit, speed );
257         }
258
259         return RESPONSE_SUCCESS;
260 }
261
262 int miracle_stop( command_argument cmd_arg )
263 {
264         miracle_unit unit = miracle_get_unit(cmd_arg->unit);
265         if ( unit == NULL )
266                 return RESPONSE_INVALID_UNIT;
267         else 
268                 miracle_unit_play( unit, 0 );
269         return RESPONSE_SUCCESS;
270 }
271
272 int miracle_pause( command_argument cmd_arg )
273 {
274         miracle_unit unit = miracle_get_unit(cmd_arg->unit);
275         if ( unit == NULL )
276                 return RESPONSE_INVALID_UNIT;
277         else 
278                 miracle_unit_play( unit, 0 );
279         return RESPONSE_SUCCESS;
280 }
281
282 int miracle_rewind( command_argument cmd_arg )
283 {
284         miracle_unit unit = miracle_get_unit(cmd_arg->unit);
285         if ( unit == NULL )
286                 return RESPONSE_INVALID_UNIT;
287         else 
288                 miracle_unit_play( unit, -2000 );
289         return RESPONSE_SUCCESS;
290 }
291
292 int miracle_step( command_argument cmd_arg )
293 {
294         /*
295         dv_unit unit = miracle_get_unit(cmd_arg->unit);
296         
297         if (unit == NULL || dv_unit_is_offline(unit))
298                 return RESPONSE_INVALID_UNIT;
299         else
300         {
301                 dv_unit_play( unit, 0 );
302                 dv_unit_step( unit, *(int*) cmd_arg->argument );
303         }
304         */
305         return RESPONSE_SUCCESS;
306 }
307
308 int miracle_goto( command_argument cmd_arg )
309 {
310         /*
311         dv_unit unit = miracle_get_unit(cmd_arg->unit);
312         int clip = parse_clip( cmd_arg, 3 );
313         
314         if (unit == NULL || dv_unit_is_offline(unit))
315                 return RESPONSE_INVALID_UNIT;
316         else
317                 dv_unit_change_position( unit, clip, *(int*) cmd_arg->argument );
318         */
319         return RESPONSE_SUCCESS;
320 }
321
322 int miracle_ff( command_argument cmd_arg )
323 {
324         miracle_unit unit = miracle_get_unit(cmd_arg->unit);
325         if ( unit == NULL )
326                 return RESPONSE_INVALID_UNIT;
327         else 
328                 miracle_unit_play( unit, 2000 );
329         return RESPONSE_SUCCESS;
330 }
331
332 int miracle_set_in_point( command_argument cmd_arg )
333 {
334         /*
335         dv_unit unit = miracle_get_unit(cmd_arg->unit);
336         int clip = parse_clip( cmd_arg, 3 );
337         
338         if (unit == NULL || dv_unit_is_offline(unit))
339                 return RESPONSE_INVALID_UNIT;
340         else
341         {
342                 int position = *(int *) cmd_arg->argument;
343
344                 switch( dv_unit_set_clip_in( unit, clip, position ) )
345                 {
346                         case -1:
347                                 return RESPONSE_BAD_FILE;
348                         case -2:
349                                 return RESPONSE_OUT_OF_RANGE;
350                 }
351         }
352         */
353         return RESPONSE_SUCCESS;
354 }
355
356 int miracle_set_out_point( command_argument cmd_arg )
357 {
358         /*
359         dv_unit unit = miracle_get_unit(cmd_arg->unit);
360         int clip = parse_clip( cmd_arg, 3 );
361         
362         if (unit == NULL || dv_unit_is_offline(unit))
363                 return RESPONSE_INVALID_UNIT;
364         else
365         {
366                 int position = *(int *) cmd_arg->argument;
367
368                 switch( dv_unit_set_clip_out( unit, clip, position ) )
369                 {
370                         case -1:
371                                 return RESPONSE_BAD_FILE;
372                         case -2:
373                                 return RESPONSE_OUT_OF_RANGE;
374                 }
375         }
376         */
377         return RESPONSE_SUCCESS;
378 }
379
380 int miracle_get_unit_status( command_argument cmd_arg )
381 {
382         valerie_status_t status;
383         int error = miracle_unit_get_status( miracle_get_unit( cmd_arg->unit ), &status );
384
385         if ( error == -1 )
386                 return RESPONSE_INVALID_UNIT;
387         else
388         {
389                 char text[ 10240 ];
390                 valerie_response_printf( cmd_arg->response, sizeof( text ), valerie_status_serialise( &status, text, sizeof( text ) ) );
391                 return RESPONSE_SUCCESS_1;
392         }
393         return 0;
394 }
395
396
397 int miracle_set_unit_property( command_argument cmd_arg )
398 {
399         /*
400         dv_unit unit = miracle_get_unit(cmd_arg->unit);
401         
402         if (unit == NULL)
403                 return RESPONSE_INVALID_UNIT;
404         else
405         {
406                 char *key = (char*) cmd_arg->argument;
407                 char *value = NULL;
408
409                 value = strchr( key, '=' );
410                 if (value == NULL)
411                         return RESPONSE_OUT_OF_RANGE;
412                 value[0] = 0;
413                 value++;
414                 miracle_log( LOG_DEBUG, "USET %s = %s", key, value );
415                 if ( strncasecmp( key, "eof", 1024) == 0 )
416                 {
417                         if ( strncasecmp( value, "pause", 1024) == 0)
418                                 dv_unit_set_eof_action( unit, dv_player_pause );
419                         else if ( strncasecmp( value, "loop", 1024) == 0)
420                                 dv_unit_set_eof_action( unit, dv_player_loop );
421                         else if ( strncasecmp( value, "stop", 1024) == 0)
422                                 dv_unit_set_eof_action( unit, dv_player_terminate );
423                         else if ( strncasecmp( value, "clean", 1024) == 0)
424                                 dv_unit_set_eof_action( unit, dv_player_clean_loop );
425                         else
426                                 return RESPONSE_OUT_OF_RANGE;
427                 }
428                 else if ( strncasecmp( key, "points", 1024) == 0 )
429                 {
430                         if ( strncasecmp( value, "use", 1024) == 0)
431                                 dv_unit_set_mode( unit, dv_clip_mode_restricted );
432                         else if ( strncasecmp( value, "ignore", 1024) == 0)
433                                 dv_unit_set_mode( unit, dv_clip_mode_unrestricted );
434                         else
435                                 return RESPONSE_OUT_OF_RANGE;
436                 }
437                 else if ( strncasecmp( key, "syt_offset", 1024) == 0 )
438                 {
439                         dv_unit_set_syt_offset( unit, atoi( value ) );
440                 }
441                 else if ( strncasecmp( key, "cip_n", 1024) == 0 )
442                 {
443                         dv_unit_set_cip_n( unit, atoi( value ) );
444                 }
445                 else if ( strncasecmp( key, "cip_d", 1024) == 0 )
446                 {
447                         dv_unit_set_cip_d( unit, atoi( value ) );
448                 }
449                 else if ( strncasecmp( key, "size", 1024) == 0 )
450                 {
451                         dv_unit_set_buffer_size( unit, atoi( value ) );
452                 }
453                 else if ( strncasecmp( key, "n_frames", 1024) == 0 )
454                 {
455                         dv_unit_set_n_frames( unit, atoi( value ) );
456                 }               
457                 else if ( strncasecmp( key, "n_fill", 1024) == 0 )
458                 {
459                         dv_unit_set_n_fill( unit, atoi( value ) );
460                 }               
461                 else
462                         return RESPONSE_OUT_OF_RANGE;
463         }
464         */
465         return RESPONSE_SUCCESS;
466 }
467
468 int miracle_get_unit_property( command_argument cmd_arg )
469 {
470         /*
471         dv_unit unit = miracle_get_unit(cmd_arg->unit);
472         
473         if (unit == NULL)
474                 return RESPONSE_INVALID_UNIT;
475         else
476         {
477                 char *key = (char*) cmd_arg->argument;
478
479                 if ( strncasecmp( key, "eof", 1024) == 0 )
480                 {
481                         switch ( dv_unit_get_eof_action( unit ) )
482                         {
483                                 case dv_player_pause:
484                                         dv_response_write( cmd_arg->response, "pause", strlen("pause") );
485                                         break;
486                                 case dv_player_loop:
487                                         dv_response_write( cmd_arg->response, "loop", strlen("loop") );
488                                         break;
489                                 case dv_player_terminate:
490                                         dv_response_write( cmd_arg->response, "stop", strlen("stop") );
491                                         break;
492                                 case dv_player_clean_loop:
493                                         dv_response_write( cmd_arg->response, "clean", strlen("clean") );
494                                         break;
495                         }
496                         return RESPONSE_SUCCESS_1;
497                 }
498                 else if ( strncasecmp( key, "points", 1024) == 0 )
499                 {
500                         if ( dv_unit_get_mode( unit ) == dv_clip_mode_restricted )
501                                 dv_response_write( cmd_arg->response, "use", strlen("use") );
502                         else
503                                 dv_response_write( cmd_arg->response, "ignore", strlen("ignore") );
504                         return RESPONSE_SUCCESS_1;
505                 }
506                 else if ( strncasecmp( key, "syt_offset", 1024) == 0 )
507                 {
508                         dv_response_printf( cmd_arg->response, 1024, "%d\n",
509                                 dv_unit_get_syt_offset( unit ) );
510                         return RESPONSE_SUCCESS_1;
511                 }
512                 else if ( strncasecmp( key, "cip_n", 1024) == 0 )
513                 {
514                         dv_response_printf( cmd_arg->response, 1024, "%d\n",
515                                 dv_unit_get_cip_n( unit ) );
516                         return RESPONSE_SUCCESS_1;
517                 }
518                 else if ( strncasecmp( key, "cip_d", 1024) == 0 )
519                 {
520                         dv_response_printf( cmd_arg->response, 1024, "%d\n",
521                                 dv_unit_get_cip_d( unit ) );
522                         return RESPONSE_SUCCESS_1;
523                 }
524                 else if ( strncasecmp( key, "size", 1024) == 0 )
525                 {
526                         dv_response_printf( cmd_arg->response, 1024, "%d\n",
527                                 dv_unit_get_buffer_size( unit ) );
528                         return RESPONSE_SUCCESS_1;
529                 }
530                 else if ( strncasecmp( key, "n_frames", 1024) == 0 )
531                 {
532                         dv_response_printf( cmd_arg->response, 1024, "%d\n",
533                                 dv_unit_get_n_frames( unit ) );
534                         return RESPONSE_SUCCESS_1;
535                 }
536                 else if ( strncasecmp( key, "n_fill", 1024) == 0 )
537                 {
538                         dv_response_printf( cmd_arg->response, 1024, "%d\n",
539                                 dv_unit_get_n_fill( unit ) );
540                         return RESPONSE_SUCCESS_1;
541                 }
542                 else if ( strncasecmp( key, "all", 1024 ) == 0 )
543                 {
544                         switch ( dv_unit_get_eof_action( unit ) )
545                         {
546                                 case dv_player_pause:
547                                         dv_response_write( cmd_arg->response, "eof=pause\n", strlen("pause") );
548                                         break;
549                                 case dv_player_loop:
550                                         dv_response_write( cmd_arg->response, "eof=loop\n", strlen("loop") );
551                                         break;
552                                 case dv_player_terminate:
553                                         dv_response_write( cmd_arg->response, "eof=stop\n", strlen("stop") );
554                                         break;
555                                 case dv_player_clean_loop:
556                                         dv_response_write( cmd_arg->response, "eof=clean\n", strlen("clean") );
557                                         break;
558                         }
559                         if ( dv_unit_get_mode( unit ) == dv_clip_mode_restricted )
560                                 dv_response_write( cmd_arg->response, "points=use\n", strlen("use") );
561                         else
562                                 dv_response_write( cmd_arg->response, "points=ignore\n", strlen("ignore") );
563                         dv_response_printf( cmd_arg->response, 1024, "syt_offset=%d\n", dv_unit_get_syt_offset( unit ) );
564                         dv_response_printf( cmd_arg->response, 1024, "cip_n=%d\n", dv_unit_get_cip_n( unit ) );
565                         dv_response_printf( cmd_arg->response, 1024, "cip_d=%d\n", dv_unit_get_cip_d( unit ) );
566                         dv_response_printf( cmd_arg->response, 1024, "size=%d\n", dv_unit_get_buffer_size( unit ) );
567                         dv_response_printf( cmd_arg->response, 1024, "n_frames=%d\n", dv_unit_get_n_frames( unit ) );
568                         dv_response_printf( cmd_arg->response, 1024, "n_fill=%d\n", dv_unit_get_n_fill( unit ) );
569                 }
570         }
571         */
572         return RESPONSE_SUCCESS;
573 }
574
575
576 int miracle_transfer( command_argument cmd_arg )
577 {
578         /*
579         dv_unit src_unit = miracle_get_unit(cmd_arg->unit);
580         int dest_unit_id = -1;
581         char *string = (char*) cmd_arg->argument;
582         if ( string != NULL && ( string[ 0 ] == 'U' || string[ 0 ] == 'u' ) && strlen( string ) > 1 )
583                 dest_unit_id = atoi( string + 1 );
584         
585         if ( src_unit != NULL && dest_unit_id != -1 )
586         {
587                 dv_unit dest_unit = miracle_get_unit( dest_unit_id );
588                 if ( dest_unit != NULL && !dv_unit_is_offline(dest_unit) && dest_unit != src_unit )
589                 {
590                         dv_unit_transfer( dest_unit, src_unit );
591                         return RESPONSE_SUCCESS;
592                 }
593         }
594         */
595         return RESPONSE_INVALID_UNIT;
596 }