Skip to content

Commit 57e6fe9

Browse files
PatternVideoSourceConfig
1 parent 6fc46ab commit 57e6fe9

3 files changed

Lines changed: 39 additions & 17 deletions

File tree

‎include/livekit/capture_source.h‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,24 @@ struct GstreamerVideoSourceConfig {
105105
std::optional<GstreamerRateControl> rate_control;
106106
};
107107

108-
/// Configuration for the built-in test source producing solid-color frames.
109-
struct DemoVideoSourceConfig {
108+
/// Test pattern rendered by the built-in pattern source.
109+
enum class Pattern {
110+
/// Animated color gradient.
111+
Gradient = 0,
112+
/// Bouncing LiveKit logo.
113+
Logo = 1,
114+
};
115+
116+
/// Configuration for the built-in test source rendering a @ref Pattern.
117+
struct PatternVideoSourceConfig {
110118
/// Output resolution; both components must be non-zero.
111119
CaptureResolution resolution;
112120

113121
/// Output frame rate in frames per second; must be non-zero.
114122
std::uint32_t framerate_fps = 0;
123+
124+
/// Pattern to render.
125+
Pattern pattern = Pattern::Gradient;
115126
};
116127

117128
/// Frame format delivered by a capture device.
@@ -350,8 +361,8 @@ class LIVEKIT_API CaptureSource {
350361
/// the future as @ref CaptureSourceError.
351362
static std::future<std::shared_ptr<CaptureSource>> create(GstreamerVideoSourceConfig config);
352363

353-
/// Create the built-in demo capture source (solid cycling colors).
354-
static std::future<std::shared_ptr<CaptureSource>> create(DemoVideoSourceConfig config);
364+
/// Create the built-in test pattern capture source.
365+
static std::future<std::shared_ptr<CaptureSource>> create(PatternVideoSourceConfig config);
355366

356367
/// Create a capture source from a camera device.
357368
///

‎src/capture_source.cpp‎

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,16 @@ proto::GstreamerBitrateUnit toProto(GstreamerBitrateUnit unit) {
144144
return proto::GstreamerBitrateUnit::GSTREAMER_BITRATE_UNIT_BPS;
145145
}
146146

147+
proto::Pattern toProto(Pattern pattern) {
148+
switch (pattern) {
149+
case Pattern::Gradient:
150+
return proto::Pattern::PATTERN_GRADIENT;
151+
case Pattern::Logo:
152+
return proto::Pattern::PATTERN_LOGO;
153+
}
154+
return proto::Pattern::PATTERN_GRADIENT;
155+
}
156+
147157
CaptureResult resultFromEvent(const proto::CaptureSourceEvent& event) {
148158
CaptureResult result;
149159
if (event.has_error()) {
@@ -180,12 +190,13 @@ std::future<std::shared_ptr<CaptureSource>> CaptureSource::create(GstreamerVideo
180190
return createFromRequest(std::move(request));
181191
}
182192

183-
std::future<std::shared_ptr<CaptureSource>> CaptureSource::create(DemoVideoSourceConfig config) {
193+
std::future<std::shared_ptr<CaptureSource>> CaptureSource::create(PatternVideoSourceConfig config) {
184194
proto::NewCaptureSourceRequest request;
185-
auto* demo = request.mutable_demo();
186-
demo->mutable_resolution()->set_width(config.resolution.width);
187-
demo->mutable_resolution()->set_height(config.resolution.height);
188-
demo->set_framerate_fps(config.framerate_fps);
195+
auto* pattern = request.mutable_pattern();
196+
pattern->mutable_resolution()->set_width(config.resolution.width);
197+
pattern->mutable_resolution()->set_height(config.resolution.height);
198+
pattern->set_framerate_fps(config.framerate_fps);
199+
pattern->set_pattern(toProto(config.pattern));
189200
return createFromRequest(std::move(request));
190201
}
191202

‎src/tests/integration/test_capture_source.cpp‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
/// Tests for capture sources (livekit-capture over FFI).
1818
///
19-
/// Two groups. `CaptureSourceServerTest` publishes the built-in demo source —
19+
/// Two groups. `CaptureSourceServerTest` publishes the built-in pattern source —
2020
/// the capture pump pushes frames server-side, so the test drives no frames
2121
/// itself — and verifies that a second participant receives real video through
2222
/// the SFU. `CaptureDeviceTest` covers camera device enumeration and format
@@ -58,8 +58,8 @@ constexpr std::uint32_t kCaptureFramerateFps = 30;
5858
GTEST_SKIP() << "livekit-ffi built without the 'capture' feature; configure with -DLIVEKIT_ENABLE_CAPTURE=ON"
5959
#endif
6060
61-
std::shared_ptr<CaptureSource> createDemoCapture() {
62-
DemoVideoSourceConfig config;
61+
std::shared_ptr<CaptureSource> createPatternCapture() {
62+
PatternVideoSourceConfig config;
6363
config.resolution = {kCaptureWidth, kCaptureHeight};
6464
config.framerate_fps = kCaptureFramerateFps;
6565
return CaptureSource::create(config).get();
@@ -166,14 +166,14 @@ TEST_F(CaptureDeviceTest, DefaultDeviceNegotiatesAFormat) {
166166
EXPECT_NE(capture->videoSource(), nullptr);
167167
}
168168
169-
TEST_F(CaptureSourceServerTest, DemoCaptureSourcePublishesFramesEndToEnd) {
169+
TEST_F(CaptureSourceServerTest, PatternCaptureSourcePublishesFramesEndToEnd) {
170170
SKIP_WITHOUT_CAPTURE_FEATURE();
171171
failIfNotConfigured();
172172
173-
auto capture = createDemoCapture();
173+
auto capture = createPatternCapture();
174174
ASSERT_NE(capture, nullptr);
175175
176-
// The demo source reports back the resolution it was configured with.
176+
// The pattern source reports back the resolution it was configured with.
177177
ASSERT_EQ(capture->kind(), CaptureSourceKind::Pixel);
178178
ASSERT_EQ(capture->width(), kCaptureWidth);
179179
ASSERT_EQ(capture->height(), kCaptureHeight);
@@ -199,7 +199,7 @@ TEST_F(CaptureSourceServerTest, DemoCaptureSourcePublishesFramesEndToEnd) {
199199
std::condition_variable cv;
200200
int frames_received = 0;
201201
202-
const std::string track_name = "demo-capture-track";
202+
const std::string track_name = "pattern-capture-track";
203203
receiver_room.setOnVideoFrameEventCallback(sender_identity, track_name,
204204
[&mutex, &cv, &frames_received](const VideoFrameEvent& /*event*/) {
205205
std::lock_guard<std::mutex> lock(mutex);
@@ -232,7 +232,7 @@ TEST_F(CaptureSourceServerTest, DemoCaptureSourcePublishesFramesEndToEnd) {
232232
std::unique_lock<std::mutex> lock(mutex);
233233
const bool got_frames =
234234
cv.wait_for(lock, 30s, [&frames_received] { return frames_received >= kMinFramesReceived; });
235-
ASSERT_TRUE(got_frames) << "Timed out waiting for demo capture frames; received " << frames_received;
235+
ASSERT_TRUE(got_frames) << "Timed out waiting for pattern capture frames; received " << frames_received;
236236
}
237237
238238
// Stop is a signal; the terminal callback delivers the stats.

0 commit comments

Comments
 (0)