From 92f3e151adf574b8403b3779a48c4c4509827786 Mon Sep 17 00:00:00 2001 From: philippegorley <philippe.gorley@savoirfairelinux.com> Date: Thu, 7 Jun 2018 15:14:38 -0400 Subject: [PATCH] recorder: change title and description Recorder replaces "%TIMESTAMP" with the start time of the recording. SIP calls now have the title: "Conversation at %TIMESTAMP between USER1 and USER2", where the registered username is used if possible, else falls back on the ring id. Change-Id: Idd65917173861b395a4bb1476274727679b087b3 Reviewed-by: Sebastien Blin <sebastien.blin@savoirfairelinux.com> --- src/media/media_recorder.cpp | 26 +++++++++++++++++++++----- src/media/media_recorder.h | 5 +++-- src/sip/sipcall.cpp | 3 ++- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/media/media_recorder.cpp b/src/media/media_recorder.cpp index fa00536fc6..a45b9f2320 100644 --- a/src/media/media_recorder.cpp +++ b/src/media/media_recorder.cpp @@ -39,6 +39,20 @@ namespace ring { static constexpr auto FRAME_DEQUEUE_INTERVAL = std::chrono::milliseconds(200); +static std::string +replaceAll(const std::string& str, const std::string& from, const std::string& to) +{ + if (from.empty()) + return str; + std::string copy(str); + size_t startPos = 0; + while ((startPos = str.find(from, startPos)) != std::string::npos) { + copy.replace(startPos, from.length(), to); + startPos += to.length(); + } + return copy; +} + MediaRecorder::MediaRecorder() : loop_([]{ return true;}, [this]{ process(); }, @@ -224,19 +238,21 @@ MediaRecorder::initRecord() std::map<std::string, std::string> encoderOptions; + std::stringstream timestampString; + timestampString << std::put_time(&startTime_, "%Y-%m-%d %H:%M:%S"); + if (title_.empty()) { std::stringstream ss; - ss << "Ring recording at " << std::put_time(&startTime_, "%Y-%m-%d %H:%M:%S"); + ss << "Conversation at %TIMESTAMP"; title_ = ss.str(); } + title_ = replaceAll(title_, "%TIMESTAMP", timestampString.str()); encoderOptions["title"] = title_; if (description_.empty()) { - std::stringstream ss; - ss << "Recorded at " << std::put_time(&startTime_, "%Y-%m-%d %H:%M:%S") - << " with Ring https://ring.cx"; - description_ = ss.str(); + description_ = "Recorded with Ring https://ring.cx"; } + description_ = replaceAll(description_, "%TIMESTAMP", timestampString.str()); encoderOptions["description"] = description_; videoFilter_.reset(); diff --git a/src/media/media_recorder.h b/src/media/media_recorder.h index 9a46fc409d..eee2288e14 100644 --- a/src/media/media_recorder.h +++ b/src/media/media_recorder.h @@ -50,8 +50,9 @@ class MediaRecorder { void audioOnly(bool audioOnly); - // default title is: "Ring recording at %Y-%m-%d %H:%M:%S" - // default description is: "Recorded at %Y-%m-%d %H:%M:%S with Ring https://ring.cx" + // replaces %TIMESTAMP with time at start of recording + // default title: "Conversation at %Y-%m-%d %H:%M:%S" + // default description: "Recorded with Ring https://ring.cx" void setMetadata(const std::string& title, const std::string& desc); [[deprecated("use setPath to set full recording path")]] diff --git a/src/sip/sipcall.cpp b/src/sip/sipcall.cpp index 848536ad0b..06c973f19b 100644 --- a/src/sip/sipcall.cpp +++ b/src/sip/sipcall.cpp @@ -1155,7 +1155,8 @@ SIPCall::toggleRecording() const bool startRecording = Call::toggleRecording(); if (startRecording) { std::stringstream ss; - ss << "Ring call between " << getSIPAccount().getUserUri() << " and " << peerUri_; + ss << "Conversation at %TIMESTAMP between " + << getSIPAccount().getUserUri() << " and " << peerUri_; recorder_->setMetadata(ss.str(), ""); // use default description if (avformatrtp_) avformatrtp_->startRecorder(recorder_); -- GitLab