]> git.sesse.net Git - mlt/blob - src/modules/opengl/transition_movit_overlay.cpp
Change how the Movit chain is built.
[mlt] / src / modules / opengl / transition_movit_overlay.cpp
1 /*
2  * transition_movit_overlay.cpp
3  * Copyright (C) 2013 Dan Dennedy <dan@dennedy.org>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program 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
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software Foundation,
17  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20
21 #include <framework/mlt.h>
22 #include <string.h>
23 #include <assert.h>
24
25 #include "filter_glsl_manager.h"
26 #include <movit/init.h>
27 #include <movit/effect_chain.h>
28 #include <movit/util.h>
29 #include <movit/overlay_effect.h>
30
31 static int get_image( mlt_frame a_frame, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable )
32 {
33         int error;
34
35         // Get the b frame from the stack
36         mlt_frame b_frame = (mlt_frame) mlt_frame_pop_frame( a_frame );
37
38         // Get the transition object
39         mlt_transition transition = (mlt_transition) mlt_frame_pop_service( a_frame );
40         mlt_service service = MLT_TRANSITION_SERVICE( transition );
41         mlt_service_lock( service );
42
43         uint8_t *a_image, *b_image;
44
45         // Get the two images.
46         *format = mlt_image_glsl;
47         error = mlt_frame_get_image( a_frame, &a_image, format, width, height, writable );
48         error = mlt_frame_get_image( b_frame, &b_image, format, width, height, writable );
49
50         GlslManager::set_effect_input( service, a_frame, (mlt_service) a_image );
51         GlslManager::set_effect_secondary_input( service, a_frame, (mlt_service) b_image, b_frame );
52         GlslManager::set_effect( service, a_frame, new OverlayEffect );
53         *image = (uint8_t *) service;
54
55         mlt_service_unlock( service );
56         return error;
57 }
58
59 static mlt_frame process( mlt_transition transition, mlt_frame a_frame, mlt_frame b_frame )
60 {
61         mlt_frame_push_service( a_frame, transition );
62         mlt_frame_push_frame( a_frame, b_frame );
63         mlt_frame_push_get_image( a_frame, get_image );
64
65         return a_frame;
66 }
67
68 extern "C"
69 mlt_transition transition_movit_overlay_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg )
70 {
71         mlt_transition transition = NULL;
72         GlslManager* glsl = GlslManager::get_instance();
73         if ( glsl && ( transition = mlt_transition_new() ) ) {
74                 transition->process = process;
75                 
76                 // Inform apps and framework that this is a video only transition
77                 mlt_properties_set_int( MLT_TRANSITION_PROPERTIES( transition ), "_transition_type", 1 );
78         }
79         return transition;
80 }