2 * mlt_field.c -- A field for planting multiple transitions and filters
3 * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
4 * Author: Charles Yates <charles.yates@pandora.be>
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.
21 #include "mlt_field.h"
22 #include "mlt_service.h"
23 #include "mlt_filter.h"
24 #include "mlt_transition.h"
29 /** Private structures.
34 // We extending service here
35 struct mlt_service_s parent;
37 // This is the producer we're connected to
41 /** Forward declarations
44 static int service_get_frame( mlt_service service, mlt_frame_ptr frame, int index );
46 /** Constructor. This service needs to know its producer at construction.
48 When the first filter or transition is planted, we connect it immediately to
49 the producer of the field, and all subsequent plants are then connected to the
50 previous plant. This immediate connection requires the producer prior to the first
53 It's a kind of arbitrary decsion - we could generate a dummy service here and
54 then connect the dummy in the normal connect manner. Behaviour may change in the
55 future (say, constructing a dummy when producer service is NULL). However, the
56 current solution is quite clean, if slightly out of sync with the rest of the
60 mlt_field mlt_field_init( mlt_service producer )
62 // Initialise the field
63 mlt_field this = calloc( sizeof( struct mlt_field_s ), 1 );
66 mlt_service service = &this->parent;
68 // Initialise the service
69 mlt_service_init( service, this );
71 // Override the get_frame method
72 service->get_frame = service_get_frame;
74 // Connect to the producer immediately
75 if ( mlt_service_connect_producer( service, producer, 0 ) == 0 )
76 this->producer = producer;
82 /** Get the service associated to this field.
85 mlt_service mlt_field_service( mlt_field this )
90 /** Get the properties associated to this field.
93 mlt_properties mlt_field_properties( mlt_field this )
95 return mlt_service_properties( &this->parent );
101 int mlt_field_plant_filter( mlt_field this, mlt_filter that, int track )
103 // Connect the filter to the last producer
104 int result = mlt_filter_connect( that, this->producer, track );
106 // If sucessful, then we'll use this for connecting in the future
110 this->producer = mlt_filter_service( that );
116 /** Plant a transition.
119 int mlt_field_plant_transition( mlt_field this, mlt_transition that, int a_track, int b_track )
121 // Connect the transition to the last producer
122 int result = mlt_transition_connect( that, this->producer, a_track, b_track );
124 // If sucessful, then we'll use this for connecting in the future
128 this->producer = mlt_transition_service( that );
137 static int service_get_frame( mlt_service service, mlt_frame_ptr frame, int index )
139 mlt_field this = service->child;
140 return mlt_service_get_frame( this->producer, frame, index );
146 void mlt_field_close( mlt_field this )
148 mlt_service_close( &this->parent );