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
99#ifndef VIEWVIDEO_AUTO_HOST
100#define VIEWVIDEO_AUTO_HOST 0
102#if VIEWVIDEO_AUTO_HOST
103#include "mcu_periph/udp_arch.h"
104#ifndef VIEWVIDEO_AUTO_MAX_GCS
105#define VIEWVIDEO_AUTO_MAX_GCS 4
107#define VIEWVIDEO_SOCKET_HOST "255.255.255.255"
108#define VIEWVIDEO_SOCKET_BROADCAST true
110#define VIEWVIDEO_SOCKET_HOST STRINGIFY(VIEWVIDEO_HOST)
111#define VIEWVIDEO_SOCKET_BROADCAST VIEWVIDEO_BROADCAST
118 .is_streaming =
FALSE,
121#if !VIEWVIDEO_USE_NETCAT
135 if(img_small->
buf != NULL){
145 if(img_jpeg->
w != img_small->
w || img_jpeg->
h != img_small->
h)
147 if(img_jpeg->
buf != NULL){
153#if VIEWVIDEO_USE_NETCAT
155 sprintf(nc_cmd,
"nc %s %d 2>/dev/null", STRINGIFY(VIEWVIDEO_HOST), VIEWVIDEO_PORT_OUT);
167#if VIEWVIDEO_USE_NETCAT
172 printf(
"[viewvideo] Could not create netcat fork.\n");
173 }
else if (pid == 0) {
175 FILE *netcat = popen(nc_cmd,
"w");
176 if (netcat != NULL) {
180 printf(
"[viewvideo] Failed to open netcat process.\n");
191#if VIEWVIDEO_AUTO_HOST
194 struct in_addr gcs[VIEWVIDEO_AUTO_MAX_GCS];
196 uint16_t packet_nr = *rtp_packet_nr;
197 uint32_t frame_time = *rtp_frame_time;
198 for (
int i = 0; i < (nb_gcs > 0 ? nb_gcs : 1); i++) {
199 viewvideo_socket->
addr_out.sin_addr.s_addr = nb_gcs > 0 ? gcs[i].s_addr : htonl(INADDR_BROADCAST);
200 *rtp_packet_nr = packet_nr;
201 *rtp_frame_time = frame_time;
203 rtp_packet_nr, rtp_frame_time);
226#ifdef VIEWVIDEO_CAMERA
227static struct image_t *viewvideo_function1(
struct image_t *img,
uint8_t camera_id __attribute__((unused)))
231 static struct image_t img_small = {.buf=NULL, .buf_size=0};
232 static struct image_t img_jpeg = {.buf=NULL, .buf_size=0};
237#ifdef VIEWVIDEO_CAMERA2
238static struct image_t *viewvideo_function2(
struct image_t *img,
uint8_t camera_id __attribute__((unused)))
242 static struct image_t img_small = {.buf=NULL, .buf_size=0};
243 static struct image_t img_jpeg = {.buf=NULL, .buf_size=0};
264#if VIEWVIDEO_USE_NETCAT
266 sprintf(save_name,
"%s/netcat-recv.sh", STRINGIFY(VIEWVIDEO_SHOT_PATH));
267 FILE *fp = fopen(save_name,
"w");
269 fprintf(fp,
"i=0\n");
270 fprintf(fp,
"while true\n");
272 fprintf(fp,
"\tn=$(printf \"%%04d\" $i)\n");
273 fprintf(fp,
"\tnc -l 0.0.0.0 %d > img_${n}.jpg\n", (
int)(VIEWVIDEO_PORT_OUT));
274 fprintf(fp,
"\ti=$((i+1))\n");
275 fprintf(fp,
"done\n");
278 printf(
"[viewvideo] Failed to create netcat receiver file.\n");
282#ifdef VIEWVIDEO_CAMERA
284 printf(
"[viewvideo]: failed to open view video socket, HOST=%s, port=%d\n", STRINGIFY(VIEWVIDEO_HOST),
289#ifdef VIEWVIDEO_CAMERA2
291 printf(
"[viewvideo]: failed to open view video socket, HOST=%s, port=%d\n", STRINGIFY(VIEWVIDEO_HOST),
292 VIEWVIDEO_PORT2_OUT);
297#ifdef VIEWVIDEO_CAMERA
300 fprintf(stderr,
"[viewvideo] Added asynchronous video streamer listener for CAMERA1 at %u FPS \n",
VIEWVIDEO_FPS);
303#ifdef VIEWVIDEO_CAMERA2
306 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.
int udp_arch_auto_gcs(struct in_addr *addr, int max)
GCS computers found by the links with host "auto", each IP address once.
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 sockaddr_in addr_out
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 UdpSocket video_sock1
#define VIEWVIDEO_USE_NETCAT
#define VIEWVIDEO_SOCKET_BROADCAST
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
#define VIEWVIDEO_SOCKET_HOST
Get live images from a RTP/UDP stream and save pictures on internal memory.
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.