Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Loading...
Searching...
No Matches
frame.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017 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/frame.h
10//! @brief Audio frame.
11
12#ifndef ROC_AUDIO_FRAME_H_
13#define ROC_AUDIO_FRAME_H_
14
15#include "roc_audio/sample.h"
18#include "roc_core/time.h"
19#include "roc_packet/units.h"
20
21namespace roc {
22namespace audio {
23
24//! Audio frame.
25class Frame : public core::NonCopyable<> {
26public:
27 //! Construct frame from raw samples.
28 //! Flags are set to zero.
29 Frame(sample_t* samples, size_t num_samples);
30
31 //! Construct frame from bytes.
32 //! Flags are set to zero.
33 Frame(uint8_t* bytes, size_t num_bytes);
34
35 //! Frame flags.
36 //! Flags are designed the way so that if you combine multiple frames into one,
37 //! (concatenate or mix), bitwise OR of their flags will give flags for resulting
38 //! frame. E.g., if at least one frame was non-blank, combined frame will be
39 //! non-blank, if at least one frame was incomplete, combined frame will be
40 //! incomplete, etc.
41 enum {
42 //! Set if the frame has format different from raw samples.
43 //! If this flag is set, only bytes() can be used, and raw_samples() panics.
44 FlagNotRaw = (1 << 0),
45
46 //! Set if the frame has at least some samples from packets.
47 //! If this flag is clear, frame is completely zero because of lack of packets.
48 FlagNotBlank = (1 << 1),
49
50 //! Set if the frame is not fully filled with samples from packets.
51 //! If this flag is set, frame is partially zero because of lack of packets.
52 FlagNotComplete = (1 << 2),
53
54 //! Set if some late packets were dropped while the frame was being built.
55 //! It's not necessarily that the frame itself is blank or incomplete.
56 FlagPacketDrops = (1 << 3)
57 };
58
59 //! Get flags.
60 unsigned flags() const;
61
62 //! Set flags.
63 void set_flags(unsigned flags);
64
65 //! Check frame data is raw samples.
66 //! Returns true if FlagAltFormat is not set.
67 bool is_raw() const;
68
69 //! Get frame data as raw samples.
70 //! May be used only if is_raw() is true, otherwise use bytes().
72
73 //! Get number of raw samples in frame,
74 //! May be used only if is_raw() is true, otherwise use num_bytes().
75 size_t num_raw_samples() const;
76
77 //! Get frame data as bytes.
78 uint8_t* bytes() const;
79
80 //! Get number of bytes in frame.
81 size_t num_bytes() const;
82
83 //! Check if duration was set.
84 bool has_duration() const;
85
86 //! Get frame duration in terms of stream timestamps.
88
89 //! Get frame duration in terms of stream timestamps.
91
92 //! Check if capture timestamp is set.
94
95 //! Get unix-epoch timestamp in ns of the 1st sample.
97
98 //! Set unix-epoch timestamp in ns of the 1st sample.
100
101 //! Print frame to stderr.
102 void print() const;
103
104private:
105 uint8_t* bytes_;
106 size_t num_bytes_;
107 unsigned flags_;
109 core::nanoseconds_t capture_timestamp_;
110};
111
112} // namespace audio
113} // namespace roc
114
115#endif // ROC_AUDIO_FRAME_H_
Audio frame.
Definition frame.h:25
void set_flags(unsigned flags)
Set flags.
packet::stream_timestamp_t duration() const
Get frame duration in terms of stream timestamps.
uint8_t * bytes() const
Get frame data as bytes.
unsigned flags() const
Get flags.
bool is_raw() const
Check frame data is raw samples. Returns true if FlagAltFormat is not set.
bool has_duration() const
Check if duration was set.
size_t num_raw_samples() const
Get number of raw samples in frame, May be used only if is_raw() is true, otherwise use num_bytes().
void set_duration(packet::stream_timestamp_t duration)
Get frame duration in terms of stream timestamps.
Frame(sample_t *samples, size_t num_samples)
Construct frame from raw samples. Flags are set to zero.
void print() const
Print frame to stderr.
void set_capture_timestamp(core::nanoseconds_t capture_ts)
Set unix-epoch timestamp in ns of the 1st sample.
sample_t * raw_samples() const
Get frame data as raw samples. May be used only if is_raw() is true, otherwise use bytes().
size_t num_bytes() const
Get number of bytes in frame.
Frame(uint8_t *bytes, size_t num_bytes)
Construct frame from bytes. Flags are set to zero.
@ FlagNotComplete
Set if the frame is not fully filled with samples from packets. If this flag is set,...
Definition frame.h:52
@ FlagPacketDrops
Set if some late packets were dropped while the frame was being built. It's not necessarily that the ...
Definition frame.h:56
@ FlagNotBlank
Set if the frame has at least some samples from packets. If this flag is clear, frame is completely z...
Definition frame.h:48
@ FlagNotRaw
Set if the frame has format different from raw samples. If this flag is set, only bytes() can be used...
Definition frame.h:44
bool has_capture_timestamp() const
Check if capture timestamp is set.
core::nanoseconds_t capture_timestamp() const
Get unix-epoch timestamp in ns of the 1st sample.
Base class for non-copyable objects.
Definition noncopyable.h:23
float sample_t
Raw audio sample.
Definition sample.h:22
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.
Audio sample.
Sample specifications.
Time definitions.
Various units used in packets.