]> git.sesse.net Git - mlt/blobdiff - src/modules/swfdec/producer_swfdec.c
linsys/consumer_SDIstream.c: check for null pointer
[mlt] / src / modules / swfdec / producer_swfdec.c
index 594b9c199ec1861f599b502fb8ab11f197dde39d..88d338f955bad8c34102f27b4bd774b0d5cc63b0 100644 (file)
@@ -24,6 +24,7 @@
 #include <string.h>
 #include <stdio.h>
 #include <math.h>
+#include <limits.h>
 
 typedef struct
 {
@@ -110,10 +111,14 @@ static void bgra_to_rgba( uint8_t *src, uint8_t* dst, int width, int height )
 static int get_image( mlt_frame frame, uint8_t **buffer, mlt_image_format *format, int *width, int *height, int writable )
 {
        producer_swfdec swfdec = mlt_frame_pop_service( frame );
+       mlt_service service = MLT_PRODUCER_SERVICE( &swfdec->parent );
+       mlt_profile profile = mlt_service_profile( service );
        mlt_properties properties = MLT_FRAME_PROPERTIES( frame );
 
+       mlt_service_lock( service );
+       
        if ( !swfdec->player )
-               swfdec_open( swfdec, mlt_service_profile( MLT_PRODUCER_SERVICE( &swfdec->parent ) ) );
+               swfdec_open( swfdec, profile );
 
        // Set width and height
        *width = swfdec->width;
@@ -121,11 +126,10 @@ static int get_image( mlt_frame frame, uint8_t **buffer, mlt_image_format *forma
        *format = mlt_image_rgb24a;
 
        *buffer = mlt_pool_alloc( *width * ( *height + 1 ) * 4 );
-       mlt_properties_set_data( properties, "image", *buffer, *width * ( *height + 1 ) * 4, (mlt_destructor) mlt_pool_release, NULL );
+       mlt_frame_set_image( frame, *buffer, *width * ( *height + 1 ) * 4, mlt_pool_release );
 
        // Seek
        mlt_position pos = mlt_properties_get_position( properties, "swfdec.position" );
-       mlt_profile profile = mlt_service_profile( MLT_PRODUCER_SERVICE( &swfdec->parent ) );
        if ( pos > swfdec->last_position )
        {
                gulong msec = 1000UL * ( pos - swfdec->last_position ) * profile->frame_rate_den / profile->frame_rate_num;
@@ -135,7 +139,7 @@ static int get_image( mlt_frame frame, uint8_t **buffer, mlt_image_format *forma
        else if ( pos < swfdec->last_position )
        {
                swfdec_close( swfdec );
-               swfdec_open( swfdec, mlt_service_profile( MLT_PRODUCER_SERVICE( &swfdec->parent ) ) );
+               swfdec_open( swfdec, mlt_service_profile( service ) );
                gulong msec = 1000UL * pos * profile->frame_rate_den / profile->frame_rate_num;
                while ( msec > 0 )
                        msec -= swfdec_player_advance( swfdec->player, msec );
@@ -153,6 +157,8 @@ static int get_image( mlt_frame frame, uint8_t **buffer, mlt_image_format *forma
        // Get image from surface
        uint8_t *image = cairo_image_surface_get_data( swfdec->surface );
        
+       mlt_service_unlock( service );
+       
        // Convert to RGBA
        bgra_to_rgba( image, *buffer, swfdec->width, swfdec->height );
 
@@ -174,8 +180,6 @@ static int get_frame( mlt_producer producer, mlt_frame_ptr frame, int index )
        mlt_properties_set_int( properties, "test_image", 0 );
        mlt_properties_set_int( properties, "width", swfdec->width );
        mlt_properties_set_int( properties, "height", swfdec->height );
-       mlt_properties_set_int( properties, "real_width", swfdec->width );
-       mlt_properties_set_int( properties, "real_height", swfdec->height );
        mlt_properties_set_int( properties, "progressive", 1 );
        mlt_properties_set_double( properties, "aspect_ratio", 1.0 );
        mlt_properties_set_position( properties, "swfdec.position", mlt_producer_frame( producer ) );
@@ -227,11 +231,28 @@ mlt_producer producer_swfdec_init( mlt_profile profile, mlt_service_type type, c
                        producer = &swfdec->parent;
 
                        // Set the resource property (required for all producers)
-                       mlt_properties_set( MLT_PRODUCER_PROPERTIES( producer ), "resource", filename );
+                       mlt_properties properties = MLT_PRODUCER_PROPERTIES( producer );
+                       mlt_properties_set( properties, "resource", filename );
 
                        // Set the callbacks
                        producer->close = (mlt_destructor) producer_close;
                        producer->get_frame = get_frame;
+
+                       // Set the meta media attributes
+                       swfdec->width = profile->width;
+                       swfdec->height = profile->height;
+                       mlt_properties_set_int( properties, "meta.media.nb_streams", 1 );
+                       mlt_properties_set( properties, "meta.media.0.stream.type", "video" );
+                       mlt_properties_set( properties, "meta.media.0.codec.name", "swf" );
+                       mlt_properties_set( properties, "meta.media.0.codec.long_name", "Adobe Flash" );
+                       mlt_properties_set( properties, "meta.media.0.codec.pix_fmt", "bgra" );
+                       mlt_properties_set_int( properties, "meta.media.width", profile->width );
+                       mlt_properties_set_int( properties, "meta.media.height", profile->height );
+                       mlt_properties_set_double( properties, "meta.media.sample_aspect_num", 1.0 );
+                       mlt_properties_set_double( properties, "meta.media.sample_aspect_den", 1.0 );
+                       mlt_properties_set_int( properties, "meta.media.frame_rate_num", profile->frame_rate_num );
+                       mlt_properties_set_int( properties, "meta.media.frame_rate_den", profile->frame_rate_den );
+                       mlt_properties_set_int( properties, "meta.media.progressive", 1 );
                }
                else
                {
@@ -248,8 +269,16 @@ mlt_producer producer_swfdec_init( mlt_profile profile, mlt_service_type type, c
        return producer;
 }
 
+static mlt_properties metadata( mlt_service_type type, const char *id, void *data )
+{
+       char file[ PATH_MAX ];
+       snprintf( file, PATH_MAX, "%s/swfdec/%s", mlt_environment( "MLT_DATA" ), (char*) data );
+       return mlt_properties_parse_yaml( file );
+}
+
 MLT_REPOSITORY
 {
        swfdec_init();
        MLT_REGISTER( producer_type, "swfdec", producer_swfdec_init );
+       MLT_REGISTER_METADATA( producer_type, "swfdec", metadata, "producer_swfdec.yml" );
 }