2 * mlt_service.c -- interface for all service classes
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.
22 #include "mlt_service.h"
23 #include "mlt_frame.h"
30 The base service implements a null frame producing service - as such,
31 it is functional without extension and will produce test cards frames
32 and PAL sized audio frames.
34 PLEASE DO NOT CHANGE THIS BEHAVIOUR!!! OVERRIDE THE METHODS THAT
35 CONTROL THIS IN EXTENDING CLASSES.
38 /** Private service definition.
53 static void mlt_service_disconnect( mlt_service
this );
54 static void mlt_service_connect( mlt_service
this, mlt_service that
);
55 static int service_get_frame( mlt_service
this, mlt_frame_ptr frame
, int index
);
60 int mlt_service_init( mlt_service
this, void *child
)
62 // Initialise everything to NULL
63 memset( this, 0, sizeof( struct mlt_service_s
) );
68 // Generate local space
69 this->local
= calloc( sizeof( mlt_service_base
), 1 );
71 // Associate the methods
72 this->get_frame
= service_get_frame
;
74 // Initialise the properties
75 return mlt_properties_init( &this->parent
, this );
78 /** Connect a producer service.
79 Returns: > 0 warning, == 0 success, < 0 serious error
80 1 = this service does not accept input
81 2 = the producer is invalid
82 3 = the producer is already registered with this consumer
85 int mlt_service_connect_producer( mlt_service
this, mlt_service producer
, int index
)
89 // Get the service base
90 mlt_service_base
*base
= this->local
;
92 // Check if the producer is already registered with this service
93 for ( i
= 0; i
< base
->count
; i
++ )
94 if ( base
->in
[ i
] == producer
)
98 if ( index
>= base
->size
)
100 int new_size
= base
->size
+ index
+ 10;
101 base
->in
= realloc( base
->in
, new_size
* sizeof( mlt_service
) );
102 if ( base
->in
!= NULL
)
104 for ( i
= base
->size
; i
< new_size
; i
++ )
105 base
->in
[ i
] = NULL
;
106 base
->size
= new_size
;
110 // If we have space, assign the input
111 if ( base
->in
!= NULL
&& index
>= 0 && index
< base
->size
)
113 // Now we disconnect the producer service from its consumer
114 mlt_service_disconnect( producer
);
116 // Add the service to index specified
117 base
->in
[ index
] = producer
;
119 // Determine the number of active tracks
120 if ( index
>= base
->count
)
121 base
->count
= index
+ 1;
123 // Now we connect the producer to its connected consumer
124 mlt_service_connect( producer
, this );
126 // Inform caller that all went well
135 /** Disconnect this service from its consumer.
138 static void mlt_service_disconnect( mlt_service
this )
140 // Get the service base
141 mlt_service_base
*base
= this->local
;
143 // There's a bit more required here...
147 /** Obtain the consumer this service is connected to.
150 mlt_service
mlt_service_consumer( mlt_service
this )
152 // Get the service base
153 mlt_service_base
*base
= this->local
;
155 // Return the connected consumer
159 /** Obtain the producer this service is connected to.
162 mlt_service
mlt_service_producer( mlt_service
this )
164 // Get the service base
165 mlt_service_base
*base
= this->local
;
167 // Return the connected producer
168 return base
->count
> 0 ? base
->in
[ base
->count
- 1 ] : NULL
;
171 /** Associate this service to the consumer.
174 static void mlt_service_connect( mlt_service
this, mlt_service that
)
176 // Get the service base
177 mlt_service_base
*base
= this->local
;
179 // There's a bit more required here...
183 /** Get the first connected producer service.
186 mlt_service
mlt_service_get_producer( mlt_service
this )
188 mlt_service producer
= NULL
;
190 // Get the service base
191 mlt_service_base
*base
= this->local
;
193 if ( base
->in
!= NULL
)
194 producer
= base
->in
[ 0 ];
199 /** Default implementation of get_frame.
202 static int service_get_frame( mlt_service
this, mlt_frame_ptr frame
, int index
)
204 mlt_service_base
*base
= this->local
;
205 if ( index
< base
->count
)
207 mlt_service producer
= base
->in
[ index
];
208 if ( producer
!= NULL
)
209 return mlt_service_get_frame( producer
, frame
, index
);
211 *frame
= mlt_frame_init( );
215 /** Return the properties object.
218 mlt_properties
mlt_service_properties( mlt_service self
)
220 return &self
->parent
;
226 int mlt_service_get_frame( mlt_service
this, mlt_frame_ptr frame
, int index
)
229 return this->get_frame( this, frame
, index
);
230 *frame
= mlt_frame_init( );
234 /** Close the service.
237 void mlt_service_close( mlt_service
this )
239 mlt_service_base
*base
= this->local
;
242 mlt_properties_close( &this->parent
);