2 * MltPushConsumer.cpp - MLT Wrapper
3 * Copyright (C) 2004-2005 Charles Yates
4 * Author: Charles Yates <charles.yates@pandora.be>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published
8 * by the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 #include "MltPushConsumer.h"
22 #include "MltFilter.h"
36 static void filter_destructor( void *arg
)
38 Filter
*filter
= ( Filter
* )arg
;
42 PushConsumer
::PushConsumer( Profile
& profile
, char *id
, char *service
) :
43 Consumer( profile
, id
, service
),
44 m_private( new PushPrivate( ) )
48 // Set up push mode (known as put mode in mlt)
49 set( "real_time", 0 );
51 set( "terminate_on_pause", 0 );
54 // We might need resize and rescale filters so we'll create them now
55 // NB: Try to use the best rescaler available here
56 Filter
*resize
= new Filter( profile
, "resize" );
57 Filter
*rescale
= new Filter( profile
, "mcrescale" );
58 if ( !rescale
->is_valid( ) )
61 rescale
= new Filter( profile
, "gtkrescale" );
63 if ( !rescale
->is_valid( ) )
66 rescale
= new Filter( profile
, "rescale" );
69 Filter
*convert
= new Filter( profile
, "avcolour_space" );
71 set( "filter_convert", convert
, 0, filter_destructor
);
72 set( "filter_resize", resize
, 0, filter_destructor
);
73 set( "filter_rescale", rescale
, 0, filter_destructor
);
77 PushConsumer
::~PushConsumer( )
81 void PushConsumer
::set_render( int width
, int height
, double aspect_ratio
)
83 set( "render_width", width
);
84 set( "render_height", height
);
85 set( "render_aspect_ratio", aspect_ratio
);
88 int PushConsumer
::connect( Service
&/*service*/ )
93 int PushConsumer
::push( Frame
*frame
)
97 // Here we have the option to process the frame at a render resolution (this will
98 // typically be PAL or NTSC) prior to scaling according to the consumers profile
99 // This is done to optimise quality, esp. with regard to compositing positions
100 if ( get_int( "render_width" ) )
102 // Process the projects render resolution first
103 mlt_image_format format
= mlt_image_yuv422
;
104 int w
= get_int( "render_width" );
105 int h
= get_int( "render_height" );
106 frame
->set( "consumer_aspect_ratio", get_double( "render_aspect_ratio" ) );
107 frame
->set( "consumer_deinterlace", get_int( "deinterlace" ) );
108 frame
->set( "deinterlace_method", get_int( "deinterlace_method" ) );
109 frame
->set( "rescale.interp", get( "rescale" ) );
112 frame
->get_image( format
, w
, h
);
114 // Now set up the post image scaling
115 Filter
*convert
= ( Filter
* )get_data( "filter_convert" );
116 mlt_filter_process( convert
->get_filter( ), frame
->get_frame( ) );
117 Filter
*rescale
= ( Filter
* )get_data( "filter_rescale" );
118 mlt_filter_process( rescale
->get_filter( ), frame
->get_frame( ) );
119 Filter
*resize
= ( Filter
* )get_data( "filter_resize" );
120 mlt_filter_process( resize
->get_filter( ), frame
->get_frame( ) );
123 return mlt_consumer_put_frame( ( mlt_consumer
)get_service( ), frame
->get_frame( ) );
126 int PushConsumer
::push( Frame
&frame
)
128 return push( &frame
);
131 int PushConsumer
::drain( )
136 // Convenience function - generates a frame with an image of a given size
137 Frame
*PushConsumer
::construct( int size
)
139 mlt_frame f
= mlt_frame_init( get_service() );
140 Frame
*frame
= new Frame( f
);
141 uint8_t *buffer
= ( uint8_t * )mlt_pool_alloc( size
);
142 frame
->set( "image", buffer
, size
, mlt_pool_release
);
143 mlt_frame_close( f
);