Defaults for PAL/NTSC on producers and consumers
[melted] / src / framework / mlt_consumer.c
1 /*
2 * mlt_consumer.c -- abstraction for all consumer services
3 * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
4 * Author: Charles Yates <charles.yates@pandora.be>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
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.
15 *
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.
19 */
20
21 #include "config.h"
22 #include "mlt_consumer.h"
23 #include "mlt_factory.h"
24 #include "mlt_producer.h"
25 #include "mlt_frame.h"
26 #include <stdio.h>
27 #include <string.h>
28 #include <stdlib.h>
29
30 /** Public final methods
31 */
32
33 int mlt_consumer_init( mlt_consumer this, void *child )
34 {
35 int error = 0;
36 memset( this, 0, sizeof( struct mlt_consumer_s ) );
37 this->child = child;
38 error = mlt_service_init( &this->parent, this );
39 if ( error == 0 )
40 {
41 // Get the properties from the service
42 mlt_properties properties = mlt_service_properties( &this->parent );
43
44 // Get the normalisation preference
45 char *normalisation = getenv( "MLT_NORMALISATION" );
46
47 // Deal with normalisation
48 if ( normalisation == NULL || strcmp( normalisation, "NTSC" ) )
49 {
50 mlt_properties_set( properties, "normalisation", "PAL" );
51 mlt_properties_set_double( properties, "fps", 25.0 );
52 mlt_properties_set_int( properties, "width", 720 );
53 mlt_properties_set_int( properties, "height", 576 );
54 }
55 else
56 {
57 mlt_properties_set( properties, "normalisation", "NTSC" );
58 mlt_properties_set_double( properties, "fps", 30000.0 / 1001.0 );
59 mlt_properties_set_int( properties, "width", 720 );
60 mlt_properties_set_int( properties, "height", 480 );
61 }
62
63 // Default rescaler for all consumers
64 mlt_properties_set( properties, "rescale", "bilinear" );
65 }
66 return error;
67 }
68
69 /** Get the parent service object.
70 */
71
72 mlt_service mlt_consumer_service( mlt_consumer this )
73 {
74 return &this->parent;
75 }
76
77 /** Get the consumer properties.
78 */
79
80 mlt_properties mlt_consumer_properties( mlt_consumer this )
81 {
82 return mlt_service_properties( &this->parent );
83 }
84
85 /** Connect the consumer to the producer.
86 */
87
88 int mlt_consumer_connect( mlt_consumer this, mlt_service producer )
89 {
90 return mlt_service_connect_producer( &this->parent, producer, 0 );
91 }
92
93 /** Start the consumer.
94 */
95
96 int mlt_consumer_start( mlt_consumer this )
97 {
98 // Get the properies
99 mlt_properties properties = mlt_consumer_properties( this );
100
101 // Determine if there's a test card producer
102 char *test_card = mlt_properties_get( properties, "test_card" );
103
104 // Deal with it now.
105 if ( test_card != NULL )
106 {
107 // Create a test card producer
108 mlt_producer producer = mlt_factory_producer( "fezzik", test_card );
109
110 // Do we have a producer
111 if ( producer != NULL )
112 {
113 // Set the test card on the consumer
114 mlt_properties_set_data( properties, "test_card_producer", producer, 0, ( mlt_destructor )mlt_producer_close, NULL );
115 }
116 }
117
118 // Start the service
119 if ( this->start != NULL )
120 return this->start( this );
121
122 return 0;
123 }
124
125 /** Protected method :-/ for consumer to get frames from connected service
126 */
127
128 mlt_frame mlt_consumer_get_frame( mlt_consumer this )
129 {
130 // Frame to return
131 mlt_frame frame = NULL;
132
133 // Get the service assoicated to the consumer
134 mlt_service service = mlt_consumer_service( this );
135
136 // Get the frame
137 if ( mlt_service_get_frame( service, &frame, 0 ) == 0 )
138 {
139 // Get the consumer properties
140 mlt_properties properties = mlt_consumer_properties( this );
141
142 // Get the frame properties
143 mlt_properties frame_properties = mlt_frame_properties( frame );
144
145 // Attach the test frame producer to it.
146 mlt_producer test_card = mlt_properties_get_data( properties, "test_card_producer", NULL );
147 mlt_properties_set_data( frame_properties, "test_card_producer", test_card, 0, NULL, NULL );
148
149 // Attach the rescale property
150 if ( mlt_properties_get( properties, "rescale" ) != NULL )
151 mlt_properties_set( frame_properties, "rescale.interp", mlt_properties_get( properties, "rescale" ) );
152
153 // TODO: Aspect ratio and other jiggery pokery
154 }
155
156 // Return the frame
157 return frame;
158 }
159
160 /** Stop the consumer.
161 */
162
163 int mlt_consumer_stop( mlt_consumer this )
164 {
165 if ( this->stop != NULL )
166 return this->stop( this );
167 return 0;
168 }
169
170 /** Determine if the consumer is stopped.
171 */
172
173 int mlt_consumer_is_stopped( mlt_consumer this )
174 {
175 // Get the properies
176 mlt_properties properties = mlt_consumer_properties( this );
177
178 // Stop the consumer
179 if ( this->is_stopped != NULL )
180 return this->is_stopped( this );
181
182 // Kill the test card
183 mlt_properties_set_data( properties, "test_card_producer", NULL, 0, NULL, NULL );
184
185 return 0;
186 }
187
188 /** Close the consumer.
189 */
190
191 void mlt_consumer_close( mlt_consumer this )
192 {
193 // Get the childs close function
194 void ( *consumer_close )( ) = this->close;
195
196 // Make sure it only gets called once
197 this->close = NULL;
198
199 // Call the childs close if available
200 if ( consumer_close != NULL )
201 consumer_close( this );
202 else
203 mlt_service_close( &this->parent );
204 }
205