Skip to content

Commit b5971f9

Browse files
Initial pass at doxygen standardization, thread-safe reporting, and AGENTS.md update around commenting code. Still pretty AI-worded and needs some cleanup
1 parent 4951765 commit b5971f9

40 files changed

Lines changed: 3729 additions & 2159 deletions

‎AGENTS.md‎

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,105 @@ with the same library loaded elsewhere in the host process.
209209
- Use `LK_LOG_WARN` for non-fatal unexpected conditions.
210210
- Use `Result<T, E>` for operations that can fail with typed errors (e.g., data track publish/subscribe).
211211

212+
### Public API Documentation (Doxygen)
213+
214+
The public API (`include/livekit/*.h`) is what consumers read first and is also
215+
published as a Doxygen site (`docs/Doxyfile`, `.github/workflows/publish-docs.yml`).
216+
Every public class, struct, free function, type alias, enum, enum value, and
217+
method in `include/livekit/` must follow the rules below. **PRs adding or
218+
modifying public symbols are gated on these rules during code review.**
219+
220+
#### Comment style
221+
222+
- Use triple-slash `///` Doxygen comments. Do **not** use `/** ... */` Javadoc
223+
blocks for new code, and prefer migrating existing ones when you touch them.
224+
- Apache license headers stay as `/* ... */` block comments — they are not
225+
documentation.
226+
- Implementation comments inside `.cpp` files (non-Doxygen) may use `//` freely.
227+
- Keep the first line a short one-sentence brief. Follow with a blank `///`
228+
line and a longer description if needed. Example:
229+
230+
```cpp
231+
/// Publish a local track to the room.
232+
///
233+
/// Blocks until the FFI publish response arrives.
234+
///
235+
/// @param track Track to publish. Must be non-null.
236+
/// @param options Publish options (codec, simulcast, etc.).
237+
/// @throws std::runtime_error if the FFI reports an error.
238+
///
239+
/// @note Thread-safety: Not thread-safe. Must be externally synchronized.
240+
void publishTrack(const std::shared_ptr<Track>& track, const TrackPublishOptions& options);
241+
```
242+
243+
#### Parameter documentation
244+
245+
- Every parameter on every public function and method must be documented with
246+
`@param name Description.`
247+
- Document `@return` for any non-void return value. Omit `@return` for `void`.
248+
- Document `@throws ExceptionType When/why it's thrown.` for anything that
249+
can throw a typed exception. Operations that can fail without throwing
250+
should return `Result<T, E>` (see Error Handling above) and the variants
251+
should be documented in the doc block.
252+
- Trivial inline accessors (e.g. `int sample_rate() const noexcept`) only need
253+
a one-line `///` brief and may omit `@param`/`@return` when they take no
254+
arguments and the brief already describes the returned value.
255+
- Use `@param[out]` or `@param[in,out]` when a non-const reference or pointer
256+
is used as an output or in-out parameter.
257+
258+
#### Thread-safety annotations
259+
260+
Every public class and every public method must declare its thread-safety in a
261+
consistent, grep-able form. Two labels are used:
262+
263+
- **`Thread-safe.`** — Safe to call concurrently from multiple threads. If the
264+
safety comes from internal synchronization (mutex, queue, atomic) rather
265+
than statelessness, briefly say so. Methods whose callers are *serialized
266+
internally* (e.g. `TextStreamWriter::write` via an internal `write_mutex_`)
267+
are documented as thread-safe with the prose noting the serialization.
268+
- **`Not thread-safe.`** — Must be externally synchronized; concurrent calls
269+
from multiple threads are undefined behavior. Briefly say what the caller
270+
must ensure (e.g. "must be called from a single capture thread").
271+
272+
Use the `@note` Doxygen tag so it renders as a styled callout and is easy to
273+
search for:
274+
275+
```cpp
276+
/// @note Thread-safety: Thread-safe. Internal `std::mutex` protects all
277+
/// mutable state.
278+
```
279+
280+
```cpp
281+
/// @note Thread-safety: Not thread-safe. Concurrent `captureFrame` calls
282+
/// from multiple threads are undefined behavior.
283+
```
284+
285+
Placement:
286+
- For classes where all (or all non-trivially) methods share the same
287+
thread-safety guarantee, put the `@note Thread-safety:` line on the class
288+
doc block. Individual methods only re-document thread-safety when they
289+
*deviate* from the class-level guarantee.
290+
- For classes where guarantees differ per-method (`Room`, `LocalParticipant`,
291+
stream writers/readers, etc.), document `@note Thread-safety:` on every
292+
public method.
293+
294+
The authoritative thread-safety table for the SDK as a whole lives in the
295+
[Threading Model](#threading-model) section above; per-symbol annotations
296+
must agree with it. If you add a new public type, also add an entry there.
297+
298+
#### Review checklist for new/modified public APIs
299+
300+
Before approving a PR that touches `include/livekit/*.h`, confirm:
301+
302+
- [ ] Every new/changed public symbol has a `///` doc block (no `/** */`).
303+
- [ ] Every parameter is covered by `@param`.
304+
- [ ] `@return` documents non-void returns; `@throws` documents thrown
305+
exceptions; `Result<T, E>` variants are described.
306+
- [ ] `@note Thread-safety: ...` is present, either at the class level or on
307+
each affected method, using the two-tier vocabulary above.
308+
- [ ] The Threading Model table at the top of this file is updated if a new
309+
public type was introduced.
310+
212311
### Integer Types
213312

214313
- Prefer fixed-width integer types from `<cstdint>` (`std::int32_t`, `std::uint64_t`, etc.) over raw primitive integer types when size or signedness matters.

‎include/livekit/audio_frame.h‎

Lines changed: 52 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* http://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an “AS IS” BASIS,
11+
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
@@ -29,65 +29,81 @@ class AudioFrameBufferInfo;
2929
class OwnedAudioFrameBuffer;
3030
} // namespace proto
3131

