Permalink
Browse files

o some comment changes. Ready to do some flac handling.

  • Loading branch information...
1 parent 5476cc2 commit 8b18938f8e96cc46104a4e67b728785270783a21 @hzeller committed Sep 10, 2012
Showing with 32 additions and 26 deletions.
  1. +4 −1 Makefile
  2. +5 −5 convolver.cc
  3. +5 −5 filter-interface.h
  4. +18 −15 fuse-convolve.c
View
@@ -1,9 +1,12 @@
CFLAGS=-D_FILE_OFFSET_BITS=64 -Wall
CXXFLAGS=-Wall
-LDFLAGS=-lfuse
+LDFLAGS=-lfuse -lsndfile
fuse-convolve: fuse-convolve.o convolver.o
g++ $(CXXFLAGS) $^ -o $@ $(LDFLAGS)
+copy-music: copy-music.cc
+ g++ $(CXXFLAGS) $< -o $@ $(LDFLAGS)
+
clean:
rm fuse-convolve *.o
View
@@ -22,7 +22,7 @@
#include "filter-interface.h"
namespace {
-class FileFilter : public filter_interface_t {
+class FileFilter : public filter_object_t {
public:
// Returns bytes read or a negative value indicating a negative errno.
virtual int Read(char *buf, size_t size, off_t offset) = 0;
@@ -83,21 +83,21 @@ bool HasSuffixString (const char *str, const char *suffix) {
}
// Implementation of the C functions in filter-interface.h
-struct filter_interface_t *create_filter(int filedes, const char *path) {
+struct filter_object_t *create_filter(int filedes, const char *path) {
if (HasSuffixString(path, ".wav")) {
return new WavFilter(filedes, path);
}
- // Everything other file is just passed through as is.
+ // Every other file-type is just passed through as is.
return new PassThroughFilter(filedes, path);
}
-int read_from_filter(struct filter_interface_t *filter,
+int read_from_filter(struct filter_object_t *filter,
char *buf, size_t size, off_t offset) {
return reinterpret_cast<FileFilter*>(filter)->Read(buf, size, offset);
}
-int close_filter(struct filter_interface_t *filter) {
+int close_filter(struct filter_object_t *filter) {
FileFilter *file_filter = reinterpret_cast<FileFilter*>(filter);
int result = file_filter->Close();
delete file_filter;
View
@@ -22,20 +22,20 @@
extern "C" {
#endif /* __cplusplus */
-struct filter_interface_t {};
+struct filter_object_t {};
// Create a new filter given the open filedescriptor and the path. Returns
-// that filter in an opaque FilterInterface*
-struct filter_interface_t *create_filter(int filedes, const char *orig_path);
+// that filter in an opaque filter_object_t*
+struct filter_object_t *create_filter(int filedes, const char *orig_path);
// Read from the given filter at the file-offset "offset, up to "size" bytes
// into "buffer". Returns number of bytes read or a negative errno value.
-int read_from_filter(struct filter_interface_t *filter,
+int read_from_filter(struct filter_object_t *filter,
char *buffer, size_t size, off_t offset);
// At the end of the operation, close filter. Return 0 on success or negative
// errno value on failure.
-int close_filter(struct filter_interface_t *filter);
+int close_filter(struct filter_object_t *filter);
#ifdef __cplusplus
} // extern "C"
View
@@ -13,6 +13,9 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
+// This fuse filesystem only provides read access to another filesystem that
+// contains *.flac and *.wav files. Accessing these files passes them
+// through a zita-filter transparently.
// This is a pure C implementation, providing basic file operations and passing
// actual reading to a filter aquired using the functions in filter-interface.h
@@ -99,31 +102,31 @@ static int fuseconv_open(const char *path, struct fuse_file_info *fi) {
char path_buf[PATH_MAX];
const char *orig_path = assemble_orig_path(path_buf, path);
const int fd = open(orig_path, fi->flags);
-
- // We want to return partial reads. That way, we can separate reading the
- // ID3-tags from the stream.
- // In order to return partical content, we need to set the direct_io.
- fi->direct_io = 1;
-
if (fd == -1)
return -errno;
+ // We want to be allowed to only return part of the requested data in read().
+ // That way, we can separate reading the ID3-tags from
+ // decoding of the music stream - that way indexing should be fast.
+ // Setting the flag 'direct_io' allows us to return partial results.
+ fi->direct_io = 1;
+
// The file-handle has the neat property to be 64 bit - so we can actually
- // store a pointer in there :) (Yay, someone was thinking while developing
- // that API).
+ // store a pointer to our filter object in there :)
+ // (Yay, someone was thinking while developing that API).
fi->fh = (uint64_t) create_filter(fd, orig_path);
return 0;
}
static int fuseconv_read(const char *path, char *buf, size_t size, off_t offset,
struct fuse_file_info *fi) {
- return read_from_filter((struct filter_interface_t*)fi->fh,
+ return read_from_filter((struct filter_object_t*)fi->fh,
buf, size, offset);
}
static int fuseconv_release(const char *path, struct fuse_file_info *fi) {
fprintf(stderr, "HZ ===== close('%s')\n", path);
- return close_filter((struct filter_interface_t*) fi->fh);
+ return close_filter((struct filter_object_t*) fi->fh);
}
static struct fuse_operations fuseconv_operations = {
@@ -140,15 +143,15 @@ static struct fuse_operations fuseconv_operations = {
.read = fuseconv_read,
};
-static void usage(const char *prog) {
- fprintf(stderr, "usage: %s <config-dir> <original-dir> <mount-point>\n",
+static int usage(const char *prog) {
+ fprintf(stderr, "usage: %s <config-file> <original-dir> <mount-point>\n",
prog);
- exit(1);
+ return 1;
}
int main(int argc, char *argv[]) {
- if (argc < 2) {
- usage(argv[0]);
+ if (argc < 4) {
+ return usage(argv[0]);
}
// First, let's extract our configuration.

0 comments on commit 8b18938

Please sign in to comment.