]> git.sesse.net Git - mlt/blob - src/miracle/miracle_unit.c
18f19acab386a937c051e249b4ae4fdb3259888f
[mlt] / src / miracle / miracle_unit.c
1 /*
2  * miracle_unit.c -- DV Transmission Unit Implementation
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 <stdio.h>
26 #include <unistd.h>
27 #include <sys/ioctl.h>
28 #include <sys/mman.h>
29 #include <sys/poll.h>
30 #include <sys/types.h>
31 #include <fcntl.h>
32 #include <stdlib.h>
33 #include <string.h>
34 #include <errno.h>
35 #include <signal.h>
36 #include <limits.h>
37
38 #include <sys/mman.h>
39
40 #include "miracle_unit.h"
41 #include "miracle_log.h"
42 #include "miracle_local.h"
43
44 #include <framework/mlt.h>
45
46 /* Forward references */
47 static void miracle_unit_status_communicate( miracle_unit );
48
49 /** Allocate a new DV transmission unit.
50
51     \return A new miracle_unit handle.
52 */
53
54 miracle_unit miracle_unit_init( int index, char *constructor )
55 {
56         miracle_unit this = NULL;
57         mlt_consumer consumer = NULL;
58
59         char *id = strdup( constructor );
60         char *arg = strchr( id, ':' );
61
62         if ( arg != NULL )
63                 *arg ++ = '\0';
64
65         consumer = mlt_factory_consumer( id, arg );
66
67         if ( consumer != NULL )
68         {
69                 mlt_playlist playlist = mlt_playlist_init( );
70                 this = calloc( sizeof( miracle_unit_t ), 1 );
71                 this->properties = mlt_properties_new( );
72                 this->old_playlist = mlt_playlist_init( );
73                 mlt_properties_init( this->properties, this );
74                 mlt_properties_set_int( this->properties, "unit", index );
75                 mlt_properties_set_int( this->properties, "generation", 0 );
76                 mlt_properties_set( this->properties, "constructor", constructor );
77                 mlt_properties_set( this->properties, "id", id );
78                 mlt_properties_set( this->properties, "arg", arg );
79                 mlt_properties_set_data( this->properties, "consumer", consumer, 0, ( mlt_destructor )mlt_consumer_close, NULL );
80                 mlt_properties_set_data( this->properties, "playlist", playlist, 0, ( mlt_destructor )mlt_playlist_close, NULL );
81                 mlt_consumer_connect( consumer, mlt_playlist_service( playlist ) );
82         }
83
84         return this;
85 }
86
87 static void copy_playlist( mlt_playlist dest, mlt_playlist src )
88 {
89         int i;
90
91         for ( i = 0; i < mlt_playlist_count( src ); i ++ )
92         {
93                 mlt_playlist_clip_info info;
94                 mlt_playlist_get_clip_info( src, &info, i );
95                 if ( info.producer != NULL )
96                         mlt_playlist_append_io( dest, info.producer, info.frame_in, info.frame_out );
97         }
98 }
99
100 static char *strip_root( miracle_unit unit, char *file )
101 {
102         mlt_properties properties = unit->properties;
103         char *root = mlt_properties_get( properties, "root" );
104         if ( file != NULL && root != NULL )
105         {
106                 int length = strlen( root );
107                 if ( root[ length - 1 ] == '/' )
108                         length --;
109                 if ( !strncmp( file, root, length ) )
110                         file += length;
111         }
112         return file;
113 }
114
115 /** Communicate the current status to all threads waiting on the notifier.
116 */
117
118 static void miracle_unit_status_communicate( miracle_unit unit )
119 {
120         if ( unit != NULL )
121         {
122                 mlt_properties properties = unit->properties;
123                 char *root_dir = mlt_properties_get( properties, "root" );
124                 valerie_notifier notifier = mlt_properties_get_data( properties, "notifier", NULL );
125                 valerie_status_t status;
126
127                 if ( root_dir != NULL && notifier != NULL )
128                 {
129                         if ( miracle_unit_get_status( unit, &status ) == 0 )
130                                 /* if ( !( ( status.status == unit_playing || status.status == unit_paused ) &&
131                                                 strcmp( status.clip, "" ) && 
132                                         !strcmp( status.tail_clip, "" ) && 
133                                                 status.position == 0 && 
134                                                 status.in == 0 && 
135                                                 status.out == 0 ) ) */
136                                         valerie_notifier_put( notifier, &status );
137                 }
138         }
139 }
140
141 /** Set the notifier info
142 */
143
144 void miracle_unit_set_notifier( miracle_unit this, valerie_notifier notifier, char *root_dir )
145 {
146         mlt_properties properties = this->properties;
147         mlt_playlist playlist = mlt_properties_get_data( properties, "playlist", NULL );
148         mlt_properties playlist_properties = mlt_playlist_properties( playlist );
149
150         mlt_properties_set( properties, "root", root_dir );
151         mlt_properties_set_data( properties, "notifier", notifier, 0, NULL, NULL );
152         mlt_properties_set_data( playlist_properties, "notifier_arg", this, 0, NULL, NULL );
153         mlt_properties_set_data( playlist_properties, "notifier", miracle_unit_status_communicate, 0, NULL, NULL );
154
155         miracle_unit_status_communicate( this );
156 }
157
158 /** Create or locate a producer for the file specified.
159 */
160
161 static mlt_producer locate_producer( miracle_unit unit, char *file )
162 {
163         return mlt_factory_producer( "fezzik", file );
164 }
165
166 /** Update the generation count.
167 */
168
169 static void update_generation( miracle_unit unit )
170 {
171         mlt_properties properties = unit->properties;
172         int generation = mlt_properties_get_int( properties, "generation" );
173         mlt_properties_set_int( properties, "generation", ++ generation );
174 }
175
176 /** Wipe all clips on the playlist for this unit.
177 */
178
179 static void clear_unit( miracle_unit unit )
180 {
181         mlt_properties properties = unit->properties;
182         mlt_playlist playlist = mlt_properties_get_data( properties, "playlist", NULL );
183         mlt_producer producer = mlt_playlist_producer( playlist );
184
185         mlt_playlist_clear( unit->old_playlist );
186         copy_playlist( unit->old_playlist, playlist );
187         mlt_playlist_clear( playlist );
188         mlt_producer_seek( producer, 0 );
189
190         update_generation( unit );
191 }
192
193 /** Wipe all but the playing clip from the unit.
194 */
195
196 static void clean_unit( miracle_unit unit )
197 {
198         mlt_properties properties = unit->properties;
199         mlt_playlist playlist = mlt_properties_get_data( properties, "playlist", NULL );
200         mlt_playlist_clip_info info;
201         int current = mlt_playlist_current_clip( playlist );
202         mlt_producer producer = mlt_playlist_producer( playlist );
203         mlt_position position = mlt_producer_frame( producer );
204         double speed = mlt_producer_get_speed( producer );
205         mlt_playlist_get_clip_info( playlist, &info, current );
206
207         if ( info.producer != NULL )
208         {
209                 mlt_properties_inc_ref( mlt_producer_properties( info.producer ) );
210                 position -= info.start;
211                 clear_unit( unit );
212                 mlt_playlist_append_io( playlist, info.producer, info.frame_in, info.frame_out );
213                 mlt_producer_seek( producer, position );
214                 mlt_producer_set_speed( producer, speed );
215                 mlt_producer_close( info.producer );
216         }
217         
218         update_generation( unit );
219 }
220
221 /** Generate a report on all loaded clips.
222 */
223
224 void miracle_unit_report_list( miracle_unit unit, valerie_response response )
225 {
226         int i;
227         mlt_properties properties = unit->properties;
228         int generation = mlt_properties_get_int( properties, "generation" );
229         mlt_playlist playlist = mlt_properties_get_data( properties, "playlist", NULL );
230
231         valerie_response_printf( response, 1024, "%d\n", generation );
232                 
233         for ( i = 0; i < mlt_playlist_count( playlist ); i ++ )
234         {
235                 mlt_playlist_clip_info info;
236                 char *title;
237                 mlt_playlist_get_clip_info( playlist , &info, i );
238                 title = mlt_properties_get( mlt_producer_properties( info.producer ), "title" );
239                 if ( title == NULL )
240                         title = strip_root( unit, info.resource );
241                 valerie_response_printf( response, 10240, "%d \"%s\" %d %d %d %d %.2f\n", 
242                                                                  i, 
243                                                                  title,
244                                                                  info.frame_in, 
245                                                                  info.frame_out,
246                                                                  info.frame_count, 
247                                                                  info.length, 
248                                                                  info.fps );
249         }
250         valerie_response_printf( response, 1024, "\n" );
251 }
252
253 /** Load a clip into the unit clearing existing play list.
254
255     \todo error handling
256     \param unit A miracle_unit handle.
257     \param clip The absolute file name of the clip to load.
258     \param in   The starting frame (-1 for 0)
259         \param out  The ending frame (-1 for maximum)
260 */
261
262 valerie_error_code miracle_unit_load( miracle_unit unit, char *clip, int32_t in, int32_t out, int flush )
263 {
264         // Now try to create a producer
265         mlt_producer instance = locate_producer( unit, clip );
266
267         if ( instance != NULL )
268         {
269                 clear_unit( unit );
270                 mlt_properties properties = unit->properties;
271                 mlt_playlist playlist = mlt_properties_get_data( properties, "playlist", NULL );
272                 mlt_consumer consumer = mlt_properties_get_data( unit->properties, "consumer", NULL );
273                 mlt_consumer_purge( consumer );
274                 mlt_playlist_append_io( playlist, instance, in, out );
275                 miracle_log( LOG_DEBUG, "loaded clip %s", clip );
276                 miracle_unit_status_communicate( unit );
277                 mlt_producer_close( instance );
278                 return valerie_ok;
279         }
280
281         return valerie_invalid_file;
282 }
283
284 valerie_error_code miracle_unit_insert( miracle_unit unit, char *clip, int index, int32_t in, int32_t out )
285 {
286         mlt_producer instance = locate_producer( unit, clip );
287
288         if ( instance != NULL )
289         {
290                 mlt_properties properties = unit->properties;
291                 mlt_playlist playlist = mlt_properties_get_data( properties, "playlist", NULL );
292                 fprintf( stderr, "inserting clip %s before %d\n", clip, index );
293                 mlt_playlist_insert( playlist, instance, index, in, out );
294                 miracle_log( LOG_DEBUG, "inserted clip %s at %d", clip, index );
295                 update_generation( unit );
296                 miracle_unit_status_communicate( unit );
297                 mlt_producer_close( instance );
298                 return valerie_ok;
299         }
300
301         return valerie_invalid_file;
302 }
303
304 valerie_error_code miracle_unit_remove( miracle_unit unit, int index )
305 {
306         mlt_properties properties = unit->properties;
307         mlt_playlist playlist = mlt_properties_get_data( properties, "playlist", NULL );
308         mlt_playlist_remove( playlist, index );
309         miracle_log( LOG_DEBUG, "removed clip at %d", index );
310         update_generation( unit );
311         miracle_unit_status_communicate( unit );
312         return valerie_ok;
313 }
314
315 valerie_error_code miracle_unit_clean( miracle_unit unit )
316 {
317         clean_unit( unit );
318         miracle_log( LOG_DEBUG, "Cleaned playlist" );
319         miracle_unit_status_communicate( unit );
320         return valerie_ok;
321 }
322
323 valerie_error_code miracle_unit_clear( miracle_unit unit )
324 {
325         mlt_consumer consumer = mlt_properties_get_data( unit->properties, "consumer", NULL );
326         clear_unit( unit );
327         mlt_consumer_purge( consumer );
328         miracle_log( LOG_DEBUG, "Cleared playlist" );
329         miracle_unit_status_communicate( unit );
330         return valerie_ok;
331 }
332
333 valerie_error_code miracle_unit_move( miracle_unit unit, int src, int dest )
334 {
335         mlt_properties properties = unit->properties;
336         mlt_playlist playlist = mlt_properties_get_data( properties, "playlist", NULL );
337         mlt_playlist_move( playlist, src, dest );
338         miracle_log( LOG_DEBUG, "moved clip %d to %d", src, dest );
339         update_generation( unit );
340         miracle_unit_status_communicate( unit );
341         return valerie_ok;
342 }
343
344 /** Add a clip to the unit play list.
345
346     \todo error handling
347     \param unit A miracle_unit handle.
348     \param clip The absolute file name of the clip to load.
349     \param in   The starting frame (-1 for 0)
350         \param out  The ending frame (-1 for maximum)
351 */
352
353 valerie_error_code miracle_unit_append( miracle_unit unit, char *clip, int32_t in, int32_t out )
354 {
355         mlt_producer instance = locate_producer( unit, clip );
356
357         if ( instance != NULL )
358         {
359                 mlt_properties properties = unit->properties;
360                 mlt_playlist playlist = mlt_properties_get_data( properties, "playlist", NULL );
361                 mlt_playlist_append_io( playlist, instance, in, out );
362                 miracle_log( LOG_DEBUG, "appended clip %s", clip );
363                 update_generation( unit );
364                 miracle_unit_status_communicate( unit );
365                 mlt_producer_close( instance );
366                 return valerie_ok;
367         }
368
369         return valerie_invalid_file;
370 }
371
372 /** Add an mlt_service to the playlist
373
374     \param unit A miracle_unit handle.
375     \param service the service to add
376 */
377
378 valerie_error_code miracle_unit_append_service( miracle_unit unit, mlt_service service )
379 {
380         mlt_properties properties = unit->properties;
381         mlt_playlist playlist = mlt_properties_get_data( properties, "playlist", NULL );
382         mlt_playlist_append( playlist, ( mlt_producer )service );
383         miracle_log( LOG_DEBUG, "appended clip" );
384         update_generation( unit );
385         miracle_unit_status_communicate( unit );
386         return valerie_ok;
387 }
388
389 /** Start playing the unit.
390
391     \todo error handling
392     \param unit A miracle_unit handle.
393     \param speed An integer that specifies the playback rate as a
394                  percentage multiplied by 100.
395 */
396
397 void miracle_unit_play( miracle_unit_t *unit, int speed )
398 {
399         mlt_properties properties = unit->properties;
400         mlt_playlist playlist = mlt_properties_get_data( properties, "playlist", NULL );
401         mlt_producer producer = mlt_playlist_producer( playlist );
402         mlt_consumer consumer = mlt_properties_get_data( unit->properties, "consumer", NULL );
403         mlt_producer_set_speed( producer, ( double )speed / 1000 );
404         mlt_consumer_start( consumer );
405         miracle_unit_status_communicate( unit );
406 }
407
408 /** Stop playback.
409
410     Terminates the dv_pump and halts dv1394 transmission.
411
412     \param unit A miracle_unit handle.
413 */
414
415 void miracle_unit_terminate( miracle_unit unit )
416 {
417         mlt_consumer consumer = mlt_properties_get_data( unit->properties, "consumer", NULL );
418         mlt_playlist playlist = mlt_properties_get_data( unit->properties, "playlist", NULL );
419         mlt_producer producer = mlt_playlist_producer( playlist );
420         mlt_producer_set_speed( producer, 0 );
421         mlt_consumer_stop( consumer );
422         miracle_unit_status_communicate( unit );
423 }
424
425 /** Query the status of unit playback.
426
427     \param unit A miracle_unit handle.
428     \return 1 if the unit is not playing, 0 if playing.
429 */
430
431 int miracle_unit_has_terminated( miracle_unit unit )
432 {
433         mlt_consumer consumer = mlt_properties_get_data( unit->properties, "consumer", NULL );
434         return mlt_consumer_is_stopped( consumer );
435 }
436
437 /** Transfer the currently loaded clip to another unit
438 */
439
440 int miracle_unit_transfer( miracle_unit dest_unit, miracle_unit src_unit )
441 {
442         int i;
443         mlt_properties dest_properties = dest_unit->properties;
444         mlt_playlist dest_playlist = mlt_properties_get_data( dest_properties, "playlist", NULL );
445         mlt_properties src_properties = src_unit->properties;
446         mlt_playlist src_playlist = mlt_properties_get_data( src_properties, "playlist", NULL );
447         mlt_playlist tmp_playlist = mlt_playlist_init( );
448
449         for ( i = 0; i < mlt_playlist_count( src_playlist ); i ++ )
450         {
451                 mlt_playlist_clip_info info;
452                 mlt_playlist_get_clip_info( src_playlist, &info, i );
453                 if ( info.producer != NULL )
454                         mlt_playlist_append_io( tmp_playlist, info.producer, info.frame_in, info.frame_out );
455         }
456
457         clear_unit( src_unit );
458
459         for ( i = 0; i < mlt_playlist_count( tmp_playlist ); i ++ )
460         {
461                 mlt_playlist_clip_info info;
462                 mlt_playlist_get_clip_info( tmp_playlist, &info, i );
463                 if ( info.producer != NULL )
464                         mlt_playlist_append_io( dest_playlist, info.producer, info.frame_in, info.frame_out );
465         }
466
467         mlt_playlist_close( tmp_playlist );
468
469         return 0;
470 }
471
472 /** Determine if unit is offline.
473 */
474
475 int miracle_unit_is_offline( miracle_unit unit )
476 {
477         return 0;
478 }
479
480 /** Obtain the status for a given unit
481 */
482
483 int miracle_unit_get_status( miracle_unit unit, valerie_status status )
484 {
485         int error = unit == NULL;
486
487         memset( status, 0, sizeof( valerie_status_t ) );
488
489         if ( !error )
490         {
491                 mlt_properties properties = unit->properties;
492                 mlt_playlist playlist = mlt_properties_get_data( properties, "playlist", NULL );
493                 mlt_producer producer = mlt_playlist_producer( playlist );
494                 mlt_producer clip = mlt_playlist_current( playlist );
495
496                 mlt_playlist_clip_info info;
497                 int clip_index = mlt_playlist_current_clip( playlist );
498                 mlt_playlist_get_clip_info( playlist, &info, clip_index );
499
500                 if ( info.resource != NULL && strcmp( info.resource, "" ) )
501                 {
502                         char *title = mlt_properties_get( mlt_producer_properties( info.producer ), "title" );
503                         if ( title == NULL )
504                                 title = strip_root( unit, info.resource );
505                         strncpy( status->clip, title, sizeof( status->clip ) );
506                         status->speed = (int)( mlt_producer_get_speed( producer ) * 1000.0 );
507                         status->fps = mlt_producer_get_fps( producer );
508                         status->in = info.frame_in;
509                         status->out = info.frame_out;
510                         status->position = mlt_producer_position( clip );
511                         status->length = mlt_producer_get_length( clip );
512                         strncpy( status->tail_clip, title, sizeof( status->tail_clip ) );
513                         status->tail_in = info.frame_in;
514                         status->tail_out = info.frame_out;
515                         status->tail_position = mlt_producer_position( clip );
516                         status->tail_length = mlt_producer_get_length( clip );
517                         status->clip_index = mlt_playlist_current_clip( playlist );
518                         status->seek_flag = 1;
519                 }
520
521                 status->generation = mlt_properties_get_int( properties, "generation" );
522
523                 if ( miracle_unit_has_terminated( unit ) )
524                         status->status = unit_stopped;
525                 else if ( !strcmp( status->clip, "" ) )
526                         status->status = unit_not_loaded;
527                 else if ( status->speed == 0 )
528                         status->status = unit_paused;
529                 else
530                         status->status = unit_playing;
531         }
532         else
533         {
534                 status->status = unit_undefined;
535         }
536
537         status->unit = mlt_properties_get_int( unit->properties, "unit" );
538
539         return error;
540 }
541
542 /** Change position in the playlist.
543 */
544
545 void miracle_unit_change_position( miracle_unit unit, int clip, int32_t position )
546 {
547         mlt_properties properties = unit->properties;
548         mlt_playlist playlist = mlt_properties_get_data( properties, "playlist", NULL );
549         mlt_producer producer = mlt_playlist_producer( playlist );
550         mlt_playlist_clip_info info;
551
552         if ( clip < 0 )
553         {
554                 clip = 0;
555                 position = 0;
556         }
557         else if ( clip >= mlt_playlist_count( playlist ) )
558         {
559                 clip = mlt_playlist_count( playlist ) - 1;
560                 position = LONG_MAX;
561         }
562
563         if ( mlt_playlist_get_clip_info( playlist, &info, clip ) == 0 )
564         {
565                 int32_t frame_start = info.start;
566                 int32_t frame_offset = position;
567
568                 if ( frame_offset < 0 )
569                         frame_offset = info.frame_out;
570                 if ( frame_offset < info.frame_in )
571                         frame_offset = info.frame_in;
572                 if ( frame_offset >= info.frame_out )
573                         frame_offset = info.frame_out;
574                 
575                 mlt_producer_seek( producer, frame_start + frame_offset - info.frame_in );
576         }
577
578         miracle_unit_status_communicate( unit );
579 }
580
581 /** Get the index of the current clip.
582 */
583
584 int     miracle_unit_get_current_clip( miracle_unit unit )
585 {
586         mlt_properties properties = unit->properties;
587         mlt_playlist playlist = mlt_properties_get_data( properties, "playlist", NULL );
588         int clip_index = mlt_playlist_current_clip( playlist );
589         return clip_index;
590 }
591
592 /** Set a clip's in point
593 */
594
595 int miracle_unit_set_clip_in( miracle_unit unit, int index, int32_t position )
596 {
597         mlt_properties properties = unit->properties;
598         mlt_playlist playlist = mlt_properties_get_data( properties, "playlist", NULL );
599         mlt_playlist_clip_info info;
600         int error = mlt_playlist_get_clip_info( playlist, &info, index );
601
602         if ( error == 0 )
603         {
604                 miracle_unit_play( unit, 0 );
605                 error = mlt_playlist_resize_clip( playlist, index, position, info.frame_out );
606                 update_generation( unit );
607                 miracle_unit_change_position( unit, index, 0 );
608         }
609
610         return error;
611 }
612
613 /** Set a clip's out point.
614 */
615
616 int miracle_unit_set_clip_out( miracle_unit unit, int index, int32_t position )
617 {
618         mlt_properties properties = unit->properties;
619         mlt_playlist playlist = mlt_properties_get_data( properties, "playlist", NULL );
620         mlt_playlist_clip_info info;
621         int error = mlt_playlist_get_clip_info( playlist, &info, index );
622
623         if ( error == 0 )
624         {
625                 miracle_unit_play( unit, 0 );
626                 error = mlt_playlist_resize_clip( playlist, index, info.frame_in, position );
627                 update_generation( unit );
628                 miracle_unit_status_communicate( unit );
629                 miracle_unit_change_position( unit, index, -1 );
630         }
631
632         return error;
633 }
634
635 /** Step by specified position.
636 */
637
638 void miracle_unit_step( miracle_unit unit, int32_t offset )
639 {
640         mlt_properties properties = unit->properties;
641         mlt_playlist playlist = mlt_properties_get_data( properties, "playlist", NULL );
642         mlt_producer producer = mlt_playlist_producer( playlist );
643         mlt_position position = mlt_producer_frame( producer );
644         mlt_producer_seek( producer, position + offset );
645 }
646
647 /** Set the unit's clip mode regarding in and out points.
648 */
649
650 //void miracle_unit_set_mode( miracle_unit unit, dv_player_clip_mode mode )
651 //{
652         //dv_player player = miracle_unit_get_dv_player( unit );
653         //if ( player != NULL )
654                 //dv_player_set_clip_mode( player, mode );
655         //miracle_unit_status_communicate( unit );
656 //}
657
658 /** Get the unit's clip mode regarding in and out points.
659 */
660
661 //dv_player_clip_mode miracle_unit_get_mode( miracle_unit unit )
662 //{
663         //dv_player player = miracle_unit_get_dv_player( unit );
664         //return dv_player_get_clip_mode( player );
665 //}
666
667 /** Set the unit's clip mode regarding eof handling.
668 */
669
670 //void miracle_unit_set_eof_action( miracle_unit unit, dv_player_eof_action action )
671 //{
672         //dv_player player = miracle_unit_get_dv_player( unit );
673         //dv_player_set_eof_action( player, action );
674         //miracle_unit_status_communicate( unit );
675 //}
676
677 /** Get the unit's clip mode regarding eof handling.
678 */
679
680 //dv_player_eof_action miracle_unit_get_eof_action( miracle_unit unit )
681 //{
682         //dv_player player = miracle_unit_get_dv_player( unit );
683         //return dv_player_get_eof_action( player );
684 //}
685
686 int miracle_unit_set( miracle_unit unit, char *name_value )
687 {
688         mlt_properties properties = NULL;
689
690         if ( strncmp( name_value, "consumer.", 9 ) )
691         {
692                 mlt_playlist playlist = mlt_properties_get_data( unit->properties, "playlist", NULL );
693                 properties = mlt_playlist_properties( playlist );
694         }
695         else
696         {
697                 mlt_consumer consumer = mlt_properties_get_data( unit->properties, "consumer", NULL );
698                 properties = mlt_consumer_properties( consumer );
699                 name_value += 9;
700         }
701
702         return mlt_properties_parse( properties, name_value );
703 }
704
705 char *miracle_unit_get( miracle_unit unit, char *name )
706 {
707         mlt_playlist playlist = mlt_properties_get_data( unit->properties, "playlist", NULL );
708         mlt_properties properties = mlt_playlist_properties( playlist );
709         return mlt_properties_get( properties, name );
710 }
711
712 /** Release the unit
713
714     \todo error handling
715     \param unit A miracle_unit handle.
716 */
717
718 void miracle_unit_close( miracle_unit unit )
719 {
720         if ( unit != NULL )
721         {
722                 miracle_log( LOG_DEBUG, "closing unit..." );
723                 miracle_unit_terminate( unit );
724                 mlt_playlist_close( unit->old_playlist );
725                 mlt_properties_close( unit->properties );
726                 free( unit );
727                 miracle_log( LOG_DEBUG, "... unit closed." );
728         }
729 }
730