]> git.sesse.net Git - mlt/commitdiff
Take MltInput out of the EffectChain.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Tue, 28 Jan 2014 19:00:35 +0000 (20:00 +0100)
committerDan Dennedy <dan@dennedy.org>
Thu, 30 Jan 2014 05:12:10 +0000 (21:12 -0800)
Having the MltInput be an Input which forwards down to the real implementation
has been a source of multiple headaches, and now lastly, when finalize()
disappeared, source of a broken build. We still need the unified
set_pixel_pointer() etc., but the class is now simply a holder of the Input*,
not a forwarder as viewed from the EffectChain.

src/modules/opengl/filter_glsl_manager.cpp
src/modules/opengl/filter_glsl_manager.h
src/modules/opengl/filter_movit_convert.cpp
src/modules/opengl/mlt_movit_input.cpp
src/modules/opengl/mlt_movit_input.h

index 100c3ab1ac420c7a2906872852178a5ed2d987fc..a276f08b1cde5e7c764aeab76e9f5f2e509b50d0 100644 (file)
@@ -326,6 +326,13 @@ mlt_filter filter_glsl_manager_init( mlt_profile profile, mlt_service_type type,
 
 static void deleteChain( GlslChain* chain )
 {
+       // The Input* is owned by the EffectChain, but the MltInput* is not.
+       // Thus, we have to delete it here.
+       for (std::map<mlt_producer, MltInput*>::iterator input_it = chain->inputs.begin();
+            input_it != chain->inputs.end();
+            ++input_it) {
+               delete input_it->second;
+       }
        delete chain->effect_chain;
        delete chain;
 }
index 673c52c96973756043d7eb1951dc021a203758f4..dff1b0c70d56a53d265535ffcf088602b715d7cd 100644 (file)
@@ -75,6 +75,10 @@ struct GlslChain
 {
        EffectChain *effect_chain;
 
+       // All MltInputs in the effect chain. These are not owned by the
+       // EffectChain (although the contained Input* is).
+       std::map<mlt_producer, MltInput*> inputs;
+
        // All services owned by the effect chain and their associated Movit effect.
        std::map<mlt_service, Effect*> effects;
 
index 3f7b587976eb5220773120bdd6d8f24beaf97d4a..764374379fa07e9ac9917e1ebdc8c5bc41e3bf3f 100644 (file)
@@ -152,9 +152,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 );
@@ -242,7 +242,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;
        }
@@ -311,7 +311,7 @@ static void dispose_pixel_pointers( GlslChain *chain, mlt_service service, mlt_f
 {
        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->invalidate_pixel_data();
                mlt_pool_release( GlslManager::get_input_pixel_pointer( producer, frame ) );
                return;
@@ -348,7 +348,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 );
@@ -470,7 +470,7 @@ static int convert_image( mlt_frame frame, uint8_t **image, mlt_image_format *fo
                        if ( !chain || !input || width != w || height != h || *format != f ) {
                                chain = new EffectChain( width, height );
                                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;
index 59306be4474cfd9c8feb84170e3877b11265812f..11f44bf37cdd3bd26f240f23eec07253d9b40afe 100644 (file)
 
 #include "mlt_movit_input.h"
 
-MltInput::MltInput(unsigned width, unsigned height)
-       : m_width(width)
-       , m_height(height)
-       , output_linear_gamma(false)
-       , needs_mipmaps(false)
-       , input(0)
+MltInput::MltInput()
+       : input(0)
        , isRGB(true)
-       , m_chain(NULL)
 {
-       register_int("output_linear_gamma", &output_linear_gamma);
-       register_int("needs_mipmaps", &needs_mipmaps);
 }
 
 MltInput::~MltInput()
 {
-       // XXX: this is crashing when a producer is closed
-       // on Windows when using melt with qglsl.
-//     delete input;
-}
-
-std::string MltInput::output_fragment_shader()
-{
-       assert(input);
-       return input->output_fragment_shader();
-}
-
-void MltInput::set_gl_state(GLuint glsl_program_num, const std::string& prefix, unsigned *sampler_num)
-{
-       assert(input);
-       input->set_gl_state(glsl_program_num, prefix, sampler_num);
-}
-
-Effect::AlphaHandling MltInput::alpha_handling() const
-{
-       assert(input);
-       return input->alpha_handling();
-}
-
-void MltInput::finalize()
-{
-       assert(input);
-       bool ok = input->set_int("output_linear_gamma", output_linear_gamma);
-       ok |= input->set_int("needs_mipmaps", needs_mipmaps);
-       assert(ok);
-       input->inform_added(m_chain);
-       input->finalize();
-}
-
-bool MltInput::can_output_linear_gamma() const
-{
-       assert(input);
-       return input->can_output_linear_gamma();
-}
-
-Colorspace MltInput::get_color_space() const
-{
-       assert(input);
-       return input->get_color_space();
-}
-GammaCurve MltInput::get_gamma_curve() const
-{
-       assert(input);
-       return input->get_gamma_curve();
 }
 
 void MltInput::useFlatInput(MovitPixelFormat pix_fmt, unsigned width, unsigned height)
index 16bed6200d14e080511a23c79564d981baa77728..df8b36ec6ade61b024e535a5e573d0f3ff864068 100644 (file)
 #include <movit/ycbcr_input.h>
 #include <movit/effect_chain.h>
 
-class MltInput : public Input
+class MltInput
 {
 public:
-       MltInput(unsigned width, unsigned height);
+       MltInput();
        ~MltInput();
 
-       // Effect overrides
-       std::string effect_type_id() const { return "MltInput"; }
-       Effect::AlphaHandling alpha_handling() const;
-       std::string output_fragment_shader();
-       void set_gl_state(GLuint glsl_program_num, const std::string& prefix, unsigned *sampler_num);
-       void inform_added(EffectChain *chain) { m_chain = chain; }
-
-       // Input ovverrides
-       void finalize();
-       bool can_output_linear_gamma() const;
-       unsigned get_width() const { return m_width; }
-       unsigned get_height() const { return m_height; }
-       Colorspace get_color_space() const;
-       GammaCurve get_gamma_curve() const;
-
-       // Custom methods
        void useFlatInput(MovitPixelFormat pix_fmt, unsigned width, unsigned height);
        void useYCbCrInput(const ImageFormat& image_format, const YCbCrFormat& ycbcr_format, unsigned width, unsigned height);
        void set_pixel_data(const unsigned char* data);
        void invalidate_pixel_data();
+       Input *get_input() { return input; }
 
 private:
        unsigned m_width, m_height;
-       int output_linear_gamma, needs_mipmaps;
+       // Note: Owned by the EffectChain, so should not be deleted by us.
        Input *input;
        bool isRGB;
        YCbCrFormat m_ycbcr_format;
-       EffectChain *m_chain;
 };
 
 #endif // MLT_MOVIT_INPUT_H