Skip to content

Commit 8270a14

Browse files
internal api converter
1 parent 3a14465 commit 8270a14

4 files changed

Lines changed: 106 additions & 6 deletions

File tree

‎CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ add_library(livekit SHARED
411411
src/audio_frame.cpp
412412
src/audio_processing_module.cpp
413413
src/capture_source.cpp
414+
src/capture_source_internal.h
414415
src/audio_source.cpp
415416
src/audio_stream.cpp
416417
src/data_track_frame.cpp

‎src/capture_source.cpp‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <stdexcept>
2020

2121
#include "capture.pb.h"
22+
#include "capture_source_internal.h"
2223
#include "ffi.pb.h"
2324
#include "ffi_client.h"
2425
#include "room_proto_converter.h"
@@ -169,6 +170,15 @@ CaptureResult resultFromEvent(const proto::CaptureSourceEvent& event) {
169170

170171
} // namespace
171172

173+
std::vector<CaptureDeviceInfo> fromProto(const proto::CaptureDeviceList& list) {
174+
std::vector<CaptureDeviceInfo> devices;
175+
devices.reserve(static_cast<std::size_t>(list.devices_size()));
176+
for (const proto::CaptureDeviceInfo& device : list.devices()) {
177+
devices.push_back(fromProto(device));
178+
}
179+
return devices;
180+
}
181+
172182
std::future<std::shared_ptr<CaptureSource>> CaptureSource::create(GstreamerVideoSourceConfig config) {
173183
proto::NewCaptureSourceRequest request;
174184
auto* gstreamer = request.mutable_gstreamer();
@@ -317,12 +327,7 @@ std::future<std::vector<CaptureDeviceInfo>> CaptureSource::listDevices() {
317327
return std::async(std::launch::async, [devices = std::move(devices)]() mutable {
318328
try {
319329
const proto::CaptureDeviceList list = devices.get();
320-
std::vector<CaptureDeviceInfo> out;
321-
out.reserve(static_cast<std::size_t>(list.devices_size()));
322-
for (const proto::CaptureDeviceInfo& info : list.devices()) {
323-
out.push_back(fromProto(info));
324-
}
325-
return out;
330+
return fromProto(list);
326331
} catch (const CaptureSourceError&) {
327332
throw;
328333
} catch (const std::exception& e) {

‎src/capture_source_internal.h‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2026 LiveKit
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an “AS IS” BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#pragma once
18+
19+
#include <vector>
20+
21+
#include "livekit/capture_source.h"
22+
#include "livekit/visibility.h"
23+
24+
namespace livekit {
25+
26+
namespace proto {
27+
class CaptureDeviceList;
28+
}
29+
30+
/// Convert an FFI capture-device list to public device information.
31+
///
32+
/// Internal test seam; not part of the public SDK API.
33+
LIVEKIT_INTERNAL_API std::vector<CaptureDeviceInfo> fromProto(const proto::CaptureDeviceList& list);
34+
35+
} // namespace livekit
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright 2026 LiveKit
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an “AS IS” BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include <gtest/gtest.h>
18+
19+
#include "capture.pb.h"
20+
#include "capture_source_internal.h"
21+
22+
namespace livekit::test {
23+
namespace {
24+
25+
TEST(CaptureSourceProtoTest, ConvertsDeviceListToPublicTypes) {
26+
proto::CaptureDeviceList list;
27+
auto* device = list.add_devices();
28+
device->set_id("camera-1");
29+
device->set_name("Front camera");
30+
device->set_model_id("model-1");
31+
device->set_manufacturer("LiveKit");
32+
device->set_formats_complete(true);
33+
34+
auto* format = device->add_formats();
35+
format->mutable_resolution()->set_width(1920);
36+
format->mutable_resolution()->set_height(1080);
37+
format->set_framerate_fps(30);
38+
format->set_frame_format(proto::DeviceFrameFormat::DEVICE_FRAME_FORMAT_NV12);
39+
40+
const std::vector<CaptureDeviceInfo> devices = fromProto(list);
41+
42+
ASSERT_EQ(devices.size(), 1u);
43+
const CaptureDeviceInfo& converted = devices.front();
44+
EXPECT_EQ(converted.id, "camera-1");
45+
EXPECT_EQ(converted.name, "Front camera");
46+
ASSERT_TRUE(converted.model_id.has_value());
47+
EXPECT_EQ(*converted.model_id, "model-1");
48+
ASSERT_TRUE(converted.manufacturer.has_value());
49+
EXPECT_EQ(*converted.manufacturer, "LiveKit");
50+
EXPECT_TRUE(converted.formats_complete);
51+
ASSERT_EQ(converted.formats.size(), 1u);
52+
EXPECT_EQ(converted.formats.front().resolution.width, 1920);
53+
EXPECT_EQ(converted.formats.front().resolution.height, 1080);
54+
EXPECT_EQ(converted.formats.front().framerate_fps, 30u);
55+
EXPECT_EQ(converted.formats.front().frame_format, DeviceFrameFormat::NV12);
56+
}
57+
58+
} // namespace
59+
} // namespace livekit::test

0 commit comments

Comments
 (0)