2015-05-14 10:46:28 +08:00
|
|
|
/*
|
2016-11-28 21:33:38 +08:00
|
|
|
Copyright © 2015 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();
|
2015-06-26 23:38:53 +08:00
|
|
|
void open();
|
2016-04-14 19:42:16 +08:00
|
|
|
void open(const QString& deviceName);
|
2017-06-12 02:48:44 +08:00
|
|
|
void open(const QString& deviceName, const VideoMode& mode);
|
2016-07-27 06:18:57 +08:00
|
|
|
void close();
|
2015-09-28 07:04:39 +08:00
|
|
|
bool isOpen();
|
2015-05-14 10:46:28 +08:00
|
|
|
|
|
|
|
// VideoSource interface
|
|
|
|
virtual bool subscribe() override;
|
|
|
|
virtual void unsubscribe() override;
|
|
|
|
|
2015-07-22 02:38:43 +08:00
|
|
|
signals:
|
|
|
|
void deviceOpened();
|
|
|
|
|
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();
|
2016-07-27 06:18:57 +08:00
|
|
|
bool openDevice();
|
|
|
|
void closeDevice();
|
2015-05-14 10:46:28 +08:00
|
|
|
|
|
|
|
private:
|
2016-07-27 06:18:57 +08:00
|
|
|
QFuture<void> streamFuture;
|
|
|
|
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;
|
2016-08-04 23:18:37 +08:00
|
|
|
QReadWriteLock streamMutex;
|
2015-09-28 07:04:39 +08:00
|
|
|
std::atomic_bool _isOpen;
|
2016-07-27 06:18:57 +08:00
|
|
|
std::atomic_bool streamBlocker;
|
|
|
|
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
|