]> git.sesse.net Git - mlt/commitdiff
Revert 3a419b4 (Use caching for swscale contexts).
authorDan Dennedy <dan@dennedy.org>
Wed, 8 Sep 2010 03:24:41 +0000 (20:24 -0700)
committerDan Dennedy <dan@dennedy.org>
Wed, 8 Sep 2010 03:24:41 +0000 (20:24 -0700)
This was just making it too unstable (bug 3060324).

src/modules/avformat/consumer_avformat.c
src/modules/avformat/filter_avcolour_space.c
src/modules/avformat/filter_swscale.c
src/modules/avformat/producer_avformat.c

index 413c6de597389f4d87dcf54d672c7c91945dcc9d..079baf1bf1ccf672a25758b016adc3e3b6c21d0c 100644 (file)
@@ -847,16 +847,6 @@ static void *consumer_thread( void *arg )
        // Need two av pictures for converting
        AVFrame *output = NULL;
        AVFrame *input = alloc_picture( PIX_FMT_YUYV422, width, height );
-#ifdef SWSCALE
-       struct SwsContext *swscale = NULL;
-       int swscale_flags = SWS_BILINEAR;
-#ifdef USE_MMX
-       swscale_flags |= SWS_CPU_CAPS_MMX;
-#endif
-#ifdef USE_SSE
-       swscale_flags |= SWS_CPU_CAPS_MMX2;
-#endif
-#endif
 
        // For receiving images from an mlt_frame
        uint8_t *image;
@@ -1292,10 +1282,18 @@ static void *consumer_thread( void *arg )
 
                                                // Do the colour space conversion
 #ifdef SWSCALE
-                                               swscale = sws_getCachedContext( swscale, width, height, PIX_FMT_YUYV422,
-                                                       width, height, video_st->codec->pix_fmt, swscale_flags, NULL, NULL, NULL);
-                                               sws_scale( swscale, input->data, input->linesize, 0, height,
+                                               int flags = SWS_BILINEAR;
+#ifdef USE_MMX
+                                               flags |= SWS_CPU_CAPS_MMX;
+#endif
+#ifdef USE_SSE
+                                               flags |= SWS_CPU_CAPS_MMX2;
+#endif
+                                               struct SwsContext *context = sws_getContext( width, height, PIX_FMT_YUYV422,
+                                                       width, height, video_st->codec->pix_fmt, flags, NULL, NULL, NULL);
+                                               sws_scale( context, input->data, input->linesize, 0, height,
                                                        output->data, output->linesize);
+                                               sws_freeContext( context );
 #else
                                                img_convert( ( AVPicture * )output, video_st->codec->pix_fmt, ( AVPicture * )input, PIX_FMT_YUYV422, width, height );
 #endif
@@ -1517,9 +1515,6 @@ static void *consumer_thread( void *arg )
        av_free( video_outbuf );
        av_free( audio_buf_1 );
        av_free( audio_buf_2 );
-#ifdef SWSCALE
-       sws_freeContext( swscale );
-#endif
 
        // Free the stream
        av_free( oc );
index ff7557fa414c36cd94d04fd751af6f2fa55b11cb..fa0e38146a043f719b3ea76950969cfe8db39756 100644 (file)
@@ -21,7 +21,6 @@
 #include <framework/mlt_filter.h>
 #include <framework/mlt_frame.h>
 #include <framework/mlt_log.h>
-#include <framework/mlt_producer.h>
 
 // ffmpeg Header files
 #include <avformat.h>
@@ -73,17 +72,11 @@ static int convert_mlt_to_av_cs( mlt_image_format format )
        return value;
 }
 
