DASH Media Packaging SDK
 All Classes Namespaces Functions Variables Typedefs Enumerator
io_cache.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_IO_CACHE_H_
8 #define PACKAGER_FILE_IO_CACHE_H_
9 
10 #include <stdint.h>
11 #include <vector>
12 #include "packager/base/macros.h"
13 #include "packager/base/synchronization/lock.h"
14 #include "packager/base/synchronization/waitable_event.h"
15 
16 namespace edash_packager {
17 namespace media {
18 
20 class IoCache {
21  public:
22  explicit IoCache(uint64_t cache_size);
23  ~IoCache();
24 
31  uint64_t Read(void* buffer, uint64_t size);
32 
40  uint64_t Write(const void* buffer, uint64_t size);
41 
43  void Clear();
44 
47  void Close();
48 
50  bool closed() { return closed_; }
51 
53  void Reopen();
54 
57  uint64_t BytesCached();
58 
61  uint64_t BytesFree();
62 
65 
66  private:
67  uint64_t BytesCachedInternal();
68  uint64_t BytesFreeInternal();
69 
70  const uint64_t cache_size_;
71  base::Lock lock_;
72  base::WaitableEvent read_event_;
73  base::WaitableEvent write_event_;
74  std::vector<uint8_t> circular_buffer_;
75  const uint8_t* end_ptr_;
76  uint8_t* r_ptr_;
77  uint8_t* w_ptr_;
78  bool closed_;
79 
80  DISALLOW_COPY_AND_ASSIGN(IoCache);
81 };
82 
83 } // namespace media
84 } // namespace edash_packager
85 
86 #endif // PACKAGER_FILE_IO_CACHE_H
void Reopen()
Reopens the cache. Any data still in the cache will be lost.
Definition: io_cache.cc:117
Declaration of class which implements a thread-safe circular buffer.
Definition: io_cache.h:20
void WaitUntilEmptyOrClosed()
Waits until the cache is empty or has been closed.
Definition: io_cache.cc:146
uint64_t Write(const void *buffer, uint64_t size)
Definition: io_cache.cc:67
void Clear()
Empties the cache.
Definition: io_cache.cc:103
uint64_t Read(void *buffer, uint64_t size)
Definition: io_cache.cc:39