xref: /haiku/headers/private/media/PluginManager.h (revision 820dca4df6c7bf955c46e8f6521b9408f50b2900)
1 /*
2  * Copyright 2004-2007, Marcus Overhagen. All rights reserved.
3  * Distributed under the terms of the OpenBeOS License.
4  */
5 #ifndef _PLUGIN_MANAGER_H
6 #define _PLUGIN_MANAGER_H
7 
8 
9 #include <string.h>
10 
11 
12 #include "DecoderPlugin.h"
13 #include "EncoderPlugin.h"
14 #include "ReaderPlugin.h"
15 #include "WriterPlugin.h"
16 
17 #include <TList.h>
18 #include <Locker.h>
19 
20 
21 namespace BPrivate { namespace media {
22 
23 class PluginManager {
24 public:
25 								PluginManager();
26 								~PluginManager();
27 
28 			MediaPlugin*		GetPlugin(const entry_ref& ref);
29 			void				PutPlugin(MediaPlugin* plugin);
30 
31 	// Readers and Decoders
32 			status_t			CreateReader(Reader** reader,
33 									int32* streamCount, media_file_format* mff,
34 									BDataIO* source);
35 			void				DestroyReader(Reader* reader);
36 
37 			status_t			CreateDecoder(Decoder** decoder,
38 									const media_format& format);
39 			status_t			CreateDecoder(Decoder** decoder,
40 									const media_codec_info& mci);
41 			status_t			GetDecoderInfo(Decoder* decoder,
42 									media_codec_info* _info) const;
43 			void				DestroyDecoder(Decoder* decoder);
44 
45 	// Writers and Encoders
46 			status_t			CreateWriter(Writer** writer,
47 									const media_file_format& mff,
48 									BDataIO* target);
49 			void				DestroyWriter(Writer* writer);
50 
51 			status_t			CreateEncoder(Encoder** encoder,
52 									const media_codec_info* codecInfo,
53 									uint32 flags);
54 			void				DestroyEncoder(Encoder* encoder);
55 
56 private:
57 			status_t			_LoadPlugin(const entry_ref& ref,
58 									MediaPlugin** plugin, image_id* image);
59 
60 			struct plugin_info {
61 				char			name[260];
62 				int				usecount;
63 				MediaPlugin*	plugin;
64 				image_id		image;
65 
66 				plugin_info& operator=(const plugin_info& other)
67 				{
68 					strcpy(name, other.name);
69 					usecount = other.usecount;
70 					plugin = other.plugin;
71 					image = other.image;
72 					return *this;
73 				}
74 			};
75 
76 			List<plugin_info>	fPluginList;
77 			BLocker				fLocker;
78 };
79 
80 } } // namespace BPrivate::media
81 
82 using namespace BPrivate::media;
83 
84 extern PluginManager gPluginManager;
85 
86 #endif // _PLUGIN_MANAGER_H
87