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;
}
{
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;
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 );
{
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;
}
{
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;
// 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 );
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;
#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)
#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