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

This plugin sample creates an export and adds to the current system. More...

#include <CreateExport.h>

Public Member Functions

 CreateExport (const std::string description)
 
 ~CreateExport ()
 
CppSamples::Common::PluginRun (CppSamples::Common::DataModel *dataModel) override
 Creates an export and adds to the current system. More...
 
- Public Member Functions inherited from CppSamples::Common::Plugin
 Plugin (const std::string description)
 
virtual ~Plugin ()
 
std::string GetDescription () const
 Gets the description of this plugin. More...
 
PluginGetParent () const
 Gets the reference to the parent of this plugin. More...
 
void SetParent (Plugin *parent)
 Sets the reference to the parent of this plugin. More...
 

Protected Member Functions

void CreateNewExportOption (VxSdk::VxCollection< VxSdk::IVxDataSource ** > dataSources, VxSdk::IVxSystem *vxSystem) const
 Creates an export using the given system. More...
 
VxSdk::IVxExportGetExport (VxSdk::IVxSystem *vxSystem, const char *expName, const char *id) const
 Get an export from the VideoExpert system with given name and ID. More...
 

Static Protected Member Functions

static VxSdk::VxCollection< VxSdk::IVxClip ** > GetClips (VxSdk::IVxDataSource *dataSource)
 Get a collection of clips from the given VideoExpert system. More...
 
static VxSdk::VxCollection< VxSdk::IVxDataSource ** > GetDataSources (VxSdk::IVxSystem *vxSystem)
 Get a collection of data source from the given VideoExpert system. More...
 

Detailed Description

This plugin sample creates an export and adds to the current system.

Definition at line 12 of file CreateExport.h.

Inherits CppSamples::Common::Plugin.

Constructor & Destructor Documentation

CppSamples::Exports::CreateExport::CreateExport ( const std::string  description)
inline

Definition at line 14 of file CreateExport.h.

14 : CppSamples::Common::Plugin(description) { }
Plugin is the abstract class which can be a menu item and/or a sample. Every sample and menu item mus...
Definition: Plugin.h:33
CppSamples::Exports::CreateExport::~CreateExport ( )
inline

Definition at line 15 of file CreateExport.h.

15 {}

Member Function Documentation

void CppSamples::Exports::CreateExport::CreateNewExportOption ( VxSdk::VxCollection< VxSdk::IVxDataSource ** >  dataSources,
VxSdk::IVxSystem vxSystem 
) const
protected

Creates an export using the given system.

Parameters
dataSourcesCollection of data source.
vxSystemPointer to the VideoExpert system.

Definition at line 28 of file CreateExport.cpp.

