Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
delayed_reader.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Roc authors
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7  */
8 
9 //! @file roc_packet/delayed_reader.h
10 //! @brief Delayed reader.
11 
12 #ifndef ROC_PACKET_DELAYED_READER_H_
13 #define ROC_PACKET_DELAYED_READER_H_
14 
15 #include "roc_core/noncopyable.h"
16 #include "roc_core/time.h"
17 #include "roc_packet/ireader.h"
19 #include "roc_packet/units.h"
20 
21 namespace roc {
22 namespace packet {
23 
24 //! Delayed reader.
25 //! @remarks
26 //! Delays audio packet reader for given amount of samples.
27 class DelayedReader : public IReader, public core::NonCopyable<> {
28 public:
29  //! Initialize.
30  //!
31  //! @b Parameters
32  //! - @p reader is used to read packets
33  //! - @p delay is the delay to insert before first packet
34  //! - @p sample_rate is the number of samples per second in incoming packets
35  DelayedReader(IReader& reader, core::nanoseconds_t delay, size_t sample_rate);
36 
37  //! Read packet.
38  virtual PacketPtr read();
39 
40 private:
41  bool fetch_packets_();
42  PacketPtr read_queued_packet_();
43 
44  timestamp_t queue_size_() const;
45 
46  IReader& reader_;
47  SortedQueue queue_;
48 
49  const timestamp_t delay_;
50  bool started_;
51 };
52 
53 } // namespace packet
54 } // namespace roc
55 
56 #endif // ROC_PACKET_DELAYED_READER_H_
Packet reader interface.
Time definitions.
Packet reader interface.
Definition: ireader.h:21
Root namespace.
virtual PacketPtr read()
Read packet.
Sorted packet queue.
int64_t nanoseconds_t
Nanoseconds.
Definition: time.h:21
uint32_t timestamp_t
Audio packet timestamp.
Definition: units.h:46
Base class for non-copyable objects.
Definition: noncopyable.h:23
DelayedReader(IReader &reader, core::nanoseconds_t delay, size_t sample_rate)
Initialize.
Various units used in packets.
Non-copyable object.
Sorted packet queue.
Definition: sorted_queue.h:27