From 51f99c29759e71318c4c575f8a68cf1b5d1c5137 Mon Sep 17 00:00:00 2001 From: ddennedy Date: Tue, 13 Jan 2009 06:17:43 +0000 Subject: [PATCH] mlt_log.[hc], mlt_transition.c, mlt_tractor.c, mlt_repository.c, mlt_properties.c, mlt_producer.c, mlt_pool.c, mlt_events.c, mlt_consumer.c, mlt.h, Makefile: add logging system based on FFmpeg's. git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt@1313 d19143bc-622f-0410-bfdd-b5b2a6649095 --- src/framework/Makefile | 6 ++- src/framework/mlt.h | 1 + src/framework/mlt_consumer.c | 10 ++-- src/framework/mlt_events.c | 3 +- src/framework/mlt_log.c | 80 ++++++++++++++++++++++++++++++++++++ src/framework/mlt_log.h | 87 ++++++++++++++++++++++++++++++++++++++++ src/framework/mlt_pool.c | 6 +- src/framework/mlt_producer.c | 8 +-- src/framework/mlt_properties.c | 5 +- src/framework/mlt_repository.c | 3 +- src/framework/mlt_tractor.c | 3 +- src/framework/mlt_transition.c | 3 +- 12 files changed, 193 insertions(+), 22 deletions(-) create mode 100644 src/framework/mlt_log.c create mode 100644 src/framework/mlt_log.h diff --git a/src/framework/Makefile b/src/framework/Makefile index e423319..9112ff1 100644 --- a/src/framework/Makefile +++ b/src/framework/Makefile @@ -35,7 +35,8 @@ OBJS = mlt_frame.o \ mlt_repository.o \ mlt_pool.o \ mlt_tokeniser.o \ - mlt_profile.o + mlt_profile.o \ + mlt_log.o INCS = mlt_consumer.h \ mlt_factory.h \ @@ -59,7 +60,8 @@ INCS = mlt_consumer.h \ mlt_service.h \ mlt_transition.h \ mlt_tokeniser.h \ - mlt_profile.h + mlt_profile.h \ + mlt_log.h SRCS := $(OBJS:.o=.c) diff --git a/src/framework/mlt.h b/src/framework/mlt.h index d4e2721..8c3dc0f 100644 --- a/src/framework/mlt.h +++ b/src/framework/mlt.h @@ -46,6 +46,7 @@ extern "C" #include "mlt_geometry.h" #include "mlt_profile.h" #include "mlt_repository.h" +#include "mlt_log.h" #ifdef __cplusplus } diff --git a/src/framework/mlt_consumer.c b/src/framework/mlt_consumer.c index 57c5b1d..04ef94e 100644 --- a/src/framework/mlt_consumer.c +++ b/src/framework/mlt_consumer.c @@ -25,6 +25,7 @@ #include "mlt_producer.h" #include "mlt_frame.h" #include "mlt_profile.h" +#include "mlt_log.h" #include #include @@ -924,22 +925,21 @@ int mlt_consumer_stop( mlt_consumer this ) { // Get the properies mlt_properties properties = MLT_CONSUMER_PROPERTIES( this ); - char *debug = mlt_properties_get( MLT_CONSUMER_PROPERTIES( this ), "debug" ); // Just in case... - if ( debug ) fprintf( stderr, "%s: stopping put waiting\n", debug ); + mlt_log( MLT_CONSUMER_SERVICE( this ), MLT_LOG_DEBUG, "stopping put waiting\n" ); pthread_mutex_lock( &this->put_mutex ); this->put_active = 0; pthread_cond_broadcast( &this->put_cond ); pthread_mutex_unlock( &this->put_mutex ); // Stop the consumer - if ( debug ) fprintf( stderr, "%s: stopping consumer\n", debug ); + mlt_log( MLT_CONSUMER_SERVICE( this ), MLT_LOG_DEBUG, "stopping consumer\n" ); if ( this->stop != NULL ) this->stop( this ); // Check if the user has requested real time or not and stop if necessary - if ( debug ) fprintf( stderr, "%s: stopping read_ahead\n", debug ); + mlt_log( MLT_CONSUMER_SERVICE( this ), MLT_LOG_DEBUG, "stopping read_ahead\n" ); if ( mlt_properties_get_int( properties, "real_time" ) ) consumer_read_ahead_stop( this ); @@ -950,7 +950,7 @@ int mlt_consumer_stop( mlt_consumer this ) if ( mlt_properties_get( properties, "post" ) ) system( mlt_properties_get( properties, "post" ) ); - if ( debug ) fprintf( stderr, "%s: stopped\n", debug ); + mlt_log( MLT_CONSUMER_SERVICE( this ), MLT_LOG_DEBUG, "stopped\n" ); return 0; } diff --git a/src/framework/mlt_events.c b/src/framework/mlt_events.c index 6732ebd..1439e3c 100644 --- a/src/framework/mlt_events.c +++ b/src/framework/mlt_events.c @@ -117,8 +117,7 @@ void mlt_event_close( mlt_event this ) if ( this->ref_count <= 0 ) { #ifdef _MLT_EVENT_CHECKS_ - events_destroyed ++; - fprintf( stderr, "Events created %d, destroyed %d\n", events_created, events_destroyed ); + mlt_log( NULL, MLT_LOG_DEBUG, "Events created %d, destroyed %d\n", events_created, ++events_destroyed ); #endif free( this ); } diff --git a/src/framework/mlt_log.c b/src/framework/mlt_log.c new file mode 100644 index 0000000..9a4c70b --- /dev/null +++ b/src/framework/mlt_log.c @@ -0,0 +1,80 @@ +/** + * \file mlt_log.c + * \brief logging functions + * + * Copyright (c) 2003 Michel Bardiaux + * + * This file was a part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "mlt_log.h" +#include "mlt_service.h" + +#include + +static int log_level = MLT_LOG_INFO; + +void default_callback( void* ptr, int level, const char* fmt, va_list vl ) +{ + static int print_prefix = 1; + mlt_properties properties = ptr ? MLT_SERVICE_PROPERTIES( ( mlt_service )ptr ) : NULL; + + if ( level > log_level ) + return; + if ( print_prefix && properties ) + { + char *mlt_type = mlt_properties_get( properties, "mlt_type" ); + char *resource = mlt_properties_get( properties, "resource" ); + + if ( resource && *resource && resource[0] == '<' && resource[ strlen(resource) - 1 ] == '>' ) + mlt_type = resource; + fprintf( stderr, "[%s @ %p]", mlt_type, ptr ); + } + print_prefix = strstr( fmt, "\n" ) != NULL; + vfprintf( stderr, fmt, vl ); +} + +static void ( *callback )( void*, int, const char*, va_list ) = default_callback; + +void mlt_log( void* service, int level, const char *fmt, ...) +{ + va_list vl; + + va_start( vl, fmt ); + mlt_vlog( service, level, fmt, vl ); + va_end( vl ); +} + +void mlt_vlog( void* service, int level, const char *fmt, va_list vl ) +{ + if ( callback ) callback( service, level, fmt, vl ); +} + +int mlt_log_get_level( void ) +{ + return log_level; +} + +void mlt_log_set_level( int level ) +{ + log_level = level; +} + +void mlt_log_set_callback( void (*new_callback)( void*, int, const char*, va_list ) ) +{ + callback = new_callback; +} diff --git a/src/framework/mlt_log.h b/src/framework/mlt_log.h new file mode 100644 index 0000000..b57f402 --- /dev/null +++ b/src/framework/mlt_log.h @@ -0,0 +1,87 @@ +/** + * \file mlt_log.h + * \brief logging functions + * + * copyright (c) 2006 Michael Niedermayer + * + * This file was a part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef MLT_LOG_H +#define MLT_LOG_H + +#include + +#define MLT_LOG_QUIET -8 + +/** + * something went really wrong and we will crash now + */ +#define MLT_LOG_PANIC 0 + +/** + * something went wrong and recovery is not possible + * like no header in a format which depends on it or a combination + * of parameters which are not allowed + */ +#define MLT_LOG_FATAL 8 + +/** + * something went wrong and cannot losslessly be recovered + * but not all future data is affected + */ +#define MLT_LOG_ERROR 16 + +/** + * something somehow does not look correct / something which may or may not + * lead to some problems + */ +#define MLT_LOG_WARNING 24 + +#define MLT_LOG_INFO 32 +#define MLT_LOG_VERBOSE 40 + +/** + * stuff which is only useful for MLT developers + */ +#define MLT_LOG_DEBUG 48 + +/** + * Send the specified message to the log if the level is less than or equal to + * the current logging level. By default, all logging messages are sent to + * stderr. This behavior can be altered by setting a different mlt_vlog callback + * function. + * + * \param service An optional pointer to a \p mlt_service_s. + * \param level The importance level of the message, lower values signifying + * higher importance. + * \param fmt The format string (printf-compatible) that specifies how + * subsequent arguments are converted to output. + * \see mlt_vlog + */ +#ifdef __GNUC__ +void mlt_log( void *service, int level, const char *fmt, ... ) __attribute__ ((__format__ (__printf__, 3, 4))); +#else +void mlt_log( void *service, int level, const char *fmt, ... ); +#endif + +void mlt_vlog( void *service, int level, const char *fmt, va_list ); +int mlt_log_get_level( void ); +void mlt_log_set_level( int ); +void mlt_log_set_callback( void (*)( void*, int, const char*, va_list ) ); + +#endif /* MLT_LOG_H */ diff --git a/src/framework/mlt_pool.c b/src/framework/mlt_pool.c index d58d02c..e4d47dd 100644 --- a/src/framework/mlt_pool.c +++ b/src/framework/mlt_pool.c @@ -344,13 +344,13 @@ void mlt_pool_close( ) #ifdef _MLT_POOL_CHECKS_ // Stats dump on close int i = 0; - fprintf( stderr, "Usage:\n\n" ); for ( i = 0; i < mlt_properties_count( pools ); i ++ ) { mlt_pool pool = mlt_properties_get_data_at( pools, i, NULL ); if ( pool->count ) - fprintf( stderr, "%d: allocated %d returned %d %c\n", pool->size, pool->count, mlt_deque_count( pool->stack ), - pool->count != mlt_deque_count( pool->stack ) ? '*' : ' ' ); + mlt_log( NULL, MLT_LOG_DEBUG, "%s: size %d allocated %d returned %d %c\n", __FUNCTION__, + pool->size, pool->count, mlt_deque_count( pool->stack ), + pool->count != mlt_deque_count( pool->stack ) ? '*' : ' ' ); } #endif diff --git a/src/framework/mlt_producer.c b/src/framework/mlt_producer.c index 2202f55..2a6a487 100644 --- a/src/framework/mlt_producer.c +++ b/src/framework/mlt_producer.c @@ -25,6 +25,7 @@ #include "mlt_frame.h" #include "mlt_parser.h" #include "mlt_profile.h" +#include "mlt_log.h" #include #include @@ -610,7 +611,7 @@ static int producer_get_frame( mlt_service service, mlt_frame_ptr frame, int ind char key[ 25 ]; sprintf( key, "_clone.%d", clone_index - 1 ); clone = mlt_properties_get_data( MLT_PRODUCER_PROPERTIES( mlt_producer_cut_parent( this ) ), key, NULL ); - if ( clone == NULL ) fprintf( stderr, "requested clone doesn't exist %d\n", clone_index ); + if ( clone == NULL ) mlt_log( service, MLT_LOG_ERROR, "requested clone doesn't exist %d\n", clone_index ); clone = clone == NULL ? this : clone; } else @@ -1016,11 +1017,8 @@ void mlt_producer_close( mlt_producer this ) #endif #ifdef _MLT_PRODUCER_CHECKS_ - // Increment destroyed count - producers_destroyed ++; - // Show current stats - these should match when the app is closed - fprintf( stderr, "Producers created %d, destroyed %d\n", producers_created, producers_destroyed ); + mlt_log( MLT_PRODUCER_SERVICE( this ), MLT_LOG_DEBUG, "Producers created %d, destroyed %d\n", producers_created, ++producers_destroyed ); #endif mlt_service_close( &this->parent ); diff --git a/src/framework/mlt_properties.c b/src/framework/mlt_properties.c index cf9e522..6057b68 100644 --- a/src/framework/mlt_properties.c +++ b/src/framework/mlt_properties.c @@ -24,6 +24,7 @@ #include "mlt_properties.h" #include "mlt_property.h" #include "mlt_deque.h" +#include "mlt_log.h" #include #include @@ -498,7 +499,7 @@ int mlt_properties_set( mlt_properties this, const char *name, const char *value // Set it if not NULL if ( property == NULL ) { - fprintf( stderr, "Whoops - %s not found (should never occur)\n", name ); + mlt_log( NULL, MLT_LOG_FATAL, "Whoops - %s not found (should never occur)\n", name ); } else if ( value == NULL ) { @@ -1149,7 +1150,7 @@ void mlt_properties_close( mlt_properties this ) properties_destroyed ++; // Show current stats - these should match when the app is closed - fprintf( stderr, "Created %d, destroyed %d\n", properties_created, properties_destroyed ); + mlt_log( NULL, MLT_LOG_DEBUG, "Created %d, destroyed %d\n", properties_created, properties_destroyed ); #endif // Clean up names and values diff --git a/src/framework/mlt_repository.c b/src/framework/mlt_repository.c index 7150397..df83e9e 100644 --- a/src/framework/mlt_repository.c +++ b/src/framework/mlt_repository.c @@ -24,6 +24,7 @@ #include "mlt_repository.h" #include "mlt_properties.h" #include "mlt_tokeniser.h" +#include "mlt_log.h" #include #include @@ -99,7 +100,7 @@ mlt_repository mlt_repository_init( const char *directory ) } else if ( strstr( object_name, "libmlt" ) ) { - fprintf( stderr, "%s, %s: failed to dlopen %s\n (%s)\n", __FILE__, __FUNCTION__, object_name, dlerror() ); + mlt_log( NULL, MLT_LOG_WARNING, "%s: failed to dlopen %s\n (%s)\n", __FUNCTION__, object_name, dlerror() ); } } diff --git a/src/framework/mlt_tractor.c b/src/framework/mlt_tractor.c index 848f7e4..0892953 100644 --- a/src/framework/mlt_tractor.c +++ b/src/framework/mlt_tractor.c @@ -24,6 +24,7 @@ #include "mlt_frame.h" #include "mlt_multitrack.h" #include "mlt_field.h" +#include "mlt_log.h" #include #include @@ -502,7 +503,7 @@ static int producer_get_frame( mlt_producer parent, mlt_frame_ptr frame, int tra } else { - fprintf( stderr, "tractor without a multitrack!!\n" ); + mlt_log( MLT_PRODUCER_SERVICE( parent ), MLT_LOG_ERROR, "tractor without a multitrack!!\n" ); mlt_service_get_frame( this->producer, frame, track ); } diff --git a/src/framework/mlt_transition.c b/src/framework/mlt_transition.c index d7e6d5d..19a308a 100644 --- a/src/framework/mlt_transition.c +++ b/src/framework/mlt_transition.c @@ -22,6 +22,7 @@ #include "mlt_transition.h" #include "mlt_frame.h" +#include "mlt_log.h" #include #include @@ -311,7 +312,7 @@ static int transition_get_frame( mlt_service service, mlt_frame_ptr frame, int i break; default: - fprintf( stderr, "invalid transition type\n" ); + mlt_log( service, MLT_LOG_ERROR, "invalid transition type\n" ); break; } -- 1.7.4.4