Commit dd6199ac authored by Philippe Gorley's avatar Philippe Gorley Committed by Adrien Béraud

recorder: make adding streams public

Instead of casting the observable object in the attached callback, have
the recorder's owner add the streams manually.

Change-Id: I5c79e32e470364b0c6a4253f50357a4bafade769
parent a2264383
......@@ -196,10 +196,14 @@ AudioRtpSession::setMuted(bool isMuted)
void
AudioRtpSession::initRecorder(std::shared_ptr<MediaRecorder>& rec)
{
if (receiveThread_)
if (receiveThread_) {
receiveThread_->attach(rec.get());
if (auto input = ring::getAudioInput(callID_))
rec->addStream(receiveThread_->getInfo());
}
if (auto input = ring::getAudioInput(callID_)) {
input->attach(rec.get());
rec->addStream(input->getInfo());
}
}
void
......
......@@ -73,6 +73,7 @@ LocalRecorder::startRecording()
audioInput_ = ring::getAudioInput(path_);
audioInput_->setFormat(AudioFormat::STEREO());
recorder_->addStream(audioInput_->getInfo());
audioInput_->attach(recorder_.get());
#ifdef RING_VIDEO
......@@ -80,6 +81,7 @@ LocalRecorder::startRecording()
if (!isAudioOnly_) {
videoInput_ = std::static_pointer_cast<video::VideoInput>(ring::getVideoCamera());
if (videoInput_) {
recorder_->addStream(videoInput_->getInfo());
videoInput_->attach(recorder_.get());
} else {
RING_ERR() << "Unable to record video (no video input)";
......@@ -96,6 +98,9 @@ LocalRecorder::stopRecording()
{
Recordable::stopRecording();
Manager::instance().getRingBufferPool().unBindHalfDuplexOut(path_, RingBufferPool::DEFAULT_ID);
audioInput_->detach(recorder_.get());
if (videoInput_)
videoInput_->detach(recorder_.get());
audioInput_.reset();
videoInput_.reset();
}
......
......@@ -150,17 +150,6 @@ MediaRecorder::update(Observable<std::shared_ptr<AudioFrame>>* ob, const std::sh
recordData(a->pointer(), streams_[name]);
}
void MediaRecorder::attached(Observable<std::shared_ptr<AudioFrame>>* ob)
{
MediaStream ms;
if (auto receiver = dynamic_cast<AudioReceiveThread*>(ob))
ms = receiver->getInfo();
else if (auto input = dynamic_cast<AudioInput*>(ob))
ms = input->getInfo();
if (addStream(ms) >= 0)
hasAudio_ = true;
}
void MediaRecorder::update(Observable<std::shared_ptr<VideoFrame>>* ob, const std::shared_ptr<VideoFrame>& v)
{
std::string name;
......@@ -171,17 +160,6 @@ void MediaRecorder::update(Observable<std::shared_ptr<VideoFrame>>* ob, const st
recordData(v->pointer(), streams_[name]);
}
void MediaRecorder::attached(Observable<std::shared_ptr<VideoFrame>>* ob)
{
MediaStream ms;
if (auto receiver = dynamic_cast<video::VideoReceiveThread*>(ob))
ms = receiver->getInfo();
else if (auto input = dynamic_cast<video::VideoInput*>(ob))
ms = input->getInfo();
if (addStream(ms) >= 0)
hasVideo_ = true;
}
int
MediaRecorder::addStream(const MediaStream& ms)
{
......@@ -192,6 +170,10 @@ MediaRecorder::addStream(const MediaStream& ms)
if (streams_.insert(std::make_pair(ms.name, ms)).second) {
RING_DBG() << "Recorder input #" << streams_.size() << ": " << ms;
if (ms.isVideo)
hasVideo_ = true;
else
hasAudio_ = true;
return 0;
} else {
RING_ERR() << "Could not add stream '" << ms.name << "' to record";
......
......@@ -70,19 +70,18 @@ public:
void stopRecording();
int addStream(const MediaStream& ms);
/* Observer methods*/
void update(Observable<std::shared_ptr<AudioFrame>>* ob, const std::shared_ptr<AudioFrame>& a) override;
void attached(Observable<std::shared_ptr<AudioFrame>>* ob) override;
void update(Observable<std::shared_ptr<VideoFrame>>* ob, const std::shared_ptr<VideoFrame>& v) override;
void attached(Observable<std::shared_ptr<VideoFrame>>* ob) override;
private:
NON_COPYABLE(MediaRecorder);
int recordData(AVFrame* frame, const MediaStream& ms);
int addStream(const MediaStream& ms);
int initRecord();
MediaStream setupVideoOutput();
std::string buildVideoFilter(const std::vector<MediaStream>& peers, const MediaStream& local) const;
......
......@@ -567,10 +567,14 @@ VideoRtpSession::processPacketLoss()
void
VideoRtpSession::initRecorder(std::shared_ptr<MediaRecorder>& rec)
{
if (receiveThread_)
if (receiveThread_) {
receiveThread_->attach(rec.get());
if (auto vidInput = std::static_pointer_cast<VideoInput>(videoLocal_))
rec->addStream(receiveThread_->getInfo());
}
if (auto vidInput = std::static_pointer_cast<VideoInput>(videoLocal_)) {
vidInput->attach(rec.get());
rec->addStream(vidInput->getInfo());
}
}
void
......
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