<commit_before>/*
 * factory.c -- the factory method interfaces
 * Copyright (C) 2003-2012 Ushodaya Enterprises Limited
 * Author: <NAME> <<EMAIL>>
 *
 * 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 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
 * Lesser General Public License for more details.
 *
 * 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 <string.h>
#include <pthread.h>
#include <limits.h>
#include <float.h>

#include <framework/mlt.h>

extern mlt_consumer consumer_avformat_init( mlt_profile profile, char *file );
extern mlt_filter filter_avcolour_space_init( void *arg );
extern mlt_filter filter_avdeinterlace_init( void *arg );
extern mlt_filter filter_avresample_init( char *arg );
extern mlt_filter filter_swscale_init( mlt_profile profile, char *arg );
extern mlt_producer producer_avformat_init( mlt_profile profile, const char *service, char *file );

// ffmpeg Header files
#include <libavformat/avformat.h>
#ifdef AVDEVICE
#include <libavdevice/avdevice.h>
#endif
#if LIBAVCODEC_VERSION_MAJOR >= 53
#include <libavutil/opt.h>
#else
#include <libavcodec/opt.h>
#endif

#if LIBAVUTIL_VERSION_INT < ((51<<16)+(12<<8)+0)
#define AV_OPT_TYPE_FLAGS    FF_OPT_TYPE_FLAGS
#define AV_OPT_TYPE_INT      FF_OPT_TYPE_INT
#define AV_OPT_TYPE_INT64    FF_OPT_TYPE_INT64
#define AV_OPT_TYPE_DOUBLE   FF_OPT_TYPE_DOUBLE
#define AV_OPT_TYPE_FLOAT    FF_OPT_TYPE_FLOAT
#define AV_OPT_TYPE_STRING   FF_OPT_TYPE_STRING
#define AV_OPT_TYPE_RATIONAL FF_OPT_TYPE_RATIONAL
#define AV_OPT_TYPE_BINARY   FF_OPT_TYPE_BINARY
#define AV_OPT_TYPE_CONST    FF_OPT_TYPE_CONST
#endif

// A static flag used to determine if avformat has been initialised
static int avformat_initialised = 0;

static int avformat_lockmgr(void **mutex, enum AVLockOp op)
{
   pthread_mutex_t** pmutex = (pthread_mutex_t**) mutex;

   switch (op)
   {
   case AV_LOCK_CREATE:
      *pmutex = (pthread_mutex_t*) malloc(sizeof(pthread_mutex_t));
       pthread_mutex_init(*pmutex, NULL);
       break;
   case AV_LOCK_OBTAIN:
       pthread_mutex_lock(*pmutex);
       break;
   case AV_LOCK_RELEASE:
       pthread_mutex_unlock(*pmutex);
       break;
   case AV_LOCK_DESTROY:
       pthread_mutex_destroy(*pmutex);
       free(*pmutex);
       break;
   }

   return 0;
}

static void avformat_init( )
{
	// Initialise avformat if necessary
	if ( avformat_initialised == 0 )
	{
		avformat_initialised = 1;
		av_lockmgr_register( &avformat_lockmgr );
		av_register_all( );
#ifdef AVDEVICE
		avdevice_register_all();
#endif
#if LIBAVFORMAT_VERSION_INT >= ((53<<16)+(13<<8))
		avformat_network_init();
#endif
		av_log_set_level( mlt_log_get_level() );
	}
}

static void *create_service( mlt_profile profile, mlt_service_type type, const char *id, void *arg )
{<commit_msg>Fix Segmentation fault at exit by calling av_lockmgr_register( NULL );<commit_after>/*
 * factory.c -- the factory method interfaces
 * Copyright (C) 2003-2012 Ushodaya Enterprises Limited
 * Author: <NAME> <<EMAIL>>
 *
 * 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 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
 * Lesser General Public License for more details.
 *
 * 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 <string.h>
#include <pthread.h>
#include <limits.h>
#include <float.h>

#include <framework/mlt.h>

extern mlt_consumer consumer_avformat_init( mlt_profile profile, char *file );
extern mlt_filter filter_avcolour_space_init( void *arg );
extern mlt_filter filter_avdeinterlace_init( void *arg );
extern mlt_filter filter_avresample_init( char *arg );
extern mlt_filter filter_swscale_init( mlt_profile profile, char *arg );
extern mlt_producer producer_avformat_init( mlt_profile profile, const char *service, char *file );

// ffmpeg Header files
#include <libavformat/avformat.h>
#ifdef AVDEVICE
#include <libavdevice/avdevice.h>
#endif
#if LIBAVCODEC_VERSION_MAJOR >= 53
#include <libavutil/opt.h>
#else
#include <libavcodec/opt.h>
#endif

#if LIBAVUTIL_VERSION_INT < ((51<<16)+(12<<8)+0)
#define AV_OPT_TYPE_FLAGS    FF_OPT_TYPE_FLAGS
#define AV_OPT_TYPE_INT      FF_OPT_TYPE_INT
#define AV_OPT_TYPE_INT64    FF_OPT_TYPE_INT64
#define AV_OPT_TYPE_DOUBLE   FF_OPT_TYPE_DOUBLE
#define AV_OPT_TYPE_FLOAT    FF_OPT_TYPE_FLOAT
#define AV_OPT_TYPE_STRING   FF_OPT_TYPE_STRING
#define AV_OPT_TYPE_RATIONAL FF_OPT_TYPE_RATIONAL
#define AV_OPT_TYPE_BINARY   FF_OPT_TYPE_BINARY
#define AV_OPT_TYPE_CONST    FF_OPT_TYPE_CONST
#endif

// A static flag used to determine if avformat has been initialised
static int avformat_initialised = 0;

static int avformat_lockmgr(void **mutex, enum AVLockOp op)
{
   pthread_mutex_t** pmutex = (pthread_mutex_t**) mutex;

   switch (op)
   {
   case AV_LOCK_CREATE:
      *pmutex = (pthread_mutex_t*) malloc(sizeof(pthread_mutex_t));
       pthread_mutex_init(*pmutex, NULL);
       break;
   case AV_LOCK_OBTAIN:
       pthread_mutex_lock(*pmutex);
       break;
   case AV_LOCK_RELEASE:
       pthread_mutex_unlock(*pmutex);
       break;
   case AV_LOCK_DESTROY:
       pthread_mutex_destroy(*pmutex);
       free(*pmutex);
       break;
   }

   return 0;
}

static void avformat_exit( )
{
	av_lockmgr_register( NULL );
}

static void avformat_init( )
{
	// Initialise avformat if necessary
	if ( avformat_initialised == 0 )
	{
		avformat_initialised = 1;
		av_lockmgr_register( &avformat_lockmgr );
		av_register_all( );
#ifdef AVDEVICE
		avdevice_register_all();
#endif
#if LIBAVFORMAT_VERSION_INT >= ((53<<16)+(13<<8))
		avformat_network_init();
#endif
		av_log_set_level( mlt_log_get_level() );
		atexit(avformat_exit);
	}
}

static void *create_service( mlt_profile profile, mlt_service_type type, const char *id, void *arg )
{
{'fraction_non_alphanumeric': 0.08576099881093936, 'fraction_numerical': 0.014565992865636148, 'mean_word_length': 4.780927835051546, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6250542', 'n_tokens_mistral': 2364, 'n_tokens_neox': 2245, 'n_words': 653}