DASH Media Packaging SDK
 All Classes Namespaces Functions Variables Typedefs
threaded_io_file.h
1 // Copyright 2015 Google Inc. All rights reserved.
2 //
3 // Use of this source code is governed by a BSD-style
4 // license that can be found in the LICENSE file or at
5 // https://developers.google.com/open-source/licenses/bsd
6 
7 #ifndef PACKAGER_FILE_THREADED_IO_FILE_H_
8 #define PACKAGER_FILE_THREADED_IO_FILE_H_
9 
10 #include "packager/base/memory/scoped_ptr.h"
11 #include "packager/base/synchronization/lock.h"
12 #include "packager/media/file/file.h"
13 #include "packager/media/file/file_closer.h"
14 #include "packager/media/file/io_cache.h"
15 
16 namespace edash_packager {
17 namespace media {
18 
19 class ClosureThread;
20 
22 class ThreadedIoFile : public File {
23  public:
24  enum Mode {
25  kInputMode,
26  kOutputMode
27  };
28 
29  ThreadedIoFile(scoped_ptr<File, FileCloser> internal_file,
30  Mode mode,
31  uint64_t io_cache_size,
32  uint64_t io_block_size);
33 
36  virtual bool Close() OVERRIDE;
37  virtual int64_t Read(void* buffer, uint64_t length) OVERRIDE;
38  virtual int64_t Write(const void* buffer, uint64_t length) OVERRIDE;
39  virtual int64_t Size() OVERRIDE;
40  virtual bool Flush() OVERRIDE;
41  virtual bool Seek(uint64_t position) OVERRIDE;
42  virtual bool Tell(uint64_t* position) OVERRIDE;
44 
45  protected:
46  virtual ~ThreadedIoFile();
47 
48  virtual bool Open() OVERRIDE;
49 
50  void RunInInputMode();
51  void RunInOutputMode();
52 
53  private:
54  scoped_ptr<File, FileCloser> internal_file_;
55  const Mode mode_;
56  IoCache cache_;
57  std::vector<uint8_t> io_buffer_;
58  scoped_ptr<ClosureThread> thread_;
59  uint64_t size_;
60  bool eof_;
61  int64_t internal_file_error_;
62 
63  DISALLOW_COPY_AND_ASSIGN(ThreadedIoFile);
64 };
65 
66 } // namespace media
67 } // namespace edash_packager
68 
69 #endif // PACKAGER_FILE_THREADED_IO_FILE_H
virtual int64_t Write(const void *buffer, uint64_t length) OVERRIDE
virtual int64_t Read(void *buffer, uint64_t length) OVERRIDE
Declaration of class which implements a thread-safe circular buffer.
Definition: io_cache.h:20
Define an abstract file interface.
Definition: file.h:22
virtual bool Tell(uint64_t *position) OVERRIDE
virtual bool Open() OVERRIDE
Internal open. Should not be used directly.
Declaration of class which implements a thread-safe circular buffer.
virtual bool Seek(uint64_t position) OVERRIDE