Merge pull request #1426 from paparazzi/netcat

[cv] fix netcat video module
This commit is contained in:
Felix Ruess
2015-11-19 17:01:02 +01:00
4 changed files with 36 additions and 18 deletions
@@ -40,9 +40,10 @@
<define name="VIDEO_THREAD_CAMERA" value="front_camera"/>
</load>
<load name="video_rtp_stream.xml">
<configure name="VIEWVIDEO_USE_NC" value="TRUE"/>
<configure name="VIEWVIDEO_USE_NETCAT" value="FALSE"/>
</load>
<load name="rotorcraft_cam.xml"/>
<load name="bat_voltage_ardrone2.xml"/>
</modules>
<!-- include common control -->
+2 -2
View File
@@ -46,10 +46,10 @@
BEBOP_FRONT_CAMERA_BROADCAST ?= $(MODEM_BROADCAST)
BEBOPVIEWVID_CFLAGS = -DBEBOP_FRONT_CAMERA_HOST=$(BEBOP_FRONT_CAMERA_HOST) -DBEBOP_FRONT_CAMERA_PORT_OUT=$(BEBOP_FRONT_CAMERA_PORT_OUT)
ifeq ($(BEBOP_FRONT_CAMERA_USE_NC),)
ifeq ($(BEBOP_FRONT_CAMERA_USE_NETCAT),)
ap.CFLAGS += $(BEBOPVIEWVID_CFLAGS) -DBEBOP_FRONT_CAMERA_BROADCAST=$(BEBOP_FRONT_CAMERA_BROADCAST)
else
ap.CFLAGS += $(BEBOPVIEWVID_CFLAGS) -DBEBOP_FRONT_CAMERA_USE_NC
ap.CFLAGS += $(BEBOPVIEWVID_CFLAGS) -DBEBOP_FRONT_CAMERA_USE_NETCAT
endif
</raw>
+6 -4
View File
@@ -10,10 +10,11 @@
- Possibility to save an image(shot) on internal or external storage space even in full size, best quality
Example to add to ARdrone2 airframe with extra USB stick plugger in:
</description>
<configure name="VIEWVIDEO_USE_NETCAT" value="FALSE|TRUE" description="Use netcat for transfering images instead of RTP stream (default: FALSE)"/>
<configure name="VIEWVIDEO_HOST" value="192.168.1.255" description="GCS IP (default: MODEM_HOST)"/>
<define name="VIEWVIDEO_DOWNSIZE_FACTOR" value="4" description="Reduction factor of the video stream"/>
<define name="VIEWVIDEO_QUALITY_FACTOR" value="50" description="JPEG encoding compression factor [0-99]"/>
<define name="VIEWVIDEO_USE_NETCAT" value="FALSE|TRUE" description="Use netcat for transfering images (default: FALSE)"/>
<define name="VIEWVIDEO_USE_RTP" value="TRUE|FALSE" description="Use RTP for transfering images (default: TRUE)"/>
<define name="VIEWVIDEO_USE_RTP" value="TRUE|FALSE" description="Enable RTP at startup for transfering images (default: TRUE)"/>
</doc>
<settings>
<dl_settings>
@@ -41,13 +42,14 @@
VIEWVIDEO_HOST ?= $(MODEM_HOST)
VIEWVIDEO_PORT_OUT ?= 5000
VIEWVIDEO_BROADCAST ?= $(MODEM_BROADCAST)
VIEWVIDEO_USE_NETCAT ?= FALSE
VIEWVID_CFLAGS = -DVIEWVIDEO_HOST=$(VIEWVIDEO_HOST) -DVIEWVIDEO_PORT_OUT=$(VIEWVIDEO_PORT_OUT)
ifeq ($(VIEWVIDEO_USE_NC),)
ifneq (,$(findstring $(VIEWVIDEO_USE_NETCAT),0 FALSE))
ap.CFLAGS += $(VIEWVID_CFLAGS) -DVIEWVIDEO_BROADCAST=$(VIEWVIDEO_BROADCAST)
nps.CFLAGS += $(VIEWVID_CFLAGS) -DVIEWVIDEO_BROADCAST=FALSE
else
$(TARGET).CFLAGS += $(VIEWVID_CFLAGS) -DVIEWVIDEO_USE_NC
$(TARGET).CFLAGS += $(VIEWVID_CFLAGS) -DVIEWVIDEO_USE_NETCAT
endif
</raw>
+26 -11
View File
@@ -64,22 +64,32 @@ PRINT_CONFIG_VAR(VIEWVIDEO_QUALITY_FACTOR)
#endif
PRINT_CONFIG_VAR(VIEWVIDEO_RTP_TIME_INC)
// Default image folder
#ifndef VIEWVIDEO_SHOT_PATH
#ifdef VIDEO_THREAD_SHOT_PATH
#define VIEWVIDEO_SHOT_PATH VIDEO_THREAD_SHOT_PATH
#else
#define VIEWVIDEO_SHOT_PATH /data/video/images
#endif
#endif
PRINT_CONFIG_VAR(VIEWVIDEO_SHOT_PATH)
// Check if we are using netcat instead of RTP/UDP
#ifndef VIEWVIDEO_USE_NETCAT
#define VIEWVIDEO_USE_NETCAT FALSE
#endif
#ifndef VIEWVIDEO_USE_RTP
#if !VIEWVIDEO_USE_NETCAT && !(defined VIEWVIDEO_USE_RTP)
#define VIEWVIDEO_USE_RTP TRUE
#endif
#if VIEWVIDEO_USE_NETCAT && VIEWVIDEO_USE_RTP
#error "Can't set VIEWVIDEO_USE_NETCAT and VIEWVIDEO_USE_RTP to true at the same time."
#endif
#if VIEWVIDEO_USE_NETCAT
#include <sys/wait.h>
PRINT_CONFIG_MSG("[viewvideo] Using netcat.")
#elif VIEWVIDEO_USE_RTP
#else
struct UdpSocket video_sock;
PRINT_CONFIG_MSG("[viewvideo] Using RTP/UDP stream.")
PRINT_CONFIG_VAR(VIEWVIDEO_USE_RTP)
#endif
/* These are defined with configure */
@@ -91,14 +101,15 @@ struct viewvideo_t viewvideo = {
.is_streaming = FALSE,
.downsize_factor = VIEWVIDEO_DOWNSIZE_FACTOR,
.quality_factor = VIEWVIDEO_QUALITY_FACTOR,
#if !VIEWVIDEO_USE_NETCAT
.use_rtp = VIEWVIDEO_USE_RTP,
#endif
};
/**
* Handles all the video streaming and saving of the image shots
* This is a sepereate thread, so it needs to be thread safe!
*/
struct UdpSocket video_sock;
bool_t viewvideo_function(struct image_t *img);
bool_t viewvideo_function(struct image_t *img)
{
@@ -116,7 +127,6 @@ bool_t viewvideo_function(struct image_t *img)
#if VIEWVIDEO_USE_NETCAT
char nc_cmd[64];
sprintf(nc_cmd, "nc %s %d 2>/dev/null", STRINGIFY(VIEWVIDEO_HOST), VIEWVIDEO_PORT_OUT);
#else
#endif
if (viewvideo.is_streaming) {
@@ -139,7 +149,7 @@ bool_t viewvideo_function(struct image_t *img)
// We are the child and want to send the image
FILE *netcat = popen(nc_cmd, "w");
if (netcat != NULL) {
fwrite(jpegbuf, sizeof(uint8_t), size, netcat);
fwrite(img_jpeg.buf, sizeof(uint8_t), img_jpeg.buf_size, netcat);
pclose(netcat); // Ignore output, because it is too much when not connected
} else {
printf("[viewvideo] Failed to open netcat process.\n");
@@ -188,8 +198,6 @@ bool_t viewvideo_function(struct image_t *img)
void viewvideo_init(void)
{
char save_name[512];
// struct UdpSocket video_sock;
udp_socket_create(&video_sock, STRINGIFY(VIEWVIDEO_HOST), VIEWVIDEO_PORT_OUT, -1, VIEWVIDEO_BROADCAST);
cv_add(viewvideo_function);
@@ -208,8 +216,13 @@ void viewvideo_init(void)
fprintf(fp, "\ti=$((i+1))\n");
fprintf(fp, "done\n");
fclose(fp);
} else {
printf("[viewvideo] Failed to create netcat receiver file.\n");
}
#else
// Open udp socket
udp_socket_create(&video_sock, STRINGIFY(VIEWVIDEO_HOST), VIEWVIDEO_PORT_OUT, -1, VIEWVIDEO_BROADCAST);
// Create an SDP file for the streaming
sprintf(save_name, "%s/stream.sdp", STRINGIFY(VIEWVIDEO_SHOT_PATH));
FILE *fp = fopen(save_name, "w");
@@ -218,6 +231,8 @@ void viewvideo_init(void)
fprintf(fp, "m=video %d RTP/AVP 26\n", (int)(VIEWVIDEO_PORT_OUT));
fprintf(fp, "c=IN IP4 0.0.0.0\n");
fclose(fp);
} else {
printf("[viewvideo] Failed to create SDP file.\n");
}
#endif
}