-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSource.cpp
More file actions
143 lines (123 loc) · 3.91 KB
/
Source.cpp
File metadata and controls
143 lines (123 loc) · 3.91 KB
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
#include "stdafx.h"
#include "Source.h"
#include "SimpleGUIApplicationDlg.h"
using namespace std;
PV_INIT_SIGNAL_HANDLER();
#define BUFFER_COUNT ( 16 )
//
// Simple class used to control a source and get images from it
// >> modifiyed from MultiSource.cpp (MultiSource sample)
//
// Constructor
Source::Source(PvDevice *aDevice, const PvString &aConnectionID, const int32_t nCh)
: mDevice(aDevice)
, mStream(NULL)
, mPipeline(NULL)
, mConnectionID(aConnectionID)
, mSourceCh(nCh)
{
}
// Destructor
Source::~Source()
{
PVDELETE(mPipeline);
PVDELETE(mStream);
}
// Open source: opens the stream, set destination, starts pipeline
bool Source::Open()
{
// Select source (if applicable)
PvGenStateStack lStack(mDevice->GetParameters());
SelectSource(&lStack);
// Create and open stream, use same protocol as PvDevice. PvStream::CreateAndOpen is not used as we
// need to specify additional parameters like streaming channel
PvDeviceGEV *lDeviceGEV = dynamic_cast<PvDeviceGEV *>(mDevice);
PvResult lResult;
if (lDeviceGEV != NULL)
{
// Create and open stream
PvStreamGEV *lStreamGEV = new PvStreamGEV;
lResult = lStreamGEV->Open(mConnectionID, 0, mSourceCh);
if (!lResult.IsOK())
{
TRACE("**** Error opening stream to GigE Vision device\n");
return false;
}
// Save pointer to stream object
mStream = lStreamGEV;
// Get stream local information
PvString lLocalIP = lStreamGEV->GetLocalIPAddress();
uint16_t lLocalPort = lStreamGEV->GetLocalPort();
// Set source destination on GigE Vision device
lDeviceGEV->SetStreamDestination(lLocalIP, lLocalPort, mSourceCh);
// Reading payload size from device
int64_t lSize = mDevice->GetPayloadSize();
// Dynamically allocate pipeline (required PvStream pointer)
mPipeline = new PvPipeline(mStream);
// Set the Buffer size and the Buffer count
mPipeline->SetBufferSize(static_cast<uint32_t>(lSize));
mPipeline->SetBufferCount(BUFFER_COUNT); // Increase for high frame rate without missing block IDs
// Start pipeline thread
//mPipeline->Start(); ‚Ü‚¾Start‚³‚¹‚È‚¢
return true;
}
else
return false;
}
// Close source: close the stream, pipeline
void Source::Close()
{
if (mPipeline != NULL) {
if (mPipeline->IsStarted())
mPipeline->Stop();
delete mPipeline;
mPipeline = NULL;
}
if (mStream != NULL) {
if (mStream->IsOpen())
mStream->Close();
delete mStream;
mStream = NULL;
}
}
void Source::StartAcquisition()
{
// Select source (if applicable)
PvGenStateStack lStack(mDevice->GetParameters());
SelectSource(&lStack);
// Enables stream before sending the AcquisitionStart command.
mDevice->StreamEnable();
mDevice->GetParameters()->ExecuteCommand("AcquisitionStart");
}
void Source::StopAcquisition()
{
// Select source (if applicable)
PvGenStateStack lStack(mDevice->GetParameters());
SelectSource(&lStack);
// The pipeline is already "armed", we just have to tell the device
// to start sending us images
mDevice->GetParameters()->ExecuteCommand("AcquisitionStop");
// Disable stream after sending the AcquisitionStop command.
mDevice->StreamDisable();
}
void Source::SelectSource(PvGenStateStack *aStack)
{
// If no source defined, there is likely no source selector, nothing to select
if (mSourceCh < 0 || mSourceCh >= MAX_STREAM_CHANNEL)
return;
// Select source. When stack goes out of scope, the previous value will be restored
aStack->SetEnumValue("SourceSelector", (int64_t)mSourceCh);
}
CString Source::GetFrameRate()
{
// Get frame rate
double lFPS = 0.0;
mStream->GetParameters()->GetFloatValue("AcquisitionRate", lFPS);
// Get bandwidth, convert in Mb/s
double lBandwidth = 0.0;
mStream->GetParameters()->GetFloatValue("Bandwidth", lBandwidth);
lBandwidth /= 1000000.0;
CString cstrValue;
cstrValue.Format(_T("%.2f FPS %.2f Mb/s "), lFPS, lBandwidth);
return cstrValue;
}