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

feat(video): adds an ID parameter to the VideoSource class

This commit is contained in:
initramfs 2016-05-01 12:36:32 +08:00 committed by initramfs
parent 57f38e281b
commit 4ac20c7b46
No known key found for this signature in database
GPG Key ID: 78B8BDF87E9EF0AF
3 changed files with 36 additions and 0 deletions

View File

@ -414,6 +414,7 @@ SOURCES += \
src/persistence/db/rawdatabase.cpp \ src/persistence/db/rawdatabase.cpp \
src/persistence/history.cpp \ src/persistence/history.cpp \
src/video/videoframe.cpp \ src/video/videoframe.cpp \
src/video/videosource.cpp \
src/video/cameradevice.cpp \ src/video/cameradevice.cpp \
src/video/camerasource.cpp \ src/video/camerasource.cpp \
src/video/corevideosource.cpp \ src/video/corevideosource.cpp \

23
src/video/videosource.cpp Normal file
View File

@ -0,0 +1,23 @@
/*
Copyright © 2016 by The qTox Project
This file is part of qTox, a Qt-based graphical interface for Tox.
qTox is libre 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 3 of the License, or
(at your option) any later version.
qTox 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 qTox. If not, see <http://www.gnu.org/licenses/>.
*/
#include "videosource.h"
// Initialize sourceIDs to 0
VideoSource::AtomicIDType VideoSource::sourceIDs {0};

View File

@ -21,6 +21,8 @@
#define VIDEOSOURCE_H #define VIDEOSOURCE_H
#include <QObject> #include <QObject>
#include <atomic>
#include <memory> #include <memory>
class VideoFrame; class VideoFrame;
@ -35,7 +37,12 @@ class VideoSource : public QObject
{ {
Q_OBJECT Q_OBJECT
using IDType = std::uint_fast64_t;
using AtomicIDType = std::atomic_uint_fast64_t;
public: public:
VideoSource() : id(sourceIDs.fetch_add(std::memory_order_relaxed)){}
virtual ~VideoSource() = default; virtual ~VideoSource() = default;
/** /**
If subscribe sucessfully opens the source, it will start emitting frameAvailable signals. If subscribe sucessfully opens the source, it will start emitting frameAvailable signals.
@ -46,6 +53,8 @@ public:
*/ */
virtual void unsubscribe() = 0; virtual void unsubscribe() = 0;
/// ID of this VideoSource
const IDType id;
signals: signals:
/** /**
Emitted when new frame available to use. Emitted when new frame available to use.
@ -57,6 +66,9 @@ signals:
but might restart sending frames again later but might restart sending frames again later
*/ */
void sourceStopped(); void sourceStopped();
private:
/// Used to manage a global ID for all VideoSources
static AtomicIDType sourceIDs;
}; };
#endif // VIDEOSOURCE_H #endif // VIDEOSOURCE_H