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>
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.
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.
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.
22 #include "mlt_consumer.h"
23 #include "mlt_factory.h"
24 #include "mlt_producer.h"
25 #include "mlt_frame.h"
30 /** Public final methods
33 int mlt_consumer_init( mlt_consumer
this, void *child
)
36 memset( this, 0, sizeof( struct mlt_consumer_s
) );
38 error
= mlt_service_init( &this->parent
, this );
41 // Get the properties from the service
42 mlt_properties properties
= mlt_service_properties( &this->parent
);
44 // Get the normalisation preference
45 char *normalisation
= mlt_environment( "MLT_NORMALISATION" );
47 // Deal with normalisation
48 if ( normalisation
== NULL
|| strcmp( normalisation
, "NTSC" ) )
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 mlt_properties_set_int( properties
, "progressive", 0 );
58 mlt_properties_set( properties
, "normalisation", "NTSC" );
59 mlt_properties_set_double( properties
, "fps", 30000.0 / 1001.0 );
60 mlt_properties_set_int( properties
, "width", 720 );
61 mlt_properties_set_int( properties
, "height", 480 );
62 mlt_properties_set_int( properties
, "progressive", 0 );
64 mlt_properties_set_double( properties
, "aspect_ratio", 4.0 / 3.0 );
66 // Default rescaler for all consumers
67 mlt_properties_set( properties
, "rescale", "bilinear" );
72 /** Get the parent service object.
75 mlt_service
mlt_consumer_service( mlt_consumer
this )
80 /** Get the consumer properties.
83 mlt_properties
mlt_consumer_properties( mlt_consumer
this )
85 return mlt_service_properties( &this->parent
);
88 /** Connect the consumer to the producer.
91 int mlt_consumer_connect( mlt_consumer
this, mlt_service producer
)
93 return mlt_service_connect_producer( &this->parent
, producer
, 0 );
96 /** Start the consumer.
99 int mlt_consumer_start( mlt_consumer
this )
102 mlt_properties properties
= mlt_consumer_properties( this );
104 // Determine if there's a test card producer
105 char *test_card
= mlt_properties_get( properties
, "test_card" );
108 if ( test_card
!= NULL
)
110 if ( mlt_properties_get_data( properties
, "test_card_producer", NULL
) == NULL
)
112 // Create a test card producer
113 // TODO: do we want to use fezzik here?
114 mlt_producer producer
= mlt_factory_producer( "fezzik", test_card
);
116 // Do we have a producer
117 if ( producer
!= NULL
)
119 // Test card should loop I guess...
120 mlt_properties_set( mlt_producer_properties( producer
), "eof", "loop" );
122 // Set the test card on the consumer
123 mlt_properties_set_data( properties
, "test_card_producer", producer
, 0, ( mlt_destructor
)mlt_producer_close
, NULL
);
126 // Check and run an ante command
127 if ( mlt_properties_get( properties
, "ante" ) )
128 system( mlt_properties_get( properties
, "ante" ) );
133 // Allow the hash table to speed things up
134 mlt_properties_set_data( properties
, "test_card_producer", NULL
, 0, NULL
, NULL
);
138 if ( this->start
!= NULL
)
139 return this->start( this );
144 /** Protected method :-/ for consumer to get frames from connected service
147 mlt_frame
mlt_consumer_get_frame( mlt_consumer
this )
150 mlt_frame frame
= NULL
;
152 // Get the service assoicated to the consumer
153 mlt_service service
= mlt_consumer_service( this );
156 if ( mlt_service_get_frame( service
, &frame
, 0 ) == 0 )
158 // Get the consumer properties
159 mlt_properties properties
= mlt_consumer_properties( this );
161 // Get the frame properties
162 mlt_properties frame_properties
= mlt_frame_properties( frame
);
164 // Get the test card producer
165 mlt_producer test_card
= mlt_properties_get_data( properties
, "test_card_producer", NULL
);
167 // Attach the test frame producer to it.
168 if ( test_card
!= NULL
)
169 mlt_properties_set_data( frame_properties
, "test_card_producer", test_card
, 0, NULL
, NULL
);
171 // Attach the rescale property
172 mlt_properties_set( frame_properties
, "rescale.interp", mlt_properties_get( properties
, "rescale" ) );
174 // Aspect ratio and other jiggery pokery
175 mlt_properties_set_double( frame_properties
, "consumer_aspect_ratio", mlt_properties_get_double( properties
, "aspect_ratio" ) );
176 mlt_properties_set_int( frame_properties
, "consumer_progressive", mlt_properties_get_int( properties
, "progressive" ) );
177 mlt_properties_set_int( frame_properties
, "consumer_deinterlace", mlt_properties_get_int( properties
, "deinterlace" ) );
184 /** Stop the consumer.
187 int mlt_consumer_stop( mlt_consumer
this )
190 mlt_properties properties
= mlt_consumer_properties( this );
193 if ( this->stop
!= NULL
)
196 // Kill the test card
197 mlt_properties_set_data( properties
, "test_card_producer", NULL
, 0, NULL
, NULL
);
199 // Check and run a post command
200 if ( mlt_properties_get( properties
, "post" ) )
201 system( mlt_properties_get( properties
, "post" ) );
206 /** Determine if the consumer is stopped.
209 int mlt_consumer_is_stopped( mlt_consumer
this )
211 // Check if the consumer is stopped
212 if ( this->is_stopped
!= NULL
)
213 return this->is_stopped( this );
218 /** Close the consumer.
221 void mlt_consumer_close( mlt_consumer
this )
223 // Get the childs close function
224 void ( *consumer_close
)( ) = this->close
;
226 // Make sure it only gets called once
229 // Call the childs close if available
230 if ( consumer_close
!= NULL
)
231 consumer_close( this );
233 mlt_service_close( &this->parent
);