|
24 | 24 | /// LIVEKIT_URL, LIVEKIT_SENDER_TOKEN |
25 | 25 |
|
26 | 26 | #include <atomic> |
27 | | -#include <cassert> |
28 | 27 | #include <chrono> |
29 | 28 | #include <csignal> |
30 | 29 | #include <cstdlib> |
31 | 30 | #include <iomanip> |
32 | 31 | #include <iostream> |
33 | 32 | #include <sstream> |
| 33 | +#include <stdexcept> |
34 | 34 | #include <thread> |
35 | 35 |
|
36 | 36 | #include "livekit/livekit.h" |
@@ -84,27 +84,33 @@ int main(int argc, char* argv[]) { |
84 | 84 | return 1; |
85 | 85 | } |
86 | 86 |
|
87 | | - LocalParticipant* lp = room->localParticipant(); |
88 | | - assert(lp); |
| 87 | + std::shared_ptr<LocalDataTrack> data_track; |
| 88 | + std::shared_ptr<LocalVideoTrack> video_track; |
| 89 | + std::shared_ptr<VideoSource> video_source; |
| 90 | + { |
| 91 | + auto lp = room->localParticipant().lock(); |
| 92 | + if (!lp) { |
| 93 | + throw std::runtime_error("[sender] local participant is null"); |
| 94 | + } |
89 | 95 |
|
90 | | - std::cout << "[info] [sender] Connected as identity='" << lp->identity() << "' room='" << room->roomInfo().name |
91 | | - << "' — pass this identity to HelloLivekitReceiver\n"; |
| 96 | + std::cout << "[info] [sender] Connected as identity='" << lp->identity() << "' room='" << room->roomInfo().name |
| 97 | + << "' — pass this identity to HelloLivekitReceiver\n"; |
92 | 98 |
|
93 | | - auto video_source = std::make_shared<VideoSource>(kWidth, kHeight); |
| 99 | + video_source = std::make_shared<VideoSource>(kWidth, kHeight); |
94 | 100 |
|
95 | | - std::shared_ptr<LocalVideoTrack> video_track = |
96 | | - lp->publishVideoTrack(kVideoTrackName, video_source, TrackSource::SOURCE_CAMERA); |
| 101 | + video_track = lp->publishVideoTrack(kVideoTrackName, video_source, TrackSource::SOURCE_CAMERA); |
97 | 102 |
|
98 | | - auto publish_result = lp->publishDataTrack(kDataTrackName); |
99 | | - if (!publish_result) { |
100 | | - const auto& error = publish_result.error(); |
101 | | - std::cerr << "[error] Failed to publish data track: code=" << static_cast<std::uint32_t>(error.code) |
102 | | - << " message=" << error.message << "\n"; |
103 | | - room.reset(); |
104 | | - livekit::shutdown(); |
105 | | - return 1; |
| 103 | + auto publish_result = lp->publishDataTrack(kDataTrackName); |
| 104 | + if (!publish_result) { |
| 105 | + const auto& error = publish_result.error(); |
| 106 | + std::cerr << "[error] Failed to publish data track: code=" << static_cast<std::uint32_t>(error.code) |
| 107 | + << " message=" << error.message << "\n"; |
| 108 | + room.reset(); |
| 109 | + livekit::shutdown(); |
| 110 | + return 1; |
| 111 | + } |
| 112 | + data_track = publish_result.value(); |
106 | 113 | } |
107 | | - std::shared_ptr<LocalDataTrack> data_track = publish_result.value(); |
108 | 114 |
|
109 | 115 | const auto t0 = std::chrono::steady_clock::now(); |
110 | 116 | std::uint64_t count = 0; |
|
0 commit comments