1 /* GStreamer
2  * Copyright (C) 2011 Axis Communications <dev-gstreamer@axis.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19 
20 #ifndef __GST_CURL_BASE_SINK__
21 #define __GST_CURL_BASE_SINK__
22 
23 #include <gst/gst.h>
24 #include <gst/base/gstbasesink.h>
25 #include <curl/curl.h>
26 
27 G_BEGIN_DECLS
28 #define GST_TYPE_CURL_BASE_SINK \
29   (gst_curl_base_sink_get_type())
30 #define GST_CURL_BASE_SINK(obj) \
31   (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_CURL_BASE_SINK, GstCurlBaseSink))
32 #define GST_CURL_BASE_SINK_CLASS(klass) \
33   (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_CURL_BASE_SINK, GstCurlBaseSinkClass))
34 #define GST_CURL_BASE_SINK_GET_CLASS(obj) \
35   (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_CURL_BASE_SINK, GstCurlBaseSinkClass))
36 #define GST_IS_CURL_BASE_SINK(obj) \
37   (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_CURL_BASE_SINK))
38 #define GST_IS_CURL_BASE_SINK_CLASS(klass) \
39   (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_CURL_BASE_SINK))
40 typedef struct _GstCurlBaseSink GstCurlBaseSink;
41 typedef struct _GstCurlBaseSinkClass GstCurlBaseSinkClass;
42 
43 typedef struct _TransferBuffer TransferBuffer;
44 typedef struct _TransferCondition TransferCondition;
45 
46 struct _TransferBuffer
47 {
48   guint8 *ptr;
49   size_t len;
50   size_t offset;
51 };
52 
53 struct _TransferCondition
54 {
55   GCond cond;
56   gboolean data_sent;
57   gboolean data_available;
58   gboolean wait_for_response;
59 };
60 
61 struct _GstCurlBaseSink
62 {
63   GstBaseSink parent;
64 
65   /*< private > */
66   CURLM *multi_handle;
67   CURL *curl;
68   GstPollFD fd;
69   GstPoll *fdset;
70   curlsocktype socket_type;
71   GThread *transfer_thread;
72   gchar *error;
73   GstFlowReturn flow_ret;
74   TransferBuffer *transfer_buf;
75   TransferCondition *transfer_cond;
76   gint num_buffers_per_packet;
77   gint timeout;
78   gchar *url;
79   gchar *user;
80   gchar *passwd;
81   gchar *file_name;
82   guint qos_dscp;
83   gboolean transfer_thread_close;
84   gboolean new_file;
85   gboolean is_live;
86 };
87 
88 struct _GstCurlBaseSinkClass
89 {
90   GstBaseSinkClass parent_class;
91 
92   /* vmethods */
93     gboolean (*set_protocol_dynamic_options_unlocked) (GstCurlBaseSink * sink);
94     gboolean (*set_options_unlocked) (GstCurlBaseSink * sink);
95   void (*set_mime_type) (GstCurlBaseSink * sink, GstCaps * caps);
96   void (*transfer_prepare_poll_wait) (GstCurlBaseSink * sink);
97     glong (*transfer_get_response_code) (GstCurlBaseSink * sink, glong resp);
98     gboolean (*transfer_verify_response_code) (GstCurlBaseSink * sink);
99     GstFlowReturn (*prepare_transfer) (GstCurlBaseSink * sink);
100   void (*handle_transfer) (GstCurlBaseSink * sink);
101     size_t (*transfer_read_cb) (void *curl_ptr, size_t size, size_t nmemb,
102       void *stream);
103     size_t (*transfer_data_buffer) (GstCurlBaseSink * sink, void *curl_ptr,
104       size_t block_size, guint * last_chunk);
105     size_t (*flush_data_unlocked) (GstCurlBaseSink * sink, void *curl_ptr,
106       size_t block_size, gboolean new_file, gboolean close_transfer);
107     gboolean (*has_buffered_data_unlocked) (GstCurlBaseSink * sink);
108 };
109 
110 GType gst_curl_base_sink_get_type (void);
111 
112 void gst_curl_base_sink_transfer_thread_notify_unlocked
113     (GstCurlBaseSink * sink);
114 void gst_curl_base_sink_transfer_thread_close (GstCurlBaseSink * sink);
115 void gst_curl_base_sink_set_live (GstCurlBaseSink * sink, gboolean live);
116 gboolean gst_curl_base_sink_is_live (GstCurlBaseSink * sink);
117 
118 G_END_DECLS
119 #endif
120