2015-05-14 10:46:28 +08:00
|
|
|
/*
|
2018-04-13 04:02:28 +08:00
|
|
|
Copyright © 2015-2018 by The qTox Project Contributors
|
2015-06-06 09:40:08 +08:00
|
|
|
|
2015-05-14 10:46:28 +08:00
|
|
|
This file is part of qTox, a Qt-based graphical interface for Tox.
|
|
|
|
|
2015-06-06 09:40:08 +08:00
|
|
|
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.
|
2015-06-06 09:40:08 +08:00
|
|
|
|
|
|
|
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
|
2015-06-06 09:40:08 +08:00
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2015-05-14 10:46:28 +08:00
|
|
|
|
2015-06-06 09:40:08 +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
|
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
#include "src/video/videomode.h"
|
|
|
|
#include "src/video/videosource.h"
|
|
|
|
#include <QFuture>
|
2015-05-14 10:46:28 +08:00
|
|
|
#include <QHash>
|
2017-02-26 19:52:45 +08:00
|
|
|
#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-10-11 14:38:44 +08:00
|
|
|
|
2015-05-14 10:46:28 +08:00
|
|
|
public:
|
2015-06-26 23:38:53 +08:00
|
|
|
static CameraSource& getInstance();
|
2015-06-27 01:04:53 +08:00
|
|
|
static void destroyInstance();
|
2017-06-26 17:57:46 +08:00
|
|
|
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;
|
|
|
|
|
2017-06-26 19:05:26 +08:00
|
|
|
public slots:
|
|
|
|
void setupDevice(const QString& deviceName, const VideoMode& mode);
|
|
|
|
|
2015-07-22 02:38:43 +08:00
|
|
|
signals:
|
|
|
|
void deviceOpened();
|
2017-06-26 18:51:44 +08:00
|
|
|
void openFailed();
|
2015-07-22 02:38:43 +08:00
|
|
|
|
2015-05-14 10:46:28 +08:00
|
|
|
private:
|
2015-06-26 23:38:53 +08:00
|
|
|
CameraSource();
|
|
|
|
~CameraSource();
|
2015-05-14 10:46:28 +08:00
|
|
|
void stream();
|
2017-06-26 19:05:26 +08:00
|
|
|
|
|
|
|
private slots:
|
2017-06-26 18:51:44 +08:00
|
|
|
void openDevice();
|
2016-07-27 06:18:57 +08:00
|
|
|
void closeDevice();
|
2015-05-14 10:46:28 +08:00
|
|
|
|
|
|
|
private:
|
2016-07-27 06:18:57 +08:00
|
|
|
QFuture<void> streamFuture;
|
2017-06-26 18:58:22 +08:00
|
|
|
QThread* deviceThread;
|
|
|
|
|
2016-07-27 06:18:57 +08:00
|
|
|
QString deviceName;
|
|
|
|
CameraDevice* device;
|
|
|
|
VideoMode mode;
|
2017-02-16 07:38:14 +08:00
|
|
|
AVCodecContext* cctx;
|
|
|
|
// TODO: Remove when ffmpeg version will be bumped to the 3.1.0
|
|
|
|
AVCodecContext* cctxOrig;
|
2016-07-27 06:18:57 +08:00
|
|
|
int videoStreamIndex;
|
2017-06-26 18:58:22 +08:00
|
|
|
|
2017-06-26 19:00:29 +08:00
|
|
|
QReadWriteLock deviceMutex;
|
2016-08-04 23:18:37 +08:00
|
|
|
QReadWriteLock streamMutex;
|
2017-06-26 17:57:46 +08:00
|
|
|
|
|
|
|
std::atomic_bool _isNone;
|
2016-07-27 06:18:57 +08:00
|
|
|
std::atomic_int subscriptions;
|
2015-06-26 23:38:53 +08:00
|
|
|
|
|
|
|
static CameraSource* instance;
|
2015-05-14 10:46:28 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CAMERA_H
|