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

80 lines
2.0 KiB
C
Raw Normal View History

2015-05-14 10:46:28 +08:00
/*
Copyright © 2015 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 open();
void open(const QString& deviceName);
2017-06-12 02:48:44 +08:00
void open(const QString& deviceName, const VideoMode& mode);
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;
signals:
void deviceOpened();
2015-05-14 10:46:28 +08:00
private:
CameraSource();
~CameraSource();
2015-05-14 10:46:28 +08:00
void stream();
bool openDevice();
void closeDevice();
2015-05-14 10:46:28 +08:00
private:
QFuture<void> streamFuture;
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;
QReadWriteLock streamMutex;
2015-09-28 07:04:39 +08:00
std::atomic_bool _isOpen;
std::atomic_bool streamBlocker;
std::atomic_int subscriptions;
static CameraSource* instance;
2015-05-14 10:46:28 +08:00
};
#endif // CAMERA_H