JeVois  1.20
JeVois Smart Embedded Machine Vision Toolkit
Share this page:
VideoDisplayGL.H
Go to the documentation of this file.
1 // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 //
3 // JeVois Smart Embedded Machine Vision Toolkit - Copyright (C) 2020 by Laurent Itti, the University of Southern
4 // California (USC), and iLab at USC. See http://iLab.usc.edu and http://jevois.org for information about this project.
5 //
6 // This file is part of the JeVois Smart Embedded Machine Vision Toolkit. This program is free software; you can
7 // redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software
8 // Foundation, version 2. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
10 // License for more details. You should have received a copy of the GNU General Public License along with this program;
11 // if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
12 //
13 // Contact information: Laurent Itti - 3641 Watt Way, HNB-07A - Los Angeles, CA 90089-2520 - USA.
14 // Tel: +1 213 740 3527 - itti@pollux.usc.edu - http://iLab.usc.edu - http://jevois.org
15 // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
16 /*! \file */
17 
18 #pragma once
19 
20 // This is only available on JeVoisPro
21 #ifdef JEVOIS_PRO
22 
24 #include <jevois/Core/VideoBuf.H>
26 #include <jevois/GPU/GPUimage.H>
29 #include <vector>
30 #include <atomic>
31 
32 namespace jevois
33 {
34  //! Video output to local screen
35  /*! This class provides accelerated OpenGL-ES display on JeVois-Pro platform. It only works on JeVois-Pro and creates
36  fatal errors on other host or platform configs. Images are simply displayed on the local screen using
37  OpenGL-ES.
38 
39  Here is the basic theory of operation:
40 
41  - When running on host, we open an X11 window; on platform, we instead use fbdev.
42  - When the first video frame arrives, we then initialize OpenGL and create 2 triangles that will be rendered in
43  the whole window. The reason for this is to avoid threading issues (so OpenGL is initialized in the same thread
44  as rendering calls will be made). We also initialize a texture of the same size as the incoming image. We
45  finally create a surface of same size as the window or fbdev. We then load a compile shaders to render our
46  texture into our surface.
47  - On every frame, we just update the texture's pixel location and render the scene.
48 
49  \ingroup core */
50  class VideoDisplayGL : public VideoOutput
51  {
52  public:
53  //! Constructor
54  VideoDisplayGL(size_t nbufs = 2);
55 
56  //! Virtual destructor for safe inheritance
57  virtual ~VideoDisplayGL();
58 
59  //! Set the video format and frame rate, allocate the buffers
60  virtual void setFormat(VideoMapping const & m) override;
61 
62  //! Get a pre-allocated image so that we can fill the pixel data and later send out using send()
63  virtual void get(RawImage & img) override;
64 
65  //! Send an image out to display
66  virtual void send(RawImage const & img) override;
67 
68  //! Start streaming
69  virtual void streamOn() override;
70 
71  //! Abort streaming
72  /*! This only cancels future get() and done() calls, one should still call streamOff() to turn off streaming. */
73  virtual void abortStream() override;
74 
75  //! Stop streaming
76  virtual void streamOff() override;
77 
78  protected:
79  std::vector<std::shared_ptr<VideoBuf> > itsBuffers;
82 
83 #ifdef JEVOIS_PLATFORM_PRO
85 #else
86  VideoDisplayBackendX11 itsBackend;
87 #endif
88  std::atomic<bool> itsStreaming;
89  };
90 }
91 
92 #endif // JEVOIS_PRO
jevois::VideoDisplayGL::streamOff
virtual void streamOff() override
Stop streaming.
Definition: VideoDisplayGL.C:141
jevois::VideoDisplayGL::streamOn
virtual void streamOn() override
Start streaming.
Definition: VideoDisplayGL.C:133
GPUimage.H
jevois::VideoDisplayGL::itsBackend
VideoDisplayBackendMALI itsBackend
Definition: VideoDisplayGL.H:84
jevois::VideoDisplayGL
Video output to local screen.
Definition: VideoDisplayGL.H:50
jevois::GPUimage
Class to hold a GPUtexture, GPUprogram, and other data associated with rendering an image in OpenGL.
Definition: GPUimage.H:38
BoundedBuffer.H
jevois::VideoOutput
Base class for video output. Gadget, MovieOutput, VideoDisplay, and VideoOutputNone derive from it.
Definition: VideoOutput.H:27
VideoBuf.H
jevois::BoundedBuffer
Thread-safe synchronized producer/consumer queue.
Definition: BoundedBuffer.H:37
jevois::RawImage
A raw image as coming from a V4L2 Camera and/or being sent out to a USB Gadget.
Definition: RawImage.H:110
jevois::VideoDisplayBackendMALI
Backend for VideoDisplay on JeVois-Pro host using MALI.
Definition: VideoDisplayBackendMALI.H:29
jevois::VideoDisplayGL::~VideoDisplayGL
virtual ~VideoDisplayGL()
Virtual destructor for safe inheritance.
Definition: VideoDisplayGL.C:63
jevois::VideoDisplayGL::itsStreaming
std::atomic< bool > itsStreaming
Definition: VideoDisplayGL.H:88
jevois::VideoDisplayGL::VideoDisplayGL
VideoDisplayGL(size_t nbufs=2)
Constructor.
Definition: VideoDisplayGL.C:27
jevois
Definition: Concepts.dox:1
VideoDisplayBackendX11.H
VideoDisplayBackendMALI.H
jevois::VideoDisplayGL::itsImage
GPUimage itsImage
Definition: VideoDisplayGL.H:81
jevois::VideoDisplayGL::abortStream
virtual void abortStream() override
Abort streaming.
Definition: VideoDisplayGL.C:137
jevois::VideoDisplayGL::get
virtual void get(RawImage &img) override
Get a pre-allocated image so that we can fill the pixel data and later send out using send()
Definition: VideoDisplayGL.C:76
jevois::VideoDisplayGL::itsBuffers
std::vector< std::shared_ptr< VideoBuf > > itsBuffers
Definition: VideoDisplayGL.H:79
jevois::VideoDisplayGL::send
virtual void send(RawImage const &img) override
Send an image out to display.
Definition: VideoDisplayGL.C:86
VideoOutput.H
jevois::VideoDisplayGL::itsImageQueue
BoundedBuffer< RawImage, BlockingBehavior::Block, BlockingBehavior::Block > itsImageQueue
Definition: VideoDisplayGL.H:80
jevois::VideoDisplayGL::setFormat
virtual void setFormat(VideoMapping const &m) override
Set the video format and frame rate, allocate the buffers.
Definition: VideoDisplayGL.C:32