Skip to content

Commit 9709913

Browse files
alan-george-lkstephen-derosa
authored andcommitted
Video source adapter
1 parent 205a687 commit 9709913

3 files changed

Lines changed: 20 additions & 8 deletions

File tree

‎include/livekit/video_source.h‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,9 @@
2525

2626
namespace livekit {
2727

28-
namespace capture {
29-
class CaptureSource;
30-
} // namespace capture
31-
3228
class VideoFrame;
3329
class EncodedVideoSource;
30+
struct VideoSourceAccess;
3431

3532
/// Rotation of a video frame.
3633
///
@@ -101,12 +98,12 @@ class LIVEKIT_API VideoSource {
10198

10299
private:
103100
friend class EncodedVideoSource;
104-
friend class capture::CaptureSource;
101+
friend struct VideoSourceAccess;
105102

106103
enum class SourceType { Native, Encoded };
107104
VideoSource(int width, int height, SourceType source_type);
108105

109-
/// @brief Adopt an existing FFI video source handle for capture sources.
106+
/// @brief Adopt an existing FFI video source handle.
110107
/// @param handle Rust-owned video source handle.
111108
/// @param width Frame width in pixels.
112109
/// @param height Frame height in pixels.

‎src/capture_source.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ std::shared_ptr<CaptureSource> CaptureSource::fromOwned(const proto::OwnedCaptur
172172
if (info.has_codec()) {
173173
source->impl_->codec = static_cast<VideoCodec>(info.codec());
174174
}
175-
source->impl_->video_source = std::shared_ptr<VideoSource>(
176-
new VideoSource(std::move(video_handle_owner), source->impl_->width, source->impl_->height));
175+
source->impl_->video_source =
176+
VideoSourceAccess::adopt(std::move(video_handle_owner), source->impl_->width, source->impl_->height);
177177

178178
return source;
179179
}

‎src/capture_source_internal.h‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,24 @@
1616

1717
#pragma once
1818

19+
#include <memory>
20+
#include <utility>
21+
1922
#include "livekit/capture/capture_source.h"
2023
#include "livekit/visibility.h"
2124

25+
namespace livekit {
26+
27+
/// Internal adapter for adopting capture-owned video source handles without
28+
/// exposing capture types in the public VideoSource header.
29+
struct VideoSourceAccess {
30+
static std::shared_ptr<VideoSource> adopt(FfiHandle&& handle, int width, int height) {
31+
return std::shared_ptr<VideoSource>(new VideoSource(std::move(handle), width, height));
32+
}
33+
};
34+
35+
} // namespace livekit
36+
2237
namespace livekit::proto {
2338
class NewCaptureSourceRequest;
2439
} // namespace livekit::proto

0 commit comments

Comments
 (0)