Argus Camera Sample
Argus Camera Sample
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
EventThread.cpp
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 #include "EventThread.h"
30 #include "Dispatcher.h"
31 #include "Util.h"
32 #include <Argus/Ext/DebugCaptureMetadata.h>
33 
34 namespace ArgusSamples {
35 
36 EventThread::EventThread(Argus::CaptureSession *session,
37  Argus::EventQueue *eventQueue,
38  PerfTracker *perftracker)
39  : m_session(session)
40  , m_eventQueue(eventQueue)
41  , m_perfTracker(perftracker)
42 {
43 }
44 
46 {
47 }
48 
50 {
51  return true;
52 }
53 
55 {
56  Dispatcher &dispatcher = Dispatcher::getInstance();
57 
58  // wait for events (use a time out to allow the thread to be shutdown even if there are no
59  // new events)
60  PROPAGATE_ERROR(dispatcher.waitForEvents(m_eventQueue.get(), TimeValue::fromMSec(100),
61  m_session));
62 
63  Argus::IEventQueue *iEventQueue =
64  Argus::interface_cast<Argus::IEventQueue>(m_eventQueue.get());
65  if (!iEventQueue)
66  ORIGINATE_ERROR("Failed to get iEventQueue");
67 
68  for (uint32_t i = 0; i < iEventQueue->getSize(); i++)
69  {
70  const Argus::Event *event = iEventQueue->getEvent(i);
71  const Argus::IEvent *ievent = Argus::interface_cast<const Argus::IEvent>(event);
72  if (!ievent)
73  ORIGINATE_ERROR("Failed to get ievent interface");
74 
75  if (ievent->getEventType() == Argus::EVENT_TYPE_CAPTURE_COMPLETE)
76  {
78  uint64_t latencyMs = 0;
79 
80  const Argus::IEventCaptureComplete *ieventCaptureComplete
81  = Argus::interface_cast<const Argus::IEventCaptureComplete>(event);
82  const Argus::CaptureMetadata *metaData = ieventCaptureComplete->getMetadata();
83  if (metaData)
84  {
85  const Argus::ICaptureMetadata *iCaptureMeta =
86  Argus::interface_cast<const Argus::ICaptureMetadata>(metaData);
87  if (iCaptureMeta)
88  {
89  latencyMs = ievent->getTime()/1000 - iCaptureMeta->getSensorTimestamp()/1000000;
91  }
92 
93  const Argus::Ext::IDebugCaptureMetadata *iDebugCaptureMeta =
94  Argus::interface_cast<const Argus::Ext::IDebugCaptureMetadata>(metaData);
95  if (iDebugCaptureMeta)
96  {
97  uint64_t currentFrameCount = iDebugCaptureMeta->getHwFrameCount();
98  m_perfTracker->onEvent(FRAME_COUNT, currentFrameCount);
99  }
100 
101  }
102  }
103  }
104 
105  return true;
106 }
107 
109 {
110  return true;
111 }
112 
113 }; // namespace ArgusSamples