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  bool Close() override;
37  int64_t Read(void* buffer, uint64_t length) override;
38  int64_t Write(const void* buffer, uint64_t length) override;
39  int64_t Size() override;
40  bool Flush() override;
41  bool Seek(uint64_t position) override;
42  bool Tell(uint64_t* position) override;
44 
45  protected:
46  ~ThreadedIoFile() override;
47 
48  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
int64_t Write(const void *buffer, uint64_t length) override
Declaration of class which implements a thread-safe circular buffer.
Definition: io_cache.h:20
bool Seek(uint64_t position) override
Define an abstract file interface.
Definition: file.h:22
int64_t Read(void *buffer, uint64_t length) override
bool Open() override
Internal open. Should not be used directly.
Declaration of class which implements a thread-safe circular buffer.
bool Tell(uint64_t *position) override