[xiph-cvs] cvs commit: icecast/src client.h connection.c format.c format.h format_mp3.c format_vorbis.c main.c source.c
Michael Smith
msmith at xiph.org
Sun Dec 29 00:10:11 PST 2002
msmith 02/12/29 03:10:11
Modified: src client.h connection.c format.c format.h
format_mp3.c format_vorbis.c main.c source.c
Log:
Add infrastructure for better/more flexible format support. Will be needed
for mp3 metadata, for example.
Revision Changes Path
1.4 +3 -0 icecast/src/client.h
Index: client.h
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/client.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- client.h 16 Aug 2002 14:26:47 -0000 1.3
+++ client.h 29 Dec 2002 08:10:10 -0000 1.4
@@ -20,6 +20,9 @@
refbuf_queue_t *queue;
/* position in first buffer */
unsigned long pos;
+
+ /* Format-handler-specific data for this client */
+ void *format_data;
} client_t;
client_t *client_create(connection_t *con, http_parser_t *parser);
<p><p>1.31 +1 -1 icecast/src/connection.c
Index: connection.c
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/connection.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- connection.c 22 Nov 2002 13:00:44 -0000 1.30
+++ connection.c 29 Dec 2002 08:10:10 -0000 1.31
@@ -122,7 +122,7 @@
return NULL;
}
- /* malloc enough room for 123.123.123.123\0 */
+ /* malloc enough room for 123.123.123.123\0 (TODO: ipv6?)*/
ip = (char *)malloc(16);
sock = sock_accept(global.serversock, ip, 16);
<p><p>1.8 +23 -0 icecast/src/format.c
Index: format.c
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/format.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- format.c 24 Jul 2002 13:55:12 -0000 1.7
+++ format.c 29 Dec 2002 08:10:10 -0000 1.8
@@ -16,6 +16,9 @@
#include "format_vorbis.h"
#include "format_mp3.h"
+#include "logging.h"
+#define CATMODULE "format"
+
format_type_t format_get_type(char *contenttype)
{
if(strcmp(contenttype, "application/x-ogg") == 0)
@@ -60,3 +63,23 @@
return plugin;
}
+
+int format_generic_write_buf_to_client(format_plugin_t *format,
+ client_t *client, unsigned char *buf, int len)
+{
+ int ret;
+
+ ret = sock_write_bytes(client->con->sock, buf, len);
+
+ if(ret < 0) {
+ if(sock_recoverable(ret)) {
+ DEBUG1("Client had recoverable error %ld", ret);
+ ret = 0;
+ }
+ }
+ else
+ client->con->sent_bytes += ret;
+
+ return ret;
+}
+
<p><p>1.8 +10 -0 icecast/src/format.h
Index: format.h
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/format.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- format.h 10 Aug 2002 08:01:56 -0000 1.7
+++ format.h 29 Dec 2002 08:10:10 -0000 1.8
@@ -6,6 +6,9 @@
#ifndef __FORMAT_H__
#define __FORMAT_H__
+#include "client.h"
+#include "refbuf.h"
+
typedef enum _format_type_tag
{
FORMAT_TYPE_VORBIS,
@@ -29,6 +32,10 @@
int (*get_buffer)(struct _format_plugin_tag *self, char *data, unsigned long
len, refbuf_t **buffer);
refbuf_queue_t *(*get_predata)(struct _format_plugin_tag *self);
+ int (*write_buf_to_client)(struct _format_plugin_tag *format,
+ client_t *client, unsigned char *buf, int len);
+ void *(*create_client_data)(struct _format_plugin_tag *format);
+
void (*free_plugin)(struct _format_plugin_tag *self);
/* for internal state management */
@@ -38,6 +45,9 @@
format_type_t format_get_type(char *contenttype);
char *format_get_mimetype(format_type_t type);
format_plugin_t *format_get_plugin(format_type_t type, char *mount);
+
+int format_generic_write_buf_to_client(format_plugin_t *format,
+ client_t *client, unsigned char *buf, int len);
#endif /* __FORMAT_H__ */
<p><p>1.3 +10 -3 icecast/src/format_mp3.c
Index: format_mp3.c
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/format_mp3.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- format_mp3.c 10 Aug 2002 08:01:56 -0000 1.2
+++ format_mp3.c 29 Dec 2002 08:10:10 -0000 1.3
@@ -13,9 +13,11 @@
#include "stats.h"
#include "format.h"
-void format_mp3_free_plugin(format_plugin_t *self);
-int format_mp3_get_buffer(format_plugin_t *self, char *data, unsigned long len, refbuf_t **buffer);
-refbuf_queue_t *format_mp3_get_predata(format_plugin_t *self);
+static void format_mp3_free_plugin(format_plugin_t *self);
+static int format_mp3_get_buffer(format_plugin_t *self, char *data,
+ unsigned long len, refbuf_t **buffer);
+static refbuf_queue_t *format_mp3_get_predata(format_plugin_t *self);
+static void *format_mp3_create_client_data(format_plugin_t *self);
format_plugin_t *format_mp3_get_plugin(void)
{
@@ -27,6 +29,8 @@
plugin->has_predata = 0;
plugin->get_buffer = format_mp3_get_buffer;
plugin->get_predata = format_mp3_get_predata;
+ plugin->write_buf_to_client = format_generic_write_buf_to_client;
+ plugin->create_client_data = format_mp3_create_client_data;
plugin->free_plugin = format_mp3_free_plugin;
plugin->format_description = "MP3 audio";
@@ -61,5 +65,8 @@
return NULL;
}
+static void *format_mp3_create_client_data(format_plugin_t *self) {
+ return NULL;
+}
<p><p>1.10 +10 -3 icecast/src/format_vorbis.c
Index: format_vorbis.c
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/format_vorbis.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- format_vorbis.c 10 Aug 2002 08:01:56 -0000 1.9
+++ format_vorbis.c 29 Dec 2002 08:10:10 -0000 1.10
@@ -36,9 +36,11 @@
int packets;
} vstate_t;
-void format_vorbis_free_plugin(format_plugin_t *self);
-int format_vorbis_get_buffer(format_plugin_t *self, char *data, unsigned long len, refbuf_t **buffer);
-refbuf_queue_t *format_vorbis_get_predata(format_plugin_t *self);
+static void format_vorbis_free_plugin(format_plugin_t *self);
+static int format_vorbis_get_buffer(format_plugin_t *self, char *data,
+ unsigned long len, refbuf_t **buffer);
+static refbuf_queue_t *format_vorbis_get_predata(format_plugin_t *self);
+static void *format_vorbis_create_client_data(format_plugin_t *self);
format_plugin_t *format_vorbis_get_plugin(void)
{
@@ -51,6 +53,8 @@
plugin->has_predata = 1;
plugin->get_buffer = format_vorbis_get_buffer;
plugin->get_predata = format_vorbis_get_predata;
+ plugin->write_buf_to_client = format_generic_write_buf_to_client;
+ plugin->create_client_data = format_vorbis_create_client_data;
plugin->free_plugin = format_vorbis_free_plugin;
plugin->format_description = "Ogg Vorbis";
@@ -214,5 +218,8 @@
return queue;
}
+static void *format_vorbis_create_client_data(format_plugin_t *self) {
+ return NULL;
+}
<p><p>1.19 +4 -3 icecast/src/main.c
Index: main.c
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/main.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- main.c 25 Aug 2002 06:12:51 -0000 1.18
+++ main.c 29 Dec 2002 08:10:10 -0000 1.19
@@ -91,7 +91,8 @@
while (i < argc) {
if (strcmp(argv[i], "-c") == 0) {
if (i + 1 < argc) {
- strncpy(filename, argv[i + 1], size);
+ strncpy(filename, argv[i + 1], size-1);
+ filename[size-1] = 0;
return 1;
} else {
return -1;
@@ -262,12 +263,12 @@
int main(int argc, char **argv)
{
int res, ret;
- char filename[256];
+ char filename[512];
/* parse the '-c icecast.xml' option
** only, so that we can read a configfile
*/
- res = _parse_config_file(argc, argv, filename, 256);
+ res = _parse_config_file(argc, argv, filename, 512);
if (res == 1) {
/* startup all the modules */
_initialize_subsystems();
<p><p>1.24 +12 -25 icecast/src/source.c
Index: source.c
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/source.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- source.c 6 Oct 2002 09:57:07 -0000 1.23
+++ source.c 29 Dec 2002 08:10:10 -0000 1.24
@@ -219,9 +219,9 @@
else
bytes = abuf->len;
- sbytes = sock_write_bytes(client->con->sock, &abuf->data[client->pos], bytes);
+ sbytes = source->format->write_buf_to_client(source->format,
+ client, &abuf->data[client->pos], bytes);
if (sbytes >= 0) {
- client->con->sent_bytes += sbytes;
if(sbytes != bytes) {
/* We didn't send the entire buffer. Leave it for
* the moment, handle it in the next iteration.
@@ -232,16 +232,9 @@
break;
}
}
- if (sbytes < 0) {
- if (!sock_recoverable(sock_error())) {
- DEBUG0("Client has unrecoverable error catching up. Client has probably disconnected");
- client->con->error = 1;
- } else {
- DEBUG1("Client had recoverable error %ld", sock_error());
- /* put the refbuf back on top of the queue, since we didn't finish with it */
- refbuf_queue_insert(&client->queue, abuf);
- }
-
+ else {
+ DEBUG0("Client has unrecoverable error catching up. Client has probably disconnected");
+ client->con->error = 1;
data_done = 1;
break;
}
@@ -258,9 +251,9 @@
refbuf_addref(refbuf);
refbuf_queue_add(&client->queue, refbuf);
} else {
- sbytes = sock_write_bytes(client->con->sock, refbuf->data, refbuf->len);
+ sbytes = source->format->write_buf_to_client(source->format,
+ client, refbuf->data, refbuf->len);
if (sbytes >= 0) {
- client->con->sent_bytes += sbytes;
if(sbytes != refbuf->len) {
/* Didn't send the entire buffer, queue it */
client->pos = sbytes;
@@ -268,17 +261,9 @@
refbuf_queue_insert(&client->queue, refbuf);
}
}
- if (sbytes < 0) {
- bytes = sock_error();
- if (!sock_recoverable(bytes)) {
- DEBUG0("Client had unrecoverable error with new data, probably due to client disconnection");
- client->con->error = 1;
- } else {
- DEBUG1("Client had recoverable error %ld", bytes);
- client->pos = 0;
- refbuf_addref(refbuf);
- refbuf_queue_insert(&client->queue, refbuf);
- }
+ else {
+ DEBUG0("Client had unrecoverable error with new data, probably due to client disconnection");
+ client->con->error = 1;
}
}
@@ -340,6 +325,8 @@
*/
if (source->format->has_predata) {
client = (client_t *)client_node->key;
+ client->format_data = source->format->create_client_data(
+ source->format);
client->queue = source->format->get_predata(source->format);
}
<p><p>--- >8 ----
List archives: http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body. No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.
More information about the commits
mailing list