28  {
29  // Select a Data source
30  cout << "\nEnter data source index [1-"<<dataSources.collectionSize<<"]: ";
31  int camNum = Utility::ReadInt();
32 
33  // Verify input
34  if (camNum < 1 || camNum > dataSources.collectionSize)
35  return;
36 
37  // Print the details of selected data source
38  IVxDataSource* dataSource = dataSources.collection[camNum - 1];
39  cout << "\n" << "DataSource selected for export is : " << dataSource->name << "\n";
40 
41  // Read Clips from system
42  VxCollection<IVxClip**> clips = GetClips(dataSource);
43  string exportName;
44  string exportPasswd;
45  int fileFormatOption = 1;
46 
47  if (clips.collectionSize > 0) {
48  // Start time for export
49  cout << "\n" << "Input start time for export clip(yyyy-mm-dd hh:mm:ss): ";
50  struct tm startTime = Utility::GetDateAndTimeFromUser();
51  string startTimeInUTC = Utility::ConvertLocalTimetoUTC(startTime);
52 
53  // End time for export
54  cout << "\n" << "Input end time for export clip(yyyy-mm-dd hh:mm:ss): ";
55  struct tm endTime = Utility::GetDateAndTimeFromUser();
56  string endTimeInUTC = Utility::ConvertLocalTimetoUTC(endTime);
57 
58  // Read name of export
59  cout << "\n" << "Enter name for your export: ";
60  exportName = Utility::ReadString();
61 
62  // Create instance of export structure and assign user inputs.
63  VxNewExport* newExport = new VxNewExport();
64  newExport->format = VxExportFormat::kMkvZip;
65  Utilities::StrCopySafe(newExport->name, exportName.c_str());
66 
67  // Create instance of Export Clip
68  VxNewExportClip* exportClip = new VxNewExportClip();
69  Utilities::StrCopySafe(exportClip->dataSourceId, dataSource->id);
70  Utilities::StrCopySafe(exportClip->startTime, startTimeInUTC.c_str());
71  Utilities::StrCopySafe(exportClip->endTime, endTimeInUTC.c_str());
72  newExport->clips = new VxNewExportClip[1];
73  newExport->clipSize = 1;
74  newExport->clips[0] = *exportClip;
75 
76  IVxExport* exportItem = nullptr;
77  vxSystem->CreateExport(*newExport, exportItem);
78  // Remove the memory allocated to the collection.
79  delete[] newExport->clips;
80 
81  if (exportItem != nullptr) {
82  // Show progress info
83  do {
84  // Get an export from the system
85  IVxExport* newExp = GetExport(vxSystem, exportItem->name, exportItem->id);
86 
87  // Show status on screen
88  if (newExp->status == VxExportStatus::kExporting) {
89  Utility::ShowProgress("Exporting", static_cast<int>(newExp->percentComplete), 100, 50);
90  }
91  else if (newExp->status == VxExportStatus::kPending) {
92  Utility::ShowProgress("Pending", static_cast<int>(newExp->percentComplete), 100, 50);
93  }
94  else if (newExp->status == VxExportStatus::kFailed) {
95  cout << "\nExport failed!!\n";
96  break;
97  }
98  else if (newExp->status == VxExportStatus::kSuccessful) {
99  Utility::ShowProgress("Exporting", 100, 100, 50);
100  cout << "\nExport successfully created..\n";
101  break;
102  }
103 
104  delete newExp;
105  // Pause the thread for a while after each iteration.
106  this_thread::sleep_for(chrono::seconds(1));
107  } while (true);
108 
109  delete exportItem;
110  }
111  else {
112  cout << "\nFailed to export!!.\n";
113  }
114  delete exportClip;
115  delete newExport;
116  }
117  else {
118  cout << "No clips available for selected camera!!\n";
119  }
120 
121  // Remove the memory allocated to the collection.
122  delete[] clips.collection;
123 }
VxSdk::IVxExport * GetExport(VxSdk::IVxSystem *vxSystem, const char *expName, const char *id) const
Get an export from the VideoExpert system with given name and ID.
VxExportStatus::Value status
virtual VxResult::Value CreateExport(VxNewExport &newExport, IVxExport *&exportItem) const =0
static VxSdk::VxCollection< VxSdk::IVxClip ** > GetClips(VxSdk::IVxDataSource *dataSource)
Get a collection of clips from the given VideoExpert system.
VxExportFormat::Value format
VxNewExportClip * clips
VxCollection< IVxClip ** > CppSamples::Exports::CreateExport::GetClips ( VxSdk::IVxDataSource dataSource)
staticprotected

Get a collection of clips from the given VideoExpert system.

Parameters
vxSystemPointer to the VideoExpert system.
Returns
A collection of clips.

Definition at line 126 of file CreateExport.cpp.

126  {
127  cout << "Searching for available clips..Please wait..\n";
128 
129  // Read the clips from data source only if it has atleast one data interface with RTSP stream.
130  int size = dataSource->dataInterfaceSize;
131  for (int i = 0; i < size; i++) {
132  IVxDataInterface* dataInterface = dataSource->dataInterfaces[i];
133  if (dataInterface->protocol == VxStreamProtocol::kRtspRtp) {
134  // Read the size of clip collection from system.
136  VxResult::Value result = dataSource->GetClips(clips);
137  if (result == VxResult::kInsufficientSize) {
138  // Allocate memory for the requried collection.
139  clips.collection = new IVxClip*[clips.collectionSize];
140  // Read the collection from system.
141  dataSource->GetClips(clips);
142  }
143 
144  if (clips.collectionSize > 0) {
145  // Print the clip details on screen
146  cout << "Total Number of clips available: " << clips.collectionSize << "\n";
147  for (int i1 = 0; i1 < clips.collectionSize; i1++) {
148  IVxClip* clip = clips.collection[i1];
149  tm startTime = Utility::ParseDateTime(clip->startTime);
150  tm endTime = Utility::ParseDateTime(clip->endTime);
151  string startTimeStr = Utility::ConvertUTCtoLocalTime(startTime);
152  string endTimeStr = Utility::ConvertUTCtoLocalTime(endTime);
153  cout << (i1 + 1) << ". " << startTimeStr << "---" << endTimeStr << "\n";
154  }
155  }
156 
157  return clips;
158  }
159  }
160 
161  return VxCollection<IVxClip**>();
162 }
virtual VxResult::Value GetClips(VxCollection< IVxClip ** > &clipCollection) const =0
IVxDataInterface ** dataInterfaces
char endTime[64]
char startTime[64]
VxStreamProtocol::Value protocol
VxCollection< IVxDataSource ** > CppSamples::Exports::CreateExport::GetDataSources ( VxSdk::IVxSystem vxSystem)
staticprotected

