xref: /haiku/src/servers/media/NodeManager.h (revision adb0d19d561947362090081e81d90dde59142026)
1 /*
2  * Copyright 2002, Marcus Overhagen. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 #include "TList.h"
7 #include "TMap.h"
8 #include "TStack.h"
9 #include "DataExchange.h"
10 
11 
12 struct registered_node {
13 	media_node_id nodeid;
14 	media_addon_id addon_id;
15 	int32 addon_flavor_id;
16 	char name[B_MEDIA_NAME_LENGTH];
17 	uint64 kinds;
18 	port_id port;
19 	team_id creator;	// team that created the node
20 	team_id team;		// team that contains the node object
21 	int32 globalrefcount;
22 	Map<team_id, int32> teamrefcount;
23 	List<media_input> inputlist;
24 	List<media_output> outputlist;
25 };
26 
27 struct dormant_addon_flavor_info {
28 	media_addon_id AddonID;
29 	int32 AddonFlavorID;
30 
31 	int32 MaxInstancesCount;
32 	int32 GlobalInstancesCount;
33 
34 	Map<team_id, int32> TeamInstancesCount;
35 
36 	bool InfoValid;
37 	dormant_flavor_info Info;
38 };
39 
40 class DefaultManager;
41 class BufferManager;
42 
43 class NodeManager {
44 public:
45 	NodeManager();
46 	~NodeManager();
47 
48 	status_t LoadState();
49 	status_t SaveState();
50 
51 	void Dump();
52 
53 	/* Management of system wide default nodes */
54 	status_t SetDefaultNode(node_type type, const media_node *node, const dormant_node_info *info, const media_input *input);
55 	status_t GetDefaultNode(media_node_id *nodeid, char *input_name, int32 *input_id, node_type type);
56 	status_t RescanDefaultNodes();
57 
58 	/* Management of live nodes */
59 	status_t RegisterNode(media_node_id *nodeid, media_addon_id addon_id, int32 addon_flavor_id, const char *name, uint64 kinds, port_id port, team_id team);
60 	status_t UnregisterNode(media_addon_id *addonid, int32 *flavorid, media_node_id nodeid, team_id team);
61 	status_t GetCloneForId(media_node *node, media_node_id nodeid, team_id team);
62 	status_t GetClone(media_node *node, char *input_name, int32 *input_id, node_type type, team_id team);
63 	status_t ReleaseNode(const media_node &node, team_id team);
64 	status_t PublishInputs(const media_node &node, const media_input *inputs, int32 count);
65 	status_t PublishOutputs(const media_node &node, const media_output *outputs, int32 count);
66 	status_t FindNodeId(media_node_id *nodeid, port_id port);
67 	status_t GetLiveNodeInfo(live_node_info *live_info, const media_node &node);
68 	status_t GetInstances(media_node_id *node_ids, int32* count, int32 maxcount, media_addon_id addon_id, int32 addon_flavor_id);
69 	status_t GetLiveNodes(Stack<live_node_info> *livenodes,	int32 maxcount, const media_format *inputformat = NULL, const media_format *outputformat = NULL, const char* name = NULL, uint64 require_kinds = 0);
70 	status_t GetDormantNodeInfo(dormant_node_info *node_info, const media_node &node);
71 	status_t IncrementGlobalRefCount(media_node_id nodeid, team_id team);
72 	status_t DecrementGlobalRefCount(media_node_id nodeid, team_id team);
73 	status_t SetNodeCreator(media_node_id nodeid, team_id creator);
74 	void FinalReleaseNode(media_node_id nodeid);
75 
76 	/* Add media_node_id of all live nodes to the message
77 	 * int32 "media_node_id" (multiple items)
78 	 */
79 	status_t GetLiveNodes(BMessage *msg);
80 
81 	void RegisterAddon(const entry_ref &ref, media_addon_id *newid);
82 	void UnregisterAddon(media_addon_id id);
83 
84 	void AddDormantFlavorInfo(const dormant_flavor_info &dfi);
85 	void InvalidateDormantFlavorInfo(media_addon_id id);
86 	void RemoveDormantFlavorInfo(media_addon_id id);
87 	void CleanupDormantFlavorInfos();
88 
89 	status_t IncrementAddonFlavorInstancesCount(media_addon_id addonid, int32 flavorid, team_id team);
90 	status_t DecrementAddonFlavorInstancesCount(media_addon_id addonid, int32 flavorid, team_id team);
91 
92 	status_t GetAddonRef(entry_ref *ref, media_addon_id id);
93 	status_t GetDormantNodes(dormant_node_info * out_info,
94 							  int32 * io_count,
95 							  const media_format * has_input /* = NULL */,
96 							  const media_format * has_output /* = NULL */,
97 							  const char * name /* = NULL */,
98 							  uint64 require_kinds /* = NULL */,
99 							  uint64 deny_kinds /* = NULL */);
100 
101 	status_t GetDormantFlavorInfoFor(media_addon_id addon,
102 									 int32 flavor_id,
103 									 dormant_flavor_info *outFlavor);
104 
105 	void CleanupTeam(team_id team);
106 
107 private:
108 	media_addon_id fNextAddOnID;
109 	media_node_id fNextNodeID;
110 
111 	BLocker *fLocker;
112 	List<dormant_addon_flavor_info> *fDormantAddonFlavorList;
113 	Map<media_addon_id,entry_ref> *fAddonPathMap;
114 	Map<media_node_id,registered_node> *fRegisteredNodeMap;
115 	DefaultManager *fDefaultManager;
116 };
117