converted OggVorbisStream to use assman
authorJohn Tsiombikas <nuclear@member.fsf.org>
Sat, 29 Sep 2018 03:04:29 +0000 (06:04 +0300)
committerJohn Tsiombikas <nuclear@member.fsf.org>
Sat, 29 Sep 2018 03:04:29 +0000 (06:04 +0300)
src/audio/ovstream.cc

index 56f3033..0c347f8 100644 (file)
@@ -1,5 +1,6 @@
 #include <stdio.h>
 #include <assert.h>
+#include "assman.h"
 #include "logger.h"
 #include "ovstream.h"
 
@@ -15,14 +16,38 @@ OggVorbisStream::~OggVorbisStream()
        close();
 }
 
+static int io_fseek(void *fp, ogg_int64_t offs, int whence)
+{
+       if(ass_fseek(fp, offs, whence) != -1) {
+               return 0;
+       }
+       return -1;
+}
+
+static int io_close(void *fp)
+{
+       ass_fclose(fp);
+       return 0;
+}
+
+
 bool OggVorbisStream::open(const char *fname)
 {
        close();
 
        pthread_mutex_lock(&vflock);
 
-       if(ov_fopen(fname, &vf) != 0) {
-               error_log("failed to open ogg/vorbis stream: %s\n", fname ? fname : "<not found>");
+       ass_file *fp;
+       if(!(fp = ass_fopen(fname, "rb"))) {
+               error_log("failed to open ogg/vorbis stream: %s: %s\n", fname, strerror(ass_errno));
+               pthread_mutex_unlock(&vflock);
+               return false;
+       }
+
+       ov_callbacks iofuncs = { ass_fread, io_fseek, io_close, ass_ftell };
+       if(ov_open_callbacks(fp, &vf, 0, 0, iofuncs) != 0) {
+               error_log("failed to open ogg/vorbis stream: %s: %s\n", fname, strerror(ass_errno));
+               ass_fclose(fp);
                pthread_mutex_unlock(&vflock);
                return false;
        }