@@ -34,66 +34,58 @@ std::atomic<bool> g_running{true};
3434
3535void handleSignal (int ) { g_running.store (false ); }
3636
37- void printUsage (const char * prog) {
37+ void printUsage (const char * prog) {
3838 std::cerr << " Usage:\n "
3939 << " " << prog << " --url <ws-url> --token <token>\n "
4040 << " Env fallbacks:\n "
4141 << " LIVEKIT_URL, LIVEKIT_TOKEN\n " ;
4242}
4343
44- bool parseArgs (int argc, char *argv[], std::string &url, std::string &token,
45- bool &self_test) {
44+ bool parseArgs (int argc, char * argv[], std::string& url, std::string& token, bool & self_test) {
4645 for (int i = 1 ; i < argc; ++i) {
4746 const std::string a = argv[i];
48- if (a == " -h" || a == " --help" )
49- return false ;
47+ if (a == " -h" || a == " --help" ) return false ;
5048
5149 if (a == " --self-test" ) {
5250 self_test = true ;
5351 return true ;
5452 }
5553
56- auto take = [&](std::string &out) -> bool {
57- if (i + 1 >= argc)
58- return false ;
54+ auto take = [&](std::string& out) -> bool {
55+ if (i + 1 >= argc) return false ;
5956 out = argv[++i];
6057 return true ;
6158 };
6259
6360 if (a == " --url" ) {
64- if (!take (url))
65- return false ;
61+ if (!take (url)) return false ;
6662 } else if (a.rfind (" --url=" , 0 ) == 0 ) {
6763 url = a.substr (std::string (" --url=" ).size ());
6864 } else if (a == " --token" ) {
69- if (!take (token))
70- return false ;
65+ if (!take (token)) return false ;
7166 } else if (a.rfind (" --token=" , 0 ) == 0 ) {
7267 token = a.substr (std::string (" --token=" ).size ());
7368 }
7469 }
7570
7671 if (url.empty ()) {
77- if (const char *e = std::getenv (" LIVEKIT_URL" ))
78- url = e;
72+ if (const char * e = std::getenv (" LIVEKIT_URL" )) url = e;
7973 }
8074 if (token.empty ()) {
81- if (const char *e = std::getenv (" LIVEKIT_TOKEN" ))
82- token = e;
75+ if (const char * e = std::getenv (" LIVEKIT_TOKEN" )) token = e;
8376 }
8477
8578 return !(url.empty () || token.empty ());
8679}
8780
8881void print_livekit_version () {
89- std::cout << " LiveKit version: " << LIVEKIT_BUILD_VERSION_FULL << " ("
90- << LIVEKIT_BUILD_FLAVOR << " , commit " << LIVEKIT_BUILD_COMMIT
91- << " , built " << LIVEKIT_BUILD_DATE << " )" << std::endl;
82+ std::cout << " LiveKit version: " << LIVEKIT_BUILD_VERSION_FULL << " (" << LIVEKIT_BUILD_FLAVOR << " , commit "
83+ << LIVEKIT_BUILD_COMMIT << " , built " << LIVEKIT_BUILD_DATE << " )" << std::endl;
9284}
9385
9486} // namespace
9587
96- int main (int argc, char * argv[]) {
88+ int main (int argc, char * argv[]) {
9789 print_livekit_version ();
9890 std::string url, token;
9991 bool self_test = false ;
@@ -131,8 +123,7 @@ int main(int argc, char *argv[]) {
131123 // ---- Create & publish AUDIO (noise) ----
132124 // Match your runNoiseCaptureLoop pacing: it assumes frame_ms=10.
133125 auto audioSource = std::make_shared<AudioSource>(48000 , 1 , 10 );
134- auto audioTrack =
135- LocalAudioTrack::createLocalAudioTrack (" noise" , audioSource);
126+ auto audioTrack = LocalAudioTrack::createLocalAudioTrack (" noise" , audioSource);
136127
137128 TrackPublishOptions audioOpts;
138129 audioOpts.source = TrackSource::SOURCE_MICROPHONE ;
@@ -144,7 +135,7 @@ int main(int argc, char *argv[]) {
144135 room->localParticipant ()->publishTrack (audioTrack, audioOpts);
145136 audioPub = audioTrack->publication ();
146137 std::cout << " Published audio: sid=" << audioPub->sid () << " \n " ;
147- } catch (const std::exception & e) {
138+ } catch (const std::exception& e) {
148139 std::cerr << " Failed to publish audio: " << e.what () << " \n " ;
149140 }
150141
@@ -163,18 +154,16 @@ int main(int argc, char *argv[]) {
163154 room->localParticipant ()->publishTrack (videoTrack, videoOpts);
164155 videoPub = videoTrack->publication ();
165156 std::cout << " Published video: sid=" << videoPub->sid () << " \n " ;
166- } catch (const std::exception & e) {
157+ } catch (const std::exception& e) {
167158 std::cerr << " Failed to publish video: " << e.what () << " \n " ;
168159 }
169160
170161 // ---- Start synthetic capture loops ----
171162 std::atomic<bool > audio_running{true };
172163 std::atomic<bool > video_running{true };
173164
174- std::thread audioThread (
175- [&] { runNoiseCaptureLoop (audioSource, audio_running); });
176- std::thread videoThread (
177- [&] { runFakeVideoCaptureLoop (videoSource, video_running); });
165+ std::thread audioThread ([&] { runNoiseCaptureLoop (audioSource, audio_running); });
166+ std::thread videoThread ([&] { runFakeVideoCaptureLoop (videoSource, video_running); });
178167
179168 // Keep alive until Ctrl-C
180169 while (g_running.load ()) {
@@ -185,17 +174,13 @@ int main(int argc, char *argv[]) {
185174 audio_running.store (false );
186175 video_running.store (false );
187176
188- if (audioThread.joinable ())
189- audioThread.join ();
190- if (videoThread.joinable ())
191- videoThread.join ();
177+ if (audioThread.joinable ()) audioThread.join ();
178+ if (videoThread.joinable ()) videoThread.join ();
192179
193180 // Best-effort unpublish
194181 try {
195- if (audioPub)
196- room->localParticipant ()->unpublishTrack (audioPub->sid ());
197- if (videoPub)
198- room->localParticipant ()->unpublishTrack (videoPub->sid ());
182+ if (audioPub) room->localParticipant ()->unpublishTrack (audioPub->sid ());
183+ if (videoPub) room->localParticipant ()->unpublishTrack (videoPub->sid ());
199184 } catch (...) {
200185 }
201186
0 commit comments