Argus Camera Sample Argus Camera Sample

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
StreamConsumer.h
Go to the documentation of this file.
1 /*
2 * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of NVIDIA CORPORATION nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
24 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #ifndef STREAM_CONSUMER_H
30 #define STREAM_CONSUMER_H
31
32 #include <EGL/egl.h>
33 #include <EGL/eglext.h>
34
35 #include "Thread.h"
36 #include "GLContext.h"
37
38 // Workaround for Bug 1736040, Jira CA-167
39 // Root cause is that the StreamConsumer updates the stream texture with eglStreamConsumerAcquire
40 // while the Composer is using the same texture to render. Although the EGL spec says that
41 // textures are 'latched', e.g. updated atomically occasionally the texture is undefined (content
42 // is zero, rendered as green in YUV color space) occasionally.
43 // The workaround uses a mutex to make sure that eglStreamConsumerAcquire is called only when the
44 // Composer is *not* using the texture. The StreamConsumer polls the EGL stream and takes the
45 // mutex if a new frame is available. It latches that frame and releases the mutex. The Composer
46 // holds the mutex while using the stream texture to render.
47 #define WAR_EGL_STREAM_RACE
48
49 #ifdef WAR_EGL_STREAM_RACE
50 #include "Mutex.h"
51 #endif // WAR_EGL_STREAM_RACE
52
53 namespace ArgusSamples
54 {
55
56 /**
57 * This class handles creation of a thread acquiring from an EGL stream
58 */
59 class StreamConsumer : public Thread
60 {
61 public:
62 explicit StreamConsumer(EGLStreamKHR eglStream);
63 ~StreamConsumer();
64
65 bool initialize();
66 bool shutdown();
67
68 bool isEGLStream(EGLStreamKHR eglStream) const;
69 uint32_t getStreamTextureID() const;
70
71 bool setStreamAspectRatio(float aspectRatio);
72 float getStreamAspectRatio() const;
73
74 #ifdef WAR_EGL_STREAM_RACE
75 Mutex& getStreamTextureMutex();
76 #endif // WAR_EGL_STREAM_RACE
77
78 private:
79 GLContext m_context;
80 EGLStreamKHR m_eglStream;
81 EGLint m_streamState;
82 uint32_t m_streamTexture;
83 float m_aspectRatio; ///< aspect ration of the images transported by the stream
84 #ifdef WAR_EGL_STREAM_RACE
85 EGLSyncKHR m_sync; ///< stream sync object
86 Mutex m_mutex; ///< to protect access of the stream texture
87 #endif // WAR_EGL_STREAM_RACE
88
89 /**
90 * Hide default constructor
91 */
92 StreamConsumer();
93
94 virtual bool threadInitialize();
95 virtual bool threadExecute();
96 virtual bool threadShutdown();
97 };
98
99 }; // namespace ArgusSamples
100
101 #endif // STREAM_CONSUMER_H