]> git.sesse.net Git - mlt/blob - src/modules/avformat/factory.c
consumer avformat added, various cleanups and consumer realtime switching
[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
28 // ffmpeg Header files
29 #include <ffmpeg/avformat.h>
30
31 // A static flag used to determine if avformat has been initialised
32 static int avformat_initialised = 0;
33
34 // A locking mutex
35 static pthread_mutex_t avformat_mutex;
36
37 #if 0
38 // These 3 functions should override the alloc functions in libavformat
39 // but some formats or codecs seem to crash when used (wmv in particular)
40
41 void *av_malloc( unsigned int size )
42 {
43         return mlt_pool_alloc( size );
44 }
45
46 void *av_realloc( void *ptr, unsigned int size )
47 {
48         return mlt_pool_realloc( ptr, size );
49 }
50
51 void av_free( void *ptr )
52 {
53         return mlt_pool_release( ptr );
54 }
55 #endif
56
57 void avformat_destroy( void *ignore )
58 {
59         // Clean up
60         av_free_static( );
61
62         // Destroy the mutex
63         pthread_mutex_destroy( &avformat_mutex );
64 }
65
66 void avformat_lock( )
67 {
68         // Lock the mutex now
69         pthread_mutex_lock( &avformat_mutex );
70 }
71
72 void avformat_unlock( )
73 {
74         // Unlock the mutex now
75         pthread_mutex_unlock( &avformat_mutex );
76 }
77
78 static void avformat_init( )
79 {
80         // Initialise avformat if necessary
81         if ( avformat_initialised == 0 )
82         {
83                 avformat_initialised = 1;
84                 pthread_mutex_init( &avformat_mutex, NULL );
85                 av_register_all( );
86                 mlt_factory_register_for_clean_up( NULL, avformat_destroy );
87         }
88 }
89
90 void *mlt_create_producer( char *id, void *arg )
91 {
92         avformat_init( );
93         if ( !strcmp( id, "avformat" ) )
94                 return producer_avformat_init( arg );
95         return NULL;
96 }
97
98 void *mlt_create_filter( char *id, void *arg )
99 {
100         return NULL;
101 }
102
103 void *mlt_create_transition( char *id, void *arg )
104 {
105         return NULL;
106 }
107
108 void *mlt_create_consumer( char *id, void *arg )
109 {
110         avformat_init( );
111         if ( !strcmp( id, "avformat" ) )
112                 return consumer_avformat_init( arg );
113         return NULL;
114 }
115