Commit c6df9c85 authored by Akhil K Gangadharan's avatar Akhil K Gangadharan

Initialise capture parameters from core and settings

parent 99e39932
Pipeline #1651 passed with stage
in 36 minutes and 31 seconds
......@@ -20,13 +20,19 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "mediacapture.h"
#include "kdenlivesettings.h"
#include "core.h"
#include <QAudioProbe>
#include <QDir>
#include <memory>
#include <utility>
MediaCapture::MediaCapture(QObject *parent)
: QObject(parent)
, m_volume(1.)
, currentState(-1)
, m_audioDevice("default:")
, m_path(QUrl())
{
m_probe = std::make_unique<QAudioProbe>(this);
connect(m_probe.get(), &QAudioProbe::audioBufferProbed, this, &MediaCapture::processBuffer);
......@@ -47,9 +53,13 @@ void MediaCapture::recordAudio(bool record)
m_probe->setSource(m_audioRecorder.get());
if (record && m_audioRecorder->state() == QMediaRecorder::StoppedState) {
setAudioCaptureDevice();
m_audioRecorder->setAudioInput(m_audioDevice);
m_audioRecorder->setVolume(m_volume);
setCaptureOutputLocation();
m_audioRecorder->setOutputLocation(m_path);
setAudioVolume();
m_audioRecorder->setVolume(m_volume);
connect(m_audioRecorder.get(), SIGNAL(error(QMediaRecorder::Error)), this, SLOT(displayErrorMessage()));
QAudioEncoderSettings audioSettings;
......@@ -80,9 +90,9 @@ void MediaCapture::recordVideo(bool record)
}
if (record && m_videoRecorder->state() == QMediaRecorder::StoppedState) {
connect(m_videoRecorder.get(), SIGNAL(error(QMediaRecorder::Error)), this, SLOT(displayErrorMessage()));
setCaptureOutputLocation();
m_videoRecorder->setOutputLocation(m_path);
connect(m_videoRecorder.get(), SIGNAL(error(QMediaRecorder::Error)), this, SLOT(displayErrorMessage()));
m_camera->setCaptureMode(QCamera::CaptureVideo);
m_camera->start();
// QString container = "video/mpeg";
......@@ -96,11 +106,35 @@ void MediaCapture::recordVideo(bool record)
}
}
void MediaCapture::setCaptureOutputLocation(QUrl path)
void MediaCapture::setCaptureOutputLocation()
{
m_path = std::move(path);
QDir captureFolder;
if (KdenliveSettings::capturetoprojectfolder()) {
captureFolder = QDir(pCore->getProjectFolderName());
} else {
captureFolder = QDir(KdenliveSettings::capturefolder());
}
QString extension;
if (m_videoRecorder.get() != nullptr) {
extension = QStringLiteral("mpeg");
} else if (m_audioRecorder.get() != nullptr) {
extension = QStringLiteral("wav");
}
QString path = captureFolder.absoluteFilePath("capture0000." + extension);
int fileCount = 1;
while (QFile::exists(path)) {
QString num = QString::number(fileCount).rightJustified(4, '0', false);
path = captureFolder.absoluteFilePath("capture" + num + QLatin1Char('.') + extension);
++fileCount;
}
m_path = std::move(QUrl::fromLocalFile(path));
}
QUrl MediaCapture::getCaptureOutputLocation()
{
return m_path;
}
QStringList MediaCapture::getAudioCaptureDevices()
{
m_audioRecorder = std::make_unique<QAudioRecorder>(this);
......@@ -109,25 +143,27 @@ QStringList MediaCapture::getAudioCaptureDevices()
return audioDevices;
}
void MediaCapture::setAudioCaptureDevice(QString audioDevice)
void MediaCapture::setAudioCaptureDevice()
{
m_audioDevice = std::move(audioDevice);
QStringList audioDevices = getAudioCaptureDevices();
int deviceIndex = KdenliveSettings::defaultaudiocapture();
m_audioDevice = std::move(audioDevices[deviceIndex]);
}
void MediaCapture::setAudioVolume(qreal volume)
void MediaCapture::setAudioVolume()
{
m_volume = volume;
m_volume = KdenliveSettings::audiocapturevolume()/100.0;
}
int MediaCapture::getState()
{
if (m_audioRecorder != nullptr) {
return m_audioRecorder->state();
currentState = m_audioRecorder->state();
}
if (m_videoRecorder != nullptr) {
return m_videoRecorder->state();
else if (m_videoRecorder != nullptr) {
currentState = m_videoRecorder->state();
}
return -1;
return currentState;
}
template <class T> QVector<qreal> getBufferLevels(const T *buffer, int frames, int channels)
......@@ -265,4 +301,4 @@ void MediaCapture::processBuffer(const QAudioBuffer &buffer)
QVector<qreal> MediaCapture::levels() const
{
return m_levels;
}
}
\ No newline at end of file
......@@ -47,15 +47,18 @@ public:
void recordAudio(bool /*record*/);
void recordVideo(bool /*record*/);
/** @brief Sets m_path to selected output location **/
void setCaptureOutputLocation(QUrl /*path*/);
/** @brief Sets m_device to selected audio capture device **/
void setAudioCaptureDevice(QString /*audioDevice*/);
void setCaptureOutputLocation();
/** @brief Returns m_path **/
QUrl getCaptureOutputLocation();
/** @brief Sets m_audioDevice to selected audio capture device **/
void setAudioCaptureDevice();
/** @brief Sets m_volume to selected audio capture volume **/
void setAudioVolume(qreal /*volume*/);
void setAudioVolume();
/** @brief Returns list of audio devices available for capture **/
QStringList getAudioCaptureDevices();
/** @brief Returns QMediaRecorder::State value **/
/** @brief Sets currentState to QMediaRecorder::State value and returns it **/
int getState();
int currentState;
Q_INVOKABLE QVector<qreal> levels() const;
public slots:
......
......@@ -34,6 +34,7 @@ the Free Software Foundation, either version 3 of the License, or
#include <KMessageBox>
#include <QCoreApplication>
#include <QInputDialog>
#include <QDir>
#include <mlt++/MltRepository.h>
......@@ -680,15 +681,14 @@ void Core::clean()
m_self.reset();
}
void Core::startMediaCapture(bool checkAudio, bool checkVideo, QUrl path, QString audioDevice)
void Core::startMediaCapture(bool checkAudio, bool checkVideo)
{
m_capture->setCaptureOutputLocation(path);
m_capture->setAudioCaptureDevice(audioDevice);
if (checkAudio && checkVideo) {
m_capture->recordVideo(true);
} else if (checkAudio) {
m_capture->recordAudio(true);
}
m_mediaCaptureFile = m_capture->getCaptureOutputLocation();
}
void Core::stopMediaCapture(bool checkAudio, bool checkVideo)
......@@ -698,6 +698,7 @@ void Core::stopMediaCapture(bool checkAudio, bool checkVideo)
} else if (checkAudio && !checkVideo) {
m_capture->recordAudio(false);
}
bin()->slotAddClipToProject(m_mediaCaptureFile);
}
QStringList Core::getAudioCaptureDevices()
......@@ -710,12 +711,12 @@ int Core::getMediaCaptureState()
return m_capture->getState();
}
void Core::setAudioCaptureVolume(int volume)
{
m_capture->setAudioVolume(volume / 100.0);
}
MediaCapture *Core::getAudioDevice()
{
return m_capture.get();
}
QString Core::getProjectFolderName()
{
return m_monitorManager->getProjectFolder();
}
\ No newline at end of file
......@@ -181,12 +181,14 @@ public:
/** @brief Returns current timeline cursor position */
int getTimelinePosition() const;
/** @brief Handles audio and video capture **/
void startMediaCapture(bool, bool, QUrl, QString);
void startMediaCapture(bool, bool);
void stopMediaCapture(bool, bool);
QStringList getAudioCaptureDevices();
int getMediaCaptureState();
void setAudioCaptureVolume(int);
MediaCapture *getAudioDevice();
/** @brief Returns Project Folder name for capture output location */
QString getProjectFolderName();
private:
explicit Core();
......@@ -211,6 +213,7 @@ private:
/** @brief Check that the profile is valid (width is a multiple of 8 and height a multiple of 2 */
void checkProfileValidity();
std::unique_ptr<MediaCapture> m_capture;
QUrl m_mediaCaptureFile;
public slots:
void triggerAction(const QString &name);
......
......@@ -163,7 +163,6 @@ void RecManager::stopCapture()
// QMediaRecorder::RecordingState value is 1
pCore->stopMediaCapture(m_checkAudio, m_checkVideo);
m_monitor->slotOpenClip(nullptr);
emit addClipToProject(m_captureFile);
}
}
......@@ -182,31 +181,9 @@ void RecManager::slotRecord(bool record)
{
if (m_device_selector->currentData().toInt() == Video4Linux) {
if (record) {
QDir captureFolder;
if (KdenliveSettings::capturetoprojectfolder()) {
captureFolder = QDir(m_monitor->projectFolder());
} else {
captureFolder = QDir(KdenliveSettings::capturefolder());
}
QString extension;
if (!m_recVideo->isChecked()) {
extension = QStringLiteral("wav");
} else {
extension = QStringLiteral("mpeg");
}
QString path = captureFolder.absoluteFilePath("capture0000." + extension);
int i = 1;
while (QFile::exists(path)) {
QString num = QString::number(i).rightJustified(4, '0', false);
path = captureFolder.absoluteFilePath("capture" + num + QLatin1Char('.') + extension);
++i;
}
QString audioDevice = m_audio_device->currentText();
m_captureFile = QUrl::fromLocalFile(path);
m_checkAudio = m_recAudio->isChecked();
m_checkVideo = m_recVideo->isChecked();
pCore->startMediaCapture(m_checkAudio, m_checkVideo, m_captureFile, audioDevice);
pCore->startMediaCapture(m_checkAudio, m_checkVideo);
} else {
stopCapture();
}
......@@ -347,7 +324,6 @@ void RecManager::slotAudioDeviceChanged(int)
void RecManager::slotSetVolume(int volume)
{
KdenliveSettings::setAudiocapturevolume(volume);
pCore->setAudioCaptureVolume(volume);
QIcon icon;
if (volume == 0) {
......
......@@ -130,6 +130,7 @@ void TimelineWidget::setModel(const std::shared_ptr<TimelineItemModel> &model)
// rootContext()->setContextProperty("effectModel", m_effectsProxyModel.get());
rootContext()->setContextProperty("effectModel", sortedItems(KdenliveSettings::favorite_effects(), false));
rootContext()->setContextProperty("audiorec", pCore->getAudioDevice());
rootContext()->setContextProperty("core", pCore.get());
rootContext()->setContextProperty("guidesModel", pCore->projectManager()->current()->getGuideModel().get());
rootContext()->setContextProperty("clipboard", new ClipboardProxy(this));
setSource(QUrl(QStringLiteral("qrc:/qml/timeline.qml")));
......
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