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