23 #include <fvutils/net/fuse.h> 24 #include <fvutils/net/fuse_client.h> 25 #include <fvutils/net/fuse_client_handler.h> 26 #include <fvutils/net/fuse_message.h> 27 #include <fvutils/net/fuse_image_content.h> 28 #include <fvutils/net/fuse_lut_content.h> 29 #include <fvutils/net/fuse_imagelist_content.h> 30 #include <fvutils/net/fuse_lutlist_content.h> 31 #include <fvutils/writers/fvraw.h> 32 #include <fvutils/color/colorspaces.h> 33 #include <fvutils/colormap/yuvcm.h> 34 #include <fvutils/colormap/cmfile.h> 36 #include <core/threading/mutex.h> 37 #include <core/threading/wait_condition.h> 38 #include <core/exceptions/software.h> 39 #include <utils/system/argparser.h> 40 #include <utils/system/console_colors.h> 42 #include <netcomm/service_discovery/browse_handler.h> 44 #include <netcomm/dns-sd/avahi_thread.h> 48 #include <arpa/inet.h> 49 #include <netinet/in.h> 70 __explore_waitcond = NULL;
75 uint32_t remote_version)
throw()
77 printf(
"Invalid version received (local: %u, remote: %u)\n",
78 local_version, remote_version);
101 if ( ic->
format() == FUSE_IF_RAW ) {
106 }
else if ( ic->
format() == FUSE_IF_JPEG ) {
107 FILE *f = fopen(__file,
"w");
109 printf(
"Failed to write data to file");
113 printf(
"Image of unknown format (%u) received.\n", ic->
format());
117 printf(
"Received message cannot be casted to FuseImageMessage\n");
122 case FUSE_MT_IMAGE_LIST:
126 printf(
"Available images:\n");
129 char tmp[IMAGE_ID_MAX_LENGTH + 1];
130 tmp[IMAGE_ID_MAX_LENGTH] = 0;
131 strncpy(tmp, ii->
image_id, IMAGE_ID_MAX_LENGTH);
132 printf(
" %s (%u x %u, %s)\n", tmp, ntohl(ii->
width), ntohl(ii->
height),
133 colorspace_to_string((colorspace_t)ntohs(ii->
colorspace)));
136 printf(
"No images available\n");
140 printf(
"Received message cannot be casted to FuseImageListMessage\n");
144 case FUSE_MT_LUT_LIST:
148 printf(
"Available lookup tables:\n");
151 char tmp[LUT_ID_MAX_LENGTH + 1];
152 tmp[LUT_ID_MAX_LENGTH] = 0;
153 strncpy(tmp, li->
lut_id, LUT_ID_MAX_LENGTH);
154 printf(
" %s (%u x %u x %u, %u bpc)\n", tmp,
159 printf(
"No lookup tables available\n");
163 printf(
"Received message cannot be casted to FuseImageListMessage\n");
174 if ( lc->
width() != 256 ) {
175 printf(
"Invalid dimensions for LUT received, colormap width %u != 256", lc->
width());
176 }
else if ( lc->
height() != 256 ) {
177 printf(
"Invalid dimensions for LUT received, colormap height %u != 256", lc->
height());
178 }
else if ( lc->
depth() > 256 ) {
179 printf(
"Invalid dimensions for LUT received, colormap depth %u > 256", lc->
depth());
188 e.
append(
"Failed to save colormap");
194 printf(
"Received message cannot be casted to FuseLutMessage\n");
200 case FUSE_MT_SET_LUT_SUCCEEDED:
203 char lut_id[LUT_ID_MAX_LENGTH + 1];
204 lut_id[LUT_ID_MAX_LENGTH] = 0;
205 strncpy(lut_id, lutdesc->
lut_id, LUT_ID_MAX_LENGTH);
206 printf(
"LUT %s has been uploaded successfully.\n", lut_id);
211 case FUSE_MT_SET_LUT_FAILED:
214 char lut_id[LUT_ID_MAX_LENGTH + 1];
215 lut_id[LUT_ID_MAX_LENGTH] = 0;
216 strncpy(lut_id, lutdesc->
lut_id, LUT_ID_MAX_LENGTH);
217 printf(
"LUT upload of %s has failed.\n", lut_id);
223 printf(
"Unhandled message of type %u received\n", m->type());
232 printf(
"All for now\n");
233 __explore_mutex->lock();
234 __explore_waitcond->wake_all();
235 __explore_mutex->unlock();
246 printf(
"Browsing for %s failed\n", type);
252 const char *host_name,
253 const char *interface,
254 const struct sockaddr *addr,
255 const socklen_t addr_size,
257 std::list<std::string> &txt,
261 struct sockaddr_in *s;
262 if ( addr_size ==
sizeof(
struct sockaddr_in) ) {
263 s = (
struct sockaddr_in *)addr;
265 printf(
"%s socket data not IPv4, ignoring\n", name);
269 char addrp[INET_ADDRSTRLEN];
270 inet_ntop(AF_INET, &(s->sin_addr), addrp,
sizeof(addrp));
271 printf(
"Found %s%s%s (%s/%s on %hu), querying\n",
274 __client =
new FuseClient(host_name, port,
this);
277 __client->wait_greeting();
295 printf(
"Usage: %s -i/-c/-C/-s/-e [-n host[:port]/id file]\n" 297 " -j Get JPEG-compressed image\n" 299 " -C Set colormap from file\n" 300 " -s Show available images and LUTs\n" 301 " -e Explore network. Will query all instances of Fountain\n" 302 " found on the network for all available images and LUTs.\n" 303 " -n net_string Open network camera, the camera string is of the form\n" 304 " host[:port]/id. You have to specify at least the host\n" 305 " and the id, the port is optional and defaults to 5000\n" 306 " Depending on the operation id is the image or the LUT ID\n" 307 " file File to write incoming data to or to read data to send from\n",
308 __argp->program_name());
321 strncpy(idm->
image_id, image_id, IMAGE_ID_MAX_LENGTH);
322 idm->
format = (jpeg ? FUSE_IF_JPEG : FUSE_IF_RAW);
334 strncpy(ldm->
lut_id, lut_id, LUT_ID_MAX_LENGTH);
359 __client->enqueue(FUSE_MT_GET_IMAGE_LIST);
360 __client->enqueue(FUSE_MT_GET_LUT_LIST);
373 __explore_mutex =
new Mutex();
376 __explore_mutex->lock();
379 __avahi_thread->start();
381 __avahi_thread->watch_service(
"_fountain._tcp",
this);
383 __explore_waitcond->wait();
384 delete __explore_waitcond;
385 __explore_mutex->unlock();
386 delete __explore_mutex;
387 __avahi_thread->cancel();
388 __avahi_thread->join();
389 delete __avahi_thread;
391 printf(
"\nExploration is not available because Avahi support is missing. " 392 "Install avahi-devel and recompile.\n\n");
400 if ( __argp->has_arg(
"h") ) {
405 if ( __argp->has_arg(
"n") ) {
406 net_string = strdup(__argp->arg(
"n"));
408 net_string = strdup(
"localhost");
410 char *
id = NULL, *host = NULL, *port = NULL, *save_ptr = NULL;
414 hostport = strtok_r(net_string,
"/", &save_ptr);
415 id = strtok_r(NULL,
"", &save_ptr);
417 if ( strchr(hostport,
':') != NULL ) {
418 host = strtok_r(hostport,
":", &save_ptr);
419 port = strtok_r(NULL,
"", &save_ptr);
424 if ( port != NULL ) {
425 port_num = atoi(port);
426 if ( (port_num < 0) || (port_num > 0xFFFF) ) {
431 if (__argp->has_arg(
"i") || __argp->has_arg(
"j") ||
432 __argp->has_arg(
"c") || __argp->has_arg(
"C")) {
433 if ( __argp->num_items() == 0 ) {
435 printf(
"\nFile name missing\n\n");
438 __file = __argp->items()[0];
443 printf(
"\nNo Image/LUT ID given, needed for -i/-c/-C\n\n");
448 if ( ! __argp->has_arg(
"e") ) {
449 __client =
new FuseClient(host, port_num,
this);
452 __client->wait_greeting();
455 if ( __argp->has_arg(
"i") ) {
456 get_image(
id,
false);
457 }
else if ( __argp->has_arg(
"j") ) {
459 }
else if ( __argp->has_arg(
"c") ) {
461 }
else if ( __argp->has_arg(
"C") ) {
463 }
else if ( __argp->has_arg(
"s") ) {
465 }
else if ( __argp->has_arg(
"e") ) {
472 if ( ! __argp->has_arg(
"e") ) {
488 Mutex *__explore_mutex;
498 main(
int argc,
char **argv)
uint32_t bytes_per_cell
bytes per cell
Wait until a given condition holds.
FUSE lookup table content.
unsigned int depth() const
Depth of LUT.
void add_colormap(Colormap *colormap)
Add colormap.
virtual unsigned int depth() const =0
Get depth of colormap.
Fawkes library namespace.
unsigned char * buffer() const
Image buffer.
unsigned int width() const
Width of LUT.
uint32_t height
height of LUT
Parse command line arguments.
unsigned char * buffer() const
Get buffer.
virtual unsigned int height() const =0
Get height of colormap.
FUSE_lutinfo_t * next()
Get next LUT info.
static const char * c_blue
Print blue on console.
unsigned int pixel_width() const
Get image width.
uint32_t width
width of LUT
Colormap * get_colormap()
Get a freshly generated colormap based on current file content.
Interface for class that process browse results.
uint32_t width
width in pixels
uint32_t colorspace
color space
unsigned int pixel_height() const
Get image height.
virtual void write(const char *file_name)
Write file.
virtual void read(const char *file_name)
Read file.
char image_id[IMAGE_ID_MAX_LENGTH]
image ID
unsigned int height() const
Height of LUT.
FvRaw Writer implementation.
Base class for exceptions in Fawkes.
size_t buffer_size() const
Get size of buffer.
char lut_id[LUT_ID_MAX_LENGTH]
LUT ID.
FUSE lookup table list content.
unsigned int format() const
Get image format.
virtual void set(unsigned int y, unsigned int u, unsigned int v, color_t c)
Set color class for given YUV value.
virtual void write()
Write to file.
bool has_next()
Check if another image info is available.
char image_id[IMAGE_ID_MAX_LENGTH]
image ID
unsigned int colorspace() const
Get colorspace.
virtual unsigned int width() const =0
Get width of colormap.
void print_trace()
Prints trace to stderr.
char lut_id[LUT_ID_MAX_LENGTH]
LUT ID.
uint32_t format
requested image format, see FUSE_image_format_t
uint32_t height
height in pixels
bool has_next()
Check if another LUT info is available.
virtual unsigned char * get_buffer() const =0
Get the raw buffer of this colormap.
Mutex mutual exclusion lock.
uint32_t depth
depth of LUT
FUSE_imageinfo_t * next()
Get next image info.
static const char * c_normal
Print normal on console, without colors, depends on console settings.
void append(const char *format,...)
Append messages to the message list.