From db34194eaab9819772bd55ea1ab08c719ed8f1c8 Mon Sep 17 00:00:00 2001 From: Andre Date: Sat, 13 May 2006 22:46:34 +0200 Subject: [PATCH] Rename struct audio format to audio_format_handler --- aac_afh.c | 2 +- afs.c | 8 +-- afs.h | 160 ++++++++++++++++++++++++---------------------------- command.c | 2 +- dccp_send.c | 10 ++-- http_send.c | 8 +-- mp3.c | 2 +- ogg.c | 2 +- ortp_send.c | 7 ++- send.h | 6 +- server.c | 2 +- 11 files changed, 98 insertions(+), 111 deletions(-) diff --git a/aac_afh.c b/aac_afh.c index 5ace47e5..d6f37fcb 100644 --- a/aac_afh.c +++ b/aac_afh.c @@ -37,7 +37,7 @@ static FILE *infile; static int inbuf_size; static unsigned char *inbuf; static size_t inbuf_len; -struct audio_format *af; +struct audio_format_handler *af; static size_t num_chunks; static size_t entry; diff --git a/afs.c b/afs.c index 29bae161..8e0a50aa 100644 --- a/afs.c +++ b/afs.c @@ -58,7 +58,7 @@ static FILE *audio_file = NULL; /** * the list of supported audio formats */ -struct audio_format afl[] = { +struct audio_format_handler afl[] = { #if 1 { .name = "mp3", @@ -336,7 +336,7 @@ static struct timeval *afs_compute_timeout(void) return &the_timeout; } -static void afs_eof(struct audio_format *af) +static void afs_eof(struct audio_format_handler *af) { struct timeval now; int i; @@ -388,7 +388,7 @@ static void afs_eof(struct audio_format *af) */ struct timeval *afs_preselect(void) { - struct audio_format *af = NULL; + struct audio_format_handler *af = NULL; int i, format; struct timeval *ret; again: @@ -449,7 +449,7 @@ again: void afs_send_chunk(void) { int i; - struct audio_format *af; + struct audio_format_handler *af; char *buf; ssize_t ret; struct timeval now, due; diff --git a/afs.h b/afs.h index cc96dbbb..19d5b685 100644 --- a/afs.h +++ b/afs.h @@ -55,93 +55,79 @@ * para_server calls the \a init function of each audio format handler which is * expected to fill in all the other function pointers. */ -struct audio_format { -/** - * - * - * name of the audio format - */ -const char *name; -/** - * - * - * pointer to the audio format handler's init function - * - * Must initialize all function pointers and is assumed to succeed. - */ -void (*init)(void*); -/** - * - * - * period of time between sending data chunks -*/ -struct timeval chunk_tv; /* length of one chunk of data */ -/** - * - * - * end of file timeout - do not load new audio file until this time - * -*/ -struct timeval eof_tv; /* timeout on eof */ -/** - * - * - * Pointer to the optional get-header function. - * - * This is called from a sender in case a new client connects in the middle of - * the stream. The audio format handler may set this to NULL to indicate that - * this audio format does not need any special header treatment. If non-NULL, - * the function it points to must return a pointer to a buffer holding the - * current audio file header, together with the header length. -*/ -char *(*get_header_info)(int *header_len); -/** - * - * - * check if this audio format handler can handle the file - * - * This is a pointer to a function returning whether a given file is valid for - * this audio format. A negative return value indicates that this audio format - * handler did not recognize the given file. On success, the function is - * expected to return a positive value and to fill in \arg info_str, \arg - * chunks and \arg seconds appropriately. -*/ -int (*get_file_info)(FILE *audio_file, char *info_str, - long unsigned *chunks, int *seconds); -/** - * - * - * cleanup function of this audio format handler - * - * This close function should deallocate any resources - * associated with the current audio file. In particular, it is responsible - * for closing the file handle. It is assumed to succeed. -*/ -void (*close_audio_file)(void); -/** - * - * - * jump to another position in the current audio file - * - * This is called if a client issued the ff or jmp command with \a request - * being the number of the next chunk that should be sent out. Must return a - * positive value on success and a negative value on errors. -*/ -int (*reposition_stream)(long unsigned request); -/** - * - * - * function responsible for reading one data chunk. - * - * \a read_chunk() must return a pointer to the next chunk of data that should - * be sent out, or \p NULL on errors or if the end of the file was encountered. - * - * If it returns non-NULL, \a len must contain the length of the returned - * buffer (which may be zero if nothing has to be sent for some reason). - * Otherwise, \a len is used to distinguish between the eof and the error case: - * It must be zero in the eof case, or negative if an error occcured. -*/ -char * (*read_chunk)(long unsigned chunk_num, ssize_t *len); +struct audio_format_handler { + /** + * name of the audio format + */ + const char *name; + /** + * typical file endings for files that can be handled by this afh. + */ + const char **suffixes; + /** + * pointer to the audio format handler's init function + * + * Must initialize all function pointers and is assumed to succeed. + */ + void (*init)(void*); + /** + * period of time between sending data chunks + */ + struct timeval chunk_tv; /* length of one chunk of data */ + /** + * end of file timeout - do not load new audio file until this time + * + */ + struct timeval eof_tv; /* timeout on eof */ + /** + * Pointer to the optional get-header function. + * + * This is called from a sender in case a new client connects in the middle of + * the stream. The audio format handler may set this to NULL to indicate that + * this audio format does not need any special header treatment. If non-NULL, + * the function it points to must return a pointer to a buffer holding the + * current audio file header, together with the header length. + */ + char *(*get_header_info)(int *header_len); + /** + * check if this audio format handler can handle the file + * + * This is a pointer to a function returning whether a given file is valid for + * this audio format. A negative return value indicates that this audio format + * handler did not recognize the given file. On success, the function is + * expected to return a positive value and to fill in \arg info_str, \arg + * chunks and \arg seconds appropriately. + */ + int (*get_file_info)(FILE *audio_file, char *info_str, + long unsigned *chunks, int *seconds); + /** + * cleanup function of this audio format handler + * + * This close function should deallocate any resources + * associated with the current audio file. In particular, it is responsible + * for closing the file handle. It is assumed to succeed. + */ + void (*close_audio_file)(void); + /** + * jump to another position in the current audio file + * + * This is called if a client issued the ff or jmp command with \a request + * being the number of the next chunk that should be sent out. Must return a + * positive value on success and a negative value on errors. + */ + int (*reposition_stream)(long unsigned request); + /** + * function responsible for reading one data chunk. + * + * \a read_chunk() must return a pointer to the next chunk of data that should + * be sent out, or \p NULL on errors or if the end of the file was encountered. + * + * If it returns non-NULL, \a len must contain the length of the returned + * buffer (which may be zero if nothing has to be sent for some reason). + * Otherwise, \a len is used to distinguish between the eof and the error case: + * It must be zero in the eof case, or negative if an error occcured. + */ + char * (*read_chunk)(long unsigned chunk_num, ssize_t *len); }; void afs_init(void); diff --git a/command.c b/command.c index f5b39731..5d785f5c 100644 --- a/command.c +++ b/command.c @@ -44,7 +44,7 @@ extern const char *status_item_list[NUM_STAT_ITEMS]; extern struct misc_meta_data *mmd; extern struct gengetopt_args_info conf; extern struct audio_file_selector selectors[]; -extern struct audio_format afl[]; +extern struct audio_format_handler afl[]; extern struct sender senders[]; extern char *user_list; struct sockaddr_in *in_addr; diff --git a/dccp_send.c b/dccp_send.c index e838b3d8..855780e6 100644 --- a/dccp_send.c +++ b/dccp_send.c @@ -50,8 +50,8 @@ struct dccp_client { int header_sent; }; -static void dccp_pre_select(__a_unused struct audio_format *af, int *max_fileno, fd_set *rfds, - __a_unused fd_set *wfds) +static void dccp_pre_select(__a_unused struct audio_format_handler *af, + int *max_fileno, fd_set *rfds, __a_unused fd_set *wfds) { if (listen_fd < 0) return; @@ -59,8 +59,8 @@ static void dccp_pre_select(__a_unused struct audio_format *af, int *max_fileno, *max_fileno = PARA_MAX(*max_fileno, listen_fd); } -static void dccp_post_select(__a_unused struct audio_format *af, fd_set *rfds, - __a_unused fd_set *wfds) +static void dccp_post_select(__a_unused struct audio_format_handler *af, + fd_set *rfds, __a_unused fd_set *wfds) { struct dccp_client *dc; int ret; @@ -133,7 +133,7 @@ err_out: return -E_DCCP_WRITE; } -static void dccp_send(__a_unused struct audio_format *af, +static void dccp_send(__a_unused struct audio_format_handler *af, long unsigned current_chunk, __a_unused long unsigned chunks_sent, const char *buf, size_t len) { diff --git a/http_send.c b/http_send.c index ea88bd4a..f9345ace 100644 --- a/http_send.c +++ b/http_send.c @@ -206,7 +206,7 @@ static int send_queued_packets(struct http_client *hc) return 1; } -static void http_send(__a_unused struct audio_format *af, +static void http_send(__a_unused struct audio_format_handler *af, long unsigned current_chunk, __a_unused long unsigned chunks_sent, const char *buf, size_t len) { @@ -267,7 +267,7 @@ static int host_in_access_perm_list(struct http_client *hc) return 0; } -static void http_post_select(__a_unused struct audio_format *af, fd_set *rfds, +static void http_post_select(__a_unused struct audio_format_handler *af, fd_set *rfds, fd_set *wfds) { int i = -1, match; @@ -347,8 +347,8 @@ err_out: free(hc); } -static void http_pre_select(struct audio_format *af, int *max_fileno, fd_set *rfds, - fd_set *wfds) +static void http_pre_select(struct audio_format_handler *af, int *max_fileno, + fd_set *rfds, fd_set *wfds) { struct http_client *hc, *tmp; diff --git a/mp3.c b/mp3.c index bc253aa5..b9b21a94 100644 --- a/mp3.c +++ b/mp3.c @@ -107,7 +107,7 @@ static const char *mode_text[] = {"stereo", "joint stereo", "dual channel", "mon static struct mp3info mp3; static char mp3buf[8192]; static int chunk_size; -static struct audio_format *af; +static struct audio_format_handler *af; static int header_frequency(struct mp3header *h) { diff --git a/ogg.c b/ogg.c index 2d584e5b..e5647b26 100644 --- a/ogg.c +++ b/ogg.c @@ -36,7 +36,7 @@ static FILE *infile; static int header_len, oggbuf_len, vi_channels; static char *header, *oggbuf; static ssize_t *chunk_table, max_chunk_len; -struct audio_format *af; +struct audio_format_handler *af; static long vi_sampling_rate, vi_bitrate, vi_bitrate_nominal, num_chunks; diff --git a/ortp_send.c b/ortp_send.c index 9dcde7fc..46b3ece7 100644 --- a/ortp_send.c +++ b/ortp_send.c @@ -133,7 +133,8 @@ static void ortp_shutdown_targets(void) } } -static int need_extra_header(struct audio_format *af, long unsigned chunks_sent) +static int need_extra_header(struct audio_format_handler *af, + long unsigned chunks_sent) { /* FIXME: No need to compute this on every run */ int mod = conf.ortp_header_interval_arg / (tv2ms(&af->chunk_tv) + 1); @@ -142,7 +143,7 @@ static int need_extra_header(struct audio_format *af, long unsigned chunks_sent) return 1; } -static void ortp_send(struct audio_format *af, long unsigned current_chunk, +static void ortp_send(struct audio_format_handler *af, long unsigned current_chunk, long unsigned chunks_sent, const char *buf, size_t len) { struct ortp_target *ot, *tmp; @@ -289,7 +290,7 @@ success: } } -static void ortp_pre_select(__a_unused struct audio_format *af, +static void ortp_pre_select(__a_unused struct audio_format_handler *af, __a_unused int *max_fileno, __a_unused fd_set *rfds, __a_unused fd_set *wfds) { diff --git a/send.h b/send.h index 3aebb160..f7198ed7 100644 --- a/send.h +++ b/send.h @@ -45,7 +45,7 @@ struct sender { * command. Of course, \a buf is a pointer to the chunk of data which * should be sent, and \a len is the length of this buffer. */ - void (*send)(struct audio_format *af, long unsigned current_chunk, + void (*send)(struct audio_format_handler *af, long unsigned current_chunk, long unsigned chunks_sent, const char *buf, size_t len); /** add file descriptors to fd_sets * @@ -58,7 +58,7 @@ struct sender { * * \sa select(2) */ - void (*pre_select)(struct audio_format *af, int *max_fileno, fd_set *rfds, + void (*pre_select)(struct audio_format_handler *af, int *max_fileno, fd_set *rfds, fd_set *wfds); /** * handle the file descriptors which are ready for I/O @@ -67,7 +67,7 @@ struct sender { * set, this is the hook to check the result and do any I/O on those descriptors * which are ready for reading/writing. */ - void (*post_select)(struct audio_format *af, fd_set *rfds, fd_set *wfds); + void (*post_select)(struct audio_format_handler *af, fd_set *rfds, fd_set *wfds); /** * terminate all connected clients * diff --git a/server.c b/server.c index caa32d8e..62427717 100644 --- a/server.c +++ b/server.c @@ -61,7 +61,7 @@ char *user_list = NULL; extern void dccp_send_init(struct sender *); extern void http_send_init(struct sender *); extern void ortp_send_init(struct sender *); -extern struct audio_format afl[]; +extern struct audio_format_handler afl[]; /* TODO: This is better handled by autoconf */ /** the list of supported audio file selectors */ -- 2.39.5