1 /* PipeWire 2 * 3 * Copyright © 2018 Wim Taymans 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a 6 * copy of this software and associated documentation files (the "Software"), 7 * to deal in the Software without restriction, including without limitation 8 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 * and/or sell copies of the Software, and to permit persons to whom the 10 * Software is furnished to do so, subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice (including the next 13 * paragraph) shall be included in all copies or substantial portions of the 14 * Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 * DEALINGS IN THE SOFTWARE. 23 */ 24 25 #ifndef PIPEWIRE_NODE_H 26 #define PIPEWIRE_NODE_H 27 28 #ifdef __cplusplus 29 extern "C" { 30 #endif 31 32 #include <stdarg.h> 33 #include <errno.h> 34 35 #include <spa/utils/defs.h> 36 #include <spa/utils/hook.h> 37 #include <spa/node/command.h> 38 #include <spa/param/param.h> 39 40 #include <pipewire/proxy.h> 41 42 #define PW_TYPE_INTERFACE_Node PW_TYPE_INFO_INTERFACE_BASE "Node" 43 44 #define PW_VERSION_NODE 3 45 struct pw_node; 46 47 /** \enum pw_node_state The different node states \memberof pw_node */ 48 enum pw_node_state { 49 PW_NODE_STATE_ERROR = -1, /**< error state */ 50 PW_NODE_STATE_CREATING = 0, /**< the node is being created */ 51 PW_NODE_STATE_SUSPENDED = 1, /**< the node is suspended, the device might 52 * be closed */ 53 PW_NODE_STATE_IDLE = 2, /**< the node is running but there is no active 54 * port */ 55 PW_NODE_STATE_RUNNING = 3, /**< the node is running */ 56 }; 57 58 /** Convert a \ref pw_node_state to a readable string \memberof pw_node */ 59 const char * pw_node_state_as_string(enum pw_node_state state); 60 61 /** The node information. Extra information can be added in later versions \memberof pw_introspect */ 62 struct pw_node_info { 63 uint32_t id; /**< id of the global */ 64 uint32_t max_input_ports; /**< maximum number of inputs */ 65 uint32_t max_output_ports; /**< maximum number of outputs */ 66 #define PW_NODE_CHANGE_MASK_INPUT_PORTS (1 << 0) 67 #define PW_NODE_CHANGE_MASK_OUTPUT_PORTS (1 << 1) 68 #define PW_NODE_CHANGE_MASK_STATE (1 << 2) 69 #define PW_NODE_CHANGE_MASK_PROPS (1 << 3) 70 #define PW_NODE_CHANGE_MASK_PARAMS (1 << 4) 71 #define PW_NODE_CHANGE_MASK_ALL ((1 << 5)-1) 72 uint64_t change_mask; /**< bitfield of changed fields since last call */ 73 uint32_t n_input_ports; /**< number of inputs */ 74 uint32_t n_output_ports; /**< number of outputs */ 75 enum pw_node_state state; /**< the current state of the node */ 76 const char *error; /**< an error reason if \a state is error */ 77 struct spa_dict *props; /**< the properties of the node */ 78 struct spa_param_info *params; /**< parameters */ 79 uint32_t n_params; /**< number of items in \a params */ 80 }; 81 82 struct pw_node_info * 83 pw_node_info_update(struct pw_node_info *info, 84 const struct pw_node_info *update); 85 86 void 87 pw_node_info_free(struct pw_node_info *info); 88 89 #define PW_NODE_EVENT_INFO 0 90 #define PW_NODE_EVENT_PARAM 1 91 #define PW_NODE_EVENT_NUM 2 92 93 /** Node events */ 94 struct pw_node_events { 95 #define PW_VERSION_NODE_EVENTS 0 96 uint32_t version; 97 /** 98 * Notify node info 99 * 100 * \param info info about the node 101 */ 102 void (*info) (void *object, const struct pw_node_info *info); 103 /** 104 * Notify a node param 105 * 106 * Event emitted as a result of the enum_params method. 107 * 108 * \param seq the sequence number of the request 109 * \param id the param id 110 * \param index the param index 111 * \param next the param index of the next param 112 * \param param the parameter 113 */ 114 void (*param) (void *object, int seq, 115 uint32_t id, uint32_t index, uint32_t next, 116 const struct spa_pod *param); 117 }; 118 119 #define PW_NODE_METHOD_ADD_LISTENER 0 120 #define PW_NODE_METHOD_SUBSCRIBE_PARAMS 1 121 #define PW_NODE_METHOD_ENUM_PARAMS 2 122 #define PW_NODE_METHOD_SET_PARAM 3 123 #define PW_NODE_METHOD_SEND_COMMAND 4 124 #define PW_NODE_METHOD_NUM 5 125 126 /** Node methods */ 127 struct pw_node_methods { 128 #define PW_VERSION_NODE_METHODS 0 129 uint32_t version; 130 131 int (*add_listener) (void *object, 132 struct spa_hook *listener, 133 const struct pw_node_events *events, 134 void *data); 135 /** 136 * Subscribe to parameter changes 137 * 138 * Automatically emit param events for the given ids when 139 * they are changed. 140 * 141 * \param ids an array of param ids 142 * \param n_ids the number of ids in \a ids 143 */ 144 int (*subscribe_params) (void *object, uint32_t *ids, uint32_t n_ids); 145 146 /** 147 * Enumerate node parameters 148 * 149 * Start enumeration of node parameters. For each param, a 150 * param event will be emitted. 151 * 152 * \param seq a sequence number to place in the reply 153 * \param id the parameter id to enum or PW_ID_ANY for all 154 * \param start the start index or 0 for the first param 155 * \param num the maximum number of params to retrieve 156 * \param filter a param filter or NULL 157 */ 158 int (*enum_params) (void *object, int seq, uint32_t id, 159 uint32_t start, uint32_t num, 160 const struct spa_pod *filter); 161 162 /** 163 * Set a parameter on the node 164 * 165 * \param id the parameter id to set 166 * \param flags extra parameter flags 167 * \param param the parameter to set 168 */ 169 int (*set_param) (void *object, uint32_t id, uint32_t flags, 170 const struct spa_pod *param); 171 172 /** 173 * Send a command to the node 174 * 175 * \param command the command to send 176 */ 177 int (*send_command) (void *object, const struct spa_command *command); 178 }; 179 180 #define pw_node_method(o,method,version,...) \ 181 ({ \ 182 int _res = -ENOTSUP; \ 183 spa_interface_call_res((struct spa_interface*)o, \ 184 struct pw_node_methods, _res, \ 185 method, version, ##__VA_ARGS__); \ 186 _res; \ 187 }) 188 189 /** Node */ 190 #define pw_node_add_listener(c,...) pw_node_method(c,add_listener,0,__VA_ARGS__) 191 #define pw_node_subscribe_params(c,...) pw_node_method(c,subscribe_params,0,__VA_ARGS__) 192 #define pw_node_enum_params(c,...) pw_node_method(c,enum_params,0,__VA_ARGS__) 193 #define pw_node_set_param(c,...) pw_node_method(c,set_param,0,__VA_ARGS__) 194 #define pw_node_send_command(c,...) pw_node_method(c,send_command,0,__VA_ARGS__) 195 196 #ifdef __cplusplus 197 } /* extern "C" */ 198 #endif 199 200 #endif /* PIPEWIRE_NODE_H */ 201