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