summaryrefslogtreecommitdiff
path: root/tests/check/elements/test_http_src.h
blob: 3a83e253750403b3c802918e36612cbd6c97d00f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/* HTTP source element for use in tests
 *
 * Copyright (c) <2015> YouView TV Ltd
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#ifndef __GST_TEST_HTTP_SRC_H__
#define __GST_TEST_HTTP_SRC_H__

#include <gst/gst.h>

G_BEGIN_DECLS

#define GST_TYPE_TEST_HTTP_SRC            (gst_test_http_src_get_type ())

/**
 * TEST_HTTP_SRC_REQUEST_HEADERS_NAME:
 * The name of the #GstStructure that will contain all the HTTP request
 * headers
 */
#define TEST_HTTP_SRC_REQUEST_HEADERS_NAME "request-headers"

/**
 * TEST_HTTP_SRC_RESPONSE_HEADERS_NAME:
 * The name of the #GstStructure that will contain all the HTTP response
 * headers
 */
#define TEST_HTTP_SRC_RESPONSE_HEADERS_NAME "response-headers"

/* structure used by src_start function to configure the
 * GstTestHTTPSrc plugin.
 * It specifies information about a given URI.
 */
typedef struct _GstTestHTTPSrcInput
{
  gpointer context; /* opaque pointer that can be used in callbacks */
  guint64 size; /* size of resource, in bytes */
  GstStructure *request_headers;
  GstStructure *response_headers;
  guint status_code; /* HTTP status code */
} GstTestHTTPSrcInput;

/* Opaque structure used by GstTestHTTPSrc */
typedef struct _GstTestHTTPSrc GstTestHTTPSrc;

typedef struct _GstTestHTTPSrcCallbacks {
  /**
   * src_start:
   * @src: The #GstTestHTTPSrc calling this callback
   * @uri: The URI that is being requested
   * @input_data: (out) The implementation of this callback is
   * responsible for filling in this #GstTestHTTPSrcInput
   * with the appropriate information, return returning %TRUE.
   * If returning %FALSE, only GstTestHTTPSrcInput::status_code
   * should be updated.
   * Returns: %TRUE if GstTestHTTPSrc should respond to this URI,
   * using the supplied input_data.
   *
   * src_start is used to "open" the given URI. The callback must return
   * %TRUE to simulate a success, and set appropriate fields in input_data.
   * Returning %FALSE indicates that the request URI is not found.
   * In this situation GstTestHTTPSrc will cause the appropriate
   * 404 error to be posted to the bus 
   */
  gboolean (*src_start)(GstTestHTTPSrc *src,
                        const gchar *uri,
                        GstTestHTTPSrcInput *input_data,
                        gpointer user_data);
  /**
   * src_create:
   * @src: the #GstTestHTTPSrc calling this callback
   * @offset: the offset from the start of the resource
   * @length: requested number of bytes
   * @retbuf: (out) used to return a newly allocated #GstBuffer
   * @context: (allow none) the value of the context field
   * in #GstTestHTTPSrcInput.
   * @user_data: the value of user_data provided to 
   * #gst_test_http_src_install_callbacks
   * Returns: %GST_FLOW_OK to indicate success, or some other value of
   * #GstFlowReturn to indicate EOS or error.
   *
   * The src_create function is used to create a #GstBuffer for
   * simulating the data that is returned when accessing this
   * "open" stream. It can also be used to simulate various error
   * conditions by returning something other than %GST_FLOW_OK
   */
  GstFlowReturn (*src_create)(GstTestHTTPSrc *src,
                              guint64 offset,
                              guint length,
                              GstBuffer ** retbuf,
                              gpointer context,
                              gpointer user_data);
} GstTestHTTPSrcCallbacks;

GType gst_test_http_src_get_type (void);

/**
 * gst_test_http_src_register_plugin:
 * @registry: the #GstRegistry to use for registering this plugin
 * @name: the name to use for this plugin
 * Returns: true if successful
 *
 * Registers this plugin with the GstRegitry using the given name. It will
 * be given a high rank, so that it will be picked in preference to any
 * other element that implements #GstURIHandler.
 */
gboolean gst_test_http_src_register_plugin (GstRegistry * registry, const gchar * name);

/**
 * gst_test_http_src_install_callbacks:
 * @callbacks: the #GstTestHTTPSrcCallbacks callback functions that will
 * be called every time this element is asked to open a URI or provide data
 * for an open URI.
 * @user_data: a pointer that is passed to every callback
 */
void gst_test_http_src_install_callbacks (const GstTestHTTPSrcCallbacks *callbacks, gpointer user_data);

/**
 * gst_test_http_src_set_default_blocksize:
 * @blocksize: the default block size to use (0=use #GstBaseSrc default)
 *
 * Set the default blocksize that will be used by instances of
 * #GstTestHTTPSrc. It specifies the size (in bytes) that will be
 * returned in each #GstBuffer. This default can be overridden
 * by an instance of #GstTestHTTPSrc using the "blocksize" property
 * of #GstBaseSrc
 */
void gst_test_http_src_set_default_blocksize (guint blocksize);

G_END_DECLS

#endif /* __GST_TEST_HTTP_SRC_H__ */