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 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_audio/depacketizer.h
10//! @brief Depacketizer.
11
12#ifndef ROC_AUDIO_DEPACKETIZER_H_
13#define ROC_AUDIO_DEPACKETIZER_H_
14
17#include "roc_audio/sample.h"
21#include "roc_packet/ireader.h"
22
23namespace roc {
24namespace audio {
25
26//! Depacketizer.
27//! @remarks
28//! Reads packets from a packet reader, decodes samples from packets using a
29//! decoder, and produces an audio stream.
31public:
32 //! Initialization.
33 //!
34 //! @b Parameters
35 //! - @p reader is used to read packets
36 //! - @p payload_decoder is used to extract samples from packets
37 //! - @p sample_spec defines a set of channels in the output frames
38 //! - @p beep enables weird beeps instead of silence on packet loss
40 IFrameDecoder& payload_decoder,
41 const audio::SampleSpec& sample_spec,
42 bool beep);
43
44 //! Read audio frame.
45 virtual bool read(Frame& frame);
46
47 //! Did depacketizer catch first packet?
48 bool started() const;
49
50 //! Get next timestamp to be rendered.
51 //! @pre
52 //! started() should return true
54
55private:
56 struct FrameInfo {
57 // Number of samples decoded from packets into the frame.
58 size_t n_decoded_samples;
59
60 // Number of packets dropped during frame construction.
61 size_t n_dropped_packets;
62
63 FrameInfo()
64 : n_decoded_samples(0)
65 , n_dropped_packets(0) {
66 }
67 };
68
69 void read_frame_(Frame& frame);
70
71 sample_t* read_samples_(sample_t* buff_ptr, sample_t* buff_end, FrameInfo& info);
72
73 sample_t* read_packet_samples_(sample_t* buff_ptr, sample_t* buff_end);
74 sample_t* read_missing_samples_(sample_t* buff_ptr, sample_t* buff_end);
75
76 void update_packet_(FrameInfo& info);
77 packet::PacketPtr read_packet_();
78
79 void set_frame_flags_(Frame& frame, const FrameInfo& info);
80
81 void report_stats_();
82
83 packet::IReader& reader_;
84 IFrameDecoder& payload_decoder_;
85
86 const audio::SampleSpec sample_spec_;
87
88 packet::PacketPtr packet_;
89
90 packet::timestamp_t timestamp_;
91
92 packet::timestamp_t zero_samples_;
93 packet::timestamp_t missing_samples_;
94 packet::timestamp_t packet_samples_;
95
96 core::RateLimiter rate_limiter_;
97
98 bool first_packet_;
99 bool beep_;
100};
101
102} // namespace audio
103} // namespace roc
104
105#endif // ROC_AUDIO_DEPACKETIZER_H_
Depacketizer(packet::IReader &reader, IFrameDecoder &payload_decoder, const audio::SampleSpec &sample_spec, bool beep)
Initialization.
virtual bool 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.
Audio frame.
Definition frame.h:22
Audio frame decoder interface.
Frame reader interface.
Sample stream specification. Defines sample rate and channel layout.
Definition sample_spec.h:24
Base class for non-copyable objects.
Definition noncopyable.h:23
Packet reader interface.
Definition ireader.h:21
Audio frame decoder interface.
Frame reader interface.
Packet reader interface.
float sample_t
Audio sample.
Definition sample.h:22
uint32_t timestamp_t
Audio packet timestamp.
Definition units.h:25
Root namespace.
Non-copyable object.
Rate limiter.
Audio sample.
Sample specifications.