c197d901e68029b4e08abafa12584e55f9a1db94
[melted] / 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
24 #include <framework/mlt.h>
25
26 extern mlt_consumer consumer_avformat_init( mlt_profile profile, char *file );
27 extern mlt_filter filter_avcolour_space_init( void *arg );
28 extern mlt_filter filter_avdeinterlace_init( void *arg );
29 extern mlt_filter filter_avresample_init( char *arg );
30 extern mlt_producer producer_avformat_init( mlt_profile profile, char *file );
31
32 // ffmpeg Header files
33 #include <avformat.h>
34
35 // A static flag used to determine if avformat has been initialised
36 static int avformat_initialised = 0;
37
38 // A locking mutex
39 static pthread_mutex_t avformat_mutex;
40
41 #if 0
42 // These 3 functions should override the alloc functions in libavformat
43 // but some formats or codecs seem to crash when used (wmv in particular)
44
45 void *av_malloc( unsigned int size )
46 {
47 return mlt_pool_alloc( size );
48 }
49
50 void *av_realloc( void *ptr, unsigned int size )
51 {
52 return mlt_pool_realloc( ptr, size );
53 }
54
55 void av_free( void *ptr )
56 {
57 return mlt_pool_release( ptr );
58 }
59 #endif
60
61 void avformat_destroy( void *ignore )
62 {
63 // Clean up
64 // av_free_static( ); -XXX this is deprecated
65
66 // Destroy the mutex
67 pthread_mutex_destroy( &avformat_mutex );
68 }
69
70 void avformat_lock( )
71 {
72 // Lock the mutex now
73 pthread_mutex_lock( &avformat_mutex );
74 }
75
76 void avformat_unlock( )
77 {
78 // Unlock the mutex now
79 pthread_mutex_unlock( &avformat_mutex );
80 }
81
82 static void avformat_init( )
83 {
84 // Initialise avformat if necessary
85 if ( avformat_initialised == 0 )
86 {
87 avformat_initialised = 1;
88 pthread_mutex_init( &avformat_mutex, NULL );
89 av_register_all( );
90 mlt_factory_register_for_clean_up( NULL, avformat_destroy );
91 av_log_set_level( -1 );
92 }
93 }
94
95 void *mlt_create_producer( mlt_profile profile, mlt_service_type type, const char *id, void *arg )
96 {
97 avformat_init( );
98 if ( !strcmp( id, "avformat" ) )
99 return producer_avformat_init( profile, arg );
100 return NULL;
101 }
102
103 void *mlt_create_filter( mlt_profile profile, mlt_service_type type, const char *id, void *arg )
104 {
105 avformat_init( );
106 if ( !strcmp( id, "avcolour_space" ) )
107 return filter_avcolour_space_init( arg );
108 #ifdef USE_MMX
109 if ( !strcmp( id, "avdeinterlace" ) )
110 return filter_avdeinterlace_init( arg );
111 #endif
112 if ( !strcmp( id, "avresample" ) )
113 return filter_avresample_init( arg );
114 return NULL;
115 }
116
117 void *mlt_create_transition( mlt_profile profile, mlt_service_type type, const char *id, void *arg )
118 {
119 return NULL;
120 }
121
122 void *mlt_create_consumer( mlt_profile profile, mlt_service_type type, const char *id, void *arg )
123 {
124 avformat_init( );
125 if ( !strcmp( id, "avformat" ) )
126 return consumer_avformat_init( profile, arg );
127 return NULL;
128 }
129