Skip to content

Commit 7fcd2ec

Browse files
address mr comments
1 parent 07be62e commit 7fcd2ec

3 files changed

Lines changed: 28 additions & 12 deletions

File tree

user_timestamped_video/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ LIVEKIT_URL=ws://localhost:7880 LIVEKIT_TOKEN=<producer-token> ./UserTimestamped
1717
LIVEKIT_URL=ws://localhost:7880 LIVEKIT_TOKEN=<consumer-token> ./UserTimestampedVideoConsumer
1818
```
1919

20+
Requirements:
21+
22+
- LiveKit C++ SDK `v0.3.4` or newer. This example uses
23+
`VideoFrameMetadata` and `setOnVideoFrameEventCallback`, which are not
24+
available in older SDK releases.
25+
- To pin the SDK version when configuring the examples, pass
26+
`-DLIVEKIT_SDK_VERSION=0.3.4` to CMake.
27+
2028
Flags:
2129

2230
- Producer default: sends user timestamps

user_timestamped_video/consumer/main.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ constexpr const char *kTrackName = "timestamped-camera";
4949

5050
std::atomic<bool> g_running{true};
5151

52+
enum class ParseResult { Ok, Help, Error };
53+
5254
void handleSignal(int) { g_running.store(false); }
5355

5456
std::string getenvOrEmpty(const char *name) {
@@ -74,15 +76,15 @@ void printUsage(const char *program) {
7476
<< " [--with-user-timestamp|--without-user-timestamp]\n";
7577
}
7678

77-
bool parseArgs(int argc, char *argv[], std::string &url, std::string &token,
78-
bool &read_user_timestamp) {
79+
ParseResult parseArgs(int argc, char *argv[], std::string &url,
80+
std::string &token, bool &read_user_timestamp) {
7981
read_user_timestamp = true;
8082
std::vector<std::string> positional;
8183

8284
for (int i = 1; i < argc; ++i) {
8385
const std::string arg = argv[i];
8486
if (arg == "-h" || arg == "--help") {
85-
return false;
87+
return ParseResult::Help;
8688
}
8789
if (arg == "--without-user-timestamp") {
8890
read_user_timestamp = false;
@@ -104,7 +106,7 @@ bool parseArgs(int argc, char *argv[], std::string &url, std::string &token,
104106
token = positional[1];
105107
}
106108

107-
return !(url.empty() || token.empty());
109+
return (url.empty() || token.empty()) ? ParseResult::Error : ParseResult::Ok;
108110
}
109111

110112
class UserTimestampedVideoConsumerDelegate : public RoomDelegate {
@@ -203,9 +205,11 @@ int main(int argc, char *argv[]) {
203205
std::string token;
204206
bool read_user_timestamp = true;
205207

206-
if (!parseArgs(argc, argv, url, token, read_user_timestamp)) {
208+
const ParseResult parse_result =
209+
parseArgs(argc, argv, url, token, read_user_timestamp);
210+
if (parse_result != ParseResult::Ok) {
207211
printUsage(argv[0]);
208-
return 1;
212+
return parse_result == ParseResult::Help ? 0 : 1;
209213
}
210214

211215
std::signal(SIGINT, handleSignal);

user_timestamped_video/producer/main.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ constexpr int kFrameIntervalMs = 200;
5151

5252
std::atomic<bool> g_running{true};
5353

54+
enum class ParseResult { Ok, Help, Error };
55+
5456
void handleSignal(int) { g_running.store(false); }
5557

5658
std::string getenvOrEmpty(const char *name) {
@@ -89,15 +91,15 @@ void printUsage(const char *program) {
8991
<< " [--with-user-timestamp|--without-user-timestamp]\n";
9092
}
9193

92-
bool parseArgs(int argc, char *argv[], std::string &url, std::string &token,
93-
bool &send_user_timestamp) {
94+
ParseResult parseArgs(int argc, char *argv[], std::string &url,
95+
std::string &token, bool &send_user_timestamp) {
9496
send_user_timestamp = true;
9597
std::vector<std::string> positional;
9698

9799
for (int i = 1; i < argc; ++i) {
98100
const std::string arg = argv[i];
99101
if (arg == "-h" || arg == "--help") {
100-
return false;
102+
return ParseResult::Help;
101103
}
102104
if (arg == "--without-user-timestamp") {
103105
send_user_timestamp = false;
@@ -119,7 +121,7 @@ bool parseArgs(int argc, char *argv[], std::string &url, std::string &token,
119121
token = positional[1];
120122
}
121123

122-
return !(url.empty() || token.empty());
124+
return (url.empty() || token.empty()) ? ParseResult::Error : ParseResult::Ok;
123125
}
124126

125127
} // namespace
@@ -129,9 +131,11 @@ int main(int argc, char *argv[]) {
129131
std::string token;
130132
bool send_user_timestamp = true;
131133

132-
if (!parseArgs(argc, argv, url, token, send_user_timestamp)) {
134+
const ParseResult parse_result =
135+
parseArgs(argc, argv, url, token, send_user_timestamp);
136+
if (parse_result != ParseResult::Ok) {
133137
printUsage(argv[0]);
134-
return 1;
138+
return parse_result == ParseResult::Help ? 0 : 1;
135139
}
136140

137141
std::signal(SIGINT, handleSignal);

0 commit comments

Comments
 (0)