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 Streaming 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_audio/sample_spec.h"
16 #include "roc_core/noncopyable.h"
17 #include "roc_core/time.h"
18 #include "roc_packet/ireader.h"
20 #include "roc_packet/units.h"
21 
22 namespace roc {
23 namespace packet {
24 
25 //! Delayed reader.
26 //! @remarks
27 //! Delays audio packet reader for given amount of samples.
28 class DelayedReader : public IReader, public core::NonCopyable<> {
29 public:
30  //! Initialize.
31  //!
32  //! @b Parameters
33  //! - @p reader is used to read packets
34  //! - @p target_delay is the delay to insert before first packet
35  //! - @p sample_spec is the specifications of incoming packets
37  core::nanoseconds_t target_delay,
38  const audio::SampleSpec& sample_spec);
39 
40  //! Check if object was constructed successfully.
41  bool is_valid() const;
42 
43  //! Read packet.
45 
46 private:
47  status::StatusCode fetch_packets_();
48  status::StatusCode read_queued_packet_(PacketPtr&);
49 
50  stream_timestamp_t queue_size_() const;
51 
52  IReader& reader_;
53  SortedQueue queue_;
54 
55  stream_timestamp_t delay_;
56  bool started_;
57 
58  const audio::SampleSpec sample_spec_;
59 
60  bool valid_;
61 };
62 
63 } // namespace packet
64 } // namespace roc
65 
66 #endif // ROC_PACKET_DELAYED_READER_H_
#define ROC_ATTR_NODISCARD
Emit warning if function result is not checked.
Definition: attributes.h:31
Sample specification. Describes sample rate and channels.
Definition: sample_spec.h:30
Base class for non-copyable objects.
Definition: noncopyable.h:23
virtual ROC_ATTR_NODISCARD status::StatusCode read(PacketPtr &)
Read packet.
DelayedReader(IReader &reader, core::nanoseconds_t target_delay, const audio::SampleSpec &sample_spec)
Initialize.
bool is_valid() const
Check if object was constructed successfully.
Packet reader interface.
Definition: ireader.h:23
Sorted packet queue.
Definition: sorted_queue.h:27
Packet reader interface.
int64_t nanoseconds_t
Nanoseconds.
Definition: time.h:58
uint32_t stream_timestamp_t
Packet stream timestamp.
Definition: units.h:36
Root namespace.
Non-copyable object.
Sample specifications.
Sorted packet queue.
StatusCode
Status code.
Definition: status_code.h:19
Time definitions.
Various units used in packets.