Skip to content

Commit 7d3345b

Browse files
committed
docs: add Power Management utility
1 parent 8b19bac commit 7d3345b

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

docs/_sidebar.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
- [Logging](guide/logging.md)
2929
- Utilities
3030
- [Audio Converter](guide/audio_converter.md)
31+
- [Power Management](guide/power_management.md)
3132
- [Voice Activity Detector](guide/voice_activity_detector.md)
3233

3334
- [**Build Notes**](build.md)

docs/guide/overview.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ This section provides detailed guides for various features of the webrtc-java li
3838
## Utilities
3939

4040
- [Audio Converter](guide/audio_converter.md) - Resample and remix 10 ms PCM frames between different rates and channel layouts
41+
- [Power Management](guide/power_management.md) - Prevent the display from sleeping during desktop capture or presentations
4142
- [Voice Activity Detector](guide/voice_activity_detector.md) - Detect speech activity in PCM audio streams
4243

4344
## Additional Resources

docs/guide/power_management.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Power Management
2+
3+
The `PowerManagement` utility allows your application to keep the display awake and prevent the operating system from idling to sleep while the user is considered "active" by your app. This is especially useful during screen sharing, presentations, or long-running desktop capture sessions where user input may be minimal.
4+
5+
API: `dev.onvoid.webrtc.media.video.desktop.PowerManagement`
6+
7+
## Overview
8+
9+
- Purpose: Temporarily prevent the system from sleeping due to user idle.
10+
- Scope: Affects display sleep/idle behavior while enabled.
11+
- Cross‑platform: Implements native integrations for Windows, Linux, and macOS.
12+
- Responsibility: You must explicitly disable the assertion when you are done.
13+
14+
Key methods:
15+
- `void enableUserActivity()` – Declare the user as active; prevents idle sleep.
16+
- `void disableUserActivity()` – Revoke the assertion; system idle behavior resumes normally.
17+
18+
## Typical usage
19+
20+
Call `enableUserActivity()` when you start an operation that must keep the display awake (e.g., desktop capture or a presentation). Always pair it with `disableUserActivity()` (for example, in a `finally` block) to restore the normal power behavior.
21+
22+
```java
23+
import dev.onvoid.webrtc.media.video.desktop.PowerManagement;
24+
25+
PowerManagement pm = new PowerManagement();
26+
27+
// Example: keep display awake during a screen sharing session
28+
pm.enableUserActivity();
29+
try {
30+
// Start and run your desktop capture / screen sharing pipeline
31+
// ...
32+
}
33+
finally {
34+
// Always restore normal behavior
35+
pm.disableUserActivity();
36+
}
37+
```
38+
39+
## Integration tips
40+
41+
- Lifetime management: Keep the `PowerManagement` instance for as long as you need the assertion. It's safe to call `enableUserActivity()` once at the start and `disableUserActivity()` once at the end.
42+
- Fail‑safe: If your workflow can terminate unexpectedly, ensure `disableUserActivity()` is called (e.g., in `finally` blocks, shutdown hooks, or close handlers).
43+
- Minimal footprint: Only enable while strictly necessary. Do not keep the assertion enabled longer than needed.
44+
45+
## Platform notes
46+
47+
- Windows: Uses native Windows power APIs to request that the display remain on while enabled.
48+
- Linux (Freedesktop environments): Uses DBus screensaver inhibition (e.g., org.freedesktop.ScreenSaver) where available.
49+
- macOS: Uses macOS power management assertions to prevent display sleep while enabled.
50+
51+
Exact mechanisms are handled by the native layer; your Java code remains the same across platforms.
52+
53+
## When to use
54+
55+
- While capturing or sharing the desktop to prevent the monitor from sleeping during inactivity.
56+
- During long‑running, unattended demos, playback, or monitoring dashboards where user input is infrequent.
57+
58+
## Related guides
59+
60+
- [Desktop Capture](guide/desktop_capture.md)
61+
- [Logging](guide/logging.md)

0 commit comments

Comments
 (0)