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 struct sockaddr *addr,
254 const socklen_t addr_size,
256 std::list<std::string> &txt,
260 struct sockaddr_in *s;
261 if ( addr_size ==
sizeof(
struct sockaddr_in) ) {
262 s = (
struct sockaddr_in *)addr;
264 printf(
"%s socket data not IPv4, ignoring\n", name);
268 char addrp[INET_ADDRSTRLEN];
269 inet_ntop(AF_INET, &(s->sin_addr), addrp,
sizeof(addrp));
270 printf(
"Found %s%s%s (%s/%s on %hu), querying\n",
273 __client =
new FuseClient(host_name, port,
this);
276 __client->wait_greeting();
294 printf(
"Usage: %s -i/-c/-C/-s/-e [-n host[:port]/id file]\n"
296 " -j Get JPEG-compressed image\n"
298 " -C Set colormap from file\n"
299 " -s Show available images and LUTs\n"
300 " -e Explore network. Will query all instances of Fountain\n"
301 " found on the network for all available images and LUTs.\n"
302 " -n net_string Open network camera, the camera string is of the form\n"
303 " host[:port]/id. You have to specify at least the host\n"
304 " and the id, the port is optional and defaults to 5000\n"
305 " Depending on the operation id is the image or the LUT ID\n"
306 " file File to write incoming data to or to read data to send from\n",
307 __argp->program_name());
320 strncpy(idm->
image_id, image_id, IMAGE_ID_MAX_LENGTH);
321 idm->
format = (jpeg ? FUSE_IF_JPEG : FUSE_IF_RAW);
333 strncpy(ldm->
lut_id, lut_id, LUT_ID_MAX_LENGTH);
358 __client->enqueue(FUSE_MT_GET_IMAGE_LIST);
359 __client->enqueue(FUSE_MT_GET_LUT_LIST);
372 __explore_mutex =
new Mutex();
375 __explore_mutex->lock();
378 __avahi_thread->start();
380 __avahi_thread->watch_service(
"_fountain._tcp",
this);
382 __explore_waitcond->wait();
383 delete __explore_waitcond;
384 __explore_mutex->unlock();
385 delete __explore_mutex;
386 __avahi_thread->cancel();
387 __avahi_thread->join();
388 delete __avahi_thread;
390 printf(
"\nExploration is not available because Avahi support is missing. "
391 "Install avahi-devel and recompile.\n\n");
399 if ( __argp->has_arg(
"h") ) {
404 if ( __argp->has_arg(
"n") ) {
405 net_string = strdup(__argp->arg(
"n"));
407 net_string = strdup(
"localhost");
409 char *
id = NULL, *host = NULL, *port = NULL, *save_ptr = NULL;
413 hostport = strtok_r(net_string,
"/", &save_ptr);
414 id = strtok_r(NULL,
"", &save_ptr);
416 if ( strchr(hostport,
':') != NULL ) {
417 host = strtok_r(hostport,
":", &save_ptr);
418 port = strtok_r(NULL,
"", &save_ptr);
423 if ( port != NULL ) {
424 port_num = atoi(port);
425 if ( (port_num < 0) || (port_num > 0xFFFF) ) {
430 if (__argp->has_arg(
"i") || __argp->has_arg(
"j") ||
431 __argp->has_arg(
"c") || __argp->has_arg(
"C")) {
432 if ( __argp->num_items() == 0 ) {
434 printf(
"\nFile name missing\n\n");
437 __file = __argp->items()[0];
442 printf(
"\nNo Image/LUT ID given, needed for -i/-c/-C\n\n");
447 if ( ! __argp->has_arg(
"e") ) {
448 __client =
new FuseClient(host, port_num,
this);
451 __client->wait_greeting();
454 if ( __argp->has_arg(
"i") ) {
455 get_image(
id,
false);
456 }
else if ( __argp->has_arg(
"j") ) {
458 }
else if ( __argp->has_arg(
"c") ) {
460 }
else if ( __argp->has_arg(
"C") ) {
462 }
else if ( __argp->has_arg(
"s") ) {
464 }
else if ( __argp->has_arg(
"e") ) {
471 if ( ! __argp->has_arg(
"e") ) {
487 Mutex *__explore_mutex;
497 main(
int argc,
char **argv)
uint32_t bytes_per_cell
bytes per cell
unsigned int pixel_width() const
Get image width.
size_t buffer_size() const
Get size of buffer.
Wait until a given condition holds.
FUSE lookup table content.
void add_colormap(Colormap *colormap)
Add colormap.
virtual unsigned int depth() const =0
Get depth of colormap.
Fawkes library namespace.
uint32_t height
height of LUT
Parse command line arguments.
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.
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
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
FvRaw Writer implementation.
Base class for exceptions in Fawkes.
char lut_id[LUT_ID_MAX_LENGTH]
LUT ID.
FUSE lookup table list content.
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.
unsigned int height() const
Height of LUT.
bool has_next()
Check if another image info is available.
char image_id[IMAGE_ID_MAX_LENGTH]
image ID
unsigned int width() const
Width of LUT.
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
unsigned char * buffer() const
Image buffer.
bool has_next()
Check if another LUT info is available.
unsigned int depth() const
Depth of LUT.
unsigned char * buffer() const
Get buffer.
virtual unsigned char * get_buffer() const =0
Get the raw buffer of this colormap.
Mutex mutual exclusion lock.
uint32_t depth
depth of LUT
unsigned int pixel_height() const
Get image height.
FUSE_imageinfo_t * next()
Get next image info.
unsigned int format() const
Get image format.
unsigned int colorspace() const
Get colorspace.
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.