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