Commit 1c057a3a authored by Hugo Lefeuvre's avatar Hugo Lefeuvre Committed by Adrien Béraud

media_recorder: deprecate path generation

Recorded conversations should be stored at a location specified by
the client.

Currently the MediaRecorder generates a filename using timestamps,
and the directory is either specified by the user in the config.yml
or defaulted to the user's /home. This is not a wanted behavior.

This commit introduces the necessary logic to set recording file path
using setPath and deprecates the old way of specifying filename and
dir.

The changes are backward compatible for transition purposes.

In addition to this refactoring, this commit renames the getFilename()
method to getPath(). In fact this method returns "full paths" and not
filenames, so it doesn't make much sense to call it getFilename().

Change-Id: I8eb9756dd1bf2a18fb0c97eec8b9bb72c259a7e5
parent e03c39b0
......@@ -2406,7 +2406,7 @@ Manager::toggleRecordingCall(const std::string& id)
}
const bool result = rec->toggleRecording();
emitSignal<DRing::CallSignal::RecordPlaybackFilepath>(id, rec->getFilename());
emitSignal<DRing::CallSignal::RecordPlaybackFilepath>(id, rec->getPath());
emitSignal<DRing::CallSignal::RecordingStateChanged>(id, result);
return result;
}
......
......@@ -141,7 +141,7 @@ void AudioRecord::initFilename(const std::string &peerNumber)
}
}
std::string AudioRecord::getFilename() const
std::string AudioRecord::getPath() const
{
return savePath_ + filename_;
}
......@@ -155,8 +155,8 @@ AudioRecord::openFile()
const bool doAppend = fileExists();
const int access = doAppend ? SFM_RDWR : SFM_WRITE;
RING_DBG("Opening file %s with format %s", getFilename().c_str(), sndFormat_.toString().c_str());
fileHandle_.reset(new SndfileHandle (getFilename().c_str(),
RING_DBG("Opening file %s with format %s", getPath().c_str(), sndFormat_.toString().c_str());
fileHandle_.reset(new SndfileHandle (getPath().c_str(),
access,
SF_FORMAT_WAV | SF_FORMAT_PCM_16,
sndFormat_.nb_channels,
......@@ -193,7 +193,7 @@ AudioRecord::isOpenFile() const noexcept
bool AudioRecord::fileExists() const
{
return access(getFilename().c_str(), F_OK) != -1;
return access(getPath().c_str(), F_OK) != -1;
}
bool AudioRecord::isRecording() const
......@@ -217,7 +217,7 @@ AudioRecord::toggleRecording()
void
AudioRecord::stopRecording() const noexcept
{
RING_DBG("Stop recording %s", getFilename().c_str());
RING_DBG("Stop recording %s", getPath().c_str());
recordingEnabled_ = false;
}
......
......@@ -48,9 +48,9 @@ class AudioRecord {
void initFilename(const std::string &peerNumber);
/**
* Return the filepath of the recording
* Return the file path of the recording
*/
std::string getFilename() const;
std::string getPath() const;
/**
* Check if no other file is opened, then create a new one
......
......@@ -52,12 +52,20 @@ MediaRecorder::~MediaRecorder()
}
std::string
MediaRecorder::getFilename() const
MediaRecorder::getPath() const
{
if (audioOnly_)
return dir_ + filename_ + ".ogg";
else
return dir_ + filename_ + ".mkv";
if (path_.empty()) {
// FIXME deprecated code, will be removed once all clients transitioned to startRecording(path).
if (audioOnly_)
return dir_ + filename_ + ".ogg";
else
return dir_ + filename_ + ".mkv";
} else {
if (audioOnly_)
return path_ + ".ogg";
else
return path_ + ".mkv";
}
}
void
......@@ -85,6 +93,15 @@ MediaRecorder::setRecordingPath(const std::string& dir)
RING_DBG() << "Recording will be saved in '" << dir_ << "'";
}
void
MediaRecorder::setPath(const std::string& path)
{
if (!path.empty()) {
path_ = path;
}
RING_DBG() << "Recording will be saved as '" << path_ << "'";
}
void
MediaRecorder::incrementStreams(int n)
{
......@@ -111,11 +128,14 @@ MediaRecorder::toggleRecording()
int
MediaRecorder::startRecording()
{
std::time_t t = std::time(nullptr);
startTime_ = *std::localtime(&t);
std::stringstream ss;
ss << std::put_time(&startTime_, "%Y%m%d-%H%M%S");
filename_ = ss.str();
if (path_.empty()) {
// FIXME deprecated code, will be removed once all clients transitioned to startRecording(path).
std::time_t t = std::time(nullptr);
startTime_ = *std::localtime(&t);
std::stringstream ss;
ss << std::put_time(&startTime_, "%Y%m%d-%H%M%S");
filename_ = ss.str();
}
if (!frames_.empty()) {
RING_WARN() << "Frame queue not empty at beginning of recording, frames will be lost";
......@@ -128,7 +148,7 @@ MediaRecorder::startRecording()
encoder_.reset(new MediaEncoder);
RING_DBG() << "Start recording '" << getFilename() << "'";
RING_DBG() << "Start recording '" << getPath() << "'";
isRecording_ = true;
return 0;
}
......@@ -137,7 +157,7 @@ void
MediaRecorder::stopRecording()
{
if (isRecording_) {
RING_DBG() << "Stop recording '" << getFilename() << "'";
RING_DBG() << "Stop recording '" << getPath() << "'";
flush();
}
isRecording_ = false;
......@@ -231,7 +251,7 @@ MediaRecorder::initRecord()
encoderOptions["channels"] = std::to_string(audioStream.nbChannels);
}
encoder_->openFileOutput(getFilename(), encoderOptions);
encoder_->openFileOutput(getPath(), encoderOptions);
if (nbReceivedVideoStreams_ > 0) {
auto videoCodec = std::static_pointer_cast<ring::SystemVideoCodecInfo>(
......
......@@ -44,7 +44,9 @@ class MediaRecorder {
MediaRecorder();
~MediaRecorder();
std::string getFilename() const;
std::string getPath() const;
void setPath(const std::string& path);
void audioOnly(bool audioOnly);
......@@ -52,6 +54,7 @@ class MediaRecorder {
// default description is: "Recorded at %Y-%m-%d %H:%M:%S with Ring https://ring.cx"
void setMetadata(const std::string& title, const std::string& desc);
[[deprecated("use setPath to set full recording path")]]
void setRecordingPath(const std::string& dir);
// adjust nb of streams before recording
......@@ -91,11 +94,16 @@ class MediaRecorder {
std::map<bool, std::map<bool, MediaStream>> streams_;
std::tm startTime_;
std::string dir_;
std::string filename_;
std::string title_;
std::string description_;
std::string path_;
[[deprecated]]
std::string dir_;
[[deprecated]]
std::string filename_;
unsigned nbExpectedStreams_ = 0;
unsigned nbReceivedVideoStreams_ = 0;
unsigned nbReceivedAudioStreams_ = 0;
......
......@@ -38,10 +38,10 @@ Recordable::initRecFilename(const std::string& /*filename*/)
{}
std::string
Recordable::getFilename() const
Recordable::getPath() const
{
if (recorder_)
return recorder_->getFilename();
return recorder_->getPath();
else
return "";
}
......
......@@ -63,7 +63,7 @@ public:
/**
* Return the file path for this recording
*/
virtual std::string getFilename() const;
virtual std::string getPath() const;
bool isAudioOnly() const;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment