From: Dan Dennedy Date: Sun, 29 Aug 2010 05:35:25 +0000 (-0700) Subject: Add (de)serialization of profile to XML. X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=90166b303f7edeaa70a529fdf2e9e483ed4d952f;p=mlt Add (de)serialization of profile to XML. In addition to the 'profile' element, one can also set the 'profile' attribute of the root element to a named profile. --- diff --git a/src/modules/xml/consumer_xml.c b/src/modules/xml/consumer_xml.c index fae400b0..880fbc0a 100644 --- a/src/modules/xml/consumer_xml.c +++ b/src/modules/xml/consumer_xml.c @@ -630,7 +630,10 @@ xmlDocPtr xml_make_doc( mlt_consumer consumer, mlt_service 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 ); + char tmpstr[ 32 ]; + xmlDocSetRootElement( doc, root ); // If we have root, then deal with it now @@ -652,6 +655,27 @@ xmlDocPtr xml_make_doc( mlt_consumer consumer, mlt_service service ) xmlNewProp( root, _x("title"), _x(mlt_properties_get( properties, "title" )) ); mlt_properties_set_int( properties, "global_feed", 1 ); + // Add a profile child element + xmlNewProp( profile_node, _x("description"), _x(profile->description) ); + sprintf( tmpstr, "%d", profile->width ); + xmlNewProp( profile_node, _x("width"), _x(tmpstr) ); + sprintf( tmpstr, "%d", profile->height ); + xmlNewProp( profile_node, _x("height"), _x(tmpstr) ); + sprintf( tmpstr, "%d", profile->progressive ); + xmlNewProp( profile_node, _x("progressive"), _x(tmpstr) ); + sprintf( tmpstr, "%d", profile->sample_aspect_num ); + xmlNewProp( profile_node, _x("sample_aspect_num"), _x(tmpstr) ); + sprintf( tmpstr, "%d", profile->sample_aspect_den ); + xmlNewProp( profile_node, _x("sample_aspect_den"), _x(tmpstr) ); + sprintf( tmpstr, "%d", profile->display_aspect_num ); + xmlNewProp( profile_node, _x("display_aspect_num"), _x(tmpstr) ); + sprintf( tmpstr, "%d", profile->display_aspect_den ); + xmlNewProp( profile_node, _x("display_aspect_den"), _x(tmpstr) ); + sprintf( tmpstr, "%d", profile->frame_rate_num ); + xmlNewProp( profile_node, _x("frame_rate_num"), _x(tmpstr) ); + sprintf( tmpstr, "%d", profile->frame_rate_den ); + xmlNewProp( profile_node, _x("frame_rate_den"), _x(tmpstr) ); + // Construct the context maps context->id_map = mlt_properties_new(); context->hide_map = mlt_properties_new(); diff --git a/src/modules/xml/mlt-xml.dtd b/src/modules/xml/mlt-xml.dtd index bb7e1610..6c1dc2ba 100644 --- a/src/modules/xml/mlt-xml.dtd +++ b/src/modules/xml/mlt-xml.dtd @@ -1,8 +1,22 @@ - + - + + + profile; + for ( ; atts != NULL && *atts != NULL; atts += 2 ) + { + if ( xmlStrcmp( atts[ 0 ], _x("name") ) == 0 || xmlStrcmp( atts[ 0 ], _x("profile") ) == 0 ) + { + mlt_profile my_profile = mlt_profile_init( _s(atts[ 1 ]) ); + if ( my_profile ) + { + p->description = strdup( my_profile->description ); + p->display_aspect_den = my_profile->display_aspect_den; + p->display_aspect_num = my_profile->display_aspect_num; + p->frame_rate_den = my_profile->frame_rate_den; + p->frame_rate_num = my_profile->frame_rate_num; + p->width = my_profile->width; + p->height = my_profile->height; + p->progressive = my_profile->progressive; + p->sample_aspect_den = my_profile->sample_aspect_den; + p->sample_aspect_num = my_profile->sample_aspect_num; + mlt_profile_close( my_profile ); + } + } + else if ( xmlStrcmp( atts[ 0 ], _x("description") ) == 0 ) + { + if ( p->description ) + free( p->description ); + p->description = strdup( _s(atts[ 1 ]) ); + } + else if ( xmlStrcmp( atts[ 0 ], _x("display_aspect_den") ) == 0 ) + p->display_aspect_den = strtol( _s(atts[ 1 ]), NULL, 0 ); + else if ( xmlStrcmp( atts[ 0 ], _x("display_aspect_num") ) == 0 ) + p->display_aspect_num = strtol( _s(atts[ 1 ]), NULL, 0 ); + else if ( xmlStrcmp( atts[ 0 ], _x("sample_aspect_num") ) == 0 ) + p->sample_aspect_num = strtol( _s(atts[ 1 ]), NULL, 0 ); + else if ( xmlStrcmp( atts[ 0 ], _x("sample_aspect_den") ) == 0 ) + p->sample_aspect_den = strtol( _s(atts[ 1 ]), NULL, 0 ); + else if ( xmlStrcmp( atts[ 0 ], _x("width") ) == 0 ) + p->width = strtol( _s(atts[ 1 ]), NULL, 0 ); + else if ( xmlStrcmp( atts[ 0 ], _x("height") ) == 0 ) + p->height = strtol( _s(atts[ 1 ]), NULL, 0 ); + else if ( xmlStrcmp( atts[ 0 ], _x("progressive") ) == 0 ) + p->progressive = strtol( _s(atts[ 1 ]), NULL, 0 ); + else if ( xmlStrcmp( atts[ 0 ], _x("frame_rate_num") ) == 0 ) + p->frame_rate_num = strtol( _s(atts[ 1 ]), NULL, 0 ); + else if ( xmlStrcmp( atts[ 0 ], _x("frame_rate_den") ) == 0 ) + p->frame_rate_den = strtol( _s(atts[ 1 ]), NULL, 0 ); + } +} + static void on_start_tractor( deserialise_context context, const xmlChar *name, const xmlChar **atts) { mlt_tractor tractor = mlt_tractor_new( ); @@ -1054,6 +1105,14 @@ static void on_start_element( void *ctx, const xmlChar *name, const xmlChar **at deserialise_context context = ( deserialise_context )( xmlcontext->_private ); //printf("on_start_element: %s\n", name ); + if ( context->pass == 0 ) + { + if ( xmlStrcmp( name, _x("mlt") ) == 0 || + xmlStrcmp( name, _x("profile") ) == 0 || + xmlStrcmp( name, _x("profileinfo") ) == 0 ) + on_start_profile( context, name, atts ); + return; + } context->branch[ context->depth ] ++; context->depth ++; @@ -1395,12 +1454,6 @@ mlt_producer producer_xml_init( mlt_profile profile, mlt_service_type servtype, // Setup SAX callbacks sax->startElement = on_start_element; - sax->endElement = on_end_element; - sax->characters = on_characters; - sax->cdataBlock = on_characters; - sax->internalSubset = on_internal_subset; - sax->entityDecl = on_entity_declaration; - sax->getEntity = on_get_entity; // Setup libxml2 SAX parsing xmlInitParser(); @@ -1424,19 +1477,53 @@ mlt_producer producer_xml_init( mlt_profile profile, mlt_service_type servtype, return NULL; } + // Parse xmlcontext->sax = sax; - xmlcontext->_private = ( void* )context; + xmlcontext->_private = ( void* )context; + xmlParseDocument( xmlcontext ); + // Cleanup after parsing + xmlcontext->sax = NULL; + xmlcontext->_private = NULL; + xmlFreeParserCtxt( xmlcontext ); + + // Setup the second pass + context->pass ++; + if ( info == 0 ) + xmlcontext = xmlCreateFileParserCtxt( filename ); + else + xmlcontext = xmlCreateMemoryParserCtxt( data, strlen( data ) ); + + // Invalid context - clean up and return NULL + if ( xmlcontext == NULL ) + { + mlt_properties_close( context->producer_map ); + mlt_properties_close( context->destructors ); + mlt_properties_close( context->params ); + xmlFreeDoc( context->entity_doc ); + free( context ); + free( sax ); + free( filename ); + return NULL; + } + + // Setup SAX callbacks + sax->endElement = on_end_element; + sax->characters = on_characters; + sax->cdataBlock = on_characters; + sax->internalSubset = on_internal_subset; + sax->entityDecl = on_entity_declaration; + sax->getEntity = on_get_entity; + // Parse + xmlcontext->sax = sax; + xmlcontext->_private = ( void* )context; xmlParseDocument( xmlcontext ); well_formed = xmlcontext->wellFormed; - + // Cleanup after parsing xmlFreeDoc( context->entity_doc ); free( sax ); - xmlcontext->sax = NULL; - xmlcontext->_private = NULL; - xmlFreeParserCtxt( xmlcontext ); xmlMemoryDump( ); // for debugging // Get the last producer on the stack