-
Notifications
You must be signed in to change notification settings - Fork 1
/
cameracontrol.cpp
70 lines (60 loc) · 1.76 KB
/
cameracontrol.cpp
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
#include <stdio.h>
#include <bcm_host.h>
#include <stdexcept>
#include <mmal_logging.h>
#include "cameracontrol.h"
#include "mmalexception.h"
#include "pixellistener.h"
CameraControl::CameraControl()
{
camera.reset(new MMALCamera(0));
encoder.reset(new MMALEncoder());
encoder->add_port_listener(this);
camera->connect(2, encoder.get(), 0); // Connected the capture port to the encoder.
encoder->activate();
}
CameraControl::~CameraControl()
{
fprintf(stderr, "CameraControl deleted\n");
}
/**
* @brief CameraControl::buffer_received Buffer received to what ever we are listened to.
* This method is responsible to feed image data to the indi-driver code.
* @param port
* @param buffer
*/
void CameraControl::buffer_received(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer)
{
if (port->type == MMAL_PORT_TYPE_OUTPUT)
{
assert(buffer->type->video.planes == 1);
if (buffer->length) {
for(auto l : pixel_listeners) {
l->pixels_received(buffer->data + buffer->offset, buffer->length);
}
}
// Now flag if we have completed
if (buffer->flags & (MMAL_BUFFER_HEADER_FLAG_EOS | MMAL_BUFFER_HEADER_FLAG_FRAME_END | MMAL_BUFFER_HEADER_FLAG_TRANSMISSION_FAILED)) {
for(auto l : pixel_listeners) {
l->capture_complete();
}
}
}
else {
fprintf(stderr, "%s(%s): unsupported port type: %d\n", __FILE__, __func__, port->type);
}
}
/**
* @brief CameraControl::capture Start thread to perform the actual capture.
*/
void CameraControl::start_capture()
{
camera->capture();
}
/**
* @brief CameraControl::stop_capture Tell camera object to stop capturing.
*/
void CameraControl::stop_capture()
{
camera->abort();
}