C++ Samples
Demonstrates how to create a C++ application using the VideoXpert SDK
CppSamples::LiveStreaming::PtzOperationsHandler Class Reference

PtzOperationsHandler helps to converts the user inputs into operations like panning, tilting and zooming or their combinations. More...

#include <PtzOperationsHandler.h>

Public Member Functions

 PtzOperationsHandler (VxSdk::IVxPtzController *ptzControl)
 
 ~PtzOperationsHandler ()
 
bool DoOperation (char keyCode)
 Do media operation for given character. More...
 

Protected Member Functions

VxSdk::VxCollection< VxSdk::IVxPattern ** > GetPatterns () const
 
VxSdk::VxCollection< VxSdk::IVxPreset ** > GetPresets () const
 
VxSdk::VxResult::Value MoveDown () const
 
VxSdk::VxResult::Value MoveDownLeft () const
 
VxSdk::VxResult::Value MoveDownRight () const
 
VxSdk::VxResult::Value MoveLeft () const
 
VxSdk::VxResult::Value MoveUp () const
 
VxSdk::VxResult::Value MoveUpLeft () const
 
VxSdk::VxResult::Value MoveUpRight () const
 
VxSdk::VxResult::Value MoveRight () const
 
void TriggerPattern ()
 
void TriggerPreset ()
 
VxSdk::VxResult::Value ZoomIn () const
 
VxSdk::VxResult::Value ZoomOut () const
 

Private Attributes

VxSdk::IVxPtzController_ptzControl
 
bool _showResult
 

Detailed Description

PtzOperationsHandler helps to converts the user inputs into operations like panning, tilting and zooming or their combinations.

Definition at line 11 of file PtzOperationsHandler.h.

Constructor & Destructor Documentation

CppSamples::LiveStreaming::PtzOperationsHandler::PtzOperationsHandler ( VxSdk::IVxPtzController ptzControl)
inline
CppSamples::LiveStreaming::PtzOperationsHandler::~PtzOperationsHandler ( )
inline

Definition at line 14 of file PtzOperationsHandler.h.

14 { }

Member Function Documentation

bool CppSamples::LiveStreaming::PtzOperationsHandler::DoOperation ( char  keyCode)

Do media operation for given character.

Parameters
keyCodeCharacter code represent a command.
Returns
True if corresponding operation found for given keyCode. False otherwise.

Definition at line 9 of file PtzOperationsHandler.cpp.

9  {
10  // Verify the instance of PTZ controller.
11  if (_ptzControl == nullptr)
12  return false;
13 
14  // This will be false for non PTZ commands
15  bool isPtzCommandProcessed = true;
16  VxResult::Value ptzRes = VxResult::kUnknownError;
17  // Used to make exceptional cases for presets and patterns
18  _showResult = true;
19 
20  // 7 => Up Left
21  // 8 => Up
22  // 9 => UpRight
23  // 4 => Left
24  // 6 => Right
25  // 1 => Down Left
26  // 2 => Down
27  // 3 => Down Right
28  // + => Zoom In
29  // - => Zoom Out
30  // 0 => Show Presets
31  // . => Show Patterns
32  // P => Toggle between PAUSE and PLAY
33  // Keycode functions mentioned in CPPConsole::Utils::DisplayPlayerOptionsToConsole.
34  switch (keyCode) {
35  case '7':
36  ptzRes = MoveUpLeft();
37  break;
38  case '8':
39  ptzRes = MoveUp();
40  break;
41  case '9':
42  ptzRes = MoveUpRight();
43  break;
44  case '4':
45  ptzRes = MoveLeft();
46  break;
47  case '6':
48  ptzRes = MoveRight();
49  break;
50  case '1':
51  ptzRes = MoveDownLeft();
52  break;
53  case '2':
54  ptzRes = MoveDown();
55  break;
56  case '3':
57  ptzRes = MoveDownRight();
58  break;
59  case '+':
60  ptzRes = ZoomIn();
61  break;
62  case '-':
63  ptzRes = ZoomOut();
64  break;
65  case '0':
66  TriggerPreset();
67  break;
68  case '.':
70  break;
71  default:
72  // Not received a PTZ command keycode
73  isPtzCommandProcessed = false;
74  break;
75  }
76 
77  // Show message if command processed.
78  if (isPtzCommandProcessed && _showResult) {
79  if (ptzRes)
80  cout << "\n" << "PTZ command sent successfully.\n ";
81  else {
82  cout << "\n" << "PTZ command failed!!\n";
83  }
84  }
85 
86  return isPtzCommandProcessed;
87 }
VxCollection< IVxPattern ** > CppSamples::LiveStreaming::PtzOperationsHandler::GetPatterns ( ) const
protected

