renderer.h 3.98 KB
Newer Older
1
/****************************************************************************
Sébastien Blin's avatar
Sébastien Blin committed
2
 *    Copyright (C) 2012-2019 Savoir-faire Linux Inc.                          *
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
 *   Author : Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com> *
 *                                                                          *
 *   This library is free software; you can redistribute it and/or          *
 *   modify it under the terms of the GNU Lesser General Public             *
 *   License as published by the Free Software Foundation; either           *
 *   version 2.1 of the License, or (at your option) any later version.     *
 *                                                                          *
 *   This library 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      *
 *   Lesser General Public License for more details.                        *
 *                                                                          *
 *   You should have received a copy of the GNU General Public License      *
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.  *
 ***************************************************************************/
Guillaume Roguez's avatar
Guillaume Roguez committed
18
#pragma once
Emmanuel Lepage's avatar
Emmanuel Lepage committed
19

20

Emmanuel Lepage's avatar
Emmanuel Lepage committed
21 22
//Base
#include <QtCore/QObject>
23
#include "api/newvideo.h"
24
#include <typedefs.h>
Emmanuel Lepage's avatar
Emmanuel Lepage committed
25

26 27 28 29 30
// Std
#include <memory>
#include <vector>
#include <cstdint>

Emmanuel Lepage's avatar
Emmanuel Lepage committed
31
//Qt
32
class QMutex;
Kateryna Kostiuk's avatar
Kateryna Kostiuk committed
33
struct AVFrame;
Emmanuel Lepage's avatar
Emmanuel Lepage committed
34

35

36 37
namespace Video {

38 39
class RendererPrivate;
class ShmRendererPrivate;
40
class ShmRenderer;
41
class DirectRendererPrivate;
42
class DirectRenderer;
43

44 45 46 47 48 49 50 51
/**
 * This class is used by Renderer class to expose video data frame
 * that could be owned by instances of this class or shared.
 * If an instance carries data, "storage.size()" is greater than 0
 * and equals to "size", "ptr" is equals to "storage.data()".
 * If shared data is carried, only "ptr" and "size" are set.
 */
struct Frame {
52 53 54
   uint8_t*             ptr     { nullptr };
   std::size_t          size    { 0       };
   std::vector<uint8_t> storage {         };
55 56 57
   // Next variables are currently used with DirectRenderer only
   unsigned int         height  { 0       };
   unsigned int         width   { 0       };
58 59
};

60 61 62 63
/**
 * This class provide a rendering object to be used by clients
 * to get the video content. This object is not intended to be
 * extended outside of the LibRingClient.
64
 *
65 66
 * Each platform transparently provide its own implementation.
 */
67 68
class LIB_EXPORT Renderer : public QObject
{
69 70
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
71
   Q_OBJECT
72 73
#pragma GCC diagnostic pop

74 75 76 77 78
   friend class Video::ShmRendererPrivate   ;
   friend class Video::ShmRenderer          ;
   friend class Video::DirectRendererPrivate;
   friend class Video::DirectRenderer       ;
   friend class VideoRendererManagerPrivate ;
79 80

public:
81 82 83 84 85 86 87 88 89 90

   /**
    * Each platform may have its preferred color space. To be able to use a
    * client on multiple platforms, they need to check the colorspace.
    */
   enum class ColorSpace {
      BGRA , /*!< 32bit BLUE  GREEN RED ALPHA */
      RGBA , /*!< 32bit ALPHA GREEN RED BLUE  */
   };

91 92 93 94 95
   //Constructor
   Renderer (const QByteArray& id,  const QSize& res);
   virtual ~Renderer();

   //Getters
96
   virtual bool       isRendering     () const;
97
   virtual lrc::api::video::Frame currentFrame    () const = 0;
98 99 100
   virtual QSize      size            () const;
   virtual QMutex*    mutex           () const;
   virtual ColorSpace colorSpace      () const = 0;
101
#if defined(ENABLE_LIBWRAP)
Kateryna Kostiuk's avatar
Kateryna Kostiuk committed
102
   virtual std::unique_ptr<AVFrame, void(*)(AVFrame*)> currentAVFrame() const = 0;
103
#endif
104
   void setSize(const QSize& size) const;
Emmanuel Lepage's avatar
Emmanuel Lepage committed
105

106
Q_SIGNALS:
107
   void frameUpdated(); // Emitted when a new frame is ready
108 109 110 111 112 113 114 115
   void stopped     ();
   void started     ();

public Q_SLOTS:
   virtual void startRendering() = 0;
   virtual void stopRendering () = 0;

private:
116
   RendererPrivate* d_ptr;
117
   Q_DECLARE_PRIVATE(Renderer)
Emmanuel Lepage's avatar
Emmanuel Lepage committed
118 119 120

};

121
}