afh: Dynamic chunks.
[paraslash.git] / vss.c
diff --git a/vss.c b/vss.c
index 792a7393c443590f06ebe469ee95c789c5947278..24dfc6bb51af4edf67c645c0d3ccbda2ad8f1868 100644 (file)
--- a/vss.c
+++ b/vss.c
@@ -98,6 +98,8 @@ struct vss_task {
        size_t header_len;
        /** Time between audio file headers are sent. */
        struct timeval header_interval;
+       /* Only used if afh supports dynamic chunks. */
+       void *afh_context;
 };
 
 /**
@@ -349,6 +351,8 @@ static int initialize_fec_client(struct fec_client *fc, struct vss_task *vsst)
 static void vss_get_chunk(int chunk_num, struct vss_task *vsst,
                char **buf, size_t *sz)
 {
+       int ret;
+
        /*
         * Chunk zero is special for header streams: It is the first portion of
         * the audio file which consists of the audio file header. It may be
@@ -362,8 +366,15 @@ static void vss_get_chunk(int chunk_num, struct vss_task *vsst,
                *sz = vsst->header_len;
                return;
        }
-       afh_get_chunk(chunk_num, &mmd->afd.afhi, vsst->map, (const char **)buf,
-               sz);
+       ret = afh_get_chunk(chunk_num, &mmd->afd.afhi,
+               mmd->afd.audio_format_id, vsst->map, vsst->mapsize,
+               (const char **)buf, sz, &vsst->afh_context);
+       if (ret < 0) {
+               PARA_WARNING_LOG("could not get chunk %d: %s\n",
+                       chunk_num, para_strerror(-ret));
+               *buf = NULL;
+               *sz = 0;
+       }
 }
 
 static void compute_group_size(struct vss_task *vsst, struct fec_group *g,
@@ -858,6 +869,8 @@ static void vss_eof(struct vss_task *vsst)
        free(mmd->afd.afhi.chunk_table);
        mmd->afd.afhi.chunk_table = NULL;
        vsst->mapsize = 0;
+       afh_close(vsst->afh_context, mmd->afd.audio_format_id);
+       vsst->afh_context = NULL;
        mmd->events++;
 }
 
@@ -1115,7 +1128,7 @@ static int vss_post_select(struct sched *s, void *context)
                set_eof_barrier(vsst);
                mmd->chunks_sent = 0;
                mmd->current_chunk = afh_get_start_chunk(mmd->repos_request,
-                       &mmd->afd.afhi);
+                       &mmd->afd.afhi, mmd->afd.audio_format_id);
                mmd->new_vss_status_flags &= ~VSS_REPOS;
                set_mmd_offset();
        }