adaptivedemux2/downloadhelper: Ignore spurious read failure

Sometimes g_input_stream_read_all_finish() can return
0 bytes, but still succeed (return TRUE) and have more
data available later. Only finish the transfer
if it returns 0 bytes *and* FALSE with no error.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3314>
This commit is contained in:
Jan Schmidt 2022-10-14 06:17:00 +11:00
parent 1751f555f2
commit 46517d5aca

View file

@ -256,6 +256,7 @@ on_read_ready (GObject * source, GAsyncResult * result, gpointer user_data)
GstClockTime now = gst_adaptive_demux_clock_get_time (dh->clock);
gboolean read_failed =
g_input_stream_read_all_finish (in, result, &bytes_read, &error);
download_request_lock (request);
@ -279,9 +280,7 @@ on_read_ready (GObject * source, GAsyncResult * result, gpointer user_data)
return;
}
if (!bytes_read) {
goto finish_transfer;
} else {
if (bytes_read > 0) {
GstBuffer *gst_buffer =
gst_buffer_new_wrapped (transfer->read_buffer, bytes_read);
@ -328,6 +327,10 @@ on_read_ready (GObject * source, GAsyncResult * result, gpointer user_data)
transfer_task_report_progress (transfer_task);
}
} else if (read_failed) {
/* The read failed and returned 0 bytes: We're done */
goto finish_transfer;
}
/* Resubmit the read request to get more */
if (!new_read_buffer (transfer))
@ -338,7 +341,6 @@ on_read_ready (GObject * source, GAsyncResult * result, gpointer user_data)
transfer->read_buffer_size, G_PRIORITY_DEFAULT, transfer->cancellable,
on_read_ready, transfer_task);
g_main_context_pop_thread_default (dh->transfer_context);
}
download_request_unlock (request);
return;