-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpython_bindings.cpp
More file actions
716 lines (638 loc) · 24.8 KB
/
Copy pathpython_bindings.cpp
File metadata and controls
716 lines (638 loc) · 24.8 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
#include <memory>
#include <string>
#include <thread>
#include <atomic>
#include <chrono>
#include <boost/python.hpp>
#include <boost/shared_ptr.hpp>
#include <ASDP_Core_API.h>
#include <ASDP_SpinFreeQueue.hpp>
#include <ASDP_StreamPacketSortedQueue.h>
namespace bp = boost::python;
using namespace asdp;
//=========================================================
// Functions that we'll expose that are not part of a class or defined in the header.
static bp::tuple jsonstring_sender_create(const std::string& url)
{
std::shared_ptr<asdp::JSONStringSender> sender;
Status st = asdp::JSONStringSender::Create(url, sender);
return bp::make_tuple(st, sender);
}
static bp::tuple jsonstring_receiver_create(const std::string& url)
{
std::shared_ptr<asdp::JSONStringReceiver> receiver;
Status st = asdp::JSONStringReceiver::Create(url, receiver);
return bp::make_tuple(st, receiver);
}
//=========================================================
// Custom classes that implement complex C++ tasks for the module are be defined here.
#ifdef BOOST_NUMPY_ENABLED
#include <boost/python/numpy.hpp>
namespace np = boost::python::numpy;
static std::shared_ptr<Message> WaitForMessageType(std::shared_ptr<Receiver> receiver, MessageID type, float seconds)
{
std::shared_ptr<Message> empty; ///< We return this on failure.
std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now();
do {
std::shared_ptr<StreamPacket> response;
size_t offset = 0;
Status status = receiver->ReceiveStreamPacket(0, response, offset);
if ((status != OKAY) && (status != TIMEOUT)) {
return empty;
}
if (response != nullptr) {
std::shared_ptr<Message> message;
status = response->GetNextMessage(message);
if (status != OKAY) {
return empty;
}
while (message != nullptr) {
MessageID messageType;
status = message->GetType(messageType);
if (status != OKAY) {
return empty;
}
if (messageType == type) {
// Worked!
return message;
}
status = response->GetNextMessage(message);
if (status != OKAY) {
return empty;
}
}
}
} while (std::chrono::duration<double>(std::chrono::steady_clock::now() - start).count() <= seconds);
return empty;
}
static std::string WaitForEventType(std::shared_ptr<Receiver> receiver, EventID type, float seconds)
{
std::chrono::high_resolution_clock::time_point start = std::chrono::high_resolution_clock::now();
do {
std::shared_ptr<StreamPacket> response;
size_t offset = 0;
Status status = receiver->ReceiveStreamPacket(0, response, offset);
if ((status != OKAY) && (status != TIMEOUT)) {
return "Failed to receive stream packet: " + ErrorMessage(status);
}
if (response != nullptr) {
std::shared_ptr<Message> message;
status = response->GetNextMessage(message);
if (status != OKAY) {
return "Failed to get message from stream packet: " + ErrorMessage(status);
}
while (message != nullptr) {
MessageID messageType;
status = message->GetType(messageType);
if (status != OKAY) {
return "Failed to get message type: " + ErrorMessage(status);
}
if (messageType == EVENT) {
MessageEvent event(*message);
if (event.GetConstructorStatus() != OKAY) {
return "Failed to construct event message: " + ErrorMessage(event.GetConstructorStatus());
}
EventID eventType;
status = event.GetType(eventType);
if (status != OKAY) {
return "Failed to get event type: " + ErrorMessage(status);
}
if (eventType == type) {
// Worked!
return "";
}
}
status = response->GetNextMessage(message);
if (status != OKAY) {
return "Failed to get message from stream packet: " + ErrorMessage(status);
}
}
}
} while (std::chrono::duration<double>(std::chrono::high_resolution_clock::now() - start).count() <= seconds);
return "No message of the requested type received in " + std::to_string(seconds) + " seconds";
}
static std::string GetStreamList(CoreClient& client, std::shared_ptr<Receiver> receiver, std::vector<uint32_t>& IDs, float seconds)
{
// Determine how many streams are stored.
Status status = client.SendCommandPacket(CommandPacketListStoredStreams());
if (status != OKAY) {
return "Failed to send storage command: " + ErrorMessage(status);
}
std::shared_ptr<Message> msg = WaitForMessageType(receiver, STORED_STREAMS, seconds);
if (msg == nullptr) {
return "Did not get stored streams message.";
}
MessageStoredStreamList storedStreams(*msg);
if (storedStreams.GetConstructorStatus() != OKAY) {
return "Failed to construct stored streams message: " + ErrorMessage(storedStreams.GetConstructorStatus());
}
status = storedStreams.GetIDs(IDs);
if (status != OKAY) {
return "Failed to get stored stream IDs: " + ErrorMessage(status);
}
return "";
}
class VideoStreamReceiver {
public:
/// @brief Constructor to create a VideoStreamReceiver that reads from a video file.
/// @param [in] streamFileName Path to the video file to read the stream from.
VideoStreamReceiver(std::string streamFileName);
/// @brief Constructor to create a VideoStreamReceiver that reads from a network stream.
/// @param [in] IP IP address of the local NIC connected to the video stream source.
/// @param [in] serial Serial number of the camera ball to connect to.
/// @param [in] cameraID Camera ID to connect to on the ball.
/// @param [in] frameStride Frame stride to use for the video stream, 1 means every frame.
/// @param [in] replayID If non-zero, ID of the stored stream to replay.
VideoStreamReceiver(std::string IP, uint32_t serial, uint32_t cameraID, uint32_t frameStride, uint32_t replayID);
Status GetStatus() const {
return m_status;
}
/// @brief Destructor to clean up the VideoStreamReceiver object.
~VideoStreamReceiver();
/// @brief Get the next video frame from the stream.
/// @param [in] timeoutSeconds Maximum time to wait for the next frame, in seconds; 0 for immediate return.
/// @return pair of Time and the frame data as a numpy array or an empty tuple on timeout.
bp::tuple GetNextFrame(int timeoutMicroseconds);
/// @brief Discard all buffered frames in the stream.
void DiscardBufferedFrames();
protected:
std::atomic<Status> m_status;
/// @brief Receiver object to get the video stream packets.
std::shared_ptr<Receiver> m_videoReceiver;
/// @brief Receiver object to get the main stream packets (only used for network streams).
std::shared_ptr<Receiver> m_mainStreamReceiver;
/// @brief Client object to manage the network connection (only used for network streams).
std::shared_ptr<CoreClient> m_client;
/// @brief Structure that holds timestamp and frame data.
struct FrameData {
Time timestamp;
uint16_t width;
uint16_t height;
uint16_t* data; ///< Allocated when the frame is created, deleted by one who pulls from queue.
};
/// @brief Spin-free queue to send timed frames from the receiver thread to the main thread.
asdp::SpinFreeQueue<FrameData> m_frameQueue;
// Thread to receive video frames and turn them into numpy arrays with timestamps.
std::thread m_receiverThread;
std::atomic<bool> m_stopThread;
void ReceiverThreadFunction();
};
VideoStreamReceiver::VideoStreamReceiver(std::string streamFileName)
{
m_videoReceiver = std::make_shared<ReceiverFile>(streamFileName);
m_status = m_videoReceiver->GetConstructorStatus();
// Start the receiver thread if we have a receiver
if (m_status == OKAY) {
m_stopThread = false;
m_receiverThread = std::thread(&VideoStreamReceiver::ReceiverThreadFunction, this);
}
}
VideoStreamReceiver::VideoStreamReceiver(std::string IP, uint32_t serial, uint32_t cameraID,
uint32_t frameStride, uint32_t replayID)
{
// Open a client, specifying the IP address to listen on.
m_client = std::make_shared<CoreClient>(IP);
m_status = m_client->GetConstructorStatus();
if (m_status != OKAY) { return; }
// Wait for up to two seconds to allow servers to send Discovery messages with the specified serial number.
std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now();
std::map<uint32_t, std::string> servers;
Status threadStatus;
Status status;
do {
status = m_client->GetDiscoveryThreadStatus(threadStatus);
if (status != OKAY) {
m_status = status;
return;
}
if (threadStatus != OKAY) {
m_status = threadStatus;
return;
}
status = m_client->IdentifiedServers(servers);
if (status != OKAY) {
m_status = status;
return;
}
// If our serial number is found, break out of the loop.
if (servers.find(serial) != servers.end()) {
break;
}
std::this_thread::sleep_for(std::chrono::milliseconds(100));
} while (std::chrono::duration<double>(std::chrono::steady_clock::now() - start).count() <= 2.0);
// If we have not found the server, return.
if (servers.find(serial) == servers.end()) {
m_status = NOT_CONNECTED;
return;
}
// Connect to the server.
uint16_t major, minor, patch;
status = m_client->ConnectToServer(servers[serial], major, minor, patch);
if (status != OKAY) {
m_status = status;
return;
}
// Get the main stream receiver from the m_client->
status = m_client->GetMainStreamReceiver(m_mainStreamReceiver);
if (status != OKAY) {
m_status = status;
return;
}
// Ensure that we get a state message from the server within a reasonable time.
std::shared_ptr<Message> msg = WaitForMessageType(m_mainStreamReceiver, STATE, 5.0);
if (msg == nullptr) {
m_status = TIMEOUT;
return;
}
MessageState state(*msg);
if (state.GetConstructorStatus() != OKAY) {
m_status = state.GetConstructorStatus();
return;
}
// Get a list of cameras from the state message and make sure the requested one is in range.
std::vector<CameraInfo> cameras;
status = state.GetCameras(cameras);
if (status != OKAY) {
m_status = status;
return;
}
if (cameraID >= cameras.size()) {
m_status = BAD_PARAMETER;
return;
}
// If we've been asked to replay a stream, do so now.
if (replayID > 0) {
// Get the list of stored streams.
std::vector<uint32_t> IDs;
std::string error = GetStreamList(*m_client, m_mainStreamReceiver, IDs, 5.0);
if (!error.empty()) {
m_status = BAD_PARAMETER;
return;
}
// Find the stream with the requested ID.
bool found = false;
for (uint32_t ID : IDs) {
if (ID == replayID) {
found = true;
break;
}
}
if (!found) {
m_status = BAD_PARAMETER;
return;
}
// Request the stream to be replayed.
status = m_client->SendCommandPacket(CommandPacketStartReplay(replayID, { 0, 0 }));
if (status != OKAY) {
m_status = status;
return;
}
// Wait for an event saying that we've started to replay.
if (!WaitForEventType(m_mainStreamReceiver, START_OF_REPLAY, 5.0).empty()) {
m_status = TIMEOUT;
return;
}
}
// Find the minimum period for the camera and which internal trigger ID it uses, then
// configure the trigger to run at that rate.
TriggerInfo ti;
ti.ID = cameras[cameraID - 1].trigger;
ti.mode = 1;
ti.period = cameras[cameraID - 1].minTriggerPeriod;
ti.offset = 0;
ti.trackingFactor = 0.5;
status = m_client->SendCommandPacket(CommandPacketConfigureTrigger(ti));
if (status != OKAY) {
m_status = status;
return;
}
// Construct a UDP receiver for a stream from the camera.
std::shared_ptr<ReceiverUDP> receiverUDP = std::make_shared<ReceiverUDP>(IP);
if (receiverUDP->GetConstructorStatus() != OKAY) {
m_status = receiverUDP->GetConstructorStatus();
return;
}
uint16_t port;
status = receiverUDP->GetPort(port);
if (status != asdp::OKAY) {
m_status = status;
return;
}
m_videoReceiver = receiverUDP;
// Start the receiver thread
m_stopThread = false;
m_receiverThread = std::thread(&VideoStreamReceiver::ReceiverThreadFunction, this);
// Request the camera to stream full-frame images once every frameStride frames.
StreamEndpoint endpoint(IP, port);
SubregionDescription region;
region.cameraID = cameraID;
region.skipFrames = frameStride - 1;
region.startTimeSeconds = 0;
region.startTimeMicroseconds = 0;
region.left = 0;
region.top = 0;
region.right = cameras[cameraID - 1].width - 1;
region.bottom = cameras[cameraID - 1].height - 1;
status = m_client->SendCommandPacket(CommandPacketStreamSubregion(endpoint, region));
if (status != OKAY) {
m_status = status;
return;
}
m_status = OKAY;
}
VideoStreamReceiver::~VideoStreamReceiver()
{
// Stop the receiver thread
m_stopThread = true;
if (m_receiverThread.joinable()) {
m_receiverThread.join();
}
// Reset the receivers, then the client.
m_videoReceiver.reset();
m_mainStreamReceiver.reset();
m_client.reset();
}
// Custom destructor for PyCapsule to deallocate C++ vector data
static void destroy_array_data(PyObject* capsule) {
// use the same name passed to PyCapsule_New for validation
void* data_ptr = PyCapsule_GetPointer(capsule, "asdp.frame.data");
if (data_ptr) {
delete [] reinterpret_cast<uint16_t*>(data_ptr);
}
}
// Helper that creates a PyCapsule and returns a Boost.Python object that owns it.
static bp::object make_capsule_owner(void* data) {
PyObject* capsule = PyCapsule_New(data, "asdp.frame.data", destroy_array_data);
if (!capsule) {
bp::throw_error_already_set(); // propagate Python error
}
// Wrap the new-reference capsule in a boost::python object that takes ownership.
return bp::object(bp::detail::new_reference(capsule));
}
bp::tuple VideoStreamReceiver::GetNextFrame(int timeoutMicroseconds)
{
// This method is called from the main thread, so it can call Python routines. This is where
// we convert the frame data into a numpy array and then make a tuple of the time and the array.
FrameData frameData;
bool found = m_frameQueue.dequeue(frameData, std::chrono::microseconds(timeoutMicroseconds));
if (!found) {
return bp::tuple();
}
// Create a numpy array from the frame data, including code to clean up the memory.
bp::object owner = make_capsule_owner(frameData.data);
np::dtype dtype = np::dtype::get_builtin<uint16_t>();
bp::tuple shape = bp::make_tuple(frameData.height, frameData.width);
bp::tuple strides = bp::make_tuple(sizeof(uint16_t) * frameData.width, sizeof(uint16_t));
np::ndarray numpyArray = np::from_data(frameData.data, dtype, shape, strides, owner);
// Create the tuple to return.
bp::tuple frameTuple = bp::make_tuple(frameData.timestamp, numpyArray);
return frameTuple;
}
void VideoStreamReceiver::DiscardBufferedFrames()
{
// Keep dequeuing frames until the queue is empty.
FrameData frameData;
while (m_frameQueue.dequeue(frameData, std::chrono::microseconds(0))) {
// Delete the frame data.
delete[] frameData.data;
}
}
void VideoStreamReceiver::ReceiverThreadFunction()
{
// Use a sorting queue to ensure that we process the messages in order even if the UDP packets
// arrive out of order.
StreamPacketSortedQueue sortedQueue(50);
// Numpy array that will get created during begin frame and filled in with data and the time for the
// current frame.
std::shared_ptr<FrameData> currentArray;
Time currentFrameTime;
// Keep reading packets until we don't get one for five seconds or we've been asked to stop.
std::chrono::steady_clock::time_point lastPacketTime = std::chrono::steady_clock::now();
while (!m_stopThread && (std::chrono::steady_clock::now() < lastPacketTime + std::chrono::seconds(5))) {
// Service the main receiver if there is one, gobbling up any packets.
if (m_mainStreamReceiver != nullptr) {
std::shared_ptr<asdp::StreamPacket> mainPacket;
size_t offset = 0;
Status status = m_mainStreamReceiver->ReceiveStreamPacket(0, mainPacket, offset);
if (status != asdp::OKAY && status != asdp::TIMEOUT) {
m_status = status;
return;
}
}
// Get the next packet.
std::shared_ptr<StreamPacket> packet;
size_t offset = 0;
Status status = m_videoReceiver->ReceiveStreamPacket(0.0, packet, offset);
if (status == TIMEOUT) {
continue;
}
if (status != OKAY) {
m_status = status;
return;
}
lastPacketTime = std::chrono::steady_clock::now();
std::list< std::shared_ptr<StreamPacket> > readyPackets = sortedQueue.AddPacket(packet);
while (!readyPackets.empty()) {
std::shared_ptr<asdp::StreamPacket> receiveStreamPacket = readyPackets.front();
readyPackets.pop_front();
// Get and handle all messages from the packet.
std::shared_ptr<asdp::Message> message;
status = receiveStreamPacket->GetNextMessage(message);
if (status != asdp::OKAY) {
m_status = status;
return;
}
while (message != nullptr) {
asdp::MessageID rID;
status = message->GetType(rID);
if (status != asdp::OKAY) {
m_status = status;
return;
}
switch (rID) {
case asdp::CONSOLIDATED_FRAME_DATA:
{
// Get the message as a consolidated frame data message.
MessageConsolidatedFrameData frameData(*message);
if (frameData.GetConstructorStatus() != asdp::OKAY) {
m_status = frameData.GetConstructorStatus();
return;
}
// Get the frame dimensions.
uint16_t width, height;
status = frameData.GetSensorWidth(width);
if (status != asdp::OKAY) {
m_status = status;
return;
}
status = frameData.GetSensorHeight(height);
if (status != asdp::OKAY) {
m_status = status;
return;
}
bool isBeginFrame;
status = frameData.GetBeginFrameFlag(isBeginFrame);
if (status != asdp::OKAY) {
m_status = status;
return;
}
// If this is a begin frame, create a new numpy array to hold the frame data and
// record the time.
if (isBeginFrame) {
// Get the frame time.
status = frameData.GetTime(currentFrameTime);
if (status != asdp::OKAY) {
m_status = status;
return;
}
// Construct an array of zeroes.
currentArray = std::make_shared<FrameData>();
currentArray->timestamp = currentFrameTime;
currentArray->width = width;
currentArray->height = height;
currentArray->data = new uint16_t[static_cast<size_t>(width) * static_cast<size_t>(height)];
std::memset(currentArray->data, 0, sizeof(uint16_t) * static_cast<size_t>(width) * static_cast<size_t>(height));
}
// Copy the frame data into the numpy array if there is one (ensures that we've seen a begin frame).
if (currentArray != nullptr) {
// Get the frame data and copy it into the numpy array.
uint16_t left, right, top, bottom;
status = frameData.GetLeft(left);
if (status != asdp::OKAY) {
m_status = status;
return;
}
status = frameData.GetRight(right);
if (status != asdp::OKAY) {
m_status = status;
return;
}
status = frameData.GetTop(top);
if (status != asdp::OKAY) {
m_status = status;
return;
}
status = frameData.GetBottom(bottom);
if (status != asdp::OKAY) {
m_status = status;
return;
}
uint8_t* rawData;
status = frameData.GetDataPointer(rawData);
if (status != asdp::OKAY) {
m_status = status;
return;
}
// NOTE: This makes use of the fact that we're asking for the full frame, and that the server sends
// full lines at once when this is the case. Otherwise, we'd need to copy the data line by line and
// adjust for the full-image stride when doing offsets.
size_t size = (right - left + 1) * (bottom - top + 1) * sizeof(uint16_t);
size_t stride = static_cast<size_t>(width);
memcpy(currentArray->data + (top * stride + left), rawData, size);
}
// See if this is an end frame.
bool isEndFrame;
status = frameData.GetEndFrameFlag(isEndFrame);
if (status != asdp::OKAY) {
m_status = status;
return;
}
// If we're an end frame and we have an array, enqueue it.
if (isEndFrame && currentArray != nullptr) {
m_frameQueue.enqueue(*currentArray);
currentArray.reset();
// If we're not live, then make sure we don't flood the queue.
if (m_mainStreamReceiver == nullptr) {
while (!m_stopThread && !m_frameQueue.awaitEmpty(5, std::chrono::microseconds(10000))) {}
}
}
}
break;
default:
break;
}
// Get the next message from the packet.
status = receiveStreamPacket->GetNextMessage(message);
if (status != asdp::OKAY) {
m_status = status;
return;
}
}
}
}
}
#endif // BOOST_NUMPY_ENABLED
//=========================================================
// Module definition for ASDP_Core, including the functions above and some in-header classes
// and functions.
BOOST_PYTHON_MODULE(ASDP_Core)
{
#ifdef BOOST_NUMPY_ENABLED
// initialize Boost.Python NumPy support (must be done before any np::... calls)
np::initialize();
#endif
// Expose the status enum and the function to print error messages corresponding to the status codes
bp::enum_<Status>("Status")
.value("OKAY", Status::OKAY)
.value("TIMEOUT", Status::TIMEOUT)
.value("THREAD_COMPLETED", Status::THREAD_COMPLETED)
.value("BAD_PARAMETER", Status::BAD_PARAMETER)
.value("OUT_OF_MEMORY", Status::OUT_OF_MEMORY)
.value("NOT_IMPLEMENTED", Status::NOT_IMPLEMENTED)
.value("DELETION_FAILED", Status::DELETION_FAILED)
.value("NULL_OBJECT_POINTER", Status::NULL_OBJECT_POINTER)
.value("INTERNAL_EXCEPTION", Status::INTERNAL_EXCEPTION)
.value("SOCKET_FAILURE", Status::SOCKET_FAILURE)
.value("READ_PAST_END", Status::READ_PAST_END)
.value("BAD_COOKIE", Status::BAD_COOKIE)
.value("WRITE_PAST_END", Status::WRITE_PAST_END)
.value("FILE_FAILURE", Status::FILE_FAILURE)
.value("UNEXPECTED_INTERNAL_STATE", Status::UNEXPECTED_INTERNAL_STATE)
.value("INCORRECT_ENDIANNESS", Status::INCORRECT_ENDIANNESS)
.value("NOT_CONNECTED", Status::NOT_CONNECTED)
.value("INCORRECT_FLOAT_SIZE", Status::INCORRECT_FLOAT_SIZE)
.value("INCOMPATIBLE_API_VERSION", Status::INCOMPATIBLE_API_VERSION)
;
bp::def("ErrorMessage", &asdp::ErrorMessage);
// Wrap the Time structure
bp::class_<Time>("Time")
.def_readwrite("seconds", &Time::seconds)
.def_readwrite("microseconds", &Time::microseconds)
;
// Wrap the JSONStringSender class
bp::register_ptr_to_python<std::shared_ptr<asdp::JSONStringSender>>();
bp::class_<JSONStringSender, boost::noncopyable>("JSONStringSender", bp::no_init)
.def("Create", jsonstring_sender_create)
.def("Send", &JSONStringSender::Send)
.def("Test", &JSONStringSender::Test)
;
// Wrap the JSONStringReceiver class
bp::register_ptr_to_python<std::shared_ptr<asdp::JSONStringReceiver>>();
bp::class_<JSONStringReceiver, boost::noncopyable>("JSONStringReceiver", bp::no_init)
.def("Create", jsonstring_receiver_create)
.def("Send", &JSONStringReceiver::Receive)
.def("Test", &JSONStringReceiver::Test)
;
#ifdef BOOST_NUMPY_ENABLED
// Wrap the VideoStreamReceiver class
bp::class_<VideoStreamReceiver, boost::noncopyable>("VideoStreamReceiver", bp::no_init)
.def("__init__", bp::make_constructor(
static_cast<VideoStreamReceiver*(*)(std::string)>(
[](std::string streamFileName) {
return new VideoStreamReceiver(streamFileName);
}
)
))
.def("__init__", bp::make_constructor(
static_cast<VideoStreamReceiver*(*)(std::string, uint32_t, uint32_t, uint32_t, uint32_t)>(
[](std::string IP, uint32_t serial, uint32_t cameraID, uint32_t frameStride, uint32_t replayID) {
return new VideoStreamReceiver(IP, serial, cameraID, frameStride, replayID);
}
)
))
.def("GetStatus", &VideoStreamReceiver::GetStatus)
.def("GetNextFrame", &VideoStreamReceiver::GetNextFrame)
.def("DiscardBufferedFrames", &VideoStreamReceiver::DiscardBufferedFrames)
;
#endif
}