Commit 19e0dd31 authored by Wim Taymans's avatar Wim Taymans
Browse files

Move SDP and RTSP from helper objects in -good to a reusable library.

Original commit message from CVS:
* configure.ac:
* gst-libs/gst/Makefile.am:
* gst-libs/gst/rtsp/Makefile.am:
* gst-libs/gst/rtsp/gstrtspbase64.c: (gst_rtsp_base64_encode):
* gst-libs/gst/rtsp/gstrtspbase64.h:
* gst-libs/gst/rtsp/gstrtspconnection.c: (inet_aton),
(gst_rtsp_connection_create), (gst_rtsp_connection_connect),
(add_auth_header), (add_date_header), (gst_rtsp_connection_write),
(gst_rtsp_connection_send), (read_line), (read_string), (read_key),
(parse_response_status), (parse_request_line), (parse_line),
(gst_rtsp_connection_read), (read_body),
(gst_rtsp_connection_receive), (gst_rtsp_connection_close),
(gst_rtsp_connection_free), (gst_rtsp_connection_next_timeout),
(gst_rtsp_connection_reset_timeout), (gst_rtsp_connection_flush),
(gst_rtsp_connection_set_auth):
* gst-libs/gst/rtsp/gstrtspconnection.h:
* gst-libs/gst/rtsp/gstrtspdefs.c: (rtsp_init_status),
(gst_rtsp_strresult), (gst_rtsp_method_as_text),
(gst_rtsp_version_as_text), (gst_rtsp_header_as_text),
(gst_rtsp_status_as_text), (gst_rtsp_find_header_field),
(gst_rtsp_find_method):
* gst-libs/gst/rtsp/gstrtspdefs.h:
* gst-libs/gst/rtsp/gstrtspmessage.c: (key_value_foreach),
(gst_rtsp_message_new), (gst_rtsp_message_init),
(gst_rtsp_message_new_request), (gst_rtsp_message_init_request),
(gst_rtsp_message_new_response), (gst_rtsp_message_init_response),
(gst_rtsp_message_init_data), (gst_rtsp_message_unset),
(gst_rtsp_message_free), (gst_rtsp_message_add_header),
(gst_rtsp_message_remove_header), (gst_rtsp_message_get_header),
(gst_rtsp_message_append_headers), (gst_rtsp_message_set_body),
(gst_rtsp_message_take_body), (gst_rtsp_message_get_body),
(gst_rtsp_message_steal_body), (dump_mem), (dump_key_value),
(gst_rtsp_message_dump):
* gst-libs/gst/rtsp/gstrtspmessage.h:
* gst-libs/gst/rtsp/gstrtsprange.c: (parse_npt_time),
(parse_npt_range), (parse_clock_range), (parse_smpte_range),
(gst_rtsp_range_parse), (gst_rtsp_range_free):
* gst-libs/gst/rtsp/gstrtsprange.h:
* gst-libs/gst/rtsp/gstrtsptransport.c: (gst_rtsp_transport_new),
(gst_rtsp_transport_init), (gst_rtsp_transport_get_mime),
(gst_rtsp_transport_get_manager), (parse_mode), (parse_range),
(range_as_text), (rtsp_transport_mode_as_text),
(rtsp_transport_profile_as_text), (rtsp_transport_ltrans_as_text),
(gst_rtsp_transport_parse), (gst_rtsp_transport_as_text),
(gst_rtsp_transport_free):
* gst-libs/gst/rtsp/gstrtsptransport.h:
* gst-libs/gst/rtsp/gstrtspurl.c: (gst_rtsp_url_parse),
(gst_rtsp_url_free), (gst_rtsp_url_set_port),
(gst_rtsp_url_get_port), (gst_rtsp_url_get_request_uri):
* gst-libs/gst/rtsp/gstrtspurl.h:
* gst-libs/gst/sdp/Makefile.am:
* gst-libs/gst/sdp/gstsdp.h:
* gst-libs/gst/sdp/gstsdpmessage.c: (gst_sdp_origin_init),
(gst_sdp_connection_init), (gst_sdp_bandwidth_init),
(gst_sdp_time_init), (gst_sdp_zone_init), (gst_sdp_key_init),
(gst_sdp_attribute_init), (gst_sdp_message_new),
(gst_sdp_message_init), (gst_sdp_message_uninit),
(gst_sdp_message_free), (gst_sdp_media_new), (gst_sdp_media_init),
(gst_sdp_media_uninit), (gst_sdp_media_free),
(gst_sdp_message_set_origin), (gst_sdp_message_get_origin),
(gst_sdp_message_set_connection), (gst_sdp_message_get_connection),
(gst_sdp_message_add_bandwidth), (gst_sdp_message_add_time),
(gst_sdp_message_add_zone), (gst_sdp_message_set_key),
(gst_sdp_message_get_key), (gst_sdp_message_get_attribute_val_n),
(gst_sdp_message_get_attribute_val),
(gst_sdp_message_add_attribute), (gst_sdp_message_add_media),
(gst_sdp_media_add_attribute), (gst_sdp_media_add_bandwidth),
(gst_sdp_media_add_format), (gst_sdp_media_get_attribute),
(gst_sdp_media_get_attribute_val_n),
(gst_sdp_media_get_attribute_val), (gst_sdp_media_get_format),
(read_string), (read_string_del), (gst_sdp_parse_line),
(gst_sdp_message_parse_buffer), (print_media),
(gst_sdp_message_dump):
* gst-libs/gst/sdp/gstsdpmessage.h:
* pkgconfig/gstreamer-plugins-base-uninstalled.pc.in:
Move SDP and RTSP from helper objects in -good to a reusable library.
Use a proper gst_ namespace.
parent 9137e989
2007-07-24 Wim Taymans <wim.taymans@gmail.com>
* configure.ac:
* gst-libs/gst/Makefile.am:
* gst-libs/gst/rtsp/Makefile.am:
* gst-libs/gst/rtsp/gstrtspbase64.c: (gst_rtsp_base64_encode):
* gst-libs/gst/rtsp/gstrtspbase64.h:
* gst-libs/gst/rtsp/gstrtspconnection.c: (inet_aton),
(gst_rtsp_connection_create), (gst_rtsp_connection_connect),
(add_auth_header), (add_date_header), (gst_rtsp_connection_write),
(gst_rtsp_connection_send), (read_line), (read_string), (read_key),
(parse_response_status), (parse_request_line), (parse_line),
(gst_rtsp_connection_read), (read_body),
(gst_rtsp_connection_receive), (gst_rtsp_connection_close),
(gst_rtsp_connection_free), (gst_rtsp_connection_next_timeout),
(gst_rtsp_connection_reset_timeout), (gst_rtsp_connection_flush),
(gst_rtsp_connection_set_auth):
* gst-libs/gst/rtsp/gstrtspconnection.h:
* gst-libs/gst/rtsp/gstrtspdefs.c: (rtsp_init_status),
(gst_rtsp_strresult), (gst_rtsp_method_as_text),
(gst_rtsp_version_as_text), (gst_rtsp_header_as_text),
(gst_rtsp_status_as_text), (gst_rtsp_find_header_field),
(gst_rtsp_find_method):
* gst-libs/gst/rtsp/gstrtspdefs.h:
* gst-libs/gst/rtsp/gstrtspmessage.c: (key_value_foreach),
(gst_rtsp_message_new), (gst_rtsp_message_init),
(gst_rtsp_message_new_request), (gst_rtsp_message_init_request),
(gst_rtsp_message_new_response), (gst_rtsp_message_init_response),
(gst_rtsp_message_init_data), (gst_rtsp_message_unset),
(gst_rtsp_message_free), (gst_rtsp_message_add_header),
(gst_rtsp_message_remove_header), (gst_rtsp_message_get_header),
(gst_rtsp_message_append_headers), (gst_rtsp_message_set_body),
(gst_rtsp_message_take_body), (gst_rtsp_message_get_body),
(gst_rtsp_message_steal_body), (dump_mem), (dump_key_value),
(gst_rtsp_message_dump):
* gst-libs/gst/rtsp/gstrtspmessage.h:
* gst-libs/gst/rtsp/gstrtsprange.c: (parse_npt_time),
(parse_npt_range), (parse_clock_range), (parse_smpte_range),
(gst_rtsp_range_parse), (gst_rtsp_range_free):
* gst-libs/gst/rtsp/gstrtsprange.h:
* gst-libs/gst/rtsp/gstrtsptransport.c: (gst_rtsp_transport_new),
(gst_rtsp_transport_init), (gst_rtsp_transport_get_mime),
(gst_rtsp_transport_get_manager), (parse_mode), (parse_range),
(range_as_text), (rtsp_transport_mode_as_text),
(rtsp_transport_profile_as_text), (rtsp_transport_ltrans_as_text),
(gst_rtsp_transport_parse), (gst_rtsp_transport_as_text),
(gst_rtsp_transport_free):
* gst-libs/gst/rtsp/gstrtsptransport.h:
* gst-libs/gst/rtsp/gstrtspurl.c: (gst_rtsp_url_parse),
(gst_rtsp_url_free), (gst_rtsp_url_set_port),
(gst_rtsp_url_get_port), (gst_rtsp_url_get_request_uri):
* gst-libs/gst/rtsp/gstrtspurl.h:
* gst-libs/gst/sdp/Makefile.am:
* gst-libs/gst/sdp/gstsdp.h:
* gst-libs/gst/sdp/gstsdpmessage.c: (gst_sdp_origin_init),
(gst_sdp_connection_init), (gst_sdp_bandwidth_init),
(gst_sdp_time_init), (gst_sdp_zone_init), (gst_sdp_key_init),
(gst_sdp_attribute_init), (gst_sdp_message_new),
(gst_sdp_message_init), (gst_sdp_message_uninit),
(gst_sdp_message_free), (gst_sdp_media_new), (gst_sdp_media_init),
(gst_sdp_media_uninit), (gst_sdp_media_free),
(gst_sdp_message_set_origin), (gst_sdp_message_get_origin),
(gst_sdp_message_set_connection), (gst_sdp_message_get_connection),
(gst_sdp_message_add_bandwidth), (gst_sdp_message_add_time),
(gst_sdp_message_add_zone), (gst_sdp_message_set_key),
(gst_sdp_message_get_key), (gst_sdp_message_get_attribute_val_n),
(gst_sdp_message_get_attribute_val),
(gst_sdp_message_add_attribute), (gst_sdp_message_add_media),
(gst_sdp_media_add_attribute), (gst_sdp_media_add_bandwidth),
(gst_sdp_media_add_format), (gst_sdp_media_get_attribute),
(gst_sdp_media_get_attribute_val_n),
(gst_sdp_media_get_attribute_val), (gst_sdp_media_get_format),
(read_string), (read_string_del), (gst_sdp_parse_line),
(gst_sdp_message_parse_buffer), (print_media),
(gst_sdp_message_dump):
* gst-libs/gst/sdp/gstsdpmessage.h:
* pkgconfig/gstreamer-plugins-base-uninstalled.pc.in:
Move SDP and RTSP from helper objects in -good to a reusable library.
Use a proper gst_ namespace.
2007-07-23 Sebastian Dröge <slomo@circular-chaos.org>
* ext/vorbis/vorbisdec.c: (vorbis_dec_push_forward),
......@@ -646,6 +646,8 @@ gst-libs/gst/interfaces/Makefile
gst-libs/gst/netbuffer/Makefile
gst-libs/gst/riff/Makefile
gst-libs/gst/rtp/Makefile
gst-libs/gst/rtsp/Makefile
gst-libs/gst/sdp/Makefile
gst-libs/gst/tag/Makefile
gst-libs/gst/pbutils/Makefile
gst-libs/gst/video/Makefile
......
......@@ -12,6 +12,8 @@ SUBDIRS = \
pbutils \
riff \
rtp \
rtsp \
sdp \
video
noinst_HEADERS = gettext.h gst-i18n-plugin.h
libgstrtspincludedir = $(includedir)/gstreamer-@GST_MAJORMINOR@/gst/rtsp
libgstrtspinclude_HEADERS = gstrtspbase64.h \
gstrtspconnection.h \
gstrtspdefs.h \
gstrtspmessage.h \
gstrtsprange.h \
gstrtsptransport.h \
gstrtspurl.h
#gstrtspextreal.h
#gstrtspextwms.h
lib_LTLIBRARIES = libgstrtsp-@GST_MAJORMINOR@.la
libgstrtsp_@GST_MAJORMINOR@_la_SOURCES = gstrtspbase64.c \
gstrtspconnection.c \
gstrtspdefs.c \
gstrtspmessage.c \
gstrtsprange.c \
gstrtsptransport.c \
gstrtspurl.c
#gstrtspextwms.c
#rtspextreal.c
libgstrtsp_@GST_MAJORMINOR@_la_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_BASE_CFLAGS) $(GST_CFLAGS)
libgstrtsp_@GST_MAJORMINOR@_la_LIBADD = $(GST_LIBS)
libgstrtsp_@GST_MAJORMINOR@_la_LDFLAGS = $(GST_LIB_LDFLAGS) $(GST_ALL_LDFLAGS) $(GST_LT_LDFLAGS)
/* GStreamer
* Copyright (C) <2007> Mike Smith <msmith@xiph.org>
*
* 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., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "gstrtspbase64.h"
static char base64table[64] = {
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
'P',
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e',
'f',
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
'v',
'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'
};
/* This isn't efficient, but it doesn't need to be */
gchar *
gst_rtsp_base64_encode (gchar * data, gint len)
{
gchar *out = g_malloc (len * 4 / 3 + 4);
gchar *result = out;
int chunk;
while (len > 0) {
chunk = (len > 3) ? 3 : len;
*out++ = base64table[(*data & 0xFC) >> 2];
*out++ = base64table[((*data & 0x03) << 4) | ((*(data + 1) & 0xF0) >> 4)];
switch (chunk) {
case 3:
*out++ =
base64table[((*(data + 1) & 0x0F) << 2) | ((*(data +
2) & 0xC0) >> 6)];
*out++ = base64table[(*(data + 2)) & 0x3F];
break;
case 2:
*out++ = base64table[((*(data + 1) & 0x0F) << 2)];
*out++ = '=';
break;
case 1:
*out++ = '=';
*out++ = '=';
break;
}
data += chunk;
len -= chunk;
}
*out = 0;
return result;
}
/* GStreamer
* Copyright (C) <2007> Mike Smith <msmith@xiph.org>
*
* 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., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __BASE64_H__
#define __BASE64_H__
#include <glib.h>
G_BEGIN_DECLS
gchar *gst_rtsp_base64_encode(gchar *data, gint len);
G_END_DECLS
#endif
/* GStreamer
* Copyright (C) <2005,2006> Wim Taymans <wim@fluendo.com>
*
* 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., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/*
* Unless otherwise indicated, Source Code is licensed under MIT license.
* See further explanation attached in License Statement (distributed in the file
* LICENSE).
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <time.h>
/* we include this here to get the G_OS_* defines */
#include <glib.h>
#ifdef G_OS_WIN32
#include <winsock2.h>
#define EINPROGRESS WSAEINPROGRESS
#else
#include <sys/ioctl.h>
#include <netdb.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#endif
#ifdef HAVE_FIONREAD_IN_SYS_FILIO
#include <sys/filio.h>
#endif
#include "gstrtspconnection.h"
#include "gstrtspbase64.h"
/* the select call is also performed on the control sockets, that way
* we can send special commands to unlock or restart the select call */
#define CONTROL_RESTART 'R' /* restart the select call */
#define CONTROL_STOP 'S' /* stop the select call */
#define CONTROL_SOCKETS(conn) conn->control_sock
#define WRITE_SOCKET(conn) conn->control_sock[1]
#define READ_SOCKET(conn) conn->control_sock[0]
#define SEND_COMMAND(conn, command) \
G_STMT_START { \
unsigned char c; c = command; \
write (WRITE_SOCKET(conn), &c, 1); \
} G_STMT_END
#define READ_COMMAND(conn, command, res) \
G_STMT_START { \
res = read(READ_SOCKET(conn), &command, 1); \
} G_STMT_END
#ifdef G_OS_WIN32
#define IOCTL_SOCKET ioctlsocket
#define CLOSE_SOCKET(sock) closesocket(sock);
#else
#define IOCTL_SOCKET ioctl
#define CLOSE_SOCKET(sock) close(sock);
#endif
#ifdef G_OS_WIN32
static int
inet_aton (const char *c, struct in_addr *paddr)
{
/* note that inet_addr is deprecated on unix because
* inet_addr returns -1 (INADDR_NONE) for the valid 255.255.255.255
* address. */
paddr->s_addr = inet_addr (c);
if (paddr->s_addr == INADDR_NONE)
return 0;
return 1;
}
#endif
GstRTSPResult
gst_rtsp_connection_create (GstRTSPUrl * url, GstRTSPConnection ** conn)
{
gint ret;
GstRTSPConnection *newconn;
#ifdef G_OS_WIN32
unsigned long flags;
#endif /* G_OS_WIN32 */
g_return_val_if_fail (conn != NULL, GST_RTSP_EINVAL);
newconn = g_new0 (GstRTSPConnection, 1);
#ifdef G_OS_WIN32
/* This should work on UNIX too. PF_UNIX sockets replaced with pipe */
/* pipe( CONTROL_SOCKETS(newconn) ) */
if ((ret = pipe (CONTROL_SOCKETS (newconn))) < 0)
goto no_socket_pair;
ioctlsocket (READ_SOCKET (newconn), FIONBIO, &flags);
ioctlsocket (WRITE_SOCKET (newconn), FIONBIO, &flags);
#else
if ((ret =
socketpair (PF_UNIX, SOCK_STREAM, 0, CONTROL_SOCKETS (newconn))) < 0)
goto no_socket_pair;
fcntl (READ_SOCKET (newconn), F_SETFL, O_NONBLOCK);
fcntl (WRITE_SOCKET (newconn), F_SETFL, O_NONBLOCK);
#endif
newconn->url = url;
newconn->fd = -1;
newconn->timer = g_timer_new ();
newconn->auth_method = GST_RTSP_AUTH_NONE;
newconn->username = NULL;
newconn->passwd = NULL;
*conn = newconn;
return GST_RTSP_OK;
/* ERRORS */
no_socket_pair:
{
g_free (newconn);
return GST_RTSP_ESYS;
}
}
GstRTSPResult
gst_rtsp_connection_connect (GstRTSPConnection * conn, GTimeVal * timeout)
{
gint fd;
struct sockaddr_in sa_in;
struct hostent *hostinfo;
char **addrs;
const gchar *ip;
gchar ipbuf[INET_ADDRSTRLEN];
struct in_addr addr;
gint ret;
guint16 port;
GstRTSPUrl *url;
fd_set writefds;
fd_set readfds;
struct timeval tv, *tvp;
gint max_fd, retval;
#ifdef G_OS_WIN32
unsigned long flags;
#endif /* G_OS_WIN32 */
g_return_val_if_fail (conn != NULL, GST_RTSP_EINVAL);
g_return_val_if_fail (conn->url != NULL, GST_RTSP_EINVAL);
g_return_val_if_fail (conn->fd < 0, GST_RTSP_EINVAL);
url = conn->url;
/* first check if it already is an IP address */
if (inet_aton (url->host, &addr)) {
ip = url->host;
} else {
hostinfo = gethostbyname (url->host);
if (!hostinfo)
goto not_resolved; /* h_errno set */
if (hostinfo->h_addrtype != AF_INET)
goto not_ip; /* host not an IP host */
addrs = hostinfo->h_addr_list;
ip = inet_ntop (AF_INET, (struct in_addr *) addrs[0], ipbuf,
sizeof (ipbuf));
}
/* get the port from the url */
gst_rtsp_url_get_port (url, &port);
memset (&sa_in, 0, sizeof (sa_in));
sa_in.sin_family = AF_INET; /* network socket */
sa_in.sin_port = htons (port); /* on port */
sa_in.sin_addr.s_addr = inet_addr (ip); /* on host ip */
fd = socket (AF_INET, SOCK_STREAM, 0);
if (fd == -1)
goto sys_error;
/* set to non-blocking mode so that we can cancel the connect */
#ifndef G_OS_WIN32
fcntl (fd, F_SETFL, O_NONBLOCK);
#else
ioctlsocket (fd, FIONBIO, &flags);
#endif /* G_OS_WIN32 */
/* we are going to connect ASYNC now */
ret = connect (fd, (struct sockaddr *) &sa_in, sizeof (sa_in));
if (ret == 0)
goto done;
if (errno != EINPROGRESS)
goto sys_error;
/* wait for connect to complete up to the specified timeout or until we got
* interrupted. */
FD_ZERO (&writefds);
FD_SET (fd, &writefds);
FD_ZERO (&readfds);
FD_SET (READ_SOCKET (conn), &readfds);
if (timeout->tv_sec != 0 || timeout->tv_usec != 0) {
tv.tv_sec = timeout->tv_sec;
tv.tv_usec = timeout->tv_usec;
tvp = &tv;
} else {
tvp = NULL;
}
max_fd = MAX (fd, READ_SOCKET (conn));
do {
retval = select (max_fd + 1, &readfds, &writefds, NULL, tvp);
} while ((retval == -1 && errno == EINTR));
if (retval == 0)
goto timeout;
else if (retval == -1)
goto sys_error;
done:
conn->fd = fd;
conn->ip = g_strdup (ip);
return GST_RTSP_OK;
sys_error:
{
if (fd != -1)
CLOSE_SOCKET (fd);
return GST_RTSP_ESYS;
}
not_resolved:
{
return GST_RTSP_ENET;
}
not_ip:
{
return GST_RTSP_ENOTIP;
}
timeout:
{
return GST_RTSP_ETIMEOUT;
}
}
static void
add_auth_header (GstRTSPConnection * conn, GstRTSPMessage * message)
{
switch (conn->auth_method) {
case GST_RTSP_AUTH_BASIC:{
gchar *user_pass =
g_strdup_printf ("%s:%s", conn->username, conn->passwd);
gchar *user_pass64 =
gst_rtsp_base64_encode (user_pass, strlen (user_pass));
gchar *auth_string = g_strdup_printf ("Basic %s", user_pass64);
gst_rtsp_message_add_header (message, GST_RTSP_HDR_AUTHORIZATION,
auth_string);
g_free (user_pass);
g_free (user_pass64);
g_free (auth_string);
break;
}
default:
/* Nothing to do */
break;
}
}
static void
add_date_header (GstRTSPMessage * message)
{
GTimeVal tv;
gchar date_string[100];
g_get_current_time (&tv);
strftime (date_string, sizeof (date_string), "%a, %d %b %Y %H:%M:%S GMT",
gmtime (&tv.tv_sec));
gst_rtsp_message_add_header (message, GST_RTSP_HDR_DATE, date_string);
}
GstRTSPResult
gst_rtsp_connection_write (GstRTSPConnection * conn, const guint8 * data,
guint size, GTimeVal * timeout)
{
guint towrite;
fd_set writefds;
fd_set readfds;
int max_fd;
gint retval;
struct timeval tv, *tvp;
g_return_val_if_fail (conn != NULL, GST_RTSP_EINVAL);
g_return_val_if_fail (data != NULL || size == 0, GST_RTSP_EINVAL);
FD_ZERO (&writefds);
FD_SET (conn->fd, &writefds);
FD_ZERO (&readfds);
FD_SET (READ_SOCKET (conn), &readfds);
max_fd = MAX (conn->fd, READ_SOCKET (conn));
if (timeout) {
tv.tv_sec = timeout->tv_sec;
tv.tv_usec = timeout->tv_usec;
tvp = &tv;
} else {
tvp = NULL;
}
towrite = size;
while (towrite > 0) {
gint written;
do {
retval = select (max_fd + 1, &readfds, &writefds, NULL, tvp);
} while ((retval == -1 && errno == EINTR));
if (retval == 0)
goto timeout;
if (retval == -1)
goto select_error;
if (FD_ISSET (READ_SOCKET (conn), &readfds)) {
/* read all stop commands */
while (TRUE) {
gchar command;
int res;
READ_COMMAND (c