Skip to content

Commit 8261959

Browse files
ladvocstephen-derosa
authored andcommitted
Add capture source requests to FfiClient
1 parent 85a938a commit 8261959

2 files changed

Lines changed: 49 additions & 0 deletions

File tree

‎src/ffi_client.cpp‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ std::optional<FfiClient::AsyncId> ExtractAsyncId(const proto::FfiEvent& event) {
109109
return event.chat_message().async_id();
110110
case E::kPerformRpc:
111111
return event.perform_rpc().async_id();
112+
case E::kNewCaptureSource:
113+
return event.new_capture_source().async_id();
112114

113115
// low-level data stream callbacks
114116
case E::kSendStreamHeader:
@@ -710,6 +712,49 @@ std::future<proto::OwnedTrackPublication> FfiClient::publishTrackAsync(std::uint
710712
return fut;
711713
}
712714

715+
std::future<proto::OwnedCaptureSource> FfiClient::newCaptureSourceAsync(proto::NewCaptureSourceRequest request) {
716+
// Generate client-side async_id first
717+
const AsyncId async_id = generateAsyncId();
718+
719+
// Register the async handler BEFORE sending the request
720+
auto fut = registerAsync<proto::OwnedCaptureSource>(
721+
async_id,
722+
[async_id](const proto::FfiEvent& event) {
723+
return event.has_new_capture_source() && event.new_capture_source().async_id() == async_id;
724+
},
725+
[](const proto::FfiEvent& event, std::promise<proto::OwnedCaptureSource>& pr) {
726+
const auto& cb = event.new_capture_source();
727+
728+
// Oneof message { string error = 2; OwnedCaptureSource source = 3; }
729+
if (cb.has_error() && !cb.error().empty()) {
730+
pr.set_exception(std::make_exception_ptr(std::runtime_error(cb.error())));
731+
return;
732+
}
733+
if (!cb.has_source()) {
734+
pr.set_exception(std::make_exception_ptr(std::runtime_error("NewCaptureSourceCallback missing source")));
735+
return;
736+
}
737+
738+
pr.set_value(cb.source());
739+
});
740+
741+
request.set_request_async_id(async_id);
742+
proto::FfiRequest req;
743+
req.mutable_new_capture_source()->CopyFrom(request);
744+
745+
try {
746+
const proto::FfiResponse resp = sendRequest(req);
747+
if (!resp.has_new_capture_source()) {
748+
logAndThrow("FfiResponse missing new_capture_source");
749+
}
750+
} catch (...) {
751+
cancelPendingByAsyncId(async_id);
752+
throw;
753+
}
754+
755+
return fut;
756+
}
757+
713758
std::future<void> FfiClient::unpublishTrackAsync(std::uint64_t local_participant_handle, const std::string& track_sid,
714759
bool stop_on_unpublish) {
715760
// Generate client-side async_id first

‎src/ffi_client.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <unordered_map>
3030
#include <utility>
3131

32+
#include "capture.pb.h"
3233
#include "data_track.pb.h"
3334
#include "livekit/data_track_error.h"
3435
#include "livekit/data_track_options.h"
@@ -118,6 +119,9 @@ class LIVEKIT_INTERNAL_API FfiClient {
118119
std::future<void> publishSipDtmfAsync(std::uint64_t local_participant_handle, std::uint32_t code,
119120
const std::string& digit,
120121
const std::vector<std::string>& destination_identities);
122+
123+
// Capture APIs
124+
std::future<proto::OwnedCaptureSource> newCaptureSourceAsync(proto::NewCaptureSourceRequest request);
121125
std::future<void> setLocalMetadataAsync(std::uint64_t local_participant_handle, const std::string& metadata);
122126
std::future<void> captureAudioFrameAsync(std::uint64_t source_handle, const proto::AudioFrameBufferInfo& buffer);
123127
std::future<std::string> performRpcAsync(std::uint64_t local_participant_handle,

0 commit comments

Comments
 (0)