Skip to content

Commit bffaafd

Browse files
start/stop return bool
1 parent 0c4a556 commit bffaafd

3 files changed

Lines changed: 42 additions & 26 deletions

File tree

‎include/livekit/capture_source.h‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -447,16 +447,15 @@ class LIVEKIT_API CaptureSource {
447447

448448
/// Start pumping frames into the RTC video source.
449449
///
450-
/// @throws CaptureSourceError if the capture was already started or the
451-
/// FFI call fails.
452-
void start();
450+
/// @return @c true if the start request succeeds; otherwise @c false.
451+
bool start();
453452

454453
/// Signal a running capture to stop after the frame in flight. The
455454
/// finished callback fires shortly after. Stopping an already-finished
456455
/// capture is a no-op.
457456
///
458-
/// @throws CaptureSourceError if the FFI call fails.
459-
void stop();
457+
/// @return @c true if the stop request succeeds; otherwise @c false.
458+
bool stop();
460459

461460
private:
462461
CaptureSource() = default;

‎src/capture_source.cpp‎

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "capture_source_internal.h"
2323
#include "ffi.pb.h"
2424
#include "ffi_client.h"
25+
#include "lk_log.h"
2526
#include "room_proto_converter.h"
2627

2728
namespace livekit {
@@ -433,29 +434,45 @@ void CaptureSource::setOnFinishedCallback(FinishedCallback callback) {
433434
on_finished_ = std::move(callback);
434435
}
435436

436-
void CaptureSource::start() {
437-
proto::FfiRequest req;
438-
req.mutable_start_capture()->set_capture_handle(handle_.get());
437+
bool CaptureSource::start() {
438+
try {
439+
proto::FfiRequest req;
440+
req.mutable_start_capture()->set_capture_handle(handle_.get());
439441

440-
const proto::FfiResponse resp = FfiClient::instance().sendRequest(req);
441-
if (!resp.has_start_capture()) {
442-
throw CaptureSourceError("FfiResponse missing start_capture");
443-
}
444-
if (resp.start_capture().has_error()) {
445-
throw CaptureSourceError(resp.start_capture().error());
442+
const proto::FfiResponse resp = FfiClient::instance().sendRequest(req);
443+
if (!resp.has_start_capture()) {
444+
LK_LOG_WARN("Capture start request returned no start_capture response");
445+
return false;
446+
}
447+
if (resp.start_capture().has_error()) {
448+
LK_LOG_WARN("Capture start request failed: {}", resp.start_capture().error());
449+
return false;
450+
}
451+
return true;
452+
} catch (const std::exception& e) {
453+
LK_LOG_WARN("Capture start request failed: {}", e.what());
454+
return false;
446455
}
447456
}
448457

449-
void CaptureSource::stop() {
450-
proto::FfiRequest req;
451-
req.mutable_stop_capture()->set_capture_handle(handle_.get());
458+
bool CaptureSource::stop() {
459+
try {
460+
proto::FfiRequest req;
461+
req.mutable_stop_capture()->set_capture_handle(handle_.get());
452462

453-
const proto::FfiResponse resp = FfiClient::instance().sendRequest(req);
454-
if (!resp.has_stop_capture()) {
455-
throw CaptureSourceError("FfiResponse missing stop_capture");
456-
}
457-
if (resp.stop_capture().has_error()) {
458-
throw CaptureSourceError(resp.stop_capture().error());
463+
const proto::FfiResponse resp = FfiClient::instance().sendRequest(req);
464+
if (!resp.has_stop_capture()) {
465+
LK_LOG_WARN("Capture stop request returned no stop_capture response");
466+
return false;
467+
}
468+
if (resp.stop_capture().has_error()) {
469+
LK_LOG_WARN("Capture stop request failed: {}", resp.stop_capture().error());
470+
return false;
471+
}
472+
return true;
473+
} catch (const std::exception& e) {
474+
LK_LOG_WARN("Capture stop request failed: {}", e.what());
475+
return false;
459476
}
460477
}
461478

‎src/tests/integration/test_capture_source.cpp‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,8 @@ TEST_F(CaptureSourceServerTest, PatternCaptureSourcePublishesFramesEndToEnd) {
225225
cv.notify_all();
226226
});
227227
228-
ASSERT_NO_THROW(capture->start());
229-
EXPECT_THROW(capture->start(), CaptureSourceError) << "double start must be rejected";
228+
ASSERT_TRUE(capture->start());
229+
EXPECT_FALSE(capture->start()) << "double start must be rejected";
230230
231231
{
232232
std::unique_lock<std::mutex> lock(mutex);
@@ -236,7 +236,7 @@ TEST_F(CaptureSourceServerTest, PatternCaptureSourcePublishesFramesEndToEnd) {
236236
}
237237
238238
// Stop is a signal; the terminal callback delivers the stats.
239-
ASSERT_NO_THROW(capture->stop());
239+
ASSERT_TRUE(capture->stop());
240240
{
241241
std::unique_lock<std::mutex> lock(mutex);
242242
const bool got_finished = cv.wait_for(lock, 10s, [&finished] { return finished.has_value(); });

0 commit comments

Comments
 (0)