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)
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)
......
......@@ -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
......@@ -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
......@@ -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
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