]> git.sesse.net Git - mlt/blobdiff - src/modules/opengl/filter_movit_convert.cpp
Hide the movit.parms properties from serialization.
[mlt] / src / modules / opengl / filter_movit_convert.cpp
index c35b546dcbfb366c65b53e082445c99eab305a5c..46d640c7fea569c2c33ab006e0458b8dccb74abd 100644 (file)
@@ -30,6 +30,8 @@
 #include <mlt++/MltProducer.h>
 #include "mlt_flip_effect.h"
 
+using namespace movit;
+
 static void set_movit_parameters( GlslChain *chain, mlt_service service, mlt_frame frame );
 
 static void yuv422_to_yuv422p( uint8_t *yuv422, uint8_t *yuv422p, int width, int height )
@@ -129,6 +131,13 @@ static void build_fingerprint( mlt_service service, mlt_frame frame, std::string
                fingerprint->push_back( ')' );
        }
 
+       GlslManager::get_effect_third_input( service, frame, &input_b, &frame_b );
+       if ( input_b ) {
+               fingerprint->push_back( '(' );
+               build_fingerprint( input_b, frame_b, fingerprint );
+               fingerprint->push_back( ')' );
+       }
+
        fingerprint->push_back( '(' );
        fingerprint->append( mlt_properties_get( MLT_SERVICE_PROPERTIES( service ), "_unique_id" ) );
 
@@ -139,7 +148,7 @@ static void build_fingerprint( mlt_service service, mlt_frame frame, std::string
                fingerprint->push_back( ']' );
        }
 
-       bool disable = mlt_properties_get_int( MLT_SERVICE_PROPERTIES( service ), "movit.parms.int.disable" );
+       bool disable = mlt_properties_get_int( MLT_SERVICE_PROPERTIES( service ), "_movit.parms.int.disable" );
        if ( disable ) {
                fingerprint->push_back( 'd' );
        }
@@ -152,9 +161,9 @@ static Effect* build_movit_chain( mlt_service service, mlt_frame frame, GlslChai
                mlt_producer producer = mlt_producer_cut_parent( mlt_frame_get_original_producer( frame ) );
                MltInput* input = GlslManager::get_input( producer, frame );
                GlslManager::set_input( producer, frame, NULL );
-               chain->effect_chain->add_input( input );
-               chain->effects.insert(std::make_pair( MLT_SERVICE( producer ), input ) );
-               return input;
+               chain->effect_chain->add_input( input->get_input() );
+               chain->inputs.insert(std::make_pair( producer, input ) );
+               return input->get_input();
        }
 
        Effect* effect = GlslManager::get_effect( service, frame );
