#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <locale.h>
#include <libxml/tree.h>
+#include <pthread.h>
+#include <wchar.h>
#define ID_SIZE 128
+#define TIME_PROPERTY "_consumer_xml"
#define _x (const xmlChar*)
#define _s (const char*)
mlt_properties hide_map;
char *root;
char *store;
+ int no_meta;
+ mlt_profile profile;
+ mlt_time_format time_format;
};
typedef struct serialise_context_s* serialise_context;
*/
static int consumer_start( mlt_consumer parent );
+static int consumer_stop( mlt_consumer parent );
static int consumer_is_stopped( mlt_consumer this );
+static void *consumer_thread( void *arg );
static void serialise_service( serialise_context context, mlt_service service, xmlNode *node );
-typedef enum
+static char* filter_restricted( const char *in )
+{
+ if ( !in ) return NULL;
+ size_t n = strlen( in );
+ char *out = calloc( 1, n + 1 );
+ char *p = out;
+ mbstate_t mbs;
+ memset( &mbs, 0, sizeof(mbs) );
+ while ( *in )
+ {
+ wchar_t w;
+ size_t c = mbrtowc( &w, in, n, &mbs );
+ if ( c <= 0 || c > n ) break;
+ n -= c;
+ in += c;
+ if ( w == 0x9 || w == 0xA || w == 0xD ||
+ ( w >= 0x20 && w <= 0xD7FF ) ||
+ ( w >= 0xE000 && w <= 0xFFFD ) ||
+ ( w >= 0x10000 && w <= 0x10FFFF ) )
+ {
+ mbstate_t ps;
+ memset( &ps, 0, sizeof(ps) );
+ c = wcrtomb( p, w, &ps );
+ if ( c > 0 )
+ p += c;
+ }
+ }
+ return out;
+}
+
+typedef enum
{
xml_existing,
xml_producer,
// Attempt to reuse existing id
id = mlt_properties_get( MLT_SERVICE_PROPERTIES( service ), "id" );
- // If no id, or the id is used in the map (for another service), then
+ // If no id, or the id is used in the map (for another service), then
// create a new one.
if ( id == NULL || mlt_properties_get_data( map, id, NULL ) != NULL )
{
mlt_consumer consumer_xml_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg )
{
// Create the consumer object
- mlt_consumer this = calloc( sizeof( struct mlt_consumer_s ), 1 );
+ mlt_consumer this = calloc( 1, sizeof( struct mlt_consumer_s ) );
// If no malloc'd and consumer init ok
if ( this != NULL && mlt_consumer_init( this, NULL, profile ) == 0 )
{
// Allow thread to be started/stopped
this->start = consumer_start;
+ this->stop = consumer_stop;
this->is_stopped = consumer_is_stopped;
mlt_properties_set( MLT_CONSUMER_PROPERTIES( this ), "resource", arg );
+ mlt_properties_set_int( MLT_CONSUMER_PROPERTIES( this ), "real_time", -1 );
+ mlt_properties_set_int( MLT_CONSUMER_PROPERTIES( this ), "prefill", 1 );
+ mlt_properties_set_int( MLT_CONSUMER_PROPERTIES( this ), "terminate_on_pause", 1 );
// Return the consumer produced
return this;
{
int i;
xmlNode *p;
-
+
// Enumerate the properties
for ( i = 0; i < mlt_properties_count( properties ); i++ )
{
if ( name != NULL &&
name[ 0 ] != '_' &&
mlt_properties_get_value( properties, i ) != NULL &&
- strcmp( name, "mlt" ) != 0 &&
- strcmp( name, "in" ) != 0 &&
- strcmp( name, "out" ) != 0 &&
- strcmp( name, "id" ) != 0 &&
- strcmp( name, "title" ) != 0 &&
- strcmp( name, "root" ) != 0 &&
- strcmp( name, "width" ) != 0 &&
- strcmp( name, "height" ) != 0 )
+ ( !context->no_meta || strncmp( name, "meta.", 5 ) ) &&
+ strcmp( name, "mlt" ) &&
+ strcmp( name, "in" ) &&
+ strcmp( name, "out" ) &&
+ strcmp( name, "id" ) &&
+ strcmp( name, "title" ) &&
+ strcmp( name, "root" ) &&
+ strcmp( name, "width" ) &&
+ strcmp( name, "height" ) )
{
- char *value = mlt_properties_get_value( properties, i );
- int rootlen = strlen( context->root );
- if ( rootlen && !strncmp( value, context->root, rootlen ) && value[ rootlen ] == '/' )
- value += rootlen + 1;
- p = xmlNewTextChild( node, NULL, _x("property"), _x(value) );
- xmlNewProp( p, _x("name"), _x(name) );
+ char *value = NULL;
+ if ( !strcmp( name, "length" ) )
+ {
+ char *time = mlt_properties_get_time( properties, name, context->time_format );
+ if ( time )
+ value = strdup( time );
+ }
+ else
+ value = filter_restricted( mlt_properties_get_value( properties, i ) );
+ if ( value )
+ {
+ int rootlen = strlen( context->root );
+ // convert absolute path to relative
+ if ( rootlen && !strncmp( value, context->root, rootlen ) && value[ rootlen ] == '/' )
+ p = xmlNewTextChild( node, NULL, _x("property"), _x(value + rootlen + 1 ) );
+ else
+ p = xmlNewTextChild( node, NULL, _x("property"), _x(value) );
+ xmlNewProp( p, _x("name"), _x(name) );
+ free( value );
+ }
}
}
}
{
int i;
xmlNode *p;
-
+
// Enumerate the properties
for ( i = 0; store != NULL && i < mlt_properties_count( properties ); i++ )
{
char *name = mlt_properties_get_name( properties, i );
if ( !strncmp( name, store, strlen( store ) ) )
{
- char *value = mlt_properties_get_value( properties, i );
- if ( value != NULL )
+ char *value = filter_restricted( mlt_properties_get_value( properties, i ) );
+ if ( value )
{
int rootlen = strlen( context->root );
+ // convert absolute path to relative
if ( rootlen && !strncmp( value, context->root, rootlen ) && value[ rootlen ] == '/' )
- value += rootlen + 1;
- p = xmlNewTextChild( node, NULL, _x("property"), _x(value) );
+ p = xmlNewTextChild( node, NULL, _x("property"), _x(value + rootlen + 1) );
+ else
+ p = xmlNewTextChild( node, NULL, _x("property"), _x(value) );
xmlNewProp( p, _x("name"), _x(name) );
+ free( value );
}
}
}
int i;
xmlNode *p;
mlt_filter filter = NULL;
-
+
// Enumerate the filters
for ( i = 0; ( filter = mlt_producer_filter( MLT_PRODUCER( service ), i ) ) != NULL; i ++ )
{
char *id = xml_get_id( context, MLT_FILTER_SERVICE( filter ), xml_filter );
if ( id != NULL )
{
- int in = mlt_properties_get_position( properties, "in" );
- int out = mlt_properties_get_position( properties, "out" );
p = xmlNewChild( node, NULL, _x("filter"), NULL );
xmlNewProp( p, _x("id"), _x(id) );
if ( mlt_properties_get( properties, "title" ) )
xmlNewProp( p, _x("title"), _x(mlt_properties_get( properties, "title" )) );
- if ( in != 0 || out != 0 )
- {
- char temp[ 20 ];
- sprintf( temp, "%d", in );
- xmlNewProp( p, _x("in"), _x(temp) );
- sprintf( temp, "%d", out );
- xmlNewProp( p, _x("out"), _x(temp) );
- }
+ if ( mlt_properties_get_position( properties, "in" ) )
+ xmlNewProp( p, _x("in"), _x( mlt_properties_get_time( properties, "in", context->time_format ) ) );
+ if ( mlt_properties_get_position( properties, "out" ) )
+ xmlNewProp( p, _x("out"), _x( mlt_properties_get_time( properties, "out", context->time_format ) ) );
serialise_properties( context, properties, p );
serialise_service_filters( context, MLT_FILTER_SERVICE( filter ), p );
}
{
xmlNode *child = node;
mlt_service parent = MLT_SERVICE( mlt_producer_cut_parent( MLT_PRODUCER( service ) ) );
-
+
if ( context->pass == 0 )
{
mlt_properties properties = MLT_SERVICE_PROPERTIES( parent );
xmlNewProp( child, _x("id"), _x(id) );
if ( mlt_properties_get( properties, "title" ) )
xmlNewProp( child, _x("title"), _x(mlt_properties_get( properties, "title" )) );
- xmlNewProp( child, _x("in"), _x(mlt_properties_get( properties, "in" )) );
- xmlNewProp( child, _x("out"), _x(mlt_properties_get( properties, "out" )) );
+ xmlNewProp( child, _x("in"), _x(mlt_properties_get_time( properties, "in", context->time_format )) );
+ xmlNewProp( child, _x("out"), _x(mlt_properties_get_time( properties, "out", context->time_format )) );
serialise_properties( context, properties, child );
serialise_service_filters( context, service, child );
char *id = xml_get_id( context, parent, xml_existing );
mlt_properties properties = MLT_SERVICE_PROPERTIES( service );
xmlNewProp( node, _x("parent"), _x(id) );
- xmlNewProp( node, _x("in"), _x(mlt_properties_get( properties, "in" )) );
- xmlNewProp( node, _x("out"), _x(mlt_properties_get( properties, "out" )) );
+ xmlNewProp( node, _x("in"), _x(mlt_properties_get_time( properties, "in", context->time_format )) );
+ xmlNewProp( node, _x("out"), _x(mlt_properties_get_time( properties, "out", context->time_format )) );
}
}
static void serialise_multitrack( serialise_context context, mlt_service service, xmlNode *node )
{
int i;
-
+
if ( context->pass == 0 )
{
// Iterate over the tracks to collect the producers
xmlNewProp( track, _x("producer"), _x(id) );
if ( mlt_producer_is_cut( producer ) )
{
- xmlNewProp( track, _x("in"), _x(mlt_properties_get( properties, "in" )) );
- xmlNewProp( track, _x("out"), _x(mlt_properties_get( properties, "out" )) );
+ xmlNewProp( track, _x("in"), _x( mlt_properties_get_time( properties, "in", context->time_format ) ) );
+ xmlNewProp( track, _x("out"), _x( mlt_properties_get_time( properties, "out", context->time_format ) ) );
serialise_store_properties( context, MLT_PRODUCER_PROPERTIES( producer ), track, context->store );
- serialise_store_properties( context, MLT_PRODUCER_PROPERTIES( producer ), track, "meta." );
+ serialise_store_properties( context, MLT_PRODUCER_PROPERTIES( producer ), track, "xml_" );
+ if ( !context->no_meta )
+ serialise_store_properties( context, MLT_PRODUCER_PROPERTIES( producer ), track, "meta." );
serialise_service_filters( context, MLT_PRODUCER_SERVICE( producer ), track );
}
-
+
hide = mlt_properties_get_int( context->hide_map, id );
if ( hide )
xmlNewProp( track, _x("hide"), _x( hide == 1 ? "video" : ( hide == 2 ? "audio" : "both" ) ) );
xmlNode *child = node;
mlt_playlist_clip_info info;
mlt_properties properties = MLT_SERVICE_PROPERTIES( service );
-
+
if ( context->pass == 0 )
{
// Get a new id - if already allocated, do nothing
}
}
}
-
+
child = xmlNewChild( node, NULL, _x("playlist"), NULL );
// Set the id
// Store application specific properties
serialise_store_properties( context, properties, child, context->store );
- serialise_store_properties( context, properties, child, "meta." );
+ serialise_store_properties( context, properties, child, "xml_" );
+ if ( !context->no_meta )
+ serialise_store_properties( context, properties, child, "meta." );
// Add producer to the map
mlt_properties_set_int( context->hide_map, id, mlt_properties_get_int( properties, "hide" ) );
-
+
// Iterate over the playlist entries
for ( i = 0; i < mlt_playlist_count( MLT_PLAYLIST( service ) ); i++ )
{
if ( ! mlt_playlist_get_clip_info( MLT_PLAYLIST( service ), &info, i ) )
{
mlt_producer producer = mlt_producer_cut_parent( info.producer );
- char *service_s = mlt_properties_get( MLT_PRODUCER_PROPERTIES( producer ), "mlt_service" );
+ mlt_properties producer_props = MLT_PRODUCER_PROPERTIES( producer );
+ char *service_s = mlt_properties_get( producer_props, "mlt_service" );
if ( service_s != NULL && strcmp( service_s, "blank" ) == 0 )
{
- char length[ 20 ];
- length[ 19 ] = '\0';
xmlNode *entry = xmlNewChild( child, NULL, _x("blank"), NULL );
- snprintf( length, 19, "%d", (int)info.frame_count );
- xmlNewProp( entry, _x("length"), _x(length) );
+ mlt_properties_set_data( producer_props, "_profile", context->profile, 0, NULL, NULL );
+ mlt_properties_set_position( producer_props, TIME_PROPERTY, info.frame_count );
+ xmlNewProp( entry, _x("length"), _x( mlt_properties_get_time( producer_props, TIME_PROPERTY, context->time_format ) ) );
}
else
{
xmlNode *entry = xmlNewChild( child, NULL, _x("entry"), NULL );
id = xml_get_id( context, MLT_SERVICE( producer ), xml_existing );
xmlNewProp( entry, _x("producer"), _x(id) );
- sprintf( temp, "%d", (int)info.frame_in );
- xmlNewProp( entry, _x("in"), _x(temp) );
- sprintf( temp, "%d", (int)info.frame_out );
- xmlNewProp( entry, _x("out"), _x(temp) );
+ mlt_properties_set_position( producer_props, TIME_PROPERTY, info.frame_in );
+ xmlNewProp( entry, _x("in"), _x( mlt_properties_get_time( producer_props, TIME_PROPERTY, context->time_format ) ) );
+ mlt_properties_set_position( producer_props, TIME_PROPERTY, info.frame_out );
+ xmlNewProp( entry, _x("out"), _x( mlt_properties_get_time( producer_props, TIME_PROPERTY, context->time_format ) ) );
if ( info.repeat > 1 )
{
sprintf( temp, "%d", info.repeat );
if ( mlt_producer_is_cut( info.cut ) )
{
serialise_store_properties( context, MLT_PRODUCER_PROPERTIES( info.cut ), entry, context->store );
- serialise_store_properties( context, MLT_PRODUCER_PROPERTIES( info.cut ), entry, "meta." );
+ serialise_store_properties( context, MLT_PRODUCER_PROPERTIES( info.cut ), entry, "xml_" );
+ if ( !context->no_meta )
+ serialise_store_properties( context, MLT_PRODUCER_PROPERTIES( info.cut ), entry, "meta." );
serialise_service_filters( context, MLT_PRODUCER_SERVICE( info.cut ), entry );
}
}
{
xmlNode *child = node;
mlt_properties properties = MLT_SERVICE_PROPERTIES( service );
-
+
if ( context->pass == 0 )
{
// Recurse on connected producer
xmlNewProp( child, _x("title"), _x(mlt_properties_get( properties, "title" )) );
if ( mlt_properties_get( properties, "global_feed" ) )
xmlNewProp( child, _x("global_feed"), _x(mlt_properties_get( properties, "global_feed" )) );
- xmlNewProp( child, _x("in"), _x(mlt_properties_get( properties, "in" )) );
- xmlNewProp( child, _x("out"), _x(mlt_properties_get( properties, "out" )) );
+ if ( mlt_properties_get_position( properties, "in" ) >= 0 )
+ xmlNewProp( child, _x("in"), _x(mlt_properties_get_time( properties, "in", context->time_format )) );
+ if ( mlt_properties_get_position( properties, "out" ) >= 0 )
+ xmlNewProp( child, _x("out"), _x(mlt_properties_get_time( properties, "out", context->time_format )) );
// Store application specific properties
serialise_store_properties( context, MLT_SERVICE_PROPERTIES( service ), child, context->store );
- serialise_store_properties( context, MLT_SERVICE_PROPERTIES( service ), child, "meta." );
+ serialise_store_properties( context, MLT_SERVICE_PROPERTIES( service ), child, "xml_" );
+ if ( !context->no_meta )
+ serialise_store_properties( context, MLT_SERVICE_PROPERTIES( service ), child, "meta." );
// Recurse on connected producer
serialise_service( context, mlt_service_producer( service ), child );
{
xmlNode *child = node;
mlt_properties properties = MLT_SERVICE_PROPERTIES( service );
-
+
// Recurse on connected producer
serialise_service( context, mlt_service_producer( service ), node );
xmlNewProp( child, _x("id"), _x(id) );
if ( mlt_properties_get( properties, "title" ) )
xmlNewProp( child, _x("title"), _x(mlt_properties_get( properties, "title" )) );
- xmlNewProp( child, _x("in"), _x(mlt_properties_get( properties, "in" )) );
- xmlNewProp( child, _x("out"), _x(mlt_properties_get( properties, "out" )) );
+ if ( mlt_properties_get_position( properties, "in" ) )
+ xmlNewProp( child, _x("in"), _x( mlt_properties_get_time( properties, "in", context->time_format ) ) );
+ if ( mlt_properties_get_position( properties, "out" ) )
+ xmlNewProp( child, _x("out"), _x( mlt_properties_get_time( properties, "out", context->time_format ) ) );
serialise_properties( context, properties, child );
serialise_service_filters( context, service, child );
{
xmlNode *child = node;
mlt_properties properties = MLT_SERVICE_PROPERTIES( service );
-
+
// Recurse on connected producer
serialise_service( context, MLT_SERVICE( MLT_TRANSITION( service )->producer ), node );
return;
child = xmlNewChild( node, NULL, _x("transition"), NULL );
-
+
// Set the id
xmlNewProp( child, _x("id"), _x(id) );
if ( mlt_properties_get( properties, "title" ) )
xmlNewProp( child, _x("title"), _x(mlt_properties_get( properties, "title" )) );
- xmlNewProp( child, _x("in"), _x(mlt_properties_get( properties, "in" )) );
- xmlNewProp( child, _x("out"), _x(mlt_properties_get( properties, "out" )) );
+ if ( mlt_properties_get_position( properties, "in" ) )
+ xmlNewProp( child, _x("in"), _x( mlt_properties_get_time( properties, "in", context->time_format ) ) );
+ if ( mlt_properties_get_position( properties, "out" ) )
+ xmlNewProp( child, _x("out"), _x( mlt_properties_get_time( properties, "out", context->time_format ) ) );
serialise_properties( context, properties, child );
serialise_service_filters( context, service, child );
{
mlt_properties properties = MLT_SERVICE_PROPERTIES( service );
char *mlt_type = mlt_properties_get( properties, "mlt_type" );
-
+
// Tell about the producer
if ( strcmp( mlt_type, "producer" ) == 0 )
{
else if ( strcmp( mlt_type, "mlt_producer" ) == 0 )
{
char *resource = mlt_properties_get( properties, "resource" );
-
+
// Recurse on multitrack's tracks
- if ( strcmp( resource, "<multitrack>" ) == 0 )
+ if ( resource && strcmp( resource, "<multitrack>" ) == 0 )
{
serialise_multitrack( context, service, node );
break;
}
-
+
// Recurse on playlist's clips
- else if ( strcmp( resource, "<playlist>" ) == 0 )
+ else if ( resource && strcmp( resource, "<playlist>" ) == 0 )
{
serialise_playlist( context, service, node );
}
-
+
// Recurse on tractor's producer
- else if ( strcmp( resource, "<tractor>" ) == 0 )
+ else if ( resource && strcmp( resource, "<tractor>" ) == 0 )
{
context->pass = 0;
serialise_tractor( context, service, node );
else
{
serialise_producer( context, service, node );
+ if ( mlt_properties_get( properties, "xml" ) != NULL )
+ break;
}
}
-
+
// Tell about a filter
else if ( strcmp( mlt_type, "filter" ) == 0 )
{
serialise_filter( context, service, node );
break;
}
-
+
// Tell about a transition
else if ( strcmp( mlt_type, "transition" ) == 0 )
{
serialise_transition( context, service, node );
break;
}
-
+
// Get the next connected service
service = mlt_service_producer( service );
}
}
+static void serialise_other( mlt_properties properties, struct serialise_context_s *context, xmlNodePtr root )
+{
+ int i;
+ mlt_properties_debug( properties, __FUNCTION__, stderr );
+ for ( i = 0; i < mlt_properties_count( properties ); i++ )
+ {
+ const char* name = mlt_properties_get_name( properties, i );
+ if ( strlen(name) > 10 && !strncmp( name, "xml_retain", 10 ) )
+ {
+ mlt_service service = mlt_properties_get_data_at( properties, i, NULL );
+ if ( service )
+ {
+ mlt_properties_set_int( MLT_SERVICE_PROPERTIES( service ), "xml_retain", 1 );
+ serialise_service( context, service, root );
+ }
+ }
+ }
+}
+
xmlDocPtr xml_make_doc( mlt_consumer consumer, mlt_service service )
{
mlt_properties properties = MLT_SERVICE_PROPERTIES( service );
xmlDocPtr doc = xmlNewDoc( _x("1.0") );
xmlNodePtr root = xmlNewNode( NULL, _x("mlt") );
struct serialise_context_s *context = calloc( 1, sizeof( struct serialise_context_s ) );
- xmlNodePtr profile_node = xmlNewChild( root, NULL, _x("profile"), NULL );
- mlt_profile profile = mlt_service_profile( service );
+ mlt_profile profile = mlt_service_profile( MLT_CONSUMER_SERVICE( consumer ) );
char tmpstr[ 32 ];
xmlDocSetRootElement( doc, root );
+ // Indicate the numeric locale
+ xmlNewProp( root, _x("LC_NUMERIC"), _x( setlocale( LC_NUMERIC, NULL ) ) );
+
+ // Indicate the version
+ xmlNewProp( root, _x("version"), _x( mlt_version_get_string() ) );
+
// If we have root, then deal with it now
if ( mlt_properties_get( properties, "root" ) != NULL )
{
// Assign the additional 'storage' pattern for properties
context->store = mlt_properties_get( MLT_CONSUMER_PROPERTIES( consumer ), "store" );
+ context->no_meta = mlt_properties_get_int( MLT_CONSUMER_PROPERTIES( consumer ), "no_meta" );
+ const char *time_format = mlt_properties_get( MLT_CONSUMER_PROPERTIES( consumer ), "time_format" );
+ if ( time_format && ( !strcmp( time_format, "smpte" ) || !strcmp( time_format, "SMPTE" )
+ || !strcmp( time_format, "timecode" ) ) )
+ context->time_format = mlt_time_smpte;
+ else if ( time_format && ( !strcmp( time_format, "clock" ) || !strcmp( time_format, "CLOCK" ) ) )
+ context->time_format = mlt_time_clock;
// Assign a title property
if ( mlt_properties_get( properties, "title" ) != NULL )
// Add a profile child element
if ( profile )
{
+ xmlNodePtr profile_node = xmlNewChild( root, NULL, _x("profile"), NULL );
if ( profile->description )
xmlNewProp( profile_node, _x("description"), _x(profile->description) );
sprintf( tmpstr, "%d", profile->width );
xmlNewProp( profile_node, _x("frame_rate_den"), _x(tmpstr) );
sprintf( tmpstr, "%d", profile->colorspace );
xmlNewProp( profile_node, _x("colorspace"), _x(tmpstr) );
+ context->profile = profile;
}
// Construct the context maps
context->id_map = mlt_properties_new();
context->hide_map = mlt_properties_new();
-
+
// Ensure producer is a framework producer
mlt_properties_set( MLT_SERVICE_PROPERTIES( service ), "mlt_type", "mlt_producer" );
// In pass one, we serialise the end producers and playlists,
// adding them to a map keyed by address.
+ serialise_other( MLT_SERVICE_PROPERTIES( service ), context, root );
serialise_service( context, service, root );
// In pass two, we serialise the tractor and reference the
// producers and playlists
context->pass++;
+ serialise_other( MLT_SERVICE_PROPERTIES( service ), context, root );
serialise_service( context, service, root );
// Cleanup resource
mlt_properties_close( context->hide_map );
free( context->root );
free( context );
-
+
return doc;
}
-static int consumer_start( mlt_consumer this )
+
+static void output_xml( mlt_consumer this )
{
- xmlDocPtr doc = NULL;
-
// Get the producer service
mlt_service service = mlt_service_producer( MLT_CONSUMER_SERVICE( this ) );
- if ( service != NULL )
+ mlt_properties properties = MLT_CONSUMER_PROPERTIES( this );
+ char *resource = mlt_properties_get( properties, "resource" );
+ xmlDocPtr doc = NULL;
+
+ if ( !service ) return;
+
+ // Set the title if provided
+ if ( mlt_properties_get( properties, "title" ) )
+ mlt_properties_set( MLT_SERVICE_PROPERTIES( service ), "title", mlt_properties_get( properties, "title" ) );
+ else if ( mlt_properties_get( MLT_SERVICE_PROPERTIES( service ), "title" ) == NULL )
+ mlt_properties_set( MLT_SERVICE_PROPERTIES( service ), "title", "Anonymous Submission" );
+
+ // Check for a root on the consumer properties and pass to service
+ if ( mlt_properties_get( properties, "root" ) )
+ mlt_properties_set( MLT_SERVICE_PROPERTIES( service ), "root", mlt_properties_get( properties, "root" ) );
+
+ // Specify roots in other cases...
+ if ( resource != NULL && mlt_properties_get( properties, "root" ) == NULL )
{
- mlt_properties properties = MLT_CONSUMER_PROPERTIES( this );
- char *resource = mlt_properties_get( properties, "resource" );
+ // Get the current working directory
+ char *cwd = getcwd( NULL, 0 );
+ mlt_properties_set( MLT_SERVICE_PROPERTIES( service ), "root", cwd );
+ free( cwd );
+ }
- // Set the title if provided
- if ( mlt_properties_get( properties, "title" ) )
- mlt_properties_set( MLT_SERVICE_PROPERTIES( service ), "title", mlt_properties_get( properties, "title" ) );
- else if ( mlt_properties_get( MLT_SERVICE_PROPERTIES( service ), "title" ) == NULL )
- mlt_properties_set( MLT_SERVICE_PROPERTIES( service ), "title", "Anonymous Submission" );
+ // Make the document
+ doc = xml_make_doc( this, service );
- // Check for a root on the consumer properties and pass to service
- if ( mlt_properties_get( properties, "root" ) )
- mlt_properties_set( MLT_SERVICE_PROPERTIES( service ), "root", mlt_properties_get( properties, "root" ) );
+ // Handle the output
+ if ( resource == NULL || !strcmp( resource, "" ) )
+ {
+ xmlDocFormatDump( stdout, doc, 1 );
+ }
+ else if ( strchr( resource, '.' ) == NULL )
+ {
+ xmlChar *buffer = NULL;
+ int length = 0;
+ xmlDocDumpMemoryEnc( doc, &buffer, &length, "utf-8" );
+ mlt_properties_set( properties, resource, _s(buffer) );
+#ifdef WIN32
+ xmlFreeFunc xmlFree = NULL;
+ xmlMemGet( &xmlFree, NULL, NULL, NULL);
+#endif
+ xmlFree( buffer );
+ }
+ else
+ {
+ xmlSaveFormatFileEnc( resource, doc, "utf-8", 1 );
+ }
- // Specify roots in other cases...
- if ( resource != NULL && mlt_properties_get( properties, "root" ) == NULL )
+ // Close the document
+ xmlFreeDoc( doc );
+}
+static int consumer_start( mlt_consumer this )
+{
+ mlt_properties properties = MLT_CONSUMER_PROPERTIES( this );
+
+ if ( mlt_properties_get_int( properties, "all" ) )
+ {
+ // Check that we're not already running
+ if ( !mlt_properties_get_int( properties, "running" ) )
{
- // Get the current working directory
- char *cwd = getcwd( NULL, 0 );
- mlt_properties_set( MLT_SERVICE_PROPERTIES( service ), "root", cwd );
- free( cwd );
- }
+ // Allocate a thread
+ pthread_t *thread = calloc( 1, sizeof( pthread_t ) );
- // Make the document
- doc = xml_make_doc( this, service );
+ // Assign the thread to properties
+ mlt_properties_set_data( properties, "thread", thread, sizeof( pthread_t ), free, NULL );
- // Handle the output
- if ( resource == NULL || !strcmp( resource, "" ) )
- {
- xmlDocFormatDump( stdout, doc, 1 );
- }
- else if ( strchr( resource, '.' ) == NULL )
- {
- xmlChar *buffer = NULL;
- int length = 0;
- xmlDocDumpMemoryEnc( doc, &buffer, &length, "utf-8" );
- mlt_properties_set( properties, resource, _s(buffer) );
- xmlFree( buffer );
- }
- else
- {
- xmlSaveFormatFileEnc( resource, doc, "utf-8", 1 );
+ // Set the running state
+ mlt_properties_set_int( properties, "running", 1 );
+ mlt_properties_set_int( properties, "joined", 0 );
+
+ // Create the thread
+ pthread_create( thread, NULL, consumer_thread, this );
}
-
- // Close the document
- xmlFreeDoc( doc );
}
-
- mlt_consumer_stop( this );
+ else
+ {
+ output_xml( this );
+ mlt_consumer_stop( this );
+ mlt_consumer_stopped( this );
+ }
+ return 0;
+}
- mlt_consumer_stopped( this );
+static int consumer_is_stopped( mlt_consumer this )
+{
+ mlt_properties properties = MLT_CONSUMER_PROPERTIES( this );
+ return !mlt_properties_get_int( properties, "running" );
+}
+
+static int consumer_stop( mlt_consumer this )
+{
+ // Get the properties
+ mlt_properties properties = MLT_CONSUMER_PROPERTIES( this );
+
+ // Check that we're running
+ if ( !mlt_properties_get_int( properties, "joined" ) )
+ {
+ // Get the thread
+ pthread_t *thread = mlt_properties_get_data( properties, "thread", NULL );
+
+ // Stop the thread
+ mlt_properties_set_int( properties, "running", 0 );
+ mlt_properties_set_int( properties, "joined", 1 );
+
+ // Wait for termination
+ if ( thread )
+ pthread_join( *thread, NULL );
+ }
return 0;
}
-static int consumer_is_stopped( mlt_consumer this )
+static void *consumer_thread( void *arg )
{
- return 1;
+ // Map the argument to the object
+ mlt_consumer this = arg;
+
+ // Get the properties
+ mlt_properties properties = MLT_CONSUMER_PROPERTIES( this );
+
+ // Convenience functionality
+ int terminate_on_pause = mlt_properties_get_int( properties, "terminate_on_pause" );
+ int terminated = 0;
+
+ // Frame and size
+ mlt_frame frame = NULL;
+
+ int video_off = mlt_properties_get_int( properties, "video_off" );
+ int audio_off = mlt_properties_get_int( properties, "audio_off" );
+
+ // Loop while running
+ while( !terminated && mlt_properties_get_int( properties, "running" ) )
+ {
+ // Get the frame
+ frame = mlt_consumer_rt_frame( this );
+
+ // Check for termination
+ if ( terminate_on_pause && frame != NULL )
+ terminated = mlt_properties_get_double( MLT_FRAME_PROPERTIES( frame ), "_speed" ) == 0.0;
+
+ // Check that we have a frame to work with
+ if ( frame )
+ {
+ int width = 0, height = 0;
+ int frequency = mlt_properties_get_int( properties, "frequency" );
+ int channels = mlt_properties_get_int( properties, "channels" );
+ int samples = 0;
+ mlt_image_format iformat = mlt_image_yuv422;
+ mlt_audio_format aformat = mlt_audio_s16;
+ uint8_t *buffer;
+
+ if ( !video_off )
+ mlt_frame_get_image( frame, &buffer, &iformat, &width, &height, 0 );
+ if ( !audio_off )
+ mlt_frame_get_audio( frame, (void**) &buffer, &aformat, &frequency, &channels, &samples );
+
+ // Close the frame
+ mlt_events_fire( properties, "consumer-frame-show", frame, NULL );
+ mlt_frame_close( frame );
+ }
+ }
+ output_xml( this );
+
+ // Indicate that the consumer is stopped
+ mlt_properties_set_int( properties, "running", 0 );
+ mlt_consumer_stopped( this );
+
+ return NULL;
}