Definition at line 90 of file PtzOperationsHandler.cpp.

90  {
92  // Read the size of collection from system.
93  VxResult::Value result = _ptzControl->GetPatterns(patterns);
94  if (result == VxResult::kInsufficientSize) {
95  // Allocate memory for the requried collection.
96  patterns.collection = new IVxPattern*[patterns.collectionSize];
97  // Read the collection from system.
98  _ptzControl->GetPatterns(patterns);
99  }
100 
101  return patterns;
102 }
virtual VxResult::Value GetPatterns(VxCollection< IVxPattern ** > &patternCollection) const =0
VxCollection< IVxPreset ** > CppSamples::LiveStreaming::PtzOperationsHandler::GetPresets ( ) const
protected

Definition at line 105 of file PtzOperationsHandler.cpp.

105  {
107  // Read the size of collection from system.
108  VxResult::Value result = _ptzControl->GetPresets(presets);
109  if (result == VxResult::kInsufficientSize) {
110  // Allocate memory for the requried collection.
111  presets.collection = new IVxPreset*[presets.collectionSize];
112  // Read the collection from system.
113  _ptzControl->GetPresets(presets);
114  }
115 
116  return presets;
117 }
virtual VxResult::Value GetPresets(VxCollection< IVxPreset ** > &presetCollection) const =0
VxResult::Value CppSamples::LiveStreaming::PtzOperationsHandler::MoveDown ( ) const
protected

Definition at line 120 of file PtzOperationsHandler.cpp.

120  {
121  // Verify the instance of PTZ controller.
122  if (_ptzControl == nullptr)
123  return VxResult::kInvalidParameters;
124 
125  // Send PTZ Command : Down
126  cout << "\nSending PTZ Command:Down.";
127  return _ptzControl->ContinuousMove(0, -10, VxZoomDirection::kNone);
128 }
virtual VxResult::Value ContinuousMove(int speedX, int speedY, VxZoomDirection::Value inOut) const =0
VxResult::Value CppSamples::LiveStreaming::PtzOperationsHandler::MoveDownLeft ( ) const
protected

Definition at line 131 of file PtzOperationsHandler.cpp.

131  {
132  // Verify the instance of PTZ controller.
133  if (_ptzControl == nullptr)
134  return VxResult::kInvalidParameters;
135 
136  // Send PTZ Command : Down Left
137  cout << "\nSending PTZ Command:DownLeft.";
138  return _ptzControl->ContinuousMove(-10, -10, VxZoomDirection::kNone);
139 }
virtual VxResult::Value ContinuousMove(int speedX, int speedY, VxZoomDirection::Value inOut) const =0
VxResult::Value CppSamples::LiveStreaming::PtzOperationsHandler::MoveDownRight ( ) const
protected

Definition at line 142 of file PtzOperationsHandler.cpp.

142  {
143  // Verify the instance of PTZ controller.
144  if (_ptzControl == nullptr)
145  return VxResult::kInvalidParameters;
146 
147  // Send PTZ Command : Down Right
148  cout << "\nSending PTZ Command:DownRight.";
149  return _ptzControl->ContinuousMove(10, -10, VxZoomDirection::kNone);
150 }
virtual VxResult::Value ContinuousMove(int speedX, int speedY, VxZoomDirection::Value inOut) const =0
VxResult::Value CppSamples::LiveStreaming::PtzOperationsHandler::MoveLeft ( ) const
protected

Definition at line 153 of file PtzOperationsHandler.cpp.

