further deprecate v4l2 tests and spacing

This commit is contained in:
Isaac Connor 2021-10-05 17:44:26 -04:00
parent c72d34f176
commit ba26235763
1 changed files with 199 additions and 213 deletions

View File

@ -49,8 +49,7 @@ static int vidioctl(int fd, int request, void *arg) {
static _AVPIXELFORMAT getFfPixFormatFromV4lPalette(int v4l_version, int palette) {
_AVPIXELFORMAT pixFormat = AV_PIX_FMT_NONE;
if ( v4l_version == 2 ) {
switch ( palette ) {
switch (palette) {
#if defined(V4L2_PIX_FMT_RGB444) && defined(AV_PIX_FMT_RGB444)
case V4L2_PIX_FMT_RGB444 :
pixFormat = AV_PIX_FMT_RGB444;
@ -172,7 +171,6 @@ static _AVPIXELFORMAT getFfPixFormatFromV4lPalette(int v4l_version, int palette)
#endif
}
} // end switch palette
} // end if v4l2
return pixFormat;
} // end getFfPixFormatFromV4lPalette
@ -289,7 +287,7 @@ LocalCamera::LocalCamera(
BigEndian = 0;
}
if (v4l_version == 2 && palette == 0) {
if (palette == 0) {
/* Use automatic format selection */
Debug(2,"Using automatic format selection");
palette = AutoSelectFormat(colours);
@ -310,9 +308,6 @@ LocalCamera::LocalCamera(
if (capture) {
if (last_camera) {
if ((p_method == "v4l2" && v4l_version != 2) || (p_method == "v4l1" && v4l_version != 1))
Fatal("Different Video For Linux version used for monitors sharing same device");
if (standard != last_camera->standard)
Warning("Different video standards defined for monitors sharing same device, results may be unpredictable or completely wrong");
@ -324,7 +319,7 @@ LocalCamera::LocalCamera(
}
/* Get ffmpeg pixel format based on capture palette and endianness */
capturePixFormat = getFfPixFormatFromV4lPalette( v4l_version, palette );
capturePixFormat = getFfPixFormatFromV4lPalette(v4l_version, palette);
imagePixFormat = AV_PIX_FMT_NONE;
}
@ -499,7 +494,6 @@ void LocalCamera::Initialise() {
if (!S_ISCHR(st.st_mode))
Fatal("File %s is not device file: %s", device.c_str(), strerror(errno));
Debug(2, "V4L2 support enabled, using V4L%d api", v4l_version);
struct v4l2_capability vid_cap;
Debug(3, "Checking video device capabilities");
@ -1209,17 +1203,15 @@ int LocalCamera::Contrast(int p_contrast) {
int LocalCamera::PrimeCapture() {
getVideoStream();
if ( !device_prime )
if (!device_prime)
return 1;
Debug(2, "Priming capture");
if ( v4l_version == 2 ) {
Debug(3, "Queueing (%d) buffers", v4l2_data.reqbufs.count);
for ( unsigned int frame = 0; frame < v4l2_data.reqbufs.count; frame++ ) {
for (unsigned int frame = 0; frame < v4l2_data.reqbufs.count; frame++) {
struct v4l2_buffer vid_buf;
memset(&vid_buf, 0, sizeof(vid_buf));
if ( v4l2_data.fmt.type != V4L2_BUF_TYPE_VIDEO_CAPTURE ) {
if (v4l2_data.fmt.type != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
Warning("Unknown type: (%d)", v4l2_data.fmt.type);
}
@ -1242,13 +1234,11 @@ int LocalCamera::PrimeCapture() {
Error("Failed to start capture stream: %s", strerror(errno));
return -1;
}
} // end if v4l_version == 2
return 1;
} // end LocalCamera::PrimeCapture
int LocalCamera::PreCapture() {
//Debug(5, "Pre-capturing");
return 1;
}
@ -1267,8 +1257,7 @@ int LocalCamera::Capture(std::shared_ptr<ZMPacket> &zm_packet) {
}
// Do the capture, unless we are the second or subsequent camera on a channel, in which case just reuse the buffer
if ( channel_prime ) {
if ( v4l_version == 2 ) {
if (channel_prime) {
static struct v4l2_buffer vid_buf;
memset(&vid_buf, 0, sizeof(vid_buf));
@ -1277,9 +1266,9 @@ int LocalCamera::Capture(std::shared_ptr<ZMPacket> &zm_packet) {
vid_buf.memory = v4l2_data.reqbufs.memory;
Debug(3, "Capturing %d frames", captures_per_frame);
while ( captures_per_frame ) {
if ( vidioctl(vid_fd, VIDIOC_DQBUF, &vid_buf) < 0 ) {
if ( errno == EIO ) {
while (captures_per_frame) {
if (vidioctl(vid_fd, VIDIOC_DQBUF, &vid_buf) < 0) {
if (errno == EIO) {
Warning("Capture failure, possible signal loss?: %s", strerror(errno));
} else {
Error("Unable to capture frame %d: %s", vid_buf.index, strerror(errno));
@ -1292,8 +1281,8 @@ int LocalCamera::Capture(std::shared_ptr<ZMPacket> &zm_packet) {
capture_frame = v4l2_data.bufptr->index;
bytes += vid_buf.bytesused;
if ( --captures_per_frame ) {
if ( vidioctl(vid_fd, VIDIOC_QBUF, &vid_buf) < 0 ) {
if (--captures_per_frame) {
if (vidioctl(vid_fd, VIDIOC_QBUF, &vid_buf) < 0) {
Error("Unable to requeue buffer %d: %s", vid_buf.index, strerror(errno));
return -1;
}
@ -1306,39 +1295,36 @@ int LocalCamera::Capture(std::shared_ptr<ZMPacket> &zm_packet) {
buffer_bytesused = v4l2_data.bufptr->bytesused;
bytes += buffer_bytesused;
if ( (v4l2_data.fmt.fmt.pix.width * v4l2_data.fmt.fmt.pix.height) > (width * height) ) {
if ((v4l2_data.fmt.fmt.pix.width * v4l2_data.fmt.fmt.pix.height) > (width * height)) {
Fatal("Captured image dimensions larger than image buffer: V4L2: %dx%d monitor: %dx%d",
v4l2_data.fmt.fmt.pix.width, v4l2_data.fmt.fmt.pix.height, width, height);
} else if ( (v4l2_data.fmt.fmt.pix.width * v4l2_data.fmt.fmt.pix.height) != (width * height) ) {
} else if ((v4l2_data.fmt.fmt.pix.width * v4l2_data.fmt.fmt.pix.height) != (width * height)) {
Error("Captured image dimensions differ: V4L2: %dx%d monitor: %dx%d",
v4l2_data.fmt.fmt.pix.width, v4l2_data.fmt.fmt.pix.height, width, height);
}
} // end if v4l2
if ( v4l_version == 2 ) {
if ( channel_count > 1 ) {
if (channel_count > 1) {
int next_channel = (channel_index+1)%channel_count;
Debug(3, "Switching video source to %d", channels[next_channel]);
if ( vidioctl(vid_fd, VIDIOC_S_INPUT, &channels[next_channel]) < 0 ) {
if (vidioctl(vid_fd, VIDIOC_S_INPUT, &channels[next_channel]) < 0) {
Error("Failed to set camera source %d: %s", channels[next_channel], strerror(errno));
return -1;
}
v4l2_std_id stdId = standards[next_channel];
if ( vidioctl(vid_fd, VIDIOC_S_STD, &stdId) < 0 ) {
if (vidioctl(vid_fd, VIDIOC_S_STD, &stdId) < 0) {
Error("Failed to set video format %d: %s", standards[next_channel], strerror(errno));
}
}
if ( v4l2_data.bufptr ) {
if (v4l2_data.bufptr) {
Debug(3, "Requeueing buffer %d", v4l2_data.bufptr->index);
if ( vidioctl(vid_fd, VIDIOC_QBUF, v4l2_data.bufptr) < 0 ) {
if (vidioctl(vid_fd, VIDIOC_QBUF, v4l2_data.bufptr) < 0) {
Error("Unable to requeue buffer %d: %s", v4l2_data.bufptr->index, strerror(errno));
return -1;
}
} else {
Error("Unable to requeue buffer due to not v4l2_data");
}
}
} /* prime capture */
if (!zm_packet->image) {