aac audio format handler: fix end of file timeout
[paraslash.git] / afs.c
diff --git a/afs.c b/afs.c
index 0f4cd20e889811a6cbf466ba2e35990915b02e76..918c5636a5bf8d58c916e0225a96f1dab78fa8c6 100644 (file)
--- a/afs.c
+++ b/afs.c
  * the current audio format, audio file selector and of the activated senders.
  */
 
+#include "server.h"
 #include <sys/time.h> /* gettimeofday */
 #include "server.cmdline.h"
 #include "db.h"
-#include "server.h"
 #include "afs.h"
 #include "send.h"
 #include "error.h"
@@ -45,17 +45,20 @@ extern struct gengetopt_args_info conf;
 static FILE *audio_file = NULL;
 
 #if 1
-       void mp3_init(void *);
+       void mp3_init(struct audio_format_handler *);
 #endif
 
 #ifdef HAVE_OGGVORBIS
-       void ogg_init(void *);
+       void ogg_init(struct audio_format_handler *);
+#endif
+#ifdef HAVE_FAAD
+       void aac_afh_init(struct audio_format_handler *);
 #endif
 
 /**
  * the list of supported  audio formats
  */
-struct audio_format afl[] = {
+struct audio_format_handler afl[] = {
 #if 1
        {
                .name = "mp3",
@@ -67,6 +70,12 @@ struct audio_format afl[] = {
                .name = "ogg",
                .init = ogg_init,
        },
+#endif
+#ifdef HAVE_FAAD
+       {
+               .name = "aac",
+               .init = aac_afh_init,
+       },
 #endif
        {
                .name = NULL,
@@ -327,7 +336,7 @@ static struct timeval *afs_compute_timeout(void)
        return &the_timeout;
 }
 
-static void afs_eof(struct audio_format *af)
+static void afs_eof(struct audio_format_handler *af)
 {
        struct timeval now;
        int i;
@@ -379,7 +388,7 @@ static void afs_eof(struct audio_format *af)
  */
 struct timeval *afs_preselect(void)
 {
-       struct audio_format *af = NULL;
+       struct audio_format_handler *af = NULL;
        int i, format;
        struct timeval *ret;
 again:
@@ -440,7 +449,7 @@ again:
 void afs_send_chunk(void)
 {
        int i;
-       struct audio_format *af;
+       struct audio_format_handler *af;
        char *buf;
        ssize_t ret;
        struct timeval now, due;
@@ -452,6 +461,11 @@ void afs_send_chunk(void)
        afs_next_chunk_time(&due);
        if (tv_diff(&due, &now, NULL) > 0)
                return;
+       if (chk_barrier("eof", &now, &eof_barrier, &due, 1) < 0)
+               return;
+       if (chk_barrier("data send", &now, &data_send_barrier,
+                       &due, 1) < 0)
+               return;
        buf = af->read_chunk(mmd->current_chunk, &ret);
        mmd->new_afs_status_flags &= ~AFS_REPOS;
        if (!buf) {