32-
/**
33-
* @brief Represents a raw PCM audio frame with interleaved int16 samples.
34-
*
35-
* AudioFrame holds decoded audio data along with metadata such as sample rate,
36-
* number of channels, and samples per channel. It is used for capturing and
37-
* processing audio in the LiveKit SDK.
38-
*/
32+
/// A raw PCM audio frame with interleaved `int16` samples.
33+
///
34+
/// `AudioFrame` holds decoded audio data along with metadata such as
35+
/// sample rate, number of channels, and samples per channel. It is used
36+
/// for capturing and processing audio in the LiveKit SDK.
37+
///
38+
/// @note Thread-safety: Not thread-safe. A single `AudioFrame` instance
39+
/// must not be mutated concurrently from multiple threads; concurrent
40+
/// const-access is safe.
3941
class LIVEKIT_API AudioFrame {
4042
public:
41-
/**
42-
* Construct an AudioFrame from raw PCM samples.
43-
*
44-
* @param data Interleaved PCM samples (int16).
45-
* @param sample_rate Sample rate (Hz).
46-
* @param num_channels Number of channels.
47-
* @param samples_per_channel Number of samples per channel.
48-
*
49-
* Throws std::invalid_argument if the data size is inconsistent with
50-
* num_channels * samples_per_channel.
51-
*/
43+
/// Construct an `AudioFrame` from raw PCM samples.
44+
///
45+
/// @param data Interleaved PCM samples (`int16`).
46+
/// @param sample_rate Sample rate (Hz).
47+
/// @param num_channels Number of channels.
48+
/// @param samples_per_channel Number of samples per channel.
49+
///
50+
/// @throws std::invalid_argument if `data.size()` is inconsistent with
51+
/// `num_channels * samples_per_channel`.
5252
AudioFrame(std::vector<std::int16_t> data, int sample_rate, int num_channels, int samples_per_channel);
53-
AudioFrame(); // Default constructor
53+
54+
/// Construct an empty `AudioFrame` (all fields zero-initialized).
55+
AudioFrame();
56+
5457
virtual ~AudioFrame() = default;
5558

56-
/**
57-
* Create a new zero-initialized AudioFrame instance.
58-
*/
59+
/// Create a new zero-initialized `AudioFrame` instance.
60+
///
61+
/// @param sample_rate Sample rate (Hz).
62+
/// @param num_channels Number of channels.
63+
/// @param samples_per_channel Number of samples per channel.
64+
/// @return A frame whose buffer is sized to
65+
/// `num_channels * samples_per_channel`
66+
/// and zero-filled.
67+
///
68+
/// @note Thread-safety: Thread-safe. Pure factory function.
5969
static AudioFrame create(int sample_rate, int num_channels, int samples_per_channel);
6070

61-
/**
62-
* Construct an AudioFrame by copying data out of an OwnedAudioFrameBuffer.
63-
*/
71+
/// Construct an `AudioFrame` by copying data out of an FFI-owned
72+
/// audio buffer.
73+
///
74+
/// @param owned Buffer received from the FFI (data is copied).
75+
/// @return A new `AudioFrame` owning a copy of the samples.
76+
///
77+
/// @note Thread-safety: Thread-safe. Pure transformation; no global
78+
/// state.
6479
static AudioFrame fromOwnedInfo(const proto::OwnedAudioFrameBuffer& owned);
6580

66-
// ---- Accessors ----
67-
81+
/// @return Mutable reference to the underlying sample buffer.
6882
const std::vector<std::int16_t>& data() const noexcept { return data_; }
83+
84+
/// @return Mutable reference to the underlying sample buffer.
6985
std::vector<std::int16_t>& data() noexcept { return data_; }
7086

71-
/// Number of samples in the buffer (per all channels).
87+
/// @return Total number of samples in the buffer across all channels.
7288
std::size_t total_samples() const noexcept { return data_.size(); }
7389

74-
/// Sample rate in Hz.
90+
/// @return Sample rate in Hz.
7591
int sample_rate() const noexcept { return sample_rate_; }
7692

77-
/// Number of channels.
93+
/// @return Number of channels.
7894
int num_channels() const noexcept { return num_channels_; }
7995

80-
/// Samples per channel.
96+
/// @return Samples per channel.
8197
int samples_per_channel() const noexcept { return samples_per_channel_; }
8298

83-
/// Duration in seconds (samples_per_channel / sample_rate).
99+
/// @return Duration in seconds (`samples_per_channel / sample_rate`).
84100
double duration() const noexcept;
85101

86-
/// A human-readable description.
102+
/// @return Human-readable description (sample rate, channels, size).
87103
std::string to_string() const;
88104

89105
protected:
90-
// Build a proto AudioFrameBufferInfo pointing at this frame’s data.
106+
// Build a proto AudioFrameBufferInfo pointing at this frame's data.
91107
// Used internally by AudioSource.
92108
proto::AudioFrameBufferInfo toProto() const;
93109
friend class AudioSource;
@@ -99,4 +115,4 @@ class LIVEKIT_API AudioFrame {
99115
int samples_per_channel_;
100116
};
101117

102-
} // namespace livekit
118+
} // namespace livekit

0 commit comments

Comments
 (0)