]> git.sesse.net Git - mlt/blob - src/modules/avformat/factory.c
Fixup local ffmpeg build.
[mlt] / src / modules / avformat / factory.c
1 /*
2  * factory.c -- the factory method interfaces
3  * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
4  * Author: Charles Yates <charles.yates@pandora.be>
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include <string.h>
22 #include <pthread.h>
23 #include <limits.h>
24
25 #include <framework/mlt.h>
26
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, const char *service, char *file );
33
34 // ffmpeg Header files
35 #include <avformat.h>
36 #ifdef AVDEVICE
37 #include <avdevice.h>
38 #endif
39
40 // A static flag used to determine if avformat has been initialised
41 static int avformat_initialised = 0;
42
43 // A locking mutex
44 static pthread_mutex_t avformat_mutex;
45
46 #if 0
47 // These 3 functions should override the alloc functions in libavformat
48 // but some formats or codecs seem to crash when used (wmv in particular)
49
50 void *av_malloc( unsigned int size )
51 {
52         return mlt_pool_alloc( size );
53 }
54
55 void *av_realloc( void *ptr, unsigned int size )
56 {
57         return mlt_pool_realloc( ptr, size );
58 }
59
60 void av_free( void *ptr )
61 {
62         return mlt_pool_release( ptr );
63 }
64 #endif
65
66 void avformat_destroy( void *ignore )
67 {
68         // Clean up
69         // av_free_static( ); -XXX this is deprecated
70
71         // Destroy the mutex
72         pthread_mutex_destroy( &avformat_mutex );
73 }
74
75 void avformat_lock( )
76 {
77         // Lock the mutex now
78         pthread_mutex_lock( &avformat_mutex );
79 }
80
81 void avformat_unlock( )
82 {
83         // Unlock the mutex now
84         pthread_mutex_unlock( &avformat_mutex );
85 }
86
87 static void avformat_init( )
88 {
89         // Initialise avformat if necessary
90         if ( avformat_initialised == 0 )
91         {
92                 avformat_initialised = 1;
93                 pthread_mutex_init( &avformat_mutex, NULL );
94                 av_register_all( );
95 #ifdef AVDEVICE
96                 avdevice_register_all();
97 #endif
98                 mlt_factory_register_for_clean_up( NULL, avformat_destroy );
99                 av_log_set_level( mlt_log_get_level() );
100         }
101 }
102
103 static void *create_service( mlt_profile profile, mlt_service_type type, const char *id, void *arg )
104 {
105         avformat_init( );
106 #ifdef CODECS
107         if ( !strncmp( id, "avformat", 8 ) )
108         {
109                 if ( type == producer_type )
110                         return producer_avformat_init( profile, id, arg );
111                 else if ( type == consumer_type )
112                         return consumer_avformat_init( profile, arg );
113         }
114 #endif
115 #ifdef FILTERS
116         if ( !strcmp( id, "avcolor_space" ) )
117                 return filter_avcolour_space_init( arg );
118         if ( !strcmp( id, "avcolour_space" ) )
119                 return filter_avcolour_space_init( arg );
120         if ( !strcmp( id, "avdeinterlace" ) )
121                 return filter_avdeinterlace_init( arg );
122         if ( !strcmp( id, "avresample" ) )
123                 return filter_avresample_init( arg );
124 #ifdef SWSCALE
125         if ( !strcmp( id, "swscale" ) )
126                 return filter_swscale_init( profile, arg );
127 #endif
128 #endif
129         return NULL;
130 }
131
132 static mlt_properties avformat_metadata( mlt_service_type type, const char *id, void *data )
133 {
134         char file[ PATH_MAX ];
135         const char *service_type = NULL;
136         switch ( type )
137         {
138                 case consumer_type:
139                         service_type = "consumer";
140                         break;
141                 case filter_type:
142                         service_type = "filter";
143                         break;
144                 case producer_type:
145                         service_type = "producer";
146                         break;
147                 case transition_type:
148                         service_type = "transition";
149                         break;
150                 default:
151                         return NULL;
152         }
153         snprintf( file, PATH_MAX, "%s/avformat/%s_%s.yml", mlt_environment( "MLT_DATA" ), service_type, id );
154         return mlt_properties_parse_yaml( file );
155 }
156
157 MLT_REPOSITORY
158 {
159 #ifdef CODECS
160         MLT_REGISTER( consumer_type, "avformat", create_service );
161         MLT_REGISTER( producer_type, "avformat", create_service );
162         MLT_REGISTER( producer_type, "avformat-novalidate", create_service );
163         MLT_REGISTER_METADATA( producer_type, "avformat", avformat_metadata, NULL );
164 #endif
165 #ifdef FILTERS
166         MLT_REGISTER( filter_type, "avcolour_space", create_service );
167         MLT_REGISTER( filter_type, "avcolor_space", create_service );
168         MLT_REGISTER( filter_type, "avdeinterlace", create_service );
169         MLT_REGISTER( filter_type, "avresample", create_service );
170 #ifdef SWSCALE
171         MLT_REGISTER( filter_type, "swscale", create_service );
172 #endif
173 #endif
174 }