]> git.sesse.net Git - mlt/blob - src/modules/core/filter_transition.c
Remove unused string.h include
[mlt] / src / modules / core / filter_transition.c
1 /*
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>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library 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 GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include <framework/mlt_filter.h>
22 #include <framework/mlt_factory.h>
23 #include <framework/mlt_frame.h>
24 #include <framework/mlt_transition.h>
25
26 /** Get the image via the transition.
27         NB: Not all transitions will accept a and b frames being the same...
28 */
29
30 static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable )
31 {
32         mlt_transition transition = mlt_frame_pop_service( this );
33         if ( mlt_properties_get_int( MLT_FRAME_PROPERTIES( this ), "image_count" ) >= 1 )
34                 mlt_transition_process( transition, this, this );
35         return mlt_frame_get_image( this, image, format, width, height, writable );
36 }
37
38 /** Get the audio via the transition.
39         NB: Not all transitions will accept a and b frames being the same...
40 */
41
42 static int filter_get_audio( mlt_frame this, void **buffer, mlt_audio_format *format, int *frequency, int *channels, int *samples )
43 {
44         // Obtain the transition instance
45         mlt_transition transition = mlt_frame_pop_audio( this );
46         mlt_transition_process( transition, this, this );
47         return mlt_frame_get_audio( this, buffer, format, frequency, channels, samples );
48 }
49
50 /** Filter processing.
51 */
52
53 static mlt_frame filter_process( mlt_filter this, mlt_frame frame )
54 {
55         // Obtain the transition instance
56         mlt_transition transition = mlt_properties_get_data( MLT_FILTER_PROPERTIES( this ), "instance", NULL );
57
58         // If we haven't created the instance, do it now
59         if ( transition == NULL )
60         {
61                 char *name = mlt_properties_get( MLT_FILTER_PROPERTIES( this ), "transition" );
62                 mlt_profile profile = mlt_service_profile( MLT_FILTER_SERVICE( this ) );
63                 transition = mlt_factory_transition( profile, name, NULL );
64                 mlt_properties_set_data( MLT_FILTER_PROPERTIES( this ), "instance", transition, 0, ( mlt_destructor )mlt_transition_close, NULL );
65         }
66
67         // We may still not have a transition...
68         if ( transition != NULL )
69         {
70                 // Get the transition type
71                 int type = mlt_properties_get_int( MLT_TRANSITION_PROPERTIES( transition ), "_transition_type" );
72
73                 // Set the basic info
74                 mlt_properties_set_int( MLT_TRANSITION_PROPERTIES( transition ), "in", mlt_properties_get_int( MLT_FILTER_PROPERTIES( this ), "in" ) );
75                 mlt_properties_set_int( MLT_TRANSITION_PROPERTIES( transition ), "out", mlt_properties_get_int( MLT_FILTER_PROPERTIES( this ), "out" ) );
76
77                 // Refresh with current user values
78                 mlt_properties_pass( MLT_TRANSITION_PROPERTIES( transition ), MLT_FILTER_PROPERTIES( this ), "transition." );
79
80                 if ( type & 1 && !mlt_frame_is_test_card( frame ) && !( mlt_properties_get_int( MLT_FRAME_PROPERTIES( frame ), "hide" ) & 1 ) )
81                 {
82                         mlt_frame_push_service( frame, transition );
83                         mlt_frame_push_get_image( frame, filter_get_image );
84                 }
85                 if ( type & 2 && !mlt_frame_is_test_audio( frame ) && !( mlt_properties_get_int( MLT_FRAME_PROPERTIES( frame ), "hide" ) & 2 ) )
86                 {
87                         mlt_frame_push_audio( frame, transition );
88                         mlt_frame_push_audio( frame, filter_get_audio );
89                 }
90
91                 if ( type == 0 )
92                         mlt_properties_debug( MLT_TRANSITION_PROPERTIES( transition ), "unknown transition type", stderr );
93         }
94         else
95         {
96                 mlt_properties_debug( MLT_FILTER_PROPERTIES( this ), "no transition", stderr );
97         }
98
99         return frame;
100 }
101
102 /** Constructor for the filter.
103 */
104
105 mlt_filter filter_transition_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg )
106 {
107         mlt_filter this = mlt_filter_new( );
108         if ( this != NULL )
109         {
110                 mlt_properties_set( MLT_FILTER_PROPERTIES( this ), "transition", arg );
111                 this->process = filter_process;
112         }
113         return this;
114 }
115