52 #ifndef VIEWVIDEO_DOWNSIZE_FACTOR
53 #define VIEWVIDEO_DOWNSIZE_FACTOR 4
58 #ifndef VIEWVIDEO_QUALITY_FACTOR
59 #define VIEWVIDEO_QUALITY_FACTOR 50
65 #define VIEWVIDEO_FPS 5
70 #ifndef VIEWVIDEO_NICE_LEVEL
71 #define VIEWVIDEO_NICE_LEVEL 5
76 #ifndef VIEWVIDEO_USE_NETCAT
77 #define VIEWVIDEO_USE_NETCAT FALSE
80 #if !VIEWVIDEO_USE_NETCAT && !(defined VIEWVIDEO_USE_RTP)
81 #define VIEWVIDEO_USE_RTP TRUE
84 #if VIEWVIDEO_USE_NETCAT
104 #if !VIEWVIDEO_USE_NETCAT
118 if(img_small->
buf != NULL){
128 if(img_jpeg->
w != img_small->
w || img_jpeg->
h != img_small->
h)
130 if(img_jpeg->
buf != NULL){
136 #if VIEWVIDEO_USE_NETCAT
138 sprintf(nc_cmd,
"nc %s %d 2>/dev/null", STRINGIFY(VIEWVIDEO_HOST), VIEWVIDEO_PORT_OUT);
150 #if VIEWVIDEO_USE_NETCAT
155 printf(
"[viewvideo] Could not create netcat fork.\n");
156 }
else if (pid == 0) {
158 FILE *netcat = popen(nc_cmd,
"w");
159 if (netcat != NULL) {
163 printf(
"[viewvideo] Failed to open netcat process.\n");
193 #ifdef VIEWVIDEO_CAMERA
194 static struct image_t *viewvideo_function1(
struct image_t *img,
uint8_t camera_id __attribute__((unused)))
198 static struct image_t img_small = {.
buf=NULL, .buf_size=0};
199 static struct image_t img_jpeg = {.
buf=NULL, .buf_size=0};
204 #ifdef VIEWVIDEO_CAMERA2
205 static struct image_t *viewvideo_function2(
struct image_t *img,
uint8_t camera_id __attribute__((unused)))
209 static struct image_t img_small = {.
buf=NULL, .buf_size=0};
210 static struct image_t img_jpeg = {.
buf=NULL, .buf_size=0};
231 #if VIEWVIDEO_USE_NETCAT
233 sprintf(save_name,
"%s/netcat-recv.sh", STRINGIFY(VIEWVIDEO_SHOT_PATH));
234 FILE *fp = fopen(save_name,
"w");
236 fprintf(fp,
"i=0\n");
237 fprintf(fp,
"while true\n");
239 fprintf(fp,
"\tn=$(printf \"%%04d\" $i)\n");
240 fprintf(fp,
"\tnc -l 0.0.0.0 %d > img_${n}.jpg\n", (
int)(VIEWVIDEO_PORT_OUT));
241 fprintf(fp,
"\ti=$((i+1))\n");
242 fprintf(fp,
"done\n");
245 printf(
"[viewvideo] Failed to create netcat receiver file.\n");
249 #ifdef VIEWVIDEO_CAMERA
251 printf(
"[viewvideo]: failed to open view video socket, HOST=%s, port=%d\n", STRINGIFY(VIEWVIDEO_HOST),
256 #ifdef VIEWVIDEO_CAMERA2
258 printf(
"[viewvideo]: failed to open view video socket, HOST=%s, port=%d\n", STRINGIFY(VIEWVIDEO_HOST),
259 VIEWVIDEO_PORT2_OUT);
264 #ifdef VIEWVIDEO_CAMERA
267 fprintf(stderr,
"[viewvideo] Added asynchronous video streamer listener for CAMERA1 at %u FPS \n",
VIEWVIDEO_FPS);
270 #ifdef VIEWVIDEO_CAMERA2
273 fprintf(stderr,
"[viewvideo] Added asynchronous video streamer listener for CAMERA2 at %u FPS \n",
VIEWVIDEO_FPS);
struct video_listener * cv_add_to_device_async(struct video_config_t *device, cv_function func, int nice_level, uint16_t fps, uint8_t id)
Computer vision framework for onboard processing.
void image_yuv422_downsample(struct image_t *input, struct image_t *output, uint8_t downsample)
Simplified high-speed low CPU downsample function without averaging downsample factor must be 1,...
void image_free(struct image_t *img)
Free the image.
void image_create(struct image_t *img, uint16_t width, uint16_t height, enum image_type type)
Create a new image.
Image helper functions like resizing, color filter, converters...
uint32_t buf_size
The buffer size.
void * buf
Image buffer (depending on the image_type)
@ IMAGE_YUV422
UYVY format (uint16 per pixel)
@ IMAGE_JPEG
An JPEG encoded image (not per pixel encoded)
PRINT_CONFIG_MSG("USE_INS_NAV_INIT defaulting to TRUE")
void jpeg_encode_image(struct image_t *in, struct image_t *out, uint32_t quality_factor, bool add_dri_header)
Encode an YUV422 image.
Encode images with the use of the JPEG encoding.
PRINT_CONFIG_VAR(ONELOOP_ANDI_FILT_CUTOFF)
void rtp_frame_send(struct UdpSocket *udp, struct image_t *img, uint8_t format_code, uint8_t quality_code, uint8_t has_dri_header, float average_frame_rate, uint16_t *packet_number, uint32_t *rtp_time_counter)
Send an RTP frame.
Encodes a video stream with RTP Format 26 (Motion JPEG)
int udp_socket_create(struct UdpSocket *sock, char *host, int port_out, int port_in, bool broadcast)
Create UDP socket and bind it.
Easily create and use UDP sockets.
struct UdpSocket video_sock1
#define VIEWVIDEO_USE_NETCAT
static struct image_t * viewvideo_function(struct UdpSocket *viewvideo_socket, struct image_t *img, uint16_t *rtp_packet_nr, uint32_t *rtp_frame_time, struct image_t *img_small, struct image_t *img_jpeg)
Handles all the video streaming and saving of the image shots This is a separate thread,...
struct viewvideo_t viewvideo
#define VIEWVIDEO_NICE_LEVEL
#define VIEWVIDEO_USE_RTP
#define VIEWVIDEO_DOWNSIZE_FACTOR
void viewvideo_init(void)
Initialize the view video.
#define VIEWVIDEO_QUALITY_FACTOR
struct UdpSocket video_sock2
Get live images from a RTP/UDP stream and save pictures on internal memory.
uint8_t downsize_factor
Downsize factor during the stream.
volatile bool is_streaming
When the device is streaming.
bool use_rtp
Stream over RTP.
uint8_t quality_factor
Quality factor during the stream.
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.