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/memory/scoped_ptr.h"
11 #include "packager/base/synchronization/lock.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 
20 class ClosureThread;
21 
23 class ThreadedIoFile : public File {
24  public:
25  enum Mode {
26  kInputMode,
27  kOutputMode
28  };
29 
30  ThreadedIoFile(scoped_ptr<File, FileCloser> internal_file,
31  Mode mode,
32  uint64_t io_cache_size,
33  uint64_t io_block_size);
34 
37  bool Close() override;
38  int64_t Read(void* buffer, uint64_t length) override;
39  int64_t Write(const void* buffer, uint64_t length) override;
40  int64_t Size() override;
41  bool Flush() override;
42  bool Seek(uint64_t position) override;
43  bool Tell(uint64_t* position) override;
45 
46  protected:
47  ~ThreadedIoFile() override;
48 
49  bool Open() override;
50 
51  void RunInInputMode();
52  void RunInOutputMode();
53 
54  private:
55  scoped_ptr<File, FileCloser> internal_file_;
56  const Mode mode_;
57  IoCache cache_;
58  std::vector<uint8_t> io_buffer_;
59  scoped_ptr<ClosureThread> thread_;
60  uint64_t size_;
61  bool eof_;
62  bool flushing_;
63  base::WaitableEvent flush_complete_event_;
64  int64_t internal_file_error_;
65 
66  DISALLOW_COPY_AND_ASSIGN(ThreadedIoFile);
67 };
68 
69 } // namespace media
70 } // namespace edash_packager
71 
72 #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