diff --git a/qtox.pro b/qtox.pro index 1327fd25a..ef53ee79b 100644 --- a/qtox.pro +++ b/qtox.pro @@ -414,6 +414,7 @@ SOURCES += \ src/persistence/db/rawdatabase.cpp \ src/persistence/history.cpp \ src/video/videoframe.cpp \ + src/video/videosource.cpp \ src/video/cameradevice.cpp \ src/video/camerasource.cpp \ src/video/corevideosource.cpp \ diff --git a/src/video/videosource.cpp b/src/video/videosource.cpp new file mode 100644 index 000000000..9f59acf32 --- /dev/null +++ b/src/video/videosource.cpp @@ -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 . +*/ + +#include "videosource.h" + +// Initialize sourceIDs to 0 +VideoSource::AtomicIDType VideoSource::sourceIDs {0}; diff --git a/src/video/videosource.h b/src/video/videosource.h index 5ae188577..618907054 100644 --- a/src/video/videosource.h +++ b/src/video/videosource.h @@ -21,6 +21,8 @@ #define VIDEOSOURCE_H #include + +#include #include class VideoFrame; @@ -35,7 +37,12 @@ class VideoSource : public QObject { Q_OBJECT + using IDType = std::uint_fast64_t; + using AtomicIDType = std::atomic_uint_fast64_t; + public: + VideoSource() : id(sourceIDs.fetch_add(std::memory_order_relaxed)){} + virtual ~VideoSource() = default; /** If subscribe sucessfully opens the source, it will start emitting frameAvailable signals. @@ -46,6 +53,8 @@ public: */ virtual void unsubscribe() = 0; + /// ID of this VideoSource + const IDType id; signals: /** Emitted when new frame available to use. @@ -57,6 +66,9 @@ signals: but might restart sending frames again later */ void sourceStopped(); +private: + /// Used to manage a global ID for all VideoSources + static AtomicIDType sourceIDs; }; #endif // VIDEOSOURCE_H