Add RTSP channel object for async io
[platform/upstream/gstreamer.git] / gst-libs / gst / rtsp / gstrtspconnection.h
1 /* GStreamer
2  * Copyright (C) <2005,2006> Wim Taymans <wim@fluendo.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., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19 /*
20  * Unless otherwise indicated, Source Code is licensed under MIT license.
21  * See further explanation attached in License Statement (distributed in the file
22  * LICENSE).
23  *
24  * Permission is hereby granted, free of charge, to any person obtaining a copy of
25  * this software and associated documentation files (the "Software"), to deal in
26  * the Software without restriction, including without limitation the rights to
27  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
28  * of the Software, and to permit persons to whom the Software is furnished to do
29  * so, subject to the following conditions:
30  *
31  * The above copyright notice and this permission notice shall be included in all
32  * copies or substantial portions of the Software.
33  *
34  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
35  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
36  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
37  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
38  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
39  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
40  * SOFTWARE.
41  */
42
43 #ifndef __GST_RTSP_CONNECTION_H__
44 #define __GST_RTSP_CONNECTION_H__
45
46 #include <glib.h>
47
48 #include <gst/rtsp/gstrtspdefs.h>
49 #include <gst/rtsp/gstrtspurl.h>
50 #include <gst/rtsp/gstrtspmessage.h>
51
52 G_BEGIN_DECLS
53
54 typedef struct _GstRTSPConnection GstRTSPConnection;
55
56 /**
57  * GstRTSPConnection:
58  *
59  * Opaque RTSP connection object.
60  */
61 struct _GstRTSPConnection
62 {
63   /*< private >*/
64   /* URL for the connection */
65   GstRTSPUrl *url;
66
67   /* connection state */
68   GstPollFD   fd;
69   GstPoll    *fdset;
70   gchar      *ip;
71
72   /* Session state */
73   gint          cseq;                   /* sequence number */
74   gchar         session_id[512];        /* session id */
75   gint          timeout;                /* session timeout in seconds */
76   GTimer       *timer;                  /* timeout timer */
77
78   /* Authentication */
79   GstRTSPAuthMethod  auth_method;
80   gchar             *username;
81   gchar             *passwd;
82   GHashTable        *auth_params;
83 };
84
85 /* opening/closing a connection */
86 GstRTSPResult      gst_rtsp_connection_create        (GstRTSPUrl *url, GstRTSPConnection **conn);
87 GstRTSPResult      gst_rtsp_connection_connect       (GstRTSPConnection *conn, GTimeVal *timeout);
88 GstRTSPResult      gst_rtsp_connection_close         (GstRTSPConnection *conn);
89 GstRTSPResult      gst_rtsp_connection_free          (GstRTSPConnection *conn);
90
91 /* sending/receiving raw bytes */
92 GstRTSPResult      gst_rtsp_connection_read          (GstRTSPConnection * conn, guint8 * data,
93                                                       guint size, GTimeVal * timeout);
94 GstRTSPResult      gst_rtsp_connection_write         (GstRTSPConnection * conn, const guint8 * data, 
95                                                       guint size, GTimeVal * timeout);
96
97 /* sending/receiving messages */
98 GstRTSPResult      gst_rtsp_connection_send          (GstRTSPConnection *conn, GstRTSPMessage *message,
99                                                       GTimeVal *timeout);
100 GstRTSPResult      gst_rtsp_connection_receive       (GstRTSPConnection *conn, GstRTSPMessage *message,
101                                                       GTimeVal *timeout);
102
103 /* status management */
104 GstRTSPResult      gst_rtsp_connection_poll          (GstRTSPConnection *conn, GstRTSPEvent events,
105                                                       GstRTSPEvent *revents, GTimeVal *timeout);
106
107 /* reset the timeout */
108 GstRTSPResult      gst_rtsp_connection_next_timeout  (GstRTSPConnection *conn, GTimeVal *timeout);
109 GstRTSPResult      gst_rtsp_connection_reset_timeout (GstRTSPConnection *conn);
110
111 /* flushing state */
112 GstRTSPResult      gst_rtsp_connection_flush         (GstRTSPConnection *conn, gboolean flush);
113
114 /* configure authentication data */
115 GstRTSPResult      gst_rtsp_connection_set_auth      (GstRTSPConnection *conn, GstRTSPAuthMethod method,
116                                                       const gchar *user, const gchar *pass);
117
118 void               gst_rtsp_connection_set_auth_param    (GstRTSPConnection *conn,
119                                                           const gchar * param,
120                                                           const gchar *value);
121 void               gst_rtsp_connection_clear_auth_params (GstRTSPConnection *conn);
122
123 /* configure DSCP */
124 GstRTSPResult      gst_rtsp_connection_set_qos_dscp  (GstRTSPConnection *conn,
125                                                       guint qos_dscp);
126
127 /* accessors */
128 const gchar *      gst_rtsp_connection_get_ip        (const GstRTSPConnection *conn);
129
130 /* async IO */
131
132 /**
133  * GstRTSPChannel:
134  *
135  * Opaque RTSP channel object that can be used for asynchronous RTSP
136  * operations.
137  */
138 typedef struct _GstRTSPChannel GstRTSPChannel;
139
140 /**
141  * GstRTSPChannelFuncs:
142  * @message_received: callback when a message was received
143  * @message_sent: callback when a message was sent
144  * @closed: callback when the connection is closed
145  * @error: callback when an error occured
146  *
147  * Callback functions from a #GstRTSPChannel.
148  */
149 typedef struct {
150   GstRTSPResult (*message_received) (GstRTSPChannel *channel, GstRTSPMessage *message,
151                                      gpointer user_data);
152   GstRTSPResult (*message_sent)     (GstRTSPChannel *channel, guint cseq, 
153                                      gpointer user_data);
154   GstRTSPResult (*closed)           (GstRTSPChannel *channel, gpointer user_data);
155   GstRTSPResult (*error)            (GstRTSPChannel *channel, GstRTSPResult result,
156                                      gpointer user_data);
157 } GstRTSPChannelFuncs;
158
159 GstRTSPChannel *   gst_rtsp_channel_new              (GstRTSPConnection *conn,
160                                                       GstRTSPChannelFuncs *funcs,
161                                                       gpointer user_data,
162                                                       GDestroyNotify notify);
163 void               gst_rtsp_channel_unref            (GstRTSPChannel *channel);
164
165 guint              gst_rtsp_channel_attach           (GstRTSPChannel *channel,
166                                                       GMainContext *context);
167
168 guint              gst_rtsp_channel_queue_message    (GstRTSPChannel *channel,
169                                                       GstRTSPMessage *message);
170
171
172 G_END_DECLS
173
174 #endif /* __GST_RTSP_CONNECTION_H__ */