]> git.sesse.net Git - mlt/blob - src/modules/opengl/filter_movit_convert.cpp
Let Movit effects supply their own fingerprint.
[mlt] / src / modules / opengl / filter_movit_convert.cpp
1 /*
2  * filter_movit_convert.cpp
3  * Copyright (C) 2013 Dan Dennedy <dan@dennedy.org>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software Foundation,
17  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 #include <framework/mlt.h>
21 #include <string.h>
22 #include <stdlib.h>
23 #include <assert.h>
24 #include <string>
25
26 #include "filter_glsl_manager.h"
27 #include <movit/effect_chain.h>
28 #include <movit/util.h>
29 #include "mlt_movit_input.h"
30 #include <mlt++/MltProducer.h>
31 #include "mlt_flip_effect.h"
32
33 static void set_movit_parameters( GlslChain *chain, mlt_service service, mlt_frame frame );
34
35 static void yuv422_to_yuv422p( uint8_t *yuv422, uint8_t *yuv422p, int width, int height )
36 {
37         uint8_t *Y = yuv422p;
38         uint8_t *U = Y + width * height;
39         uint8_t *V = U + width * height / 2;
40         int n = width * height / 2 + 1;
41         while ( --n ) {
42                 *Y++ = *yuv422++;
43                 *U++ = *yuv422++;
44                 *Y++ = *yuv422++;
45                 *V++ = *yuv422++;
46         }
47 }
48
49 static int convert_on_cpu( mlt_frame frame, uint8_t **image, mlt_image_format *format, mlt_image_format output_format )
50 {
51         int error = 0;
52         mlt_filter cpu_csc = (mlt_filter) mlt_properties_get_data( MLT_FRAME_PROPERTIES( frame ), "cpu_csc", NULL );
53         if ( cpu_csc ) {
54                 int (* save_fp )( mlt_frame self, uint8_t **image, mlt_image_format *input, mlt_image_format output )
55                         = frame->convert_image;
56                 frame->convert_image = NULL;
57                 mlt_filter_process( cpu_csc, frame );
58                 error = frame->convert_image( frame, image, format, output_format );
59                 frame->convert_image = save_fp;
60         } else {
61                 error = 1;
62         }
63         return error;
64 }
65
66 static void delete_chain( EffectChain* chain )
67 {
68         delete chain;
69 }
70
71 static void get_format_from_properties( mlt_properties properties, ImageFormat* image_format, YCbCrFormat* ycbcr_format )
72 {
73         switch ( mlt_properties_get_int( properties, "colorspace" ) ) {
74         case 601:
75                 ycbcr_format->luma_coefficients = YCBCR_REC_601;
76                 break;
77         case 709:
78         default:
79                 ycbcr_format->luma_coefficients = YCBCR_REC_709;
80                 break;
81         }
82
83         switch ( mlt_properties_get_int( properties, "color_primaries" ) ) {
84         case 601625:
85                 image_format->color_space = COLORSPACE_REC_601_625;
86                 break;
87         case 601525:
88                 image_format->color_space = COLORSPACE_REC_601_525;
89                 break;
90         case 709:
91         default:
92                 image_format->color_space = COLORSPACE_REC_709;
93                 break;
94         }
95
96         image_format->gamma_curve = GAMMA_REC_709;
97
98         if ( mlt_properties_get_int( properties, "force_full_luma" ) ) {
99                 ycbcr_format->full_range = true;
100         } else {
101                 ycbcr_format->full_range = ( mlt_properties_get_int( properties, "full_luma" ) == 1 );
102         }
103
104         // TODO: make new frame properties set by producers
105         ycbcr_format->cb_x_position = ycbcr_format->cr_x_position = 0.0f;
106         ycbcr_format->cb_y_position = ycbcr_format->cr_y_position = 0.5f;
107 }
108
109 static void build_fingerprint( mlt_service service, mlt_frame frame, std::string *fingerprint )
110 {
111         if ( service == (mlt_service) -1 ) {
112                 fingerprint->append( "input" );
113                 return;
114         }
115
116         Effect* effect = GlslManager::get_effect( service, frame );
117         assert( effect );
118         mlt_service input_a = GlslManager::get_effect_input( service, frame );
119         fingerprint->push_back( '(' );
120         build_fingerprint( input_a, frame, fingerprint );
121         fingerprint->push_back( ')' );
122
123         mlt_frame frame_b;
124         mlt_service input_b;
125         GlslManager::get_effect_secondary_input( service, frame, &input_b, &frame_b );
126         if ( input_b ) {
127                 fingerprint->push_back( '(' );
128                 build_fingerprint( input_b, frame_b, fingerprint );
129                 fingerprint->push_back( ')' );
130         }
131
132         fingerprint->push_back( '(' );
133         fingerprint->append( mlt_properties_get( MLT_SERVICE_PROPERTIES( service ), "_unique_id" ) );
134
135         const char* effect_fingerprint = mlt_properties_get( MLT_SERVICE_PROPERTIES( service ), "_movit fingerprint" );
136         if ( effect_fingerprint ) {
137                 fingerprint->push_back( '[' );
138                 fingerprint->append( effect_fingerprint );
139                 fingerprint->push_back( ']' );
140         }
141
142         bool disable = mlt_properties_get_int( MLT_SERVICE_PROPERTIES( service ), "movit.parms.int.disable" );
143         if ( disable ) {
144                 fingerprint->push_back( 'd' );
145         }
146         fingerprint->push_back( ')' );
147 }
148
149 static Effect* build_movit_chain( mlt_service service, mlt_frame frame, GlslChain *chain )
150 {
151         if ( service == (mlt_service) -1 ) {
152                 mlt_producer producer = mlt_producer_cut_parent( mlt_frame_get_original_producer( frame ) );
153                 MltInput* input = GlslManager::get_input( producer, frame );
154                 GlslManager::set_input( producer, frame, NULL );
155                 chain->effect_chain->add_input( input );
156                 chain->effects.insert(std::make_pair( MLT_SERVICE( producer ), input ) );
157                 return input;
158         }
159
160         Effect* effect = GlslManager::get_effect( service, frame );
161         assert( effect );
162         GlslManager::set_effect( service, frame, NULL );
163
164         mlt_service input_a = GlslManager::get_effect_input( service, frame );
165         mlt_service input_b;
166         mlt_frame frame_b;
167         GlslManager::get_effect_secondary_input( service, frame, &input_b, &frame_b );
168         Effect *effect_a = build_movit_chain( input_a, frame, chain );
169
170         if ( input_b ) {
171                 Effect *effect_b = build_movit_chain( input_b, frame_b, chain );
172                 chain->effect_chain->add_effect( effect, effect_a, effect_b );
173         } else {
174                 chain->effect_chain->add_effect( effect, effect_a );
175         }
176                 
177         chain->effects.insert(std::make_pair( service, effect ) );
178         return effect;
179 }
180
181 static void dispose_movit_effects( mlt_service service, mlt_frame frame )
182 {
183         if ( service == (mlt_service) -1 ) {
184                 mlt_producer producer = mlt_producer_cut_parent( mlt_frame_get_original_producer( frame ) );
185                 delete GlslManager::get_input( producer, frame );
186                 GlslManager::set_input( producer, frame, NULL );
187                 return;
188         }
189
190         delete GlslManager::get_effect( service, frame );
191         GlslManager::set_effect( service, frame, NULL );
192
193         mlt_service input_a = GlslManager::get_effect_input( service, frame );
194         mlt_service input_b;
195         mlt_frame frame_b;
196         GlslManager::get_effect_secondary_input( service, frame, &input_b, &frame_b );
197         dispose_movit_effects( input_a, frame );
198
199         if ( input_b ) {
200                 dispose_movit_effects( input_b, frame_b );
201         }
202 }
203
204 static void finalize_movit_chain( mlt_service leaf_service, mlt_frame frame )
205 {
206         GlslChain* chain = GlslManager::get_chain( leaf_service );
207
208         std::string new_fingerprint;
209         build_fingerprint( leaf_service, frame, &new_fingerprint );
210
211         // Build the chain if needed.
212         if ( !chain || new_fingerprint != chain->fingerprint ) {
213                 mlt_log_debug( leaf_service, "=== CREATING NEW CHAIN (old chain=%p, leaf=%p, fingerprint=%s) ===\n", chain, leaf_service, new_fingerprint.c_str() );
214                 mlt_profile profile = mlt_service_profile( leaf_service );
215                 chain = new GlslChain;
216                 chain->effect_chain = new EffectChain( profile->display_aspect_num, profile->display_aspect_den );
217                 chain->fingerprint = new_fingerprint;
218
219                 build_movit_chain( leaf_service, frame, chain );
220                 set_movit_parameters( chain, leaf_service, frame );
221                 chain->effect_chain->add_effect( new Mlt::VerticalFlip );
222
223                 ImageFormat output_format;
224                 output_format.color_space = COLORSPACE_sRGB;
225                 output_format.gamma_curve = GAMMA_sRGB;
226                 chain->effect_chain->add_output(output_format, OUTPUT_ALPHA_FORMAT_POSTMULTIPLIED);
227                 chain->effect_chain->set_dither_bits(8);
228                 chain->effect_chain->finalize();
229
230                 GlslManager::set_chain( leaf_service, chain );
231         } else {
232                 // Delete all the created Effect instances to avoid memory leaks.
233                 dispose_movit_effects( leaf_service, frame );
234         }
235 }
236
237 static void set_movit_parameters( GlslChain *chain, mlt_service service, mlt_frame frame )
238 {
239         if ( service == (mlt_service) -1 ) {
240                 mlt_producer producer = mlt_producer_cut_parent( mlt_frame_get_original_producer( frame ) );
241                 MltInput* input = (MltInput *) chain->effects[ MLT_PRODUCER_SERVICE( producer ) ];
242                 input->set_pixel_data( GlslManager::get_input_pixel_pointer( producer, frame ) );
243                 return;
244         }
245
246         Effect* effect = chain->effects[ service ];
247         mlt_service input_a = GlslManager::get_effect_input( service, frame );
248         set_movit_parameters( chain, input_a, frame );
249
250         mlt_service input_b;
251         mlt_frame frame_b;
252         GlslManager::get_effect_secondary_input( service, frame, &input_b, &frame_b );
253         if ( input_b ) {
254                 set_movit_parameters( chain, input_b, frame_b );
255         }
256                 
257         mlt_properties properties = MLT_SERVICE_PROPERTIES( service );
258         int count = mlt_properties_count( properties );
259         for (int i = 0; i < count; ++i) {
260                 const char *name = mlt_properties_get_name( properties, i );
261                 if (strncmp(name, "movit.parms.float.", strlen("movit.parms.float.")) == 0) {
262                         bool ok = effect->set_float(name + strlen("movit.parms.float."),
263                                 mlt_properties_get_double( properties, name ));
264                         assert(ok);
265                 }
266                 if (strncmp(name, "movit.parms.int.", strlen("movit.parms.int.")) == 0) {
267                         bool ok = effect->set_int(name + strlen("movit.parms.int."),
268                                 mlt_properties_get_int( properties, name ));
269                         assert(ok);
270                 }
271                 if (strncmp(name, "movit.parms.vec3.", strlen("movit.parms.vec3.")) == 0 &&
272                     strcmp(name + strlen(name) - 3, "[0]") == 0) {
273                         float val[3];
274                         char *name_copy = strdup(name);
275                         char *index_char = name_copy + strlen(name_copy) - 2;
276                         val[0] = mlt_properties_get_double( properties, name_copy );
277                         *index_char = '1';
278                         val[1] = mlt_properties_get_double( properties, name_copy );
279                         *index_char = '2';
280                         val[2] = mlt_properties_get_double( properties, name_copy );
281                         index_char[-1] = '\0';
282                         bool ok = effect->set_vec3(name_copy + strlen("movit.parms.vec3."), val);
283                         assert(ok);
284                         free(name_copy);
285                 }
286                 if (strncmp(name, "movit.parms.vec4.", strlen("movit.parms.vec4.")) == 0 &&
287                     strcmp(name + strlen(name) - 3, "[0]") == 0) {
288                         float val[4];
289                         char *name_copy = strdup(name);
290                         char *index_char = name_copy + strlen(name_copy) - 2;
291                         val[0] = mlt_properties_get_double( properties, name_copy );
292                         *index_char = '1';
293                         val[1] = mlt_properties_get_double( properties, name_copy );
294                         *index_char = '2';
295                         val[2] = mlt_properties_get_double( properties, name_copy );
296                         *index_char = '3';
297                         val[3] = mlt_properties_get_double( properties, name_copy );
298                         index_char[-1] = '\0';
299                         bool ok = effect->set_vec4(name_copy + strlen("movit.parms.vec4."), val);
300                         assert(ok);
301                         free(name_copy);
302                 }
303         }
304 }
305
306 static void dispose_pixel_pointers( mlt_service service, mlt_frame frame )
307 {
308         if ( service == (mlt_service) -1 ) {
309                 mlt_producer producer = mlt_producer_cut_parent( mlt_frame_get_original_producer( frame ) );
310                 mlt_pool_release( GlslManager::get_input_pixel_pointer( producer, frame ) );
311                 return;
312         }
313
314         mlt_service input_a = GlslManager::get_effect_input( service, frame );
315         dispose_pixel_pointers( input_a, frame );
316
317         mlt_service input_b;
318         mlt_frame frame_b;
319         GlslManager::get_effect_secondary_input( service, frame, &input_b, &frame_b );
320         if ( input_b ) {
321                 dispose_pixel_pointers( input_b, frame_b );
322         }
323 }
324
325 static int movit_render( EffectChain *chain, mlt_frame frame, mlt_image_format *format, mlt_image_format output_format, int width, int height, uint8_t **image )
326 {
327         GlslManager* glsl = GlslManager::get_instance();
328         int error;
329         if ( output_format == mlt_image_glsl_texture ) {
330                 error = glsl->render_frame_texture( chain, frame, width, height, image );
331         }
332         else {
333                 error = glsl->render_frame_rgba( chain, frame, width, height, image );
334                 if ( !error && output_format != mlt_image_rgb24a ) {
335                         *format = mlt_image_rgb24a;
336                         error = convert_on_cpu( frame, image, format, output_format );
337                 }
338         }
339         return error;
340 }
341
342 // Create an MltInput for an image with the given format and dimensions.
343 static MltInput* create_input( mlt_properties properties, mlt_image_format format, int aspect_width, int aspect_height, int width, int height )
344 {
345         MltInput* input = new MltInput( aspect_width, aspect_height );
346         if ( format == mlt_image_rgb24a || format == mlt_image_opengl ) {
347                 // TODO: Get the color space if available.
348                 input->useFlatInput( FORMAT_RGBA_POSTMULTIPLIED_ALPHA, width, height );
349         }
350         else if ( format == mlt_image_rgb24 ) {
351                 // TODO: Get the color space if available.
352                 input->useFlatInput( FORMAT_RGB, width, height );
353         }
354         else if ( format == mlt_image_yuv420p ) {
355                 ImageFormat image_format;
356                 YCbCrFormat ycbcr_format;
357                 get_format_from_properties( properties, &image_format, &ycbcr_format );
358                 ycbcr_format.chroma_subsampling_x = ycbcr_format.chroma_subsampling_y = 2;
359                 input->useYCbCrInput( image_format, ycbcr_format, width, height );
360         }
361         else if ( format == mlt_image_yuv422 ) {
362                 ImageFormat image_format;
363                 YCbCrFormat ycbcr_format;
364                 get_format_from_properties( properties, &image_format, &ycbcr_format );
365                 ycbcr_format.chroma_subsampling_x = 2;
366                 ycbcr_format.chroma_subsampling_y = 1;
367                 input->useYCbCrInput( image_format, ycbcr_format, width, height );
368         }
369         return input;
370 }
371
372 // Make a copy of the given image (allocated using mlt_pool_alloc) suitable
373 // to pass as pixel pointer to an MltInput (created using create_input
374 // with the same parameters), and return that pointer.
375 static uint8_t* make_input_copy( mlt_image_format format, uint8_t *image, int width, int height )
376 {
377         int img_size = mlt_image_format_size( format, width, height, NULL );
378         uint8_t* img_copy = (uint8_t*) mlt_pool_alloc( img_size );
379         if ( format == mlt_image_yuv422 ) {
380                 yuv422_to_yuv422p( image, img_copy, width, height );
381         } else {
382                 memcpy( img_copy, image, img_size );
383         }
384         return img_copy;
385 }
386
387 static int convert_image( mlt_frame frame, uint8_t **image, mlt_image_format *format, mlt_image_format output_format )
388 {
389         // Nothing to do!
390         if ( *format == output_format )
391                 return 0;
392
393         mlt_properties properties = MLT_FRAME_PROPERTIES( frame );
394
395         mlt_log_debug( NULL, "filter_movit_convert: %s -> %s (%d)\n",
396                 mlt_image_format_name( *format ), mlt_image_format_name( output_format ),
397                 mlt_frame_get_position( frame ) );
398
399         // Use CPU if glsl not initialized or not supported.
400         GlslManager* glsl = GlslManager::get_instance();
401         if ( !glsl || !glsl->get_int("glsl_supported" ) )
402                 return convert_on_cpu( frame, image, format, output_format );
403
404         // Do non-GL image conversions on a CPU-based image converter.
405         if ( *format != mlt_image_glsl && output_format != mlt_image_glsl && output_format != mlt_image_glsl_texture )
406                 return convert_on_cpu( frame, image, format, output_format );
407
408         int error = 0;
409         int width = mlt_properties_get_int( properties, "width" );
410         int height = mlt_properties_get_int( properties, "height" );
411         GlslManager::get_instance()->lock_service( frame );
412         
413         // If we're at the beginning of a series of Movit effects, store the input
414         // sent into the chain.
415         if ( output_format == mlt_image_glsl ) {
416                 mlt_producer producer = mlt_producer_cut_parent( mlt_frame_get_original_producer( frame ) );
417                 mlt_profile profile = mlt_service_profile( MLT_PRODUCER_SERVICE( producer ) );
418                 MltInput *input = create_input( properties, *format, profile->width, profile->height, width, height );
419                 GlslManager::set_input( producer, frame, input );
420                 uint8_t *img_copy = make_input_copy( *format, *image, width, height );
421                 GlslManager::set_input_pixel_pointer( producer, frame, img_copy );
422
423                 *image = (uint8_t *) -1;
424                 mlt_frame_set_image( frame, *image, 0, NULL );
425         }
426
427         // If we're at the _end_ of a series of Movit effects, render the chain.
428         if ( *format == mlt_image_glsl ) {
429                 mlt_service leaf_service = (mlt_service) *image;
430
431                 // Construct the chain unless we already have a good one.
432                 finalize_movit_chain( leaf_service, frame );
433
434                 // Set per-frame parameters now that we know which Effect instances to set them on.
435                 // (finalize_movit_chain may already have done this, though, but twice doesn't hurt.)
436                 GlslChain *chain = GlslManager::get_chain( leaf_service );
437                 set_movit_parameters( chain, leaf_service, frame );
438
439                 error = movit_render( chain->effect_chain, frame, format, output_format, width, height, image );
440
441                 dispose_pixel_pointers( leaf_service, frame );
442         }
443
444         // If we've been asked to render some frame directly to a texture (without any
445         // effects in-between), we create a new mini-chain to do so.
446         if ( *format != mlt_image_glsl && output_format == mlt_image_glsl_texture ) {
447                 // We might already have a texture from a previous conversion from mlt_image_glsl.
448                 glsl_texture texture = (glsl_texture) mlt_properties_get_data( properties, "movit.convert.texture", NULL );
449                 // XXX: requires a special property set on the frame by the app for now
450                 // because we do not have reliable way to clear the texture property
451                 // when a downstream filter has changed image.
452                 if ( texture && mlt_properties_get_int( properties, "movit.convert.use_texture") ) {
453                         *image = (uint8_t*) &texture->texture;
454                         mlt_frame_set_image( frame, *image, 0, NULL );
455                 } else {
456                         // Use a separate chain to convert image in RAM to OpenGL texture.
457                         // Use cached chain if available and compatible.
458                         Mlt::Producer producer( mlt_producer_cut_parent( mlt_frame_get_original_producer( frame ) ) );
459                         EffectChain *chain = (EffectChain*) producer.get_data( "movit.convert.chain" );
460                         MltInput *input = (MltInput*) producer.get_data( "movit.convert.input" );
461                         int w = producer.get_int( "movit.convert.width" );
462                         int h = producer.get_int( "movit.convert.height" );
463                         mlt_image_format f = (mlt_image_format) producer.get_int( "movit.convert.format" );
464                         if ( !chain || !input || width != w || height != h || *format != f ) {
465                                 chain = new EffectChain( width, height );
466                                 input = create_input( properties, *format, width, height, width, height );
467                                 chain->add_input( input );
468                                 chain->add_effect( new Mlt::VerticalFlip() );
469                                 ImageFormat movit_output_format;
470                                 movit_output_format.color_space = COLORSPACE_sRGB;
471                                 movit_output_format.gamma_curve = GAMMA_sRGB;
472                                 chain->add_output(movit_output_format, OUTPUT_ALPHA_FORMAT_POSTMULTIPLIED);
473                                 chain->set_dither_bits(8);
474                                 chain->finalize();
475                                 producer.set( "movit.convert.chain", chain, 0, (mlt_destructor) delete_chain );
476                                 producer.set( "movit.convert.input", input, 0, NULL );
477                                 producer.set( "movit.convert.width", width );
478                                 producer.set( "movit.convert.height", height );
479                                 producer.set( "movit.convert.format", *format );
480                         }
481
482                         if ( *format == mlt_image_yuv422 ) {
483                                 // We need to convert to planar, which make_input_copy() will do for us.
484                                 uint8_t *planar = make_input_copy( *format, *image, width, height );
485                                 input->set_pixel_data( planar );
486                                 error = movit_render( chain, frame, format, output_format, width, height, image );
487                                 mlt_pool_release( planar );
488                         } else {
489                                 input->set_pixel_data( *image );
490                                 error = movit_render( chain, frame, format, output_format, width, height, image );
491                         }
492                 }
493         }
494
495         GlslManager::get_instance()->unlock_service( frame );
496
497         mlt_properties_set_int( properties, "format", output_format );
498         *format = output_format;
499
500         return error;
501 }
502
503 static mlt_frame process( mlt_filter filter, mlt_frame frame )
504 {
505         // Set a default colorspace on the frame if not yet set by the producer.
506         // The producer may still change it during get_image.
507         // This way we do not have to modify each producer to set a valid colorspace.
508         mlt_properties properties = MLT_FRAME_PROPERTIES(frame);
509         if ( mlt_properties_get_int( properties, "colorspace" ) <= 0 )
510                 mlt_properties_set_int( properties, "colorspace", mlt_service_profile( MLT_FILTER_SERVICE(filter) )->colorspace );
511
512         frame->convert_image = convert_image;
513
514         mlt_filter cpu_csc = (mlt_filter) mlt_properties_get_data( MLT_FILTER_PROPERTIES( filter ), "cpu_csc", NULL );
515         mlt_properties_inc_ref( MLT_FILTER_PROPERTIES(cpu_csc) );
516         mlt_properties_set_data( properties, "cpu_csc", cpu_csc, 0,
517                 (mlt_destructor) mlt_filter_close, NULL );
518
519         return frame;
520 }
521
522 static mlt_filter create_filter( mlt_profile profile, const char *effect )
523 {
524         mlt_filter filter;
525         char *id = strdup( effect );
526         char *arg = strchr( id, ':' );
527         if ( arg != NULL )
528                 *arg ++ = '\0';
529
530         // The swscale and avcolor_space filters require resolution as arg to test compatibility
531         if ( !strcmp( effect, "avcolor_space" ) )
532                 filter = mlt_factory_filter( profile, id, &profile->width );
533         else
534                 filter = mlt_factory_filter( profile, id, arg );
535         if ( filter )
536                 mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "_loader", 1 );
537         free( id );
538         return filter;
539 }
540
541 extern "C" {
542
543 mlt_filter filter_movit_convert_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg )
544 {
545         mlt_filter filter = NULL;
546         GlslManager* glsl = GlslManager::get_instance();
547
548         if ( glsl && ( filter = mlt_filter_new() ) )
549         {
550 #ifdef WIN32
551                 // XXX avcolor_space is crashing on Windows in this context!
552                 mlt_filter cpu_csc = NULL;
553 #else
554                 mlt_filter cpu_csc = create_filter( profile, "avcolor_space" );
555 #endif
556                 if ( !cpu_csc )
557                         cpu_csc = create_filter( profile, "imageconvert" );
558                 if ( cpu_csc )
559                         mlt_properties_set_data( MLT_FILTER_PROPERTIES( filter ), "cpu_csc", cpu_csc, 0,
560                                 (mlt_destructor) mlt_filter_close, NULL );
561                 filter->process = process;
562         }
563         return filter;
564 }
565
566 }