- *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;
+/**
+ * Get the data of the given chunk.
+ *
+ * \param chunk_num The number of the desired chunk.
+ * \param buf Chunk data.
+ * \param len Chunk length in bytes.
+ *
+ * \return Positive on success, negative on errors.
+ */
+int vss_get_chunk(long unsigned chunk_num, char **buf, size_t *len)
+{
+ if (mmd->audio_format < 0 || !map || !vss_playing())
+ return -E_CHUNK;
+ if (chunk_num >= mmd->afi.chunks_total)
+ return -E_CHUNK;
+ get_chunk(chunk_num, buf, len);
+ return 1;