-static void av_convert_image( mlt_properties properties, uint8_t *out, uint8_t *in, int out_fmt, int in_fmt, int width, int height )
+static void av_convert_image( uint8_t *out, uint8_t *in, int out_fmt, int in_fmt, int width, int height )
 {
        AVPicture input;
        AVPicture output;
-       avpicture_fill( &input, in, in_fmt, width, height );
-       avpicture_fill( &output, out, out_fmt, width, height );
-
-#ifdef SWSCALE
        int flags = SWS_BILINEAR | SWS_ACCURATE_RND;
-       struct SwsContext *context = mlt_properties_get_data( properties, "avcolorspace.swscale", NULL );
-       struct SwsContext *new_context;
 
        if ( out_fmt == PIX_FMT_YUYV422 )
                flags |= SWS_FULL_CHR_H_INP;
@@ -95,15 +88,15 @@ static void av_convert_image( mlt_properties properties, uint8_t *out, uint8_t *
 #ifdef USE_SSE
        flags |= SWS_CPU_CAPS_MMX2;
 #endif
-       new_context = sws_getCachedContext( context, width, height, in_fmt,
+
+       avpicture_fill( &input, in, in_fmt, width, height );
+       avpicture_fill( &output, out, out_fmt, width, height );
+#ifdef SWSCALE
+       struct SwsContext *context = sws_getContext( width, height, in_fmt,
                width, height, out_fmt, flags, NULL, NULL, NULL);
-//     Disable using cached context here due to crashing in libswscale.
-//     if ( new_context != context )
-//             mlt_properties_set_data( properties, "avcolorspace.swscale", new_context, 0, NULL, NULL );
-       sws_scale( new_context, input.data, input.linesize, 0, height,
+       sws_scale( context, input.data, input.linesize, 0, height,
                output.data, output.linesize);
-       sws_freeContext( new_context );
-
+       sws_freeContext( context );
 #else
        img_convert( &output, out_fmt, &input, in_fmt, width, height );
 #endif
@@ -160,9 +153,7 @@ static int convert_image( mlt_frame frame, uint8_t **image, mlt_image_format *fo
                }
 
                // Update the output
-               mlt_producer producer = mlt_frame_get_original_producer( frame );
-               mlt_properties prod_props = MLT_PRODUCER_PROPERTIES( mlt_producer_cut_parent( producer ) );
-               av_convert_image( prod_props, output, *image, out_fmt, in_fmt, width, height );
+               av_convert_image( output, *image, out_fmt, in_fmt, width, height );
                *image = output;
                *format = output_format;
                mlt_properties_set_data( properties, "image", output, size, mlt_pool_release, NULL );
@@ -210,14 +201,6 @@ static mlt_frame filter_process( mlt_filter this, mlt_frame frame )
        return frame;
 }
 
-static void filter_close( mlt_filter filter )
-{
-#ifdef SWSCALE
-       struct SwsContext *context = mlt_properties_get_data( MLT_FILTER_PROPERTIES(filter), "avcolorspace.swscale", NULL );
-       sws_freeContext( context );
-#endif
-}
-
 /** Constructor for the filter.
 */
 
@@ -241,10 +224,7 @@ mlt_filter filter_avcolour_space_init( void *arg )
 #endif
        mlt_filter this = mlt_filter_new( );
        if ( this != NULL )
-       {
                this->process = filter_process;
-               this->close = filter_close;
-       }
        return this;
 }
 
index 9af5dc05417c147c196c4f27163c30e30294c4f0..9ec35cf19c578a9dcd2fa9b45ddf35a4a8c12fca 100644 (file)
@@ -21,7 +21,6 @@
 #include <framework/mlt_filter.h>
 #include <framework/mlt_frame.h>
 #include <framework/mlt_factory.h>
-#include <framework/mlt_producer.h>
 
 
 // ffmpeg Header files
@@ -132,25 +131,19 @@ static int filter_scale( mlt_frame this, uint8_t **image, mlt_image_format *form
        avpicture_fill( &input, *image, avformat, iwidth, iheight );
        avpicture_fill( &output, outbuf, avformat, owidth, oheight );
 
-       // Get the cached swscale context
-       mlt_producer producer = mlt_frame_get_original_producer( this );
-       mlt_properties prod_props = MLT_PRODUCER_PROPERTIES( mlt_producer_cut_parent( producer ) );
-       struct SwsContext *context = mlt_properties_get_data( prod_props, "swscale.context", NULL );
-
        // Create the context and output image
        owidth = owidth > 5120 ? 5120 : owidth;
-       struct SwsContext *new_context = sws_getCachedContext( context, iwidth, iheight, avformat, owidth, oheight, avformat, interp, NULL, NULL, NULL);
-       if ( !new_context )
+       struct SwsContext *context = sws_getContext( iwidth, iheight, avformat, owidth, oheight, avformat, interp, NULL, NULL, NULL);
+       if ( !context )
        {
                owidth = owidth > 2048 ? 2048 : owidth;
-               new_context = sws_getCachedContext( context, iwidth, iheight, avformat, owidth, oheight, avformat, interp, NULL, NULL, NULL);
+               context = sws_getContext( iwidth, iheight, avformat, owidth, oheight, avformat, interp, NULL, NULL, NULL);
        }
-       if ( new_context != context )
-               mlt_properties_set_data( properties, "swscale.context", new_context, 0, NULL, NULL );
-       if ( new_context )
+       if ( context )
        {
                // Perform the scaling
-               sws_scale( new_context, input.data, input.linesize, 0, iheight, output.data, output.linesize);
+               sws_scale( context, input.data, input.linesize, 0, iheight, output.data, output.linesize);
+               sws_freeContext( context );
        
                // Now update the frame
                mlt_properties_set_data( properties, "image", output.data[0], owidth * ( oheight + 1 ) * bpp, ( mlt_destructor )mlt_pool_release, NULL );
@@ -169,18 +162,14 @@ static int filter_scale( mlt_frame this, uint8_t **image, mlt_image_format *form
                        uint8_t *alpha = mlt_frame_get_alpha_mask( this );
                        if ( alpha )
                        {
-                               context = mlt_properties_get_data( prod_props, "swscale.context2", NULL );
-                               new_context = sws_getCachedContext( context, iwidth, iheight, avformat, owidth, oheight, avformat, interp, NULL, NULL, NULL);
-                               if ( new_context != context )
-                                       mlt_properties_set_data( prod_props, "swscale.context2", new_context, 0, NULL, NULL );
-
                                avformat = PIX_FMT_GRAY8;
+                               struct SwsContext *context = sws_getContext( iwidth, iheight, avformat, owidth, oheight, avformat, interp, NULL, NULL, NULL);
                                avpicture_fill( &input, alpha, avformat, iwidth, iheight );
                                outbuf = mlt_pool_alloc( owidth * oheight );
                                avpicture_fill( &output, outbuf, avformat, owidth, oheight );
        
                                // Perform the scaling
-                               sws_scale( new_context, input.data, input.linesize, 0, iheight, output.data, output.linesize);
+                               sws_scale( context, input.data, input.linesize, 0, iheight, output.data, output.linesize);
        
                                // Set it back on the frame
                                mlt_properties_set_data( MLT_FRAME_PROPERTIES( this ), "alpha", output.data[0], owidth * oheight, mlt_pool_release, NULL );
@@ -195,14 +184,6 @@ static int filter_scale( mlt_frame this, uint8_t **image, mlt_image_format *form
        }
 }
 
-static void filter_close( mlt_filter filter )
-{
-       struct SwsContext *context = mlt_properties_get_data( MLT_FILTER_PROPERTIES(filter), "swscale.context", NULL );
-       sws_freeContext( context );
-       context = mlt_properties_get_data( MLT_FILTER_PROPERTIES(filter), "swscale.context2", NULL );
-       sws_freeContext( context );
-}
-
 /** Constructor for the filter.
 */
 
@@ -233,8 +214,6 @@ mlt_filter filter_swscale_init( mlt_profile profile, void *arg )
 
                // Set the method
                mlt_properties_set_data( properties, "method", filter_scale, 0, NULL, NULL );
-
-               this->close = filter_close;
        }
 
        return this;
index 2a2d454059f178aac15ca6fedbf382634e92b164..d24af96010299ff6859b3682d0faecce97a49679 100644 (file)
@@ -109,11 +109,6 @@ struct producer_avformat_s
                uint8_t *buffer;
        } *vdpau;
 #endif
-#ifdef SWSCALE
-       struct SwsContext *swscale;
-#else
-       void *swscale;
-#endif
 };
 typedef struct producer_avformat_s *producer_avformat;
 
@@ -681,10 +676,9 @@ static void get_audio_streams_info( producer_avformat this )
        this->resample_factor = 1.0;
 }
 
-static inline void convert_image( void **ctx, AVFrame *frame, uint8_t *buffer, int pix_fmt, mlt_image_format *format, int width, int height )
+static inline void convert_image( AVFrame *frame, uint8_t *buffer, int pix_fmt, mlt_image_format *format, int width, int height )
 {
 #ifdef SWSCALE
-       struct SwsContext **context = ctx;
        int flags = SWS_BILINEAR | SWS_ACCURATE_RND;
 
 #ifdef USE_MMX
@@ -697,16 +691,17 @@ static inline void convert_image( void **ctx, AVFrame *frame, uint8_t *buffer, i
        if ( pix_fmt == PIX_FMT_RGB32 )
        {
                *format = mlt_image_rgb24a;
-               *context = sws_getCachedContext( *context, width, height, pix_fmt,
+               struct SwsContext *context = sws_getContext( width, height, pix_fmt,
                        width, height, PIX_FMT_RGBA, flags, NULL, NULL, NULL);
                AVPicture output;
                avpicture_fill( &output, buffer, PIX_FMT_RGBA, width, height );
-               sws_scale( *context, frame->data, frame->linesize, 0, height,
+               sws_scale( context, frame->data, frame->linesize, 0, height,
                        output.data, output.linesize);
+               sws_freeContext( context );
        }
        else if ( *format == mlt_image_yuv420p )
        {
-               *context = sws_getCachedContext( *context, width, height, pix_fmt,
+               struct SwsContext *context = sws_getContext( width, height, pix_fmt,
                        width, height, PIX_FMT_YUV420P, flags, NULL, NULL, NULL);
                AVPicture output;
                output.data[0] = buffer;
@@ -715,35 +710,39 @@ static inline void convert_image( void **ctx, AVFrame *frame, uint8_t *buffer, i
                output.linesize[0] = width;
                output.linesize[1] = width >> 1;
                output.linesize[2] = width >> 1;
-               sws_scale( *context, frame->data, frame->linesize, 0, height,
+               sws_scale( context, frame->data, frame->linesize, 0, height,
                        output.data, output.linesize);
+               sws_freeContext( context );
        }
        else if ( *format == mlt_image_rgb24 )
        {
-               *context = sws_getCachedContext( *context, width, height, pix_fmt,
+               struct SwsContext *context = sws_getContext( width, height, pix_fmt,
                        width, height, PIX_FMT_RGB24, flags | SWS_FULL_CHR_H_INT, NULL, NULL, NULL);
                AVPicture output;
                avpicture_fill( &output, buffer, PIX_FMT_RGB24, width, height );
-               sws_scale( *context, frame->data, frame->linesize, 0, height,
+               sws_scale( context, frame->data, frame->linesize, 0, height,
                        output.data, output.linesize);
+               sws_freeContext( context );
        }
        else if ( *format == mlt_image_rgb24a || *format == mlt_image_opengl )
        {
-               *context = sws_getCachedContext( *context, width, height, pix_fmt,
+               struct SwsContext *context = sws_getContext( width, height, pix_fmt,
                        width, height, PIX_FMT_RGBA, flags | SWS_FULL_CHR_H_INT, NULL, NULL, NULL);
                AVPicture output;
                avpicture_fill( &output, buffer, PIX_FMT_RGBA, width, height );
-               sws_scale( *context, frame->data, frame->linesize, 0, height,
+               sws_scale( context, frame->data, frame->linesize, 0, height,
                        output.data, output.linesize);
+               sws_freeContext( context );
        }
        else
        {
-               *context = sws_getCachedContext( *context, width, height, pix_fmt,
+               struct SwsContext *context = sws_getContext( width, height, pix_fmt,
                        width, height, PIX_FMT_YUYV422, flags | SWS_FULL_CHR_H_INP, NULL, NULL, NULL);
                AVPicture output;
                avpicture_fill( &output, buffer, PIX_FMT_YUYV422, width, height );
-               sws_scale( *context, frame->data, frame->linesize, 0, height,
+               sws_scale( context, frame->data, frame->linesize, 0, height,
                        output.data, output.linesize);
+               sws_freeContext( context );
        }
 #else
        if ( *format == mlt_image_yuv420p )
@@ -763,7 +762,7 @@ static inline void convert_image( void **ctx, AVFrame *frame, uint8_t *buffer, i
                avpicture_fill( &output, buffer, PIX_FMT_RGB24, width, height );
                img_convert( &output, PIX_FMT_RGB24, (AVPicture *)frame, pix_fmt, width, height );
        }
-       else if ( *format == mlt_image_rgb24a || *format == mlt_image_opengl )
+       else if ( format == mlt_image_rgb24a || format == mlt_image_opengl )
        {
                AVPicture output;
                avpicture_fill( &output, buffer, PIX_FMT_RGB32, width, height );
@@ -1036,11 +1035,11 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form
                                picture.linesize[0] = codec_context->width;
                                picture.linesize[1] = codec_context->width / 2;
                                picture.linesize[2] = codec_context->width / 2;
-                               convert_image( (void**) &this->swscale, (AVFrame*) &picture, *buffer, PIX_FMT_YUV420P, format, *width, *height );
+                               convert_image( (AVFrame*) &picture, *buffer, PIX_FMT_YUV420P, format, *width, *height );
                        }
                        else
 #endif
-                       convert_image( (void**) &this->swscale, this->av_frame, *buffer, codec_context->pix_fmt, format, *width, *height );
+                       convert_image( this->av_frame, *buffer, codec_context->pix_fmt, format, *width, *height );
                }
                else
                        mlt_frame_get_image( frame, buffer, format, width, height, writable );
@@ -1222,7 +1221,7 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form
                                                        VdpStatus status = vdp_surface_get_bits( render->surface, dest_format, planes, pitches );
                                                        if ( status == VDP_STATUS_OK )
                                                        {
-                                                               convert_image( (void**) &this->swscale, (AVFrame*) &picture, *buffer, PIX_FMT_YUV420P, format, *width, *height );
+                                                               convert_image( (AVFrame*) &picture, *buffer, PIX_FMT_YUV420P, format, *width, *height );
                                                        }
                                                        else
                                                        {
@@ -1238,7 +1237,7 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form
                                        }
                                        else
 #endif
-                                       convert_image( (void**) &this->swscale, this->av_frame, *buffer, codec_context->pix_fmt, format, *width, *height );
+                                       convert_image( this->av_frame, *buffer, codec_context->pix_fmt, format, *width, *height );
                                        this->top_field_first |= this->av_frame->top_field_first;
                                        this->current_position = int_position;
                                        this->got_picture = 1;
@@ -2060,9 +2059,6 @@ static void producer_avformat_close( producer_avformat this )
        avformat_unlock();
 #ifdef VDPAU
        vdpau_producer_close( this );
-#endif
-#ifdef SWSCALE
-       sws_freeContext( this->swscale );
 #endif
        if ( this->image_cache )
                mlt_cache_close( this->image_cache );