]> git.sesse.net Git - mlt/blob - src/modules/frei0r/producer_frei0r.c
7e24be456582b3ad20bc8cba8489cdd9b693511d
[mlt] / src / modules / frei0r / producer_frei0r.c
1 /*
2  * producer_frei0r.c -- frei0r producer
3  * Copyright (c) 2009 Jean-Baptiste Mardelle <jb@kdenlive.org>
4  *
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.
9  *
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.
14  *
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  */
19
20 #include <framework/mlt.h>
21
22 #include "frei0r_helper.h"
23
24 #include <stdlib.h>
25 #include <string.h>
26
27 static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_format *format, int *width, int *height, int writable )
28 {
29         
30         // Obtain properties of frame
31         mlt_properties properties = MLT_FRAME_PROPERTIES( frame );
32
33         // Obtain the producer for this frame
34         mlt_producer producer = mlt_properties_get_data( properties, "producer_frei0r", NULL );
35
36         // Obtain properties of producer
37         mlt_properties producer_props = MLT_PRODUCER_PROPERTIES( producer );
38
39         // Choose suitable out values if nothing specific requested
40         if ( *width <= 0 )
41                 *width = mlt_service_profile( MLT_PRODUCER_SERVICE(producer) )->width;
42         if ( *height <= 0 )
43                 *height = mlt_service_profile( MLT_PRODUCER_SERVICE(producer) )->height;
44
45         // Allocate the image
46         int size = *width * ( *height + 1 ) * 4;
47
48         // Allocate the image
49         *buffer = mlt_pool_alloc( size );
50
51         // Update the frame
52         mlt_frame_set_image( frame, *buffer, size, mlt_pool_release );
53
54         *format = mlt_image_rgb24a;
55         if ( *buffer != NULL )
56         {
57                 double position = mlt_frame_get_position( frame );
58                 mlt_profile profile = mlt_service_profile( MLT_PRODUCER_SERVICE( producer ) );
59                 double time = position / mlt_profile_fps( profile );
60                 process_frei0r_item( MLT_PRODUCER_SERVICE(producer), position, time, producer_props, frame, buffer, width, height );
61         }
62
63     return 0;
64 }
65
66 int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int index )
67 {
68         // Generate a frame
69         *frame = mlt_frame_init( MLT_PRODUCER_SERVICE( producer ) );
70
71         if ( *frame != NULL )
72         {
73                 // Obtain properties of frame and producer
74                 mlt_properties properties = MLT_FRAME_PROPERTIES( *frame );
75
76                 // Obtain properties of producer
77                 mlt_properties producer_props = MLT_PRODUCER_PROPERTIES( producer );
78
79                 // Set the producer on the frame properties
80                 mlt_properties_set_data( properties, "producer_frei0r", producer, 0, NULL, NULL );
81
82                 // Update timecode on the frame we're creating
83                 mlt_frame_set_position( *frame, mlt_producer_position( producer ) );
84
85                 // Set producer-specific frame properties
86                 mlt_properties_set_int( properties, "progressive", 1 );
87                 mlt_profile profile = mlt_service_profile( MLT_PRODUCER_SERVICE( producer ) );
88                 mlt_properties_set_double( properties, "aspect_ratio", mlt_profile_sar( profile ) );
89
90                 // Push the get_image method
91                 mlt_frame_push_get_image( *frame, producer_get_image );
92         }
93
94         // Calculate the next timecode
95         mlt_producer_prepare_next( producer );
96
97         return 0;
98 }
99
100 void producer_close( mlt_producer producer )
101 {
102         producer->close = NULL;
103         mlt_producer_close( producer );
104         free( producer );
105 }