Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 121 lines (100 sloc) 4.464 kb
a9d3e53 @hzeller o Found a project name: "Folve". Some renamings because of that.
authored
1 // -*- c++ -*-
4d4d90b @hzeller o More legalese
authored
2 // Folve - A fuse filesystem that convolves audio files on-the-fly.
3 //
6e895e3 @hzeller o add conversion buffer that uses the virtual file provided
authored
4 // Copyright (C) 2012 Henner Zeller <h.zeller@acm.org>
b4eec5c @hzeller o libboost caused too many troubles in embedded systems with weak
authored
5 //
6e895e3 @hzeller o add conversion buffer that uses the virtual file provided
authored
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18
a9d3e53 @hzeller o Found a project name: "Folve". Some renamings because of that.
authored
19 #ifndef FOLVE_CONVERSION_BUFFER_H
20 #define FOLVE_CONVERSION_BUFFER_H
21
6e895e3 @hzeller o add conversion buffer that uses the virtual file provided
authored
22 #include <sndfile.h>
b4eec5c @hzeller o libboost caused too many troubles in embedded systems with weak
authored
23 #include "util.h"
6e895e3 @hzeller o add conversion buffer that uses the virtual file provided
authored
24
fd4ed76 @hzeller o write to a file instead of a buffer.
authored
25 // A file-backed buffer for a SNDFILE, that is only filled on demand via
26 // a SoundSource.
27 // If Read() is called beyond the current available data, a callback is
28 // called to write more into the SNDFILE.
6e895e3 @hzeller o add conversion buffer that uses the virtual file provided
authored
29 class ConversionBuffer {
a9d3e53 @hzeller o Found a project name: "Folve". Some renamings because of that.
authored
30 public:
fd4ed76 @hzeller o write to a file instead of a buffer.
authored
31 // SoundSource, a instance of which needs to be passed to the
32 // ConversionBuffer.
33 class SoundSource {
6e895e3 @hzeller o add conversion buffer that uses the virtual file provided
authored
34 public:
fd4ed76 @hzeller o write to a file instead of a buffer.
authored
35 virtual ~SoundSource() {}
36
37 // The soundfile is set by this conversion buffer and to be filled when
38 // requested. There can be an error in opening the sound-file, in that
39 // case SetOutputSoundfile() will be called with NULL.
40 // Ask sf_strerror() to find out why.
b4eec5c @hzeller o libboost caused too many troubles in embedded systems with weak
authored
41 // Ownership is passed to the SoundSource, receiver needs to
5a6dffa @hzeller o comment update.
authored
42 // sf_close() the file.
47c2b03 @hzeller o better skip mode detection. Only if someone _really_ jumps to the
authored
43 virtual void SetOutputSoundfile(ConversionBuffer *parent,
44 SNDFILE *sndfile) = 0;
b4eec5c @hzeller o libboost caused too many troubles in embedded systems with weak
authored
45
fd4ed76 @hzeller o write to a file instead of a buffer.
authored
46 // This callback is called by the ConversionBuffer if it needs more data.
47 // Rerturns 'true' if there is more, 'false' if that was the last available
48 // data.
47c2b03 @hzeller o better skip mode detection. Only if someone _really_ jumps to the
authored
49 virtual bool AddMoreSoundData() = 0;
6e895e3 @hzeller o add conversion buffer that uses the virtual file provided
authored
50 };
51
a9d3e53 @hzeller o Found a project name: "Folve". Some renamings because of that.
authored
52 // Create a conversion buffer providing an sound output described in
53 // "out_info".
54 // The "source" will be called back whenever this conversion buffer needs
55 // more data.
56 //
fd4ed76 @hzeller o write to a file instead of a buffer.
authored
57 // Ownership is not taken over for source.
a9d3e53 @hzeller o Found a project name: "Folve". Some renamings because of that.
authored
58 ConversionBuffer(SoundSource *source, const SF_INFO &out_info);
6e895e3 @hzeller o add conversion buffer that uses the virtual file provided
authored
59 ~ConversionBuffer();
60
fd4ed76 @hzeller o write to a file instead of a buffer.
authored
61 // Read data from buffer. Can block and call the SoundSource first to get
62 // more data if needed.
6e895e3 @hzeller o add conversion buffer that uses the virtual file provided
authored
63 ssize_t Read(char *buf, size_t size, off_t offset);
64
7e27dab @hzeller o initial version of copying header. Not sure yet though if
authored
65 // Append data. Usually called via the SndWrite() virtual-SNFFILE callback,
9ca938d @hzeller o comment tweaking.
authored
66 // but can be used to write raw data as well (e.g. to write headers in
67 // SetOutputSoundfile())
7e27dab @hzeller o initial version of copying header. Not sure yet though if
authored
68 ssize_t Append(const void *data, size_t count);
69
a85bebb @hzeller o Fix Flac header manually. Luckily the streamheader is a fixed
authored
70 // Write at a particular position. Writes a single character - this is
9ca938d @hzeller o comment tweaking.
authored
71 // used for chirurgical header editing...
a85bebb @hzeller o Fix Flac header manually. Luckily the streamheader is a fixed
authored
72 void WriteCharAt(unsigned char c, off_t offset);
73
fea3d55 @hzeller o Initial implementation of pre-buffering thread.
authored
74 // Fill read file until we have the required bytes available.
75 void FillUntil(off_t requested_min_written);
76
f8cb9e5 @hzeller o redacting MD5.
authored
77 // Enable writing through the SNDFILE.
78 // If set to 'false', writes via the SNDFILE are ignored.
79 // To be used to suppress writing of the header or
7e27dab @hzeller o initial version of copying header. Not sure yet though if
authored
80 // footer if we want to handle that on our own.
f8cb9e5 @hzeller o redacting MD5.
authored
81 void set_sndfile_writes_enabled(bool b) { snd_writing_enabled_ = b; }
82 bool sndfile_writes_enabled() const { return snd_writing_enabled_; }
7e27dab @hzeller o initial version of copying header. Not sure yet though if
authored
83
550c4e0 @hzeller o allow short read in header area, but not in the stream
authored
84 // Tell conversion buffer when we're done writing the header. It needs to
a9d3e53 @hzeller o Found a project name: "Folve". Some renamings because of that.
authored
85 // know so that it can serve reads in these different regions differently.
86 // (Long story, see Read() for details).
550c4e0 @hzeller o allow short read in header area, but not in the stream
authored
87 void HeaderFinished();
88
fea3d55 @hzeller o Initial implementation of pre-buffering thread.
authored
89 // Returns if we've completed this file.
90 bool IsFileComplete() const;
91
7fa80f5 @hzeller o Don't lock read access to FileSize(). Otherwise we're potentially
authored
92 // Current max file position.
fea3d55 @hzeller o Initial implementation of pre-buffering thread.
authored
93 off_t FileSize() const;
94
95 // Maximum position accessed. This might be different from FileSize in case
96 // we have a pre-buffering thread running.
97 off_t MaxAccessed() const;
ba7fde8 @hzeller o implement size estimate. If the user stat() or fstat() the file,
authored
98
a9d3e53 @hzeller o Found a project name: "Folve". Some renamings because of that.
authored
99 private:
6e895e3 @hzeller o add conversion buffer that uses the virtual file provided
authored
100 static sf_count_t SndTell(void *userdata);
101 static sf_count_t SndWrite(const void *ptr, sf_count_t count, void *userdata);
102
7e27dab @hzeller o initial version of copying header. Not sure yet though if
authored
103 // Append for the SndWrite callback.
104 ssize_t SndAppend(const void *data, size_t count);
105
fd4ed76 @hzeller o write to a file instead of a buffer.
authored
106 // Create a SNDFILE the user has to write to in the WriteToSoundfile callback.
107 // Can be NULL on error.
108 SNDFILE *CreateOutputSoundfile(const SF_INFO &info);
6e895e3 @hzeller o add conversion buffer that uses the virtual file provided
authored
109
fd4ed76 @hzeller o write to a file instead of a buffer.
authored
110 SoundSource *const source_;
b698853 @hzeller o README updates.
authored
111 int out_filedes_;
7e27dab @hzeller o initial version of copying header. Not sure yet though if
authored
112 bool snd_writing_enabled_;
fd4ed76 @hzeller o write to a file instead of a buffer.
authored
113 off_t total_written_;
fea3d55 @hzeller o Initial implementation of pre-buffering thread.
authored
114 off_t max_accessed_;
550c4e0 @hzeller o allow short read in header area, but not in the stream
authored
115 off_t header_end_;
fea3d55 @hzeller o Initial implementation of pre-buffering thread.
authored
116 bool file_complete_;
117 mutable folve::Mutex mutex_;
6e895e3 @hzeller o add conversion buffer that uses the virtual file provided
authored
118 };
a9d3e53 @hzeller o Found a project name: "Folve". Some renamings because of that.
authored
119
120 #endif // FOLVE_CONVERSION_BUFFER_H
Something went wrong with that request. Please try again.