2 * producer_kdenlivetitle.c -- kdenlive producer
3 * Copyright (c) 2009 Marco Gittler <g.marco@freenet.de>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 #include <framework/mlt.h>
24 extern void init_qt();
26 extern void refresh_kdenlivetitle( uint8_t*, int, int, double, char*, char*, int );
28 static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_format *format, int *width, int *height, int writable )
31 // Obtain properties of frame
32 mlt_properties properties = MLT_FRAME_PROPERTIES( frame );
34 // Obtain the producer for this frame
35 mlt_producer producer = mlt_properties_get_data( properties, "producer_kdenlivetitle", NULL );
37 // Obtain properties of producer
38 mlt_properties producer_props = MLT_PRODUCER_PROPERTIES( producer );
41 int size = *width * ( *height ) * 4;
43 *buffer = mlt_pool_alloc( size );
45 mlt_properties_set_int( properties, "width", *width );
46 mlt_properties_set_int( properties, "height", *height );
49 mlt_properties_set_data( properties, "image", *buffer, size, mlt_pool_release, NULL );
55 *format = mlt_image_rgb24a;
56 mlt_position in = mlt_producer_get_in( producer );
57 mlt_position out = mlt_producer_get_out( producer );
58 mlt_position time = mlt_producer_position( producer );
59 double position = ( double )( time - in ) / ( double )( out - in + 1 );
60 fprintf(stderr, "TITLE POS: %dx%d = %d\n", (int)in, (int)out, (int) time);
61 if ( mlt_properties_get_int( producer_props, "force_reload" ) ) {
62 refresh_kdenlivetitle( *buffer, *width, *height, position, mlt_properties_get( producer_props, "xmldata" ), mlt_properties_get( producer_props, "templatetext" ), 1);
63 mlt_properties_set_int( producer_props, "force_reload", 0 );
65 else refresh_kdenlivetitle( *buffer, *width, *height, position, mlt_properties_get( producer_props, "xmldata" ), mlt_properties_get( producer_props, "templatetext" ), 0);
66 mlt_log_debug( MLT_PRODUCER_SERVICE( producer ), "width:%d height:%d %s\n", *width, *height, mlt_image_format_name( *format ) );
72 int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int index )
77 *frame = mlt_frame_init( MLT_PRODUCER_SERVICE( producer ) );
81 // Obtain properties of frame and producer
82 mlt_properties properties = MLT_FRAME_PROPERTIES( *frame );
84 // Obtain properties of producer
85 mlt_properties producer_props = MLT_PRODUCER_PROPERTIES( producer );
87 // Set the producer on the frame properties
88 mlt_properties_set_data( properties, "producer_kdenlivetitle", producer, 0, NULL, NULL );
90 // Update timecode on the frame we're creating
91 mlt_frame_set_position( *frame, mlt_producer_position( producer ) );
93 // Set producer-specific frame properties
94 mlt_properties_set_int( properties, "progressive", 1 );
95 mlt_properties_set_double( properties, "aspect_ratio", mlt_properties_get_double( producer_props, "aspect_ratio" ) );
97 // Push the get_image method
98 mlt_frame_push_get_image( *frame, producer_get_image );
101 // Calculate the next timecode
102 mlt_producer_prepare_next( producer );
107 void producer_close( mlt_producer producer )
109 producer->close = NULL;
110 mlt_producer_close( producer );
115 mlt_producer producer_kdenlivetitle_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg )
117 // Create a new producer object
118 mlt_producer this = mlt_producer_new( );
120 // Initialise the producer
125 // Callback registration
126 this->get_frame = producer_get_frame;
127 this->close = ( mlt_destructor ) producer_close;
128 mlt_properties properties = MLT_PRODUCER_PROPERTIES( this );
129 mlt_properties_set( properties, "resource", arg );