]> git.sesse.net Git - mlt/blob - src/modules/avformat/factory.c
config mods; avformat static or shared build; corrections to sdl
[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 program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program 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
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19  */
20
21 #include <string.h>
22 #include <pthread.h>
23
24 #include <framework/mlt_factory.h>
25 #include "producer_avformat.h"
26 #include "consumer_avformat.h"
27 #include "filter_avdeinterlace.h"
28 #include "filter_avresample.h"
29
30 // ffmpeg Header files
31 #include <avformat.h>
32
33 // A static flag used to determine if avformat has been initialised
34 static int avformat_initialised = 0;
35
36 // A locking mutex
37 static pthread_mutex_t avformat_mutex;
38
39 #if 0
40 // These 3 functions should override the alloc functions in libavformat
41 // but some formats or codecs seem to crash when used (wmv in particular)
42
43 void *av_malloc( unsigned int size )
44 {
45         return mlt_pool_alloc( size );
46 }
47
48 void *av_realloc( void *ptr, unsigned int size )
49 {
50         return mlt_pool_realloc( ptr, size );
51 }
52
53 void av_free( void *ptr )
54 {
55         return mlt_pool_release( ptr );
56 }
57 #endif
58
59 void avformat_destroy( void *ignore )
60 {
61         // Clean up
62         av_free_static( );
63
64         // Destroy the mutex
65         pthread_mutex_destroy( &avformat_mutex );
66 }
67
68 void avformat_lock( )
69 {
70         // Lock the mutex now
71         pthread_mutex_lock( &avformat_mutex );
72 }
73
74 void avformat_unlock( )
75 {
76         // Unlock the mutex now
77         pthread_mutex_unlock( &avformat_mutex );
78 }
79
80 static void avformat_init( )
81 {
82         // Initialise avformat if necessary
83         if ( avformat_initialised == 0 )
84         {
85                 avformat_initialised = 1;
86                 pthread_mutex_init( &avformat_mutex, NULL );
87                 av_register_all( );
88                 mlt_factory_register_for_clean_up( NULL, avformat_destroy );
89         }
90 }
91
92 void *mlt_create_producer( char *id, void *arg )
93 {
94         avformat_init( );
95         if ( !strcmp( id, "avformat" ) )
96                 return producer_avformat_init( arg );
97         return NULL;
98 }
99
100 void *mlt_create_filter( char *id, void *arg )
101 {
102         avformat_init( );
103         if ( !strcmp( id, "avdeinterlace" ) )
104                 return filter_avdeinterlace_init( arg );
105         if ( !strcmp( id, "avresample" ) )
106                 return filter_avresample_init( arg );
107         return NULL;
108 }
109
110 void *mlt_create_transition( char *id, void *arg )
111 {
112         return NULL;
113 }
114
115 void *mlt_create_consumer( char *id, void *arg )
116 {
117         avformat_init( );
118         if ( !strcmp( id, "avformat" ) )
119                 return consumer_avformat_init( arg );
120         return NULL;
121 }
122