@@ -162,12 +171,17 @@ static Effect* build_movit_chain( mlt_service service, mlt_frame frame, GlslChai
        GlslManager::set_effect( service, frame, NULL );
 
        mlt_service input_a = GlslManager::get_effect_input( service, frame );
-       mlt_service input_b;
-       mlt_frame frame_b;
+       mlt_service input_b, input_c;
+       mlt_frame frame_b, frame_c;
        GlslManager::get_effect_secondary_input( service, frame, &input_b, &frame_b );
+       GlslManager::get_effect_third_input( service, frame, &input_c, &frame_c );
        Effect *effect_a = build_movit_chain( input_a, frame, chain );
 
-       if ( input_b ) {
+       if ( input_c && input_b ) {
+               Effect *effect_b = build_movit_chain( input_b, frame_b, chain );
+               Effect *effect_c = build_movit_chain( input_c, frame_c, chain );
+               chain->effect_chain->add_effect( effect, effect_a, effect_b, effect_c );
+       } else  if ( input_b ) {
                Effect *effect_b = build_movit_chain( input_b, frame_b, chain );
                chain->effect_chain->add_effect( effect, effect_a, effect_b );
        } else {
@@ -199,6 +213,10 @@ static void dispose_movit_effects( mlt_service service, mlt_frame frame )
        if ( input_b ) {
                dispose_movit_effects( input_b, frame_b );
        }
+       GlslManager::get_effect_third_input( service, frame, &input_b, &frame_b );
+       if ( input_b ) {
+               dispose_movit_effects( input_b, frame_b );
+       }
 }
 
 static void finalize_movit_chain( mlt_service leaf_service, mlt_frame frame )
@@ -213,7 +231,11 @@ static void finalize_movit_chain( mlt_service leaf_service, mlt_frame frame )
                mlt_log_debug( leaf_service, "=== CREATING NEW CHAIN (old chain=%p, leaf=%p, fingerprint=%s) ===\n", chain, leaf_service, new_fingerprint.c_str() );
                mlt_profile profile = mlt_service_profile( leaf_service );
                chain = new GlslChain;
-               chain->effect_chain = new EffectChain( profile->display_aspect_num, profile->display_aspect_den );
+               chain->effect_chain = new EffectChain(
+                       profile->display_aspect_num,
+                       profile->display_aspect_den,
+                       GlslManager::get_instance()->get_resource_pool()
+               );
                chain->fingerprint = new_fingerprint;
 
                build_movit_chain( leaf_service, frame, chain );
@@ -238,7 +260,7 @@ static void set_movit_parameters( GlslChain *chain, mlt_service service, mlt_fra
 {
        if ( service == (mlt_service) -1 ) {
                mlt_producer producer = mlt_producer_cut_parent( mlt_frame_get_original_producer( frame ) );
-               MltInput* input = (MltInput *) chain->effects[ MLT_PRODUCER_SERVICE( producer ) ];
+               MltInput* input = chain->inputs[ producer ];
                input->set_pixel_data( GlslManager::get_input_pixel_pointer( producer, frame ) );
                return;
        }
@@ -253,23 +275,30 @@ static void set_movit_parameters( GlslChain *chain, mlt_service service, mlt_fra
        if ( input_b ) {
                set_movit_parameters( chain, input_b, frame_b );
        }
-               
+       GlslManager::get_effect_third_input( service, frame, &input_b, &frame_b );
+       if ( input_b ) {
+               set_movit_parameters( chain, input_b, frame_b );
+       }
+
        mlt_properties properties = MLT_SERVICE_PROPERTIES( service );
        int count = mlt_properties_count( properties );
        for (int i = 0; i < count; ++i) {
                const char *name = mlt_properties_get_name( properties, i );
-               if (strncmp(name, "movit.parms.float.", strlen("movit.parms.float.")) == 0) {
-                       bool ok = effect->set_float(name + strlen("movit.parms.float."),
+               if (strncmp(name, "_movit.parms.float.", strlen("_movit.parms.float.")) == 0 &&
+                       mlt_properties_get_value( properties, i )) {
+                       bool ok = effect->set_float(name + strlen("_movit.parms.float."),
                                mlt_properties_get_double( properties, name ));
                        assert(ok);
                }
-               if (strncmp(name, "movit.parms.int.", strlen("movit.parms.int.")) == 0) {
-                       bool ok = effect->set_int(name + strlen("movit.parms.int."),
+               if (strncmp(name, "_movit.parms.int.", strlen("_movit.parms.int.")) == 0 &&
+                       mlt_properties_get_value( properties, i )) {
+                       bool ok = effect->set_int(name + strlen("_movit.parms.int."),
                                mlt_properties_get_int( properties, name ));
                        assert(ok);
                }
-               if (strncmp(name, "movit.parms.vec3.", strlen("movit.parms.vec3.")) == 0 &&
-                   strcmp(name + strlen(name) - 3, "[0]") == 0) {
+               if (strncmp(name, "_movit.parms.vec3.", strlen("_movit.parms.vec3.")) == 0 &&
+                   strcmp(name + strlen(name) - 3, "[0]") == 0 &&
+                   mlt_properties_get_value( properties, i )) {
                        float val[3];
                        char *name_copy = strdup(name);
                        char *index_char = name_copy + strlen(name_copy) - 2;
@@ -279,12 +308,13 @@ static void set_movit_parameters( GlslChain *chain, mlt_service service, mlt_fra
                        *index_char = '2';
                        val[2] = mlt_properties_get_double( properties, name_copy );
                        index_char[-1] = '\0';
-                       bool ok = effect->set_vec3(name_copy + strlen("movit.parms.vec3."), val);
+                       bool ok = effect->set_vec3(name_copy + strlen("_movit.parms.vec3."), val);
                        assert(ok);
                        free(name_copy);
                }
-               if (strncmp(name, "movit.parms.vec4.", strlen("movit.parms.vec4.")) == 0 &&
-                   strcmp(name + strlen(name) - 3, "[0]") == 0) {
+               if (strncmp(name, "_movit.parms.vec4.", strlen("_movit.parms.vec4.")) == 0 &&
+                   strcmp(name + strlen(name) - 3, "[0]") == 0 &&
+                   mlt_properties_get_value( properties, i )) {
                        float val[4];
                        char *name_copy = strdup(name);
                        char *index_char = name_copy + strlen(name_copy) - 2;
@@ -296,29 +326,35 @@ static void set_movit_parameters( GlslChain *chain, mlt_service service, mlt_fra
                        *index_char = '3';
                        val[3] = mlt_properties_get_double( properties, name_copy );
                        index_char[-1] = '\0';
-                       bool ok = effect->set_vec4(name_copy + strlen("movit.parms.vec4."), val);
+                       bool ok = effect->set_vec4(name_copy + strlen("_movit.parms.vec4."), val);
                        assert(ok);
                        free(name_copy);
                }
        }
 }
 
-static void dispose_pixel_pointers( mlt_service service, mlt_frame frame )
+static void dispose_pixel_pointers( GlslChain *chain, mlt_service service, mlt_frame frame )
 {
        if ( service == (mlt_service) -1 ) {
                mlt_producer producer = mlt_producer_cut_parent( mlt_frame_get_original_producer( frame ) );
+               MltInput* input = chain->inputs[ producer ];
+               input->invalidate_pixel_data();
                mlt_pool_release( GlslManager::get_input_pixel_pointer( producer, frame ) );
                return;
        }
 
        mlt_service input_a = GlslManager::get_effect_input( service, frame );
-       dispose_pixel_pointers( input_a, frame );
+       dispose_pixel_pointers( chain, input_a, frame );
 
        mlt_service input_b;
        mlt_frame frame_b;
        GlslManager::get_effect_secondary_input( service, frame, &input_b, &frame_b );
        if ( input_b ) {
-               dispose_pixel_pointers( input_b, frame_b );
+               dispose_pixel_pointers( chain, input_b, frame_b );
+       }
+       GlslManager::get_effect_third_input( service, frame, &input_b, &frame_b );
+       if ( input_b ) {
+               dispose_pixel_pointers( chain, input_b, frame_b );
        }
 }
 
@@ -342,7 +378,7 @@ static int movit_render( EffectChain *chain, mlt_frame frame, mlt_image_format *
 // Create an MltInput for an image with the given format and dimensions.
 static MltInput* create_input( mlt_properties properties, mlt_image_format format, int aspect_width, int aspect_height, int width, int height )
 {
-       MltInput* input = new MltInput( aspect_width, aspect_height );
+       MltInput* input = new MltInput();
        if ( format == mlt_image_rgb24a || format == mlt_image_opengl ) {
                // TODO: Get the color space if available.
                input->useFlatInput( FORMAT_RGBA_POSTMULTIPLIED_ALPHA, width, height );
@@ -438,7 +474,7 @@ static int convert_image( mlt_frame frame, uint8_t **image, mlt_image_format *fo
 
                error = movit_render( chain->effect_chain, frame, format, output_format, width, height, image );
 
-               dispose_pixel_pointers( leaf_service, frame );
+               dispose_pixel_pointers( chain, leaf_service, frame );
        }
 
        // If we've been asked to render some frame directly to a texture (without any
@@ -462,9 +498,9 @@ static int convert_image( mlt_frame frame, uint8_t **image, mlt_image_format *fo
                        int h = producer.get_int( "movit.convert.height" );
                        mlt_image_format f = (mlt_image_format) producer.get_int( "movit.convert.format" );
                        if ( !chain || !input || width != w || height != h || *format != f ) {
-                               chain = new EffectChain( width, height );
+                               chain = new EffectChain( width, height, GlslManager::get_instance()->get_resource_pool() );
                                input = create_input( properties, *format, width, height, width, height );
-                               chain->add_input( input );
+                               chain->add_input( input->get_input() );
                                chain->add_effect( new Mlt::VerticalFlip() );
                                ImageFormat movit_output_format;
                                movit_output_format.color_space = COLORSPACE_sRGB;
@@ -547,6 +583,8 @@ mlt_filter filter_movit_convert_init( mlt_profile profile, mlt_service_type type
 
        if ( glsl && ( filter = mlt_filter_new() ) )
        {
+               mlt_properties properties = MLT_FILTER_PROPERTIES( filter );
+               glsl->add_ref( properties );
 #ifdef WIN32
                // XXX avcolor_space is crashing on Windows in this context!
                mlt_filter cpu_csc = NULL;