+ write_u8(buf + 18, fc->current_slice_num);
+ write_u16(buf + 20, p->max_slice_bytes - FEC_HEADER_SIZE);
+ write_u8(buf + 22, g->first_chunk? 0 : 1);
+ write_u8(buf + 23, vsst->header_len? 1 : 0);
+ memset(buf + 24, 0, 7);
+}
+
+static int need_audio_header(struct fec_client *fc, struct vss_task *vsst)
+{
+ if (!mmd->current_chunk) {
+ tv_add(now, &vsst->header_interval, &fc->next_header_time);
+ return 0;
+ }
+ if (!vsst->header_buf)
+ return 0;
+ if (!vsst->header_len)
+ return 0;
+ if (fc->group.num && tv_diff(&fc->next_header_time, now, NULL) > 0)
+ return 0;
+ tv_add(now, &vsst->header_interval, &fc->next_header_time);
+ return 1;
+}
+
+static int num_slices(long unsigned bytes, struct fec_client *fc, uint8_t *result)
+{
+ unsigned long m = fc->fcp->max_slice_bytes - FEC_HEADER_SIZE;
+ unsigned rv, redundant_slices = fc->fcp->slices_per_group
+ - fc->fcp->data_slices_per_group;
+
+ if (!m)
+ return -E_BAD_CT;
+ rv = (bytes + m - 1) / m;
+ if (rv + redundant_slices > 255)
+ return -E_BAD_CT;
+ *result = rv;
+ return 1;
+}
+
+/* set group start and group duration */
+static void set_group_timing(struct fec_client *fc, struct fec_group *g)
+{
+ struct timeval *chunk_tv = vss_chunk_time();
+
+ tv_scale(g->num_chunks, chunk_tv, &g->duration);
+ tv_divide(fc->fcp->slices_per_group + fc->num_extra_slices,
+ &g->duration, &g->slice_duration);
+ PARA_DEBUG_LOG("durations (group/chunk/slice): %lu/%lu/%lu\n",
+ tv2ms(&g->duration), tv2ms(chunk_tv), tv2ms(&g->slice_duration));