2 * consumer_null.c -- a null consumer
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 "consumer_null.h"
25 #include <framework/mlt_frame.h>
27 // System header files
33 // Forward references.
34 static int consumer_start( mlt_consumer
this );
35 static int consumer_stop( mlt_consumer
this );
36 static int consumer_is_stopped( mlt_consumer
this );
37 static void *consumer_thread( void *arg
);
38 static void consumer_close( mlt_consumer
this );
40 /** Initialise the dv consumer.
43 mlt_consumer
consumer_null_init( char *arg
)
45 // Allocate the consumer
46 mlt_consumer
this = mlt_consumer_new( );
48 // If memory allocated and initialises without error
51 // Assign close callback
52 this->close
= consumer_close
;
54 // Set up start/stop/terminated callbacks
55 this->start
= consumer_start
;
56 this->stop
= consumer_stop
;
57 this->is_stopped
= consumer_is_stopped
;
64 /** Start the consumer.
67 static int consumer_start( mlt_consumer
this )
70 mlt_properties properties
= MLT_CONSUMER_PROPERTIES( this );
72 // Check that we're not already running
73 if ( !mlt_properties_get_int( properties
, "running" ) )
76 pthread_t
*thread
= calloc( 1, sizeof( pthread_t
) );
78 // Assign the thread to properties
79 mlt_properties_set_data( properties
, "thread", thread
, sizeof( pthread_t
), free
, NULL
);
81 // Set the running state
82 mlt_properties_set_int( properties
, "running", 1 );
85 pthread_create( thread
, NULL
, consumer_thread
, this );
90 /** Stop the consumer.
93 static int consumer_stop( mlt_consumer
this )
96 mlt_properties properties
= MLT_CONSUMER_PROPERTIES( this );
98 // Check that we're running
99 if ( mlt_properties_get_int( properties
, "running" ) )
102 pthread_t
*thread
= mlt_properties_get_data( properties
, "thread", NULL
);
105 mlt_properties_set_int( properties
, "running", 0 );
107 // Wait for termination
108 pthread_join( *thread
, NULL
);
114 /** Determine if the consumer is stopped.
117 static int consumer_is_stopped( mlt_consumer
this )
119 // Get the properties
120 mlt_properties properties
= MLT_CONSUMER_PROPERTIES( this );
121 return !mlt_properties_get_int( properties
, "running" );
124 /** The main thread - the argument is simply the consumer.
127 static void *consumer_thread( void *arg
)
129 // Map the argument to the object
130 mlt_consumer
this = arg
;
132 // Get the properties
133 mlt_properties properties
= MLT_CONSUMER_PROPERTIES( this );
136 mlt_frame frame
= NULL
;
138 // Loop while running
139 while( mlt_properties_get_int( properties
, "running" ) )
142 frame
= mlt_consumer_rt_frame( this );
144 // Check that we have a frame to work with
148 mlt_events_fire( properties
, "consumer-frame-show", frame
, NULL
);
149 mlt_frame_close( frame
);
153 // Indicate that the consumer is stopped
154 mlt_consumer_stopped( this );
159 /** Close the consumer.
162 static void consumer_close( mlt_consumer
this )
165 mlt_consumer_stop( this );
168 mlt_consumer_close( this );