24#include <core/exception.h>
25#include <core/exceptions/software.h>
26#include <fvcams/cam_exceptions.h>
27#include <fvcams/net.h>
28#include <fvutils/compression/jpeg_decompressor.h>
29#include <fvutils/net/fuse_client.h>
30#include <fvutils/net/fuse_image_content.h>
31#include <fvutils/net/fuse_imagelist_content.h>
32#include <fvutils/net/fuse_message.h>
33#include <fvutils/system/camargp.h>
34#include <netinet/in.h>
73 decompressed_buffer_ = NULL;
78 fuse_imageinfo_ = NULL;
95 if (image_id == NULL) {
101 image_id_ = strdup(image_id);
102 host_ = strdup(host);
110 decompressor_ = NULL;
111 decompressed_buffer_ = NULL;
115 fuse_message_ = NULL;
116 fuse_imageinfo_ = NULL;
135 if (cap->
has(
"image")) {
136 image_id_ = strdup(cap->
get(
"image").c_str());
140 if (cap->
has(
"host")) {
141 host_ = strdup(cap->
get(
"host").c_str());
143 host_ = strdup(
"localhost");
145 if (cap->
has(
"port")) {
146 int i = atoi(cap->
get(
"port").c_str());
147 if ((i < 0) || (i >= 0xFFFF)) {
150 port_ = (
unsigned int)i;
155 get_jpeg_ = (cap->
has(
"jpeg") && (cap->
get(
"jpeg") ==
"true"));
161 decompressor_ = NULL;
162 decompressed_buffer_ = NULL;
166 fuse_message_ = NULL;
167 fuse_imageinfo_ = NULL;
182 if (decompressed_buffer_ != NULL)
183 free(decompressed_buffer_);
184 delete decompressor_;
200 strncpy(imagedesc->
image_id, image_id_, IMAGE_ID_MAX_LENGTH - 1);
203 if (!fuse_imageinfo_) {
204 throw Exception(
"Could not receive image info. Image not available?");
235 throw CaptureException(
"You must dispose the buffer before fetching a new image");
243 strncpy(irm->
image_id, image_id_, IMAGE_ID_MAX_LENGTH - 1);
244 irm->
format = (get_jpeg_ ? FUSE_IF_JPEG : FUSE_IF_RAW);
248 throw CaptureException(
"Capture failed, connection died while waiting for image");
257 if (decompressed_buffer_ != NULL) {
258 free(decompressed_buffer_);
260 size_t buffer_size = colorspace_buffer_size(YUV422_PLANAR,
263 decompressed_buffer_ = (
unsigned char *)malloc(
buffer_size);
275 return decompressed_buffer_;
278 return fuse_image_->
buffer();
294 return colorspace_buffer_size((colorspace_t)fuse_image_->
colorspace(),
308 if (fuse_imageinfo_) {
309 free(fuse_imageinfo_);
310 fuse_imageinfo_ = NULL;
326 fuse_message_->
unref();
327 fuse_message_ = NULL;
334 if (fuse_imageinfo_) {
335 return ntohl(fuse_imageinfo_->
width);
344 if (fuse_imageinfo_) {
345 return ntohl(fuse_imageinfo_->
height);
381 image_id_ = strdup(image_id);
385 strncpy(imagedesc->
image_id, image_id_, IMAGE_ID_MAX_LENGTH - 1);
388 if (!fuse_imageinfo_) {
389 throw Exception(
"Could not received image info. Image not available?");
403 return YUV422_PLANAR;
405 if (fuse_imageinfo_) {
406 return (colorspace_t)ntohs(fuse_imageinfo_->
colorspace);
416std::vector<FUSE_imageinfo_t> &
433 local_version_ = local_version;
434 remote_version_ = remote_version;
458 fuse_message_->ref();
462 fuse_message_ = NULL;
466 case FUSE_MT_IMAGE_INFO:
try { fuse_imageinfo_ = m->msg_copy<
FUSE_imageinfo_t>();
468 fuse_imageinfo_ = NULL;
472 case FUSE_MT_IMAGE_INFO_FAILED: fuse_imageinfo_ = NULL;
break;
474 case FUSE_MT_GET_IMAGE_FAILED:
476 fuse_message_->unref();
478 fuse_message_ = NULL;
482 case FUSE_MT_IMAGE_LIST:
485 if (fuse_image_list) {
486 while (fuse_image_list->
has_next()) {
494 image_list_.push_back(ii);
Base class for exceptions in Fawkes.
Expected parameter is missing.
A NULL pointer was supplied where not allowed.
void unref()
Decrement reference count and conditionally delete this instance.
void start(bool wait=true)
Call this method to start the thread.
void join()
Join the thread.
void cancel()
Cancel a thread.
A class for handling time.
bool has(std::string s) const
Check if an parameter was given.
std::string get(std::string s) const
Get the value of the given parameter.
Capturing a frame failed.
void wait_greeting()
Wait for greeting message.
void enqueue_and_wait(FuseNetworkMessage *message)
Enqueue message and wait for reply.
void disconnect()
Disconnect.
size_t buffer_size() const
Get size of buffer.
unsigned int colorspace() const
Get colorspace.
fawkes::Time * capture_time() const
Get capture time.
unsigned char * buffer() const
Image buffer.
unsigned int pixel_height() const
Get image height.
unsigned int pixel_width() const
Get image width.
bool has_next()
Check if another image info is available.
FUSE_imageinfo_t * next()
Get next image info.
virtual void set_decompressed_buffer(unsigned char *buf, unsigned int buf_size)
Set decompressed buffer.
virtual void set_compressed_buffer(unsigned char *buf, unsigned int buf_size)
Set compressed buffer.
Decompressor for JPEG images.
virtual void decompress()
Decompress image.
virtual void open()
Open the camera.
virtual unsigned int pixel_height()
Height of image in pixels.
virtual ~NetworkCamera()
Destructor.
virtual void stop()
Stop image transfer from the camera.
virtual bool ready()
Camera is ready for taking pictures.
virtual std::vector< FUSE_imageinfo_t > & image_list()
List the available images.
virtual colorspace_t colorspace()
Colorspace of returned image.
virtual void fuse_inbound_received(FuseNetworkMessage *m) noexcept
Message received.
virtual void fuse_connection_established() noexcept
Connection has been established.
virtual void set_image_number(unsigned int n)
Set image number to retrieve.
virtual unsigned char * buffer()
Get access to current image buffer.
virtual void print_info()
Print out camera information.
virtual void fuse_connection_died() noexcept
Connection died.
virtual unsigned int buffer_size()
Size of buffer.
virtual void start()
Start image transfer from the camera.
virtual void flush()
Flush image queue.
NetworkCamera(const char *host, unsigned short port, bool jpeg=false)
Constructor.
virtual fawkes::Time * capture_time()
Get the Time of the last successfully captured image.
virtual void close()
Close camera.
virtual unsigned int pixel_width()
Width of image in pixels.
virtual void dispose_buffer()
Dispose current buffer.
virtual void set_image_id(const char *image_id)
Select the image that is opened.
virtual void capture()
Capture an image.
virtual void fuse_invalid_server_version(uint32_t local_version, uint32_t remote_version) noexcept
Invalid version string received.
Fawkes library namespace.
Image description message.
char image_id[IMAGE_ID_MAX_LENGTH]
image ID
uint32_t colorspace
color space
uint32_t height
height in pixels
uint32_t width
width in pixels
char image_id[IMAGE_ID_MAX_LENGTH]
image ID
uint32_t buffer_size
size of following image buffer in bytes
char image_id[IMAGE_ID_MAX_LENGTH]
image ID
uint32_t format
requested image format, see FUSE_image_format_t