afhi->chunk_table[0] = ret;
for (i = 1; i<= afhi->chunks_total; i++)
afhi->chunk_table[i] += ret;
+ set_max_chunk_size(afhi);
afhi->channels = channels;
afhi->frequency = rate;
ret = (afhi->chunk_table[afhi->chunks_total] - afhi->chunk_table[0]) * 8; /* bits */
* the current audio file.
*/
uint32_t *chunk_table;
+ /** Size of the largest chunk, introduced in v0.6.0. */
+ uint32_t max_chunk_size;
/** Period of time between sending data chunks. */
struct timeval chunk_tv;
/**
int fd;
/** Vss needs this for streaming. */
struct afh_info afhi;
- /** Size of the largest chunk. */
+ /**
+ * Size of the largest chunk. Superseded by afhi->max_chunk_size. May
+ * be removed after v0.6.1.
+ */
uint32_t max_chunk_size;
/** Needed to get the audio file header. */
uint8_t audio_format_id;
unsigned afh_get_afhi_txt(int audio_format_num, struct afh_info *afhi, char **result);
int afh_rewrite_tags(int audio_format_id, void *map, size_t mapsize,
struct taginfo *tags, int output_fd, const char *filename);
+void set_max_chunk_size(struct afh_info *afhi);
"%s: %" PRIu32 "\n" /* seconds total */
"%s: %lu: %lu\n" /* chunk time */
"%s: %" PRIu32 "\n" /* num chunks */
+ "%s: %" PRIu32 "\n" /* max chunk size */
"%s: %s\n" /* techinfo */
"%s: %s\n" /* artist */
"%s: %s\n" /* title */
status_item_list[SI_CHUNK_TIME], (long unsigned)afhi->chunk_tv.tv_sec,
(long unsigned)afhi->chunk_tv.tv_usec,
status_item_list[SI_NUM_CHUNKS], afhi->chunks_total,
+ status_item_list[SI_MAX_CHUNK_SIZE], afhi->max_chunk_size,
status_item_list[SI_TECHINFO], afhi->techinfo? afhi->techinfo : "",
status_item_list[SI_ARTIST], afhi->tags.artist? afhi->tags.artist : "",
status_item_list[SI_TITLE], afhi->tags.title? afhi->tags.title : "",
);
}
+/**
+ * Determine the maximal chunk size by investigating the chunk table.
+ *
+ * \param afhi Value/result.
+ *
+ * This function iterates over the chunk table and sets ->max_chunk_size
+ * accordingly. The function exists only for backward compatibility since as of
+ * version 0.6.0, para_server stores the maximal chunk size in its database.
+ * This function is only called if the database value is zero, indicating that
+ * the file was added by an older server version.
+ */
+void set_max_chunk_size(struct afh_info *afhi)
+{
+ uint32_t n, max = 0, old = 0;
+
+ for (n = 0; n <= afhi->chunks_total; n++) {
+ uint32_t val = afhi->chunk_table[n];
+ /*
+ * If the first chunk is the header, do not consider it for the
+ * calculation of the largest chunk size.
+ */
+ if (n == 0 || (n == 1 && afhi->header_len > 0)) {
+ old = val;
+ continue;
+ }
+ max = PARA_MAX(max, val - old);
+ old = val;
+ }
+ afhi->max_chunk_size = max;
+}
+
/**
* Create a copy of the given file with altered meta tags.
*
CHUNKS_TOTAL_OFFSET = 20,
/** The length of the audio file header (4 bytes). */
HEADER_LEN_OFFSET = 24,
- /** Was: The start of the audio file header (4 bytes). */
- AFHI_UNUSED2_OFFSET = 28,
+ /** Size of the largest chunk in bytes. (4 bytes). */
+ AFHI_MAX_CHUNK_SIZE_OFFSET = 28,
/** The seconds part of the chunk time (4 bytes). */
CHUNK_TV_TV_SEC_OFFSET = 32,
/** The microseconds part of the chunk time (4 bytes). */
write_u8(buf + AFHI_CHANNELS_OFFSET, afhi->channels);
write_u32(buf + CHUNKS_TOTAL_OFFSET, afhi->chunks_total);
write_u32(buf + HEADER_LEN_OFFSET, afhi->header_len);
- write_u32(buf + AFHI_UNUSED2_OFFSET, 0);
+ write_u32(buf + AFHI_MAX_CHUNK_SIZE_OFFSET, afhi->max_chunk_size);
write_u32(buf + CHUNK_TV_TV_SEC_OFFSET, afhi->chunk_tv.tv_sec);
write_u32(buf + CHUNK_TV_TV_USEC_OFFSET, afhi->chunk_tv.tv_usec);
p = buf + AFHI_INFO_STRING_OFFSET;
afhi->channels = read_u8(buf + AFHI_CHANNELS_OFFSET);
afhi->chunks_total = read_u32(buf + CHUNKS_TOTAL_OFFSET);
afhi->header_len = read_u32(buf + HEADER_LEN_OFFSET);
+ afhi->max_chunk_size = read_u32(buf + AFHI_MAX_CHUNK_SIZE_OFFSET);
afhi->chunk_tv.tv_sec = read_u32(buf + CHUNK_TV_TV_SEC_OFFSET);
afhi->chunk_tv.tv_usec = read_u32(buf + CHUNK_TV_TV_USEC_OFFSET);
afhi->techinfo = (char *)buf + AFHI_INFO_STRING_OFFSET;
return 4 * (afhi->chunks_total + 1);
}
-static uint32_t save_chunk_table(struct afh_info *afhi, char *buf)
+static void save_chunk_table(struct afh_info *afhi, char *buf)
{
- int i;
- uint32_t max = 0, old = 0;
+ uint32_t n;
- for (i = 0; i <= afhi->chunks_total; i++) {
- uint32_t val = afhi->chunk_table[i];
- write_u32(buf + 4 * i, val);
- /*
- * If the first chunk is the header, do not consider it for the
- * calculation of the largest chunk size.
- */
- if (i == 0 || (i == 1 && afhi->header_len > 0)) {
- old = val;
- continue;
- }
- max = PARA_MAX(max, val - old);
- old = val;
- }
- return max;
+ for (n = 0; n <= afhi->chunks_total; n++)
+ write_u32(buf + 4 * n, afhi->chunk_table[n]);
}
static void load_chunk_table(struct afh_info *afhi, const struct osl_object *ct)
goto err;
buf = shm_afd;
buf += sizeof(*afd);
- afd->max_chunk_size = save_chunk_table(&afd->afhi, buf);
+ save_chunk_table(&afd->afhi, buf);
+ if (afd->afhi.max_chunk_size == 0) { /* v0.5.x on-disk afhi */
+ set_max_chunk_size(&afd->afhi);
+ PARA_NOTICE_LOG("max chunk size unset, re-add required\n");
+ } else
+ PARA_INFO_LOG("using max chunk size from afhi\n");
+ afd->max_chunk_size = afd->afhi.max_chunk_size;
*(struct audio_file_data *)shm_afd = *afd;
shm_detach(shm_afd);
return shmid;
WRITE_STATUS_ITEM(b, SI_CHUNK_TIME, "%lu\n", tv2ms(&afhi->chunk_tv));
WRITE_STATUS_ITEM(b, SI_NUM_CHUNKS, "%" PRIu32 "\n",
afhi->chunks_total);
+ WRITE_STATUS_ITEM(b, SI_MAX_CHUNK_SIZE, "%" PRIu32 "\n",
+ afhi->max_chunk_size);
WRITE_STATUS_ITEM(b, SI_TECHINFO, "%s\n", afhi->techinfo);
WRITE_STATUS_ITEM(b, SI_ARTIST, "%s\n", afhi->tags.artist);
WRITE_STATUS_ITEM(b, SI_TITLE, "%s\n", afhi->tags.title);
offset seconds_total stream_start current_time audiod_uptime image_id
lyrics_id duration directory lyrics_name image_name path hash channels
last_played num_chunks chunk_time amplification artist title year album
-comment"
+comment max_chunk_size"
result=
for i in $status_items; do
break;
}
afhi->chunks_total = c;
+ set_max_chunk_size(afhi);
ret = 1;
free_decoder:
FLAC__stream_decoder_finish(decoder);
tv_divide(afhi->chunks_total, &total_time, &afhi->chunk_tv);
PARA_DEBUG_LOG("%" PRIu32 "chunks, each %lums\n", afhi->chunks_total,
tv2ms(&afhi->chunk_tv));
+ set_max_chunk_size(afhi);
ret = mp3_get_id3(map, numbytes, fd, &afhi->tags);
afhi->techinfo = make_message("%cbr, %s, %s tags", vbr? 'v' : 'c',
header_mode(&header), tag_versions[ret]);
}
}
afhi->chunks_total = j;
+ set_max_chunk_size(afhi);
set_chunk_tv(frames_per_chunk, afhi->frequency, &afhi->chunk_tv);
ret = 0;
out:
}
}
afhi->chunks_total = j;
+ set_max_chunk_size(afhi);
set_chunk_tv(frames_per_chunk, afhi->frequency, &afhi->chunk_tv);
return 1;
fail: