Skip to content

Commit

Permalink
Fix qtext glitches with multiple threads.
Browse files Browse the repository at this point in the history
  • Loading branch information
ddennedy committed Jan 4, 2019
1 parent 5ffd91d commit d0d0392
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 75 deletions.
39 changes: 6 additions & 33 deletions src/modules/plus/filter_dynamictext.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,6 @@

#define MAX_TEXT_LEN 512

static void property_changed( mlt_service owner, mlt_filter filter, char *name )
{
if( !strcmp( "geometry", name ) ||
!strcmp( "family", name ) ||
!strcmp( "size", name ) ||
!strcmp( "weight", name ) ||
!strcmp( "style", name ) ||
!strcmp( "fgcolour", name ) ||
!strcmp( "bgcolour", name ) ||
!strcmp( "olcolour", name ) ||
!strcmp( "pad", name ) ||
!strcmp( "halign", name ) ||
!strcmp( "valign", name ) ||
!strcmp( "outline", name ) ||
!strcmp( "in", name ) ||
!strcmp( "out", name ))
{
mlt_properties_set_int( MLT_FILTER_PROPERTIES(filter), "_reset", 1 );
}
}

/** Get the next token and indicate whether it is enclosed in "# #".
*/
static int get_next_token(char* str, int* pos, char* token, int* is_keyword)
Expand Down Expand Up @@ -251,17 +230,15 @@ static mlt_frame filter_process( mlt_filter filter, mlt_frame frame )
return frame;

mlt_filter text_filter = mlt_properties_get_data( properties, "_text_filter", NULL );
mlt_properties text_filter_properties = MLT_FILTER_PROPERTIES( text_filter );
mlt_properties text_filter_properties = mlt_frame_unique_properties( frame, MLT_FILTER_SERVICE(text_filter));

// Apply keyword substitution before passing the text to the filter.
char result[MAX_TEXT_LEN] = "";
char* result = calloc( 1, MAX_TEXT_LEN );
substitute_keywords( filter, result, dynamic_text, frame );
mlt_properties_set( text_filter_properties, "argument", (char*)result );
if( mlt_properties_get_int( properties, "_reset" ) )
{
mlt_properties_pass_list( text_filter_properties, properties,
"geometry family size weight style fgcolour bgcolour olcolour pad halign valign outline in out" );
}
mlt_properties_set( text_filter_properties, "argument", result );
free( result );
mlt_properties_pass_list( text_filter_properties, properties,
"geometry family size weight style fgcolour bgcolour olcolour pad halign valign outline in out" );
return mlt_filter_process( text_filter, frame );
}