153  {
154  // Verify the instance of PTZ controller.
155  if (_ptzControl == nullptr)
156  return VxResult::kInvalidParameters;
157 
158  // Send PTZ Command : Left
159  cout << "\nSending PTZ Command:Left.";
160  return _ptzControl->ContinuousMove(-10, 0, VxZoomDirection::kNone);
161 }
virtual VxResult::Value ContinuousMove(int speedX, int speedY, VxZoomDirection::Value inOut) const =0
VxResult::Value CppSamples::LiveStreaming::PtzOperationsHandler::MoveRight ( ) const
protected

Definition at line 197 of file PtzOperationsHandler.cpp.

197  {
198  // Verify the instance of PTZ controller.
199  if (_ptzControl == nullptr)
200  return VxResult::kInvalidParameters;
201 
202  // Send PTZ Command : Right
203  cout << "\nSending PTZ Command:Right.";
204  return _ptzControl->ContinuousMove(10, 0, VxZoomDirection::kNone);
205 }
virtual VxResult::Value ContinuousMove(int speedX, int speedY, VxZoomDirection::Value inOut) const =0
VxResult::Value CppSamples::LiveStreaming::PtzOperationsHandler::MoveUp ( ) const
protected

Definition at line 164 of file PtzOperationsHandler.cpp.

164  {
165  // Verify the instance of PTZ controller.
166  if (_ptzControl == nullptr)
167  return VxResult::kInvalidParameters;
168 
169  // Send PTZ Command : Up
170  cout << "\nSending PTZ Command:Up.";
171  return _ptzControl->ContinuousMove(0, 10, VxZoomDirection::kNone);
172 }
virtual VxResult::Value ContinuousMove(int speedX, int speedY, VxZoomDirection::Value inOut) const =0
VxResult::Value CppSamples::LiveStreaming::PtzOperationsHandler::MoveUpLeft ( ) const
protected

Definition at line 175 of file PtzOperationsHandler.cpp.

175  {
176  // Verify the instance of PTZ controller.
177  if (_ptzControl == nullptr)
178  return VxResult::kInvalidParameters;
179 
180  // Send PTZ Command : Up Left
181  cout << "\nSending PTZ Command:UpLeft.";
182  return _ptzControl->ContinuousMove(-10, 10, VxZoomDirection::kNone);
183 }
virtual VxResult::Value ContinuousMove(int speedX, int speedY, VxZoomDirection::Value inOut) const =0
VxResult::Value CppSamples::LiveStreaming::PtzOperationsHandler::MoveUpRight ( ) const
protected

Definition at line 186 of file PtzOperationsHandler.cpp.

186  {
187  // Verify the instance of PTZ controller.
188  if (_ptzControl == nullptr)
189  return VxResult::kInvalidParameters;
190 
191  // Send PTZ Command : Up Right
192  cout << "\nSending PTZ Command:UpRight.";
193  return _ptzControl->ContinuousMove(10, 10, VxZoomDirection::kNone);
194 }
virtual VxResult::Value ContinuousMove(int speedX, int speedY, VxZoomDirection::Value inOut) const =0
void CppSamples::LiveStreaming::PtzOperationsHandler::TriggerPattern ( )
protected

Definition at line 208 of file PtzOperationsHandler.cpp.

