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>
25 extern void refresh_kdenlivetitle( mlt_producer producer, uint8_t*, int, int, double, int );
27 void read_xml(mlt_properties properties)
29 FILE *f = fopen( mlt_properties_get( properties, "resource" ), "r");
35 fseek (f , 0 , SEEK_END);
39 char *infile = (char*) mlt_pool_alloc(lSize);
40 size=fread(infile,1,lSize,f);
43 mlt_properties_set(properties, "xmldata", infile);
44 mlt_pool_release( infile );
48 static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_format *format, int *width, int *height, int writable )
50 /* Obtain properties of frame */
51 mlt_properties properties = MLT_FRAME_PROPERTIES( frame );
53 /* Obtain the producer for this frame */
54 mlt_producer producer = mlt_properties_get_data( properties, "producer_kdenlivetitle", NULL );
56 /* Obtain properties of producer */
57 mlt_properties producer_props = MLT_PRODUCER_PROPERTIES( producer );
59 *width = mlt_properties_get_int( properties, "width" );
60 *height = mlt_properties_get_int( properties, "height" );
62 /* Allocate the image */
63 int size = *width * ( *height ) * 4;
65 *buffer = mlt_pool_alloc( size );
67 mlt_properties_set_int( properties, "width", *width );
68 mlt_properties_set_int( properties, "height", *height );
74 /* Allocate the image */
75 *format = mlt_image_rgb24a;
76 mlt_position in = mlt_producer_get_in( producer );
77 mlt_position out = mlt_producer_get_out( producer );
78 mlt_position time = mlt_producer_position( producer );
79 double position = ( double )( time - in ) / ( double )( out - in + 1 );
80 if ( mlt_properties_get_int( producer_props, "force_reload" ) ) {
81 if (mlt_properties_get_int( producer_props, "force_reload" ) > 1) read_xml(producer_props);
82 mlt_properties_set_int( producer_props, "force_reload", 0 );
83 refresh_kdenlivetitle( producer, *buffer, *width, *height, position, 1);
85 else refresh_kdenlivetitle( producer, *buffer, *width, *height, position, 0);
86 /* Update the frame */
87 mlt_properties_set_data( properties, "image", *buffer, size, mlt_pool_release, NULL );
89 mlt_log_debug( MLT_PRODUCER_SERVICE( producer ), "width:%d height:%d %s\n", *width, *height, mlt_image_format_name( *format ) );
95 static int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int index )
99 /* Generate a frame */
100 *frame = mlt_frame_init( MLT_PRODUCER_SERVICE( producer ) );
102 if ( *frame != NULL )
104 /* Obtain properties of frame and producer */
105 mlt_properties properties = MLT_FRAME_PROPERTIES( *frame );
107 /* Obtain properties of producer */
108 mlt_properties producer_props = MLT_PRODUCER_PROPERTIES( producer );
110 /* Set the producer on the frame properties */
111 mlt_properties_set_data( properties, "producer_kdenlivetitle", producer, 0, NULL, NULL );
113 /* Update timecode on the frame we're creating */
114 mlt_frame_set_position( *frame, mlt_producer_position( producer ) );
116 /* Set producer-specific frame properties */
117 mlt_properties_set_int( properties, "progressive", 1 );
118 mlt_properties_set_double( properties, "aspect_ratio", mlt_properties_get_double( producer_props, "aspect_ratio" ) );
120 /* Push the get_image method */
121 mlt_frame_push_get_image( *frame, producer_get_image );
124 /* Calculate the next timecode */
125 mlt_producer_prepare_next( producer );
130 static void producer_close( mlt_producer producer )
132 /* fprintf(stderr, ":::::::::::::: CLOSING TITLE\n"); */
133 producer->close = NULL;
134 mlt_producer_close( producer );
139 mlt_producer producer_kdenlivetitle_init( mlt_profile profile, mlt_service_type type, const char *id, char *filename )
141 /* fprintf(stderr, ":::::::::::: CREATE TITLE\n"); */
142 /* Create a new producer object */
144 mlt_producer producer = calloc( 1, sizeof( struct mlt_producer_s ) );
145 if ( producer != NULL && mlt_producer_init( producer, NULL ) == 0 )
147 /* Get the properties interface */
148 mlt_properties properties = MLT_PRODUCER_PROPERTIES( producer );
149 /* Callback registration */
150 producer->get_frame = producer_get_frame;
151 producer->close = ( mlt_destructor )producer_close;
152 mlt_properties_set( properties, "resource", filename );
153 //mlt_properties_set_int( properties, "aspect_ratio", 1 );
154 read_xml(properties);