File: OniStream.h

package info (click to toggle)
openni2 2.2.0.33%2Bdfsg-11
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 22,216 kB
  • sloc: cpp: 111,197; ansic: 35,511; sh: 10,542; python: 1,313; java: 952; makefile: 575; xml: 12
file content (150 lines) | stat: -rw-r--r-- 5,353 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*****************************************************************************
*                                                                            *
*  OpenNI 2.x Alpha                                                          *
*  Copyright (C) 2012 PrimeSense Ltd.                                        *
*                                                                            *
*  This file is part of OpenNI.                                              *
*                                                                            *
*  Licensed under the Apache License, Version 2.0 (the "License");           *
*  you may not use this file except in compliance with the License.          *
*  You may obtain a copy of the License at                                   *
*                                                                            *
*      http://www.apache.org/licenses/LICENSE-2.0                            *
*                                                                            *
*  Unless required by applicable law or agreed to in writing, software       *
*  distributed under the License is distributed on an "AS IS" BASIS,         *
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  *
*  See the License for the specific language governing permissions and       *
*  limitations under the License.                                            *
*                                                                            *
*****************************************************************************/
#ifndef _ONI_IMPL_STREAM_H_
#define _ONI_IMPL_STREAM_H_

#include "OniDriverHandler.h"
#include "OniCommon.h"
#include "OniFrameHolder.h"
#include "OniFrameManager.h"
#include "OniSensor.h"
#include "XnEvent.h"
#include "XnErrorLogger.h"
#include "XnHash.h"
#include "XnLockable.h"

ONI_NAMESPACE_IMPLEMENTATION_BEGIN

class Device;
class FrameHolder;
class Recorder;

class VideoStream
{
public:
	VideoStream(Sensor* pSensor, const OniSensorInfo* pSensorInfo, Device& device, const DriverHandler& driverHandler, FrameManager& frameManager, xnl::ErrorLogger& errorLogger);
	virtual ~VideoStream();

	typedef void (XN_CALLBACK_TYPE* NewFrameFuncPtr)(void* pCookie);

	void setNewFrameCallback(NewFrameFuncPtr callback, void* pCookie) { m_newFrameCallback = callback; m_newFrameCookie = pCookie; }

	OniStatus start();
	void stop();
	OniBool isStarted();

	OniStatus readFrame(OniFrame** pFrame);
	
	OniFrame* peekFrame();
	void lockFrame();
	void unlockFrame();

	OniStatus setProperty(int propertyId, const void* data, int dataSize);
	OniStatus getProperty(int propertyId, void* data, int* pDataSize);
	OniBool isPropertySupported(int propertyId);
	OniStatus invoke(int commandId, void* data, int dataSize);
	OniBool isCommandSupported(int commandId);
	void notifyAllProperties();

	OniStatus registerNewFrameCallback(OniGeneralCallback handler, void* pCookie, XnCallbackHandle* pHandle);
	void unregisterNewFrameCallback(XnCallbackHandle handle);

	const OniSensorInfo* getSensorInfo() const;

	Device& getDevice();

	void* getHandle() const;

	void setFrameHolder(FrameHolder* pFrameHolder);
	FrameHolder* getFrameHolder();

	void raiseNewFrameEvent();
	XnStatus waitForNewFrameEvent();

    OniStatus addRecorder(Recorder& aRecorder);
    OniStatus removeRecorder(Recorder& aRecorder);

	OniStatus setFrameBufferAllocator(OniFrameAllocBufferCallback alloc, OniFrameFreeBufferCallback free, void* pCookie);

	OniStatus convertDepthToWorldCoordinates(float depthX, float depthY, float depthZ, float* pWorldX, float* pWorldY, float* pWorldZ);
	OniStatus convertWorldToDepthCoordinates(float worldX, float worldY, float worldZ, float* pDepthX, float* pDepthY, float* pDepthZ);
	OniStatus convertDepthToColorCoordinates(VideoStream* colorStream, int depthX, int depthY, OniDepthPixel depthZ, int* pColorX, int* pColorY);

	int getRequiredFrameSize();

protected:
	XN_EVENT_HANDLE m_newFrameInternalEvent;
	XN_EVENT_HANDLE m_newFrameInternalEventForFrameHolder;

	xnl::ErrorLogger& m_errorLogger;

private:
	XN_DISABLE_COPY_AND_ASSIGN(VideoStream)

	FrameHolder* m_pFrameHolder;

	xnl::EventNoArgs m_newFrameEvent;
	XN_THREAD_HANDLE m_newFrameThread;

	OniSensorInfo* m_pSensorInfo;

	static XN_THREAD_PROC newFrameThread(XN_THREAD_PARAM pThreadParam);
	void newFrameThreadMainloop();
	bool m_running;

	static void ONI_CALLBACK_TYPE stream_NewFrame(OniFrame* pFrame, void* pCookie);
	static void ONI_CALLBACK_TYPE stream_PropertyChanged(void* streamHandle, int propertyId, const void* data, int dataSize, void* pCookie);

	void refreshWorldConversionCache();

	NewFrameFuncPtr m_newFrameCallback;
	void* m_newFrameCookie;

	Device& m_device;
	const DriverHandler& m_driverHandler;
	FrameManager& m_frameManager;
	Sensor* m_pSensor;

	XnCallbackHandle m_hNewFrameEvent;

	OniBool m_started;

    // XnLib does not provide a set container. I decided to use this odd
    // Recorder* -> Recorder* map to mimic a set.
    typedef xnl::Lockable<xnl::Hash<Recorder*, Recorder*> > Recorders;
    Recorders m_recorders;

	struct WorldConversionCache
	{
		float xzFactor;
		float yzFactor;
		float coeffX;
		float coeffY;
		int resolutionX;
		int resolutionY;
		int halfResX;
		int halfResY;
	} m_worldConvertCache;
};

ONI_NAMESPACE_IMPLEMENTATION_END

#endif // _ONI_IMPL_STREAM_H_