mediacapture.h 2.95 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
/*
Copyright (C) 2019  Akhil K Gangadharan <akhilam512@gmail.com>
This file is part of Kdenlive. See www.kdenlive.org.

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 the Free Software Foundation; either version 2 of
the License or (at your option) version 3 or any later version
accepted by the membership of KDE e.V. (or its successor approved
by the membership of KDE e.V.), which shall act as a proxy
defined in Section 14 of version 3 of the license.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef MEDIACAPTURE_H
#define MEDIACAPTURE_H

Nicolas Carion's avatar
Nicolas Carion committed
25
#include <QAudioBuffer>
26
#include <QAudioEncoderSettings>
Nicolas Carion's avatar
Nicolas Carion committed
27
#include <QAudioRecorder>
28 29
#include <QCamera>
#include <QCameraInfo>
Nicolas Carion's avatar
Nicolas Carion committed
30
#include <QMediaRecorder>
31 32
#include <QStringList>
#include <QUrl>
Nicolas Carion's avatar
Nicolas Carion committed
33
#include <QVideoEncoderSettings>
34 35
#include <QTimer>
#include <QMutex>
36 37 38
#include <memory>

class QAudioRecorder;
39
class QAudioProbe;
40

Nicolas Carion's avatar
Nicolas Carion committed
41
class MediaCapture : public QObject
42 43
{
    Q_OBJECT
44
    Q_PROPERTY(QVector<qreal> levels READ levels NOTIFY levelsChanged)
45
    Q_PROPERTY(int recordState READ recordState NOTIFY recordStateChanged)
46 47

public:
Nicolas Carion's avatar
Nicolas Carion committed
48
    MediaCapture(QObject *parent);
Nicolas Carion's avatar
Nicolas Carion committed
49 50 51
    ~MediaCapture() override;
    void recordAudio(bool /*record*/);
    void recordVideo(bool /*record*/);
52 53
    /** @brief Returns true if a recording is in progress **/
    bool isRecording() const;
54
    /** @brief Sets m_path to selected output location **/
55 56 57 58 59
    void setCaptureOutputLocation();
    /** @brief Returns m_path **/
    QUrl getCaptureOutputLocation();
    /** @brief Sets m_audioDevice to selected audio capture device **/
    void setAudioCaptureDevice();
60
    /** @brief Sets m_volume to selected audio capture volume **/
61
    void setAudioVolume();
62 63
    /** @brief Returns list of audio devices available for capture **/
    QStringList getAudioCaptureDevices();
64
    /** @brief Sets currentState to QMediaRecorder::State value and returns it **/
65
    int getState();
66
    int currentState;
67
    Q_INVOKABLE QVector<qreal> levels() const;
68
    Q_INVOKABLE int recordState() const;
69 70 71 72 73 74 75 76

public slots:
    void displayErrorMessage();

private:
    std::unique_ptr<QAudioRecorder> m_audioRecorder;
    std::unique_ptr<QMediaRecorder> m_videoRecorder;
    std::unique_ptr<QCamera> m_camera;
77
    std::unique_ptr<QAudioProbe> m_probe;
78 79 80
    QString m_audioDevice;
    qreal m_volume;
    QUrl m_path;
81
    QVector<qreal> m_levels;
82
    int m_recordState;
83 84
    QTimer m_resetTimer;
    QMutex m_recMutex;
85 86

private slots:
Nicolas Carion's avatar
Nicolas Carion committed
87
    void processBuffer(const QAudioBuffer &buffer);
88
    void resetIfUnused();
Nicolas Carion's avatar
Nicolas Carion committed
89

90 91
signals:
    void levelsChanged();
92
    void recordStateChanged();
93
    void recordDone();
94 95 96
};

#endif