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