1/*
2 * Copyright 2009, Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
5#ifndef _MEDIA_ADD_ON_H
6#define _MEDIA_ADD_ON_H
7
8
9#include <image.h>
10
11#include <MediaDefs.h>
12#include <Flattenable.h>
13
14
15class BMediaNode;
16class BMimeType;
17struct entry_ref;
18
19struct dormant_node_info {
20								dormant_node_info();
21								~dormant_node_info();
22
23			media_addon_id		addon;
24			int32				flavor_id;
25			char				name[B_MEDIA_NAME_LENGTH];
26
27private:
28			char				reserved[128];
29};
30
31// flavor_flags
32enum {
33	B_FLAVOR_IS_GLOBAL	= 0x100000L,		// force in media_addon_server,
34											// only one instance
35	B_FLAVOR_IS_LOCAL	= 0x200000L			// force in loading app, many
36											// instances if none is set, could
37											// go either way
38};
39
40struct flavor_info {
41	const char*			name;
42	const char*			info;
43	uint64				kinds;				// node kind
44	uint32				flavor_flags;
45	int32				internal_id;		// For BMediaAddOn internal use
46	int32				possible_count;		// 0 for "any number"
47
48	int32				in_format_count;	// for BufferConsumer kinds
49	uint32				in_format_flags;	// set to 0
50	const media_format*	in_formats;
51
52	int32				out_format_count;	// for BufferProducer kinds
53	uint32				out_format_flags;	// set to 0
54	const media_format*	out_formats;
55
56	uint32				_reserved_[16];
57
58private:
59	flavor_info&		operator=(const flavor_info& other);
60};
61
62struct dormant_flavor_info : public flavor_info, public BFlattenable {
63								dormant_flavor_info();
64	virtual						~dormant_flavor_info();
65
66								dormant_flavor_info(
67									const dormant_flavor_info& other);
68			dormant_flavor_info& operator=(const dormant_flavor_info& other);
69			dormant_flavor_info& operator=(const flavor_info& other);
70
71			dormant_node_info	node_info;
72
73			void				set_name(const char* name);
74			void				set_info(const char* info);
75			void				add_in_format(const media_format& format);
76			void				add_out_format(const media_format& format);
77
78	virtual	bool				IsFixedSize() const;
79	virtual	type_code			TypeCode() const;
80	virtual	ssize_t				FlattenedSize() const;
81	virtual	status_t			Flatten(void* buffer, ssize_t size) const;
82	virtual	status_t			Unflatten(type_code type, const void* buffer,
83									ssize_t size);
84};
85
86
87namespace BPrivate {
88	namespace media {
89		class DormantNodeManager;
90	};
91};
92
93
94//! a MediaAddOn is something which can manufacture MediaNodes
95class BMediaAddOn {
96public:
97	explicit					BMediaAddOn(image_id image);
98	virtual						~BMediaAddOn();
99
100	virtual	status_t			InitCheck(const char** _failureText);
101	virtual	int32				CountFlavors();
102	virtual	status_t			GetFlavorAt(int32 index,
103									const flavor_info** _info);
104	virtual	BMediaNode*			InstantiateNodeFor(const flavor_info* info,
105									BMessage* config, status_t* _error);
106	virtual	status_t			GetConfigurationFor(BMediaNode* yourNode,
107									BMessage* intoMessage);
108	virtual	bool				WantsAutoStart();
109	virtual	status_t			AutoStart(int index, BMediaNode** _node,
110									int32* _internalID, bool* _hasMore);
111
112	// NOTE: Only implement if you have a B_FILE_INTERFACE node
113	virtual	status_t			SniffRef(const entry_ref& file,
114									BMimeType* ioMimeType, float* _quality,
115									int32* _internalID);
116	// NOTE: This is broken if you deal with producers and consumers both.
117	// Implement SniffTypeKind instead. If you implement SniffTypeKind, this
118	// doesn't get called.
119	virtual	status_t			SniffType(const BMimeType& type,
120									float* _quality, int32* _internalID);
121
122	virtual	status_t			GetFileFormatList(int32 forNodeFlavorID,
123									media_file_format* _writableFormats,
124									int32 writableFormatsCount,
125									int32* _writableFormatsTotalCount,
126									media_file_format* _readableFormats,
127									int32 readableFormatsCount,
128									int32* _readableFormatsTotalCount,
129									void* _reserved);
130
131	// NOTE: Like SniffType, but for the specific kind(s)
132	virtual	status_t			SniffTypeKind(const BMimeType& type,
133									uint64 kinds, float* _quality,
134									int32* _internalID, void* _reserved);
135
136			image_id			ImageID();
137			media_addon_id		AddonID();
138
139protected:
140	// Calling this will cause everyone to get notified, and also
141	// cause the server to re-scan your flavor info. It is thread safe.
142			status_t			NotifyFlavorChange();
143
144	// TODO: Needs a Perform() virtual method!
145
146private:
147	// FBC padding and forbidden methods
148								BMediaAddOn();
149								BMediaAddOn(const BMediaAddOn& other);
150			BMediaAddOn&		operator=(const BMediaAddOn& other);
151
152			friend class BPrivate::media::DormantNodeManager;
153
154	virtual	status_t			_Reserved_MediaAddOn_2(void*);
155	virtual	status_t			_Reserved_MediaAddOn_3(void*);
156	virtual	status_t			_Reserved_MediaAddOn_4(void*);
157	virtual	status_t			_Reserved_MediaAddOn_5(void*);
158	virtual	status_t			_Reserved_MediaAddOn_6(void*);
159	virtual	status_t			_Reserved_MediaAddOn_7(void*);
160
161			image_id 			fImage;
162			media_addon_id		fAddon;
163
164			uint32				_reserved_media_add_on_[7];
165};
166
167
168#if BUILDING_MEDIA_ADDON
169	extern "C" _EXPORT BMediaAddOn* make_media_addon(image_id yourImage);
170#endif
171
172
173#endif // _MEDIA_ADD_ON_H
174
175