filesink: Fix stack overflow when writing huge buffer lists and implement proper full buffer mode
On top of !409 (merged)
commit f267d6cadd2a0d619666e8725a309bb5b4608f5d (HEAD -> filesink-write-stackoverflow, gitlab-slomo/filesink-write-stackoverflow)
Author: Sebastian Dröge <sebastian@centricular.com>
Date: Fri Mar 20 19:28:37 2020 +0200
filesink: Add a new full buffer mode to filesink
Previously the default and full modes were the same. Now the default
mode is like before: it accumulates all buffers in a buffer list until
the threshold is reached and then writes them all out, potentially in
multiple writes.
The new full mode works by always copying memory to a single memory area
and writing everything out with a single write once the threshold is
reached.
commit 16ace35b4d8fd44058d0680ffded45105f54f371
Author: Sebastian Dröge <sebastian@centricular.com>
Date: Fri Mar 20 18:43:30 2020 +0200
fdsink/filesink: Refactor writev() code to prevent stack overflows
If buffer lists with too many buffers would be written before, a stack
overflow would happen because of memory linear with the number of
GstMemory would be allocated on the stack. This could happen for example
when filesink is configured with a very big buffer size.
Instead now move the buffer and buffer list writing into the helper
functions and at most write IOV_MAX memories at once. Anything bigger
than that wouldn't be passed to writev() anyway and written differently
in the previous code, so this also potentially speeds up writing for
these cases.
For example the following pipeline would crash with a stackoverflow:
gst-launch-1.0 audiotestsrc ! filesink buffer-size=1073741824 location=/dev/null
CC @tpm