Get a collection of data source from the given VideoExpert system.

Parameters
vxSystemPointer to the VideoExpert system.
Returns
A collection of data source.

Definition at line 165 of file CreateExport.cpp.

165  {
166  cout << "Fetching datasources from system, Please wait...\n";
167  // Read the size of collection from system.
168  VxCollection<IVxDataSource**> dataSources;
169  VxResult::Value result = vxSystem->GetDataSources(dataSources);
170  if (result == VxResult::kInsufficientSize) {
171  // Allocate memory for the requried collection.
172  dataSources.collection = new IVxDataSource*[dataSources.collectionSize];
173  // Read the collection from system.
174  vxSystem->GetDataSources(dataSources);
175  }
176  // Print the number of data source items read from the system.
177  cout << dataSources.collectionSize << " datasources found.\n";
178  return dataSources;
179 }
virtual VxResult::Value GetDataSources(VxCollection< IVxDataSource ** > &dataSourceCollection) const =0
IVxExport * CppSamples::Exports::CreateExport::GetExport ( VxSdk::IVxSystem vxSystem,
const char *  expName,
const char *  id 
) const
protected

Get an export from the VideoExpert system with given name and ID.

Parameters
vxSystemPointer to the VideoExpert system.
expNameName of the export.
idID of the export.
Returns
Export with given name and ID.

Definition at line 182 of file CreateExport.cpp.

182  {
183  // Create filter with given export name.
185  exports.filterSize = 1;
186  VxCollectionFilter filters[1];
187  filters->key = VxCollectionFilterItem::kName;
188  Utilities::StrCopySafe(filters->value, expName);
189  exports.filters = filters;
190 
191  IVxExport* vxExport = nullptr;
192  // Read the size of collection from system.
193  VxResult::Value result = vxSystem->GetExports(exports);
194  if (result == VxResult::kInsufficientSize) {
195  // Allocate memory for the requried collection.
196  exports.collection = new IVxExport*[exports.collectionSize];
197  // Read the collection from system.
198  result = vxSystem->GetExports(exports);
199  if (result == VxResult::kOK) {
200  // Find the export with given ID from the result collection of exports.
201  for (int i = 0; i < exports.collectionSize; i++) {
202  IVxExport* exportObj = exports.collection[i];
203  if (strcmp(exportObj->id, id) == 0) {
204  vxExport = exports.collection[i];
205  break;
206  }
207  }
208  }
209 
210  // Remove the memory allocated to the collection.
211  delete[] exports.collection;
212  }
213 
214  return vxExport;
215 }
VxCollectionFilterItem::Value key
virtual VxResult::Value GetExports(VxCollection< IVxExport ** > &exportCollection) const =0
VxCollectionFilter * filters
Plugin * CppSamples::Exports::CreateExport::Run ( CppSamples::Common::DataModel dataModel)
overridevirtual

Creates an export and adds to the current system.

Parameters
dataModelInstance of data model.

Implements CppSamples::Common::Plugin.

Definition at line 12 of file CreateExport.cpp.

12  {
13  cout << "\n\n";
14  VxCollection<IVxDataSource**> dataSources = GetDataSources(dataModel->VxSystem);
15 
16  CreateNewExportOption(dataSources, dataModel->VxSystem);
17 
18  // Wait for user response before going back to parent menu.
19  Utility::Pause();
20 
21  // Remove the memory allocated to the collection.
22  delete[] dataSources.collection;
23  // Return reference of parent plugin to move back to parent menu.
24  return GetParent();
25 }
VxSdk::IVxSystem * VxSystem
Represents a VideoXpert system and allows the user to manage the system and devices.
Definition: Plugin.h:17
Plugin * GetParent() const
Gets the reference to the parent of this plugin.
Definition: Plugin.h:46
void CreateNewExportOption(VxSdk::VxCollection< VxSdk::IVxDataSource ** > dataSources, VxSdk::IVxSystem *vxSystem) const
Creates an export using the given system.
static VxSdk::VxCollection< VxSdk::IVxDataSource ** > GetDataSources(VxSdk::IVxSystem *vxSystem)
Get a collection of data source from the given VideoExpert system.

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