aboutsummaryrefslogtreecommitdiff
path: root/cast
diff options
context:
space:
mode:
authorYuri Wiitala <miu@chromium.org>2020-10-26 12:30:13 -0700
committerCommit Bot <commit-bot@chromium.org>2020-10-26 20:44:44 +0000
commit2837c9f0c416803cbab994f1fe10296d2a132971 (patch)
treedae3d9a0167f1bc6a56ee65be4f329ce086b73ed /cast
parent83e50af3e0bd628e7307e67e0ae1c6a611b8d7bb (diff)
downloadopenscreen-2837c9f0c416803cbab994f1fe10296d2a132971.tar.gz
Add StringPrintf() wrapper utility.
Adds an efficient wrapper around std::snprintf() that returns the formatted result in a std::string. Background: The issue of either 1) wanting to use absl::StrFormat() without bloating our binary sizes, or 2) manually writing char[] buffer code around std::snprintf() has come up several times over the past year or so. So, this new utility is about reducing friction and improving future developer velocity. Change-Id: Ie898f91575852b06d59844dd564a0da03df1f7ed Reviewed-on: https://chromium-review.googlesource.com/c/openscreen/+/2487768 Commit-Queue: Yuri Wiitala <miu@chromium.org> Reviewed-by: Yuri Wiitala <miu@chromium.org> Reviewed-by: Brandon Tolsch <btolsch@chromium.org>
Diffstat (limited to 'cast')
-rw-r--r--cast/standalone_receiver/main.cc11
-rw-r--r--cast/standalone_sender/main.cc22
-rw-r--r--cast/streaming/sender_session_unittest.cc28
3 files changed, 30 insertions, 31 deletions
diff --git a/cast/standalone_receiver/main.cc b/cast/standalone_receiver/main.cc
index 0c9d3c1b..4e8c321c 100644
--- a/cast/standalone_receiver/main.cc
+++ b/cast/standalone_receiver/main.cc
@@ -116,16 +116,15 @@ std::unique_ptr<CastAgent> StartCastAgent(TaskRunnerImpl* task_runner,
}
void LogUsage(const char* argv0) {
- std::cerr << R"(
-usage: )" << argv0
- << R"( <options> <interface>
+ constexpr char kTemplate[] = R"(
+usage: %s <options> <interface>
-options:
interface
Specifies the network interface to bind to. The interface is
looked up from the system interface registry.
Mandatory, as it must be known for publishing discovery.
+options:
-p, --private-key=path-to-key: Path to OpenSSL-generated private key to be
used for TLS authentication. If a private key is not
provided, a randomly generated one will be used for this
@@ -153,7 +152,9 @@ options:
-v, --verbose: Enable verbose logging.
-h, --help: Show this help message.
- )";
+)";
+
+ std::cerr << StringPrintf(kTemplate, argv0);
}
InterfaceInfo GetInterfaceInfoFromName(const char* name) {
diff --git a/cast/standalone_sender/main.cc b/cast/standalone_sender/main.cc
index 8b0d9d08..470a6b52 100644
--- a/cast/standalone_sender/main.cc
+++ b/cast/standalone_sender/main.cc
@@ -42,24 +42,20 @@ IPEndpoint GetDefaultEndpoint() {
}
void LogUsage(const char* argv0) {
- std::cerr << R"(
- usage:)" << argv0
- << R"( <options> <media_file>
+ constexpr char kTemplate[] = R"(
+usage: %s <options> <media_file>
-r, --remote=addr[:port]
Specify the destination (e.g., 192.168.1.22:9999 or [::1]:12345).
- Default if not set: )"
- << GetDefaultEndpoint() << R"(
+ Default if not set: %s
-m, --max-bitrate=N
Specifies the maximum bits per second for the media streams.
- Default if not set: )"
- << kDefaultMaxBitrate << "\n"
-
+ Default if not set: %d)"
#if defined(CAST_ALLOW_DEVELOPER_CERTIFICATE)
- << R"(
+ R"(
-d, --developer-certificate=path-to-cert
Specifies the path to a self-signed developer certificate that will
be permitted for use as a root CA certificate for receivers that
@@ -68,7 +64,7 @@ void LogUsage(const char* argv0) {
Google-signed cast certificate chain will be permitted.
)"
#endif
- << R"(
+ R"(
-a, --android-hack:
Use the wrong RTP payload types, for compatibility with older Android
TV receivers.
@@ -78,7 +74,11 @@ void LogUsage(const char* argv0) {
-v, --verbose: Enable verbose logging.
-h, --help: Show this help message.
- )";
+)";
+
+ std::cerr << StringPrintf(kTemplate, argv0,
+ GetDefaultEndpoint().ToString().c_str(),
+ kDefaultMaxBitrate);
}
int StandaloneSenderMain(int argc, char* argv[]) {
diff --git a/cast/streaming/sender_session_unittest.cc b/cast/streaming/sender_session_unittest.cc
index d56a9f30..f5e1117b 100644
--- a/cast/streaming/sender_session_unittest.cc
+++ b/cast/streaming/sender_session_unittest.cc
@@ -17,6 +17,7 @@
#include "platform/test/fake_clock.h"
#include "platform/test/fake_task_runner.h"
#include "util/chrono_helpers.h"
+#include "util/stringprintf.h"
using ::testing::_;
using ::testing::InSequence;
@@ -180,21 +181,18 @@ class SenderSessionTest : public ::testing::Test {
const int video_index = video_stream["index"].asInt();
const int video_ssrc = video_stream["ssrc"].asUInt();
- constexpr size_t kAnswerSize = 512u;
- char answer[kAnswerSize];
- snprintf(answer, kAnswerSize, R"({ "type": "ANSWER",
- "seqNum": %d,
- "answer": {
- "castMode": "mirroring",
- "udpPort": 1234,
- "sendIndexes": [%d, %d],
- "ssrcs": [%d, %d]
- }
- })",
- offer["seqNum"].asInt(), audio_index, video_index, audio_ssrc + 1,
- video_ssrc + 1);
-
- return std::string(answer);
+ constexpr char kAnswerTemplate[] = R"({
+ "type": "ANSWER",
+ "seqNum": %d,
+ "answer": {
+ "castMode": "mirroring",
+ "udpPort": 1234,
+ "sendIndexes": [%d, %d],
+ "ssrcs": [%d, %d]
+ }
+ })";
+ return StringPrintf(kAnswerTemplate, offer["seqNum"].asInt(), audio_index,
+ video_index, audio_ssrc + 1, video_ssrc + 1);
}
protected: