mf
Media Framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
timed_ring.h
Go to the documentation of this file.
1 #ifndef MF_TIMED_RING_H_
2 #define MF_TIMED_RING_H_
3 
4 #include <atomic>
5 #include <ostream>
6 #include <stdexcept>
7 #include "ring.h"
8 #include "frame.h"
9 
10 namespace mf {
11 
13 class timed_ring : public ring {
14  using base = ring;
15 
16 private:
18 
19  std::atomic<time_unit> last_write_time_{-1};
20  // TODO remove atomic?
21 
22 public:
24 
25  timed_ring(const frame_array_properties& prop) : base(prop) { }
26 
27  void initialize();
28 
29  time_unit current_time() const noexcept { return last_write_time_; }
30  time_unit read_start_time() const noexcept;
31  time_unit write_start_time() const noexcept;
32 
35 
36  bool can_write_span(time_span) const;
37  bool can_read_span(time_span) const;
38  bool can_skip_span(time_span) const;
39 
42  void end_write(time_unit written_duration);
43 
44  section_view_type begin_read(time_unit);
46 
47  void skip_span(time_span);
48 
49  void seek(time_unit);
50 };
51 
52 
53 }
54 
55 #endif
Ring buffer.
Definition: ring.h:12
section_view_type begin_read_span(time_span)
Definition: timed_ring.cc:83
Generic ndarray_view where lower dimension(s) are type-erased.
Definition: ndarray_view_generic.h:25
section_view_type begin_read(time_unit)
Definition: timed_ring.cc:77
std::ptrdiff_t time_unit
Discrete time unit type.
Definition: common.h:52
time_span writable_time_span() const
Definition: timed_ring.cc:25
bool can_write_span(time_span) const
Definition: timed_ring.cc:43
section_view_type begin_write_span(time_span)
Definition: timed_ring.cc:71
void initialize()
Definition: timed_ring.cc:5
time_unit write_start_time() const noexcept
Definition: timed_ring.cc:38
void seek(time_unit)
Definition: timed_ring.cc:106
timed_ring(const frame_array_properties &prop)
Definition: timed_ring.h:25
section_view_type begin_write(time_unit)
Definition: timed_ring.cc:65
time_unit read_start_time() const noexcept
Definition: timed_ring.cc:33
void skip_span(time_span)
Definition: timed_ring.cc:97
time_unit current_time() const noexcept
Definition: timed_ring.h:29
Properties for construction of ndarray_generic and derived container objects.
Definition: ndarray_generic.h:15
void end_write(time_unit written_duration)
Definition: timed_ring.cc:11
ring(const frame_array_properties &)
Definition: ring.cc:10
Ring buffer which adds absolute time index to frames.
Definition: timed_ring.h:13
ndarray_timed_view_generic< 1 > timed_frame_array_view
Definition: frame.h:10
bool can_skip_span(time_span) const
Definition: timed_ring.cc:58
One-dimensional time span.
Definition: common.h:61
bool can_read_span(time_span) const
Definition: timed_ring.cc:50
timed_frame_array_view section_view_type
Definition: timed_ring.h:23
time_span readable_time_span() const
Definition: timed_ring.cc:17