xref: /haiku/src/servers/media/NodeManager.h (revision 97901ec593ec4dd50ac115c1c35a6d72f6e489a5)
1 /*
2  * Copyright 2002, Marcus Overhagen. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef NODE_MANAGER_H
6 #define NODE_MANAGER_H
7 
8 
9 #include <map>
10 #include <vector>
11 
12 #include <Locker.h>
13 
14 #include "TStack.h"
15 #include "DataExchange.h"
16 
17 
18 class DefaultManager;
19 class BufferManager;
20 
21 
22 typedef std::map<team_id, int32> TeamCountMap;
23 typedef std::vector<media_input> InputList;
24 typedef std::vector<media_output> OutputList;
25 typedef std::vector<live_node_info> LiveNodeList;
26 
27 
28 struct registered_node {
29 	media_node_id			node_id;
30 	media_addon_id			add_on_id;
31 	int32					flavor_id;
32 	char					name[B_MEDIA_NAME_LENGTH];
33 	uint64					kinds;
34 	port_id					port;
35 	team_id					creator;	// team that created the node
36 	team_id					containing_team;
37 	int32					ref_count;
38 	TeamCountMap			team_ref_count;
39 	InputList				input_list;
40 	OutputList				output_list;
41 };
42 
43 struct dormant_add_on_flavor_info {
44 	media_addon_id			add_on_id;
45 	int32					flavor_id;
46 
47 	int32					max_instances_count;
48 	int32					instances_count;
49 
50 	TeamCountMap		 	team_instances_count;
51 
52 	bool					info_valid;
53 	dormant_flavor_info		info;
54 };
55 
56 
57 class NodeManager : BLocker {
58 public:
59 								NodeManager();
60 								~NodeManager();
61 
62 	// Management of system wide default nodes
63 			status_t			SetDefaultNode(node_type type,
64 									const media_node* node,
65 									const dormant_node_info* info,
66 									const media_input* input);
67 			status_t			GetDefaultNode(node_type type,
68 									media_node_id* _nodeID, char* inputName,
69 									int32* _inputID);
70 			status_t			RescanDefaultNodes();
71 
72 	// Management of live nodes
73 			status_t			RegisterNode(media_addon_id addOnID,
74 									int32 flavorID, const char* name,
75 									uint64 kinds, port_id port, team_id team,
76 									media_node_id* _nodeID);
77 			status_t			UnregisterNode(media_node_id nodeID,
78 									team_id team, media_addon_id* addOnID,
79 									int32* _flavorID);
80 			status_t			ReleaseNodeReference(media_node_id id,
81 									team_id team);
82 			status_t			ReleaseNodeAll(media_node_id id);
83 			status_t			GetCloneForID(media_node_id id, team_id team,
84 									media_node* node);
85 			status_t			GetClone(node_type type, team_id team,
86 									media_node* node, char* inputName,
87 									int32* _id);
88 			status_t			ReleaseNode(const media_node& node,
89 									team_id team);
90 			status_t			PublishInputs(const media_node& node,
91 									const media_input* inputs, int32 count);
92 			status_t			PublishOutputs(const media_node& node,
93 									const media_output* outputs, int32 count);
94 			status_t			FindNodeID(port_id port, media_node_id* _id);
95 			status_t			GetLiveNodeInfo(const media_node& node,
96 									live_node_info* liveInfo);
97 			status_t			GetInstances(media_addon_id addOnID,
98 									int32 flavorID, media_node_id* ids,
99 									int32* _count, int32 maxCount);
100 			status_t			GetLiveNodes(LiveNodeList& liveNodes,
101 									int32 maxCount,
102 									const media_format* inputFormat = NULL,
103 									const media_format* outputFormat = NULL,
104 									const char* name = NULL,
105 									uint64 requireKinds = 0);
106 			status_t			GetDormantNodeInfo(const media_node& node,
107 									dormant_node_info* nodeInfo);
108 			status_t			SetNodeCreator(media_node_id id,
109 									team_id creator);
110 
111 	// Add media_node_id of all live nodes to the message
112 	// int32 "media_node_id" (multiple items)
113 			status_t			GetLiveNodes(BMessage* message);
114 
115 			void				RegisterAddOn(const entry_ref& ref,
116 									media_addon_id* _newID);
117 			void				UnregisterAddOn(media_addon_id id);
118 
119 			status_t			AddDormantFlavorInfo(
120 									const dormant_flavor_info& flavorInfo);
121 			void				InvalidateDormantFlavorInfo(media_addon_id id);
122 			void				RemoveDormantFlavorInfo(media_addon_id id);
123 			void				CleanupDormantFlavorInfos();
124 
125 			status_t			IncrementFlavorInstancesCount(
126 									media_addon_id addOnID, int32 flavorID,
127 									team_id team);
128 			status_t			DecrementFlavorInstancesCount(
129 									media_addon_id addOnID, int32 flavorID,
130 									team_id team);
131 
132 			status_t			GetAddOnRef(media_addon_id addOnID,
133 									entry_ref* ref);
134 			status_t			GetDormantNodes(dormant_node_info* infos,
135 									int32* _count, const media_format* hasInput,
136 									const media_format* hasOutput,
137 									const char* name, uint64 requireKinds,
138 									uint64 denyKinds);
139 
140 			status_t			GetDormantFlavorInfoFor(media_addon_id addOnID,
141 									 int32 flavorID,
142 									 dormant_flavor_info* flavorInfo);
143 
144 			void				CleanupTeam(team_id team);
145 
146 			status_t			LoadState();
147 			status_t			SaveState();
148 
149 			void				Dump();
150 
151 private:
152 			status_t			_AcquireNodeReference(media_node_id id,
153 									team_id team);
154 
155 private:
156 			typedef std::map<media_addon_id, registered_node> NodeMap;
157 			typedef std::vector<dormant_add_on_flavor_info> DormantFlavorList;
158 			typedef std::map<media_addon_id, entry_ref> PathMap;
159 
160 			media_addon_id		fNextAddOnID;
161 			media_node_id		fNextNodeID;
162 
163 			DormantFlavorList	fDormantFlavors;
164 			PathMap				fPathMap;
165 			NodeMap				fNodeMap;
166 			DefaultManager*		fDefaultManager;
167 };
168 
169 #endif	// NODE_MANAGER_H
170