@@ -29,36 +29,33 @@ namespace {
2929
3030proto::GstreamerBitrateUnit toProto (GstreamerBitrateUnit unit) {
3131 switch (unit) {
32- case GstreamerBitrateUnit::Bps:
33- return proto::GstreamerBitrateUnit::GSTREAMER_BITRATE_UNIT_BPS ;
34- case GstreamerBitrateUnit::Kbps:
35- return proto::GstreamerBitrateUnit::GSTREAMER_BITRATE_UNIT_KBPS ;
32+ case GstreamerBitrateUnit::Bps:
33+ return proto::GstreamerBitrateUnit::GSTREAMER_BITRATE_UNIT_BPS ;
34+ case GstreamerBitrateUnit::Kbps:
35+ return proto::GstreamerBitrateUnit::GSTREAMER_BITRATE_UNIT_KBPS ;
3636 }
3737 return proto::GstreamerBitrateUnit::GSTREAMER_BITRATE_UNIT_BPS ;
3838}
3939
40- CaptureResult resultFromEvent (const proto::CaptureSourceEvent & event) {
40+ CaptureResult resultFromEvent (const proto::CaptureSourceEvent& event) {
4141 CaptureResult result;
4242 if (event.has_error ()) {
4343 result.error = event.error ().error ();
4444 return result;
4545 }
4646 if (event.has_finished ()) {
4747 result.frames_captured = event.finished ().frames_captured ();
48- result.exit = event.finished ().exit () ==
49- proto::CaptureExit::CAPTURE_EXIT_END_OF_STREAM
50- ? CaptureExit::EndOfStream
51- : CaptureExit::Stopped;
48+ result.exit = event.finished ().exit () == proto::CaptureExit::CAPTURE_EXIT_END_OF_STREAM ? CaptureExit::EndOfStream
49+ : CaptureExit::Stopped;
5250 }
5351 return result;
5452}
5553
5654} // namespace
5755
58- std::future<std::shared_ptr<CaptureSource>>
59- CaptureSource::create (GstreamerVideoSourceConfig config) {
56+ std::future<std::shared_ptr<CaptureSource>> CaptureSource::create (GstreamerVideoSourceConfig config) {
6057 proto::NewCaptureSourceRequest request;
61- auto * gstreamer = request.mutable_gstreamer ();
58+ auto * gstreamer = request.mutable_gstreamer ();
6259 gstreamer->set_pipeline (config.pipeline );
6360 if (config.codec ) {
6461 gstreamer->set_codec (static_cast <proto::VideoCodec>(*config.codec ));
@@ -68,23 +65,21 @@ CaptureSource::create(GstreamerVideoSourceConfig config) {
6865 gstreamer->mutable_resolution ()->set_height (config.resolution ->height );
6966 }
7067 if (config.rate_control ) {
71- auto * rate_control = gstreamer->mutable_rate_control ();
68+ auto * rate_control = gstreamer->mutable_rate_control ();
7269 rate_control->set_element (config.rate_control ->element );
7370 rate_control->set_property (config.rate_control ->property );
7471 rate_control->set_unit (toProto (config.rate_control ->unit ));
7572 }
7673 return createFromRequest (std::move (request));
7774}
7875
79- std::future<std::shared_ptr<CaptureSource>>
80- CaptureSource::create (DemoVideoSourceConfig /* config*/ ) {
76+ std::future<std::shared_ptr<CaptureSource>> CaptureSource::create (DemoVideoSourceConfig /* config*/ ) {
8177 proto::NewCaptureSourceRequest request;
8278 request.mutable_demo ();
8379 return createFromRequest (std::move (request));
8480}
8581
86- std::future<std::shared_ptr<CaptureSource>>
87- CaptureSource::createFromRequest (proto::NewCaptureSourceRequest request) {
82+ std::future<std::shared_ptr<CaptureSource>> CaptureSource::createFromRequest (proto::NewCaptureSourceRequest request) {
8883 auto owned = FfiClient::instance ().newCaptureSourceAsync (std::move (request));
8984 // Map the FFI payload onto a wrapper once the callback resolves. A helper
9085 // thread keeps the returned future's wait semantics standard.
@@ -99,56 +94,49 @@ CaptureSource::createFromRequest(proto::NewCaptureSourceRequest request) {
9994 });
10095}
10196
102- std::shared_ptr<CaptureSource>
103- CaptureSource::fromOwned (const proto::OwnedCaptureSource &owned) {
104- const proto::CaptureSourceInfo &info = owned.info ();
97+ std::shared_ptr<CaptureSource> CaptureSource::fromOwned (const proto::OwnedCaptureSource& owned) {
98+ const proto::CaptureSourceInfo& info = owned.info ();
10599
106100 std::shared_ptr<CaptureSource> source (new CaptureSource ());
107101 source->handle_ = FfiHandle (static_cast <uintptr_t >(owned.handle ().id ()));
108- source->kind_ =
109- info.kind () == proto::CaptureSourceKind::CAPTURE_SOURCE_ENCODED
110- ? CaptureSourceKind::Encoded
111- : CaptureSourceKind::Pixel;
102+ source->kind_ = info.kind () == proto::CaptureSourceKind::CAPTURE_SOURCE_ENCODED ? CaptureSourceKind::Encoded
103+ : CaptureSourceKind::Pixel;
112104 source->width_ = static_cast <int >(info.resolution ().width ());
113105 source->height_ = static_cast <int >(info.resolution ().height ());
114106 if (info.has_codec ()) {
115107 source->codec_ = static_cast <VideoCodec>(info.codec ());
116108 }
117109 source->source_publish_options_ = fromProto (info.recommended_publish_options ());
118110 source->video_source_ = std::shared_ptr<VideoSource>(new VideoSource (
119- FfiHandle (static_cast <uintptr_t >(info.video_source ().handle ().id ())),
120- source->width_ , source->height_ ));
111+ FfiHandle (static_cast <uintptr_t >(info.video_source ().handle ().id ())), source->width_ , source->height_ ));
121112
122113 // The terminal CaptureSourceEvent is unsolicited (not async-id
123114 // correlated); observe it with a listener filtered by our handle. The
124115 // destructor removes the listener before releasing the handle, so no
125116 // callback can outlive the wrapper.
126- CaptureSource * raw = source.get ();
117+ CaptureSource* raw = source.get ();
127118 const std::uint64_t capture_handle = source->handle_ .get ();
128- source->listener_id_ = FfiClient::instance ().addListener (
129- [raw, capture_handle](const proto::FfiEvent &event) {
130- if (!event.has_capture_source_event () ||
131- event.capture_source_event ().capture_handle () != capture_handle) {
132- return ;
133- }
134- const CaptureResult result =
135- resultFromEvent (event.capture_source_event ());
136- FinishedCallback callback;
137- {
138- const std::scoped_lock lock (raw->callback_mutex_ );
139- callback = raw->on_finished_ ;
140- }
141- if (callback) {
142- callback (result);
143- }
144- });
119+ source->listener_id_ = FfiClient::instance ().addListener ([raw, capture_handle](const proto::FfiEvent& event) {
120+ if (!event.has_capture_source_event () || event.capture_source_event ().capture_handle () != capture_handle) {
121+ return ;
122+ }
123+ const CaptureResult result = resultFromEvent (event.capture_source_event ());
124+ FinishedCallback callback;
125+ {
126+ const std::scoped_lock lock (raw->callback_mutex_ );
127+ callback = raw->on_finished_ ;
128+ }
129+ if (callback) {
130+ callback (result);
131+ }
132+ });
145133
146134 return source;
147135}
148136
149137TrackPublishOptions CaptureSource::publishOptions (TrackPublishOptions options) const {
150- const TrackPublishOptions & dictated = source_publish_options_;
151- const auto overlay = [](auto & target, const auto & source) {
138+ const TrackPublishOptions& dictated = source_publish_options_;
139+ const auto overlay = [](auto & target, const auto & source) {
152140 if (source.has_value ()) {
153141 target = source;
154142 }
0 commit comments