UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
types.h
Go to the documentation of this file.
1
7/*
8 * Copyright (c) 2011-2021 CESNET, z. s. p. o.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, is permitted provided that the following conditions
13 * are met:
14 *
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 *
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 *
22 * 3. Neither the name of CESNET nor the names of its contributors may be
23 * used to endorse or promote products derived from this software without
24 * specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS
27 * "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
28 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
29 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
30 * EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
31 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
32 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
33 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
36 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
37 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 */
39
40#ifndef AUDIO_TYPES_H
41#define AUDIO_TYPES_H
42
43#ifdef __cplusplus
44#include <cstdint>
45#else
46#include <stdint.h>
47#endif
48
49#include "../types.h" // fec_desc
50
64
67enum {
70};
71
72#ifdef __cplusplus
73#include <string>
74#endif
75
76struct audio_desc {
77 int bps; /* bytes per sample */
79 int ch_count; /* count of channels */
81#ifdef __cplusplus
82 bool operator!() const;
83 bool operator==(audio_desc const &) const;
84 operator std::string() const;
85#endif
86};
87
88#ifdef __cplusplus
89#include <ostream>
90std::ostream& operator<<(std::ostream& os, const audio_desc& desc);
91#endif
92
98typedef struct audio_frame
99{
100 int bps; /* bytes per sample */
102 char *data; /* data should be at least 4B aligned */
103 int data_len; /* size of useful data in buffer */
104 int ch_count; /* count of channels */
105 int max_size; /* maximal size of data in buffer */
106 void *network_source; /* pointer to sockaddr_storage containing
107 network source that the audio stream came
108 from. Relevant only for receiver. */
109 int64_t timestamp;
111 int flags;
112 void (*dispose)(struct audio_frame *);
114}
116
117#define AUDIO_FRAME_DISPOSE(frame) if ((frame) && (frame)->dispose) \
118 (frame)->dispose(frame)
119
121typedef struct
122{
123 int bps; /* bytes per sample */
125 const char *data; /* data should be at least 4B aligned */
126 int data_len; /* size of useful data in buffer */
128 int64_t timestamp;
129 double duration;
131
132#ifdef __cplusplus
133#include <memory>
134#include <tuple>
135#include <vector>
136
138
145{
146public:
147 audio_frame2() = default;
148 ~audio_frame2() = default;
149 audio_frame2(audio_frame2 const &) = delete;
151 explicit audio_frame2(const struct audio_frame *);
154 explicit operator bool() const;
155 void init(int nr_channels, audio_codec_t codec, int bps, int sample_rate);
156 void append(audio_frame2 const &frame);
157 void append(int channel, const char *data, size_t length);
158 void replace(int channel, size_t offset, const char *data, size_t length);
159 void reserve(size_t len);
160 void resize(int channel, size_t len);
161 void reset();
162 void set_timestamp(int64_t ts);
163 [[nodiscard]] int get_bps() const;
164 [[nodiscard]] struct audio_desc get_desc() const;
165 [[nodiscard]] audio_codec_t get_codec() const;
166 [[nodiscard]] char *get_data(int channel);
167 [[nodiscard]] const char *get_data(int channel) const;
168 [[nodiscard]] size_t get_data_len(int channel) const;
169 [[nodiscard]] size_t get_data_len() const;
170 [[nodiscard]] double get_duration() const;
171 [[nodiscard]] int get_channel_count() const;
172 [[nodiscard]] fec_desc const &get_fec_params(int channel) const;
173 [[nodiscard]] int get_sample_count() const;
174 [[nodiscard]] int get_sample_rate() const;
175 [[nodiscard]] int64_t get_timestamp() const; // u32 TS, -1 if unavail
176 [[nodiscard]] bool has_same_prop_as(audio_frame2 const &frame) const;
177 void set_duration(double duration);
178 void set_fec_params(int channel, fec_desc const &);
179 [[nodiscard]] static audio_frame2 copy_with_bps_change(audio_frame2 const &frame, int new_bps);
180 void change_bps(int new_bps);
194 bool resample(audio_frame2_resampler &resampler_state, int new_sample_rate);
195
197 std::tuple<bool, audio_frame2> resample_fake(audio_frame2_resampler & resampler_state, int new_sample_rate_num, int new_sample_rate_den);
198private:
199 struct channel {
200 std::unique_ptr<char []> data;
201 size_t len;
202 size_t max_len;
204 };
205 void reserve(int channel, size_t len);
206 struct audio_desc
207 desc = {};
208 std::vector<channel> channels; /* data should be at least 4B aligned */
209 double duration = 0.0;
210 int64_t timestamp = -1;
211
213 friend class soxr_resampler;
214 friend class speex_resampler;
215};
216
217#endif // __cplusplus
218
219#endif // defined AUDIO_TYPES_H
220
struct video_desc desc
int int int sample_rate
struct video_frame * frame
int void size_t * len
audio_codec_t
Definition types.h:51
@ AC_G722
Definition types.h:58
@ AC_AAC
Definition types.h:60
@ AC_OPUS
Definition types.h:57
@ AC_FLAC
Definition types.h:61
@ AC_MULAW
Definition types.h:55
@ AC_SPEEX
Definition types.h:56
@ AC_MP3
Definition types.h:59
@ AC_COUNT
Definition types.h:62
@ AC_PCM
Definition types.h:53
@ AC_ALAW
Definition types.h:54
@ AC_NONE
Definition types.h:52
struct audio_frame audio_frame
struct used to comunicate with audio capture/playback device
@ MAX_AUD_CH_COUNT
Definition types.h:68
@ MAX_AUD_SAMPLE_RATE
Definition types.h:69
std::ostream & operator<<(std::ostream &os, const audio_desc &desc)
Definition audio.cpp:1215
int64_t timestamp
Definition types.h:210
void change_bps(int new_bps)
Definition types.cpp:313
void resize(int channel, size_t len)
Definition types.cpp:183
audio_frame2 & operator=(audio_frame2 &&)=default
char * get_data(int channel)
Definition types.cpp:218
struct audio_desc get_desc() const
Definition types.cpp:205
bool has_same_prop_as(audio_frame2 const &frame) const
Definition types.cpp:280
void set_fec_params(int channel, fec_desc const &)
Definition types.cpp:293
audio_frame2(audio_frame2 const &)=delete
std::vector< channel > channels
Definition types.h:208
void init(int nr_channels, audio_codec_t codec, int bps, int sample_rate)
Initializes audio_frame2 for use. If already initialized, data are dropped.
Definition types.cpp:115
void set_duration(double duration)
Definition types.cpp:288
audio_frame2(audio_frame2 &&)=default
friend class soxr_resampler
Definition types.h:213
void reset()
Definition types.cpp:192
audio_codec_t get_codec() const
Definition types.cpp:213
audio_frame2()=default
void reserve(size_t len)
Definition types.cpp:161
friend class speex_resampler
Definition types.h:214
int get_channel_count() const
Definition types.cpp:260
bool resample(audio_frame2_resampler &resampler_state, int new_sample_rate)
Definition types.cpp:361
audio_frame2 & operator=(audio_frame2 const &)=delete
int64_t get_timestamp() const
Definition types.cpp:340
void replace(int channel, size_t offset, const char *data, size_t length)
replaces portion of data of specified channel. If the size of the channel is not sufficient,...
Definition types.cpp:152
fec_desc const & get_fec_params(int channel) const
Definition types.cpp:255
struct audio_desc desc
desc.ch_count not set, use channels.size() instead
Definition types.h:207
std::tuple< bool, audio_frame2 > resample_fake(audio_frame2_resampler &resampler_state, int new_sample_rate_num, int new_sample_rate_den)
@ resamples to new sample rate while keeping nominal sample rate intact
Definition types.cpp:342
void set_timestamp(int64_t ts)
Definition types.cpp:335
~audio_frame2()=default
double get_duration() const
Definition types.cpp:246
int get_sample_rate() const
Definition types.cpp:275
static audio_frame2 copy_with_bps_change(audio_frame2 const &frame, int new_bps)
Definition types.cpp:298
int get_bps() const
Definition types.cpp:200
size_t get_data_len() const
Definition types.cpp:236
void append(audio_frame2 const &frame)
Definition types.cpp:125
int get_sample_count() const
Definition types.cpp:265
static __device__ const float offset
Definition cuda_dxt.cu:139
steady_clock::duration duration
Definition echo.cpp:67
Audio channel is a non-owning view on audio_frame2 isolating one channel.
Definition types.h:122
audio_codec_t codec
Definition types.h:127
int64_t timestamp
Definition types.h:128
const char * data
Definition types.h:125
int sample_rate
Definition types.h:124
double duration
Definition types.h:129
int data_len
Definition types.h:126
int sample_rate
Definition types.h:78
int ch_count
Definition types.h:79
bool operator==(audio_desc const &) const
Definition types.cpp:69
int bps
Definition types.h:77
audio_codec_t codec
Definition types.h:80
bool operator!() const
Definition types.cpp:64
std::unique_ptr< char[]> data
Definition types.h:200
struct fec_desc fec_params
Definition types.h:203
struct used to comunicate with audio capture/playback device
Definition types.h:99
int sample_rate
Definition types.h:101
int64_t timestamp
Definition types.h:109
char * data
Definition types.h:102
void(* dispose)(struct audio_frame *)
called by sender when frame was processed
Definition types.h:112
int ch_count
Definition types.h:104
int data_len
Definition types.h:103
void * network_source
Definition types.h:106
int flags
Definition types.h:111
int bps
Definition types.h:100
int max_size
Definition types.h:105
void * dispose_udata
additional data that may the caller use in dispose
Definition types.h:113
uint32_t ts
Definition tfrc.c:101
This file contains some common data types.