X-Git-Url: http://research.m1stereo.tv/gitweb?a=blobdiff_plain;f=src%2Fmodules%2Fvalerie%2Fconsumer_valerie.c;h=4c36a9ec4ae0ad747139a2c532d23f57e3454c76;hb=2e467c2eeba2b51aecddda21d4bb97bef4cd1459;hp=e47358484cb2c94c46b955d4717f3600386de9ae;hpb=8cf0f77981284b7549c811b67283eb73d0c520d6;p=melted diff --git a/src/modules/valerie/consumer_valerie.c b/src/modules/valerie/consumer_valerie.c index e473584..4c36a9e 100644 --- a/src/modules/valerie/consumer_valerie.c +++ b/src/modules/valerie/consumer_valerie.c @@ -42,15 +42,28 @@ mlt_consumer consumer_valerie_init( char *arg ) // If no malloc'd and consumer init ok if ( this != NULL && mlt_consumer_init( this, NULL ) == 0 ) { - // Allow thread to be started/stopped - this->start = consumer_start; - this->is_stopped = consumer_is_stopped; + if ( arg != NULL && strchr( arg, ':' ) ) + { + char *temp = NULL; + int port = atoi( strchr( arg, ':' ) + 1 ); + mlt_properties_set( mlt_consumer_properties( this ), "server", arg ); + temp = mlt_properties_get( mlt_consumer_properties( this ), "server" ); + *( strchr( temp, ':' ) ) = '\0'; + mlt_properties_set_int( mlt_consumer_properties( this ), "port", port ); + } + else + { + mlt_properties_set( mlt_consumer_properties( this ), "server", arg == NULL ? "localhost" : arg ); + mlt_properties_set_int( mlt_consumer_properties( this ), "port", 5250 ); + } - mlt_properties_set( mlt_consumer_properties( this ), "server", arg == NULL ? "localhost" : arg ); - mlt_properties_set_int( mlt_consumer_properties( this ), "port", 5250 ); mlt_properties_set_int( mlt_consumer_properties( this ), "unit", 0 ); mlt_properties_set( mlt_consumer_properties( this ), "command", "append" ); + // Allow thread to be started/stopped + this->start = consumer_start; + this->is_stopped = consumer_is_stopped; + // Return the consumer produced return this; } @@ -73,15 +86,37 @@ static int consumer_start( mlt_consumer this ) // Get all the properties now char *server = mlt_properties_get( properties, "server" ); int port = mlt_properties_get_int( properties, "port" ); - char *command = mlt_properties_get( properties, "command" ); + char *cmd = mlt_properties_get( properties, "command" ); int unit = mlt_properties_get_int( properties, "unit" ); char *title = mlt_properties_get( properties, "title" ); + char command[ 2048 ]; // If this is a reuse, then a valerie object will exist valerie connection = mlt_properties_get_data( properties, "connection", NULL ); + // Special case - we can get a doc too... + char *doc = mlt_properties_get( properties, "westley" ); + + // Set the title if provided if ( service != NULL ) { + if ( title != NULL ) + mlt_properties_set( mlt_service_properties( service ), "title", title ); + else if ( mlt_properties_get( mlt_service_properties( service ), "title" ) == NULL ) + mlt_properties_set( mlt_service_properties( service ), "title", "Anonymous Submission" ); + title = mlt_properties_get( mlt_service_properties( service ), "title" ); + } + + strcpy( command, cmd == NULL ? "" : cmd ); + if ( strstr( command, "title=" ) == NULL && title != NULL ) + { + strcat( command, " title=\"" ); + strcat( command, title ); + strcat( command, "\"" ); + } + + if ( service != NULL || doc != NULL ) + { // Initiate the connection if required if ( connection == NULL ) { @@ -95,6 +130,7 @@ static int consumer_start( mlt_consumer this ) else { fprintf( stderr, "Unable to connect to the server at %s:%d\n", server, port ); + mlt_properties_set_int( properties, "_error", 1 ); valerie_close( connection ); valerie_parser_close( parser ); connection = NULL; @@ -104,20 +140,26 @@ static int consumer_start( mlt_consumer this ) // If we have connection, push the service over if ( connection != NULL ) { - int error; + if ( doc == NULL ) + { + int error; - // Set the title if provided - if ( title != NULL ) - mlt_properties_set( mlt_service_properties( service ), "title", title ); - else if ( mlt_properties_get( mlt_service_properties( service ), "title" ) == NULL ) - mlt_properties_set( mlt_service_properties( service ), "title", "Anonymous Submission" ); + // Push the service + error = valerie_unit_push( connection, unit, command, service ); - // Push the service - error = valerie_unit_push( connection, unit, command, service ); + // Report error + if ( error != valerie_ok ) + fprintf( stderr, "Push failed on %s:%d %s u%d (%d)\n", server, port, command, unit, error ); + } + else + { + // Push the service + int error = valerie_unit_receive( connection, unit, command, doc ); - // Report error - if ( error != valerie_ok ) - fprintf( stderr, "Push failed on %s:%d %s u%d (%d)\n", server, port, command, unit, error ); + // Report error + if ( error != valerie_ok ) + fprintf( stderr, "Send failed on %s:%d %s u%d (%d)\n", server, port, command, unit, error ); + } } }