Expand All @@ -285,9 +262,6 @@ mlt_filter filter_dynamictext_init( mlt_profile profile, mlt_service_type type,
// Register the text filter for reuse/destruction
mlt_properties_set_data( my_properties, "_text_filter", text_filter, 0, ( mlt_destructor )mlt_filter_close, NULL );

// Listen for property changes.
mlt_events_listen( MLT_FILTER_PROPERTIES(filter), filter, "property-changed", (mlt_listener)property_changed );

// Assign default values
mlt_properties_set( my_properties, "argument", arg ? arg: "#timecode#" );
mlt_properties_set( my_properties, "geometry", "0%/0%:100%x100%:100%" );
Expand All @@ -302,7 +276,6 @@ mlt_filter filter_dynamictext_init( mlt_profile profile, mlt_service_type type,
mlt_properties_set( my_properties, "halign", "left" );
mlt_properties_set( my_properties, "valign", "top" );
mlt_properties_set( my_properties, "outline", "0" );
mlt_properties_set_int( my_properties, "_reset", 1 );
mlt_properties_set_int( my_properties, "_filter_private", 1 );

filter->process = filter_process;
Expand Down
39 changes: 6 additions & 33 deletions src/modules/plus/filter_timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,6 @@

#define MAX_TEXT_LEN 512

static void property_changed( mlt_service owner, mlt_filter filter, char *name )
{
if( !strcmp( "geometry", name ) ||
!strcmp( "family", name ) ||
!strcmp( "size", name ) ||
!strcmp( "weight", name ) ||
!strcmp( "style", name ) ||
!strcmp( "fgcolour", name ) ||
!strcmp( "bgcolour", name ) ||
!strcmp( "olcolour", name ) ||
!strcmp( "pad", name ) ||
!strcmp( "halign", name ) ||
!strcmp( "valign", name ) ||
!strcmp( "outline", name ) ||
!strcmp( "in", name ) ||
!strcmp( "out", name ) )
{
mlt_properties_set_int( MLT_FILTER_PROPERTIES(filter), "_reset", 1 );
}
}

double time_to_seconds( char* time )
{
int hours = 0;
Expand Down Expand Up @@ -131,15 +110,13 @@ static mlt_frame filter_process( mlt_filter filter, mlt_frame frame )
{
mlt_properties properties = MLT_FILTER_PROPERTIES( filter );
mlt_filter text_filter = mlt_properties_get_data( properties, "_text_filter", NULL );
mlt_properties text_filter_properties = MLT_FILTER_PROPERTIES( text_filter );
char result[MAX_TEXT_LEN] = "";
mlt_properties text_filter_properties = mlt_frame_unique_properties( frame, MLT_FILTER_SERVICE(text_filter));
char* result = calloc( 1, MAX_TEXT_LEN );
get_timer_str( filter, frame, result );
mlt_properties_set( text_filter_properties, "argument", (char*)result );
if( mlt_properties_get_int( properties, "_reset" ) )
{
mlt_properties_pass_list( text_filter_properties, properties,
"geometry family size weight style fgcolour bgcolour olcolour pad halign valign outline in out" );
}
mlt_properties_set( text_filter_properties, "argument", result );
free( result );
mlt_properties_pass_list( text_filter_properties, properties,
"geometry family size weight style fgcolour bgcolour olcolour pad halign valign outline in out" );
return mlt_filter_process( text_filter, frame );
}

Expand All @@ -163,9 +140,6 @@ mlt_filter filter_timer_init( mlt_profile profile, mlt_service_type type, const
// Register the text filter for reuse/destruction
mlt_properties_set_data( my_properties, "_text_filter", text_filter, 0, ( mlt_destructor )mlt_filter_close, NULL );

// Listen for property changes.
mlt_events_listen( MLT_FILTER_PROPERTIES(filter), filter, "property-changed", (mlt_listener)property_changed );

// Assign default values
mlt_properties_set( my_properties, "format", "SS.SS" );
mlt_properties_set( my_properties, "start", "00:00:00.000" );
Expand All @@ -183,7 +157,6 @@ mlt_filter filter_timer_init( mlt_profile profile, mlt_service_type type, const
mlt_properties_set( my_properties, "halign", "left" );
mlt_properties_set( my_properties, "valign", "top" );
mlt_properties_set( my_properties, "outline", "0" );
mlt_properties_set_int( my_properties, "_reset", 1 );
mlt_properties_set_int( my_properties, "_filter_private", 1 );

filter->process = filter_process;
Expand Down
20 changes: 11 additions & 9 deletions src/modules/qt/filter_qtext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include <framework/mlt.h>
#include <framework/mlt_log.h>
#include <QPainter>
#include <QTextCodec>
#include <QString>

static QRectF get_text_path( QPainterPath* qpath, mlt_properties filter_properties, const char* text )
Expand All @@ -37,10 +36,7 @@ static QRectF get_text_path( QPainterPath* qpath, mlt_properties filter_properti
qpath->setFillRule( Qt::WindingFill );

// Get the strings to display
QTextCodec *codec = QTextCodec::codecForName( mlt_properties_get( filter_properties, "encoding" ) );
QTextDecoder *decoder = codec->makeDecoder();
QString s = decoder->toUnicode( text );
delete decoder;
QString s = QString::fromUtf8(text);
QStringList lines = s.split( "\n" );

// Configure the font
Expand Down Expand Up @@ -225,12 +221,20 @@ static void paint_text( QPainter* painter, QPainterPath* qpath, mlt_properties f
painter->drawPath( *qpath );
}

static mlt_properties get_filter_properties( mlt_filter filter, mlt_frame frame )
{
mlt_properties properties = mlt_frame_get_unique_properties( frame, MLT_FILTER_SERVICE(filter) );
if ( !properties )
properties = MLT_FILTER_PROPERTIES(filter);
return properties;
}

static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format *image_format, int *width, int *height, int writable )
{
int error = 0;
mlt_filter filter = (mlt_filter)mlt_frame_pop_service( frame );
char* argument = (char*)mlt_frame_pop_service( frame );
mlt_properties filter_properties = MLT_FILTER_PROPERTIES( filter );
mlt_properties filter_properties = get_filter_properties( filter, frame );
mlt_profile profile = mlt_service_profile(MLT_FILTER_SERVICE(filter));
mlt_position position = mlt_filter_get_position( filter, frame );
mlt_position length = mlt_filter_get_length2( filter, frame );
Expand Down Expand Up @@ -283,7 +287,7 @@ static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format

static mlt_frame filter_process( mlt_filter filter, mlt_frame frame )
{
mlt_properties properties = MLT_FILTER_PROPERTIES( filter );
mlt_properties properties = get_filter_properties( filter, frame );
char* argument = mlt_properties_get( properties, "argument" );
if ( !argument || !strcmp( "", argument ) )
return frame;
Expand Down Expand Up @@ -334,8 +338,6 @@ mlt_filter filter_qtext_init( mlt_profile profile, mlt_service_type type, const
mlt_properties_set( filter_properties, "halign", "left" );
mlt_properties_set( filter_properties, "valign", "top" );
mlt_properties_set( filter_properties, "outline", "0" );
mlt_properties_set( filter_properties, "encoding", "UTF-8" );

mlt_properties_set_int( filter_properties, "_filter_private", 1 );

return filter;
Expand Down

0 comments on commit d0d0392

Please sign in to comment.