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/waitable_event.h"
13 #include "packager/media/file/file.h"
14 #include "packager/media/file/file_closer.h"
15 #include "packager/media/file/io_cache.h"
16 
17 namespace edash_packager {
18 namespace media {
19 
21 class ThreadedIoFile : public File {
22  public:
23  enum Mode {
24  kInputMode,
25  kOutputMode
26  };
27 
28  ThreadedIoFile(scoped_ptr<File, FileCloser> internal_file,
29  Mode mode,
30  uint64_t io_cache_size,
31  uint64_t io_block_size);
32 
35  bool Close() override;
36  int64_t Read(void* buffer, uint64_t length) override;
37  int64_t Write(const void* buffer, uint64_t length) override;
38  int64_t Size() override;
39  bool Flush() override;
40  bool Seek(uint64_t position) override;
41  bool Tell(uint64_t* position) override;
43 
44  protected:
45  ~ThreadedIoFile() override;
46 
47  bool Open() override;
48 
49  private:
50  // Internal task handler implementation. Will dispatch to either
51  // |RunInInputMode| or |RunInOutputMode| depending on |mode_|.
52  void TaskHandler();
53  void RunInInputMode();
54  void RunInOutputMode();
55 
56  scoped_ptr<File, FileCloser> internal_file_;
57  const Mode mode_;
58  IoCache cache_;
59  std::vector<uint8_t> io_buffer_;
60  uint64_t position_;
61  uint64_t size_;
62  base::subtle::Atomic32 eof_;
63  bool flushing_;
64  base::WaitableEvent flush_complete_event_;
65  base::subtle::Atomic32 internal_file_error_;
66  // Signalled when thread task exits.
67  base::WaitableEvent task_exit_event_;
68 
69  DISALLOW_COPY_AND_ASSIGN(ThreadedIoFile);
70 };
71 
72 } // namespace media
73 } // namespace edash_packager
74 
75 #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:24
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