From f62c1e7c174cbbfb291aa6aa788f951bca311fc0 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Tue, 28 Jan 2014 20:00:35 +0100 Subject: [PATCH] Take MltInput out of the EffectChain. 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 | 7 +++ src/modules/opengl/filter_glsl_manager.h | 4 ++ src/modules/opengl/filter_movit_convert.cpp | 14 ++--- src/modules/opengl/mlt_movit_input.cpp | 59 +-------------------- src/modules/opengl/mlt_movit_input.h | 24 ++------- 5 files changed, 24 insertions(+), 84 deletions(-) diff --git a/src/modules/opengl/filter_glsl_manager.cpp b/src/modules/opengl/filter_glsl_manager.cpp index 100c3ab1..a276f08b 100644 --- a/src/modules/opengl/filter_glsl_manager.cpp +++ b/src/modules/opengl/filter_glsl_manager.cpp @@ -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::iterator input_it = chain->inputs.begin(); + input_it != chain->inputs.end(); + ++input_it) { + delete input_it->second; + } delete chain->effect_chain; delete chain; } diff --git a/src/modules/opengl/filter_glsl_manager.h b/src/modules/opengl/filter_glsl_manager.h index 673c52c9..dff1b0c7 100644 --- a/src/modules/opengl/filter_glsl_manager.h +++ b/src/modules/opengl/filter_glsl_manager.h @@ -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 inputs; + // All services owned by the effect chain and their associated Movit effect. std::map effects; diff --git a/src/modules/opengl/filter_movit_convert.cpp b/src/modules/opengl/filter_movit_convert.cpp index 3f7b5879..76437437 100644 --- a/src/modules/opengl/filter_movit_convert.cpp +++ b/src/modules/opengl/filter_movit_convert.cpp @@ -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; diff --git a/src/modules/opengl/mlt_movit_input.cpp b/src/modules/opengl/mlt_movit_input.cpp index 59306be4..11f44bf3 100644 --- a/src/modules/opengl/mlt_movit_input.cpp +++ b/src/modules/opengl/mlt_movit_input.cpp @@ -19,69 +19,14 @@ #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) diff --git a/src/modules/opengl/mlt_movit_input.h b/src/modules/opengl/mlt_movit_input.h index 16bed620..df8b36ec 100644 --- a/src/modules/opengl/mlt_movit_input.h +++ b/src/modules/opengl/mlt_movit_input.h @@ -24,40 +24,24 @@ #include #include -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 -- 2.39.2