]> git.sesse.net Git - mlt/commitdiff
+ Added a push based consumer wrapper
authorlilo_booter <lilo_booter@d19143bc-622f-0410-bfdd-b5b2a6649095>
Wed, 28 Sep 2005 14:00:34 +0000 (14:00 +0000)
committerlilo_booter <lilo_booter@d19143bc-622f-0410-bfdd-b5b2a6649095>
Wed, 28 Sep 2005 14:00:34 +0000 (14:00 +0000)
git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt++@834 d19143bc-622f-0410-bfdd-b5b2a6649095

mlt++/src/Makefile
mlt++/src/Mlt.h
mlt++/src/MltPushConsumer.cpp [new file with mode: 0644]
mlt++/src/MltPushConsumer.h [new file with mode: 0644]

index 33ebef3a03faa335065f68ed9a808a7e12a8d236..9c1cbb32b4113122b5ce0f6029ba419425678a64 100644 (file)
@@ -20,6 +20,7 @@ OBJS = MltConsumer.o \
           MltPlaylist.o \
           MltProducer.o \
           MltProperties.o \
+          MltPushConsumer.o \
           MltResponse.o \
           MltService.o \
           MltTokeniser.o \
index b30a8ad1e2cd63998ff1859a5041a4e239560d8e..17621c8839ba48c86ef7601a677f99d1cf598306 100644 (file)
@@ -36,6 +36,7 @@
 #include "MltPlaylist.h"
 #include "MltProducer.h"
 #include "MltProperties.h"
+#include "MltPushConsumer.h"
 #include "MltResponse.h"
 #include "MltService.h"
 #include "MltTokeniser.h"
diff --git a/mlt++/src/MltPushConsumer.cpp b/mlt++/src/MltPushConsumer.cpp
new file mode 100644 (file)
index 0000000..5c70777
--- /dev/null
@@ -0,0 +1,145 @@
+/**
+ * MltPushConsumer.cpp - MLT Wrapper
+ * Copyright (C) 2004-2005 Charles Yates
+ * Author: Charles Yates <charles.yates@pandora.be>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "MltPushConsumer.h"
+#include "MltFilter.h"
+using namespace Mlt;
+
+namespace Mlt
+{
+       class PushPrivate
+       {
+               public:
+                       PushPrivate( )
+                       {
+                       }
+       };
+}
+
+static void filter_destructor( void *arg )
+{
+       Filter *filter = ( Filter * )arg;
+       delete filter;
+}
+
+PushConsumer::PushConsumer( char *id , char *service ) :
+       Consumer( id, service ),
+       m_private( new PushPrivate( ) )
+{
+       if ( is_valid( ) )
+       {
+               // Set up push mode (known as put mode in mlt)
+               set( "real_time", 0 );
+               set( "put_mode", 1 );
+               set( "terminate_on_pause", 0 );
+               set( "buffer", 0 );
+
+               // We might need resize and rescale filters so we'll create them now
+               // NB: Try to use the best rescaler available here
+               Filter *resize = new Filter( "resize" );
+               Filter *rescale = new Filter( "mcrescale" );
+               if ( !rescale->is_valid( ) )
+               {
+                       delete rescale;
+                       rescale = new Filter( "gtkrescale" );
+               }
+               if ( !rescale->is_valid( ) )
+               {
+                       delete rescale;
+                       rescale = new Filter( "rescale" );
+               }
+
+               Filter *convert = new Filter( "avcolour_space" );
+
+               set( "filter_convert", convert, 0, filter_destructor );
+               set( "filter_resize", resize, 0, filter_destructor );
+               set( "filter_rescale", rescale, 0, filter_destructor );
+       }
+}
+
+PushConsumer::~PushConsumer( )
+{
+}
+
+void PushConsumer::set_render( int width, int height, double aspect_ratio )
+{
+       set( "render_width", width );
+       set( "render_height", height );
+       set( "render_aspect_ratio", aspect_ratio );
+}
+
+int PushConsumer::connect( Service &service )
+{
+       return -1;
+}
+
+int PushConsumer::push( Frame *frame )
+{
+       frame->inc_ref( );
+
+       // Here we have the option to process the frame at a render resolution (this will 
+       // typically be PAL or NTSC) prior to scaling according to the consumers profile
+       // This is done to optimise quality, esp. with regard to compositing positions 
+       if ( get_int( "render_width" ) )
+       {
+               // Process the projects render resolution first
+               mlt_image_format format = mlt_image_yuv422;
+               int w = get_int( "render_width" );
+               int h = get_int( "render_height" );
+               frame->set( "consumer_aspect_ratio", get_double( "render_aspect_ratio" ) );
+               frame->set( "consumer_deinterlace", get_int( "deinterlace" ) );
+               frame->set( "deinterlace_method", get_int( "deinterlace_method" ) );
+               frame->set( "rescale.interp", get( "rescale" ) );
+
+               // Render the frame
+               frame->get_image( format, w, h );
+
+               // Now set up the post image scaling
+               Filter *convert = ( Filter * )get_data( "filter_convert" );
+               mlt_filter_process( convert->get_filter( ), frame->get_frame( ) );
+               Filter *rescale = ( Filter * )get_data( "filter_rescale" );
+               mlt_filter_process( rescale->get_filter( ), frame->get_frame( ) );
+               Filter *resize = ( Filter * )get_data( "filter_resize" );
+               mlt_filter_process( resize->get_filter( ), frame->get_frame( ) );
+       }
+
+       return mlt_consumer_put_frame( ( mlt_consumer )get_service( ), frame->get_frame( ) );
+}
+
+int PushConsumer::push( Frame &frame )
+{
+       return push( &frame );
+}
+
+int PushConsumer::drain( )
+{
+       return 0;
+}
+
+// Convenience function - generates a frame with an image of a given size
+Frame *PushConsumer::construct( int size )
+{
+       mlt_frame f = mlt_frame_init( );
+       Frame *frame = new Frame( f );
+       uint8_t *buffer = ( uint8_t * )mlt_pool_alloc( size );
+       frame->set( "image", buffer, size, mlt_pool_release );
+       return frame;
+}
+
diff --git a/mlt++/src/MltPushConsumer.h b/mlt++/src/MltPushConsumer.h
new file mode 100644 (file)
index 0000000..abb8a3c
--- /dev/null
@@ -0,0 +1,48 @@
+/**
+ * MltPushConsumer.h - MLT Wrapper
+ * Copyright (C) 2004-2005 Charles Yates
+ * Author: Charles Yates <charles.yates@pandora.be>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef MLTPP_PUSH_CONSUMER_H
+#define MLTPP_PUSH_CONSUMER_H
+
+#include "MltConsumer.h"
+
+namespace Mlt
+{
+       class Frame;
+       class Service;
+       class PushPrivate;
+
+       class PushConsumer : public Consumer
+       {
+               private:
+                       PushPrivate *m_private;
+               public:
+                       PushConsumer( char *id , char *service = NULL );
+                       virtual ~PushConsumer( );
+                       void set_render( int width, int height, double aspect_ratio );
+                       virtual int connect( Service &service );
+                       int push( Frame *frame );
+                       int push( Frame &frame );
+                       int drain( );
+                       Frame *construct( int );
+       };
+}
+
+#endif