DASH Media Packaging SDK
 All Classes Namespaces Functions Variables Typedefs Enumerator
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/atomicops.h"
11 #include "packager/base/memory/scoped_ptr.h"
12 #include "packager/base/synchronization/lock.h"
13 #include "packager/base/synchronization/waitable_event.h"
14 #include "packager/media/file/file.h"
15 #include "packager/media/file/file_closer.h"
16 #include "packager/media/file/io_cache.h"
17 
18 namespace edash_packager {
19 namespace media {
20 
21 class ClosureThread;
22 
24 class ThreadedIoFile : public File {
25  public:
26  enum Mode {
27  kInputMode,
28  kOutputMode
29  };
30 
31  ThreadedIoFile(scoped_ptr<File, FileCloser> internal_file,
32  Mode mode,
33  uint64_t io_cache_size,
34  uint64_t io_block_size);
35 
38  bool Close() override;
39  int64_t Read(void* buffer, uint64_t length) override;
40  int64_t Write(const void* buffer, uint64_t length) override;
41  int64_t Size() override;
42  bool Flush() override;
43  bool Seek(uint64_t position) override;
44  bool Tell(uint64_t* position) override;
46 
47  protected:
48  ~ThreadedIoFile() override;
49 
50  bool Open() override;
51 
52  void RunInInputMode();
53  void RunInOutputMode();
54 
55  private:
56  scoped_ptr<File, FileCloser> internal_file_;
57  const Mode mode_;
58  IoCache cache_;
59  std::vector<uint8_t> io_buffer_;
60  scoped_ptr<ClosureThread> thread_;
61  uint64_t position_;
62  uint64_t size_;
63  base::subtle::Atomic32 eof_;
64  bool flushing_;
65  base::WaitableEvent flush_complete_event_;
66  base::subtle::Atomic32 internal_file_error_;
67 
68  DISALLOW_COPY_AND_ASSIGN(ThreadedIoFile);
69 };
70 
71 } // namespace media
72 } // namespace edash_packager
73 
74 #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