mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-04 16:39:39 +00:00
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>
This commit is contained in:
parent
b70e83c409
commit
1a1a885db4
1 changed files with 5 additions and 17 deletions
|
@ -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;
|
||||
|
@ -277,23 +277,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;
|
||||
|
@ -301,7 +289,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));
|
||||
|
|
Loading…
Reference in a new issue