diff --git a/src/client/videomanager.cpp b/src/client/videomanager.cpp index 2c33fd6b1a5cdb38ab068591b73864aef2701b98..f6761acb3be14ab98ec9fca89c22eed6b9bccfcd 100644 --- a/src/client/videomanager.cpp +++ b/src/client/videomanager.cpp @@ -278,15 +278,7 @@ startLocalRecorder(const bool& audioOnly, const std::string& filepath) return ""; } - std::unique_ptr<ring::LocalRecorder> rec; - std::shared_ptr<ring::video::VideoInput> input = nullptr; - if (!audioOnly) { - input = std::static_pointer_cast<ring::video::VideoInput>(ring::getVideoCamera()); - } - - /* in case of audio-only recording, nullptr is passed and LocalRecorder will - assume isAudioOnly_ = true, so no need to call Recordable::isAudioOnly(). */ - rec.reset(new ring::LocalRecorder(input)); + auto rec = std::make_unique<ring::LocalRecorder>(audioOnly); rec->setPath(filepath); // retrieve final path (containing file extension) diff --git a/src/media/localrecorder.cpp b/src/media/localrecorder.cpp index d2a27cc5c01d92e0c61f933747f89af78fad2181..2c3f0f6b2e64ce6756fe44f2073ad0ceec01dc40 100644 --- a/src/media/localrecorder.cpp +++ b/src/media/localrecorder.cpp @@ -22,21 +22,16 @@ #include "localrecorder.h" #include "audio/ringbufferpool.h" #include "audio/ringbuffer.h" +#include "client/videomanager.h" #include "media_stream.h" #include "manager.h" #include "logger.h" namespace ring { -LocalRecorder::LocalRecorder(std::shared_ptr<ring::video::VideoInput> input) { - if (input) { - videoInput_ = input; - videoInputSet_ = true; - } else { - isAudioOnly_ = true; - } - - recorder_->audioOnly(isAudioOnly_); +LocalRecorder::LocalRecorder(const bool& audioOnly) { + isAudioOnly_ = audioOnly; + recorder_->audioOnly(audioOnly); } void @@ -81,11 +76,11 @@ LocalRecorder::startRecording() #ifdef RING_VIDEO // video recording if (!isAudioOnly_) { - if (videoInputSet_) { - auto videoInputShpnt = videoInput_.lock(); - videoInputShpnt->initRecorder(recorder_); + videoInput_ = std::static_pointer_cast<video::VideoInput>(ring::getVideoCamera()); + if (videoInput_) { + videoInput_->initRecorder(recorder_); } else { - RING_ERR("[BUG] can't record video (video input pointer is null)"); + RING_ERR() << "Unable to record video (no video input)"; return false; } } @@ -98,12 +93,11 @@ void LocalRecorder::stopRecording() { Recordable::stopRecording(); - - if (audioInput_) { - Manager::instance().getRingBufferPool().unBindHalfDuplexOut(path_, RingBufferPool::DEFAULT_ID); - } else { - RING_ERR("could not stop audio layer (audio input is null)"); - } + Manager::instance().getRingBufferPool().unBindHalfDuplexOut(path_, RingBufferPool::DEFAULT_ID); + audioInput_.reset(); + if (videoInput_) + videoInput_->initRecorder(nullptr); // workaround for deiniting recorder + videoInput_.reset(); } } // namespace ring diff --git a/src/media/localrecorder.h b/src/media/localrecorder.h index 81be4e9733764c0e81e27cda26b8af63f28d29b7..bf31bae899fe149dd49fcf16b3bb7b73a2553df4 100644 --- a/src/media/localrecorder.h +++ b/src/media/localrecorder.h @@ -2,6 +2,7 @@ * Copyright (C) 2018 Savoir-faire Linux Inc. * * Author: Hugo Lefeuvre <hugo.lefeuvre@savoirfairelinux.com> + * Author: Philippe Gorley <philippe.gorley@savoirfairelinux.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,9 +21,9 @@ #pragma once -#include "media/video/video_input.h" -#include "media/audio/audio_input.h" +#include "audio/audio_input.h" #include "recordable.h" +#include "video/video_input.h" namespace ring { @@ -45,7 +46,7 @@ class LocalRecorder : public Recordable { * If input pointer in null, video recording will be disabled on this * recorder. */ - LocalRecorder(std::shared_ptr<ring::video::VideoInput> input); + LocalRecorder(const bool& audioOnly); /** * Start local recording. Return true if recording was successfully @@ -61,10 +62,11 @@ class LocalRecorder : public Recordable { void setPath(const std::string& path); private: - bool videoInputSet_ = false; - std::weak_ptr<ring::video::VideoInput> videoInput_; - std::unique_ptr<ring::AudioInput> audioInput_ = nullptr; std::string path_; + + // media inputs + std::shared_ptr<ring::video::VideoInput> videoInput_; + std::unique_ptr<ring::AudioInput> audioInput_; }; } // namespace ring diff --git a/src/media/video/video_input.cpp b/src/media/video/video_input.cpp index db0a77609bcde946dd745ef3ed6cf81c55f94230..d7a6334ddb672f56b3312e5b42f4e64820af6b32 100644 --- a/src/media/video/video_input.cpp +++ b/src/media/video/video_input.cpp @@ -625,8 +625,12 @@ VideoInput::foundDecOpts(const DeviceParams& params) void VideoInput::initRecorder(const std::shared_ptr<MediaRecorder>& rec) { - recorder_ = rec; - rec->incrementExpectedStreams(1); + if (rec) { + recorder_ = rec; + rec->incrementExpectedStreams(1); + } else { + recorder_.reset(); + } } }} // namespace ring::video