2 * Copyright (C) 2011 Andoni Morales Alastruey <ylatuya@gmail.com>
3 * Copyright (C) 2021-2022 Jan Schmidt <jan@centricular.com>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
23 #ifndef __DOWNLOAD_REQUEST_H__
24 #define __DOWNLOAD_REQUEST_H__
30 #define DOWNLOAD_REQUEST(obj) ((DownloadRequest *)(obj))
32 typedef struct _DownloadRequest DownloadRequest;
33 typedef enum _DownloadRequestState DownloadRequestState;
35 typedef void (*DownloadRequestEventCallback) (DownloadRequest *request, DownloadRequestState state, void *cb_data);
37 enum _DownloadRequestState {
38 DOWNLOAD_REQUEST_STATE_UNSENT,
39 DOWNLOAD_REQUEST_STATE_OPEN, /* Request sent, but no response yet */
40 DOWNLOAD_REQUEST_STATE_HEADERS_RECEIVED, /* Response headers received, awaiting body */
41 DOWNLOAD_REQUEST_STATE_LOADING, /* Content loading in progress */
42 DOWNLOAD_REQUEST_STATE_COMPLETE, /* Request processing finished successfully - check status_code for completion 200-399 codes */
43 DOWNLOAD_REQUEST_STATE_ERROR, /* Request generated an http error - check status_code */
46 struct _DownloadRequest
50 gboolean in_use; /* TRUE if this request is being serviced */
51 gboolean send_progress; /* TRUE if this request wants progress events */
53 DownloadRequestState state;
54 guint status_code; /* HTTP status code */
56 /* Request parameters */
57 gchar * uri; /* URI of the request */
61 /* possibly populated during a download */
62 gchar * redirect_uri; /* Redirect target if any */
63 gboolean redirect_permanent; /* If the redirect is permanent */
65 GstStructure *headers; /* HTTP request/response headers */
66 guint64 content_length; /* Response content length, if known (or 0) */
67 guint64 content_received; /* Response content received so far */
69 guint64 download_request_time; /* Epoch time when the download started */
70 guint64 download_start_time; /* Epoch time when the first data for the download arrived */
71 guint64 download_end_time; /* Epoch time when the download finished */
74 void download_request_set_uri (DownloadRequest *request, const gchar *uri,
75 gint64 range_start, gint64 range_end);
77 /* Reset the request state back to UNSENT and clear any stored info. The request must not be in use */
78 void download_request_reset (DownloadRequest *request);
80 void download_request_begin_download (DownloadRequest *request);
82 void download_request_set_caps (DownloadRequest * request, GstCaps * caps);
84 GstCaps * download_request_get_caps (DownloadRequest * request);
86 gboolean download_request_add_buffer (DownloadRequest *request, GstBuffer *buffer);
87 GstBuffer * download_request_take_buffer (DownloadRequest *request);
89 DownloadRequest * download_request_new (void);
90 DownloadRequest * download_request_new_uri (const gchar * uri);
91 DownloadRequest * download_request_new_uri_range (const gchar * uri, gint64 range_start, gint64 range_end);
93 void download_request_set_callbacks (DownloadRequest *request,
94 DownloadRequestEventCallback on_completion,
95 DownloadRequestEventCallback on_error,
96 DownloadRequestEventCallback on_cancellation,
97 DownloadRequestEventCallback on_progress,
100 DownloadRequest *download_request_ref (DownloadRequest *request);
101 void download_request_unref (DownloadRequest *request);
103 void download_request_lock (DownloadRequest *request);
104 void download_request_unlock (DownloadRequest *request);
106 void download_request_despatch_progress (DownloadRequest *request);
107 void download_request_despatch_completion (DownloadRequest *request);
110 #endif /* __DOWNLOAD_REQUEST_H__ */