qTox  Version: nightly | Commit: bc751c8e1cac455f9690654fcfe0f560d2d7dfdd
videosurface.h
Go to the documentation of this file.
1 /*
2  Copyright © 2014-2019 by The qTox Project Contributors
3 
4  This file is part of qTox, a Qt-based graphical interface for Tox.
5 
6  qTox is libre software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  qTox is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with qTox. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #pragma once
21 
22 #include "src/video/videosource.h"
23 #include <QWidget>
24 #include <atomic>
25 #include <memory>
26 
27 class VideoSurface : public QWidget
28 {
29  Q_OBJECT
30 
31 public:
32  VideoSurface(const QPixmap& avatar, QWidget* parent = nullptr, bool expanding = false);
33  VideoSurface(const QPixmap& avatar, VideoSource* source, QWidget* parent = nullptr);
34  ~VideoSurface();
35 
36  bool isExpanding() const;
37  void setSource(VideoSource* src);
38  QRect getBoundingRect() const;
39  float getRatio() const;
40  void setAvatar(const QPixmap& pixmap);
41  QPixmap getAvatar() const;
42 
43 signals:
44  void ratioChanged();
45  void boundaryChanged();
46 
47 protected:
48  void subscribe();
49  void unsubscribe();
50 
51  void paintEvent(QPaintEvent* event) final;
52  void resizeEvent(QResizeEvent* event) final;
53  void showEvent(QShowEvent* event) final;
54 
55 private slots:
56  void onNewFrameAvailable(const std::shared_ptr<VideoFrame>& newFrame);
57  void onSourceStopped();
58 
59 private:
60  void recalulateBounds();
61  void lock();
62  void unlock();
63 
64  QRect boundingRect;
66  std::shared_ptr<VideoFrame> lastFrame;
67  std::atomic_bool frameLock;
68  uint8_t hasSubscribed;
69  QPixmap avatar;
70  float ratio;
71  bool expanding;
72 };
VideoSurface::frameLock
std::atomic_bool frameLock
Fast lock for lastFrame.
Definition: videosurface.h:67
VideoSurface::VideoSurface
VideoSurface(const QPixmap &avatar, QWidget *parent=nullptr, bool expanding=false)
Definition: videosurface.cpp:43
VideoSurface::setAvatar
void setAvatar(const QPixmap &pixmap)
Definition: videosurface.cpp:100
VideoSource
An abstract source of video frames.
Definition: videosource.h:29
VideoSurface::boundingRect
QRect boundingRect
Definition: videosurface.h:64
VideoSurface::onNewFrameAvailable
void onNewFrameAvailable(const std::shared_ptr< VideoFrame > &newFrame)
Definition: videosurface.cpp:142
VideoSurface::getAvatar
QPixmap getAvatar() const
Definition: videosurface.cpp:106
VideoSurface::getBoundingRect
QRect getBoundingRect() const
Definition: videosurface.cpp:88
VideoSurface::resizeEvent
void resizeEvent(QResizeEvent *event) final
Definition: videosurface.cpp:195
VideoSurface::unsubscribe
void unsubscribe()
Definition: videosurface.cpp:120
VideoSurface::showEvent
void showEvent(QShowEvent *event) final
Definition: videosurface.cpp:202
VideoSurface::isExpanding
bool isExpanding() const
Definition: videosurface.cpp:66
VideoSurface::source
VideoSource * source
Definition: videosurface.h:65
VideoSurface::ratio
float ratio
Definition: videosurface.h:70
VideoSurface::lastFrame
std::shared_ptr< VideoFrame > lastFrame
Definition: videosurface.h:66
VideoSurface::unlock
void unlock()
Definition: videosurface.cpp:239
VideoSurface::avatar
QPixmap avatar
Definition: videosurface.h:69
VideoSurface::~VideoSurface
~VideoSurface()
Definition: videosurface.cpp:61
VideoSurface::recalulateBounds
void recalulateBounds()
Definition: videosurface.cpp:208
VideoSurface::getRatio
float getRatio() const
Definition: videosurface.cpp:95
VideoSurface::onSourceStopped
void onSourceStopped()
Definition: videosurface.cpp:163
VideoSurface::setSource
void setSource(VideoSource *src)
Update source.
Definition: videosurface.cpp:78
VideoSurface::subscribe
void subscribe()
Definition: videosurface.cpp:111
VideoSurface::expanding
bool expanding
Definition: videosurface.h:71
VideoSurface::ratioChanged
void ratioChanged()
VideoSurface::boundaryChanged
void boundaryChanged()
VideoSurface::hasSubscribed
uint8_t hasSubscribed
Definition: videosurface.h:68
VideoSurface::paintEvent
void paintEvent(QPaintEvent *event) final
Definition: videosurface.cpp:170
VideoSurface
Definition: videosurface.h:27
videosource.h
VideoSurface::lock
void lock()
Definition: videosurface.cpp:231