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 \
mlt_service.h \
mlt_transition.h \
mlt_tokeniser.h \
- mlt_profile.h
+ mlt_profile.h \
+ mlt_log.h
SRCS := $(OBJS:.o=.c)
#include "mlt_geometry.h"
#include "mlt_profile.h"
#include "mlt_repository.h"
+#include "mlt_log.h"
#ifdef __cplusplus
}
#include "mlt_producer.h"
#include "mlt_frame.h"
#include "mlt_profile.h"
+#include "mlt_log.h"
#include <stdio.h>
#include <string.h>
{
// 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 );
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;
}
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 );
}
--- /dev/null
+/**
+ * \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 <string.h>
+
+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;
+}
--- /dev/null
+/**
+ * \file mlt_log.h
+ * \brief logging functions
+ *
+ * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * 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 <stdarg.h>
+
+#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 */
#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
#include "mlt_frame.h"
#include "mlt_parser.h"
#include "mlt_profile.h"
+#include "mlt_log.h"
#include <stdio.h>
#include <string.h>
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
#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 );
#include "mlt_properties.h"
#include "mlt_property.h"
#include "mlt_deque.h"
+#include "mlt_log.h"
#include <stdio.h>
#include <stdlib.h>
// 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 )
{
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
#include "mlt_repository.h"
#include "mlt_properties.h"
#include "mlt_tokeniser.h"
+#include "mlt_log.h"
#include <stdio.h>
#include <stdlib.h>
}
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() );
}
}
#include "mlt_frame.h"
#include "mlt_multitrack.h"
#include "mlt_field.h"
+#include "mlt_log.h"
#include <stdio.h>
#include <stdlib.h>
}
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 );
}
#include "mlt_transition.h"
#include "mlt_frame.h"
+#include "mlt_log.h"
#include <stdio.h>
#include <stdlib.h>
break;
default:
- fprintf( stderr, "invalid transition type\n" );
+ mlt_log( service, MLT_LOG_ERROR, "invalid transition type\n" );
break;
}