Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Loading...
Searching...
No Matches
depacketizer.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_audio/depacketizer.h
10//! @brief Depacketizer.
11
12#ifndef ROC_AUDIO_DEPACKETIZER_H_
13#define ROC_AUDIO_DEPACKETIZER_H_
14
16#include "roc_audio/ireader.h"
17#include "roc_audio/units.h"
20#include "roc_packet/ireader.h"
21
22namespace roc {
23namespace audio {
24
25//! Depacketizer.
26//! @remarks
27//! Reads packets from a packet reader, decodes samples from packets using a
28//! decoder, and produces an audio stream.
29class Depacketizer : public IReader, public core::NonCopyable<> {
30public:
31 //! Initialization.
32 //!
33 //! @b Parameters
34 //! - @p reader is used to read packets
35 //! - @p payload_decoder is used to extract samples from packets
36 //! - @p channels defines a set of channels in the output frames
37 //! - @p beep enables weird beeps instead of silence on packet loss
39 IFrameDecoder& payload_decoder,
41 bool beep);
42
43 //! Read audio frame.
44 virtual void read(Frame& frame);
45
46 //! Did depacketizer catch first packet?
47 bool started() const;
48
49 //! Get next timestamp to be rendered.
50 //! @pre
51 //! started() should return true
53
54private:
55 void read_frame_(Frame& frame);
56
57 sample_t* read_samples_(sample_t* buff_ptr, sample_t* buff_end);
58
59 sample_t* read_packet_samples_(sample_t* buff_ptr, sample_t* buff_end);
60 sample_t* read_missing_samples_(sample_t* buff_ptr, sample_t* buff_end);
61
62 void set_frame_flags_(Frame& frame,
63 size_t prev_dropped_packets,
64 packet::timestamp_t prev_packet_samples);
65
66 void update_packet_();
67 packet::PacketPtr read_packet_();
68
69 packet::IReader& reader_;
70 IFrameDecoder& payload_decoder_;
71
72 const packet::channel_mask_t channels_;
73 const size_t num_channels_;
74
75 packet::PacketPtr packet_;
76
77 packet::timestamp_t timestamp_;
78
79 packet::timestamp_t zero_samples_;
80 packet::timestamp_t missing_samples_;
81 packet::timestamp_t packet_samples_;
82
83 core::RateLimiter rate_limiter_;
84
85 bool first_packet_;
86 bool beep_;
87
88 size_t dropped_packets_;
89};
90
91} // namespace audio
92} // namespace roc
93
94#endif // ROC_AUDIO_DEPACKETIZER_H_
virtual void read(Frame &frame)
Read audio frame.
bool started() const
Did depacketizer catch first packet?
packet::timestamp_t timestamp() const
Get next timestamp to be rendered.
Depacketizer(packet::IReader &reader, IFrameDecoder &payload_decoder, packet::channel_mask_t channels, bool beep)
Initialization.
Audio frame.
Definition: frame.h:22
Audio frame decoder interface.
Audio reader interface.
Definition: ireader.h:22
Base class for non-copyable objects.
Definition: noncopyable.h:23
Packet reader interface.
Definition: ireader.h:21
Audio frame decoder interface.
float sample_t
Audio sample.
Definition: units.h:21
uint32_t timestamp_t
Audio packet timestamp.
Definition: units.h:46
uint32_t channel_mask_t
Bitmask of channels present in audio packet.
Definition: units.h:77
Root namespace.
Non-copyable object.
Rate limiter.
Audio reader interface.
Various units used in audio processing.
Packet reader interface.