diff --git a/subprojects/gst-plugins-good/ext/adaptivedemux2/downloadhelper.c b/subprojects/gst-plugins-good/ext/adaptivedemux2/downloadhelper.c index 6fd59e3dae..0d68fcec2f 100644 --- a/subprojects/gst-plugins-good/ext/adaptivedemux2/downloadhelper.c +++ b/subprojects/gst-plugins-good/ext/adaptivedemux2/downloadhelper.c @@ -268,7 +268,7 @@ on_read_ready (GObject * source, GAsyncResult * result, gpointer user_data) if (!g_cancellable_is_cancelled (transfer->cancellable)) { GST_ERROR ("Failed to read stream: %s", error->message); - if (request->state != DOWNLOAD_REQUEST_STATE_UNSENT) + if (request->state != DOWNLOAD_REQUEST_STATE_CANCELLED) request->state = DOWNLOAD_REQUEST_STATE_ERROR; finish_transfer_task (dh, transfer_task, error); } else { @@ -311,9 +311,8 @@ on_read_ready (GObject * source, GAsyncResult * result, gpointer user_data) } if (gst_buffer != NULL) { - /* Unsent means cancellation is in progress, so don't override - * the state. Otherwise make sure it is LOADING */ - if (request->state != DOWNLOAD_REQUEST_STATE_UNSENT) + /* Don't override CANCELLED state. Otherwise make sure it is LOADING */ + if (request->state != DOWNLOAD_REQUEST_STATE_CANCELLED) request->state = DOWNLOAD_REQUEST_STATE_LOADING; if (request->download_start_time == GST_CLOCK_TIME_NONE) { @@ -357,12 +356,13 @@ finish_transfer: request->uri, request->range_start, request->range_end); #endif - if (request->state != DOWNLOAD_REQUEST_STATE_UNSENT) { + if (request->state != DOWNLOAD_REQUEST_STATE_CANCELLED) { if (SOUP_STATUS_IS_SUCCESSFUL (status_code) - || SOUP_STATUS_IS_REDIRECTION (status_code)) + || SOUP_STATUS_IS_REDIRECTION (status_code)) { request->state = DOWNLOAD_REQUEST_STATE_COMPLETE; - else + } else { request->state = DOWNLOAD_REQUEST_STATE_ERROR; + } } } request->download_end_time = now; @@ -532,7 +532,7 @@ on_request_sent (GObject * source, GAsyncResult * result, gpointer user_data) G_GINT64_FORMAT, request->status_code, request->uri, request->range_start, request->range_end); - if (request->state != DOWNLOAD_REQUEST_STATE_UNSENT) + if (request->state != DOWNLOAD_REQUEST_STATE_CANCELLED) request->state = DOWNLOAD_REQUEST_STATE_ERROR; finish_transfer_task (dh, transfer_task, error); } else { @@ -547,8 +547,8 @@ on_request_sent (GObject * source, GAsyncResult * result, gpointer user_data) return; } - /* If the state went back to UNSENT, we were cancelled so don't override it */ - if (request->state != DOWNLOAD_REQUEST_STATE_UNSENT && + /* If the state is cancelled don't override it */ + if (request->state != DOWNLOAD_REQUEST_STATE_CANCELLED && request->state != DOWNLOAD_REQUEST_STATE_HEADERS_RECEIVED) { request->state = DOWNLOAD_REQUEST_STATE_HEADERS_RECEIVED; @@ -589,7 +589,9 @@ finish_transfer_error: GST_LOG ("request complete. Code %d URI %s range %" G_GINT64_FORMAT " %" G_GINT64_FORMAT, _soup_message_get_status (msg), request->uri, request->range_start, request->range_end); - if (request->state != DOWNLOAD_REQUEST_STATE_UNSENT) + + /* If the state is cancelled don't override it */ + if (request->state != DOWNLOAD_REQUEST_STATE_CANCELLED) request->state = DOWNLOAD_REQUEST_STATE_ERROR; } @@ -693,6 +695,13 @@ submit_transfer (DownloadHelper * dh, GTask * transfer_task) DownloadRequest *request = transfer->request; download_request_lock (request); + if (request->state == DOWNLOAD_REQUEST_STATE_CANCELLED) { + download_request_unlock (request); + + GST_DEBUG ("Don't submit already cancelled transfer"); + return; + } + request->state = DOWNLOAD_REQUEST_STATE_OPEN; request->download_request_time = gst_adaptive_demux_clock_get_time (dh->clock); @@ -803,8 +812,7 @@ downloadhelper_stop (DownloadHelper * dh) DownloadRequest *request = transfer->request; download_request_lock (request); - /* Reset the state to UNSENT, to indicate cancellation, like an XMLHttpRequest does */ - request->state = DOWNLOAD_REQUEST_STATE_UNSENT; + request->state = DOWNLOAD_REQUEST_STATE_CANCELLED; download_request_unlock (request); transfer->complete = TRUE; @@ -970,8 +978,7 @@ downloadhelper_cancel_request (DownloadHelper * dh, DownloadRequest * request) GST_DEBUG ("Cancelling request for URI %s range %" G_GINT64_FORMAT " %" G_GINT64_FORMAT, request->uri, request->range_start, request->range_end); - request->state = DOWNLOAD_REQUEST_STATE_UNSENT; - + request->state = DOWNLOAD_REQUEST_STATE_CANCELLED; for (i = dh->active_transfers->len - 1; i >= 0; i--) { GTask *transfer_task = g_array_index (dh->active_transfers, GTask *, i); DownloadHelperTransfer *transfer = g_task_get_task_data (transfer_task); diff --git a/subprojects/gst-plugins-good/ext/adaptivedemux2/downloadrequest.c b/subprojects/gst-plugins-good/ext/adaptivedemux2/downloadrequest.c index 421ff85d1a..37c5acd9c8 100644 --- a/subprojects/gst-plugins-good/ext/adaptivedemux2/downloadrequest.c +++ b/subprojects/gst-plugins-good/ext/adaptivedemux2/downloadrequest.c @@ -162,6 +162,7 @@ download_request_despatch_completion (DownloadRequest * request) DownloadRequestPrivate *priv = DOWNLOAD_REQUEST_PRIVATE (request); switch (request->state) { case DOWNLOAD_REQUEST_STATE_UNSENT: + case DOWNLOAD_REQUEST_STATE_CANCELLED: if (priv->cancellation_cb) priv->cancellation_cb (request, request->state, priv->cb_data); break; diff --git a/subprojects/gst-plugins-good/ext/adaptivedemux2/downloadrequest.h b/subprojects/gst-plugins-good/ext/adaptivedemux2/downloadrequest.h index 280417b6da..b8dea7466b 100644 --- a/subprojects/gst-plugins-good/ext/adaptivedemux2/downloadrequest.h +++ b/subprojects/gst-plugins-good/ext/adaptivedemux2/downloadrequest.h @@ -41,6 +41,7 @@ enum _DownloadRequestState { DOWNLOAD_REQUEST_STATE_LOADING, /* Content loading in progress */ DOWNLOAD_REQUEST_STATE_COMPLETE, /* Request processing finished successfully - check status_code for completion 200-399 codes */ DOWNLOAD_REQUEST_STATE_ERROR, /* Request generated an http error - check status_code */ + DOWNLOAD_REQUEST_STATE_CANCELLED, /* Request has been cancelled by the user */ }; struct _DownloadRequest