return 1;
}
-static char *aac_read_chunk(long unsigned current_chunk, ssize_t *len)
-{
- int ret;
- size_t pos;
-
- *len = 0;
- if (current_chunk >= num_chunks)
- return NULL;
- *len = chunk_table[current_chunk + 1] - chunk_table[current_chunk];
- if (!*len) /* nothing to send for this run */
- return inbuf;
- pos = chunk_table[current_chunk];
- if (inbuf_size < *len) {
- PARA_INFO_LOG("increasing inbuf for chunk #%lu/%zu to %zd bytes\n",
- current_chunk, num_chunks, *len);
- inbuf = para_realloc(inbuf, *len);
- inbuf_size = *len;
- }
-// PARA_DEBUG_LOG("reading chunk #%lu@%zd (%zd bytes)\n", current_chunk,
-// pos, *len);
- ret = fseek(infile, pos, SEEK_SET);
- if (ret < 0)
- return NULL;
- ret = para_fread(inbuf, *len, 1, infile);
- if (ret != *len)
- return NULL;
-// PARA_DEBUG_LOG("ret: %d, inbuf[0]: %lx - %lx\n", ret, (long unsigned) inbuf[0],
-// (long unsigned) inbuf[4]);
- return (char *)inbuf;
-}
-
-
static const char* aac_suffixes[] = {"m4a", "mp4", NULL};
/** the init function of the aac audio format handler */
void aac_afh_init(struct audio_format_handler *p)
{
af = p;
af->get_file_info = aac_get_file_info,
- af->read_chunk = aac_read_chunk;
af->close_audio_file = aac_close_audio_file;
af->get_header_info = NULL;
af->suffixes = aac_suffixes;
* for closing the file handle. It is assumed to succeed.
*/
void (*close_audio_file)(void);
- /**
- * 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);
};
return 1;
}
-static char *mp3_read_chunk(long unsigned current_chunk, ssize_t *len)
-{
- int ret;
- size_t pos;
-
- *len = 0;
- if (current_chunk >= num_chunks)
- return NULL;
- *len = chunk_table[current_chunk + 1] - chunk_table[current_chunk];
- if (!*len) /* nothing to send for this run */
- return inbuf;
- pos = chunk_table[current_chunk];
- if (inbuf_size < *len) {
- PARA_INFO_LOG("increasing inbuf for chunk #%lu/%zu to %zd bytes\n",
- current_chunk, num_chunks, *len);
- inbuf = para_realloc(inbuf, *len);
- inbuf_size = *len;
- }
-// PARA_DEBUG_LOG("reading chunk #%lu@%zd (%zd bytes)\n", current_chunk,
-// pos, *len);
- ret = fseek(infile, pos, SEEK_SET);
- if (ret < 0)
- return NULL;
- ret = para_fread(inbuf, *len, 1, infile);
- if (ret != *len)
- return NULL;
-// PARA_DEBUG_LOG("ret: %d, inbuf[0]: %lx - %lx\n", ret, (long unsigned) inbuf[0],
-// (long unsigned) inbuf[4]);
- return (char *)inbuf;
-}
-
static void mp3_close_audio_file(void)
{
if (!infile)
{
af = p;
af->get_file_info = mp3_get_file_info;
- af->read_chunk = mp3_read_chunk;
af->close_audio_file = mp3_close_audio_file;
af->get_header_info = NULL;
/* eof_tv gets overwritten in mp3_get_file_info() */
return ret;
}
-static char *ogg_read_chunk(long unsigned current_chunk, ssize_t *len)
-{
- int ret;
- size_t pos;
-
- *len = 0;
- if (current_chunk >= num_chunks)
- return NULL;
- *len = chunk_table[current_chunk + 1] - chunk_table[current_chunk];
- if (!*len) /* nothing to send for this run */
- return inbuf;
- pos = chunk_table[current_chunk];
- if (inbuf_size < *len) {
- PARA_INFO_LOG("increasing inbuf for chunk #%lu/%zu to %zd bytes\n",
- current_chunk, num_chunks, *len);
- inbuf = para_realloc(inbuf, *len);
- inbuf_size = *len;
- }
-// PARA_DEBUG_LOG("reading chunk #%lu@%zd (%zd bytes)\n", current_chunk,
-// pos, *len);
- ret = fseek(infile, pos, SEEK_SET);
- if (ret < 0)
- return NULL;
- ret = para_fread(inbuf, *len, 1, infile);
- if (ret != *len)
- return NULL;
-// PARA_DEBUG_LOG("ret: %d, inbuf[0]: %lx - %lx\n", ret, (long unsigned) inbuf[0],
-// (long unsigned) inbuf[4]);
- return (char *)inbuf;
-}
-
static char *ogg_get_header_info(int *len)
{
*len = header_len;
{
af = p;
af->get_file_info = ogg_get_file_info,
- af->read_chunk = ogg_read_chunk;
af->close_audio_file = ogg_close_audio_file;
af->get_header_info = ogg_get_header_info;
af->chunk_tv.tv_sec = 0;
#include "send.h"
#include "error.h"
#include "string.h"
+#include "fd.h"
extern const char *status_item_list[];
extern struct misc_meta_data *mmd;
extern struct audio_file_selector selectors[];
extern struct sender senders[];
-static size_t *chunk_table;
+static char *inbuf;
+static size_t *chunk_table, inbuf_size;
static FILE *audio_file = NULL;
return ret;
}
+static char *vss_read_chunk(long unsigned current_chunk, ssize_t *len)
+{
+ int ret;
+ size_t pos;
+
+ *len = 0;
+ if (current_chunk >= mmd->chunks_total)
+ return NULL;
+ *len = chunk_table[current_chunk + 1] - chunk_table[current_chunk];
+ if (!*len) /* nothing to send for this run */
+ return inbuf;
+ pos = chunk_table[current_chunk];
+ if (inbuf_size < *len) {
+ PARA_INFO_LOG("increasing inbuf for chunk #%lu/%lu to %zd bytes\n",
+ current_chunk, mmd->chunks_total, *len);
+ inbuf = para_realloc(inbuf, *len);
+ inbuf_size = *len;
+ }
+// PARA_DEBUG_LOG("reading chunk #%lu@%zd (%zd bytes)\n", current_chunk,
+// pos, *len);
+ ret = fseek(audio_file, pos, SEEK_SET);
+ if (ret < 0)
+ return NULL;
+ ret = para_fread(inbuf, *len, 1, audio_file);
+ if (ret != *len)
+ return NULL;
+ return inbuf;
+}
+
/**
* main sending function
*
* Return value: Positive return value on success, zero on eof and negative
* on errors.
*/
-
void vss_send_chunk(void)
{
int i;
if (chk_barrier("data send", &now, &data_send_barrier,
&due, 1) < 0)
return;
- buf = af->read_chunk(mmd->current_chunk, &ret);
+ buf = vss_read_chunk(mmd->current_chunk, &ret);
mmd->new_vss_status_flags &= ~VSS_REPOS;
if (!buf) {
if (ret < 0)