X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fmodules%2Fxml%2Fconsumer_xml.c;h=92988f142f61f28fc17f747d0b240c989e0b3f45;hb=236717e4ecc23e458e191b6c9a2ba70915b80937;hp=98cc1e9255c2142bec9d5b88da14117dc9704382;hpb=ab4f5ab7148b76ac532eea9273185c53130afd80;p=mlt diff --git a/src/modules/xml/consumer_xml.c b/src/modules/xml/consumer_xml.c index 98cc1e92..92988f14 100644 --- a/src/modules/xml/consumer_xml.c +++ b/src/modules/xml/consumer_xml.c @@ -26,11 +26,10 @@ #include #include #include -#ifdef FILTER_WCHAR #include -#endif #define ID_SIZE 128 +#define TIME_PROPERTY "_consumer_xml" #define _x (const xmlChar*) #define _s (const char*) @@ -50,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; @@ -62,44 +63,37 @@ 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 ); -#ifdef FILTER_WCHAR - -void* filter_restricted( const wchar_t *in ) +static char* filter_restricted( const char *in ) { if ( !in ) return NULL; - wchar_t *out = calloc( 1, strlen( (const char*) in ) ); - size_t i, j, n = wcslen( in ); - for ( i = 0, j = 0; i < n; i++ ) + 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 = in[i]; + 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 ) ) - out[ j++ ] = w; - } - return out; -} - -#else - -void* filter_restricted( const char *in ) -{ - if ( !in ) return NULL; - char *out = calloc( 1, strlen( in ) ); - size_t i, j, n = strlen( in ); - for ( i = 0, j = 0; i < n; i++ ) - { - char c = in[i]; - if ( c == 0x9 || c == 0xA || c == 0xD || ( c >= 0x20 && c <= 0xFF ) ) - out[ j++ ] = c; + { + mbstate_t ps; + memset( &ps, 0, sizeof(ps) ); + c = wcrtomb( p, w, &ps ); + if ( c > 0 ) + p += c; + } } return out; } -#endif - -typedef enum +typedef enum { xml_existing, xml_producer, @@ -131,7 +125,7 @@ static char *xml_get_id( serialise_context context, mlt_service service, xml_typ // 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 ) { @@ -192,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 ) @@ -222,7 +216,7 @@ static void serialise_properties( serialise_context context, mlt_properties prop { int i; xmlNode *p; - + // Enumerate the properties for ( i = 0; i < mlt_properties_count( properties ); i++ ) { @@ -240,13 +234,23 @@ 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 ); + // 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 ); } @@ -258,7 +262,7 @@ static void serialise_store_properties( serialise_context context, mlt_propertie { int i; xmlNode *p; - + // Enumerate the properties for ( i = 0; store != NULL && i < mlt_properties_count( properties ); i++ ) { @@ -269,9 +273,11 @@ static void serialise_store_properties( serialise_context context, mlt_propertie 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 ); } @@ -284,7 +290,7 @@ static inline void serialise_service_filters( serialise_context context, mlt_ser int i; xmlNode *p; mlt_filter filter = NULL; - + // Enumerate the filters for ( i = 0; ( filter = mlt_producer_filter( MLT_PRODUCER( service ), i ) ) != NULL; i ++ ) { @@ -295,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 ); } @@ -320,7 +320,7 @@ static void serialise_producer( serialise_context context, mlt_service service, { 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 ); @@ -335,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 ); @@ -348,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 )) ); } } @@ -358,7 +358,7 @@ static void serialise_tractor( serialise_context context, mlt_service service, x 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 @@ -389,14 +389,15 @@ 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 ); } - + hide = mlt_properties_get_int( context->hide_map, id ); if ( hide ) xmlNewProp( track, _x("hide"), _x( hide == 1 ? "video" : ( hide == 2 ? "audio" : "both" ) ) ); @@ -411,7 +412,7 @@ static void serialise_playlist( serialise_context context, mlt_service service, 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 @@ -436,7 +437,7 @@ static void serialise_playlist( serialise_context context, mlt_service service, } } } - + child = xmlNewChild( node, NULL, _x("playlist"), NULL ); // Set the id @@ -446,26 +447,27 @@ 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." ); // 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 { @@ -473,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 ); @@ -485,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 ); @@ -506,7 +509,7 @@ static void serialise_tractor( serialise_context context, mlt_service service, x { xmlNode *child = node; mlt_properties properties = MLT_SERVICE_PROPERTIES( service ); - + if ( context->pass == 0 ) { // Recurse on connected producer @@ -527,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." ); @@ -545,7 +551,7 @@ static void serialise_filter( serialise_context context, mlt_service service, xm { xmlNode *child = node; mlt_properties properties = MLT_SERVICE_PROPERTIES( service ); - + // Recurse on connected producer serialise_service( context, mlt_service_producer( service ), node ); @@ -562,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 ); @@ -574,7 +582,7 @@ static void serialise_transition( serialise_context context, mlt_service service { xmlNode *child = node; mlt_properties properties = MLT_SERVICE_PROPERTIES( service ); - + // Recurse on connected producer serialise_service( context, MLT_SERVICE( MLT_TRANSITION( service )->producer ), node ); @@ -586,13 +594,15 @@ static void serialise_transition( serialise_context context, mlt_service service 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 ); @@ -606,7 +616,7 @@ static void serialise_service( serialise_context context, mlt_service service, x { 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 ) { @@ -632,20 +642,20 @@ static void serialise_service( serialise_context context, mlt_service service, x else if ( strcmp( mlt_type, "mlt_producer" ) == 0 ) { char *resource = mlt_properties_get( properties, "resource" ); - + // Recurse on multitrack's tracks if ( resource && strcmp( resource, "" ) == 0 ) { serialise_multitrack( context, service, node ); break; } - + // Recurse on playlist's clips else if ( resource && strcmp( resource, "" ) == 0 ) { serialise_playlist( context, service, node ); } - + // Recurse on tractor's producer else if ( resource && strcmp( resource, "" ) == 0 ) { @@ -661,28 +671,49 @@ 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; } } - + // 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 ); @@ -714,6 +745,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 ) @@ -746,22 +783,25 @@ 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 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 @@ -769,7 +809,7 @@ xmlDocPtr xml_make_doc( mlt_consumer consumer, mlt_service service ) mlt_properties_close( context->hide_map ); free( context->root ); free( context ); - + return doc; } @@ -907,6 +947,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" ) ) { @@ -928,8 +971,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 );