Commit ecf9650a authored by Philippe Gorley's avatar Philippe Gorley

localrecorder: simplify setup

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