Skip to content

Commit bbbcd01

Browse files
committed
Add capture source requests to FfiClient
1 parent 2498719 commit bbbcd01

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
@@ -107,6 +107,8 @@ std::optional<FfiClient::AsyncId> ExtractAsyncId(const proto::FfiEvent& event) {
107107
return event.chat_message().async_id();
108108
case E::kPerformRpc:
109109
return event.perform_rpc().async_id();
110+
case E::kNewCaptureSource:
111+
return event.new_capture_source().async_id();
110112

111113
// low-level data stream callbacks
112114
case E::kSendStreamHeader:
@@ -708,6 +710,49 @@ std::future<proto::OwnedTrackPublication> FfiClient::publishTrackAsync(std::uint
708710
return fut;
709711
}
710712

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