X-Git-Url: http://research.m1stereo.tv/gitweb?a=blobdiff_plain;f=src%2Fmodules%2Fcore%2Ffilter_data_show.c;h=6782a8b1270d663fd11c8779e1621092ecbe4185;hb=fece0ecea4efde1a2df3d78f793935315dcb2c02;hp=b8fcd4cfde90d55f4dd53b671552714665e2fb89;hpb=9ee9f721d85c1dd4df071034b6cef3ea1eb768a0;p=melted diff --git a/src/modules/core/filter_data_show.c b/src/modules/core/filter_data_show.c index b8fcd4c..6782a8b 100644 --- a/src/modules/core/filter_data_show.c +++ b/src/modules/core/filter_data_show.c @@ -3,22 +3,21 @@ * Copyright (C) 2004-2005 Ushodaya Enterprises Limited * Author: Charles Yates * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. * - * This program is distributed in the hope that it will be useful, + * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "filter_data.h" #include #include #include @@ -51,9 +50,9 @@ static mlt_filter obtain_filter( mlt_filter filter, char *type ) // If none is specified, pick up the default for this normalisation if ( profile == NULL ) - sprintf( temp, "%s/feeds/%s/data_fx.properties", mlt_factory_prefix( ), mlt_environment( "MLT_NORMALISATION" ) ); + sprintf( temp, "%s/feeds/%s/data_fx.properties", mlt_environment( "MLT_DATA" ), mlt_environment( "MLT_NORMALISATION" ) ); else if ( strchr( profile, '%' ) ) - sprintf( temp, "%s/feeds/%s/%s", mlt_factory_prefix( ), mlt_environment( "MLT_NORMALISATION" ), strchr( profile, '%' ) + 1 ); + sprintf( temp, "%s/feeds/%s/%s", mlt_environment( "MLT_DATA" ), mlt_environment( "MLT_NORMALISATION" ), strchr( profile, '%' ) + 1 ); else strcpy( temp, profile ); @@ -72,7 +71,7 @@ static mlt_filter obtain_filter( mlt_filter filter, char *type ) char *value = mlt_properties_get_value( profile_properties, i ); if ( result == NULL && !strcmp( name, type ) && result == NULL ) - result = mlt_factory_filter( value, NULL ); + result = mlt_factory_filter( mlt_service_profile( MLT_FILTER_SERVICE( filter ) ), value, NULL ); else if ( result != NULL && !strncmp( name, type, type_len ) && name[ type_len ] == '.' ) mlt_properties_set( MLT_FILTER_PROPERTIES( result ), name + type_len + 1, value ); else if ( result != NULL ) @@ -86,21 +85,23 @@ static mlt_filter obtain_filter( mlt_filter filter, char *type ) /** Retrieve medatata value */ -const char* metadata_value(mlt_properties properties, char* name) +char* metadata_value(mlt_properties properties, char* name) { - if (name == NULL) return "-"; + if (name == NULL) return NULL; char *meta = malloc( strlen(name) + 18 ); sprintf( meta, "meta.attr.%s.markup", name); - return mlt_properties_get( properties, meta); + char *result = mlt_properties_get( properties, meta); + free(meta); + return result; } /** Convert frames to Timecode */ -const char* frame_to_timecode( int frames , int fps) +char* frame_to_timecode( int frames , int fps) { + if (fps == 0) return strdup("-"); char *res = malloc(12); - if (fps == 0) return "-"; int seconds = frames / (int) fps; frames = frames % ((int) fps); int minutes = seconds / 60; @@ -172,33 +173,49 @@ static int process_feed( mlt_properties feed, mlt_filter filter, mlt_frame frame else { char *value = mlt_properties_get( feed, name + len ); - if ( value != NULL ) { + if ( value != NULL ) + { // check for metadata keywords in metadata markup if user requested so if ( mlt_properties_get_int( filter_properties, "dynamic" ) == 1 && !strcmp( name + strlen( name ) - 6, "markup") ) { // Find keywords which should be surrounded by '#', like: #title# - char* keywords = strtok ( value, "\\#" ); - char result[] = ""; + char* keywords = strtok( value, "#" ); + char result[512] = ""; // XXX: how much is enough? int ct = 0; - int fromStart = 0; - if ( value[0] == '\\' ) fromStart = 1; + int fromStart = ( value[0] == '#' ) ? 1 : 0; - while (keywords != NULL) { - if (ct % 2 == fromStart) - strcat( result, keywords); - else if (!strcmp(keywords, "timecode")) { - // special case: replace #tc# with current frame timecode + while ( keywords != NULL ) + { + if ( ct % 2 == fromStart ) + { + // backslash in front of # suppresses substitution + if ( keywords[ strlen( keywords ) -1 ] == '\\' ) + { + // keep characters except backslash + strncat( result, keywords, strlen( keywords ) -1 ); + strcat( result, "#" ); + ct++; + } + else + { + strcat( result, keywords ); + } + } + else if ( !strcmp( keywords, "timecode" ) ) + { + // special case: replace #timecode# with current frame timecode int pos = mlt_properties_get_int( feed, "position" ); - const char *tc = frame_to_timecode(pos, mlt_properties_get_int( MLT_FRAME_PROPERTIES( frame ), "fps" )); - strcat( result, tc); + char *tc = frame_to_timecode( pos, mlt_profile_fps( mlt_service_profile( MLT_FILTER_SERVICE( filter ) ) ) ); + strcat( result, tc ); + free( tc ); } - else { + else + { // replace keyword with metadata value - const char * metavalue = metadata_value(MLT_FRAME_PROPERTIES( frame ), keywords); - if (metavalue == NULL) metavalue = "-"; - strcat( result, metavalue); + char *metavalue = metadata_value( MLT_FRAME_PROPERTIES( frame ), keywords ); + strcat( result, metavalue ? metavalue : "-" ); } - keywords = strtok ( NULL, "\\#" ); + keywords = strtok( NULL, "#" ); ct++; } mlt_properties_set( properties, key, (char*) result ); @@ -303,7 +320,7 @@ static mlt_frame filter_process( mlt_filter this, mlt_frame frame ) /** Constructor for the filter. */ -mlt_filter filter_data_show_init( char *arg ) +mlt_filter filter_data_show_init( mlt_profile profile, mlt_service_type type, const char *id, void *arg ) { // Create the filter mlt_filter this = mlt_filter_new( );