2 * factory.c -- the factory method interfaces
3 * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
4 * Author: Charles Yates <charles.yates@pandora.be>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include <framework/mlt.h>
27 extern mlt_consumer consumer_avformat_init( mlt_profile profile, char *file );
28 extern mlt_filter filter_avcolour_space_init( void *arg );
29 extern mlt_filter filter_avdeinterlace_init( void *arg );
30 extern mlt_filter filter_avresample_init( char *arg );
31 extern mlt_filter filter_swscale_init( mlt_profile profile, char *arg );
32 extern mlt_producer producer_avformat_init( mlt_profile profile, char *file );
34 // ffmpeg Header files
37 // A static flag used to determine if avformat has been initialised
38 static int avformat_initialised = 0;
41 static pthread_mutex_t avformat_mutex;
44 // These 3 functions should override the alloc functions in libavformat
45 // but some formats or codecs seem to crash when used (wmv in particular)
47 void *av_malloc( unsigned int size )
49 return mlt_pool_alloc( size );
52 void *av_realloc( void *ptr, unsigned int size )
54 return mlt_pool_realloc( ptr, size );
57 void av_free( void *ptr )
59 return mlt_pool_release( ptr );
63 void avformat_destroy( void *ignore )
66 // av_free_static( ); -XXX this is deprecated
69 pthread_mutex_destroy( &avformat_mutex );
75 pthread_mutex_lock( &avformat_mutex );
78 void avformat_unlock( )
80 // Unlock the mutex now
81 pthread_mutex_unlock( &avformat_mutex );
84 static void avformat_init( )
86 // Initialise avformat if necessary
87 if ( avformat_initialised == 0 )
89 avformat_initialised = 1;
90 pthread_mutex_init( &avformat_mutex, NULL );
92 mlt_factory_register_for_clean_up( NULL, avformat_destroy );
93 av_log_set_level( mlt_log_get_level() );
97 static void *create_service( mlt_profile profile, mlt_service_type type, const char *id, void *arg )
101 if ( !strcmp( id, "avformat" ) )
103 if ( type == producer_type )
104 return producer_avformat_init( profile, arg );
105 else if ( type == consumer_type )
106 return consumer_avformat_init( profile, arg );
110 if ( !strcmp( id, "avcolour_space" ) )
111 return filter_avcolour_space_init( arg );
112 if ( !strcmp( id, "avdeinterlace" ) )
113 return filter_avdeinterlace_init( arg );
114 if ( !strcmp( id, "avresample" ) )
115 return filter_avresample_init( arg );
117 if ( !strcmp( id, "swscale" ) )
118 return filter_swscale_init( profile, arg );
124 static mlt_properties avformat_metadata( mlt_service_type type, const char *id, void *data )
126 char file[ PATH_MAX ];
127 const char *service_type = NULL;
131 service_type = "consumer";
134 service_type = "filter";
137 service_type = "producer";
139 case transition_type:
140 service_type = "transition";
145 snprintf( file, PATH_MAX, "%s/avformat/%s_%s.yml", mlt_environment( "MLT_DATA" ), service_type, id );
146 return mlt_properties_parse_yaml( file );
152 MLT_REGISTER( consumer_type, "avformat", create_service );
153 MLT_REGISTER( producer_type, "avformat", create_service );
154 MLT_REGISTER_METADATA( producer_type, "avformat", avformat_metadata, NULL );
157 MLT_REGISTER( filter_type, "avcolour_space", create_service );
158 MLT_REGISTER( filter_type, "avcolor_space", create_service );
159 MLT_REGISTER( filter_type, "avdeinterlace", create_service );
160 MLT_REGISTER( filter_type, "avresample", create_service );
162 MLT_REGISTER( filter_type, "swscale", create_service );