2 * mlt_filter.c -- abstraction for all filter services
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.
23 #include "mlt_filter.h"
24 #include "mlt_frame.h"
30 static int filter_get_frame( mlt_service
this, mlt_frame_ptr frame
, int index
);
32 /** Constructor method.
35 int mlt_filter_init( mlt_filter
this, void *child
)
37 mlt_service service
= &this->parent
;
38 memset( this, 0, sizeof( struct mlt_filter_s
) );
40 if ( mlt_service_init( service
, this ) == 0 )
42 mlt_properties properties
= mlt_service_properties( service
);
44 // Override the get_frame method
45 service
->get_frame
= filter_get_frame
;
47 // Default in, out, track properties
48 mlt_properties_set_timecode( properties
, "in", 0 );
49 mlt_properties_set_timecode( properties
, "out", 0 );
50 mlt_properties_set_int( properties
, "track", 0 );
57 /** Get the service associated to this filter
60 mlt_service
mlt_filter_service( mlt_filter
this )
65 /** Connect this filter to a producers track. Note that a filter only operates
66 on a single track, and by default it operates on the entirety of that track.
69 int mlt_filter_connect( mlt_filter
this, mlt_service producer
, int index
)
71 int ret
= mlt_service_connect_producer( &this->parent
, producer
, index
);
73 // If the connection was successful, grab the producer, track and reset in/out
76 mlt_properties properties
= mlt_service_properties( &this->parent
);
77 this->producer
= producer
;
78 mlt_properties_set_timecode( properties
, "in", 0 );
79 mlt_properties_set_timecode( properties
, "out", 0 );
80 mlt_properties_set_int( properties
, "track", index
);
86 /** Tune the in/out points.
89 void mlt_filter_set_in_and_out( mlt_filter
this, mlt_timecode in
, mlt_timecode out
)
91 mlt_properties properties
= mlt_service_properties( &this->parent
);
92 mlt_properties_set_timecode( properties
, "in", in
);
93 mlt_properties_set_timecode( properties
, "out", out
);
96 /** Return the track that this filter is operating on.
99 int mlt_filter_get_track( mlt_filter
this )
101 mlt_properties properties
= mlt_service_properties( &this->parent
);
102 return mlt_properties_get_int( properties
, "track" );
105 /** Get the in point.
108 mlt_timecode
mlt_filter_get_in( mlt_filter
this )
110 mlt_properties properties
= mlt_service_properties( &this->parent
);
111 return mlt_properties_get_timecode( properties
, "in" );
114 /** Get the out point.
117 mlt_timecode
mlt_filter_get_out( mlt_filter
this )
119 mlt_properties properties
= mlt_service_properties( &this->parent
);
120 return mlt_properties_get_timecode( properties
, "out" );
123 /** Process the frame.
126 static mlt_frame
filter_process( mlt_filter
this, mlt_frame frame
)
128 if ( this->process
== NULL
)
131 return this->process( this, frame
);
134 /** Get a frame from this filter.
137 static int filter_get_frame( mlt_service service
, mlt_frame_ptr frame
, int index
)
139 mlt_filter
this = service
->child
;
141 // Get coords in/out/track
142 int track
= mlt_filter_get_track( this );
143 int in
= mlt_filter_get_in( this );
144 int out
= mlt_filter_get_out( this );
146 // If the frame request is for this filters track, we need to process it
147 if ( index
== track
)
149 int ret
= mlt_service_get_frame( this->producer
, frame
, index
);
152 if ( !mlt_frame_is_test_card( *frame
) )
154 mlt_timecode timecode
= mlt_frame_get_timecode( *frame
);
155 if ( timecode
>= in
&& ( out
== 0 || timecode
< out
) )
156 *frame
= filter_process( this, *frame
);
162 *frame
= mlt_frame_init( );
168 return mlt_service_get_frame( this->producer
, frame
, index
);
172 /** Close the filter.
175 void mlt_filter_close( mlt_filter
this )
177 if ( this->close
!= NULL
)
180 mlt_service_close( &this->parent
);