Skip to content

Commit 7865d79

Browse files
committed
Refine docs
1 parent 8d2894f commit 7865d79

File tree

2 files changed

+145
-106
lines changed

2 files changed

+145
-106
lines changed

components/livekit/include/livekit.h

Lines changed: 113 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -9,162 +9,199 @@
99
extern "C" {
1010
#endif
1111

12-
/// @brief Handle to a room object.
13-
typedef void *livekit_room_handle_t;
14-
15-
/// @brief Result
12+
/// Error type returned by all public functions.
1613
typedef enum {
17-
LIVEKIT_ERR_NONE = 0,
18-
LIVEKIT_ERR_INVALID_ARG = -1,
19-
LIVEKIT_ERR_NO_MEM = -2,
20-
LIVEKIT_ERR_ENGINE = -3,
21-
LIVEKIT_ERR_OTHER = -4,
22-
LIVEKIT_ERR_INVALID_STATE = -5,
23-
// TODO: Add more error cases as needed
14+
LIVEKIT_ERR_NONE = 0, ///< No error
15+
LIVEKIT_ERR_INVALID_ARG = -1, ///< Invalid argument
16+
LIVEKIT_ERR_NO_MEM = -2, ///< Dynamic memory allocation failed
17+
LIVEKIT_ERR_ENGINE = -3, ///< Engine
18+
LIVEKIT_ERR_OTHER = -4, ///< Other error
19+
LIVEKIT_ERR_INVALID_STATE = -5, ///< Invalid state
2420
} livekit_err_t;
2521

26-
/// @brief Video codec to use within a room.
22+
/// Video codec to use within a room.
2723
typedef enum {
28-
LIVEKIT_VIDEO_CODEC_NONE = 0, // No video codec set
29-
LIVEKIT_VIDEO_CODEC_H264 = 1 // H.264 (AVC)
24+
LIVEKIT_VIDEO_CODEC_NONE = 0, ///< No video codec set
25+
LIVEKIT_VIDEO_CODEC_H264 = 1 ///< H.264 (AVC)
3026
} livekit_video_codec_t;
3127

32-
/// @brief Audio codec to use within a room.
28+
/// Audio codec to use within a room.
3329
typedef enum {
34-
LIVEKIT_AUDIO_CODEC_NONE = 0, // No audio codec set
35-
LIVEKIT_AUDIO_CODEC_G711A = 1, // G.711 A-law (PCMA)
36-
LIVEKIT_AUDIO_CODEC_G711U = 2, // G.711 u-law (PCMU)
37-
LIVEKIT_AUDIO_CODEC_OPUS = 3 // Opus
30+
LIVEKIT_AUDIO_CODEC_NONE = 0, ///< No audio codec set
31+
LIVEKIT_AUDIO_CODEC_G711A = 1, ///< G.711 A-law (PCMA)
32+
LIVEKIT_AUDIO_CODEC_G711U = 2, ///< G.711 u-law (PCMU)
33+
LIVEKIT_AUDIO_CODEC_OPUS = 3 ///< Opus
3834
} livekit_audio_codec_t;
3935

40-
/// @brief Media mode for the room.
36+
/// Media mode for the room.
4137
typedef enum {
42-
LIVEKIT_MEDIA_TYPE_NONE = 0, // No media
43-
LIVEKIT_MEDIA_TYPE_AUDIO = (1 << 0), // Audio only
44-
LIVEKIT_MEDIA_TYPE_VIDEO = (1 << 1), // Video only
45-
LIVEKIT_MEDIA_TYPE_BOTH = LIVEKIT_MEDIA_TYPE_AUDIO | LIVEKIT_MEDIA_TYPE_VIDEO, // Audio and video
38+
LIVEKIT_MEDIA_TYPE_NONE = 0, ///< No media
39+
LIVEKIT_MEDIA_TYPE_AUDIO = (1 << 0), ///< Audio only
40+
LIVEKIT_MEDIA_TYPE_VIDEO = (1 << 1), ///< Video only
41+
LIVEKIT_MEDIA_TYPE_BOTH = LIVEKIT_MEDIA_TYPE_AUDIO | LIVEKIT_MEDIA_TYPE_VIDEO, ///< Audio and video
4642
} livekit_media_kind_t;
4743

48-
/// @brief Options for the video encoder.
44+
/// Options for the video encoder.
4945
typedef struct {
50-
livekit_video_codec_t codec; // Codec to use for encoding
51-
int width; // Output frame width in pixels
52-
int height; // Output frame height in pixels
53-
int fps; // Output frame per second
46+
livekit_video_codec_t codec; ///< Codec to use for encoding
47+
int width; ///< Output frame width in pixels
48+
int height; ///< Output frame height in pixels
49+
int fps; ///< Output frame per second
5450
} livekit_video_encode_options_t;
5551

56-
/// @brief Options for the audio encoder.
52+
/// Options for the audio encoder.
5753
typedef struct {
58-
livekit_audio_codec_t codec; // Codec to use for encoding
59-
uint32_t sample_rate; // Output sample rate in Hz
60-
uint8_t channel_count; // Output number of channels
54+
livekit_audio_codec_t codec; ///< Codec to use for encoding
55+
uint32_t sample_rate; ///< Output sample rate in Hz
56+
uint8_t channel_count; ///< Output number of channels
6157
} livekit_audio_encode_options_t;
6258

63-
/// @brief Options for publishing a data packet.
59+
/// Payload containing a pointer to data and its size.
6460
typedef struct {
65-
/// @brief Topic to send the data packet under.
66-
char* topic;
67-
68-
/// @brief Whether the data packet is sent using the lossy channel.
69-
bool lossy;
70-
71-
/// @brief Identifies of participants to send the data packet to. If not
72-
/// specified, the data packet is sent to all participants.
73-
char** destination_identities;
74-
75-
/// @brief Number of destination identities.
76-
int destination_identities_count;
77-
} livekit_publish_data_options_t;
78-
79-
/// @brief Payload containing a pointer to data and its size.
80-
typedef struct {
81-
uint8_t *bytes;
82-
size_t size;
61+
uint8_t *bytes; ///< Pointer to data
62+
size_t size; ///< Size of the data
8363
} livekit_payload_t;
8464

8565
/// @brief Options for publishing media.
8666
typedef struct {
87-
/// @brief Kind of media that can be published.
67+
/// Kind of media that can be published.
8868
livekit_media_kind_t kind;
8969

90-
/// @brief Video encoder options.
70+
/// Video encoder options.
9171
/// @note Only required if the room publishes video.
9272
livekit_video_encode_options_t video_encode;
9373

94-
/// @brief Audio encoder options.
74+
/// Audio encoder options.
9575
/// @note Only required if the room publishes audio.
9676
livekit_audio_encode_options_t audio_encode;
9777

98-
/// @brief Capturer to use for obtaining media to publish.
78+
/// Capturer to use for obtaining media to publish.
9979
/// @note Only required if the room publishes media.
10080
esp_capture_handle_t capturer;
10181
} livekit_pub_options_t;
10282

10383
/// @brief Options for subscribing to media.
10484
typedef struct {
105-
/// @brief Kind of media that can be subscribed to.
85+
/// Kind of media that can be subscribed to.
10686
livekit_media_kind_t kind;
10787

108-
/// @brief Renderer to use for subscribed media tracks.
88+
/// Renderer to use for subscribed media tracks.
10989
/// @note Only required if the room subscribes to media.
11090
av_render_handle_t renderer;
11191
} livekit_sub_options_t;
11292

113-
/// @brief Options for a room.
93+
/// Options for a room passed to @ref livekit_room_create.
94+
/// @ingroup Lifecycle
11495
typedef struct {
115-
/// @brief Options for publishing media.
96+
/// Options for publishing media.
11697
/// @note Only required if the room publishes media.
11798
livekit_pub_options_t publish;
11899

119-
/// @brief Options for subscribing to media.
100+
/// Options for subscribing to media.
120101
/// @note Only required if the room subscribes to media.
121102
livekit_sub_options_t subscribe;
122103

104+
/// Callback for RPC results.
105+
/// @see RPC
123106
void (*on_rpc_result)(const livekit_rpc_result_t* result, void* ctx);
124107

125-
/// @brief User context passed to all handlers.
108+
/// User context passed to all handlers.
126109
void* ctx;
127110
} livekit_room_options_t;
128111

129-
/// @brief Creates a room.
112+
/// @defgroup Lifecycle
113+
/// Create and destroy room objects.
114+
/// @{
115+
116+
/// Handle to a room object.
117+
typedef void *livekit_room_handle_t;
118+
119+
/// Creates a room.
130120
/// @param handle[out] Room handle.
131121
/// @param options[in] Options for the new room.
132-
/// @return LIVEKIT_ERR_NONE if successful, otherwise an error code.
122+
/// @return @ref LIVEKIT_ERR_NONE if successful, otherwise an error code.
133123
livekit_err_t livekit_room_create(livekit_room_handle_t *handle, const livekit_room_options_t *options);
134124

135-
/// @brief Destroys a room.
125+
/// Destroys a room.
136126
/// @param handle[in] Room handle.
137-
/// @return LIVEKIT_ERR_NONE if successful, otherwise an error code.
138-
/// @warning Be sure to close the room before destroying it for normal closure.
127+
/// @warning For normal connection closure, disconnect the room first using
128+
/// @ref livekit_room_close before destroying the room.
129+
/// @return @ref LIVEKIT_ERR_NONE if successful, otherwise an error code.
139130
livekit_err_t livekit_room_destroy(livekit_room_handle_t handle);
140131

141-
/// @brief Connects to a room asynchronously.
132+
/// @}
133+
134+
/// @defgroup Connection
135+
/// Connect and disconnect from a room.
136+
/// @{
137+
138+
/// Connects to a room asynchronously.
142139
/// @param handle[in] Room handle.
143-
/// @param server_url[in] URL of the LiveKit server beginning with "wss://" or "ws://" (development only).
140+
/// @param server_url[in] URL of the LiveKit server beginning with "wss://" or "ws://".
144141
/// @param token[in] Server-generated token for authentication.
145142
/// @note Handle room events to get notified once the connection is established or fails.
146-
/// @return LIVEKIT_ERR_NONE, otherwise an error code.
143+
/// @return @ref LIVEKIT_ERR_NONE, otherwise an error code.
147144
livekit_err_t livekit_room_connect(livekit_room_handle_t handle, const char *server_url, const char *token);
148145

149-
/// @brief Disconnects from a room asynchronously.
146+
/// Disconnects from a room asynchronously.
150147
/// @param handle[in] Room handle.
151148
/// @note Handle room events to get notified once the disconnection is complete.
152-
/// @return LIVEKIT_ERR_NONE if successful, otherwise an error code.
149+
/// @return @ref LIVEKIT_ERR_NONE if successful, otherwise an error code.
153150
livekit_err_t livekit_room_close(livekit_room_handle_t handle);
154151

155-
/// @brief Publishes a data packet to participants in a room asynchronously.
152+
/// @}
153+
154+
/// @defgroup DataPackets Data packets
155+
///
156+
/// Low-level API for high-frequency data exchange.
157+
///
158+
/// For more information about this feature, see the
159+
/// [data packets documentation](https://docs.livekit.io/home/client/data/packets/).
160+
/// @{
161+
162+
/// Options passed to @ref livekit_room_publish_data.
163+
typedef struct {
164+
/// Topic to send the data packet under.
165+
char* topic;
166+
167+
/// Whether the data packet is sent using the lossy channel.
168+
bool lossy;
169+
170+
/// Identifies of participants to send the data packet to. If not
171+
/// specified, the data packet is sent to all participants.
172+
char** destination_identities;
173+
174+
/// Number of destination identities.
175+
int destination_identities_count;
176+
} livekit_publish_data_options_t;
177+
178+
/// Publishes a data packet to participants in a room asynchronously.
179+
/// @ingroup DataPackets
156180
/// @param handle[in] Room handle.
157181
/// @param payload[in] Data to publish and its size.
158182
/// @param options[in] Options for sending the data packet (e.g. reliability, topic, etc.).
159-
/// @return LIVEKIT_ERR_NONE if successful, otherwise an error code.
183+
/// @return @ref LIVEKIT_ERR_NONE if successful, otherwise an error code.
160184
livekit_err_t livekit_room_publish_data(livekit_room_handle_t handle, livekit_payload_t *payload, livekit_publish_data_options_t *options);
161185

162-
/// @brief Registers a handler for an RPC method.
186+
/// @}
187+
188+
/// @defgroup RPC Remote method calls (RPC)
189+
///
190+
/// Use RPC to execute custom methods on other participants in the room and
191+
/// await a response.
192+
///
193+
/// For more information about this feature, see the
194+
/// [RPC documentation](https://docs.livekit.io/home/client/data/rpc/).
195+
/// @{
196+
197+
/// Registers a handler for an RPC method.
163198
livekit_err_t livekit_room_rpc_register(livekit_room_handle_t handle, const char* method, livekit_rpc_handler_t handler);
164199

165-
/// @brief Unregisters a handler for an RPC method.
200+
/// Unregisters a handler for an RPC method.
166201
livekit_err_t livekit_room_rpc_unregister(livekit_room_handle_t handle, const char* method);
167202

203+
/// @}
204+
168205
#ifdef __cplusplus
169206
}
170207
#endif

0 commit comments

Comments
 (0)