1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00
qTox/src/video/camerasource.h

87 lines
2.0 KiB
C
Raw Normal View History

2015-05-14 10:46:28 +08:00
/*
Copyright © 2015-2018 by The qTox Project Contributors
2015-05-14 10:46:28 +08:00
This file is part of qTox, a Qt-based graphical interface for Tox.
qTox is libre software: you can redistribute it and/or modify
2015-05-14 10:46:28 +08:00
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
qTox is distributed in the hope that it will be useful,
2015-05-14 10:46:28 +08:00
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.
2015-05-14 10:46:28 +08:00
You should have received a copy of the GNU General Public License
along with qTox. If not, see <http://www.gnu.org/licenses/>.
2015-05-14 10:46:28 +08:00
*/
#ifndef CAMERA_H
#define CAMERA_H
#include "src/video/videomode.h"
#include "src/video/videosource.h"
#include <QFuture>
2015-05-14 10:46:28 +08:00
#include <QHash>
#include <QReadWriteLock>
2015-05-14 10:46:28 +08:00
#include <QString>
#include <QVector>
#include <atomic>
class CameraDevice;
struct AVCodecContext;
class CameraSource : public VideoSource
{
Q_OBJECT
2015-05-14 10:46:28 +08:00
public:
static CameraSource& getInstance();
2015-06-27 01:04:53 +08:00
static void destroyInstance();
void setupDefault();
bool isNone() const;
2015-05-14 10:46:28 +08:00
// VideoSource interface
2017-06-26 18:51:44 +08:00
virtual void subscribe() override;
2015-05-14 10:46:28 +08:00
virtual void unsubscribe() override;
public slots:
void setupDevice(const QString& deviceName, const VideoMode& mode);
signals:
void deviceOpened();
2017-06-26 18:51:44 +08:00
void openFailed();
2015-05-14 10:46:28 +08:00
private:
CameraSource();
~CameraSource();
2015-05-14 10:46:28 +08:00
void stream();
private slots:
2017-06-26 18:51:44 +08:00
void openDevice();
void closeDevice();
2015-05-14 10:46:28 +08:00
private:
QFuture<void> streamFuture;
2017-06-26 18:58:22 +08:00
QThread* deviceThread;
QString deviceName;
CameraDevice* device;
VideoMode mode;
AVCodecContext* cctx;
// TODO: Remove when ffmpeg version will be bumped to the 3.1.0
AVCodecContext* cctxOrig;
int videoStreamIndex;
2017-06-26 18:58:22 +08:00
QReadWriteLock deviceMutex;
QReadWriteLock streamMutex;
std::atomic_bool _isNone;
std::atomic_int subscriptions;
static CameraSource* instance;
2015-05-14 10:46:28 +08:00
};
#endif // CAMERA_H