Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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/1100>
  • Loading branch information
rburchell authored and GStreamer Marge Bot committed Apr 9, 2021
1 parent b70e83c commit 1a1a885
Showing 1 changed file with 5 additions and 17 deletions.
22 changes: 5 additions & 17 deletions gst/gio/gstgiobasesink.c
Expand Up @@ -264,7 +264,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;
Expand All @@ -277,31 +277,19 @@ 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;

} 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));
Expand Down

0 comments on commit 1a1a885

Please sign in to comment.