Skip to content

Commit 0643be2

Browse files
committed
docs: add Video Capture guide
1 parent 1772a81 commit 0643be2

File tree

3 files changed

+112
-0
lines changed

3 files changed

+112
-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+
- [Video Capture](guide/video_capture.md)
3132
- [Screen Capturer](guide/screen_capturer.md)
3233
- [Window Capturer](guide/window_capturer.md)
3334
- [Voice Activity Detector](guide/voice_activity_detector.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+
- [Video Capture](guide/video_capture.md) - Control a camera device, configure capabilities, and deliver frames to a sink
4142
- [Screen Capturer](guide/screen_capturer.md) - Enumerate and capture full desktop screens/monitors
4243
- [Window Capturer](guide/window_capturer.md) - Enumerate and capture individual application windows
4344
- [Voice Activity Detector](guide/voice_activity_detector.md) - Detect speech activity in PCM audio streams

docs/guide/video_capture.md

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# Video Capture
2+
3+
The `VideoCapture` class represents a controllable video capture device and coordinates device selection, capability negotiation, frame delivery to a sink, and lifecycle/resource management.
4+
5+
API: `dev.onvoid.webrtc.media.video.VideoCapture`
6+
7+
## Overview
8+
9+
- Purpose: Control a physical or virtual video input device and deliver frames to a sink.
10+
- Typical workflow: set device ➜ set capability ➜ set sink ➜ start ➜ stop ➜ dispose.
11+
- Resource management: Always call `dispose()` to release native resources.
12+
- Threading: Methods are not guaranteed to be thread‑safe; synchronize externally if accessed from multiple threads.
13+
14+
Key methods:
15+
- `void setVideoCaptureDevice(VideoDevice device)` – select the camera/device to bind.
16+
- `void setVideoCaptureCapability(VideoCaptureCapability capability)` – configure desired resolution, frame rate, pixel format, etc.
17+
- `void setVideoSink(VideoTrackSink sink)` – register/replace the sink that will receive frames.
18+
- `void start()` – begin asynchronous capture and frame delivery.
19+
- `void stop()` – stop capture (idempotent).
20+
- `void dispose()` – release native resources; implicitly stops if running.
21+
22+
Related types:
23+
- `VideoDevice` – describes a capturable device (enumerate via your platform/device utilities).
24+
- `VideoCaptureCapability` – resolution, FPS, and pixel format preferences.
25+
- `VideoTrackSink` – consumer that receives `VideoFrame` callbacks.
26+
27+
## Typical usage
28+
29+
```java
30+
import dev.onvoid.webrtc.media.video.*;
31+
32+
// 1) Create capture
33+
VideoCapture capture = new VideoCapture();
34+
35+
try {
36+
// 2) Select a device (obtained from your device enumeration logic)
37+
VideoDevice device = /* obtain a VideoDevice */;
38+
capture.setVideoCaptureDevice(device);
39+
40+
// 3) Configure capability
41+
VideoCaptureCapability cap = new VideoCaptureCapability();
42+
cap.width = 1280;
43+
cap.height = 720;
44+
cap.maxFPS = 30;
45+
// cap.pixelFormat = ... // if applicable in your build
46+
capture.setVideoCaptureCapability(cap);
47+
48+
// 4) Provide a sink to receive frames
49+
VideoTrackSink sink = frame -> {
50+
// Consume VideoFrame
51+
// e.g., render, encode, or forward to a WebRTC VideoSource/Track
52+
};
53+
capture.setVideoSink(sink);
54+
55+
// 5) Start capture
56+
capture.start();
57+
58+
// ... capture is running, frames delivered to sink ...
59+
60+
// 6) Stop capture
61+
capture.stop();
62+
}
63+
finally {
64+
// 7) Cleanup
65+
capture.dispose();
66+
}
67+
```
68+
69+
Notes:
70+
- Call `setVideoCaptureDevice` and `setVideoCaptureCapability` before `start()`.
71+
- You may call `setVideoSink` before or after `start()`; passing `null` detaches the sink (if supported), dropping frames until a new sink is set.
72+
- Some capability values may be negotiated to the nearest supported values by the underlying platform.
73+
74+
## Integration with WebRTC tracks
75+
76+
While `VideoCapture` handles raw capture, most WebRTC pipelines use a `VideoSource`/`VideoTrack` abstraction. If you need to feed frames into a `VideoTrack`, use or implement a sink that forwards frames to your `VideoSource` (or use a higher‑level helper provided by this project/examples).
77+
78+
Example sketch:
79+
80+
```java
81+
VideoTrackSink sink = frame -> {
82+
// Convert/forward frame into your WebRTC VideoSource or renderer
83+
};
84+
85+
capture.setVideoSink(sink);
86+
capture.start();
87+
```
88+
89+
If you need pixel format conversion, see `VideoBufferConverter`.
90+
91+
## Error handling and lifecycle
92+
93+
- Constructor: Initializes native resources; failures may surface as runtime exceptions from native code.
94+
- `IllegalStateException`: Thrown if methods are invoked after disposal or when prerequisites are missing.
95+
- Idempotency: `start()` and `stop()` are intended to be safe to call multiple times (implementation‑dependent no‑op if already in that state).
96+
- Always call `dispose()` in a `finally` block to avoid leaking native resources.
97+
98+
## Tips
99+
100+
- Device changes (plug/unplug cameras) may require re‑enumeration and re‑selection via `setVideoCaptureDevice`.
101+
- If frames need scaling or color conversion, use `VideoBufferConverter` before feeding frames to encoders or renderers.
102+
- Synchronize access if multiple threads change device, capability, or sink while capturing.
103+
104+
## Related guides
105+
106+
- [Camera Capture](guide/camera_capture.md)
107+
- [Custom Video Source](guide/custom_video_source.md)
108+
- [Screen Capturer](guide/screen_capturer.md)
109+
- [Window Capturer](guide/window_capturer.md)
110+
- [Power Management](guide/power_management.md)

0 commit comments

Comments
 (0)