tunable read ahead buffer and fix for luma
authorlilo_booter <lilo_booter@d19143bc-622f-0410-bfdd-b5b2a6649095>
Thu, 4 Mar 2004 15:35:41 +0000 (15:35 +0000)
committerlilo_booter <lilo_booter@d19143bc-622f-0410-bfdd-b5b2a6649095>
Thu, 4 Mar 2004 15:35:41 +0000 (15:35 +0000)
git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt@193 d19143bc-622f-0410-bfdd-b5b2a6649095

src/framework/mlt_consumer.c
src/framework/mlt_consumer.h
src/modules/core/transition_luma.c
src/modules/dv/consumer_libdv.c
src/modules/sdl/consumer_sdl.c

index 5845d51..aadbb07 100644 (file)
@@ -62,10 +62,18 @@ int mlt_consumer_init( mlt_consumer this, void *child )
                        mlt_properties_set_int( properties, "height", 480 );
                        mlt_properties_set_int( properties, "progressive", 0 );
                }
+
+               // Default aspect ratio
                mlt_properties_set_double( properties, "aspect_ratio", 4.0 / 3.0 );
 
                // Default rescaler for all consumers
                mlt_properties_set( properties, "rescale", "bilinear" );
+
+               // Default read ahead buffer size
+               mlt_properties_set_int( properties, "buffer", 25 );
+
+               // Hmm - default all consumers to yuv422 :-/
+               this->format = mlt_image_yuv422;
        }
        return error;
 }
@@ -203,6 +211,9 @@ static void *consumer_read_ahead_thread( void *arg )
        int width = mlt_properties_get_int( properties, "width" );
        int height = mlt_properties_get_int( properties, "height" );
 
+       // Get the maximum size of the buffer
+       int buffer = mlt_properties_get_int( properties, "buffer" );
+
        // General frame variable
        mlt_frame frame = NULL;
        uint8_t *image = NULL;
@@ -231,7 +242,7 @@ static void *consumer_read_ahead_thread( void *arg )
        {
                // Put the current frame into the queue
                pthread_mutex_lock( &this->mutex );
-               while( this->ahead && mlt_deque_count( this->queue ) >= 25 )
+               while( this->ahead && mlt_deque_count( this->queue ) >= buffer )
                        pthread_cond_wait( &this->cond, &this->mutex );
                mlt_deque_push_back( this->queue, frame );
                pthread_cond_broadcast( &this->cond );
@@ -314,19 +325,19 @@ static void consumer_read_ahead_stop( mlt_consumer this )
        }
 }
 
