Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supported dynamic resolution change by DV timings & ioctl() timeout #164

Merged
merged 5 commits into from
Oct 14, 2018
Merged

Conversation

mdevaev
Copy link
Contributor

@mdevaev mdevaev commented Sep 12, 2018

input_uvc had two problems:

  1. It hangs if you disconnect the camera cable (or HDMI cable from capture board) while mjpg-streamer was running on ioctl(VIDIOC_DQBUF). I added select() befure this syscall and now mjpg streamer closes after timeout (5 sec. by default). It can be changed by option -timeout.

  2. When using video capture devices, it is possible to change the resolution spontaneously when changing the source. I added support of DV timings events and now mjpg-streamer don't hang on changing source disconnecting/connecting cable - it changes resolution automatically and and continues streaming. This behavior may be enabled by -dv_timings.

Both these changes are necessary for work Auvidea B101 board:
https://auvidea.com/b101-hdmi-to-csi-2-bridge-15-pin-fpc/

This is a very promising device for video processing. It's officially supports by Raspberry Pi team:
https://www.raspberrypi.org/forums/viewtopic.php?f=38&t=120702

May I ask you to take this patch as soon as possible? It is necessary for the open-source IP-KVM project that I develop. In addition, it will be very useful to everyone who uses devices that are disconnected from the PC.

Example for B101:

mjpg_streamer -i 'input_uvc.so -d /dev/video0 -u -n -timeout 1 -dv_timings' -o 'output_http.so -l 0.0.0.0 -p 8082'
MJPG Streamer Version.: 2.0
 i: Using V4L2 device.: /dev/video0
 i: Desired Resolution: 640 x 480
 i: Frames Per Second.: -1
 i: Format............: UYVY
 i: JPEG Quality......: 80
 i: TV-Norm...........: DEFAULT
 i: QUERY_DV_TIMINGS returned 640x480 pixclk 25200000
 o: www-folder-path......: disabled
 o: HTTP TCP port........: 8082
 o: HTTP Listen Address..: 0.0.0.0
 o: username:password....: disabled
 o: commands.............: enabled
# -------------------- hdmi cable disconnected
 i: select() timeout
 i: select() timeout
 i: select() timeout
 i: select() timeout
 i: select() timeout
 i: select() timeout
 i: select() timeout
 i: select() timeout
 i: select() timeout
 i: select() timeout
 i: select() timeout
# -------------------- connected hd source, streaming...
 i: QUERY_DV_TIMINGS returned 1920x1080 pixclk 148500000
# -------------------- hdmi cable disconnected
 i: select() timeout
 i: select() timeout
 i: select() timeout
 i: select() timeout
 i: select() timeout
# -------------------- connected old PC, streaming...
 i: QUERY_DV_TIMINGS returned 640x480 pixclk 25200000

PS: Sorry for my English.

input_uvc had two problems:

1) It hangs if you disconnect the camera cable (or HDMI cable from capture board) while mjpg-streamer was running on ioctl(VIDIOC_DQBUF). I added select() befure this syscall and now mjpg streamer closes after timeout (5 sec. by default). It can be changed by option -timeout.

2) When using video capture devices, it is possible to change the resolution spontaneously when changing the source. I added support of DV timings events and now mjpg-streamer don't hang on changing source disconnecting/connecting cable - it changes resolution automatically and and continues streaming.

Both these changes are necessary for work Auvidea B101 board:
https://auvidea.com/b101-hdmi-to-csi-2-bridge-15-pin-fpc/

This is a very promising device for video processing. It's officially supports by Raspberry Pi team:
https://www.raspberrypi.org/forums/viewtopic.php?f=38&t=120702
@mdevaev
Copy link
Contributor Author

mdevaev commented Sep 12, 2018

Also my patch fixes segfault on IN_CMD_RESOLUTION.
When changing the resolution from smaller to larger the image did not fit into framebuffer.

Copy link
Owner

@jacksonliam jacksonliam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this, resolution switching is something I've wanted for a while and I'm sure people will find the timeout useful.

However, I'm hoping you can disable the timeout by default, because some people might not want mjpg streamer to quit or may want it to wait a really long time.

mjpg-streamer-experimental/plugins/input_uvc/input_uvc.c Outdated Show resolved Hide resolved
@@ -74,6 +74,8 @@ static unsigned int every = 1;
static int wantTimestamp = 0;
static struct timeval timestamp;
static int softfps = -1;
static unsigned int timeout = 5;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can timeout be disabled by default? To keep current behaviour.

Copy link
Contributor Author

@mdevaev mdevaev Sep 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current behaviour is totally broken. You don't have any way to know that something went wrong while the program is running. If the connection to device is broken it will never be restored and the fd will be "dead". Mjpg-streamer will hang forever and you do not know why. If you have a timeout, at least you can restart the program.

For example, if mjpg-streamer works inside the camera firmware, the self-monitoring will restart stream in case of a problem if you have this timeout. With old behavior this is impossible, mjpg-streamer will remain frozen and broken.

Do you really want to keep this behavior?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mjpg-streamer-experimental/plugins/input_uvc/input_uvc.c Outdated Show resolved Hide resolved
pthread_mutex_unlock(&pglobal->in[pcontext->id].db);
}

other_select_handlers:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not crazy about the multiple gotos, but I guess this code not very well structured to start with and I can't see an quick way to fix it!

Copy link
Contributor Author

@mdevaev mdevaev Sep 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's an old problem of this function. I didn't want to modify the existing code too much to get a giant patch because I saw that you are working on something in this function. I plan to investigate the automatic resolution change and continue to implement the best support for B101 and maybe I will have to refactor. It seems to me that it is better to make other PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I refactored this code and moved events processing into a separate function.

@mdevaev
Copy link
Contributor Author

mdevaev commented Sep 24, 2018

BTW I started my own streamer project. Now it supports multi-threaded compression, hardware compression on Raspberry Pi using OpenMAX and dynamic resolution change. I managed to get a much larger FPS than in mjpg-streamer. Perhaps you will find it useful for yourself :)
https://github.com/pi-kvm/ustreamer

@jacksonliam jacksonliam merged commit 856d237 into jacksonliam:master Oct 14, 2018
@jacksonliam
Copy link
Owner

Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants