/* * Copyright (c) 2016 - 2018, NVIDIA CORPORATION. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of NVIDIA CORPORATION nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "ArgusHelpers.h" #include "CommonOptions.h" #include "Error.h" #include "Thread.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "PreviewConsumer.h" using namespace Argus; using namespace EGLStream; // Extensions used by this demo #define EXTENSION_LIST(T) \ T( PFNEGLQUERYSTREAMKHRPROC, eglQueryStreamKHR ) \ T( PFNEGLQUERYSTREAMU64KHRPROC, eglQueryStreamu64KHR ) \ T( PFNEGLSTREAMCONSUMERACQUIREKHRPROC, eglStreamConsumerAcquireKHR ) \ T( PFNEGLSTREAMCONSUMERRELEASEKHRPROC, eglStreamConsumerReleaseKHR ) \ T( PFNEGLCREATESTREAMKHRPROC, eglCreateStreamKHR ) \ T( PFNEGLDESTROYSTREAMKHRPROC, eglDestroyStreamKHR ) \ T( PFNEGLSTREAMCONSUMERGLTEXTUREEXTERNALKHRPROC, \ eglStreamConsumerGLTextureExternalKHR ) \ T( PFNEGLGETSTREAMFILEDESCRIPTORKHRPROC, \ eglGetStreamFileDescriptorKHR ) \ T( PFNEGLCREATESTREAMFROMFILEDESCRIPTORKHRPROC, \ eglCreateStreamFromFileDescriptorKHR ) #define EXTLST_DECL(tx, x) static tx x = NULL; #define EXTLST_ENTRY(tx, x) { (extlst_fnptr_t *)&x, #x }, EXTENSION_LIST(EXTLST_DECL) typedef void (*extlst_fnptr_t)(void); static const struct { extlst_fnptr_t *fnptr; char const *name; } extensionList[] = { EXTENSION_LIST(EXTLST_ENTRY) }; namespace ArgusSamples { #ifdef ANDROID #define JPEG_PREFIX "/sdcard/DCIM/Argus_" #else #define JPEG_PREFIX "" #endif // Debug print macros. #define PRODUCER_PRINT(...) printf("PRODUCER: " __VA_ARGS__) #define CONSUMER_PRINT(...) printf("CONSUMER: " __VA_ARGS__) static const Rectangle DEFAULT_WINDOW_RECT(0, 0, 1920,1080); int connect_fd = -1; int send_fd = -1; EGLNativeFileDescriptorKHR fileDescriptor = EGL_NO_FILE_DESCRIPTOR_KHR; #define SOCK_PATH "/tmp/tegra_sw_egl_socket" /******************************************************************************* * FrameConsumer thread: * Creates a FrameConsumer object to read frames from the OutputStream, then * acquires and prints frame info from the IImage and IImage2D interfaces * while frames are presented. It will also write JPEG files to disk using the * IImageJPEG interface. ******************************************************************************/ class ConsumerThread : public Thread { public: explicit ConsumerThread(OutputStream* stream) : m_stream(stream) { } ~ConsumerThread() { } private: /** @name Thread methods */ /**@{*/ virtual bool threadInitialize(); virtual bool threadExecute(); virtual bool threadShutdown(); /**@}*/ OutputStream* m_stream; UniqueObj m_consumer; }; bool ConsumerThread::threadInitialize() { // Create the FrameConsumer. m_consumer = UniqueObj(FrameConsumer::create(m_stream)); if (!m_consumer) ORIGINATE_ERROR("Failed to create FrameConsumer"); return true; } bool ConsumerThread::threadExecute() { IEGLOutputStream *iStream = interface_cast(m_stream); IFrameConsumer *iFrameConsumer = interface_cast(m_consumer); // Wait until the producer has connected to the stream. CONSUMER_PRINT("Waiting until producer is connected...\n"); if (iStream->waitUntilConnected() != STATUS_OK) ORIGINATE_ERROR("Stream failed to connect."); CONSUMER_PRINT("Producer has connected; continuing.\n"); while (true) { UniqueObj frame(iFrameConsumer->acquireFrame()); if (!frame) break; // Use the IFrame interface to print out the frame number/timestamp, and // to provide access to the Image in the Frame. IFrame *iFrame = interface_cast