-mlt_frame mlt_consumer_rt_frame( mlt_consumer this, mlt_image_format format )
+mlt_frame mlt_consumer_rt_frame( mlt_consumer this )
 {
        // Frame to return
        mlt_frame frame = NULL;
        int size = 1;
 
-
        // Is the read ahead running?
        if ( this->ahead == 0 )
        {
-               this->format = format;
+               int buffer = mlt_properties_get_int( mlt_consumer_properties( this ), "buffer" );
                consumer_read_ahead_start( this );
-               size = 12;
+               if ( buffer > 1 )
+                       size = buffer / 2;
        }
 
        // Get frame from queue
index 1881ded..bd7960d 100644 (file)
@@ -59,7 +59,7 @@ extern mlt_properties mlt_consumer_properties( mlt_consumer this );
 extern int mlt_consumer_connect( mlt_consumer this, mlt_service producer );
 extern int mlt_consumer_start( mlt_consumer this );
 extern mlt_frame mlt_consumer_get_frame( mlt_consumer this );
-extern mlt_frame mlt_consumer_rt_frame( mlt_consumer this, mlt_image_format format );
+extern mlt_frame mlt_consumer_rt_frame( mlt_consumer this );
 extern int mlt_consumer_stop( mlt_consumer this );
 extern int mlt_consumer_is_stopped( mlt_consumer this );
 extern void mlt_consumer_close( mlt_consumer );
index 97b2266..8db5d4d 100644 (file)
@@ -37,7 +37,8 @@ static float position_calculate( mlt_transition this, mlt_frame frame )
        mlt_position out = mlt_transition_get_out( this );
 
        // Get the position of the frame
-       mlt_position position = mlt_frame_get_position( frame );
+       char *name = mlt_properties_get( mlt_transition_properties( this ), "_unique_id" );
+       mlt_position position = mlt_properties_get_position( mlt_frame_properties( frame ), name );
 
        // Now do the calcs
        return ( float )( position - in ) / ( float )( out - in + 1 );
index 1d4fafa..5883abc 100644 (file)
@@ -199,13 +199,18 @@ static int consumer_encode_video( mlt_consumer this, uint8_t *dv_frame, mlt_fram
        // This will hold the size of the dv frame
        int size = 0;
 
+       // Is the image rendered
+       int rendered = mlt_properties_get_int( mlt_frame_properties( frame ), "rendered" );
+
+       // Get width and height
+       int width = mlt_properties_get_int( this_properties, "width" );
+       int height = mlt_properties_get_int( this_properties, "height" );
+
        // If we get an encoder, then encode the image
-       if ( encoder != NULL )
+       if ( rendered && encoder != NULL )
        {
                // Specify desired image properties
                mlt_image_format fmt = mlt_image_yuv422;
-               int width = mlt_properties_get_int( this_properties, "width" );
-               int height = mlt_properties_get_int( this_properties, "height" );
                uint8_t *image = NULL;
 
                // Get the image
@@ -233,6 +238,11 @@ static int consumer_encode_video( mlt_consumer this, uint8_t *dv_frame, mlt_fram
                        dv_encode_full_frame( encoder, &image, e_dv_color_yuv, dv_frame );
                }
        }
+       else if ( encoder != NULL )
+       {
+               // Calculate the size of the dv frame (duplicate of previous)
+               size = height == 576 ? frame_size_625_50 : frame_size_525_60;
+       }
        
        return size;
 }
@@ -363,7 +373,7 @@ static void *consumer_thread( void *arg )
        while( mlt_properties_get_int( properties, "running" ) )
        {
                // Get the frame
-               mlt_frame frame = mlt_consumer_rt_frame( this, mlt_image_yuv422 );
+               mlt_frame frame = mlt_consumer_rt_frame( this );
 
                // Check that we have a frame to work with
                if ( frame != NULL )
index b06ca48..0de719e 100644 (file)
@@ -103,6 +103,9 @@ mlt_consumer consumer_sdl_init( char *arg )
                // Default scaler (for now we'll use nearest)
                mlt_properties_set( this->properties, "rescale", "nearest" );
 
+               // Default buffer for low latency
+               mlt_properties_set_int( this->properties, "buffer", 8 );
+
                // Default progressive true
                mlt_properties_set_int( this->properties, "progressive", 1 );
 
@@ -347,7 +350,7 @@ static int consumer_play_video( consumer_sdl this, mlt_frame frame, int64_t elap
                // Get the image, width and height
                mlt_frame_get_image( frame, &image, &vfmt, &width, &height, 0 );
 
-               if ( playtime > elapsed + 20000 )
+               if ( playtime > elapsed + 25000 )
                {
                        struct timespec tm = { ( playtime - elapsed ) / 1000000, ( ( playtime - elapsed ) % 1000000 ) * 1000 };
                        nanosleep( &tm, NULL );
@@ -498,7 +501,7 @@ static void *consumer_thread( void *arg )
        while( this->running )
        {
                // Get a frame from the attached producer
-               mlt_frame frame = mlt_consumer_rt_frame( consumer, mlt_image_yuv422 );
+               mlt_frame frame = mlt_consumer_rt_frame( consumer );
 
                // Ensure that we have a frame
                if ( frame != NULL )