2 * melted_unit_commands.c
3 * Copyright (C) 2002-2009 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 "melted_unit.h"
34 #include "melted_commands.h"
35 #include "melted_log.h"
37 int melted_load( command_argument cmd_arg
)
39 melted_unit unit
= melted_get_unit(cmd_arg
->unit
);
40 char *filename
= (char*) cmd_arg
->argument
;
45 if ( filename
[0] == '!' )
51 service
= strchr( filename
, ':' );
52 if ( service
!= NULL
)
55 filename
= strchr( service
, ':' );
58 if ( strlen( cmd_arg
->root_dir
) && filename
[0] == '/' )
61 snprintf( fullname
, 1023, "%s:%s%s", service
, cmd_arg
->root_dir
, filename
);
65 if ( strlen( cmd_arg
->root_dir
) && filename
[0] == '/' )
68 snprintf( fullname
, 1023, "%s%s", cmd_arg
->root_dir
, filename
);
72 return RESPONSE_INVALID_UNIT
;
75 int32_t in
= -1, out
= -1;
76 if ( mvcp_tokeniser_count( cmd_arg
->tokeniser
) == 5 )
78 in
= atol( mvcp_tokeniser_get_string( cmd_arg
->tokeniser
, 3 ) );
79 out
= atol( mvcp_tokeniser_get_string( cmd_arg
->tokeniser
, 4 ) );
81 if ( melted_unit_load( unit
, fullname
, in
, out
, flush
) != mvcp_ok
)
82 return RESPONSE_BAD_FILE
;
84 return RESPONSE_SUCCESS
;
87 int melted_list( command_argument cmd_arg
)
89 melted_unit unit
= melted_get_unit( cmd_arg
->unit
);
93 melted_unit_report_list( unit
, cmd_arg
->response
);
94 return RESPONSE_SUCCESS
;
97 return RESPONSE_INVALID_UNIT
;
100 static int parse_clip( command_argument cmd_arg
, int arg
)
102 melted_unit unit
= melted_get_unit(cmd_arg
->unit
);
103 int clip
= melted_unit_get_current_clip( unit
);
105 if ( mvcp_tokeniser_count( cmd_arg
->tokeniser
) > arg
)
107 char *token
= mvcp_tokeniser_get_string( cmd_arg
->tokeniser
, arg
);
108 if ( token
[ 0 ] == '+' )
109 clip
+= atoi( token
+ 1 );
110 else if ( token
[ 0 ] == '-' )
111 clip
-= atoi( token
+ 1 );
113 clip
= atoi( token
);
119 int melted_insert( command_argument cmd_arg
)
121 melted_unit unit
= melted_get_unit(cmd_arg
->unit
);
122 char *filename
= (char*) cmd_arg
->argument
;
125 if ( strlen( cmd_arg
->root_dir
) && filename
[0] == '/' )
128 snprintf( fullname
, 1023, "%s%s", cmd_arg
->root_dir
, filename
);
131 return RESPONSE_INVALID_UNIT
;
134 long in
= -1, out
= -1;
135 int index
= parse_clip( cmd_arg
, 3 );
137 if ( mvcp_tokeniser_count( cmd_arg
->tokeniser
) == 6 )
139 in
= atoi( mvcp_tokeniser_get_string( cmd_arg
->tokeniser
, 4 ) );
140 out
= atoi( mvcp_tokeniser_get_string( cmd_arg
->tokeniser
, 5 ) );
143 switch( melted_unit_insert( unit
, fullname
, index
, in
, out
) )
146 return RESPONSE_SUCCESS
;
148 return RESPONSE_BAD_FILE
;
151 return RESPONSE_SUCCESS
;
154 int melted_remove( command_argument cmd_arg
)
156 melted_unit unit
= melted_get_unit(cmd_arg
->unit
);
159 return RESPONSE_INVALID_UNIT
;
162 int index
= parse_clip( cmd_arg
, 2 );
164 if ( melted_unit_remove( unit
, index
) != mvcp_ok
)
165 return RESPONSE_BAD_FILE
;
167 return RESPONSE_SUCCESS
;
170 int melted_clean( command_argument cmd_arg
)
172 melted_unit unit
= melted_get_unit(cmd_arg
->unit
);
175 return RESPONSE_INVALID_UNIT
;
178 if ( melted_unit_clean( unit
) != mvcp_ok
)
179 return RESPONSE_BAD_FILE
;
181 return RESPONSE_SUCCESS
;
184 int melted_wipe( command_argument cmd_arg
)
186 melted_unit unit
= melted_get_unit(cmd_arg
->unit
);
189 return RESPONSE_INVALID_UNIT
;
192 if ( melted_unit_wipe( unit
) != mvcp_ok
)
193 return RESPONSE_BAD_FILE
;
195 return RESPONSE_SUCCESS
;
198 int melted_clear( command_argument cmd_arg
)
200 melted_unit unit
= melted_get_unit(cmd_arg
->unit
);
203 return RESPONSE_INVALID_UNIT
;
206 if ( melted_unit_clear( unit
) != mvcp_ok
)
207 return RESPONSE_BAD_FILE
;
209 return RESPONSE_SUCCESS
;
212 int melted_move( command_argument cmd_arg
)
214 melted_unit unit
= melted_get_unit(cmd_arg
->unit
);
218 if ( mvcp_tokeniser_count( cmd_arg
->tokeniser
) > 2 )
220 int src
= parse_clip( cmd_arg
, 2 );
221 int dest
= parse_clip( cmd_arg
, 3 );
223 if ( melted_unit_move( unit
, src
, dest
) != mvcp_ok
)
224 return RESPONSE_BAD_FILE
;
228 return RESPONSE_MISSING_ARG
;
233 return RESPONSE_INVALID_UNIT
;
236 return RESPONSE_SUCCESS
;
239 int melted_append( command_argument cmd_arg
)
241 melted_unit unit
= melted_get_unit(cmd_arg
->unit
);
242 char *filename
= (char*) cmd_arg
->argument
;
245 if ( strlen( cmd_arg
->root_dir
) && filename
[0] == '/' )
248 snprintf( fullname
, 1023, "%s%s", cmd_arg
->root_dir
, filename
);
251 return RESPONSE_INVALID_UNIT
;
254 int32_t in
= -1, out
= -1;
255 if ( mvcp_tokeniser_count( cmd_arg
->tokeniser
) == 5 )
257 in
= atol( mvcp_tokeniser_get_string( cmd_arg
->tokeniser
, 3 ) );
258 out
= atol( mvcp_tokeniser_get_string( cmd_arg
->tokeniser
, 4 ) );
260 switch ( melted_unit_append( unit
, fullname
, in
, out
) )
263 return RESPONSE_SUCCESS
;
265 return RESPONSE_BAD_FILE
;
268 return RESPONSE_SUCCESS
;
271 int melted_push( command_argument cmd_arg
, mlt_service service
)
273 melted_unit unit
= melted_get_unit(cmd_arg
->unit
);
274 if ( unit
!= NULL
&& service
!= NULL
)
275 if ( melted_unit_append_service( unit
, service
) == mvcp_ok
)
276 return RESPONSE_SUCCESS
;
277 return RESPONSE_BAD_FILE
;
280 int melted_receive( command_argument cmd_arg
, char *doc
)
282 melted_unit unit
= melted_get_unit(cmd_arg
->unit
);
285 // Get the consumer's profile
286 mlt_consumer consumer
= mlt_properties_get_data( unit
->properties
, "consumer", NULL
);
287 mlt_profile profile
= mlt_service_profile( MLT_CONSUMER_SERVICE( consumer
) );
288 mlt_producer producer
= mlt_factory_producer( profile
, "xml-string", doc
);
289 if ( producer
!= NULL
)
291 if ( melted_unit_append_service( unit
, MLT_PRODUCER_SERVICE( producer
) ) == mvcp_ok
)
293 mlt_producer_close( producer
);
294 return RESPONSE_SUCCESS
;
296 mlt_producer_close( producer
);
299 return RESPONSE_BAD_FILE
;
302 int melted_play( command_argument cmd_arg
)
304 melted_unit unit
= melted_get_unit(cmd_arg
->unit
);
308 return RESPONSE_INVALID_UNIT
;
313 if ( mvcp_tokeniser_count( cmd_arg
->tokeniser
) == 3 )
314 speed
= atoi( mvcp_tokeniser_get_string( cmd_arg
->tokeniser
, 2 ) );
315 melted_unit_play( unit
, speed
);
318 return RESPONSE_SUCCESS
;
321 int melted_stop( command_argument cmd_arg
)
323 melted_unit unit
= melted_get_unit(cmd_arg
->unit
);
325 return RESPONSE_INVALID_UNIT
;
327 melted_unit_terminate( unit
);
328 return RESPONSE_SUCCESS
;
331 int melted_pause( command_argument cmd_arg
)
333 melted_unit unit
= melted_get_unit(cmd_arg
->unit
);
335 return RESPONSE_INVALID_UNIT
;
337 melted_unit_play( unit
, 0 );
338 return RESPONSE_SUCCESS
;
341 int melted_rewind( command_argument cmd_arg
)
343 melted_unit unit
= melted_get_unit(cmd_arg
->unit
);
345 return RESPONSE_INVALID_UNIT
;
346 else if ( melted_unit_has_terminated( unit
) )
347 melted_unit_change_position( unit
, 0, 0 );
349 melted_unit_play( unit
, -2000 );
350 return RESPONSE_SUCCESS
;
353 int melted_step( command_argument cmd_arg
)
355 melted_unit unit
= melted_get_unit(cmd_arg
->unit
);
358 return RESPONSE_INVALID_UNIT
;
361 melted_unit_play( unit
, 0 );
362 melted_unit_step( unit
, *(int*) cmd_arg
->argument
);
364 return RESPONSE_SUCCESS
;
367 int melted_goto( command_argument cmd_arg
)
369 melted_unit unit
= melted_get_unit(cmd_arg
->unit
);
370 int clip
= parse_clip( cmd_arg
, 3 );
372 if (unit
== NULL
|| melted_unit_is_offline(unit
))
373 return RESPONSE_INVALID_UNIT
;
375 melted_unit_change_position( unit
, clip
, *(int*) cmd_arg
->argument
);
376 return RESPONSE_SUCCESS
;
379 int melted_ff( command_argument cmd_arg
)
381 melted_unit unit
= melted_get_unit(cmd_arg
->unit
);
383 return RESPONSE_INVALID_UNIT
;
384 else if ( melted_unit_has_terminated( unit
) )
385 melted_unit_change_position( unit
, 0, 0 );
387 melted_unit_play( unit
, 2000 );
388 return RESPONSE_SUCCESS
;
391 int melted_set_in_point( command_argument cmd_arg
)
393 melted_unit unit
= melted_get_unit(cmd_arg
->unit
);
394 int clip
= parse_clip( cmd_arg
, 3 );
397 return RESPONSE_INVALID_UNIT
;
400 int position
= *(int *) cmd_arg
->argument
;
402 switch( melted_unit_set_clip_in( unit
, clip
, position
) )
405 return RESPONSE_BAD_FILE
;
407 return RESPONSE_OUT_OF_RANGE
;
410 return RESPONSE_SUCCESS
;
413 int melted_set_out_point( command_argument cmd_arg
)
415 melted_unit unit
= melted_get_unit(cmd_arg
->unit
);
416 int clip
= parse_clip( cmd_arg
, 3 );
419 return RESPONSE_INVALID_UNIT
;
422 int position
= *(int *) cmd_arg
->argument
;
424 switch( melted_unit_set_clip_out( unit
, clip
, position
) )
427 return RESPONSE_BAD_FILE
;
429 return RESPONSE_OUT_OF_RANGE
;
433 return RESPONSE_SUCCESS
;
436 int melted_get_unit_status( command_argument cmd_arg
)
438 mvcp_status_t status
;
439 int error
= melted_unit_get_status( melted_get_unit( cmd_arg
->unit
), &status
);
442 return RESPONSE_INVALID_UNIT
;
446 mvcp_response_printf( cmd_arg
->response
, sizeof( text
), mvcp_status_serialise( &status
, text
, sizeof( text
) ) );
447 return RESPONSE_SUCCESS_1
;
453 int melted_set_unit_property( command_argument cmd_arg
)
455 melted_unit unit
= melted_get_unit(cmd_arg
->unit
);
456 char *name_value
= (char*) cmd_arg
->argument
;
458 return RESPONSE_INVALID_UNIT
;
460 melted_unit_set( unit
, name_value
);
461 return RESPONSE_SUCCESS
;
464 int melted_get_unit_property( command_argument cmd_arg
)
466 melted_unit unit
= melted_get_unit(cmd_arg
->unit
);
467 char *name
= (char*) cmd_arg
->argument
;
468 char *value
= melted_unit_get( unit
, name
);
470 return RESPONSE_INVALID_UNIT
;
471 else if ( value
!= NULL
)
472 mvcp_response_printf( cmd_arg
->response
, 1024, "%s\n", value
);
473 return RESPONSE_SUCCESS
;
477 int melted_transfer( command_argument cmd_arg
)
479 melted_unit src_unit
= melted_get_unit(cmd_arg
->unit
);
480 int dest_unit_id
= -1;
481 char *string
= (char*) cmd_arg
->argument
;
482 if ( string
!= NULL
&& ( string
[ 0 ] == 'U' || string
[ 0 ] == 'u' ) && strlen( string
) > 1 )
483 dest_unit_id
= atoi( string
+ 1 );
485 if ( src_unit
!= NULL
&& dest_unit_id
!= -1 )
487 melted_unit dest_unit
= melted_get_unit( dest_unit_id
);
488 if ( dest_unit
!= NULL
&& !melted_unit_is_offline(dest_unit
) && dest_unit
!= src_unit
)
490 melted_unit_transfer( dest_unit
, src_unit
);
491 return RESPONSE_SUCCESS
;
494 return RESPONSE_INVALID_UNIT
;