2 * filter_transition.c -- Convert any transition into a filter
3 * Copyright (C) 2005 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 "filter_transition.h"
22 #include <framework/mlt_factory.h>
23 #include <framework/mlt_frame.h>
24 #include <framework/mlt_transition.h>
26 /** Get the image via the transition.
27 NB: Not all transitions will accept a and b frames being the same...
30 static int filter_get_image( mlt_frame
this, uint8_t **image
, mlt_image_format
*format
, int *width
, int *height
, int writable
)
32 mlt_transition transition
= mlt_frame_pop_service( this );
33 mlt_transition_process( transition
, this, this );
34 return mlt_frame_get_image( this, image
, format
, width
, height
, writable
);
37 /** Get the audio via the transition.
38 NB: Not all transitions will accept a and b frames being the same...
41 static int filter_get_audio( mlt_frame
this, int16_t **buffer
, mlt_audio_format
*format
, int *frequency
, int *channels
, int *samples
)
43 // Obtain the transition instance
44 mlt_transition transition
= mlt_frame_pop_audio( this );
45 mlt_transition_process( transition
, this, this );
46 return mlt_frame_get_audio( this, buffer
, format
, frequency
, channels
, samples
);
49 /** Filter processing.
52 static mlt_frame
filter_process( mlt_filter
this, mlt_frame frame
)
54 // Obtain the transition instance
55 mlt_transition transition
= mlt_properties_get_data( MLT_FILTER_PROPERTIES( this ), "instance", NULL
);
57 // If we haven't created the instance, do it now
58 if ( transition
== NULL
)
60 char *name
= mlt_properties_get( MLT_FILTER_PROPERTIES( this ), "transition" );
61 transition
= mlt_factory_transition( name
, NULL
);
62 mlt_properties_set_data( MLT_FILTER_PROPERTIES( this ), "instance", transition
, 0, ( mlt_destructor
)mlt_transition_close
, NULL
);
65 // We may still not have a transition...
66 if ( transition
!= NULL
)
68 // Get the transition type
69 int type
= mlt_properties_get_int( MLT_TRANSITION_PROPERTIES( transition
), "_transition_type" );
72 mlt_properties_set_int( MLT_TRANSITION_PROPERTIES( transition
), "in", mlt_properties_get_int( MLT_FILTER_PROPERTIES( this ), "in" ) );
73 mlt_properties_set_int( MLT_TRANSITION_PROPERTIES( transition
), "out", mlt_properties_get_int( MLT_FILTER_PROPERTIES( this ), "out" ) );
75 // Refresh with current user values
76 mlt_properties_pass( MLT_TRANSITION_PROPERTIES( transition
), MLT_FILTER_PROPERTIES( this ), "transition." );
80 mlt_frame_push_service( frame
, transition
);
81 mlt_frame_push_get_image( frame
, filter_get_image
);
85 mlt_frame_push_audio( frame
, transition
);
86 mlt_frame_push_audio( frame
, filter_get_audio
);
90 mlt_properties_debug( MLT_TRANSITION_PROPERTIES( transition
), "unknown transition type", stderr
);
94 mlt_properties_debug( MLT_FILTER_PROPERTIES( this ), "no transition", stderr
);
100 /** Constructor for the filter.
103 mlt_filter
filter_transition_init( char *arg
)
105 mlt_filter
this = mlt_filter_new( );
108 mlt_properties_set( MLT_FILTER_PROPERTIES( this ), "transition", arg
);
109 this->process
= filter_process
;