208  {
209  _showResult = false;
210  // Verify the instance of PTZ controller.
211  if (_ptzControl != nullptr) {
212  cout << "\nFetching patterns...";
213  // Get collection of patterns from the PTZ control
215  if (patterns.collectionSize > 0) {
216  // Print the collection of patterns on screen.
217  for (int i = 0; i < patterns.collectionSize; i++) {
218  cout << "\n " << i + 1 << ": " << patterns.collection[i]->name;
219  }
220 
221  // User inputs a pattern index
222  cout << "\nEnter the index of pattern to be triggered (0 to cancel): ";
223  int ch = Utility::ReadInt();
224  // Verify the pattern index
225  if (ch > 0 && ch <= patterns.collectionSize) {
226  // Select the pattern
227  IVxPattern* pattern = patterns.collection[ch - 1];
228  // Trigger the control using selected pattern.
229  if (_ptzControl->TriggerPattern(*pattern))
230  cout << "\nPattern triggered succesfully..\n";
231  else
232  cout << "\nFailed to trigger pattern.\n";
233  }
234  else if (ch == 0) {
235  cout << "\nCancelled..\n";
236  }
237  else {
238  cout << "\nInvalid option selected.";
239  }
240  }
241  else {
242  cout << "\nNo patterns available for this LiveStreaming!\n";
243  }
244 
245  // Remove the memory allocated to the collection.
246  delete[] patterns.collection;
247  }
248 }
VxSdk::VxCollection< VxSdk::IVxPattern ** > GetPatterns() const
virtual VxResult::Value TriggerPattern(IVxPattern &pattern) const =0
void CppSamples::LiveStreaming::PtzOperationsHandler::TriggerPreset ( )
protected

Definition at line 251 of file PtzOperationsHandler.cpp.

251  {
252  _showResult = false;
253  // Verify the instance of PTZ controller.
254  if (_ptzControl != nullptr) {
255  cout << "\nFetching presets...";
256  // Get collection of presets from the PTZ control
258  if (presets.collectionSize > 0) {
259  // Print the collection of presets on screen.
260  for (int i = 0; i < presets.collectionSize; i++) {
261  cout << "\n " << i + 1 << ": " << presets.collection[i]->name;
262  }
263 
264  // User inputs a preset index
265  cout << "\nEnter the index of preset to be triggered (0 to cancel): ";
266  int ch = Utility::ReadInt();
267  // Verify the preset index
268  if (ch > 0 && ch <= presets.collectionSize) {
269  // Select the preset
270  IVxPreset* preset = presets.collection[ch - 1];
271  // Trigger the control using selected preset.
272  if (_ptzControl->TriggerPreset(*preset))
273  cout << "\nPreset triggered succesfully..\n";
274  else
275  cout << "\nFailed to trigger preset.\n";
276  }
277  else if (ch == 0) {
278  cout << "\nCancelled..\n";
279  }
280  else {
281  cout << "\nInvalid option selected.";
282  }
283  }
284  else {
285  cout << "\nNo presets available for this LiveStreaming!\n";
286  }
287 
288  // Remove the memory allocated to the collection.
289  delete[] presets.collection;
290  }
291 }
virtual VxResult::Value TriggerPreset(int index) const =0
VxSdk::VxCollection< VxSdk::IVxPreset ** > GetPresets() const
VxResult::Value CppSamples::LiveStreaming::PtzOperationsHandler::ZoomIn ( ) const
protected

Definition at line 294 of file PtzOperationsHandler.cpp.

294  {
295  // Verify the instance of PTZ controller.
296  if (_ptzControl == nullptr)
297  return VxResult::kInvalidParameters;
298 
299  cout << "\nSending PTZ Command:ZoomIn.";
300  return _ptzControl->ContinuousMove(0, 0, VxZoomDirection::kIn);
301 }
virtual VxResult::Value ContinuousMove(int speedX, int speedY, VxZoomDirection::Value inOut) const =0
VxResult::Value CppSamples::LiveStreaming::PtzOperationsHandler::ZoomOut ( ) const
protected

Definition at line 304 of file PtzOperationsHandler.cpp.

304  {
305  // Verify the instance of PTZ controller.
306  if (_ptzControl == nullptr)
307  return VxResult::kInvalidParameters;
308 
309  cout << "\nSending PTZ Command:ZoomOut.";
310  return _ptzControl->ContinuousMove(0, 0, VxZoomDirection::kOut);
311 }
virtual VxResult::Value ContinuousMove(int speedX, int speedY, VxZoomDirection::Value inOut) const =0

Member Data Documentation

VxSdk::IVxPtzController* CppSamples::LiveStreaming::PtzOperationsHandler::_ptzControl
private

Definition at line 54 of file PtzOperationsHandler.h.

bool CppSamples::LiveStreaming::PtzOperationsHandler::_showResult
private

Definition at line 55 of file PtzOperationsHandler.h.


The documentation for this class was generated from the following files: