X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fmodules%2Fxml%2Fconsumer_xml.c;h=b7936a9d92f509db59986ab1efa85075255f4146;hb=cb186b864f4b3151dbd3082b490f6903ef1d739b;hp=3e1544b54e60a2ad2f0bcd414bbb879a234959f6;hpb=2d328408132825439fc69462865e78659170efdc;p=mlt diff --git a/src/modules/xml/consumer_xml.c b/src/modules/xml/consumer_xml.c index 3e1544b5..b7936a9d 100644 --- a/src/modules/xml/consumer_xml.c +++ b/src/modules/xml/consumer_xml.c @@ -29,6 +29,7 @@ #include #define ID_SIZE 128 +#define TIME_PROPERTY "_consumer_xml" #define _x (const xmlChar*) #define _s (const char*) @@ -48,6 +49,8 @@ struct serialise_context_s char *root; char *store; int no_meta; + mlt_profile profile; + mlt_time_format time_format; }; typedef struct serialise_context_s* serialise_context; @@ -72,7 +75,7 @@ static char* filter_restricted( const char *in ) { wchar_t w; size_t c = mbrtowc( &w, in, n, &mbs ); - if ( c <= 0 ) break; + if ( c <= 0 || c > n ) break; n -= c; in += c; if ( w == 0x9 || w == 0xA || w == 0xD || @@ -183,7 +186,7 @@ static char *xml_get_id( serialise_context context, mlt_service service, xml_typ 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 ) @@ -231,7 +234,15 @@ static void serialise_properties( serialise_context context, mlt_properties prop strcmp( name, "width" ) && strcmp( name, "height" ) ) { - char *value = filter_restricted( mlt_properties_get_value( properties, i ) ); + 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 ); @@ -290,20 +301,14 @@ static inline void serialise_service_filters( serialise_context context, mlt_ser 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 ); } @@ -330,8 +335,8 @@ static void serialise_producer( serialise_context context, mlt_service service, 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 ); @@ -343,8 +348,8 @@ static void serialise_producer( serialise_context context, mlt_service service, 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 )) ); } } @@ -384,9 +389,10 @@ static void serialise_multitrack( serialise_context context, mlt_service service 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, "xml_" ); if ( !context->no_meta ) serialise_store_properties( context, MLT_PRODUCER_PROPERTIES( producer ), track, "meta." ); serialise_service_filters( context, MLT_PRODUCER_SERVICE( producer ), track ); @@ -441,6 +447,7 @@ static void serialise_playlist( serialise_context context, mlt_service service, // Store application specific properties serialise_store_properties( context, properties, child, context->store ); + serialise_store_properties( context, properties, child, "xml_" ); if ( !context->no_meta ) serialise_store_properties( context, properties, child, "meta." ); @@ -453,14 +460,14 @@ static void serialise_playlist( serialise_context context, mlt_service service, 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 { @@ -468,10 +475,10 @@ static void serialise_playlist( serialise_context context, mlt_service service, 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 ); @@ -480,6 +487,7 @@ static void serialise_playlist( serialise_context context, mlt_service service, 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, "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 ); @@ -522,11 +530,14 @@ static void serialise_tractor( serialise_context context, mlt_service service, x 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, "xml_" ); if ( !context->no_meta ) serialise_store_properties( context, MLT_SERVICE_PROPERTIES( service ), child, "meta." ); @@ -557,8 +568,10 @@ static void serialise_filter( serialise_context context, mlt_service service, xm 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 ); @@ -586,8 +599,10 @@ static void serialise_transition( serialise_context context, mlt_service service 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 ); @@ -656,6 +671,8 @@ static void serialise_service( serialise_context context, mlt_service service, x else { serialise_producer( context, service, node ); + if ( mlt_properties_get( properties, "xml" ) != NULL ) + break; } } @@ -678,6 +695,24 @@ static void serialise_service( serialise_context context, mlt_service service, x } } +static void serialise_other( mlt_properties properties, struct serialise_context_s *context, xmlNodePtr root ) +{ + int i; + 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 ); @@ -709,6 +744,12 @@ xmlDocPtr xml_make_doc( mlt_consumer consumer, mlt_service service ) // 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 ) @@ -741,6 +782,7 @@ xmlDocPtr xml_make_doc( mlt_consumer consumer, mlt_service service ) 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 @@ -752,11 +794,13 @@ xmlDocPtr xml_make_doc( mlt_consumer consumer, mlt_service service ) // 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 @@ -798,6 +842,12 @@ static void output_xml( mlt_consumer this ) free( cwd ); } +#if !defined(__GLIBC__) && !defined(__DARWIN__) + // Get the current locale + char *orig_localename = strdup( setlocale( LC_NUMERIC, NULL ) ); + setlocale( LC_NUMERIC, "C" ); +#endif + // Make the document doc = xml_make_doc( this, service ); @@ -823,6 +873,12 @@ static void output_xml( mlt_consumer this ) xmlSaveFormatFileEnc( resource, doc, "utf-8", 1 ); } +#if !defined(__GLIBC__) && !defined(__DARWIN__) + // Restore the current locale + setlocale( LC_NUMERIC, orig_localename ); + free( orig_localename ); +#endif + // Close the document xmlFreeDoc( doc ); } @@ -902,6 +958,9 @@ static void *consumer_thread( void *arg ) // 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" ) ) { @@ -923,8 +982,10 @@ static void *consumer_thread( void *arg ) mlt_audio_format aformat = mlt_audio_s16; uint8_t *buffer; - mlt_frame_get_image( frame, &buffer, &iformat, &width, &height, 0 ); - mlt_frame_get_audio( frame, (void**) &buffer, &aformat, &frequency, &channels, &samples ); + 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 );