summaryrefslogtreecommitdiff
path: root/src/input
diff options
context:
space:
mode:
Diffstat (limited to 'src/input')
-rw-r--r--src/input/Makefile.am1
-rw-r--r--src/input/http_helper.c3
-rw-r--r--src/input/input_cdda.c308
-rw-r--r--src/input/input_dvb.c178
-rw-r--r--src/input/input_dvd.c69
-rw-r--r--src/input/input_file.c58
-rw-r--r--src/input/input_gnome_vfs.c7
-rw-r--r--src/input/input_http.c125
-rw-r--r--src/input/input_mms.c11
-rw-r--r--src/input/input_net.c18
-rw-r--r--src/input/input_plugin.h90
-rw-r--r--src/input/input_pnm.c26
-rw-r--r--src/input/input_pvr.c41
-rw-r--r--src/input/input_rtp.c18
-rw-r--r--src/input/input_rtsp.c29
-rw-r--r--src/input/input_smb.c61
-rw-r--r--src/input/input_stdin_fifo.c19
-rw-r--r--src/input/input_v4l.c218
-rw-r--r--src/input/input_vcd.c89
-rw-r--r--src/input/libdvdnav/bswap.h2
-rw-r--r--src/input/libdvdnav/diff_against_cvs.patch2
-rw-r--r--src/input/libdvdnav/dvd_reader.c24
-rw-r--r--src/input/libdvdnav/dvd_reader.h4
-rw-r--r--src/input/libdvdnav/ifo_read.c6
-rw-r--r--src/input/libdvdnav/md5.c2
-rw-r--r--src/input/libdvdnav/remap.c1
-rw-r--r--src/input/libreal/asmrp.c6
-rw-r--r--src/input/libreal/real.c15
-rw-r--r--src/input/libreal/rmff.c144
-rw-r--r--src/input/libreal/rmff.h14
-rw-r--r--src/input/libreal/sdpplin.c42
-rw-r--r--src/input/libreal/sdpplin.h6
-rw-r--r--src/input/librtsp/rtsp.c60
-rw-r--r--src/input/librtsp/rtsp.h2
-rw-r--r--src/input/librtsp/rtsp_session.c12
-rw-r--r--src/input/librtsp/rtsp_session.h2
-rw-r--r--src/input/mms.c24
-rw-r--r--src/input/mmsh.c6
-rw-r--r--src/input/net_buf_ctrl.c6
-rw-r--r--src/input/net_buf_ctrl.h8
-rw-r--r--src/input/pnm.c23
-rw-r--r--src/input/vcd/Makefile.am1
-rw-r--r--src/input/vcd/libcdio/FreeBSD/freebsd.c2
-rw-r--r--src/input/vcd/libcdio/MSWindows/aspi32.c4
-rw-r--r--src/input/vcd/xine-extra.c10
-rw-r--r--src/input/vcd/xineplug_inp_vcd.c16
46 files changed, 1072 insertions, 741 deletions
diff --git a/src/input/Makefile.am b/src/input/Makefile.am
index 81dd62eca..8e9c9385d 100644
--- a/src/input/Makefile.am
+++ b/src/input/Makefile.am
@@ -1,3 +1,4 @@
+include $(top_builddir)/misc/Makefile.plugins
include $(top_srcdir)/misc/Makefile.common
EXTRA_DIST = input_dvd.c input_vcd.c input_gnome_vfs.c input_rtp.c
diff --git a/src/input/http_helper.c b/src/input/http_helper.c
index 4883763b0..279d3ff05 100644
--- a/src/input/http_helper.c
+++ b/src/input/http_helper.c
@@ -240,8 +240,7 @@ char *_x_canonicalise_url (const char *base, const char *url) {
++cut;
}
base_length = cut ? (size_t)(cut - base) : strlen (base);
- ret = malloc (base_length + strlen (url) + 1);
- sprintf (ret, "%.*s%s", (int)base_length, base, url);
+ asprintf (&ret, "%.*s%s", (int)base_length, base, url);
return ret;
}
diff --git a/src/input/input_cdda.c b/src/input/input_cdda.c
index fd4dd1fa9..d982909eb 100644
--- a/src/input/input_cdda.c
+++ b/src/input/input_cdda.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2000-2005 the xine project
+ * Copyright (C) 2000-2008 the xine project
*
* This file is part of xine, a free video player.
*
@@ -44,6 +44,7 @@
# include <sys/ioctl.h>
#else
/* for WIN32 */
+# include <windef.h>
# include <winioctl.h>
#endif
@@ -70,6 +71,8 @@
#define DEFAULT_CDDA_DEVICE "/vol/dev/aliases/cdrom0"
#elif defined(WIN32)
#define DEFAULT_CDDA_DEVICE "d:\\"
+#elif defined(__OpenBSD__)
+#define DEFAULT_CDDA_DEVICE "/dev/rcd0c"
#else
#define DEFAULT_CDDA_DEVICE "/dev/cdrom"
#endif
@@ -135,7 +138,7 @@ typedef struct {
char *disc_category;
int fd;
- unsigned long disc_id;
+ uint32_t disc_id;
int disc_length;
trackinfo_t *track;
@@ -370,7 +373,7 @@ static cdrom_toc * init_cdrom_toc(void) {
cdrom_toc *toc;
- toc = (cdrom_toc *) xine_xmalloc(sizeof (cdrom_toc));
+ toc = calloc(1, sizeof (cdrom_toc));
toc->first_track = toc->last_track = toc->total_tracks = 0;
toc->toc_entries = NULL;
@@ -418,10 +421,9 @@ static int read_cdrom_toc(int fd, cdrom_toc *toc) {
toc->total_tracks = toc->last_track - toc->first_track + 1;
/* allocate space for the toc entries */
- toc->toc_entries =
- (cdrom_toc_entry *)malloc(toc->total_tracks * sizeof(cdrom_toc_entry));
+ toc->toc_entries = calloc(toc->total_tracks, sizeof(cdrom_toc_entry));
if (!toc->toc_entries) {
- perror("malloc");
+ perror("calloc");
return -1;
}
@@ -529,10 +531,9 @@ static int read_cdrom_toc(int fd, cdrom_toc *toc) {
toc->total_tracks = toc->last_track - toc->first_track + 1;
/* allocate space for the toc entries */
- toc->toc_entries =
- (cdrom_toc_entry *)malloc(toc->total_tracks * sizeof(cdrom_toc_entry));
+ toc->toc_entries = calloc(toc->total_tracks, sizeof(cdrom_toc_entry));
if (!toc->toc_entries) {
- perror("malloc");
+ perror("calloc");
return -1;
}
@@ -612,7 +613,7 @@ static int read_cdrom_frames(cdda_input_plugin_t *this_gen, int frame, int num_f
return 0;
}
-#elif defined(__FreeBSD_kernel__) || defined(__NetBSD__)
+#elif defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__)
#include <sys/cdio.h>
@@ -625,7 +626,7 @@ static int read_cdrom_toc(int fd, cdrom_toc *toc) {
struct ioc_toc_header tochdr;
#if defined(__FreeBSD_kernel__)
struct ioc_read_toc_single_entry tocentry;
-#elif defined(__NetBSD__)
+#elif defined(__NetBSD__) || defined(__OpenBSD__)
struct ioc_read_toc_entry tocentry;
struct cd_toc_entry data;
#endif
@@ -642,10 +643,9 @@ static int read_cdrom_toc(int fd, cdrom_toc *toc) {
toc->total_tracks = toc->last_track - toc->first_track + 1;
/* allocate space for the toc entries */
- toc->toc_entries =
- (cdrom_toc_entry *)malloc(toc->total_tracks * sizeof(cdrom_toc_entry));
+ toc->toc_entries = calloc(toc->total_tracks, sizeof(cdrom_toc_entry));
if (!toc->toc_entries) {
- perror("malloc");
+ perror("calloc");
return -1;
}
@@ -661,7 +661,7 @@ static int read_cdrom_toc(int fd, cdrom_toc *toc) {
perror("CDIOREADTOCENTRY");
return -1;
}
-#elif defined(__NetBSD__)
+#elif defined(__NetBSD__) || defined(__OpenBSD__)
memset(&data, 0, sizeof(data));
tocentry.data_len = sizeof(data);
tocentry.data = &data;
@@ -682,7 +682,7 @@ static int read_cdrom_toc(int fd, cdrom_toc *toc) {
(tocentry.entry.addr.msf.minute * CD_SECONDS_PER_MINUTE * CD_FRAMES_PER_SECOND) +
(tocentry.entry.addr.msf.second * CD_FRAMES_PER_SECOND) +
tocentry.entry.addr.msf.frame;
-#elif defined(__NetBSD__)
+#elif defined(__NetBSD__) || defined(__OpenBSD__)
toc->toc_entries[i-1].track_mode = (tocentry.data->control & 0x04) ? 1 : 0;
toc->toc_entries[i-1].first_frame_minute = tocentry.data->addr.msf.minute;
toc->toc_entries[i-1].first_frame_second = tocentry.data->addr.msf.second;
@@ -704,7 +704,7 @@ static int read_cdrom_toc(int fd, cdrom_toc *toc) {
perror("CDIOREADTOCENTRY");
return -1;
}
-#elif defined(__NetBSD__)
+#elif defined(__NetBSD__) || defined(__OpenBSD__)
memset(&data, 0, sizeof(data));
tocentry.data_len = sizeof(data);
tocentry.data = &data;
@@ -725,7 +725,7 @@ static int read_cdrom_toc(int fd, cdrom_toc *toc) {
(tocentry.entry.addr.msf.minute * CD_SECONDS_PER_MINUTE * CD_FRAMES_PER_SECOND) +
(tocentry.entry.addr.msf.second * CD_FRAMES_PER_SECOND) +
tocentry.entry.addr.msf.frame;
-#elif defined(__NetBSD__)
+#elif defined(__NetBSD__) || defined(__OpenBSD__)
toc->leadout_track.track_mode = (tocentry.data->control & 0x04) ? 1 : 0;
toc->leadout_track.first_frame_minute = tocentry.data->addr.msf.minute;
toc->leadout_track.first_frame_second = tocentry.data->addr.msf.second;
@@ -763,7 +763,7 @@ static int read_cdrom_frames(cdda_input_plugin_t *this_gen, int frame, int num_f
perror("CDIOCREADAUDIO");
return -1;
}
-#elif defined(__NetBSD__)
+#elif defined(__NetBSD__) || defined(__OpenBSD__)
scsireq_t req;
int nblocks = 1;
@@ -835,10 +835,9 @@ static int read_cdrom_toc(cdda_input_plugin_t *this_gen, cdrom_toc *toc) {
/* allocate space for the toc entries */
- toc->toc_entries =
- (cdrom_toc_entry *)malloc(toc->total_tracks * sizeof(cdrom_toc_entry));
+ toc->toc_entries = calloc(toc->total_tracks, sizeof(cdrom_toc_entry));
if (!toc->toc_entries) {
- perror("malloc");
+ perror("calloc");
return -1;
}
@@ -1036,13 +1035,13 @@ network_command( xine_stream_t *stream, int socket, char *data_buf, char *msg, .
#ifndef WIN32
-static int network_connect(xine_stream_t *stream, char *url )
+static int network_connect(xine_stream_t *stream, const char *got_url )
{
- char *host;
+ char *host, *url;
int port;
int fd;
- url = strdup(url);
+ url = strdup(got_url);
parse_url(url, &host, &port);
if( !host || !strlen(host) || !port )
@@ -1081,10 +1080,9 @@ static int network_read_cdrom_toc(xine_stream_t *stream, int fd, cdrom_toc *toc)
toc->total_tracks = toc->last_track - toc->first_track + 1;
/* allocate space for the toc entries */
- toc->toc_entries =
- (cdrom_toc_entry *)malloc(toc->total_tracks * sizeof(cdrom_toc_entry));
+ toc->toc_entries = calloc(toc->total_tracks, sizeof(cdrom_toc_entry));
if (!toc->toc_entries) {
- perror("malloc");
+ perror("calloc");
return -1;
}
@@ -1312,20 +1310,17 @@ static void _cdda_mkdir_recursive_safe(xine_t *xine, char *path) {
if(p && strlen(p)) {
#ifdef WIN32
- if (*buf2 != '\0') {
+ if (*buf2 != '\0') {
#endif
-
- int size = strlen(buf2);
- snprintf(buf2 + size, sizeof(buf2) - size, "/%s", p);
-
+ size_t size = strlen(buf2);
+ snprintf(buf2 + size, sizeof(buf2) - size, "/%s", p);
#ifdef WIN32
- }
- else {
- snprintf(buf2, sizeof(buf2), "%s", p);
- }
-
+ }
+ else {
+ snprintf(buf2, sizeof(buf2), "%s", p);
+ }
#endif /* WIN32 */
-
+
_cdda_mkdir_safe(xine, buf2);
}
}
@@ -1443,13 +1438,13 @@ static int _cdda_cddb_handle_code(char *buf) {
*/
static int _cdda_load_cached_cddb_infos(cdda_input_plugin_t *this) {
char cdir[XINE_PATH_MAX + XINE_NAME_MAX + 1];
+ size_t cdir_size = 0;
DIR *dir;
if(this == NULL)
return 0;
- memset(&cdir, 0, sizeof(cdir));
- snprintf(cdir, sizeof(cdir), "%s", this->cddb.cache_dir);
+ cdir_size = snprintf(cdir, sizeof(cdir), "%s", this->cddb.cache_dir);
if((dir = opendir(cdir)) != NULL) {
struct dirent *pdir;
@@ -1457,14 +1452,12 @@ static int _cdda_load_cached_cddb_infos(cdda_input_plugin_t *this) {
while((pdir = readdir(dir)) != NULL) {
char discid[9];
- memset(&discid, 0, sizeof(discid));
- snprintf(discid, sizeof(discid), "%08lx", this->cddb.disc_id);
+ snprintf(discid, sizeof(discid), "%08" PRIx32, this->cddb.disc_id);
if(!strcasecmp(pdir->d_name, discid)) {
FILE *fd;
- int size = strlen(cdir);
- snprintf(cdir + size, sizeof(cdir) - size, "/%s", discid);
+ cdir_size += snprintf(cdir + cdir_size, sizeof(cdir) - cdir_size, "/%s", discid);
if((fd = fopen(cdir, "r")) == NULL) {
xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG,
"input_cdda: fopen(%s) failed: %s.\n", cdir, strerror(errno));
@@ -1484,7 +1477,7 @@ static int _cdda_load_cached_cddb_infos(cdda_input_plugin_t *this) {
if (sscanf(buffer, "DTITLE=%s", &buf[0]) == 1) {
char *pt, *artist, *title;
- pt = strrchr(buffer, '=');
+ pt = strchr(buffer, '=');
if (pt) {
pt++;
@@ -1524,7 +1517,7 @@ static int _cdda_load_cached_cddb_infos(cdda_input_plugin_t *this) {
else if (sscanf(buffer, "TTITLE%d=%s", &tnum, &buf[0]) == 2) {
char *pt;
- pt = strrchr(buffer, '=');
+ pt = strchr(buffer, '=');
if (pt)
pt++;
if (this->cddb.track[tnum].title == NULL)
@@ -1542,14 +1535,9 @@ static int _cdda_load_cached_cddb_infos(cdda_input_plugin_t *this) {
int nyear;
y = strstr(buffer, "YEAR:");
- if(y) {
- if (sscanf(y+5, "%4d", &nyear) == 1) {
- char year[5];
-
- snprintf(year, 5, "%d", nyear);
- if (this->cddb.disc_year == NULL)
- this->cddb.disc_year = strdup(year);
- }
+ if (y && this->cddb.disc_year == NULL) {
+ if (sscanf(y+5, "%4d", &nyear) == 1)
+ asprintf(&this->cddb.disc_year, "%d", nyear);
}
}
}
@@ -1563,7 +1551,7 @@ static int _cdda_load_cached_cddb_infos(cdda_input_plugin_t *this) {
}
}
xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG,
- "input_cdda: cached entry for disc ID %08lx not found.\n", this->cddb.disc_id);
+ "input_cdda: cached entry for disc ID %08" PRIx32 " not found.\n", this->cddb.disc_id);
closedir(dir);
}
@@ -1587,7 +1575,7 @@ static void _cdda_save_cached_cddb_infos(cdda_input_plugin_t *this, char *fileco
_cdda_mkdir_recursive_safe(this->stream->xine, cfile);
- snprintf(cfile, sizeof(cfile), "%s/%08lx", this->cddb.cache_dir, this->cddb.disc_id);
+ snprintf(cfile, sizeof(cfile), "%s/%08" PRIx32 , this->cddb.cache_dir, this->cddb.disc_id);
if((fd = fopen(cfile, "w")) == NULL) {
xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG,
@@ -1726,12 +1714,11 @@ static int _cdda_cddb_retrieve(cdda_input_plugin_t *this) {
/* Send query command */
memset(&buffer, 0, sizeof(buffer));
- sprintf(buffer, "cddb query %08lx %d ", this->cddb.disc_id, this->cddb.num_tracks);
+ size_t size = sprintf(buffer, "cddb query %08" PRIx32 " %d ", this->cddb.disc_id, this->cddb.num_tracks);
for (i = 0; i < this->cddb.num_tracks; i++) {
- int size = strlen(buffer);
- snprintf(buffer + size, sizeof(buffer) - size, "%d ", this->cddb.track[i].start);
+ size += snprintf(buffer + size, sizeof(buffer) - size, "%d ", this->cddb.track[i].start);
}
- snprintf(buffer + strlen(buffer), sizeof(buffer) - strlen(buffer), "%d\n", this->cddb.disc_length);
+ snprintf(buffer + strlen(buffer), sizeof(buffer) - size, "%d\n", this->cddb.disc_length);
if ((err = _cdda_cddb_send_command(this, buffer)) <= 0) {
xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG,
"input_cdda: error while sending cddb query command.\n");
@@ -1818,7 +1805,7 @@ static int _cdda_cddb_retrieve(cdda_input_plugin_t *this) {
while (strcmp(buffer, ".")) {
char buf[2048];
int tnum;
- int bufsize = strlen(buffercache);
+ size_t bufsize = strlen(buffercache);
memset(&buffer, 0, sizeof(buffer));
_cdda_cddb_socket_read(this, buffer, sizeof(buffer) - 1);
@@ -1886,14 +1873,9 @@ static int _cdda_cddb_retrieve(cdda_input_plugin_t *this) {
int nyear;
y = strstr(buffer, "YEAR:");
- if (y) {
- if (sscanf(y+5, "%4d", &nyear) == 1) {
- char year[5];
-
- snprintf(year, 5, "%d", nyear);
- if (this->cddb.disc_year == NULL)
- this->cddb.disc_year = strdup(year);
- }
+ if (y && this->cddb.disc_year == NULL) {
+ if (sscanf(y+5, "%4d", &nyear) == 1)
+ asprintf(&this->cddb.disc_year, "%d", nyear);
}
}
}
@@ -1922,7 +1904,7 @@ static unsigned int _cdda_cddb_sum(int n) {
}
return ret;
}
-static unsigned long _cdda_calc_cddb_id(cdda_input_plugin_t *this) {
+static uint32_t _cdda_calc_cddb_id(cdda_input_plugin_t *this) {
int i, tsum = 0;
if(this == NULL || (this->cddb.num_tracks <= 0))
@@ -1979,7 +1961,7 @@ static void _cdda_cdindex(cdda_input_plugin_t *this, cdrom_toc *toc) {
/*
* return cbbd disc id.
*/
-static unsigned long _cdda_get_cddb_id(cdda_input_plugin_t *this) {
+static uint32_t _cdda_get_cddb_id(cdda_input_plugin_t *this) {
if(this == NULL || (this->cddb.num_tracks <= 0))
return 0;
@@ -2024,7 +2006,7 @@ static void _cdda_free_cddb_info(cdda_input_plugin_t *this) {
*/
static int cdda_open(cdda_input_plugin_t *this_gen,
- char *cdda_device, cdrom_toc *toc, int *fdd) {
+ const char *cdda_device, cdrom_toc *toc, int *fdd) {
#ifndef WIN32
int fd = -1;
@@ -2104,9 +2086,9 @@ static int cdda_open(cdda_input_plugin_t *this_gen,
hASPI = LoadLibrary( "wnaspi32.dll" );
if( hASPI != NULL )
{
- (FARPROC) lpGetSupport = GetProcAddress( hASPI,
+ lpGetSupport = GetProcAddress( hASPI,
"GetASPI32SupportInfo" );
- (FARPROC) lpSendCommand = GetProcAddress( hASPI,
+ lpSendCommand = GetProcAddress( hASPI,
"SendASPI32Command" );
}
@@ -2458,7 +2440,7 @@ static int cdda_plugin_open (input_plugin_t *this_gen ) {
if(this->cddb.num_tracks) {
int t;
- this->cddb.track = (trackinfo_t *) xine_xmalloc(sizeof(trackinfo_t) * this->cddb.num_tracks);
+ this->cddb.track = (trackinfo_t *) calloc(this->cddb.num_tracks, sizeof(trackinfo_t));
for(t = 0; t < this->cddb.num_tracks; t++) {
int length = (toc->toc_entries[t].first_frame_minute * CD_SECONDS_PER_MINUTE +
@@ -2485,15 +2467,31 @@ static int cdda_plugin_open (input_plugin_t *this_gen ) {
}
if(this->cddb.track[this->track].title) {
- lprintf("Track %d Title: %s\n", this->track+1, this->cddb.track[this->track].title);
-
- _x_meta_info_set_utf8(this->stream, XINE_META_INFO_TITLE, this->cddb.track[this->track].title);
- }
+ /* Check for track 'titles' of the form <artist> / <title>. */
+ char *pt;
+ pt = strstr(this->cddb.track[this->track].title, " / ");
+ if (pt != NULL) {
+ char *track_artist;
+ track_artist = strdup(this->cddb.track[this->track].title);
+ track_artist[pt - this->cddb.track[this->track].title] = 0;
+ lprintf("Track %d Artist: %s\n", this->track+1, track_artist);
+
+ _x_meta_info_set_utf8(this->stream, XINE_META_INFO_ARTIST, track_artist);
+ free(track_artist);
+ pt += 3;
+ }
+ else {
+ if(this->cddb.disc_artist) {
+ lprintf("Disc Artist: %s\n", this->cddb.disc_artist);
+
+ _x_meta_info_set_utf8(this->stream, XINE_META_INFO_ARTIST, this->cddb.disc_artist);
+ }
- if(this->cddb.disc_artist) {
- lprintf("Disc Artist: %s\n", this->cddb.disc_artist);
+ pt = this->cddb.track[this->track].title;
+ }
+ lprintf("Track %d Title: %s\n", this->track+1, pt);
- _x_meta_info_set_utf8(this->stream, XINE_META_INFO_ARTIST, this->cddb.disc_artist);
+ _x_meta_info_set_utf8(this->stream, XINE_META_INFO_TITLE, pt);
}
if(this->cddb.disc_category) {
@@ -2513,13 +2511,140 @@ static int cdda_plugin_open (input_plugin_t *this_gen ) {
return 1;
}
+static xine_mrl_t** cdda_class_get_dir(input_class_t *this_gen,
+ const char *filename,
+ int *num_files) {
+ cdda_input_class_t *this = (cdda_input_class_t *) this_gen;
+ cdda_input_plugin_t *ip;
+ cdrom_toc *toc;
+ char *base_mrl;
+ int len, frame;
+ const char * device;
+ int fd, i, err = -1;
+ int num_tracks;
+
+ if (filename && *filename) {
+ device = filename;
+ if (strncasecmp(device,"cdda:/",6) == 0) {
+ device += 6;
+ while ('/' == *device)
+ device++;
+ device--;
+ }
+ }
+ else {
+ device = this->cdda_device;
+ }
+ lprintf("cdda_class_get_dir for >%s<\n", device);
+
+ /* get the CD TOC */
+ toc = init_cdrom_toc();
+
+ fd = -1;
+
+ /* we create a new instance because getting a directory of a cd
+ * should not affect another cd that might be playing. */
+ ip = (cdda_input_plugin_t *)xine_xmalloc(sizeof(cdda_input_plugin_t));
+ ip->stream = NULL;
+ ip->fd = -1;
+ ip->net_fd = -1;
+
+#ifndef WIN32
+ if( strchr(device,':') ) {
+ fd = network_connect(ip->stream, device);
+ if( fd != -1 ) {
+ err = network_read_cdrom_toc(ip->stream, fd, toc);
+ }
+ }
+#endif
+
+ if (fd == -1) {
+ if (cdda_open(ip, device, toc, &fd) == -1) {
+ lprintf("cdda_class_get_dir: opening >%s< failed %s\n",
+ device, strerror(errno));
+ free(ip);
+ return NULL;
+ }
+
+#ifndef WIN32
+ err = read_cdrom_toc(fd, toc);
+#else
+ err = read_cdrom_toc(ip, toc);
+#endif /* WIN32 */
+ }
+
+#ifdef LOG
+ print_cdrom_toc(toc);
+#endif
+
+ cdda_close(ip);
+
+ if ( err < 0 ) {
+ free(ip);
+ return NULL;
+ }
+
+ num_tracks = toc->last_track - toc->first_track + 1;
+
+ /* this could be done in read_cdrom_toc, but it seems other code doesn't use it */
+ frame = toc->leadout_track.first_frame;
+ for ( i = num_tracks-1 ; i >= 0 ; i--) {
+ toc->toc_entries[i].total_frames = frame - toc->toc_entries[i].first_frame;
+ frame = toc->toc_entries[i].first_frame;
+ }
+
+ if (toc->ignore_last_track)
+ num_tracks--;
+
+ len = strlen(device) + 5;
+ base_mrl = xine_xmalloc(len+1);
+ sprintf(base_mrl, "cdda:%s", device);
+
+ /* allocate space for the mrls's if needed. */
+ if (num_tracks+1 > this->mrls_allocated_entries) {
+ this->mrls = realloc(this->mrls, (num_tracks+1) * sizeof(xine_mrl_t*));
+ }
+ for (i = 0 ; i < num_tracks ; i++) {
+ if (i < this->mrls_allocated_entries) {
+ if (this->mrls[i]->origin)
+ free(this->mrls[i]->origin);
+ if (this->mrls[i]->mrl)
+ free(this->mrls[i]->mrl);
+ if (this->mrls[i]->link) {
+ free(this->mrls[i]->link);
+ this->mrls[i]->link = NULL;
+ }
+ }
+ else {
+ this->mrls[i] = (xine_mrl_t *) xine_xmalloc(sizeof(xine_mrl_t));
+ this->mrls[i]->link = NULL;
+ this->mrls_allocated_entries++;
+ }
+ this->mrls[i]->origin = strdup(base_mrl);
+ this->mrls[i]->mrl = xine_xmalloc(len+4);
+ sprintf( this->mrls[i]->mrl, "%s/%d", base_mrl, i+toc->first_track);
+ this->mrls[i]->type = mrl_cda | mrl_file_blockdev;
+ this->mrls[i]->size = toc->toc_entries[i].total_frames * CD_RAW_FRAME_SIZE;
+ }
+ /* Clean up */
+ while(this->mrls_allocated_entries > num_tracks) {
+ MRL_ZERO(this->mrls[this->mrls_allocated_entries - 1]);
+ free(this->mrls[this->mrls_allocated_entries--]);
+ }
+ free_cdrom_toc(toc);
+ free(ip);
+
+ this->mrls[num_tracks] = NULL;
+ *num_files = num_tracks;
+ return this->mrls;
+}
+
static char ** cdda_class_get_autoplay_list (input_class_t *this_gen,
int *num_files) {
cdda_input_class_t *this = (cdda_input_class_t *) this_gen;
cdda_input_plugin_t *ip = this->ip;
cdrom_toc *toc;
- char trackmrl[20];
int fd, i, err = -1;
int num_tracks;
@@ -2541,7 +2666,7 @@ static char ** cdda_class_get_autoplay_list (input_class_t *this_gen,
* device we are going to open; but it is possible that this function
* gets called, before a plugin instance has been created;
* let's create a dummy instance in such a condition */
- ip = (cdda_input_plugin_t *)xine_xmalloc(sizeof(cdda_input_plugin_t));
+ ip = calloc(1, sizeof(cdda_input_plugin_t));
ip->stream = NULL;
ip->fd = -1;
ip->net_fd = -1;
@@ -2585,10 +2710,8 @@ static char ** cdda_class_get_autoplay_list (input_class_t *this_gen,
num_tracks = toc->last_track - toc->first_track;
if (toc->ignore_last_track)
num_tracks--;
- for ( i = 0; i <= num_tracks; i++ ) {
- sprintf(trackmrl,"cdda:/%d",i+toc->first_track);
- this->autoplaylist[i] = strdup(trackmrl);
- }
+ for ( i = 0; i <= num_tracks; i++ )
+ asprintf(&this->autoplaylist[i],"cdda:/%d",i+toc->first_track);
*num_files = toc->last_track - toc->first_track + 1;
@@ -2642,7 +2765,7 @@ static input_plugin_t *cdda_class_get_instance (input_class_t *cls_gen, xine_str
} else
return NULL;
- this = (cdda_input_plugin_t *) xine_xmalloc (sizeof (cdda_input_plugin_t));
+ this = calloc(1, sizeof (cdda_input_plugin_t));
class->ip = this;
this->stream = stream;
@@ -2731,7 +2854,7 @@ static void *init_plugin (xine_t *xine, void *data) {
cdda_input_class_t *this;
config_values_t *config;
- this = (cdda_input_class_t *) xine_xmalloc (sizeof (cdda_input_class_t));
+ this = calloc(1, sizeof (cdda_input_class_t));
this->xine = xine;
this->config = xine->config;
@@ -2740,8 +2863,7 @@ static void *init_plugin (xine_t *xine, void *data) {
this->input_class.get_instance = cdda_class_get_instance;
this->input_class.get_identifier = cdda_class_get_identifier;
this->input_class.get_description = cdda_class_get_description;
- /* this->input_class.get_dir = cdda_class_get_dir; */
- this->input_class.get_dir = NULL;
+ this->input_class.get_dir = cdda_class_get_dir;
this->input_class.get_autoplay_list = cdda_class_get_autoplay_list;
this->input_class.dispose = cdda_class_dispose;
this->input_class.eject_media = cdda_class_eject_media;
diff --git a/src/input/input_dvb.c b/src/input/input_dvb.c
index 795b843c5..5060757e4 100644
--- a/src/input/input_dvb.c
+++ b/src/input/input_dvb.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2000-2005 the xine project
+ * Copyright (C) 2000-2008 the xine project
*
* This file is part of xine, a free video player.
*
@@ -66,14 +66,14 @@
* OSD - this will allow for filtering/searching of epg data - useful for automatic recording :)
*/
-/* pthread.h must be included first so rest of the headers are imported
- thread safely (on some systems). */
-#include <pthread.h>
-
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
+/* pthread.h must be included first so rest of the headers are imported
+ thread safely (on some systems). */
+#include <pthread.h>
+
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
@@ -286,11 +286,12 @@ typedef struct {
xine_t *xine;
- char *mrls[5];
+ char *mrls[6];
int numchannels;
char *autoplaylist[MAX_AUTOCHANNELS];
+ char *default_channels_conf_filename;
} dvb_input_class_t;
typedef struct {
@@ -331,6 +332,9 @@ typedef struct {
/* scratch buffer for forward seeking */
char seek_buf[BUFSIZE];
+ /* Is the GUI enabled at all? */
+ int dvb_gui_enabled;
+
/* simple vcr-like functionality */
int record_fd;
int record_paused;
@@ -369,6 +373,7 @@ static const Param bw_list [] = {
{ "BANDWIDTH_6_MHZ", BANDWIDTH_6_MHZ },
{ "BANDWIDTH_7_MHZ", BANDWIDTH_7_MHZ },
{ "BANDWIDTH_8_MHZ", BANDWIDTH_8_MHZ },
+ { "BANDWIDTH_AUTO", BANDWIDTH_AUTO },
{ NULL, 0 }
};
@@ -391,6 +396,7 @@ static const Param guard_list [] = {
{"GUARD_INTERVAL_1_32", GUARD_INTERVAL_1_32},
{"GUARD_INTERVAL_1_4", GUARD_INTERVAL_1_4},
{"GUARD_INTERVAL_1_8", GUARD_INTERVAL_1_8},
+ {"GUARD_INTERVAL_AUTO", GUARD_INTERVAL_AUTO},
{ NULL, 0 }
};
@@ -399,6 +405,7 @@ static const Param hierarchy_list [] = {
{ "HIERARCHY_2", HIERARCHY_2 },
{ "HIERARCHY_4", HIERARCHY_4 },
{ "HIERARCHY_NONE", HIERARCHY_NONE },
+ { "HIERARCHY_AUTO", HIERARCHY_AUTO },
{ NULL, 0 }
};
@@ -417,12 +424,14 @@ static const Param qam_list [] = {
{ "QAM_256", QAM_256 },
{ "QAM_32", QAM_32 },
{ "QAM_64", QAM_64 },
+ { "QAM_AUTO", QAM_AUTO },
{ NULL, 0 }
};
static const Param transmissionmode_list [] = {
{ "TRANSMISSION_MODE_2K", TRANSMISSION_MODE_2K },
{ "TRANSMISSION_MODE_8K", TRANSMISSION_MODE_8K },
+ { "TRANSMISSION_MODE_AUTO", TRANSMISSION_MODE_AUTO },
{ NULL, 0 }
};
@@ -513,7 +522,7 @@ time_t dvb_mjdtime (char *buf)
int i;
unsigned int year, month, day, hour, min, sec;
unsigned long int mjd;
- struct tm *tma = xine_xmalloc(sizeof(struct tm));
+ struct tm *tma = calloc(1, sizeof(struct tm));
time_t t;
_x_assert(tma != NULL);
@@ -571,24 +580,23 @@ static void tuner_dispose(tuner_t * this)
}
-static tuner_t *tuner_init(xine_t * xine, int adapter)
+static tuner_t *XINE_MALLOC tuner_init(xine_t * xine, int adapter)
{
tuner_t *this;
int x;
int test_video;
- char *video_device=xine_xmalloc(200);
+ char *video_device=malloc(100);
_x_assert(video_device != NULL);
- this = (tuner_t *) xine_xmalloc(sizeof(tuner_t));
+ this = calloc(1, sizeof(tuner_t));
_x_assert(this != NULL);
xprintf(this->xine, XINE_VERBOSITY_DEBUG, "tuner_init adapter=%d\n", adapter);
this->fd_frontend = -1;
- for (x = 0; x < MAX_FILTERS; x++)
- this->fd_pidfilter[x] = 0;
+ memset(this->fd_pidfilter, 0, sizeof(this->fd_pidfilter));
this->xine = xine;
this->adapter_num = adapter;
@@ -881,14 +889,15 @@ static channel_t *load_channels(xine_t *xine, xine_stream_t *stream, int *num_ch
FILE *f;
char str[BUFSIZE];
- char filename[BUFSIZE];
channel_t *channels = NULL;
int num_channels = 0;
int num_alloc = 0;
- int i;
struct stat st;
-
- snprintf(filename, BUFSIZE, "%s/.xine/channels.conf", xine_get_homedir());
+ xine_cfg_entry_t channels_conf;
+ char *filename;
+
+ xine_config_lookup_entry(xine, "media.dvb.channels_conf", &channels_conf);
+ filename = channels_conf.str_value;
f = fopen(filename, "r");
if (!f) {
@@ -910,8 +919,8 @@ static channel_t *load_channels(xine_t *xine, xine_stream_t *stream, int *num_ch
while ( fgets (str, BUFSIZE, f)) {
channel_t channel = {0};
- /* lose trailing spaces & control characters */
- i = strlen (str);
+ /* lose trailing spaces & control characters */
+ size_t i = strlen (str);
while (i && str[i - 1] <= ' ')
--i;
if (i == 0)
@@ -922,7 +931,7 @@ static channel_t *load_channels(xine_t *xine, xine_stream_t *stream, int *num_ch
continue;
if (num_channels >= num_alloc) {
- channel_t *new_channels = xine_xmalloc((num_alloc += 32) * sizeof (channel_t));
+ channel_t *new_channels = calloc((num_alloc += 32), sizeof (channel_t));
_x_assert(new_channels != NULL);
memcpy(new_channels, channels, num_channels * sizeof (channel_t));
free(channels);
@@ -933,8 +942,7 @@ static channel_t *load_channels(xine_t *xine, xine_stream_t *stream, int *num_ch
/* Initially there's no EPG data in the EPG structs. */
channels[num_channels].epg_count = 0;
- for (i = 0; i < MAX_EPG_ENTRIES_PER_CHANNEL; ++i)
- channels[num_channels].epg[i] = NULL;
+ memset(channels[num_channels].epg, 0, sizeof(channels[num_channels].epg));
num_channels++;
}
@@ -1144,6 +1152,8 @@ static void parse_pmt(dvb_input_plugin_t *this, const unsigned char *buf, int se
switch (buf[0]) {
case 0x01:
case 0x02:
+ case 0x10:
+ case 0x1b:
if(!has_video) {
xprintf(this->stream->xine,XINE_VERBOSITY_LOG,"input_dvb: Adding VIDEO : PID 0x%04x\n", elementary_pid);
dvb_set_pidfilter(this, VIDFILTER, elementary_pid, DMX_PES_VIDEO, DMX_OUT_TS_TAP);
@@ -1153,6 +1163,8 @@ static void parse_pmt(dvb_input_plugin_t *this, const unsigned char *buf, int se
case 0x03:
case 0x04:
+ case 0x0f:
+ case 0x11:
if(!has_audio) {
xprintf(this->stream->xine,XINE_VERBOSITY_LOG,"input_dvb: Adding AUDIO : PID 0x%04x\n", elementary_pid);
dvb_set_pidfilter(this, AUDFILTER, elementary_pid, DMX_PES_AUDIO, DMX_OUT_TS_TAP);
@@ -1229,7 +1241,7 @@ static void dvb_parse_si(dvb_input_plugin_t *this) {
struct pollfd pfd;
tuner_t *tuner = this->tuner;
- tmpbuffer = xine_xmalloc (8192);
+ tmpbuffer = calloc(1, 8192);
_x_assert(tmpbuffer != NULL);
@@ -1437,13 +1449,10 @@ static void load_epg_data(dvb_input_plugin_t *this)
already "found" in the stream. This information is used to initialize the
channel's EPG structs when the EPG information for the channel is seen in
the stream the first time. */
- seen_channels = xine_xmalloc(this->num_channels*sizeof(char));
+ seen_channels = calloc(this->num_channels, sizeof(char));
_x_assert(seen_channels != NULL);
- for (i = 0; i < this->num_channels; i++) {
- seen_channels[i] = 0;
- }
- foo = xine_xmalloc(8192);
+ foo = calloc(1, 8192);
_x_assert(foo != NULL);
fd.fd = this->tuner->fd_pidfilter[EITFILTER];
@@ -1493,19 +1502,19 @@ static void load_epg_data(dvb_input_plugin_t *this)
Allocate space for the strings. */
if (current_channel->epg[current_channel->epg_count] == NULL) {
current_channel->epg[current_channel->epg_count] =
- xine_xmalloc(sizeof(epg_entry_t));
+ calloc(1, sizeof(epg_entry_t));
_x_assert(current_channel->epg[current_channel->epg_count] != NULL);
current_channel->epg[current_channel->epg_count]->progname =
- xine_xmalloc((MAX_EPG_PROGRAM_NAME_LENGTH + 1) * sizeof(char));
+ malloc(MAX_EPG_PROGRAM_NAME_LENGTH + 1);
_x_assert(current_channel->epg[current_channel->epg_count]->progname != NULL);
current_channel->epg[current_channel->epg_count]->description =
- xine_xmalloc((MAX_EPG_PROGRAM_DESCRIPTION_LENGTH + 1) * sizeof(char));
+ malloc(MAX_EPG_PROGRAM_DESCRIPTION_LENGTH + 1);
_x_assert(current_channel->epg[current_channel->epg_count]->description != NULL);
current_channel->epg[current_channel->epg_count]->content =
- xine_xmalloc((MAX_EPG_CONTENT_TYPE_LENGTH + 1) * sizeof(char));
+ malloc(MAX_EPG_CONTENT_TYPE_LENGTH + 1);
_x_assert(current_channel->epg[current_channel->epg_count]->content != NULL);
current_channel->epg[current_channel->epg_count]->running = 0;
@@ -1655,21 +1664,22 @@ static void load_epg_data(dvb_input_plugin_t *this)
}
/* Prints text to an area, tries to cut the lines in between words. */
-static void render_text_area(osd_renderer_t* renderer, osd_object_t* osd, char* text,
+static void render_text_area(osd_renderer_t* renderer, osd_object_t* osd, const char* text,
int x, int y, int row_space,
int max_x, int max_y, int* height, int color_base) {
/* The position of the text to be printed. */
- char* cursor = text;
+ const char* cursor = text;
+ const char *const text_end = text + strlen(text);
/* The line to be printed next. */
char text_line[512];
int text_width, text_height;
- int old_line_length, line_cursor;
- char* bound, *old_bound;
+ size_t old_line_length, line_cursor;
+ const char* bound, *old_bound;
*height = 0;
- while (cursor < text + strlen(text)) {
+ while (cursor < text_end) {
bound = cursor;
line_cursor = 0;
text_line[0] = '\0';
@@ -1726,7 +1736,7 @@ static void render_text_area(osd_renderer_t* renderer, osd_object_t* osd, char*
}
/* OK, it did fit, let's try to fit some more. */
- } while (bound < text + strlen(text));
+ } while (bound < text_end);
if (y + text_height + row_space > max_y) {
break;
@@ -1825,7 +1835,7 @@ static void show_program_info(int x, int y, int max_x, int max_y, int* last_y,
if (epg_data == NULL || epg_data->progname == NULL)
return;
- buffer = xine_xmalloc(512);
+ buffer = calloc(1, 512);
_x_assert(buffer != NULL);
@@ -1842,8 +1852,7 @@ static void show_program_info(int x, int y, int max_x, int max_y, int* last_y,
/*Content type and rating, if any. */
if (strlen(epg_data->content) > 3) {
-
- snprintf(buffer, 94, "%s", epg_data->content);
+ strncpy(buffer, epg_data->content, 94-1);
prog_rating = epg_data->rating;
if (prog_rating > 0) {
@@ -1873,7 +1882,7 @@ static void show_program_info(int x, int y, int max_x, int max_y, int* last_y,
/* Print the description. */
if (epg_data->description && strlen(epg_data->description) > 0) {
renderer->set_font(osd, "sans", EPG_DESCRIPTION_FONT_SIZE);
- sprintf(buffer, "%s", epg_data->description);
+ strcpy(buffer, epg_data->description);
/* If the description is not complete (i.e., there is no comma at the end),
add "..." to the end. In my locale they often seem to send incomplete description
texts :( */
@@ -2207,7 +2216,7 @@ static void do_record (dvb_input_plugin_t *this) {
this->stream->osd_renderer->hide (this->paused_osd, 0);
this->record_paused=0;
} else {
- t=xine_xmalloc(sizeof(time_t));
+ t=calloc(1, sizeof(time_t));
_x_assert(t != NULL);
@@ -2499,15 +2508,13 @@ static off_t dvb_plugin_read (input_plugin_t *this_gen,
if (!this->tuned_in)
return 0;
- dvb_event_handler (this);
+ if (this->dvb_gui_enabled)
+ dvb_event_handler (this);
#ifdef LOG_READS
xprintf(this->class->xine,XINE_VERBOSITY_DEBUG,
"input_dvb: reading %" PRIdMAX " bytes...\n", (intmax_t)len);
#endif
-#ifndef DVB_NO_BUFFERING
- nbc_check_buffers (this->nbc);
-#endif
/* protect against channel changes */
have_mutex = pthread_mutex_lock(&this->channel_change_mutex);
total=0;
@@ -2595,6 +2602,12 @@ static buf_element_t *dvb_plugin_read_block (input_plugin_t *this_gen,
buf_element_t *buf = fifo->buffer_pool_alloc (fifo);
int total_bytes;
+ if (todo > buf->max_size)
+ todo = buf->max_size;
+ if (todo < 0) {
+ buf->free_buffer (buf);
+ return NULL;
+ }
buf->content = buf->mem;
buf->type = BUF_DEMUX_BLOCK;
@@ -2764,7 +2777,12 @@ static int dvb_plugin_open(input_plugin_t * this_gen)
xine_cfg_entry_t zoomdvb;
xine_cfg_entry_t adapter;
xine_cfg_entry_t lastchannel;
+ xine_cfg_entry_t gui_enabled;
+ xine_config_lookup_entry(this->stream->xine, "media.dvb.gui_enabled", &gui_enabled);
+ this->dvb_gui_enabled = gui_enabled.num_value;
+ xprintf(this->class->xine, XINE_VERBOSITY_LOG, _("input_dvb: DVB GUI %s\n"), this->dvb_gui_enabled ? "enabled" : "disabled");
+
xine_config_lookup_entry(this->stream->xine, "media.dvb.adapter", &adapter);
if (!(tuner = tuner_init(this->class->xine,adapter.num_value))) {
@@ -2822,7 +2840,7 @@ static int dvb_plugin_open(input_plugin_t * this_gen)
* that the channels have really ugly names, sometimes prefixed
* by numbers...
*/
- int chanlen = strlen(channame);
+ size_t chanlen = strlen(channame);
int offset = 0;
xprintf(this->class->xine, XINE_VERBOSITY_LOG,
@@ -2876,7 +2894,7 @@ static int dvb_plugin_open(input_plugin_t * this_gen)
}
ptr = this->mrl;
ptr += 7;
- channels = xine_xmalloc(sizeof(channel_t));
+ channels = calloc(1, sizeof(channel_t));
_x_assert(channels != NULL);
if (extract_channel_from_string(channels, ptr, tuner->feinfo.type) < 0) {
free(channels);
@@ -2896,7 +2914,7 @@ static int dvb_plugin_open(input_plugin_t * this_gen)
}
ptr = this->mrl;
ptr += 7;
- channels = xine_xmalloc(sizeof(channel_t));
+ channels = calloc(1, sizeof(channel_t));
_x_assert(channels != NULL);
if (extract_channel_from_string(channels, ptr, tuner->feinfo.type) < 0) {
free(channels);
@@ -2919,7 +2937,7 @@ static int dvb_plugin_open(input_plugin_t * this_gen)
}
ptr = this->mrl;
ptr += 7;
- channels = xine_xmalloc(sizeof(channel_t));
+ channels = calloc(1, sizeof(channel_t));
_x_assert(channels != NULL);
if (extract_channel_from_string(channels, ptr, tuner->feinfo.type) < 0)
{
@@ -2945,7 +2963,7 @@ static int dvb_plugin_open(input_plugin_t * this_gen)
}
ptr = this->mrl;
ptr += 7;
- channels = xine_xmalloc(sizeof(channel_t));
+ channels = calloc(1, sizeof(channel_t));
_x_assert(channels != NULL);
if (extract_channel_from_string(channels, ptr, tuner->feinfo.type) < 0)
{
@@ -2990,15 +3008,16 @@ static int dvb_plugin_open(input_plugin_t * this_gen)
this->event_queue = xine_event_new_queue(this->stream);
#ifdef EPG_UPDATE_IN_BACKGROUND
- /* Start the EPG updater thread. */
- this->epg_updater_stop = 0;
- if (pthread_create(&this->epg_updater_thread, NULL,
- epg_data_updater, this) != 0) {
- xprintf(
- this->class->xine, XINE_VERBOSITY_LOG,
- _("input_dvb: cannot create EPG updater thread\n"));
- return 0;
-
+ if (this->dvb_gui_enabled) {
+ /* Start the EPG updater thread. */
+ this->epg_updater_stop = 0;
+ if (pthread_create(&this->epg_updater_thread, NULL,
+ epg_data_updater, this) != 0) {
+ xprintf(
+ this->class->xine, XINE_VERBOSITY_LOG,
+ _("input_dvb: cannot create EPG updater thread\n"));
+ return 0;
+ }
}
#endif
/*
@@ -3109,7 +3128,7 @@ static input_plugin_t *dvb_class_get_instance (input_class_t *class_gen,
fprintf(stderr, "input_dvb: continuing in get_instance\n");
- this = (dvb_input_plugin_t *) xine_xmalloc (sizeof(dvb_input_plugin_t));
+ this = calloc(1, sizeof(dvb_input_plugin_t));
_x_assert(this != NULL);
@@ -3164,6 +3183,8 @@ static void dvb_class_dispose(input_class_t * this_gen)
{
dvb_input_class_t *class = (dvb_input_class_t *) this_gen;
int x;
+
+ free(class->default_channels_conf_filename);
for(x=0;x<class->numchannels;x++)
free(class->autoplaylist[x]);
@@ -3181,7 +3202,6 @@ static char **dvb_class_get_autoplay_list(input_class_t * this_gen,
{
dvb_input_class_t *class = (dvb_input_class_t *) this_gen;
channel_t *channels=NULL;
- char foobuffer[BUFSIZE];
int ch, apch, num_channels = 0;
int default_channel = -1;
xine_cfg_entry_t lastchannel_enable = {0};
@@ -3226,21 +3246,19 @@ static char **dvb_class_get_autoplay_list(input_class_t * this_gen,
for (ch = 0, apch = !!lastchannel_enable.num_value;
ch < num_channels && ch < MAX_AUTOCHANNELS;
++ch, ++apch) {
- snprintf(foobuffer, BUFSIZE, "dvb://%s", channels[ch].name);
- free(class->autoplaylist[apch]);
- class->autoplaylist[apch] = strdup(foobuffer);
- _x_assert(class->autoplaylist[apch] != NULL);
+ free(class->autoplaylist[apch]);
+ asprintf(&(class->autoplaylist[apch]), "dvb://%s", channels[ch].name);
+ _x_assert(class->autoplaylist[apch] != NULL);
}
if (lastchannel_enable.num_value){
+ free(class->autoplaylist[0]);
if (default_channel != -1)
/* plugin has been used before - channel is valid */
- sprintf (foobuffer, "dvb://%s", channels[default_channel].name);
+ asprintf (&(class->autoplaylist[0]), "dvb://%s", channels[default_channel].name);
else
/* set a reasonable default - the first channel */
- sprintf (foobuffer, "dvb://%s", num_channels ? channels[0].name : "0");
- free(class->autoplaylist[0]);
- class->autoplaylist[0]=strdup(foobuffer);
+ asprintf (&(class->autoplaylist[0]), "dvb://%s", num_channels ? channels[0].name : "0");
}
free_channel_list(channels, num_channels);
@@ -3256,7 +3274,7 @@ static void *init_class (xine_t *xine, void *data) {
dvb_input_class_t *this;
config_values_t *config = xine->config;
- this = (dvb_input_class_t *) xine_xmalloc (sizeof (dvb_input_class_t));
+ this = calloc(1, sizeof (dvb_input_class_t));
_x_assert(this != NULL);
this->xine = xine;
@@ -3275,6 +3293,10 @@ static void *init_class (xine_t *xine, void *data) {
this->mrls[3] = "dvbt://";
this->mrls[4] = "dvba://";
this->mrls[5] = 0;
+
+ asprintf(&this->default_channels_conf_filename,
+ "%s/.xine/channels.conf",
+ xine_get_homedir());
xprintf(this->xine,XINE_VERBOSITY_DEBUG,"init class succeeded\n");
@@ -3308,7 +3330,19 @@ static void *init_class (xine_t *xine, void *data) {
"in your system."),
0, NULL, (void *) this);
-
+ /* set to 0 to turn off the GUI built into this input plugin */
+ config->register_bool(config, "media.dvb.gui_enabled",
+ 1,
+ _("Enable the DVB GUI"),
+ _("Enable the DVB GUI, mouse controlled recording and channel switching."),
+ 21, NULL, NULL);
+ /* Override the default channels file */
+ config->register_filename(config, "media.dvb.channels_conf",
+ this->default_channels_conf_filename,
+ XINE_CONFIG_STRING_IS_FILENAME,
+ _("DVB Channels config file"),
+ _("DVB Channels config file to use instead of the ~/.xine/channels.conf file."),
+ 21, NULL, NULL);
return this;
}
diff --git a/src/input/input_dvd.c b/src/input/input_dvd.c
index a891b9877..279f3c64e 100644
--- a/src/input/input_dvd.c
+++ b/src/input/input_dvd.c
@@ -115,6 +115,9 @@
/* There really isn't a default on Windows! */
#define DVD_PATH "d:\\"
#define RDVD_PATH "d:\\"
+#elif defined(__OpenBSD__)
+#define DVD_PATH "/dev/rcd0c"
+#define RDVD_PATH "/dev/rcd0c"
#else
#define DVD_PATH "/dev/dvd"
#define RDVD_PATH "/dev/rdvd"
@@ -352,11 +355,14 @@ static void send_mouse_enter_leave_event(dvd_input_plugin_t *this, int direction
}
static int update_title_display(dvd_input_plugin_t *this) {
- char ui_title[MAX_STR_LEN + 1];
- xine_event_t uevent;
xine_ui_data_t data;
+ xine_event_t uevent = {
+ .type = XINE_EVENT_UI_SET_TITLE,
+ .stream = this->stream,
+ .data = &data,
+ .data_length = sizeof(data)
+ };
int tt=-1, pr=-1;
- size_t ui_str_length=0;
int num_tt = 0;
if(!this || !(this->stream))
@@ -386,15 +392,15 @@ static int update_title_display(dvd_input_plugin_t *this) {
dvdnav_get_number_of_parts(this->dvdnav, tt, &num_part);
dvdnav_get_angle_info(this->dvdnav, &cur_angle, &num_angle);
if(num_angle > 1) {
- snprintf(ui_title, MAX_STR_LEN,
- "Title %i, Chapter %i, Angle %i of %i",
- tt,pr,cur_angle, num_angle);
+ data.str_len = snprintf(data.str, sizeof(data.str),
+ "Title %i, Chapter %i, Angle %i of %i",
+ tt,pr,cur_angle, num_angle);
_x_stream_info_set(this->stream,XINE_STREAM_INFO_DVD_ANGLE_NUMBER,cur_angle);
_x_stream_info_set(this->stream,XINE_STREAM_INFO_DVD_ANGLE_COUNT,num_angle);
} else {
- snprintf(ui_title, MAX_STR_LEN,
- "Title %i, Chapter %i",
- tt,pr);
+ data.str_len = snprintf(data.str, sizeof(data.str),
+ "Title %i, Chapter %i",
+ tt,pr);
_x_stream_info_set(this->stream,XINE_STREAM_INFO_DVD_ANGLE_NUMBER,0);
_x_stream_info_set(this->stream,XINE_STREAM_INFO_DVD_ANGLE_COUNT,0);
}
@@ -403,9 +409,9 @@ static int update_title_display(dvd_input_plugin_t *this) {
_x_stream_info_set(this->stream,XINE_STREAM_INFO_DVD_CHAPTER_NUMBER,pr);
_x_stream_info_set(this->stream,XINE_STREAM_INFO_DVD_CHAPTER_COUNT,num_part);
} else if (tt == 0 && dvdnav_menu_table[pr]) {
- snprintf(ui_title, MAX_STR_LEN,
- "DVD %s Menu",
- dvdnav_menu_table[pr]);
+ data.str_len = snprintf(data.str, sizeof(data.str),
+ "DVD %s Menu",
+ dvdnav_menu_table[pr]);
_x_stream_info_set(this->stream,XINE_STREAM_INFO_DVD_TITLE_NUMBER,tt);
_x_stream_info_set(this->stream,XINE_STREAM_INFO_DVD_TITLE_COUNT,num_tt);
_x_stream_info_set(this->stream,XINE_STREAM_INFO_DVD_CHAPTER_NUMBER,0);
@@ -413,7 +419,8 @@ static int update_title_display(dvd_input_plugin_t *this) {
_x_stream_info_set(this->stream,XINE_STREAM_INFO_DVD_ANGLE_NUMBER,0);
_x_stream_info_set(this->stream,XINE_STREAM_INFO_DVD_ANGLE_COUNT,0);
} else {
- strcpy(ui_title, "DVD Menu");
+ strcpy(data.str, "DVD Menu");
+ data.str_len = strlen(data.str);
_x_stream_info_set(this->stream,XINE_STREAM_INFO_DVD_TITLE_NUMBER,0);
_x_stream_info_set(this->stream,XINE_STREAM_INFO_DVD_TITLE_COUNT,num_tt);
_x_stream_info_set(this->stream,XINE_STREAM_INFO_DVD_CHAPTER_NUMBER,0);
@@ -421,22 +428,15 @@ static int update_title_display(dvd_input_plugin_t *this) {
_x_stream_info_set(this->stream,XINE_STREAM_INFO_DVD_ANGLE_NUMBER,0);
_x_stream_info_set(this->stream,XINE_STREAM_INFO_DVD_ANGLE_COUNT,0);
}
- ui_str_length = strlen(ui_title);
if (this->dvd_name && this->dvd_name[0] &&
- (ui_str_length + strlen(this->dvd_name) < MAX_STR_LEN)) {
- snprintf(ui_title+ui_str_length, MAX_STR_LEN - ui_str_length,
- ", %s", this->dvd_name);
+ (data.str_len + strlen(this->dvd_name) < sizeof(data.str))) {
+ data.str_len += snprintf(data.str+data.str_len, sizeof(data.str) - data.str_len,
+ ", %s", this->dvd_name);
}
#ifdef INPUT_DEBUG
- printf("input_dvd: Changing title to read '%s'\n", ui_title);
+ printf("input_dvd: Changing title to read '%s'\n", data.str);
#endif
- uevent.type = XINE_EVENT_UI_SET_TITLE;
- uevent.stream = this->stream;
- uevent.data = &data;
- uevent.data_length = sizeof(data);;
- memcpy(data.str, ui_title, strlen(ui_title) + 1);
- data.str_len = strlen(ui_title) + 1;
xine_event_send(this->stream, &uevent);
return 1;
@@ -853,6 +853,9 @@ static buf_element_t *dvd_plugin_read_block (input_plugin_t *this_gen,
static off_t dvd_plugin_read (input_plugin_t *this_gen, char *ch_buf, off_t len) {
/* dvd_input_plugin_t *this = (dvd_input_plugin_t*)this_gen; */
+ if (len < 4)
+ return -1;
+
/* FIXME: Tricking the demux_mpeg_block plugin */
ch_buf[0] = 0;
ch_buf[1] = 0;
@@ -1313,7 +1316,7 @@ static int dvd_plugin_get_optional_data (input_plugin_t *this_gen,
if(this && this->stream && this->dvdnav) {
if(!(dvdnav_is_domain_vts(this->dvdnav))) {
- sprintf(data, "%s", "menu");
+ strcpy(data, "menu");
if (channel <= 0)
return INPUT_OPTIONAL_SUCCESS;
else
@@ -1336,7 +1339,7 @@ static int dvd_plugin_get_optional_data (input_plugin_t *this_gen,
return INPUT_OPTIONAL_SUCCESS;
} else {
if(channel == -1) {
- sprintf(data, "%s", "none");
+ strcpy(data, "none");
return INPUT_OPTIONAL_SUCCESS;
}
}
@@ -1369,10 +1372,7 @@ check_solaris_vold_device(dvd_input_class_t *this)
(volume_action = getenv("VOLUME_ACTION")) != NULL &&
strcmp(volume_action, "insert") == 0) {
- device = malloc(strlen(volume_device) + strlen(volume_name) + 2);
- if (device == NULL)
- return;
- sprintf(device, "%s/%s", volume_device, volume_name);
+ asprintf(&device, "%s/%s", volume_device, volume_name);
if (stat(device, &stb) != 0 || !S_ISCHR(stb.st_mode)) {
free(device);
return;
@@ -1625,14 +1625,14 @@ static input_plugin_t *dvd_class_get_instance (input_class_t *class_gen, xine_st
if (strncasecmp (data, handled_mrl, strlen(handled_mrl) ) != 0)
return NULL;
- this = (dvd_input_plugin_t *) xine_xmalloc (sizeof (dvd_input_plugin_t));
+ this = calloc(1, sizeof (dvd_input_plugin_t));
if (!this) {
return NULL;
}
this->mem_stack = 0;
this->mem_stack_max = 1024;
- this->mem = xine_xmalloc(sizeof(unsigned char *) * this->mem_stack_max);
+ this->mem = calloc(this->mem_stack_max, sizeof(unsigned char *));
if (!this->mem) {
free(this);
return NULL;
@@ -1758,7 +1758,7 @@ static void *init_class (xine_t *xine, void *data) {
printf("input_dvd.c: config = %p\n", config);
#endif
- this = (dvd_input_class_t *) xine_xmalloc (sizeof (dvd_input_class_t));
+ this = (dvd_input_class_t *) calloc(1, sizeof (dvd_input_class_t));
if (!this)
return NULL;
@@ -1820,8 +1820,7 @@ static void *init_class (xine_t *xine, void *data) {
"playing scrambled DVDs."), 20, NULL, NULL);
xine_setenv("DVDCSS_METHOD", decrypt_modes[mode], 0);
- css_cache_default = (char *)malloc(strlen(xine_get_homedir()) + 10);
- sprintf(css_cache_default, "%s/.dvdcss/", xine_get_homedir());
+ asprintf(&css_cache_default, "%s/.dvdcss/", xine_get_homedir());
css_cache = config->register_filename(config, "media.dvd.css_cache_path", css_cache_default, XINE_CONFIG_STRING_IS_DIRECTORY_NAME,
_("path to the title key cache"),
_("Since cracking the copy protection of scrambled DVDs can "
diff --git a/src/input/input_file.c b/src/input/input_file.c
index f81103dcd..2187f0007 100644
--- a/src/input/input_file.c
+++ b/src/input/input_file.c
@@ -145,6 +145,9 @@ static int check_mmap_file(file_input_plugin_t *this) {
static off_t file_plugin_read (input_plugin_t *this_gen, char *buf, off_t len) {
file_input_plugin_t *this = (file_input_plugin_t *) this_gen;
+ if (len < 0)
+ return -1;
+
#ifdef HAVE_MMAP
if ( check_mmap_file(this) ) {
off_t l = len;
@@ -166,6 +169,13 @@ static buf_element_t *file_plugin_read_block (input_plugin_t *this_gen, fifo_buf
file_input_plugin_t *this = (file_input_plugin_t *) this_gen;
buf_element_t *buf = fifo->buffer_pool_alloc (fifo);
+ if (todo > buf->max_size)
+ todo = buf->max_size;
+ if (todo < 0) {
+ buf->free_buffer (buf);
+ return NULL;
+ }
+
buf->type = BUF_DEMUX_BLOCK;
#ifdef HAVE_MMAP
@@ -421,7 +431,7 @@ static input_plugin_t *file_class_get_instance (input_class_t *cls_gen, xine_str
return NULL;
}
- this = (file_input_plugin_t *) xine_xmalloc (sizeof (file_input_plugin_t));
+ this = (file_input_plugin_t *) calloc(1, sizeof (file_input_plugin_t));
this->stream = stream;
this->mrl = mrl;
this->fh = -1;
@@ -689,9 +699,9 @@ static xine_mrl_t **file_class_get_dir (input_class_t *this_gen,
return NULL;
}
- dir_files = (xine_mrl_t *) xine_xmalloc(sizeof(xine_mrl_t) * MAXFILES);
- hide_files = (xine_mrl_t *) xine_xmalloc(sizeof(xine_mrl_t) * MAXFILES);
- norm_files = (xine_mrl_t *) xine_xmalloc(sizeof(xine_mrl_t) * MAXFILES);
+ dir_files = (xine_mrl_t *) calloc(MAXFILES, sizeof(xine_mrl_t));
+ hide_files = (xine_mrl_t *) calloc(MAXFILES, sizeof(xine_mrl_t));
+ norm_files = (xine_mrl_t *) calloc(MAXFILES, sizeof(xine_mrl_t));
while((pdirent = readdir(pdir)) != NULL) {
@@ -708,11 +718,8 @@ static xine_mrl_t **file_class_get_dir (input_class_t *this_gen,
}
else {
- dir_files[num_dir_files].mrl = (char *)
- xine_xmalloc(strlen(current_dir_slashed) + 1 + strlen(pdirent->d_name) + 1);
-
dir_files[num_dir_files].origin = strdup(current_dir);
- sprintf(dir_files[num_dir_files].mrl, "%s%s",
+ asprintf(&(dir_files[num_dir_files].mrl), "%s%s",
current_dir_slashed, pdirent->d_name);
dir_files[num_dir_files].link = NULL;
dir_files[num_dir_files].type = get_file_type(fullfilename, current_dir, this->xine);
@@ -730,8 +737,9 @@ static xine_mrl_t **file_class_get_dir (input_class_t *this_gen,
xprintf (this->xine, XINE_VERBOSITY_DEBUG,
"input_file: readlink() failed: %s\n", strerror(errno));
else {
- dir_files[num_dir_files].link = (char *) xine_xmalloc(linksize + 1);
- strncpy(dir_files[num_dir_files].link, linkbuf, linksize);
+ dir_files[num_dir_files].link =
+ strndup(linkbuf, linksize);
+
dir_files[num_dir_files].type |= get_file_type(dir_files[num_dir_files].link, current_dir, this->xine);
}
}
@@ -746,11 +754,8 @@ static xine_mrl_t **file_class_get_dir (input_class_t *this_gen,
/* if user don't want to see hidden files, ignore them */
if(this->show_hidden_files) {
- hide_files[num_hide_files].mrl = (char *)
- xine_xmalloc(strlen(current_dir_slashed) + 1 + strlen(pdirent->d_name) + 1);
-
hide_files[num_hide_files].origin = strdup(current_dir);
- sprintf(hide_files[num_hide_files].mrl, "%s%s",
+ asprintf(&(hide_files[num_hide_files].mrl), "%s%s",
current_dir_slashed, pdirent->d_name);
hide_files[num_hide_files].link = NULL;
hide_files[num_hide_files].type = get_file_type(fullfilename, current_dir, this->xine);
@@ -769,9 +774,8 @@ static xine_mrl_t **file_class_get_dir (input_class_t *this_gen,
"input_file: readlink() failed: %s\n", strerror(errno));
}
else {
- hide_files[num_hide_files].link = (char *)
- xine_xmalloc(linksize + 1);
- strncpy(hide_files[num_hide_files].link, linkbuf, linksize);
+ hide_files[num_hide_files].link =
+ strndup(linkbuf, linksize);
hide_files[num_hide_files].type |= get_file_type(hide_files[num_hide_files].link, current_dir, this->xine);
}
}
@@ -782,11 +786,8 @@ static xine_mrl_t **file_class_get_dir (input_class_t *this_gen,
} /* So a *normal* one. */
else {
- norm_files[num_norm_files].mrl = (char *)
- xine_xmalloc(strlen(current_dir_slashed) + 1 + strlen(pdirent->d_name) + 1);
-
norm_files[num_norm_files].origin = strdup(current_dir);
- sprintf(norm_files[num_norm_files].mrl, "%s%s",
+ asprintf(&(norm_files[num_norm_files].mrl), "%s%s",
current_dir_slashed, pdirent->d_name);
norm_files[num_norm_files].link = NULL;
norm_files[num_norm_files].type = get_file_type(fullfilename, current_dir, this->xine);
@@ -805,9 +806,8 @@ static xine_mrl_t **file_class_get_dir (input_class_t *this_gen,
"input_file: readlink() failed: %s\n", strerror(errno));
}
else {
- norm_files[num_norm_files].link = (char *)
- xine_xmalloc(linksize + 1);
- strncpy(norm_files[num_norm_files].link, linkbuf, linksize);
+ norm_files[num_norm_files].link =
+ strndup(linkbuf, linksize);
norm_files[num_norm_files].type |= get_file_type(norm_files[num_norm_files].link, current_dir, this->xine);
}
}
@@ -849,7 +849,7 @@ static xine_mrl_t **file_class_get_dir (input_class_t *this_gen,
if(num_files >= this->mrls_allocated_entries) {
++this->mrls_allocated_entries;
this->mrls = realloc(this->mrls, (this->mrls_allocated_entries+1) * sizeof(xine_mrl_t*));
- this->mrls[num_files] = (xine_mrl_t *) xine_xmalloc(sizeof(xine_mrl_t));
+ this->mrls[num_files] = calloc(1, sizeof(xine_mrl_t));
}
else
memset(this->mrls[num_files], 0, sizeof(xine_mrl_t));
@@ -867,7 +867,7 @@ static xine_mrl_t **file_class_get_dir (input_class_t *this_gen,
if(num_files >= this->mrls_allocated_entries) {
++this->mrls_allocated_entries;
this->mrls = realloc(this->mrls, (this->mrls_allocated_entries+1) * sizeof(xine_mrl_t*));
- this->mrls[num_files] = (xine_mrl_t *) xine_xmalloc(sizeof(xine_mrl_t));
+ this->mrls[num_files] = calloc(1, sizeof(xine_mrl_t));
}
else
memset(this->mrls[num_files], 0, sizeof(xine_mrl_t));
@@ -885,7 +885,7 @@ static xine_mrl_t **file_class_get_dir (input_class_t *this_gen,
if(num_files >= this->mrls_allocated_entries) {
++this->mrls_allocated_entries;
this->mrls = realloc(this->mrls, (this->mrls_allocated_entries+1) * sizeof(xine_mrl_t*));
- this->mrls[num_files] = (xine_mrl_t *) xine_xmalloc(sizeof(xine_mrl_t));
+ this->mrls[num_files] = calloc(1, sizeof(xine_mrl_t));
}
else
memset(this->mrls[num_files], 0, sizeof(xine_mrl_t));
@@ -965,7 +965,7 @@ static void *init_plugin (xine_t *xine, void *data) {
file_input_class_t *this;
config_values_t *config;
- this = (file_input_class_t *) xine_xmalloc (sizeof (file_input_class_t));
+ this = (file_input_class_t *) calloc(1, sizeof (file_input_class_t));
this->xine = xine;
this->config = xine->config;
@@ -979,7 +979,7 @@ static void *init_plugin (xine_t *xine, void *data) {
this->input_class.dispose = file_class_dispose;
this->input_class.eject_media = NULL;
- this->mrls = (xine_mrl_t **) xine_xmalloc(sizeof(xine_mrl_t*));
+ this->mrls = (xine_mrl_t **) calloc(1, sizeof(xine_mrl_t*));
this->mrls_allocated_entries = 0;
{
diff --git a/src/input/input_gnome_vfs.c b/src/input/input_gnome_vfs.c
index 0848b9206..a3dfafdd5 100644
--- a/src/input/input_gnome_vfs.c
+++ b/src/input/input_gnome_vfs.c
@@ -121,6 +121,13 @@ gnomevfs_plugin_read_block (input_plugin_t *this_gen, fifo_buffer_t *fifo,
off_t total_bytes;
buf_element_t *buf = fifo->buffer_pool_alloc (fifo);
+ if (todo > buf->max_size)
+ todo = buf->max_size;
+ if (todo < 0) {
+ buf->free_buffer (buf);
+ return NULL;
+ }
+
buf->content = buf->mem;
buf->type = BUF_DEMUX_BLOCK;
diff --git a/src/input/input_http.c b/src/input/input_http.c
index af696ca14..c831dfc59 100644
--- a/src/input/input_http.c
+++ b/src/input/input_http.c
@@ -82,6 +82,8 @@ typedef struct {
char auth[BUFSIZE];
char proxyauth[BUFSIZE];
+
+ char *mime_type;
char *proto;
char *user;
@@ -235,26 +237,16 @@ static int http_plugin_basicauth (const char *user, const char *password, char*
char *tmp;
char *sptr;
char *dptr;
- int totlen;
+ size_t count;
int enclen;
- int count;
-
- totlen = strlen (user) + 1;
- if(password != NULL)
- totlen += strlen (password);
- enclen = ((totlen + 2) / 3 ) * 4 + 1;
+ count = asprintf(&tmp, "%s:%s", user, (password != NULL) ? password : "");
+
+ enclen = ((count + 2) / 3 ) * 4 + 1;
if (len < enclen)
return -1;
-
- tmp = malloc (sizeof(char) * (totlen + 1));
- strcpy (tmp, user);
- strcat (tmp, ":");
- if (password != NULL)
- strcat (tmp, password);
-
- count = strlen(tmp);
+
sptr = tmp;
dptr = dest;
while (count >= 3) {
@@ -429,6 +421,9 @@ static off_t http_plugin_read (input_plugin_t *this_gen,
num_bytes = 0;
+ if (nlen < 0)
+ return -1;
+
if (this->curpos < this->preview_size) {
if (nlen > (this->preview_size - this->curpos))
@@ -445,7 +440,7 @@ static off_t http_plugin_read (input_plugin_t *this_gen,
n = nlen - num_bytes;
- if (n) {
+ if (n > 0) {
int read_bytes;
read_bytes = http_plugin_read_int (this, &buf[num_bytes], n);
@@ -511,6 +506,13 @@ static buf_element_t *http_plugin_read_block (input_plugin_t *this_gen, fifo_buf
off_t total_bytes;
buf_element_t *buf = fifo->buffer_pool_alloc (fifo);
+ if (todo > buf->max_size)
+ todo = buf->max_size;
+ if (todo < 0) {
+ buf->free_buffer (buf);
+ return NULL;
+ }
+
buf->content = buf->mem;
buf->type = BUF_DEMUX_BLOCK;
@@ -562,7 +564,7 @@ static off_t http_plugin_seek(input_plugin_t *this_gen, off_t offset, int origin
if ((origin == SEEK_CUR) && (offset >= 0)) {
for (;((int)offset) - BUFSIZE > 0; offset -= BUFSIZE) {
- if( !this_gen->read (this_gen, this->seek_buf, BUFSIZE) )
+ if( this_gen->read (this_gen, this->seek_buf, BUFSIZE) <= 0 )
return this->curpos;
}
@@ -584,7 +586,7 @@ static off_t http_plugin_seek(input_plugin_t *this_gen, off_t offset, int origin
offset -= this->curpos;
for (;((int)offset) - BUFSIZE > 0; offset -= BUFSIZE) {
- if( !this_gen->read (this_gen, this->seek_buf, BUFSIZE) )
+ if( this_gen->read (this_gen, this->seek_buf, BUFSIZE) <= 0 )
return this->curpos;
}
@@ -602,17 +604,20 @@ static const char* http_plugin_get_mrl (input_plugin_t *this_gen) {
}
static int http_plugin_get_optional_data (input_plugin_t *this_gen,
- void *data, int data_type) {
+ void *const data, int data_type) {
+ void **const ptr = (void **const) data;
http_input_plugin_t *this = (http_input_plugin_t *) this_gen;
switch (data_type) {
case INPUT_OPTIONAL_DATA_PREVIEW:
-
memcpy (data, this->preview, this->preview_size);
return this->preview_size;
- break;
+ case INPUT_OPTIONAL_DATA_MIME_TYPE:
+ *ptr = this->mime_type;
+ case INPUT_OPTIONAL_DATA_DEMUX_MIME_TYPE:
+ return *this->mime_type ? INPUT_OPTIONAL_SUCCESS : INPUT_OPTIONAL_UNSUPPORTED;
}
return INPUT_OPTIONAL_UNSUPPORTED;
@@ -637,6 +642,7 @@ static void http_plugin_dispose (input_plugin_t *this_gen ) {
if (this->user) free(this->user);
if (this->password) free(this->password);
if (this->uri) free(this->uri);
+ if (this->mime_type) free(this->mime_type);
free (this);
}
@@ -661,11 +667,13 @@ static int http_plugin_open (input_plugin_t *this_gen ) {
int done, len, linenum;
int httpcode;
int res;
- int buflen;
+ size_t buflen;
int use_proxy;
int proxyport;
int mpegurl_redirect = 0;
-
+ char mime_type[256];
+
+ mime_type[0] = 0;
use_proxy = this_class->proxyhost && strlen(this_class->proxyhost);
if (use_proxy) {
@@ -753,43 +761,38 @@ static int http_plugin_open (input_plugin_t *this_gen ) {
if (use_proxy) {
if (this->port != DEFAULT_HTTP_PORT) {
- snprintf (this->buf, BUFSIZE, "GET http://%s:%d%s HTTP/1.0\015\012",
- this->host, this->port, this->uri);
+ buflen = snprintf (this->buf, BUFSIZE, "GET http://%s:%d%s HTTP/1.0\015\012",
+ this->host, this->port, this->uri);
} else {
- snprintf (this->buf, BUFSIZE, "GET http://%s%s HTTP/1.0\015\012",
- this->host, this->uri);
+ buflen = snprintf (this->buf, BUFSIZE, "GET http://%s%s HTTP/1.0\015\012",
+ this->host, this->uri);
}
}
else
- snprintf (this->buf, BUFSIZE, "GET %s HTTP/1.0\015\012", this->uri);
+ buflen = snprintf (this->buf, BUFSIZE, "GET %s HTTP/1.0\015\012", this->uri);
- buflen = strlen(this->buf);
if (this->port != DEFAULT_HTTP_PORT)
- snprintf (this->buf + buflen, BUFSIZE - buflen, "Host: %s:%d\015\012",
- this->host, this->port);
+ buflen += snprintf (this->buf + buflen, BUFSIZE - buflen, "Host: %s:%d\015\012",
+ this->host, this->port);
else
- snprintf (this->buf + buflen, BUFSIZE - buflen, "Host: %s\015\012",
- this->host);
+ buflen += snprintf (this->buf + buflen, BUFSIZE - buflen, "Host: %s\015\012",
+ this->host);
- buflen = strlen(this->buf);
if (this_class->proxyuser && strlen(this_class->proxyuser)) {
- snprintf (this->buf + buflen, BUFSIZE - buflen,
- "Proxy-Authorization: Basic %s\015\012", this->proxyauth);
- buflen = strlen(this->buf);
+ buflen += snprintf (this->buf + buflen, BUFSIZE - buflen,
+ "Proxy-Authorization: Basic %s\015\012", this->proxyauth);
}
if (this->user && strlen(this->user)) {
- snprintf (this->buf + buflen, BUFSIZE - buflen,
- "Authorization: Basic %s\015\012", this->auth);
- buflen = strlen(this->buf);
+ buflen += snprintf (this->buf + buflen, BUFSIZE - buflen,
+ "Authorization: Basic %s\015\012", this->auth);
}
- snprintf(this->buf + buflen, BUFSIZE - buflen,
- "User-Agent: xine/%s\015\012"
- "Accept: */*\015\012"
- "Icy-MetaData: 1\015\012"
- "\015\012",
- VERSION);
- buflen = strlen(this->buf);
+ buflen += snprintf(this->buf + buflen, BUFSIZE - buflen,
+ "User-Agent: xine/%s\015\012"
+ "Accept: */*\015\012"
+ "Icy-MetaData: 1\015\012"
+ "\015\012",
+ VERSION);
if (_x_io_tcp_write (this->stream, this->fh, this->buf, buflen) != buflen) {
_x_message(this->stream, XINE_MSG_CONNECTION_REFUSED, "couldn't send request", NULL);
xprintf(this_class->xine, XINE_VERBOSITY_DEBUG, "input_http: couldn't send request\n");
@@ -934,7 +937,11 @@ static int http_plugin_open (input_plugin_t *this_gen ) {
/* content type */
if (!strncasecmp(this->buf, TAG_CONTENT_TYPE, sizeof(TAG_CONTENT_TYPE) - 1)) {
- if (!strncasecmp(this->buf + sizeof(TAG_CONTENT_TYPE) - 1, "video/nsv", 9)) {
+ const char *type = this->buf + sizeof (TAG_CONTENT_TYPE) - 1;
+ while (isspace (*type))
+ ++type;
+ sprintf (mime_type, "%.255s", type);
+ if (!strncasecmp (type, "video/nsv", 9)) {
lprintf("shoutcast nsv detected\n");
this->is_nsv = 1;
}
@@ -999,12 +1006,15 @@ static int http_plugin_open (input_plugin_t *this_gen ) {
this->preview_size = http_plugin_read_int (this, this->preview, MAX_PREVIEW_SIZE);
}
if (this->preview_size < 0) {
+ this->preview_size = 0;
xine_log (this->stream->xine, XINE_LOG_MSG, _("input_http: read error %d\n"), errno);
return -12;
}
lprintf("preview_size=%"PRId64"\n", this->preview_size);
this->curpos = 0;
+ if (*mime_type)
+ this->mime_type = strdup (mime_type);
return 1;
}
@@ -1022,11 +1032,10 @@ static input_plugin_t *http_class_get_instance (input_class_t *cls_gen, xine_str
strncasecmp (mrl, "peercast://pls/", 15)) {
return NULL;
}
- this = (http_input_plugin_t *) xine_xmalloc(sizeof(http_input_plugin_t));
+ this = calloc(1, sizeof(http_input_plugin_t));
if (!strncasecmp (mrl, "peercast://pls/", 15)) {
- this->mrl = xine_xmalloc (30 + strlen(mrl) - 15);
- sprintf (this->mrl, "http://127.0.0.1:7144/stream/%s", mrl+15);
+ asprintf (&this->mrl, "http://127.0.0.1:7144/stream/%s", mrl+15);
} else {
this->mrl = strdup (mrl);
}
@@ -1073,7 +1082,7 @@ static void *init_class (xine_t *xine, void *data) {
config_values_t *config;
char *proxy_env;
- this = (http_input_class_t *) xine_xmalloc (sizeof (http_input_class_t));
+ this = calloc(1, sizeof (http_input_class_t));
this->xine = xine;
this->config = xine->config;
@@ -1090,25 +1099,21 @@ static void *init_class (xine_t *xine, void *data) {
/*
* honour http_proxy envvar
*/
- if((proxy_env = getenv("http_proxy")) && (strlen(proxy_env))) {
+ if((proxy_env = getenv("http_proxy")) && *proxy_env) {
int proxy_port = DEFAULT_HTTP_PORT;
- char *http_proxy = xine_xmalloc(strlen(proxy_env) + 1);
char *p;
if(!strncmp(proxy_env, "http://", 7))
proxy_env += 7;
+
+ this->proxyhost_env = strdup(proxy_env);
- sprintf(http_proxy, "%s", proxy_env);
-
- if((p = strrchr(&http_proxy[0], ':')) && (strlen(p) > 1)) {
+ if((p = strrchr(this->proxyhost_env, ':')) && (strlen(p) > 1)) {
*p++ = '\0';
proxy_port = (int) strtol(p, &p, 10);
}
- this->proxyhost_env = strdup(http_proxy);
this->proxyport_env = proxy_port;
-
- free(http_proxy);
}
else
proxy_env = NULL; /* proxy_env can be "" */
diff --git a/src/input/input_mms.c b/src/input/input_mms.c
index 6a1e729e6..cd88a0609 100644
--- a/src/input/input_mms.c
+++ b/src/input/input_mms.c
@@ -122,6 +122,13 @@ static buf_element_t *mms_plugin_read_block (input_plugin_t *this_gen,
lprintf ("mms_plugin_read_block: %"PRId64" bytes...\n", todo);
+ if (todo > buf->max_size)
+ todo = buf->max_size;
+ if (todo < 0) {
+ buf->free_buffer (buf);
+ return NULL;
+ }
+
buf->content = buf->mem;
buf->type = BUF_DEMUX_BLOCK;
@@ -401,7 +408,7 @@ static input_plugin_t *mms_class_get_instance (input_class_t *cls_gen, xine_stre
return NULL;
}
- this = (mms_input_plugin_t *) xine_xmalloc (sizeof (mms_input_plugin_t));
+ this = calloc(1, sizeof (mms_input_plugin_t));
cls->ip = this;
this->stream = stream;
this->mms = NULL;
@@ -459,7 +466,7 @@ static void *init_class (xine_t *xine, void *data) {
mms_input_class_t *this;
- this = (mms_input_class_t *) xine_xmalloc (sizeof (mms_input_class_t));
+ this = calloc(1, sizeof (mms_input_class_t));
this->xine = xine;
this->ip = NULL;
diff --git a/src/input/input_net.c b/src/input/input_net.c
index fe78c93f4..d9da27b54 100644
--- a/src/input/input_net.c
+++ b/src/input/input_net.c
@@ -253,6 +253,9 @@ static off_t net_plugin_read (input_plugin_t *this_gen,
lprintf("reading %" PRIdMAX " bytes...\n", (intmax_t)len);
+ if (len < 0)
+ return -1;
+
total=0;
if (this->curpos < this->preview_size) {
n = this->preview_size - this->curpos;
@@ -288,6 +291,13 @@ static buf_element_t *net_plugin_read_block (input_plugin_t *this_gen,
buf_element_t *buf = fifo->buffer_pool_alloc (fifo);
off_t total_bytes;
+ if (todo > buf->max_size)
+ todo = buf->max_size;
+ if (todo < 0) {
+ buf->free_buffer (buf);
+ return NULL;
+ }
+
buf->content = buf->mem;
buf->type = BUF_DEMUX_BLOCK;
@@ -331,7 +341,7 @@ static off_t net_plugin_seek (input_plugin_t *this_gen, off_t offset, int origin
if ((origin == SEEK_CUR) && (offset >= 0)) {
for (;((int)offset) - BUFSIZE > 0; offset -= BUFSIZE) {
- if( !this_gen->read (this_gen, this->seek_buf, BUFSIZE) )
+ if( this_gen->read (this_gen, this->seek_buf, BUFSIZE) <= 0 )
return this->curpos;
}
@@ -353,7 +363,7 @@ static off_t net_plugin_seek (input_plugin_t *this_gen, off_t offset, int origin
offset -= this->curpos;
for (;((int)offset) - BUFSIZE > 0; offset -= BUFSIZE) {
- if( !this_gen->read (this_gen, this->seek_buf, BUFSIZE) )
+ if( this_gen->read (this_gen, this->seek_buf, BUFSIZE) <= 0 )
return this->curpos;
}
@@ -480,7 +490,7 @@ static input_plugin_t *net_class_get_instance (input_class_t *cls_gen, xine_stre
return NULL;
}
- this = xine_xmalloc(sizeof(net_input_plugin_t));
+ this = calloc(1, sizeof(net_input_plugin_t));
this->mrl = strdup(mrl);
this->host_port = strdup(filename);
this->stream = stream;
@@ -528,7 +538,7 @@ static void *init_class (xine_t *xine, void *data) {
net_input_class_t *this;
- this = (net_input_class_t *) xine_xmalloc(sizeof(net_input_class_t));
+ this = calloc(1, sizeof(net_input_class_t));
this->config = xine->config;
this->xine = xine;
diff --git a/src/input/input_plugin.h b/src/input/input_plugin.h
index 1d1e5cf53..080e05476 100644
--- a/src/input/input_plugin.h
+++ b/src/input/input_plugin.h
@@ -307,6 +307,13 @@ struct input_plugin_s {
#define INPUT_OPTIONAL_DATA_SPULANG 3
#define INPUT_OPTIONAL_DATA_PREVIEW 7
+/* buffer is a const char **; the string is freed by the input plugin. */
+#define INPUT_OPTIONAL_DATA_MIME_TYPE 8
+/* buffer is unused; true if the demuxer should be determined by the MIME type */
+#define INPUT_OPTIONAL_DATA_DEMUX_MIME_TYPE 9
+/* buffer is a const char **; the string is static or freed by the input plugin. */
+#define INPUT_OPTIONAL_DATA_DEMUXER 10
+
#define MAX_MRL_ENTRIES 255
#define MAX_PREVIEW_SIZE 4096
@@ -333,65 +340,38 @@ struct input_plugin_s {
/*
* Freeing/zeroing all of entries of given mrl.
*/
-#define MRL_ZERO(m) { \
- if((m)) { \
- if((m)->origin) \
- free((m)->origin); \
- if((m)->mrl) \
- free((m)->mrl); \
- if((m)->link) \
- free((m)->link); \
- (m)->origin = NULL; \
- (m)->mrl = NULL; \
- (m)->link = NULL; \
- (m)->type = 0; \
- (m)->size = (off_t) 0; \
- } \
-}
+#define MRL_ZERO(m) { \
+ if((m)) { \
+ free((m)->origin); \
+ free((m)->mrl); \
+ free((m)->link); \
+ (m)->origin = NULL; \
+ (m)->mrl = NULL; \
+ (m)->link = NULL; \
+ (m)->type = 0; \
+ (m)->size = (off_t) 0; \
+ } \
+ }
/*
* Duplicate two mrls entries (s = source, d = destination).
*/
-#define MRL_DUPLICATE(s, d) { \
- _x_assert((s) != NULL); \
- _x_assert((d) != NULL); \
- \
- if((s)->origin) { \
- if((d)->origin) { \
- (d)->origin = (char *) realloc((d)->origin, strlen((s)->origin) + 1); \
- sprintf((d)->origin, "%s", (s)->origin); \
- } \
- else \
- (d)->origin = strdup((s)->origin); \
- } \
- else \
- (d)->origin = NULL; \
- \
- if((s)->mrl) { \
- if((d)->mrl) { \
- (d)->mrl = (char *) realloc((d)->mrl, strlen((s)->mrl) + 1); \
- sprintf((d)->mrl, "%s", (s)->mrl); \
- } \
- else \
- (d)->mrl = strdup((s)->mrl); \
- } \
- else \
- (d)->mrl = NULL; \
- \
- if((s)->link) { \
- if((d)->link) { \
- (d)->link = (char *) realloc((d)->link, strlen((s)->link) + 1); \
- sprintf((d)->link, "%s", (s)->link); \
- } \
- else \
- (d)->link = strdup((s)->link); \
- } \
- else \
- (d)->link = NULL; \
- \
- (d)->type = (s)->type; \
- (d)->size = (s)->size; \
-}
+#define MRL_DUPLICATE(s, d) { \
+ _x_assert((s) != NULL); \
+ _x_assert((d) != NULL); \
+ \
+ free((d)->origin); \
+ (d)->origin = (s)->origin ? strdup((s)->origin) : NULL; \
+ \
+ free((d)->mrl); \
+ (d)->mrl = (s)->mrl ? strdup((s)->mrl) : NULL; \
+ \
+ free((d)->link); \
+ (d)->link = (s)->link ? strdup((s)->link) : NULL; \
+ \
+ (d)->type = (s)->type; \
+ (d)->size = (s)->size; \
+ }
/*
* Duplicate two arrays of mrls (s = source, d = destination).
diff --git a/src/input/input_pnm.c b/src/input/input_pnm.c
index 680c5b1e8..f609695d5 100644
--- a/src/input/input_pnm.c
+++ b/src/input/input_pnm.c
@@ -82,10 +82,9 @@ static off_t pnm_plugin_read (input_plugin_t *this_gen,
lprintf ("pnm_plugin_read: %"PRId64" bytes ...\n", len);
- nbc_check_buffers (this->nbc);
-
n = pnm_read (this->pnm, buf, len);
- this->curpos += n;
+ if (n >= 0)
+ this->curpos += n;
return n;
}
@@ -98,6 +97,13 @@ static buf_element_t *pnm_plugin_read_block (input_plugin_t *this_gen,
lprintf ("pnm_plugin_read_block: %"PRId64" bytes...\n", todo);
+ if (todo > buf->max_size)
+ todo = buf->max_size;
+ if (todo < 0) {
+ buf->free_buffer (buf);
+ return NULL;
+ }
+
buf->content = buf->mem;
buf->type = BUF_DEMUX_BLOCK;
@@ -125,10 +131,16 @@ static off_t pnm_plugin_seek (input_plugin_t *this_gen, off_t offset, int origin
if ((origin == SEEK_CUR) && (offset >= 0)) {
for (;((int)offset) - BUFSIZE > 0; offset -= BUFSIZE) {
- this->curpos += pnm_plugin_read (this_gen, this->scratch, BUFSIZE);
+ off_t n = pnm_plugin_read (this_gen, this->scratch, BUFSIZE);
+ if (n <= 0)
+ return this->curpos;
+ this->curpos += n;
}
- this->curpos += pnm_plugin_read (this_gen, this->scratch, offset);
+ off_t n = pnm_plugin_read (this_gen, this->scratch, offset);
+ if (n <= 0)
+ return this->curpos;
+ this->curpos += n;
}
return this->curpos;
@@ -231,7 +243,7 @@ static input_plugin_t *pnm_class_get_instance (input_class_t *cls_gen, xine_stre
return NULL;
}
- this = (pnm_input_plugin_t *) xine_xmalloc (sizeof (pnm_input_plugin_t));
+ this = calloc(1, sizeof (pnm_input_plugin_t));
this->stream = stream;
this->pnm = NULL;
@@ -276,7 +288,7 @@ static void *init_class (xine_t *xine, void *data) {
pnm_input_class_t *this;
- this = (pnm_input_class_t *) xine_xmalloc (sizeof (pnm_input_class_t));
+ this = calloc(1, sizeof (pnm_input_class_t));
this->xine = xine;
diff --git a/src/input/input_pvr.c b/src/input/input_pvr.c
index 1b8000072..a9c92e42e 100644
--- a/src/input/input_pvr.c
+++ b/src/input/input_pvr.c
@@ -376,10 +376,10 @@ static void pvrscr_exit (scr_plugin_t *scr) {
free(this);
}
-static pvrscr_t* pvrscr_init (void) {
+static pvrscr_t *XINE_MALLOC pvrscr_init (void) {
pvrscr_t *this;
- this = (pvrscr_t *) xine_xmalloc(sizeof(pvrscr_t));
+ this = calloc(1, sizeof(pvrscr_t));
this->scr.interface_version = 3;
this->scr.get_priority = pvrscr_get_priority;
@@ -424,6 +424,9 @@ static uint32_t pvr_plugin_get_capabilities (input_plugin_t *this_gen) {
static off_t pvr_plugin_read (input_plugin_t *this_gen, char *buf, off_t len) {
/*pvr_input_plugin_t *this = (pvr_input_plugin_t *) this_gen;*/
+ if (len < 4)
+ return -1;
+
/* FIXME: Tricking the demux_mpeg_block plugin */
buf[0] = 0;
buf[1] = 0;
@@ -504,34 +507,24 @@ static void pvr_adjust_realtime_speed(pvr_input_plugin_t *this, fifo_buffer_t *f
}
#define PVR_FILENAME "%s%08d_%08d.vob"
-#define PVR_FILENAME_SIZE 1+8+1+8+4+1
static char *make_temp_name(pvr_input_plugin_t *this, int page) {
-
char *filename;
- int size = strlen(this->tmp_prefix)+PVR_FILENAME_SIZE;
- filename = malloc(size);
-
- snprintf(filename, size, PVR_FILENAME, this->tmp_prefix, this->session, page);
+ asprintf(&filename, PVR_FILENAME, this->tmp_prefix, this->session, page);
return filename;
}
#define SAVE_BASE_FILENAME "ch%03d %02d-%02d-%04d %02d:%02d:%02d"
-#define SAVE_BASE_FILENAME_SIZE 2+3+1+2+1+2+1+4+1+2+1+2+1+2+1
static char *make_base_save_name(int channel, time_t tm) {
-
struct tm rec_time;
char *filename;
- int size = SAVE_BASE_FILENAME_SIZE;
- filename = malloc(size);
-
localtime_r(&tm, &rec_time);
- snprintf(filename, size, SAVE_BASE_FILENAME,
+ asprintf(&filename, SAVE_BASE_FILENAME,
channel, rec_time.tm_mon+1, rec_time.tm_mday,
rec_time.tm_year+1900, rec_time.tm_hour, rec_time.tm_min,
rec_time.tm_sec);
@@ -539,16 +532,11 @@ static char *make_base_save_name(int channel, time_t tm) {
}
#define SAVE_FILENAME "%s%s_%04d.vob"
-#define SAVE_FILENAME_SIZE 1+4+4+1
static char *make_save_name(pvr_input_plugin_t *this, char *base, int page) {
-
char *filename;
- int size = strlen(this->save_prefix)+strlen(base)+SAVE_FILENAME_SIZE;
- filename = malloc(size);
-
- snprintf(filename, size, SAVE_FILENAME, this->save_prefix, base, page);
+ asprintf(&filename, SAVE_FILENAME, this->save_prefix, base, page);
return filename;
}
@@ -1219,6 +1207,14 @@ static buf_element_t *pvr_plugin_read_block (input_plugin_t *this_gen, fifo_buff
return NULL;
}
+ buf = fifo->buffer_pool_alloc (fifo);
+ if (todo > buf->max_size)
+ todo = buf->max_size;
+ if (todo < 0) {
+ buf->free_buffer(buf);
+ return NULL;
+ }
+
if( this->scr_tunning == -2 )
speed = this->speed_before_pause;
@@ -1242,7 +1238,6 @@ static buf_element_t *pvr_plugin_read_block (input_plugin_t *this_gen, fifo_buff
pvr_event_handler(this);
- buf = fifo->buffer_pool_alloc (fifo);
buf->content = buf->mem;
pthread_mutex_lock(&this->lock);
@@ -1480,7 +1475,7 @@ static input_plugin_t *pvr_class_get_instance (input_class_t *cls_gen, xine_stre
mrl = strdup(data);
aux = &mrl[5];
- this = (pvr_input_plugin_t *) xine_xmalloc (sizeof (pvr_input_plugin_t));
+ this = calloc(1, sizeof (pvr_input_plugin_t));
this->class = cls;
this->stream = stream;
this->dev_fd = -1;
@@ -1564,7 +1559,7 @@ static void *init_plugin (xine_t *xine, void *data) {
pvr_input_class_t *this;
- this = (pvr_input_class_t *) xine_xmalloc (sizeof (pvr_input_class_t));
+ this = calloc(1, sizeof (pvr_input_class_t));
this->xine = xine;
this->config = xine->config;
diff --git a/src/input/input_rtp.c b/src/input/input_rtp.c
index 25498f289..90bae6670 100644
--- a/src/input/input_rtp.c
+++ b/src/input/input_rtp.c
@@ -453,6 +453,9 @@ static off_t rtp_plugin_read (input_plugin_t *this_gen,
struct timespec timeout;
off_t copied = 0;
+ if (length < 0)
+ return -1;
+
while(length > 0) {
off_t n;
@@ -524,6 +527,12 @@ static buf_element_t *rtp_plugin_read_block (input_plugin_t *this_gen,
buf_element_t *buf = fifo->buffer_pool_alloc (fifo);
int total_bytes;
+ if (todo > buf->max_size)
+ todo = buf->max_size;
+ if (todo < 0) {
+ buf->free_buffer (buf);
+ return NULL;
+ }
buf->content = buf->mem;
buf->type = BUF_DEMUX_BLOCK;
@@ -609,11 +618,14 @@ static int rtp_plugin_get_optional_data (input_plugin_t *this_gen,
if (data_type == INPUT_OPTIONAL_DATA_PREVIEW) {
if (!this->preview_read_done) {
this->preview_size = rtp_plugin_read(this_gen, this->preview, MAX_PREVIEW_SIZE);
+ if (this->preview_size < 0)
+ this->preview_size = 0;
lprintf("Preview data length = %d\n", this->preview_size);
this->preview_read_done = 1;
}
- memcpy(data, this->preview, this->preview_size);
+ if (this->preview_size)
+ memcpy(data, this->preview, this->preview_size);
return this->preview_size;
}
else {
@@ -717,7 +729,7 @@ static input_plugin_t *rtp_class_get_instance (input_class_t *cls_gen,
}
}
- this = (rtp_input_plugin_t *) xine_xmalloc(sizeof(rtp_input_plugin_t));
+ this = calloc(1, sizeof(rtp_input_plugin_t));
this->stream = stream;
this->mrl = mrl;
this->filename = filename;
@@ -784,7 +796,7 @@ static void *init_class (xine_t *xine, void *data) {
rtp_input_class_t *this;
- this = (rtp_input_class_t *) xine_xmalloc(sizeof(rtp_input_class_t));
+ this = calloc(1, sizeof(rtp_input_class_t));
this->config = xine->config;
this->xine = xine;
diff --git a/src/input/input_rtsp.c b/src/input/input_rtsp.c
index 2895edf5d..fad395e0b 100644
--- a/src/input/input_rtsp.c
+++ b/src/input/input_rtsp.c
@@ -83,10 +83,9 @@ static off_t rtsp_plugin_read (input_plugin_t *this_gen,
lprintf ("rtsp_plugin_read: %"PRId64" bytes ...\n", len);
- nbc_check_buffers (this->nbc);
-
n = rtsp_session_read (this->rtsp, buf, len);
- this->curpos += n;
+ if (n > 0)
+ this->curpos += n;
return n;
}
@@ -99,6 +98,13 @@ static buf_element_t *rtsp_plugin_read_block (input_plugin_t *this_gen,
lprintf ("rtsp_plugin_read_block: %"PRId64" bytes...\n", todo);
+ if (todo > buf->max_size)
+ todo = buf->max_size;
+ if (todo < 0) {
+ buf->free_buffer (buf);
+ return NULL;
+ }
+
buf->content = buf->mem;
buf->type = BUF_DEMUX_BLOCK;
@@ -125,10 +131,16 @@ static off_t rtsp_plugin_seek (input_plugin_t *this_gen, off_t offset, int origi
if ((origin == SEEK_CUR) && (offset >= 0)) {
for (;((int)offset) - BUFSIZE > 0; offset -= BUFSIZE) {
- this->curpos += rtsp_plugin_read (this_gen, this->scratch, BUFSIZE);
+ off_t n = rtsp_plugin_read (this_gen, this->scratch, BUFSIZE);
+ if (n <= 0)
+ return this->curpos;
+ this->curpos += n;
}
- this->curpos += rtsp_plugin_read (this_gen, this->scratch, offset);
+ off_t n = rtsp_plugin_read (this_gen, this->scratch, offset);
+ if (n <= 0)
+ return this->curpos;
+ this->curpos += n;
}
return this->curpos;
@@ -246,7 +258,7 @@ static input_plugin_t *rtsp_class_get_instance (input_class_t *cls_gen, xine_str
if (strncasecmp (mrl, "rtsp://", 6))
return NULL;
- this = (rtsp_input_plugin_t *) xine_xmalloc (sizeof (rtsp_input_plugin_t));
+ this = calloc(1, sizeof (rtsp_input_plugin_t));
this->stream = stream;
this->rtsp = NULL;
@@ -254,8 +266,7 @@ static input_plugin_t *rtsp_class_get_instance (input_class_t *cls_gen, xine_str
/* since we handle only real streams yet, we can savely add
* an .rm extention to force handling by demux_real.
*/
- this->public_mrl = xine_xmalloc (sizeof (char)*(strlen(this->mrl)+10));
- sprintf(this->public_mrl, "%s.rm", this->mrl);
+ asprintf(&this->public_mrl, "%s.rm", this->mrl);
this->nbc = nbc_init (stream);
@@ -298,7 +309,7 @@ static void *init_class (xine_t *xine, void *data) {
rtsp_input_class_t *this;
- this = (rtsp_input_class_t *) xine_xmalloc (sizeof (rtsp_input_class_t));
+ this = calloc(1, sizeof (rtsp_input_class_t));
this->xine = xine;
diff --git a/src/input/input_smb.c b/src/input/input_smb.c
index 7da9c1454..e49eaa889 100644
--- a/src/input/input_smb.c
+++ b/src/input/input_smb.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2004 the xine project
+ * Copyright (C) 2008 the xine project
*
* This file is part of xine, a free video player.
*
@@ -51,7 +51,7 @@ typedef struct {
xine_stream_t *stream;
/* File */
- char *mrl;
+ const char *mrl;
int fd;
} smb_input_t;
@@ -69,6 +69,8 @@ smb_plugin_read (input_plugin_t *this_gen, char *buf, off_t len)
smb_input_t *this = (smb_input_t *) this_gen;
off_t n, num_bytes;
+ if (len < 0)
+ return -1;
num_bytes = 0;
while (num_bytes < len)
@@ -89,6 +91,13 @@ smb_plugin_read_block (input_plugin_t *this_gen, fifo_buffer_t *fifo,
off_t total_bytes;
buf_element_t *buf = fifo->buffer_pool_alloc (fifo);
+ if (todo > buf->max_size)
+ todo = buf->max_size;
+ if (todo < 0) {
+ buf->free_buffer (buf);
+ return NULL;
+ }
+
buf->content = buf->mem;
buf->type = BUF_DEMUX_BLOCK;
@@ -138,7 +147,7 @@ smb_plugin_get_length (input_plugin_t *this_gen)
return st.st_size;
}
-static char*
+static const char*
smb_plugin_get_mrl (input_plugin_t *this_gen)
{
smb_input_t *this = (smb_input_t *) this_gen;
@@ -150,7 +159,7 @@ static uint32_t smb_plugin_get_blocksize (input_plugin_t *this_gen) {
return 0;
}
-static char
+static const char
*smb_class_get_description (input_class_t *this_gen)
{
return _("CIFS/SMB input plugin based on libsmbclient");
@@ -256,8 +265,8 @@ static xine_mrl_t **smb_class_get_dir (input_class_t *this_gen,
}
if ((dir = smbc_opendir(current_path_smb)) >= 0){
- xine_mrl_t *dir_files = (xine_mrl_t *) xine_xmalloc(sizeof(xine_mrl_t) * MAXFILES);
- xine_mrl_t *norm_files = (xine_mrl_t *) xine_xmalloc(sizeof(xine_mrl_t) * MAXFILES);
+ xine_mrl_t *dir_files = (xine_mrl_t *) calloc(MAXFILES, sizeof(xine_mrl_t));
+ xine_mrl_t *norm_files = (xine_mrl_t *) calloc(MAXFILES, sizeof(xine_mrl_t));
int num_dir_files=0;
int num_norm_files=0;
while ((pdirent = smbc_readdir(dir)) != NULL){
@@ -265,9 +274,7 @@ static xine_mrl_t **smb_class_get_dir (input_class_t *this_gen,
dir_files[num_dir_files].link = NULL;
dir_files[num_dir_files].type = mrl_file | mrl_file_directory;
dir_files[num_dir_files].origin = strdup(current_path);
- dir_files[num_dir_files].mrl = (char *) xine_xmalloc(
- strlen(current_path) + 1 + strlen(pdirent->name) + 1);
- sprintf(dir_files[num_dir_files].mrl, "%s/%s", current_path, pdirent->name);
+ asprintf(&(dir_files[num_dir_files].mrl), "%s/%s", current_path, pdirent->name);
dir_files[num_dir_files].size = pdirent->dirlen;
num_dir_files ++;
}else if (pdirent->smbc_type == SMBC_SERVER){
@@ -275,17 +282,14 @@ static xine_mrl_t **smb_class_get_dir (input_class_t *this_gen,
dir_files[num_dir_files].link = NULL;
dir_files[num_dir_files].type = mrl_file | mrl_file_directory;
dir_files[num_dir_files].origin = strdup("smb:/");
- dir_files[num_dir_files].mrl = (char *) xine_xmalloc(strlen("smb:/") + 4);
- sprintf(dir_files[num_dir_files].mrl, "%s/%s", "smb:/", "..");
+ asprintf(&(dir_files[num_dir_files].mrl), "%s/%s", "smb:/", "..");
dir_files[num_dir_files].size = pdirent->dirlen;
num_dir_files ++;
}
dir_files[num_dir_files].link = NULL;
dir_files[num_dir_files].type = mrl_file | mrl_file_directory;
dir_files[num_dir_files].origin = strdup("smb:/");
- dir_files[num_dir_files].mrl =
- (char *) xine_xmalloc(strlen("smb:/") + 1 + strlen(pdirent->name) + 1);
- sprintf(dir_files[num_dir_files].mrl, "%s/%s", "smb:/", pdirent->name);
+ asprintf(&(dir_files[num_dir_files].mrl), "%s/%s", "smb:/", pdirent->name);
dir_files[num_dir_files].size = pdirent->dirlen;
num_dir_files ++;
} else if (pdirent->smbc_type == SMBC_FILE_SHARE){
@@ -293,9 +297,7 @@ static xine_mrl_t **smb_class_get_dir (input_class_t *this_gen,
dir_files[num_dir_files].link = NULL;
dir_files[num_dir_files].type = mrl_file | mrl_file_directory;
dir_files[num_dir_files].origin = strdup(current_path);
- dir_files[num_dir_files].mrl = (char *) xine_xmalloc(
- strlen(current_path) + 3);
- sprintf(dir_files[num_dir_files].mrl, "%s/%s", current_path, "..");
+ asprintf(&(dir_files[num_dir_files].mrl), "%s/%s", current_path, "..");
dir_files[num_dir_files].type |= mrl_file_directory;
dir_files[num_dir_files].size = pdirent->dirlen;
num_dir_files ++;
@@ -304,9 +306,7 @@ static xine_mrl_t **smb_class_get_dir (input_class_t *this_gen,
dir_files[num_dir_files].link = NULL;
dir_files[num_dir_files].type = mrl_file | mrl_file_directory;
dir_files[num_dir_files].origin = strdup(current_path);
- dir_files[num_dir_files].mrl = (char *) xine_xmalloc(
- strlen(current_path) + 1 + strlen(pdirent->name) + 1);
- sprintf(dir_files[num_dir_files].mrl, "%s/%s", current_path, pdirent->name);
+ asprintf(&(dir_files[num_dir_files].mrl), "%s/%s", current_path, pdirent->name);
dir_files[num_dir_files].size = pdirent->dirlen;
num_dir_files ++;
}
@@ -314,18 +314,14 @@ static xine_mrl_t **smb_class_get_dir (input_class_t *this_gen,
dir_files[num_dir_files].link = NULL;
dir_files[num_dir_files].type = mrl_file | mrl_file_directory;
dir_files[num_dir_files].origin = strdup(current_path);
- dir_files[num_dir_files].mrl =
- (char *) xine_xmalloc(strlen(current_path) + 1 + strlen(pdirent->name) + 1);
- sprintf(dir_files[num_dir_files].mrl, "%s/%s", current_path, pdirent->name);
+ asprintf(&(dir_files[num_dir_files].mrl), "%s/%s", current_path, pdirent->name);
dir_files[num_dir_files].size = pdirent->dirlen;
num_dir_files ++;
}else if (pdirent->smbc_type == SMBC_FILE){
norm_files[num_norm_files].link = NULL;
norm_files[num_norm_files].type = mrl_file | mrl_file_normal;
norm_files[num_norm_files].origin = strdup(current_path);
- norm_files[num_norm_files].mrl =
- (char *) xine_xmalloc(strlen(current_path) + 1 + strlen(pdirent->name) + 1);
- sprintf(norm_files[num_norm_files].mrl, "%s/%s", current_path, pdirent->name);
+ asprintf(&(norm_files[num_norm_files].mrl), "%s/%s", current_path, pdirent->name);
norm_files[num_norm_files].size = pdirent->dirlen;
num_norm_files ++;
}
@@ -335,8 +331,7 @@ static xine_mrl_t **smb_class_get_dir (input_class_t *this_gen,
if (num_dir_files == 0) {
dir_files[num_dir_files].link = NULL;
dir_files[num_dir_files].origin = strdup(current_path);
- dir_files[num_dir_files].mrl = (char *) xine_xmalloc(strlen(current_path) + 4);
- sprintf(dir_files[num_dir_files].mrl, "%s/%s", current_path, "..");
+ asprintf(&(dir_files[num_dir_files].mrl), "%s/%s", current_path, "..");
dir_files[num_dir_files].type = mrl_file | mrl_file_directory;
dir_files[num_dir_files].size = 0;
num_dir_files ++;
@@ -359,7 +354,7 @@ static xine_mrl_t **smb_class_get_dir (input_class_t *this_gen,
++this->mrls_allocated_entries;
this->mrls = realloc(this->mrls,
(this->mrls_allocated_entries+1) * sizeof(xine_mrl_t*));
- this->mrls[num_files] = (xine_mrl_t *) xine_xmalloc(sizeof(xine_mrl_t));
+ this->mrls[num_files] = calloc(1, sizeof(xine_mrl_t));
}else
memset(this->mrls[num_files], 0, sizeof(xine_mrl_t));
@@ -376,7 +371,7 @@ static xine_mrl_t **smb_class_get_dir (input_class_t *this_gen,
++this->mrls_allocated_entries;
this->mrls = realloc(this->mrls,
(this->mrls_allocated_entries+1) * sizeof(xine_mrl_t*));
- this->mrls[num_files] = (xine_mrl_t *) xine_xmalloc(sizeof(xine_mrl_t));
+ this->mrls[num_files] = calloc(1, sizeof(xine_mrl_t));
}else
memset(this->mrls[num_files], 0, sizeof(xine_mrl_t));
@@ -437,7 +432,7 @@ smb_plugin_dispose (input_plugin_t *this_gen )
if (this->fd>=0)
smbc_close(this->fd);
if (this->mrl)
- free (this->mrl);
+ free ((char *)this->mrl);
free (this);
}
@@ -475,7 +470,7 @@ smb_class_get_instance (input_class_t *class_gen, xine_stream_t *stream,
if (strncmp (mrl, "smb://",6))
return NULL;
- this = (smb_input_t *)xine_xmalloc(sizeof(smb_input_t));
+ this = calloc(1, sizeof(smb_input_t));
this->stream = stream;
this->mrl = strdup (mrl);
this->fd = -1;
@@ -514,7 +509,7 @@ static void
if (smbc_init(smb_auth,(xine->verbosity >= XINE_VERBOSITY_DEBUG)))
goto _exit_error;
- this = (smb_input_class_t *) xine_xmalloc(sizeof(smb_input_class_t));
+ this = calloc(1, sizeof(smb_input_class_t));
this->xine = xine;
this->input_class.get_instance = smb_class_get_instance;
diff --git a/src/input/input_stdin_fifo.c b/src/input/input_stdin_fifo.c
index 465e9c00b..64b8d748c 100644
--- a/src/input/input_stdin_fifo.c
+++ b/src/input/input_stdin_fifo.c
@@ -85,6 +85,8 @@ static off_t stdin_plugin_read (input_plugin_t *this_gen,
off_t n, total;
lprintf ("reading %"PRId64" bytes...\n", len);
+ if (len < 0)
+ return -1;
total=0;
if (this->curpos < this->preview_size) {
@@ -121,6 +123,13 @@ static buf_element_t *stdin_plugin_read_block (input_plugin_t *this_gen, fifo_bu
/* stdin_input_plugin_t *this = (stdin_input_plugin_t *) this_gen; */
buf_element_t *buf = fifo->buffer_pool_alloc (fifo);
+ if (todo > buf->max_size)
+ todo = buf->max_size;
+ if (todo < 0) {
+ buf->free_buffer (buf);
+ return NULL;
+ }
+
buf->content = buf->mem;
buf->type = BUF_DEMUX_BLOCK;
@@ -146,7 +155,7 @@ static off_t stdin_plugin_seek (input_plugin_t *this_gen, off_t offset, int orig
if ((origin == SEEK_CUR) && (offset >= 0)) {
for (;((int)offset) - BUFSIZE > 0; offset -= BUFSIZE) {
- if( !this_gen->read (this_gen, this->seek_buf, BUFSIZE) )
+ if( this_gen->read (this_gen, this->seek_buf, BUFSIZE) <= 0 )
return this->curpos;
}
@@ -168,7 +177,7 @@ static off_t stdin_plugin_seek (input_plugin_t *this_gen, off_t offset, int orig
offset -= this->curpos;
for (;((int)offset) - BUFSIZE > 0; offset -= BUFSIZE) {
- if( !this_gen->read (this_gen, this->seek_buf, BUFSIZE) )
+ if( this_gen->read (this_gen, this->seek_buf, BUFSIZE) <= 0 )
return this->curpos;
}
@@ -270,6 +279,8 @@ static int stdin_plugin_open (input_plugin_t *this_gen ) {
this->preview_size = stdin_plugin_read (&this->input_plugin, this->preview,
MAX_PREVIEW_SIZE);
+ if (this->preview_size < 0)
+ this->preview_size = 0;
this->curpos = 0;
return 1;
@@ -311,7 +322,7 @@ static input_plugin_t *stdin_class_get_instance (input_class_t *class_gen,
* => create plugin instance
*/
- this = (stdin_input_plugin_t *) xine_xmalloc(sizeof(stdin_input_plugin_t));
+ this = calloc(1, sizeof(stdin_input_plugin_t));
this->stream = stream;
this->curpos = 0;
@@ -362,7 +373,7 @@ static void *init_class (xine_t *xine, void *data) {
stdin_input_class_t *this;
- this = (stdin_input_class_t *) xine_xmalloc (sizeof (stdin_input_class_t));
+ this = calloc(1, sizeof (stdin_input_class_t));
this->xine = xine;
diff --git a/src/input/input_v4l.c b/src/input/input_v4l.c
index b43a2684a..3a020bd69 100644
--- a/src/input/input_v4l.c
+++ b/src/input/input_v4l.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2004 the xine project
+ * Copyright (C) 2003-2008 the xine project
* Copyright (C) 2003 J.Asselman <j.asselman@itsec-ps.nl>
*
* This file is part of xine, a free video player.
@@ -91,13 +91,15 @@ static const resolution_t resolutions[] = {
};
#define NUM_RESOLUTIONS (sizeof(resolutions)/sizeof(resolutions[0]))
-#define RADIO_DEV "/dev/v4l/radio0"
-#define VIDEO_DEV "/dev/v4l/video0"
-
-#if !defined(NDELAY) && defined(O_NDELAY)
-#define FNDELAY O_NDELAY
+#define RADIO_DEV "/dev/radio0"
+#define VIDEO_DEV "/dev/video0"
+#ifdef HAVE_ALSA
+#define AUDIO_DEV "plughw:0,0"
#endif
+static char *tv_standard_names[] = { "AUTO", "PAL", "NTSC", "SECAM", "OLD", NULL };
+static int tv_standard_values[] = { VIDEO_MODE_AUTO, VIDEO_MODE_PAL, VIDEO_MODE_NTSC, VIDEO_MODE_SECAM, -1 };
+
typedef struct pvrscr_s pvrscr_t;
typedef struct {
@@ -117,6 +119,10 @@ typedef struct {
int old_zoomx;
int old_zoomy;
int audio_only;
+
+ buf_element_t *frames_base;
+ void *audio_content_base;
+ void *video_content_base;
/* Audio */
buf_element_t *aud_frames;
@@ -342,11 +348,11 @@ static void pvrscr_exit (scr_plugin_t *scr)
free(this);
}
-static pvrscr_t* pvrscr_init (void)
+static pvrscr_t *XINE_MALLOC pvrscr_init (void)
{
pvrscr_t *this;
- this = (pvrscr_t *) xine_xmalloc(sizeof(pvrscr_t));
+ this = calloc(1, sizeof(pvrscr_t));
this->scr.interface_version = 3;
this->scr.get_priority = pvrscr_get_priority;
@@ -539,6 +545,12 @@ static int set_frequency(v4l_input_plugin_t *this, unsigned long frequency)
fd = this->radio_fd;
if (frequency != 0) {
+ /* FIXME: Don't assume tuner 0 ? */
+ this->tuner = 0;
+ ret = ioctl(fd, VIDIOCSTUNER, &this->tuner);
+ lprintf("(%d) Response on set tuner to %d\n", ret, this->tuner);
+ this->video_tuner.tuner = this->tuner;
+
if (this->video_tuner.flags & VIDEO_TUNER_LOW) {
this->calc_frequency = frequency * 16;
} else {
@@ -624,6 +636,7 @@ static int search_by_channel(v4l_input_plugin_t *this, char *input_source)
{
int ret = 0;
int fd = 0;
+ cfg_entry_t *tv_standard_entry;
lprintf("input_source: %s\n", input_source);
@@ -659,20 +672,19 @@ static int search_by_channel(v4l_input_plugin_t *this, char *input_source)
return -1;
}
+ tv_standard_entry = this->stream->xine->config->lookup_entry(this->stream->xine->config,
+ "media.video4linux.tv_standard");
this->tuner_name = input_source;
- ret = ioctl(fd, VIDIOCSCHAN, &this->input);
+ if (tv_standard_entry->num_value != 0) {
+ this->video_channel.norm = tv_standard_values[ tv_standard_entry->num_value ];
+ xprintf(this->stream->xine, XINE_VERBOSITY_LOG,
+ "input_v4l: TV Standard configured as STD %s (%d)\n",
+ tv_standard_names[ tv_standard_entry->num_value ], this->video_channel.norm );
+ ret = ioctl(fd, VIDIOCSCHAN, &this->video_channel);
+ } else
+ ret = ioctl(fd, VIDIOCSCHAN, &this->input);
lprintf("(%d) Set channel to %d\n", ret, this->input);
-
- /* FIXME: Don't assume tuner 0 ? */
-
- this->tuner = 0;
-
- ret = ioctl(fd, VIDIOCSTUNER, &this->tuner);
-
- lprintf("(%d) Response on set tuner to %d\n", ret, this->tuner);
-
- this->video_tuner.tuner = this->tuner;
} else {
xprintf(this->stream->xine, XINE_VERBOSITY_LOG,
"input_v4l: Not setting video source. No source given\n");
@@ -708,23 +720,50 @@ static int search_by_channel(v4l_input_plugin_t *this, char *input_source)
return 1;
}
-static void allocate_audio_frames(v4l_input_plugin_t *this)
+static void allocate_frames(v4l_input_plugin_t *this, unsigned dovideo)
{
+ const size_t framescount = dovideo ? 2*NUM_FRAMES : NUM_FRAMES;
+
+ /* Allocate a single memory area for both audio and video frames */
+ buf_element_t *frames = this->frames_base =
+ calloc(framescount, sizeof(buf_element_t));
+ extra_info_t *infos =
+ calloc(framescount, sizeof(extra_info_t));
+
int i;
-
+
+ uint8_t *audio_content = this->audio_content_base =
+ calloc(NUM_FRAMES, this->periodsize);
+
+ /* Set up audio frames */
for (i = 0; i < NUM_FRAMES; i++) {
- buf_element_t *frame;
-
/* Audio frame */
- frame = xine_xmalloc(sizeof(buf_element_t));
-
- frame->content = xine_xmalloc(this->periodsize);
- frame->type = BUF_AUDIO_LPCM_LE;
- frame->source = this;
- frame->free_buffer = store_aud_frame;
- frame->extra_info = xine_xmalloc(sizeof(extra_info_t));
-
- store_aud_frame(frame);
+ frames[i].content = audio_content;
+ frames[i].type = BUF_AUDIO_LPCM_LE;
+ frames[i].source = this;
+ frames[i].free_buffer = store_aud_frame;
+ frames[i].extra_info = &infos[i];
+
+ audio_content += this->periodsize;
+ store_aud_frame(&frames[i]);
+ }
+
+ if ( dovideo ) {
+ uint8_t *video_content = this->video_content_base =
+ calloc(NUM_FRAMES, this->frame_size);
+
+ /* Set up video frames */
+ for (i = NUM_FRAMES; i < 2*NUM_FRAMES; i++) {
+ /* Video frame */
+ frames[i].content = video_content;
+ frames[i].type = this->frame_format;
+ frames[i].source = this;
+ frames[i].free_buffer = store_vid_frame;
+ frames[i].extra_info = &infos[i];
+
+ video_content += this->frame_size;
+ store_vid_frame(&frames[i]);
+ }
}
}
@@ -775,7 +814,7 @@ static int open_radio_capture_device(v4l_input_plugin_t *this)
/* Pre-allocate some frames for audio so it doesn't have to be done during
* capture */
- allocate_audio_frames(this);
+ allocate_frames(this, 0);
this->audio_only = 1;
@@ -801,7 +840,7 @@ static int open_video_capture_device(v4l_input_plugin_t *this)
{
int found = 0;
int tuner_found = 0;
- int i, ret;
+ int ret;
unsigned int j;
cfg_entry_t *entry;
@@ -845,10 +884,6 @@ static int open_video_capture_device(v4l_input_plugin_t *this)
_x_stream_info_set(this->stream, XINE_STREAM_INFO_HAS_AUDIO, 1);
_x_stream_info_set(this->stream, XINE_STREAM_INFO_HAS_VIDEO, 1);
- /* Pre-allocate some frames for audio and video so it doesn't have to be
- * done during capture */
- allocate_audio_frames(this);
-
/* Unmute audio off video capture device */
unmute_audio(this);
@@ -951,27 +986,17 @@ static int open_video_capture_device(v4l_input_plugin_t *this)
break;
}
- for (i = 0; i < NUM_FRAMES; i++) {
- buf_element_t *frame;
-
- frame = xine_xmalloc (sizeof (buf_element_t));
-
- frame->content = xine_xmalloc (this->frame_size);
- frame->type = this->frame_format;
- frame->source = this;
- frame->free_buffer = store_vid_frame;
- frame->extra_info = xine_xmalloc(sizeof(extra_info_t));
-
- store_vid_frame(frame);
- }
-
/* Strip the vbi / sync signal from the image by zooming in */
this->old_zoomx = xine_get_param(this->stream, XINE_PARAM_VO_ZOOM_X);
this->old_zoomy = xine_get_param(this->stream, XINE_PARAM_VO_ZOOM_Y);
xine_set_param(this->stream, XINE_PARAM_VO_ZOOM_X, 103);
xine_set_param(this->stream, XINE_PARAM_VO_ZOOM_Y, 103);
-
+
+ /* Pre-allocate some frames for audio and video so it doesn't have to be
+ * done during capture */
+ allocate_frames(this, 1);
+
/* If we made it here, everything went ok */
this->audio_only = 0;
if (tuner_found)
@@ -1566,52 +1591,19 @@ static void v4l_plugin_dispose (input_plugin_t *this_gen) {
if (this->event_queue)
xine_event_dispose_queue (this->event_queue);
-
- lprintf("Freeing allocated audio frames");
- if (this->aud_frames) {
- buf_element_t *cur_frame = this->aud_frames;
-
- while (cur_frame != NULL) {
- buf_element_t *next_frame = cur_frame->next;
-#ifdef LOG
- printf(".");
-#endif
- if (cur_frame->content)
- free(cur_frame->content);
-
- if (cur_frame->extra_info)
- free(cur_frame->extra_info);
-
- free(cur_frame);
- cur_frame = next_frame;
- }
- }
-#ifdef LOG
- printf("\n");
-#endif
+ /* All the frames, both video and audio, are allocated in a single
+ memory area pointed by the frames_base pointer. The content of
+ the frames is divided in two areas, one pointed by
+ audio_content_base and the other by video_content_base. The
+ extra_info structures are all allocated in the first frame
+ data. */
+ free(this->audio_content_base);
+ free(this->video_content_base);
+ if (this->frames_base)
+ free(this->frames_base->extra_info);
+ free(this->frames_base);
-
- lprintf("Freeing allocated video frames");
- if (this->vid_frames) {
- buf_element_t *cur_frame = this->vid_frames;
-
- while (cur_frame != NULL) {
- buf_element_t *next_frame = cur_frame->next;
-#ifdef LOG
- printf(".");
-#endif
-
- if (cur_frame->content)
- free(cur_frame->content);
-
- if (cur_frame->extra_info)
- free(cur_frame->extra_info);
-
- free(cur_frame);
- cur_frame = next_frame;
- }
- }
#ifdef LOG
printf("\n");
#endif
@@ -1701,6 +1693,9 @@ static input_plugin_t *v4l_class_get_instance (input_class_t *cls_gen,
{
/* v4l_input_class_t *cls = (v4l_input_class_t *) cls_gen; */
v4l_input_plugin_t *this;
+#ifdef HAVE_ALSA
+ cfg_entry_t *entry;
+#endif
char *mrl = strdup(data);
/* Example mrl: v4l:/Television/62500 */
@@ -1709,7 +1704,7 @@ static input_plugin_t *v4l_class_get_instance (input_class_t *cls_gen,
return NULL;
}
- this = (v4l_input_plugin_t *) xine_xmalloc (sizeof (v4l_input_plugin_t));
+ this = calloc(1, sizeof (v4l_input_plugin_t));
extract_mrl(this, mrl);
@@ -1721,13 +1716,14 @@ static input_plugin_t *v4l_class_get_instance (input_class_t *cls_gen,
this->event_queue = NULL;
this->scr = NULL;
#ifdef HAVE_ALSA
- this->pcm_name = NULL;
this->pcm_data = NULL;
this->pcm_hwparams = NULL;
/* Audio */
this->pcm_stream = SND_PCM_STREAM_CAPTURE;
- this->pcm_name = strdup("plughw:0,0");
+ entry = this->stream->xine->config->lookup_entry(this->stream->xine->config,
+ "media.video4linux.audio_device");
+ this->pcm_name = strdup (entry->str_value);
this->audio_capture = 1;
#endif
this->rate = 44100;
@@ -1870,11 +1866,11 @@ static input_plugin_t *v4l_class_get_radio_instance (input_class_t *cls_gen,
* v4l input plugin class stuff
*/
-static char *v4l_class_get_video_description (input_class_t *this_gen) {
+static const char *v4l_class_get_video_description (input_class_t *this_gen) {
return _("v4l tv input plugin");
}
-static char *v4l_class_get_radio_description (input_class_t *this_gen) {
+static const char *v4l_class_get_radio_description (input_class_t *this_gen) {
return _("v4l radio input plugin");
}
@@ -1893,7 +1889,7 @@ static void *init_video_class (xine_t *xine, void *data)
v4l_input_class_t *this;
config_values_t *config = xine->config;
- this = (v4l_input_class_t *) xine_xmalloc (sizeof (v4l_input_class_t));
+ this = calloc(1, sizeof (v4l_input_class_t));
this->xine = xine;
@@ -1910,7 +1906,19 @@ static void *init_video_class (xine_t *xine, void *data)
_("v4l video device"),
_("The path to your Video4Linux video device."),
10, NULL, NULL);
-
+#ifdef HAVE_ALSA
+ config->register_filename (config, "media.video4linux.audio_device",
+ AUDIO_DEV, 0,
+ _("v4l ALSA audio input device"),
+ _("The name of the audio device which corresponds "
+ "to your Video4Linux video device."),
+ 10, NULL, NULL);
+#endif
+ config->register_enum (config, "media.video4linux.tv_standard", 4 /* old */,
+ tv_standard_names, _("v4l TV standard"),
+ _("Selects the TV standard of the input signals. "
+ "Either: AUTO, PAL, NTSC or SECAM. "), 20, NULL, NULL);
+
return this;
}
@@ -1919,7 +1927,7 @@ static void *init_radio_class (xine_t *xine, void *data)
v4l_input_class_t *this;
config_values_t *config = xine->config;
- this = (v4l_input_class_t *) xine_xmalloc (sizeof (v4l_input_class_t));
+ this = calloc(1, sizeof (v4l_input_class_t));
this->xine = xine;
diff --git a/src/input/input_vcd.c b/src/input/input_vcd.c
index 007fa5946..c99f57f09 100644
--- a/src/input/input_vcd.c
+++ b/src/input/input_vcd.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2000-2006 the xine project
+ * Copyright (C) 2000-2008 the xine project
*
* This file is part of xine, a free video player.
*
@@ -84,7 +84,7 @@ typedef struct {
const char *device;
- char *filelist[100];
+ char **filelist;
int mrls_allocated_entries;
xine_mrl_t **mrls;
@@ -92,7 +92,7 @@ typedef struct {
#if defined (__linux__) || defined(__sun)
struct cdrom_tochdr tochdr;
struct cdrom_tocentry tocent[100];
-#elif defined (__FreeBSD_kernel__)
+#elif defined (__FreeBSD_kernel__) || defined (__OpenBSD__)
struct ioc_toc_header tochdr;
struct cd_toc_entry *tocent;
off_t cur_sec;
@@ -117,7 +117,7 @@ typedef struct {
int cur_track;
-#if defined (__linux__) || defined(__sun) || defined (__FreeBSD_kernel__)
+#if defined (__linux__) || defined(__sun) || defined (__FreeBSD_kernel__) || defined (__OpenBSD__)
uint8_t cur_min, cur_sec, cur_frame;
#endif
@@ -177,7 +177,7 @@ static int input_vcd_read_toc (vcd_input_class_t *this, int fd) {
return 0;
}
-#elif defined (__FreeBSD_kernel__)
+#elif defined (__FreeBSD_kernel__) || defined (__OpenBSD__)
static int input_vcd_read_toc (vcd_input_class_t *this, int fd) {
struct ioc_read_toc_entry te;
@@ -393,7 +393,7 @@ static off_t vcd_plugin_read (input_plugin_t *this_gen,
memcpy (buf, data.data, VCDSECTORSIZE); /* FIXME */
return VCDSECTORSIZE;
}
-#elif defined (__FreeBSD_kernel__)
+#elif defined (__FreeBSD_kernel__) || defined (__OpenBSD__)
static off_t vcd_plugin_read (input_plugin_t *this_gen,
char *buf, off_t nlen) {
vcd_input_plugin_t *this = (vcd_input_plugin_t *) this_gen;
@@ -531,7 +531,7 @@ static buf_element_t *vcd_plugin_read_block (input_plugin_t *this_gen,
memcpy (buf->mem, data.data, VCDSECTORSIZE); /* FIXME */
return buf;
}
-#elif defined (__FreeBSD_kernel__)
+#elif defined (__FreeBSD_kernel__) || defined (__OpenBSD__)
static buf_element_t *vcd_plugin_read_block (input_plugin_t *this_gen,
fifo_buffer_t *fifo, off_t nlen) {
@@ -690,7 +690,7 @@ static off_t vcd_plugin_seek (input_plugin_t *this_gen,
return offset ; /* FIXME */
}
-#elif defined (__FreeBSD_kernel__)
+#elif defined (__FreeBSD_kernel__) || defined (__OpenBSD__)
static off_t vcd_plugin_seek (input_plugin_t *this_gen,
off_t offset, int origin) {
@@ -764,7 +764,7 @@ static off_t vcd_plugin_get_length (input_plugin_t *this_gen) {
return (off_t) 0;
}
-#elif defined (__FreeBSD_kernel__)
+#elif defined (__FreeBSD_kernel__) || defined (__OpenBSD__)
static off_t vcd_plugin_get_length (input_plugin_t *this_gen) {
vcd_input_plugin_t *this = (vcd_input_plugin_t *) this_gen;
off_t len ;
@@ -859,6 +859,10 @@ static int vcd_plugin_open (input_plugin_t *this_gen) {
this->cur_min = this->cls->tocent[this->cur_track].cdte_addr.msf.minute;
this->cur_sec = this->cls->tocent[this->cur_track].cdte_addr.msf.second;
this->cur_frame = this->cls->tocent[this->cur_track].cdte_addr.msf.frame;
+#elif defined (__OpenBSD__)
+ this->cur_min = this->cls->tocent[this->cur_track + 1 - this->cls->tochdr.starting_track].addr.msf.minute;
+ this->cur_sec = this->cls->tocent[this->cur_track + 1 - this->cls->tochdr.starting_track].addr.msf.second;
+ this->cur_frame = this->cls->tocent[this->cur_track + 1 - this->cls->tochdr.starting_track].addr.msf.frame;
#elif defined (__FreeBSD_kernel__)
{
int bsize = 2352;
@@ -889,7 +893,7 @@ static input_plugin_t *vcd_class_get_instance (input_class_t *cls_gen, xine_stre
return 0;
}
- this = (vcd_input_plugin_t *) xine_xmalloc(sizeof(vcd_input_plugin_t));
+ this = calloc(1, sizeof(vcd_input_plugin_t));
this->stream = stream;
this->mrl = mrl;
@@ -924,17 +928,26 @@ static const char *vcd_class_get_identifier (input_class_t *this_gen) {
return "vcdo";
}
+static void vcd_filelist_dispose(vcd_input_class_t *this) {
+ if ( this->filelist == NULL ) return;
+
+ char **entry = this->filelist;
+
+ while(*(entry)) {
+ free(*(entry++));
+ }
+
+ free(this->filelist);
+}
+
static void vcd_class_dispose (input_class_t *this_gen) {
vcd_input_class_t *this = (vcd_input_class_t *) this_gen;
- int i;
config_values_t *config = this->xine->config;
config->unregister_callback(config, "media.vcd.device");
- for (i = 0; i < 100; i++)
- free (this->filelist[i]);
-
+ vcd_filelist_dispose(this);
free (this->mrls);
free (this);
}
@@ -982,33 +995,19 @@ static xine_mrl_t **vcd_class_get_dir (input_class_t *this_gen, const char *file
/* printf ("%d tracks\n", this->total_tracks); */
for (i=1; i<this->total_tracks; i++) { /* FIXME: check if track 0 contains valid data */
- char mrl[1024];
-
- memset(&mrl, 0, sizeof (mrl));
- sprintf(mrl, "vcdo:/%d",i);
-
if((i-1) >= this->mrls_allocated_entries) {
++this->mrls_allocated_entries;
/* note: 1 extra pointer for terminating NULL */
this->mrls = realloc(this->mrls, (this->mrls_allocated_entries+1) * sizeof(xine_mrl_t*));
- this->mrls[(i-1)] = (xine_mrl_t *) xine_xmalloc(sizeof(xine_mrl_t));
+ this->mrls[(i-1)] = calloc(1, sizeof(xine_mrl_t));
}
else {
memset(this->mrls[(i-1)], 0, sizeof(xine_mrl_t));
}
- if(this->mrls[(i-1)]->mrl) {
- this->mrls[(i-1)]->mrl = (char *)
- realloc(this->mrls[(i-1)]->mrl, strlen(mrl) + 1);
- }
- else {
- this->mrls[(i-1)]->mrl = (char *) xine_xmalloc(strlen(mrl) + 1);
- }
-
- this->mrls[i-1]->origin = NULL;
- sprintf(this->mrls[i-1]->mrl, "%s", mrl);
- this->mrls[i-1]->link = NULL;
- this->mrls[i-1]->type = (0 | mrl_vcd);
+ asprintf(&(this->mrls[i-1]->mrl), "vcdo:/%d", i);
+
+ this->mrls[i-1]->type = mrl_vcd;
/* hack */
this->mrls[i-1]->size = vcd_plugin_get_length ((input_plugin_t *) this);
@@ -1055,20 +1054,15 @@ static char ** vcd_class_get_autoplay_list (input_class_t *this_gen, int *num_fi
fd = -1;
*num_files = this->total_tracks - 1;
-
- /* printf ("%d tracks\n", this->total_tracks); */
-
- for (i = 1; i < this->total_tracks; i++) { /* FIXME: check if track 0 contains valid data */
- if(this->filelist[i - 1] == NULL)
- this->filelist[i - 1] = (char *) realloc(this->filelist[i - 1], sizeof(char *) * 256);
+ vcd_filelist_dispose(this);
+ this->filelist = calloc(this->total_tracks+1, sizeof(char*));
- sprintf (this->filelist[i - 1], "vcdo:/%d",i);
- /* printf ("list[%d] : %d %s\n", i, this->filelist[i-1], this->filelist[i-1]); */
- }
+ /* FIXME: check if track 0 contains valid data */
+ for (i = 1; i < this->total_tracks; i++)
+ asprintf(&this->filelist[i-1], "vcdo:/%d", i);
- this->filelist[i - 1] = (char *) realloc(this->filelist[i-1], sizeof(char *));
- this->filelist[i - 1] = NULL;
+ /* printf ("%d tracks\n", this->total_tracks); */
return this->filelist;
}
@@ -1077,9 +1071,8 @@ static void *init_class (xine_t *xine, void *data) {
vcd_input_class_t *this;
config_values_t *config = xine->config;
- int i;
- this = (vcd_input_class_t *) xine_xmalloc (sizeof (vcd_input_class_t));
+ this = calloc(1, sizeof (vcd_input_class_t));
this->xine = xine;
@@ -1097,13 +1090,9 @@ static void *init_class (xine_t *xine, void *data) {
"you intend to play your VideoCDs with."),
10, device_change_cb, (void *)this);
- this->mrls = (xine_mrl_t **) xine_xmalloc(sizeof(xine_mrl_t*));
+ this->mrls = calloc(1, sizeof(xine_mrl_t*));
this->mrls_allocated_entries = 0;
- for (i = 0; i < 100; i++) {
- this->filelist[i] = (char *) xine_xmalloc(sizeof(char *) * 256);
- }
-
return this;
}
diff --git a/src/input/libdvdnav/bswap.h b/src/input/libdvdnav/bswap.h
index 2a2d222fe..23f0251d6 100644
--- a/src/input/libdvdnav/bswap.h
+++ b/src/input/libdvdnav/bswap.h
@@ -20,7 +20,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include <config.h>
+#include "config.h"
#if defined(WORDS_BIGENDIAN)
/* All bigendian systems are fine, just ignore the swaps. */
diff --git a/src/input/libdvdnav/diff_against_cvs.patch b/src/input/libdvdnav/diff_against_cvs.patch
index 202474fef..6df704e2a 100644
--- a/src/input/libdvdnav/diff_against_cvs.patch
+++ b/src/input/libdvdnav/diff_against_cvs.patch
@@ -323,7 +323,7 @@ diff -u -p -u -r1.5 dvd_reader.h
-#ifdef _MSC_VER
+#ifdef HAVE_CONFIG_H
- #include <config.h>
+ #include "config.h"
+#endif
+#ifdef _MSC_VER
diff --git a/src/input/libdvdnav/dvd_reader.c b/src/input/libdvdnav/dvd_reader.c
index 200a1dbec..eff1977fc 100644
--- a/src/input/libdvdnav/dvd_reader.c
+++ b/src/input/libdvdnav/dvd_reader.c
@@ -1037,6 +1037,28 @@ int32_t DVDFileSeek( dvd_file_t *dvd_file, int32_t offset )
return offset;
}
+int32_t DVDFileSeekForce( dvd_file_t *dvd_file, int offset, int force_size )
+{
+ /* Check arguments. */
+ if( dvd_file == NULL || offset < 0 )
+ return -1;
+
+ if( dvd_file->dvd->isImageFile ) {
+ if( force_size < 0 )
+ force_size = (offset - 1) / DVD_VIDEO_LB_LEN + 1;
+ if( dvd_file->filesize < force_size) {
+ dvd_file->filesize = force_size;
+ fprintf(stderr, "libdvdread: Ignored UDF provided size of file.\n");
+ }
+ }
+
+ if( offset > dvd_file->filesize * DVD_VIDEO_LB_LEN ) {
+ return -1;
+ }
+ dvd_file->seek_pos = (uint32_t) offset;
+ return offset;
+}
+
ssize_t DVDReadBytes( dvd_file_t *dvd_file, void *data, size_t byte_size )
{
unsigned char *secbuf_base, *secbuf;
@@ -1077,7 +1099,7 @@ ssize_t DVDReadBytes( dvd_file_t *dvd_file, void *data, size_t byte_size )
memcpy( data, &(secbuf[ seek_byte ]), byte_size );
free( secbuf_base );
- dvd_file->seek_pos += byte_size;
+ DVDFileSeekForce(dvd_file, dvd_file->seek_pos + byte_size, -1);
return byte_size;
}
diff --git a/src/input/libdvdnav/dvd_reader.h b/src/input/libdvdnav/dvd_reader.h
index bb3f5053b..c7b3f9df8 100644
--- a/src/input/libdvdnav/dvd_reader.h
+++ b/src/input/libdvdnav/dvd_reader.h
@@ -22,7 +22,7 @@
*/
#ifdef HAVE_CONFIG_H
-#include <config.h>
+#include "config.h"
#endif
#ifdef _MSC_VER
@@ -171,6 +171,8 @@ ssize_t DVDReadBlocks( dvd_file_t *, int, size_t, unsigned char * );
*/
int32_t DVDFileSeek( dvd_file_t *, int32_t );
+int32_t DVDFileSeekForce( dvd_file_t *, int, int );
+
/**
* Reads the given number of bytes from the file. This call can only be used
* on the information files, and may not be used for reading from a VOB. This
diff --git a/src/input/libdvdnav/ifo_read.c b/src/input/libdvdnav/ifo_read.c
index 8f47d2a54..bc1ba580b 100644
--- a/src/input/libdvdnav/ifo_read.c
+++ b/src/input/libdvdnav/ifo_read.c
@@ -93,6 +93,10 @@ static inline int DVDFileSeek_( dvd_file_t *dvd_file, uint32_t offset ) {
return (DVDFileSeek(dvd_file, (int)offset) == (int)offset);
}
+static inline int32_t DVDFileSeekForce_( dvd_file_t *dvd_file, uint32_t offset, int force_size ) {
+ return (DVDFileSeekForce(dvd_file, (int)offset, force_size) == (int)offset);
+}
+
ifo_handle_t *ifoOpen(dvd_reader_t *dvd, int title) {
ifo_handle_t *ifofile;
@@ -1507,7 +1511,7 @@ static int ifoRead_VOBU_ADMAP_internal(ifo_handle_t *ifofile,
unsigned int i;
int info_length;
- if(!DVDFileSeek_(ifofile->file, sector * DVD_BLOCK_LEN))
+ if(!DVDFileSeekForce_(ifofile->file, sector * DVD_BLOCK_LEN, sector))
return 0;
if(!(DVDReadBytes(ifofile->file, vobu_admap, VOBU_ADMAP_SIZE)))
diff --git a/src/input/libdvdnav/md5.c b/src/input/libdvdnav/md5.c
index 2bfdddee4..16b7b0690 100644
--- a/src/input/libdvdnav/md5.c
+++ b/src/input/libdvdnav/md5.c
@@ -21,7 +21,7 @@
/* Written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995. */
#ifdef HAVE_CONFIG_H
-# include <config.h>
+# include "config.h"
#endif
#include <sys/types.h>
diff --git a/src/input/libdvdnav/remap.c b/src/input/libdvdnav/remap.c
index 43c81c66f..df0be29ce 100644
--- a/src/input/libdvdnav/remap.c
+++ b/src/input/libdvdnav/remap.c
@@ -216,6 +216,7 @@ remap_t* remap_loadmap( char *title) {
remap_add_node( map, tmp);
}
}
+ close (fp); /* ignoring errors... */
if (map->nblocks == 0 && map->debug == 0) return NULL;
return map;
diff --git a/src/input/libreal/asmrp.c b/src/input/libreal/asmrp.c
index f7206b583..902c59d42 100644
--- a/src/input/libreal/asmrp.c
+++ b/src/input/libreal/asmrp.c
@@ -32,6 +32,10 @@
*/
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@@ -95,7 +99,7 @@ typedef struct {
} asmrp_t;
-static asmrp_t *asmrp_new () {
+static asmrp_t *XINE_MALLOC asmrp_new () {
asmrp_t *p;
diff --git a/src/input/libreal/real.c b/src/input/libreal/real.c
index df50f0440..dcb90bcd0 100644
--- a/src/input/libreal/real.c
+++ b/src/input/libreal/real.c
@@ -21,6 +21,10 @@
* adopted from joschkas real tools.
*/
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
#include <stdio.h>
#include <string.h>
@@ -48,9 +52,6 @@ static const unsigned char xor_table[] = {
#define _X_BE_32C(x,y) do { *(uint32_t *)(x) = be2me_32((y)); } while(0)
#define _X_LE_32C(x,y) do { *(uint32_t *)(x) = le2me_32((y)); } while(0)
-#define MAX(x,y) ((x>y) ? x : y)
-
-
static void hash(char *field, char *param) {
uint32_t a, b, c, d;
@@ -313,7 +314,7 @@ static void calc_response_string (char *result, char *challenge) {
void real_calc_response_and_checksum (char *response, char *chksum, char *challenge) {
- int ch_len, resp_len;
+ size_t ch_len, resp_len;
int i;
char *ptr;
char buf[128];
@@ -449,7 +450,7 @@ rmff_header_t *real_parse_sdp(char *data, char **stream_rules, uint32_t bandwidt
if (!desc) return NULL;
buf=xine_buffer_init(2048);
- header = xine_xmalloc(sizeof(rmff_header_t));
+ header = calloc(1, sizeof(rmff_header_t));
header->fileheader=rmff_new_fileheader(4+desc->stream_count);
header->cont=rmff_new_cont(
@@ -458,7 +459,7 @@ rmff_header_t *real_parse_sdp(char *data, char **stream_rules, uint32_t bandwidt
desc->copyright,
desc->abstract);
header->data=rmff_new_dataheader(0,0);
- header->streams = xine_xmalloc(sizeof(rmff_mdpr_t*)*(desc->stream_count+1));
+ header->streams = calloc((desc->stream_count+1), sizeof(rmff_mdpr_t*));
lprintf("number of streams: %u\n", desc->stream_count);
for (i=0; i<desc->stream_count; i++) {
@@ -660,7 +661,7 @@ rmff_header_t *real_setup_and_get_header(rtsp_t *rtsp_session, uint32_t bandwid
lprintf("Stream description size: %i\n", size);
- description = malloc(sizeof(char)*(size+1));
+ description = malloc(size+1);
if( rtsp_read_data(rtsp_session, description, size) <= 0) {
xine_buffer_free(buf);
diff --git a/src/input/libreal/rmff.c b/src/input/libreal/rmff.c
index 159b81ee6..2d3fcc613 100644
--- a/src/input/libreal/rmff.c
+++ b/src/input/libreal/rmff.c
@@ -21,6 +21,10 @@
* adopted from joschkas real tools
*/
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
#define LOG_MODULE "rmff"
#define LOG_VERBOSE
/*
@@ -35,9 +39,13 @@
* writes header data to a buffer
*/
-static void rmff_dump_fileheader(rmff_fileheader_t *fileheader, char *buffer) {
+static int rmff_dump_fileheader(rmff_fileheader_t *fileheader, uint8_t *buffer, int bufsize) {
+
+ if (!fileheader) return 0;
+
+ if (bufsize < RMFF_FILEHEADER_SIZE)
+ return -1;
- if (!fileheader) return;
fileheader->object_id=_X_BE_32(&fileheader->object_id);
fileheader->size=_X_BE_32(&fileheader->size);
fileheader->object_version=_X_BE_16(&fileheader->object_version);
@@ -53,11 +61,17 @@ static void rmff_dump_fileheader(rmff_fileheader_t *fileheader, char *buffer) {
fileheader->file_version=_X_BE_32(&fileheader->file_version);
fileheader->num_headers=_X_BE_32(&fileheader->num_headers);
fileheader->object_id=_X_BE_32(&fileheader->object_id);
+
+ return RMFF_FILEHEADER_SIZE;
}
-static void rmff_dump_prop(rmff_prop_t *prop, char *buffer) {
+static int rmff_dump_prop(rmff_prop_t *prop, uint8_t *buffer, int bufsize) {
+
+ if (!prop) return 0;
+
+ if (bufsize < RMFF_PROPHEADER_SIZE)
+ return -1;
- if (!prop) return;
prop->object_id=_X_BE_32(&prop->object_id);
prop->size=_X_BE_32(&prop->size);
prop->object_version=_X_BE_16(&prop->object_version);
@@ -93,13 +107,19 @@ static void rmff_dump_prop(rmff_prop_t *prop, char *buffer) {
prop->num_streams=_X_BE_16(&prop->num_streams);
prop->flags=_X_BE_16(&prop->flags);
prop->object_id=_X_BE_32(&prop->object_id);
+
+ return RMFF_PROPHEADER_SIZE;
}
-static void rmff_dump_mdpr(rmff_mdpr_t *mdpr, char *buffer) {
+static int rmff_dump_mdpr(rmff_mdpr_t *mdpr, uint8_t *buffer, int bufsize) {
int s1, s2, s3;
- if (!mdpr) return;
+ if (!mdpr) return 0;
+
+ if (bufsize < RMFF_MDPRHEADER_SIZE + mdpr->type_specific_len + mdpr->stream_name_size + mdpr->mime_type_size)
+ return -1;
+
mdpr->object_id=_X_BE_32(&mdpr->object_id);
mdpr->size=_X_BE_32(&mdpr->size);
mdpr->object_version=_X_BE_16(&mdpr->object_version);
@@ -141,13 +161,19 @@ static void rmff_dump_mdpr(rmff_mdpr_t *mdpr, char *buffer) {
mdpr->duration=_X_BE_32(&mdpr->duration);
mdpr->object_id=_X_BE_32(&mdpr->object_id);
+ return RMFF_MDPRHEADER_SIZE + s1 + s2 + s3;
}
-static void rmff_dump_cont(rmff_cont_t *cont, char *buffer) {
+static int rmff_dump_cont(rmff_cont_t *cont, uint8_t *buffer, int bufsize) {
int p;
- if (!cont) return;
+ if (!cont) return 0;
+
+ if (bufsize < RMFF_CONTHEADER_SIZE + cont->title_len + cont->author_len +
+ cont->copyright_len + cont->comment_len)
+ return -1;
+
cont->object_id=_X_BE_32(&cont->object_id);
cont->size=_X_BE_32(&cont->size);
cont->object_version=_X_BE_16(&cont->object_version);
@@ -181,11 +207,18 @@ static void rmff_dump_cont(rmff_cont_t *cont, char *buffer) {
cont->size=_X_BE_32(&cont->size);
cont->object_version=_X_BE_16(&cont->object_version);
cont->object_id=_X_BE_32(&cont->object_id);
+
+ return RMFF_CONTHEADER_SIZE + cont->title_len + cont->author_len +
+ cont->copyright_len + cont->comment_len;
}
-static void rmff_dump_dataheader(rmff_data_t *data, char *buffer) {
+static int rmff_dump_dataheader(rmff_data_t *data, uint8_t *buffer, int bufsize) {
+
+ if (!data) return 0;
+
+ if (bufsize < RMFF_DATAHEADER_SIZE)
+ return -1;
- if (!data) return;
data->object_id=_X_BE_32(&data->object_id);
data->size=_X_BE_32(&data->size);
data->object_version=_X_BE_16(&data->object_version);
@@ -201,31 +234,43 @@ static void rmff_dump_dataheader(rmff_data_t *data, char *buffer) {
data->size=_X_BE_32(&data->size);
data->object_version=_X_BE_16(&data->object_version);
data->object_id=_X_BE_32(&data->object_id);
+
+ return RMFF_DATAHEADER_SIZE;
}
-int rmff_dump_header(rmff_header_t *h, char *buffer, int max) {
+int rmff_dump_header(rmff_header_t *h, void *buf_gen, int max) {
+ uint8_t *buffer = buf_gen;
- int written=0;
+ int written=0, size;
rmff_mdpr_t **stream=h->streams;
- rmff_dump_fileheader(h->fileheader, &buffer[written]);
- written+=h->fileheader->size;
- rmff_dump_prop(h->prop, &buffer[written]);
- written+=h->prop->size;
- rmff_dump_cont(h->cont, &buffer[written]);
- written+=h->cont->size;
+ if ((size=rmff_dump_fileheader(h->fileheader, &buffer[written], max)) < 0)
+ return -1;
+ written+=size;
+ max -= size;
+ if ((size=rmff_dump_prop(h->prop, &buffer[written], max)) < 0)
+ return -1;
+ written+=size;
+ max -= size;
+ if ((size=rmff_dump_cont(h->cont, &buffer[written], max)) < 0)
+ return -1;
+ written+=size;
+ max -= size;
if (stream)
{
while(*stream)
{
- rmff_dump_mdpr(*stream, &buffer[written]);
- written+=(*stream)->size;
+ if ((size=rmff_dump_mdpr(*stream, &buffer[written], max)) < 0)
+ return -1;
+ written+=size;
+ max -= size;
stream++;
}
}
- rmff_dump_dataheader(h->data, &buffer[written]);
- written+=18;
+ if ((size=rmff_dump_dataheader(h->data, &buffer[written], max)) < 0)
+ return -1;
+ written+=size;
return written;
}
@@ -289,12 +334,14 @@ static rmff_prop_t *rmff_scan_prop(const char *data) {
return prop;
}
-static rmff_mdpr_t *rmff_scan_mdpr(const char *data) {
-
- rmff_mdpr_t *mdpr = malloc(sizeof(rmff_mdpr_t));
+static rmff_mdpr_t *rmff_scan_mdpr(const char *data)
+{
+ rmff_mdpr_t *mdpr = calloc(sizeof(rmff_mdpr_t), 1);
mdpr->object_id=_X_BE_32(data);
mdpr->size=_X_BE_32(&data[4]);
+ if (mdpr->size < 46)
+ goto fail;
mdpr->object_version=_X_BE_16(&data[8]);
if (mdpr->object_version != 0)
{
@@ -310,21 +357,40 @@ static rmff_mdpr_t *rmff_scan_mdpr(const char *data) {
mdpr->duration=_X_BE_32(&data[36]);
mdpr->stream_name_size=data[40];
- mdpr->stream_name = malloc(sizeof(char)*(mdpr->stream_name_size+1));
+ if (mdpr->size < 46 + mdpr->stream_name_size)
+ goto fail;
+ mdpr->stream_name = malloc(mdpr->stream_name_size+1);
+ if (!mdpr->stream_name)
+ goto fail;
memcpy(mdpr->stream_name, &data[41], mdpr->stream_name_size);
mdpr->stream_name[mdpr->stream_name_size]=0;
mdpr->mime_type_size=data[41+mdpr->stream_name_size];
- mdpr->mime_type = malloc(sizeof(char)*(mdpr->mime_type_size+1));
+ if (mdpr->size < 46 + mdpr->stream_name_size + mdpr->mime_type_size)
+ goto fail;
+ mdpr->mime_type = malloc(mdpr->mime_type_size+1);
+ if (!mdpr->mime_type)
+ goto fail;
memcpy(mdpr->mime_type, &data[42+mdpr->stream_name_size], mdpr->mime_type_size);
mdpr->mime_type[mdpr->mime_type_size]=0;
mdpr->type_specific_len=_X_BE_32(&data[42+mdpr->stream_name_size+mdpr->mime_type_size]);
- mdpr->type_specific_data = malloc(sizeof(char)*(mdpr->type_specific_len));
+ if (mdpr->size < 46 + mdpr->stream_name_size + mdpr->mime_type_size + mdpr->type_specific_data)
+ goto fail;
+ mdpr->type_specific_data = malloc(mdpr->type_specific_len);
+ if (!mdpr->type_specific_data)
+ goto fail;
memcpy(mdpr->type_specific_data,
&data[46+mdpr->stream_name_size+mdpr->mime_type_size], mdpr->type_specific_len);
return mdpr;
+
+fail:
+ free (mdpr->stream_name);
+ free (mdpr->mime_type);
+ free (mdpr->type_specific_data);
+ free (mdpr);
+ return NULL;
}
static rmff_cont_t *rmff_scan_cont(const char *data) {
@@ -340,22 +406,22 @@ static rmff_cont_t *rmff_scan_cont(const char *data) {
lprintf("warning: unknown object version in CONT: 0x%04x\n", cont->object_version);
}
cont->title_len=_X_BE_16(&data[10]);
- cont->title = malloc(sizeof(char)*(cont->title_len+1));
+ cont->title = malloc(cont->title_len+1);
memcpy(cont->title, &data[12], cont->title_len);
cont->title[cont->title_len]=0;
pos=cont->title_len+12;
cont->author_len=_X_BE_16(&data[pos]);
- cont->author = malloc(sizeof(char)*(cont->author_len+1));
+ cont->author = malloc(cont->author_len+1);
memcpy(cont->author, &data[pos+2], cont->author_len);
cont->author[cont->author_len]=0;
pos=pos+2+cont->author_len;
cont->copyright_len=_X_BE_16(&data[pos]);
- cont->copyright = malloc(sizeof(char)*(cont->copyright_len+1));
+ cont->copyright = malloc(cont->copyright_len+1);
memcpy(cont->copyright, &data[pos+2], cont->copyright_len);
cont->copyright[cont->copyright_len]=0;
pos=pos+2+cont->copyright_len;
cont->comment_len=_X_BE_16(&data[pos]);
- cont->comment = malloc(sizeof(char)*(cont->comment_len+1));
+ cont->comment = malloc(cont->comment_len+1);
memcpy(cont->comment, &data[pos+2], cont->comment_len);
cont->comment[cont->comment_len]=0;
@@ -403,10 +469,7 @@ rmff_header_t *rmff_scan_header(const char *data) {
header->fileheader=rmff_scan_fileheader(ptr);
ptr += header->fileheader->size;
- header->streams = malloc(sizeof(rmff_mdpr_t*)*(header->fileheader->num_headers));
- for (i=0; i<header->fileheader->num_headers; i++) {
- header->streams[i]=NULL;
- }
+ header->streams = calloc(header->fileheader->num_headers, sizeof(rmff_mdpr_t*));
for (i=1; i<header->fileheader->num_headers; i++) {
chunk_type = _X_BE_32(ptr);
@@ -425,8 +488,11 @@ rmff_header_t *rmff_scan_header(const char *data) {
break;
case MDPR_TAG:
mdpr=rmff_scan_mdpr(ptr);
- chunk_size=mdpr->size;
- header->streams[mdpr->stream_number]=mdpr;
+ if (mdpr) /* FIXME: what to do if NULL? */
+ {
+ chunk_size=mdpr->size;
+ header->streams[mdpr->stream_number]=mdpr;
+ }
break;
case CONT_TAG:
header->cont=rmff_scan_cont(ptr);
@@ -586,7 +652,7 @@ rmff_mdpr_t *rmff_new_mdpr(
mdpr->mime_type_size=strlen(mime_type);
}
mdpr->type_specific_len=type_specific_len;
- mdpr->type_specific_data = malloc(sizeof(char)*type_specific_len);
+ mdpr->type_specific_data = malloc(type_specific_len);
memcpy(mdpr->type_specific_data,type_specific_data,type_specific_len);
mdpr->mlti_data=NULL;
diff --git a/src/input/libreal/rmff.h b/src/input/libreal/rmff.h
index d39942088..50656349d 100644
--- a/src/input/libreal/rmff.h
+++ b/src/input/libreal/rmff.h
@@ -32,13 +32,19 @@
#include <string.h>
#include <inttypes.h>
-
#ifndef HAVE_RMFF_H
#define HAVE_RMFF_H
+#include "attributes.h"
#define RMFF_HEADER_SIZE 0x12
+#define RMFF_FILEHEADER_SIZE 18
+#define RMFF_PROPHEADER_SIZE 50
+#define RMFF_MDPRHEADER_SIZE 46
+#define RMFF_CONTHEADER_SIZE 18
+#define RMFF_DATAHEADER_SIZE 18
+
#define FOURCC_TAG( ch0, ch1, ch2, ch3 ) \
(((long)(unsigned char)(ch3) ) | \
( (long)(unsigned char)(ch2) << 8 ) | \
@@ -214,7 +220,7 @@ rmff_data_t *rmff_new_dataheader(
/*
* reads header infos from data and returns a newly allocated header struct
*/
-rmff_header_t *rmff_scan_header(const char *data);
+rmff_header_t *rmff_scan_header(const char *data) XINE_MALLOC;
/*
* scans a data packet header. Notice, that this function does not allocate
@@ -225,7 +231,7 @@ void rmff_scan_pheader(rmff_pheader_t *h, char *data);
/*
* reads header infos from stream and returns a newly allocated header struct
*/
-rmff_header_t *rmff_scan_header_stream(int fd);
+rmff_header_t *rmff_scan_header_stream(int fd) XINE_MALLOC;
/*
* prints header information in human readible form to stdout
@@ -245,7 +251,7 @@ int rmff_get_header_size(rmff_header_t *h);
/*
* dumps the header <h> to <buffer>. <max> is the size of <buffer>
*/
-int rmff_dump_header(rmff_header_t *h, char *buffer, int max);
+int rmff_dump_header(rmff_header_t *h, void *buf_gen, int max);
/*
* dumps a packet header
diff --git a/src/input/libreal/sdpplin.c b/src/input/libreal/sdpplin.c
index c62b6bbc1..a07cb3360 100644
--- a/src/input/libreal/sdpplin.c
+++ b/src/input/libreal/sdpplin.c
@@ -19,6 +19,10 @@
*
* sdp/sdpplin parser.
*/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
#define LOG_MODULE "sdpplin"
#define LOG_VERBOSE
@@ -60,7 +64,8 @@ static char *b64_decode(const char *in, char *out, int *size)
k=0;
/*CONSTANTCONDITION*/
- for (j=0; j<strlen(in); j+=4)
+ const size_t in_len = strlen(in);
+ for (j=0; j<in_len; j+=4)
{
char a[4], b[4];
@@ -99,7 +104,7 @@ static char *nl(char *data) {
static int filter(const char *in, const char *filter, char **out) {
- int flen=strlen(filter);
+ size_t flen=strlen(filter);
size_t len;
if (!in)
@@ -120,9 +125,9 @@ static int filter(const char *in, const char *filter, char **out) {
return 0;
}
-static sdpplin_stream_t *sdpplin_parse_stream(char **data) {
+static sdpplin_stream_t *XINE_MALLOC sdpplin_parse_stream(char **data) {
- sdpplin_stream_t *desc = xine_xmalloc(sizeof(sdpplin_stream_t));
+ sdpplin_stream_t *desc = calloc(1, sizeof(sdpplin_stream_t));
char *buf=xine_buffer_init(32);
char *decoded=xine_buffer_init(32);
int handled;
@@ -143,7 +148,14 @@ static sdpplin_stream_t *sdpplin_parse_stream(char **data) {
handled=0;
if(filter(*data,"a=control:streamid=",&buf)) {
- desc->stream_id=atoi(buf);
+ /* This way negative values are mapped to unfeasibly high
+ * values, and will be discarded afterward
+ */
+ unsigned long tmp = strtoul(buf, NULL, 10);
+ if ( tmp > UINT16_MAX )
+ lprintf("stream id out of bound: %lu\n", tmp);
+ else
+ desc->stream_id=tmp;
handled=1;
*data=nl(*data);
}
@@ -199,7 +211,7 @@ static sdpplin_stream_t *sdpplin_parse_stream(char **data) {
if(filter(*data,"a=OpaqueData:buffer;",&buf)) {
decoded = b64_decode(buf, decoded, &(desc->mlti_data_size));
if ( decoded != NULL ) {
- desc->mlti_data = malloc(sizeof(char)*desc->mlti_data_size);
+ desc->mlti_data = malloc(desc->mlti_data_size);
memcpy(desc->mlti_data, decoded, desc->mlti_data_size);
handled=1;
*data=nl(*data);
@@ -232,7 +244,7 @@ static sdpplin_stream_t *sdpplin_parse_stream(char **data) {
sdpplin_t *sdpplin_parse(char *data) {
- sdpplin_t *desc = xine_xmalloc(sizeof(sdpplin_t));
+ sdpplin_t *desc = calloc(1, sizeof(sdpplin_t));
sdpplin_stream_t *stream;
char *buf=xine_buffer_init(32);
char *decoded=xine_buffer_init(32);
@@ -252,7 +264,10 @@ sdpplin_t *sdpplin_parse(char *data) {
}
stream=sdpplin_parse_stream(&data);
lprintf("got data for stream id %u\n", stream->stream_id);
- desc->stream[stream->stream_id]=stream;
+ if ( stream->stream_id >= desc->stream_count )
+ lprintf("stream id %u is greater than stream count %u\n", stream->stream_id, desc->stream_count);
+ else
+ desc->stream[stream->stream_id]=stream;
continue;
}
@@ -293,8 +308,15 @@ sdpplin_t *sdpplin_parse(char *data) {
}
if(filter(data,"a=StreamCount:integer;",&buf)) {
- desc->stream_count=atoi(buf);
- desc->stream = malloc(sizeof(sdpplin_stream_t*)*desc->stream_count);
+ /* This way negative values are mapped to unfeasibly high
+ * values, and will be discarded afterward
+ */
+ unsigned long tmp = strtoul(buf, NULL, 10);
+ if ( tmp > UINT16_MAX )
+ lprintf("stream count out of bound: %lu\n", tmp);
+ else
+ desc->stream_count = tmp;
+ desc->stream = calloc(desc->stream_count, sizeof(sdpplin_stream_t*));
handled=1;
data=nl(data);
}
diff --git a/src/input/libreal/sdpplin.h b/src/input/libreal/sdpplin.h
index cb3b434d4..1604ee38c 100644
--- a/src/input/libreal/sdpplin.h
+++ b/src/input/libreal/sdpplin.h
@@ -37,7 +37,7 @@ typedef struct {
char *id;
char *bandwidth;
- int stream_id;
+ uint16_t stream_id;
char *range;
char *length;
char *rtpmap;
@@ -81,7 +81,7 @@ typedef struct {
int flags;
int is_real_data_type;
- int stream_count;
+ uint16_t stream_count;
char *title;
char *author;
char *copyright;
@@ -101,7 +101,7 @@ typedef struct {
} sdpplin_t;
-sdpplin_t *sdpplin_parse(char *data);
+sdpplin_t *sdpplin_parse(char *data) XINE_MALLOC;
void sdpplin_free(sdpplin_t *description);
diff --git a/src/input/librtsp/rtsp.c b/src/input/librtsp/rtsp.c
index 530ffc6cf..de4440b1c 100644
--- a/src/input/librtsp/rtsp.c
+++ b/src/input/librtsp/rtsp.c
@@ -21,6 +21,10 @@
* *not* RFC 2326 compilant yet.
*/
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
#include <unistd.h>
#include <stdio.h>
#include <assert.h>
@@ -123,7 +127,7 @@ static char *rtsp_get(rtsp_t *s) {
static void rtsp_put(rtsp_t *s, const char *string) {
- int len=strlen(string);
+ size_t len=strlen(string);
char *buf = malloc(sizeof(char)*len+2);
lprintf(">> '%s'", string);
@@ -173,9 +177,7 @@ static void rtsp_send_request(rtsp_t *s, const char *type, const char *what) {
char **payload=s->scheduled;
char *buf;
- buf = malloc(strlen(type)+strlen(what)+strlen(rtsp_protocol_version)+3);
-
- sprintf(buf,"%s %s %s",type, what, rtsp_protocol_version);
+ asprintf(&buf,"%s %s %s",type, what, rtsp_protocol_version);
rtsp_put(s,buf);
free(buf);
if (payload)
@@ -200,8 +202,7 @@ static void rtsp_schedule_standard(rtsp_t *s) {
if (s->session) {
char *buf;
- buf = malloc(strlen(s->session)+15);
- sprintf(buf, "Session: %s", s->session);
+ asprintf(&buf, "Session: %s", s->session);
rtsp_schedule_field(s, buf);
free(buf);
}
@@ -232,38 +233,32 @@ static int rtsp_get_answers(rtsp_t *s) {
if (!answer)
return 0;
- if (!strncasecmp(answer,"Cseq:",5)) {
- sscanf(answer,"%*s %u",&answer_seq);
+ if (!strncasecmp(answer,"Cseq: ",6)) {
+ sscanf(answer+6,"%u",&answer_seq);
if (s->cseq != answer_seq) {
lprintf("warning: Cseq mismatch. got %u, assumed %u", answer_seq, s->cseq);
s->cseq=answer_seq;
}
}
- if (!strncasecmp(answer,"Server:",7)) {
- char *buf = xine_xmalloc(strlen(answer));
- sscanf(answer,"%*s %s",buf);
- if (s->server) free(s->server);
- s->server=strdup(buf);
- free(buf);
+ if (!strncasecmp(answer,"Server: ",8)) {
+ free(s->server);
+ s->server = strdup(answer + 8);
}
- if (!strncasecmp(answer,"Session:",8)) {
- char *buf = xine_xmalloc(strlen(answer));
- sscanf(answer,"%*s %s",buf);
+ if (!strncasecmp(answer,"Session: ",9)) {
+ char *tmp = answer + 9;
if (s->session) {
- if (strcmp(buf, s->session)) {
+ if (strcmp(tmp, s->session)) {
xprintf(s->stream->xine, XINE_VERBOSITY_DEBUG,
- "rtsp: warning: setting NEW session: %s\n", buf);
- free(s->session);
- s->session=strdup(buf);
+ "rtsp: warning: setting NEW session: %s\n", tmp);
+ s->session=strdup(tmp);
}
} else
{
lprintf("setting session id to: %s\n", buf);
- s->session=strdup(buf);
+ s->session=strdup(tmp);
}
- free(buf);
}
*answer_ptr=answer;
answer_ptr++;
@@ -304,8 +299,7 @@ int rtsp_request_options(rtsp_t *s, const char *what) {
buf=strdup(what);
} else
{
- buf = malloc(sizeof(char)*(strlen(s->host)+16));
- sprintf(buf,"rtsp://%s:%i", s->host, s->port);
+ asprintf(&buf,"rtsp://%s:%i", s->host, s->port);
}
rtsp_send_request(s,"OPTIONS",buf);
free(buf);
@@ -321,8 +315,7 @@ int rtsp_request_describe(rtsp_t *s, const char *what) {
buf=strdup(what);
} else
{
- buf = malloc(sizeof(char)*(strlen(s->host)+strlen(s->path)+16));
- sprintf(buf,"rtsp://%s:%i/%s", s->host, s->port, s->path);
+ asprintf(&buf,"rtsp://%s:%i/%s", s->host, s->port, s->path);
}
rtsp_send_request(s,"DESCRIBE",buf);
free(buf);
@@ -345,8 +338,7 @@ int rtsp_request_setparameter(rtsp_t *s, const char *what) {
buf=strdup(what);
} else
{
- buf = malloc(sizeof(char)*(strlen(s->host)+strlen(s->path)+16));
- sprintf(buf,"rtsp://%s:%i/%s", s->host, s->port, s->path);
+ asprintf(&buf,"rtsp://%s:%i/%s", s->host, s->port, s->path);
}
rtsp_send_request(s,"SET_PARAMETER",buf);
free(buf);
@@ -362,8 +354,7 @@ int rtsp_request_play(rtsp_t *s, const char *what) {
buf=strdup(what);
} else
{
- buf = malloc(sizeof(char)*(strlen(s->host)+strlen(s->path)+16));
- sprintf(buf,"rtsp://%s:%i/%s", s->host, s->port, s->path);
+ asprintf(&buf,"rtsp://%s:%i/%s", s->host, s->port, s->path);
}
rtsp_send_request(s,"PLAY",buf);
free(buf);
@@ -412,8 +403,7 @@ int rtsp_read_data(rtsp_t *s, char *buffer, unsigned int size) {
}
/* lets make the server happy */
rtsp_put(s, "RTSP/1.0 451 Parameter Not Understood");
- rest = malloc(sizeof(char)*17);
- sprintf(rest,"CSeq: %u", seq);
+ asprintf(&rest,"CSeq: %u", seq);
rtsp_put(s, rest);
free(rest);
rtsp_put(s, "");
@@ -486,9 +476,7 @@ rtsp_t *rtsp_connect(xine_stream_t *stream, const char *mrl, const char *user_ag
pathbegin=slash-mrl_ptr;
hostend=colon-mrl_ptr;
- s->host = malloc(sizeof(char)*hostend+1);
- strncpy(s->host, mrl_ptr, hostend);
- s->host[hostend]=0;
+ s->host = strndup(mrl_ptr, hostend);
if (pathbegin < strlen(mrl_ptr)) s->path=strdup(mrl_ptr+pathbegin+1);
if (colon != slash) {
diff --git a/src/input/librtsp/rtsp.h b/src/input/librtsp/rtsp.h
index dc2624459..2e1fd6aa0 100644
--- a/src/input/librtsp/rtsp.h
+++ b/src/input/librtsp/rtsp.h
@@ -40,7 +40,7 @@
typedef struct rtsp_s rtsp_t;
-rtsp_t* rtsp_connect (xine_stream_t *stream, const char *mrl, const char *user_agent);
+rtsp_t* rtsp_connect (xine_stream_t *stream, const char *mrl, const char *user_agent) XINE_MALLOC;
int rtsp_request_options(rtsp_t *s, const char *what);
int rtsp_request_describe(rtsp_t *s, const char *what);
diff --git a/src/input/librtsp/rtsp_session.c b/src/input/librtsp/rtsp_session.c
index f3ddb59bc..88103aa7d 100644
--- a/src/input/librtsp/rtsp_session.c
+++ b/src/input/librtsp/rtsp_session.c
@@ -20,6 +20,10 @@
* high level interface to rtsp servers.
*/
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
@@ -78,7 +82,7 @@ const char *rtsp_bandwidth_strs[]={"14.4 Kbps (Modem)", "19.2 Kbps (Modem)",
rtsp_session_t *rtsp_session_start(xine_stream_t *stream, char *mrl) {
- rtsp_session_t *rtsp_session = xine_xmalloc(sizeof(rtsp_session_t));
+ rtsp_session_t *rtsp_session = calloc(1, sizeof(rtsp_session_t));
xine_t *xine = stream->xine;
char *server;
char *mrl_line=strdup(mrl);
@@ -148,6 +152,11 @@ connect:
rtsp_session->header_left =
rtsp_session->header_len = rmff_dump_header(h,rtsp_session->header,HEADER_SIZE);
+ if (rtsp_session->header_len < 0) {
+ xprintf (stream->xine, XINE_VERBOSITY_LOG,
+ _("rtsp_session: rtsp server returned overly-large headers, session can not be established.\n"));
+ goto session_abort;
+ }
xine_buffer_copyin(rtsp_session->recv, 0, rtsp_session->header, rtsp_session->header_len);
rtsp_session->recv_size = rtsp_session->header_len;
@@ -157,6 +166,7 @@ connect:
{
xprintf(stream->xine, XINE_VERBOSITY_LOG,
_("rtsp_session: rtsp server type '%s' not supported yet. sorry.\n"), server);
+ session_abort:
rtsp_close(rtsp_session->s);
free(server);
xine_buffer_free(rtsp_session->recv);
diff --git a/src/input/librtsp/rtsp_session.h b/src/input/librtsp/rtsp_session.h
index b47db0730..33ac579e1 100644
--- a/src/input/librtsp/rtsp_session.h
+++ b/src/input/librtsp/rtsp_session.h
@@ -25,7 +25,7 @@
typedef struct rtsp_session_s rtsp_session_t;
-rtsp_session_t *rtsp_session_start(xine_stream_t *stream, char *mrl);
+rtsp_session_t *rtsp_session_start(xine_stream_t *stream, char *mrl) XINE_MALLOC;
void rtsp_session_set_start_time(rtsp_session_t *this, int start_time);
diff --git a/src/input/mms.c b/src/input/mms.c
index f11a89cf3..b2d00a46e 100644
--- a/src/input/mms.c
+++ b/src/input/mms.c
@@ -202,9 +202,9 @@ static void mms_buffer_put_64 (mms_buffer_t *mms_buffer, uint64_t value) {
}
+#ifdef LOG
static void print_command (char *data, int len) {
-#ifdef LOG
int i;
int dir = _X_LE_32 (data + 36) >> 16;
int comm = _X_LE_32 (data + 36) & 0xFFFF;
@@ -240,8 +240,10 @@ static void print_command (char *data, int len) {
if (len > CMD_HEADER_LEN)
printf ("\n");
printf ("----------------------------------------------\n");
+}
+#else
+# define print_command(data, len)
#endif
-}
@@ -288,7 +290,7 @@ static int send_command (mms_t *this, int command,
#ifdef USE_ICONV
static iconv_t string_utf16_open() {
- return iconv_open("UTF-16LE", nl_langinfo(CODESET));
+ return iconv_open("UTF-16LE", "UTF-8");
}
static void string_utf16_close(iconv_t url_conv) {
@@ -678,7 +680,7 @@ mms_t *mms_connect (xine_stream_t *stream, const char *url, int bandwidth) {
if (!url)
return NULL;
- this = (mms_t*) xine_xmalloc (sizeof (mms_t));
+ this = calloc(1, sizeof (mms_t));
this->stream = stream;
this->url = strdup (url);
@@ -769,12 +771,17 @@ mms_t *mms_connect (xine_stream_t *stream, const char *url, int bandwidth) {
/* command 0x5 */
{
mms_buffer_t command_buffer;
- char *path;
- int pathlen;
+ char *path, *unescaped;
+ size_t pathlen;
+
+ unescaped = strdup (this->uri);
+ if (!unescaped)
+ goto fail;
+ _x_mrl_unescape (unescaped);
/* remove the first '/' */
- path = this->uri;
- pathlen = strlen(path);
+ path = unescaped;
+ pathlen = strlen (path);
if (pathlen > 1) {
path++;
pathlen--;
@@ -785,6 +792,7 @@ mms_t *mms_connect (xine_stream_t *stream, const char *url, int bandwidth) {
mms_buffer_put_32 (&command_buffer, 0x00000000); /* ?? */
mms_buffer_put_32 (&command_buffer, 0x00000000); /* ?? */
string_utf16 (url_conv, this->scmd_body + command_buffer.pos, path, pathlen);
+ free (unescaped);
if (!send_command (this, 5, 1, 0xffffffff, pathlen * 2 + 12))
goto fail;
}
diff --git a/src/input/mmsh.c b/src/input/mmsh.c
index ae1c62bc1..4ee7ed07d 100644
--- a/src/input/mmsh.c
+++ b/src/input/mmsh.c
@@ -190,11 +190,9 @@ struct mmsh_s {
};
static int send_command (mmsh_t *this, char *cmd) {
- int length;
-
lprintf ("send_command:\n%s\n", cmd);
- length = strlen(cmd);
+ const size_t length = strlen(cmd);
if (_x_io_tcp_write(this->stream, this->s, cmd, length) != length) {
xprintf (this->stream->xine, XINE_LOG_MSG, _("libmmsh: send error\n"));
return 0;
@@ -636,7 +634,7 @@ mmsh_t *mmsh_connect (xine_stream_t *stream, const char *url, int bandwidth) {
report_progress (stream, 0);
- this = (mmsh_t*) xine_xmalloc (sizeof (mmsh_t));
+ this = calloc(1, sizeof (mmsh_t));
this->stream = stream;
this->url = strdup(url);
diff --git a/src/input/net_buf_ctrl.c b/src/input/net_buf_ctrl.c
index 624af4081..e27ed99f3 100644
--- a/src/input/net_buf_ctrl.c
+++ b/src/input/net_buf_ctrl.c
@@ -118,8 +118,8 @@ void nbc_check_buffers (nbc_t *this) {
}
static void display_stats (nbc_t *this) {
- const char *buffering[2] = {" ", "buf"};
- const char *enabled[2] = {"off", "on "};
+ const char buffering[2][4] = {" ", "buf"};
+ const char enabled[2][4] = {"off", "on "};
printf("bufing: %d, enb: %d\n", this->buffering, this->enabled);
printf("net_buf_ctrl: vid %3d%% %4.1fs %4" PRId64 "kbps %1d, "\
@@ -496,7 +496,7 @@ static void nbc_get_cb (fifo_buffer_t *fifo,
nbc_t *nbc_init (xine_stream_t *stream) {
- nbc_t *this = (nbc_t *) xine_xmalloc (sizeof (nbc_t));
+ nbc_t *this = calloc(1, sizeof (nbc_t));
fifo_buffer_t *video_fifo = stream->video_fifo;
fifo_buffer_t *audio_fifo = stream->audio_fifo;
double video_fifo_factor, audio_fifo_factor;
diff --git a/src/input/net_buf_ctrl.h b/src/input/net_buf_ctrl.h
index 79f698008..7dfb7b0d1 100644
--- a/src/input/net_buf_ctrl.h
+++ b/src/input/net_buf_ctrl.h
@@ -27,14 +27,14 @@
typedef struct nbc_s nbc_t;
-nbc_t *nbc_init (xine_stream_t *xine);
+nbc_t *nbc_init (xine_stream_t *xine) XINE_MALLOC;
-void nbc_check_buffers (nbc_t *this);
+void nbc_check_buffers (nbc_t *this) XINE_DEPRECATED;
void nbc_close (nbc_t *this);
-void nbc_set_high_water_mark(nbc_t *this, int value);
+void nbc_set_high_water_mark(nbc_t *this, int value) XINE_DEPRECATED;
-void nbc_set_low_water_mark(nbc_t *this, int value);
+void nbc_set_low_water_mark(nbc_t *this, int value) XINE_DEPRECATED;
#endif
diff --git a/src/input/pnm.c b/src/input/pnm.c
index 38d65b850..aabdbde96 100644
--- a/src/input/pnm.c
+++ b/src/input/pnm.c
@@ -21,6 +21,10 @@
* based upon code from joschka
*/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
#include <unistd.h>
#include <stdio.h>
#include <sys/socket.h>
@@ -90,7 +94,7 @@ struct pnm_s {
/* header of rm files */
#define RM_HEADER_SIZE 0x12
-const unsigned char rm_header[]={
+static const unsigned char rm_header[]={
0x2e, 0x52, 0x4d, 0x46, /* object_id ".RMF" */
0x00, 0x00, 0x00, 0x12, /* header_size 0x12 */
0x00, 0x00, /* object_version 0x00 */
@@ -100,7 +104,7 @@ const unsigned char rm_header[]={
/* data chunk header */
#define PNM_DATA_HEADER_SIZE 18
-const unsigned char pnm_data_header[]={
+static const unsigned char pnm_data_header[]={
'D','A','T','A',
0,0,0,0, /* data chunk size */
0,0, /* object version */
@@ -411,8 +415,8 @@ static void pnm_send_request(pnm_t *p, uint32_t bandwidth) {
*/
static void pnm_send_response(pnm_t *p, const char *response) {
-
- int size=strlen(response);
+ /** @TODO should check that sze is always < 256 */
+ size_t size=strlen(response);
p->buffer[0]=0x23;
p->buffer[1]=0;
@@ -627,10 +631,7 @@ static int pnm_get_stream_chunk(pnm_t *p) {
*/
n=0;
while (p->buffer[0] != 0x5a) {
- int i;
- for (i=1; i<8; i++) {
- p->buffer[i-1]=p->buffer[i];
- }
+ memmove(p->buffer, &p->buffer[1], 8);
_x_io_tcp_read (p->stream, p->s, &p->buffer[7], 1);
n++;
}
@@ -716,7 +717,7 @@ pnm_t *pnm_connect(xine_stream_t *stream, const char *mrl) {
mrl_ptr+=6;
- p = xine_xmalloc(sizeof(pnm_t));
+ p = calloc(1, sizeof(pnm_t));
p->stream = stream;
p->port=7070;
p->url=strdup(mrl);
@@ -732,9 +733,7 @@ pnm_t *pnm_connect(xine_stream_t *stream, const char *mrl) {
pathbegin=slash-mrl_ptr;
hostend=colon-mrl_ptr;
- p->host = malloc(sizeof(char)*hostend+1);
- strncpy(p->host, mrl_ptr, hostend);
- p->host[hostend]=0;
+ p->host = strndup(mrl_ptr, hostend);
if (pathbegin < strlen(mrl_ptr)) p->path=strdup(mrl_ptr+pathbegin+1);
if (colon != slash) {
diff --git a/src/input/vcd/Makefile.am b/src/input/vcd/Makefile.am
index 31ec6a44c..61eac753b 100644
--- a/src/input/vcd/Makefile.am
+++ b/src/input/vcd/Makefile.am
@@ -1,3 +1,4 @@
+include $(top_builddir)/misc/Makefile.plugins
include $(top_srcdir)/misc/Makefile.common
SUBDIRS = libcdio libvcd
diff --git a/src/input/vcd/libcdio/FreeBSD/freebsd.c b/src/input/vcd/libcdio/FreeBSD/freebsd.c
index 5a3443e95..bcfe674a5 100644
--- a/src/input/vcd/libcdio/FreeBSD/freebsd.c
+++ b/src/input/vcd/libcdio/FreeBSD/freebsd.c
@@ -29,11 +29,11 @@
static const char _rcsid[] = "$Id: freebsd.c,v 1.1 2005/01/01 02:43:57 rockyb Exp $";
-#include <arpa/inet.h>
#include "freebsd.h"
#ifdef HAVE_FREEBSD_CDROM
+#include <arpa/inet.h>
#include <cdio/sector.h>
static access_mode_t
diff --git a/src/input/vcd/libcdio/MSWindows/aspi32.c b/src/input/vcd/libcdio/MSWindows/aspi32.c
index 238a4b4e9..e62f8a089 100644
--- a/src/input/vcd/libcdio/MSWindows/aspi32.c
+++ b/src/input/vcd/libcdio/MSWindows/aspi32.c
@@ -162,9 +162,9 @@ have_aspi( HMODULE *hASPI,
return false;
}
- (FARPROC) *lpGetSupport = GetProcAddress( *hASPI,
+ *lpGetSupport = (FARPROC)GetProcAddress( *hASPI,
"GetASPI32SupportInfo" );
- (FARPROC) *lpSendCommand = GetProcAddress( *hASPI,
+ *lpSendCommand = (FARPROC)GetProcAddress( *hASPI,
"SendASPI32Command" );
/* make sure that we've got both function addresses */
diff --git a/src/input/vcd/xine-extra.c b/src/input/vcd/xine-extra.c
index 79c962a79..e3b6da912 100644
--- a/src/input/vcd/xine-extra.c
+++ b/src/input/vcd/xine-extra.c
@@ -45,8 +45,10 @@ static xine_t *my_xine = NULL;
void
xine_vlog_msg(xine_t *this, int buf, const char *format, va_list args)
{
+ va_list copy;
+ va_copy (copy, args);
xine_vlog(this, buf, format, args);
- vfprintf(stdout, format, args);
+ vfprintf(stdout, format, copy);
}
/*! This routine is like xine_log, except it takes a va_list instead
@@ -59,8 +61,10 @@ xine_vlog_msg(xine_t *this, int buf, const char *format, va_list args)
void
xine_vlog_err(xine_t *this, int buf, const char *format, va_list args)
{
+ va_list copy;
+ va_copy (copy, args);
xine_vlog(this, buf, format, args);
- vfprintf(stderr, format, args);
+ vfprintf(stderr, format, copy);
}
/*! Call this before calling any of the xine_log_msg or xine_log_err
@@ -116,8 +120,8 @@ xine_log_err(const char *format, ...)
{
va_list args;
- va_start(args, format);
if (NULL == my_xine) return false;
+ va_start(args, format);
xine_vlog_err(my_xine, XINE_LOG_MSG, format, args);
va_end(args);
return true;
diff --git a/src/input/vcd/xineplug_inp_vcd.c b/src/input/vcd/xineplug_inp_vcd.c
index 2e52ccc0f..50382ee7e 100644
--- a/src/input/vcd/xineplug_inp_vcd.c
+++ b/src/input/vcd/xineplug_inp_vcd.c
@@ -20,7 +20,7 @@
/*
These are plugin routines called by the xine engine. See
Chapter 4. Extending xine's input
- http://xinehq.de/index.php/hackersguide/index.php?resource=5.3&action=default#INPUT
+ http://www.xine-project.org/hackersguide#INPUT
and the comments in input_plugin.h
This is what is referred to below a "the xine plugin spec"
@@ -272,11 +272,9 @@ vcd_add_mrl_slot(vcd_input_class_t *this, const char *mrl, off_t size,
this->mrls[*i]->type = mrl_vcd;
this->mrls[*i]->size = size * M2F2_SECTOR_SIZE;
- this->mrls[*i]->mrl = (char *) malloc(strlen(mrl) + 1);
+ this->mrls[*i]->mrl = strdup(mrl);
if (NULL==this->mrls[*i]->mrl) {
LOG_ERR("Can't malloc %zu bytes for MRL name %s", sizeof(xine_mrl_t), mrl);
- } else {
- sprintf(this->mrls[*i]->mrl, "%s", mrl);
}
(*i)++;
}
@@ -968,7 +966,7 @@ vcd_class_eject_media (input_class_t *this_gen)
* From spec:
* return current MRL
*/
-static char *
+static const char *
vcd_plugin_get_mrl (input_plugin_t *this_gen)
{
vcd_input_plugin_t *t = (vcd_input_plugin_t *) this_gen;
@@ -989,7 +987,7 @@ vcd_plugin_get_mrl (input_plugin_t *this_gen)
/* Bad type. */
LOG_ERR("%s %d", _("Invalid current entry type"),
vcdplayer->play_item.type);
- return strdup("");
+ return "";
} else {
n += offset;
if (n < t->class->num_mrls) {
@@ -997,7 +995,7 @@ vcd_plugin_get_mrl (input_plugin_t *this_gen)
t->class->mrls[n]->mrl);
return t->class->mrls[n]->mrl;
} else {
- return strdup("");
+ return "";
}
}
}
@@ -1007,7 +1005,7 @@ vcd_plugin_get_mrl (input_plugin_t *this_gen)
return human readable (verbose = 1 line) description for this plugin
*/
-static char *
+static const char *
vcd_class_get_description (input_class_t *this_gen)
{
dbg_print((INPUT_DBG_CALL|INPUT_DBG_EXT), "called\n");
@@ -1767,7 +1765,7 @@ vcd_init (xine_t *xine, void *data)
dbg_print(INPUT_DBG_CALL, "Called\n");
- class = (vcd_input_class_t *) xine_xmalloc (sizeof (vcd_input_class_t));
+ class = calloc(1, sizeof (vcd_input_class_t));
class->xine = xine;
class->config = config = xine->config;