MP4v2

File.h
1#ifndef MP4V2_PLATFORM_IO_FILE_H
2#define MP4V2_PLATFORM_IO_FILE_H
3
4 namespace mp4v2 { namespace platform { namespace io {
5
7
8 class MP4V2_EXPORT FileProvider
9{
10 public:
11 static FileProvider& standard();
12
13 public:
15 enum Mode {
16 MODE_UNDEFINED,
17 MODE_READ,
18 MODE_MODIFY,
19 MODE_CREATE
20 };
21
23 typedef int64_t Size;
24
25 public:
26 virtual ~FileProvider() { }
27
28 virtual bool open( const std::string& name, Mode mode ) = 0;
29 virtual bool seek( Size pos ) = 0;
30 virtual bool read( void* buffer, Size size, Size& nin ) = 0;
31 virtual bool write( const void* buffer, Size size, Size& nout ) = 0;
32 virtual bool truncate( Size size ) = 0;
33 virtual bool close() = 0;
34 virtual bool getSize( Size& nout ) = 0;
35
36 protected:
37 FileProvider() { }
38};
39
51
52 class MP4V2_EXPORT File : public FileProvider
53{
54 public:
73
74 explicit File( const std::string& name = "", Mode mode = MODE_UNDEFINED,
75 FileProvider* provider = NULL );
76
85
86 ~File();
87
103
104 bool open( const std::string& name = "", Mode mode = MODE_UNDEFINED );
105
116
117 bool close();
118
128
129 bool seek( Size pos );
130
146
147 bool read( void* buffer, Size size, Size& nin );
148
164
165 bool write( const void* buffer, Size size, Size& nout );
166
176
177 bool truncate( Size size );
178
188
189 bool getSize( Size& nout );
190
191 private:
192 std::string _name;
193 bool _isOpen;
194 Mode _mode;
195 Size _size;
196 Size _position;
197 FileProvider& _provider;
198
199 public:
200 const std::string& name;
201 const bool& isOpen;
202 const Mode& mode;
203 const Size& size;
204 const Size& position;
205
206 public:
207 void setName( const std::string& name );
208 void setMode( Mode mode );
209};
210
212
213 class CustomFileProvider : public FileProvider
214{
215 public:
216 CustomFileProvider( const MP4FileProvider& );
217
218 bool open( const std::string& name, Mode mode );
219 bool seek( Size pos );
220 bool read( void* buffer, Size size, Size& nin );
221 bool write( const void* buffer, Size size, Size& nout );
222 bool truncate( Size size );
223 bool close();
224 bool getSize( Size& nout );
225
226 private:
227 MP4FileProvider _call;
228 void* _handle;
229 std::string _name;
230};
231
233
234 class CallbacksFileProvider : public FileProvider
235{
236 public:
237 CallbacksFileProvider( const MP4IOCallbacks& callbacks, void* handle );
238
239 bool open( const std::string& name, Mode mode );
240 bool seek( Size pos );
241 bool read( void* buffer, Size size, Size& nin );
242 bool write( const void* buffer, Size size, Size& nout );
243 bool truncate( Size size );
244 bool close();
245 bool getSize( Size& nout );
246
247 private:
248 MP4IOCallbacks _call;
249 void* _handle;
250};
251
253
254}}} // namespace mp4v2::platform::io
255
256#endif // MP4V2_PLATFORM_IO_FILE_H
mp4v2::platform::io::CallbacksFileProvider
Definition: File.h:235
mp4v2::platform::io::CustomFileProvider
Definition: File.h:214
mp4v2::platform::io::File
File implementation.
Definition: File.h:53
mp4v2::platform::io::File::mode
const Mode & mode
read-only: file mode
Definition: File.h:202
mp4v2::platform::io::File::close
bool close()
Closes file.
mp4v2::platform::io::File::truncate
bool truncate(Size size)
Truncate file to length in bytes.
mp4v2::platform::io::File::write
bool write(const void *buffer, Size size, Size &nout)
Binary stream write.
mp4v2::platform::io::File::size
const Size & size
read-only: file size
Definition: File.h:203
mp4v2::platform::io::File::seek
bool seek(Size pos)
Set current file position in bytes.
mp4v2::platform::io::File::position
const Size & position
read-only: file position
Definition: File.h:204
mp4v2::platform::io::File::open
bool open(const std::string &name="", Mode mode=MODE_UNDEFINED)
Open file.
mp4v2::platform::io::File::~File
~File()
Destructor.
mp4v2::platform::io::File::read
bool read(void *buffer, Size size, Size &nin)
Binary stream read.
mp4v2::platform::io::File::getSize
bool getSize(Size &nout)
Get size of file in bytes.
mp4v2::platform::io::File::name
const std::string & name
read-only: file pathname or empty-string if not applicable
Definition: File.h:200
mp4v2::platform::io::File::File
File(const std::string &name="", Mode mode=MODE_UNDEFINED, FileProvider *provider=NULL)
Constructor.
mp4v2::platform::io::File::isOpen
const bool & isOpen
read-only: true if file is open
Definition: File.h:201
mp4v2::platform::io::FileProvider
Definition: File.h:9
mp4v2::platform::io::FileProvider::Mode
Mode
file operation mode flags
Definition: File.h:15
mp4v2::platform::io::FileProvider::MODE_MODIFY
@ MODE_MODIFY
file may be read/written
Definition: File.h:18
mp4v2::platform::io::FileProvider::MODE_UNDEFINED
@ MODE_UNDEFINED
undefined
Definition: File.h:16
mp4v2::platform::io::FileProvider::MODE_READ
@ MODE_READ
file may be read
Definition: File.h:17
mp4v2::platform::io::FileProvider::Size
int64_t Size
type used to represent all file sizes and offsets
Definition: File.h:23
MP4FileProvider_s
Structure of functions implementing custom file provider.
Definition: file.h:41
MP4IOCallbacks_s
Structure of functions implementing custom I/O callbacks.
Definition: file.h:60