summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Burchell <robin.burchell@crimson.no>2021-04-06 13:22:15 +0200
committerTim-Philipp Müller <tim@centricular.com>2021-04-13 16:30:14 +0100
commitbbc4d2cf305ed3ca9f2a78c0271afaccea876bf0 (patch)
tree0aadec5d6064fb538749fc2123dded990e57d0c5
parent92afe79be011c182e697a195fd4e92f8b3a6b65b (diff)
downloadgstreamer-plugins-base-bbc4d2cf305ed3ca9f2a78c0271afaccea876bf0.tar.gz
gstgiobasesink: Handle incomplete writes in gst_gio_base_sink_render()
As the comment asked, yes, incomplete writes can happen. I have encountered this with an sshfs mount, for example. It seems like g_output_stream_write_all() is designed to handle this case, by not returning until the requested buffer has been completely written, or an error occurs, which seems to match up with the desired behaviour. Fixes https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/issues/885 Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/merge_requests/1108>
-rw-r--r--gst/gio/gstgiobasesink.c22
1 files changed, 5 insertions, 17 deletions
diff --git a/gst/gio/gstgiobasesink.c b/gst/gio/gstgiobasesink.c
index 6a8f5b191..cbd400492 100644
--- a/gst/gio/gstgiobasesink.c
+++ b/gst/gio/gstgiobasesink.c
@@ -263,7 +263,7 @@ static GstFlowReturn
gst_gio_base_sink_render (GstBaseSink * base_sink, GstBuffer * buffer)
{
GstGioBaseSink *sink = GST_GIO_BASE_SINK (base_sink);
- gssize written;
+ gsize written;
GstMapInfo map;
gboolean success;
GError *err = NULL;
@@ -276,23 +276,11 @@ gst_gio_base_sink_render (GstBaseSink * base_sink, GstBuffer * buffer)
"writing %" G_GSIZE_FORMAT " bytes to offset %" G_GUINT64_FORMAT,
map.size, sink->position);
- written =
- g_output_stream_write (sink->stream, map.data, map.size, sink->cancel,
- &err);
+ success =
+ g_output_stream_write_all (sink->stream, map.data, map.size, &written,
+ sink->cancel, &err);
gst_buffer_unmap (buffer, &map);
- success = (written >= 0);
-
- if (G_UNLIKELY (success && written < map.size)) {
- /* FIXME: Can this happen? Should we handle it gracefully? gnomevfssink
- * doesn't... */
- GST_ELEMENT_ERROR (sink, RESOURCE, WRITE, (NULL),
- ("Could not write to stream: (short write, only %"
- G_GSSIZE_FORMAT " bytes of %" G_GSIZE_FORMAT " bytes written)",
- written, map.size));
- return GST_FLOW_ERROR;
- }
-
if (success) {
sink->position += written;
return GST_FLOW_OK;
@@ -300,7 +288,7 @@ gst_gio_base_sink_render (GstBaseSink * base_sink, GstBuffer * buffer)
} else {
GstFlowReturn ret;
- if (!gst_gio_error (sink, "g_output_stream_write", &err, &ret)) {
+ if (!gst_gio_error (sink, "g_output_stream_write_all", &err, &ret)) {
if (GST_GIO_ERROR_MATCHES (err, NO_SPACE)) {
GST_ELEMENT_ERROR (sink, RESOURCE, NO_SPACE_LEFT, (NULL),
("Could not write to stream: %s", err->message));