adaptivedemux2/downloadhelper: Fix function name
[platform/upstream/gstreamer.git] / subprojects / gst-plugins-good / ext / adaptivedemux2 / downloadrequest.h
1 /* GStreamer
2  * Copyright (C) 2011 Andoni Morales Alastruey <ylatuya@gmail.com>
3  * Copyright (C) 2021-2022 Jan Schmidt <jan@centricular.com>
4  *
5  * downloadrequest.h:
6  *
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.
11  *
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.
16  *
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.
21  */
22
23 #ifndef __DOWNLOAD_REQUEST_H__
24 #define __DOWNLOAD_REQUEST_H__
25
26 #include <gst/gst.h>
27
28 G_BEGIN_DECLS
29
30 #define DOWNLOAD_REQUEST(obj) ((DownloadRequest *)(obj))
31
32 typedef struct _DownloadRequest DownloadRequest;
33 typedef enum _DownloadRequestState DownloadRequestState;
34
35 typedef void (*DownloadRequestEventCallback) (DownloadRequest *request, DownloadRequestState state, void *cb_data);
36
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 */
44 };
45
46 struct _DownloadRequest
47 {
48   gint ref_count;
49
50   gboolean in_use; /* TRUE if this request is being serviced */
51   gboolean send_progress; /* TRUE if this request wants progress events */
52
53   DownloadRequestState state;
54   guint status_code; /* HTTP status code */
55
56   /* Request parameters */
57   gchar * uri;                  /* URI of the request */
58   gint64 range_start;
59   gint64 range_end;
60
61   /* possibly populated during a download */
62   gchar * redirect_uri;         /* Redirect target if any */
63   gboolean redirect_permanent;  /* If the redirect is permanent */
64
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 */
68
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 */
72 };
73
74 void download_request_set_uri (DownloadRequest *request, const gchar *uri,
75     gint64 range_start, gint64 range_end);
76
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);
79
80 void download_request_begin_download (DownloadRequest *request);
81
82 void download_request_set_caps (DownloadRequest * request, GstCaps * caps);
83
84 GstCaps * download_request_get_caps (DownloadRequest * request);
85
86 gboolean download_request_add_buffer (DownloadRequest *request, GstBuffer *buffer);
87 GstBuffer * download_request_take_buffer (DownloadRequest *request);
88
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);
92
93 void download_request_set_callbacks (DownloadRequest *request,
94     DownloadRequestEventCallback on_completion,
95     DownloadRequestEventCallback on_error,
96     DownloadRequestEventCallback on_cancellation,
97     DownloadRequestEventCallback on_progress,
98     void *cb_data);
99
100 DownloadRequest *download_request_ref (DownloadRequest *request);
101 void download_request_unref (DownloadRequest *request);
102
103 void download_request_lock (DownloadRequest *request);
104 void download_request_unlock (DownloadRequest *request);
105
106 void download_request_despatch_progress (DownloadRequest *request);
107 void download_request_despatch_completion (DownloadRequest *request);
108
109 G_END_DECLS
110 #endif /* __DOWNLOAD_REQUEST_H__ */