mirror of
https://github.com/outbackdingo/UltraGrid.git
synced 2026-03-21 11:40:22 +00:00
audio_frame2: added const semantics
This commit is contained in:
@@ -841,7 +841,7 @@ static void *audio_sender_thread(void *arg)
|
||||
process_statistics(s, &buffer_new);
|
||||
free(resample_state.resampled.data);
|
||||
audio_frame2 *uncompressed = &buffer_new;
|
||||
audio_frame2 *compressed = NULL;
|
||||
const audio_frame2 *compressed = NULL;
|
||||
while((compressed = audio_codec_compress(s->audio_coder, uncompressed))) {
|
||||
audio_tx_send(s->tx_session, s->audio_network_device, compressed);
|
||||
uncompressed = NULL;
|
||||
@@ -853,7 +853,7 @@ static void *audio_sender_thread(void *arg)
|
||||
buffer_new = audio_frame2(&resample_state.resampled);
|
||||
free(resample_state.resampled.data);
|
||||
audio_frame2 *uncompressed = &buffer_new;
|
||||
audio_frame2 *compressed = NULL;
|
||||
const audio_frame2 *compressed = NULL;
|
||||
while((compressed = audio_codec_compress(s->audio_coder, uncompressed))) {
|
||||
//TODO to be dynamic as a function of the selected codec, now only accepting mulaw without checking errors
|
||||
audio_tx_send_standard(s->tx_session, s->audio_network_device, compressed);
|
||||
|
||||
@@ -92,7 +92,7 @@ typedef struct
|
||||
{
|
||||
int bps; /* bytes per sample */
|
||||
int sample_rate;
|
||||
char *data; /* data should be at least 4B aligned */
|
||||
const char *data; /* data should be at least 4B aligned */
|
||||
int data_len; /* size of useful data in buffer */
|
||||
audio_codec_t codec;
|
||||
double duration;
|
||||
@@ -109,6 +109,7 @@ class audio_frame2
|
||||
{
|
||||
public:
|
||||
audio_frame2();
|
||||
audio_frame2(audio_frame2&& other) = default;
|
||||
audio_frame2(struct audio_frame *);
|
||||
audio_frame2& operator=(audio_frame2&& other) = default;
|
||||
void init(int nr_channels, audio_codec_t codec, int bps, int sample_rate);
|
||||
@@ -117,15 +118,15 @@ public:
|
||||
void replace(int channel, size_t offset, const char *data, size_t length);
|
||||
void resize(int channel, size_t len);
|
||||
void reset();
|
||||
int get_bps();
|
||||
audio_codec_t get_codec();
|
||||
const char *get_data(int channel);
|
||||
size_t get_data_len(int channel);
|
||||
double get_duration();
|
||||
int get_channel_count();
|
||||
int get_sample_count();
|
||||
int get_sample_rate();
|
||||
bool has_same_prop_as(audio_frame2 const &frame);
|
||||
int get_bps() const;
|
||||
audio_codec_t get_codec() const;
|
||||
const char *get_data(int channel) const;
|
||||
size_t get_data_len(int channel) const;
|
||||
double get_duration() const;
|
||||
int get_channel_count() const;
|
||||
int get_sample_count() const;
|
||||
int get_sample_rate() const;
|
||||
bool has_same_prop_as(audio_frame2 const &frame) const;
|
||||
void set_duration(double duration);
|
||||
private:
|
||||
int bps; /* bytes per sample */
|
||||
|
||||
@@ -223,7 +223,7 @@ struct audio_codec_state *audio_codec_reconfigure(struct audio_codec_state *old,
|
||||
* @retval pointer pointing to data
|
||||
* @retval NULL indicating that there are no data left
|
||||
*/
|
||||
audio_frame2 *audio_codec_compress(struct audio_codec_state *s, audio_frame2 *frame)
|
||||
const audio_frame2 *audio_codec_compress(struct audio_codec_state *s, const audio_frame2 *frame)
|
||||
{
|
||||
if(frame && s->state_count < frame->get_channel_count()) {
|
||||
s->state = (void **) realloc(s->state, sizeof(void **) * frame->get_channel_count());
|
||||
|
||||
@@ -85,7 +85,7 @@ struct audio_codec_state *audio_codec_init(audio_codec_t audio_codec, audio_code
|
||||
struct audio_codec_state *audio_codec_init_cfg(const char *audio_codec_cfg, audio_codec_direction_t);
|
||||
struct audio_codec_state *audio_codec_reconfigure(struct audio_codec_state *old,
|
||||
audio_codec_t audio_codec, audio_codec_direction_t);
|
||||
audio_frame2 *audio_codec_compress(struct audio_codec_state *, audio_frame2 *);
|
||||
const audio_frame2 *audio_codec_compress(struct audio_codec_state *, const audio_frame2 *);
|
||||
audio_frame2 *audio_codec_decompress(struct audio_codec_state *, audio_frame2 *);
|
||||
const int *audio_codec_get_supported_bps(struct audio_codec_state *);
|
||||
void audio_codec_done(struct audio_codec_state *);
|
||||
|
||||
@@ -341,11 +341,11 @@ static audio_channel *libavcodec_compress(void *state, audio_channel * channel)
|
||||
}
|
||||
|
||||
if(s->change_bps_to) {
|
||||
change_bps(s->tmp.data, s->saved_desc.bps, channel->data,
|
||||
change_bps((char *) s->tmp.data, s->saved_desc.bps, channel->data,
|
||||
s->change_bps_to, channel->data_len);
|
||||
s->tmp.data_len += channel->data_len / s->saved_desc.bps * s->change_bps_to;
|
||||
} else {
|
||||
memcpy(s->tmp.data + s->tmp.data_len, channel->data, channel->data_len);
|
||||
memcpy((char *) s->tmp.data + s->tmp.data_len, channel->data, channel->data_len);
|
||||
s->tmp.data_len += channel->data_len;
|
||||
}
|
||||
}
|
||||
@@ -382,7 +382,7 @@ static audio_channel *libavcodec_compress(void *state, audio_channel * channel)
|
||||
}
|
||||
|
||||
s->tmp.data_len -= offset;
|
||||
memmove(s->tmp.data, s->tmp.data + offset, s->tmp.data_len);
|
||||
memmove((char *) s->tmp.data, s->tmp.data + offset, s->tmp.data_len);
|
||||
|
||||
///fprintf(stderr, "%d %d\n", i++% 2, s->output_channel.data_len);
|
||||
if(s->output_channel.data_len) {
|
||||
@@ -425,7 +425,7 @@ static audio_channel *libavcodec_decompress(void *state, audio_channel * channel
|
||||
int data_size = av_samples_get_buffer_size(NULL, channels,
|
||||
s->av_frame->nb_samples,
|
||||
s->codec_ctx->sample_fmt, 1);
|
||||
memcpy(s->output_channel.data + offset, s->av_frame->data[0],
|
||||
memcpy((char *) s->output_channel.data + offset, s->av_frame->data[0],
|
||||
data_size);
|
||||
offset += len;
|
||||
s->output_channel.data_len += data_size;
|
||||
@@ -461,8 +461,8 @@ static void libavcodec_done(void *state)
|
||||
pthread_mutex_unlock(s->libav_global_lock);
|
||||
|
||||
rm_release_shared_lock(LAVCD_LOCK_NAME);
|
||||
free(s->output_channel.data);
|
||||
free(s->tmp.data);
|
||||
free((void *) s->output_channel.data);
|
||||
free((void *) s->tmp.data);
|
||||
av_free_packet(&s->pkt);
|
||||
av_freep(&s->samples);
|
||||
#if LIBAVCODEC_VERSION_MAJOR >= 54
|
||||
|
||||
@@ -34,7 +34,7 @@ void resampler_done(struct resampler *s)
|
||||
free(s);
|
||||
}
|
||||
|
||||
audio_frame2 *resampler_resample(struct resampler *s, audio_frame2 *frame)
|
||||
const audio_frame2 *resampler_resample(struct resampler *s, const audio_frame2 *frame)
|
||||
{
|
||||
if(s->resample_to == frame->get_sample_rate()) {
|
||||
return frame;
|
||||
|
||||
@@ -14,7 +14,7 @@ struct resampler;
|
||||
|
||||
struct resampler *resampler_init(int dst_sample_rate);
|
||||
void resampler_done(struct resampler *);
|
||||
audio_frame2 *resampler_resample(struct resampler *, audio_frame2 *);
|
||||
const audio_frame2 *resampler_resample(struct resampler *, const audio_frame2 *);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -175,27 +175,27 @@ void audio_frame2::reset()
|
||||
duration = 0.0;
|
||||
}
|
||||
|
||||
int audio_frame2::get_bps()
|
||||
int audio_frame2::get_bps() const
|
||||
{
|
||||
return bps;
|
||||
}
|
||||
|
||||
audio_codec_t audio_frame2::get_codec()
|
||||
audio_codec_t audio_frame2::get_codec() const
|
||||
{
|
||||
return codec;
|
||||
}
|
||||
|
||||
const char *audio_frame2::get_data(int channel)
|
||||
const char *audio_frame2::get_data(int channel) const
|
||||
{
|
||||
return channels[channel].first.get();
|
||||
}
|
||||
|
||||
size_t audio_frame2::get_data_len(int channel)
|
||||
size_t audio_frame2::get_data_len(int channel) const
|
||||
{
|
||||
return channels[channel].second;
|
||||
}
|
||||
|
||||
double audio_frame2::get_duration()
|
||||
double audio_frame2::get_duration() const
|
||||
{
|
||||
if (codec == AC_PCM) {
|
||||
int samples = get_sample_count();
|
||||
@@ -205,12 +205,12 @@ double audio_frame2::get_duration()
|
||||
}
|
||||
}
|
||||
|
||||
int audio_frame2::get_channel_count()
|
||||
int audio_frame2::get_channel_count() const
|
||||
{
|
||||
return channels.size();
|
||||
}
|
||||
|
||||
int audio_frame2::get_sample_count()
|
||||
int audio_frame2::get_sample_count() const
|
||||
{
|
||||
// for PCM, we can deduce samples count from length of the data
|
||||
if (codec == AC_PCM) {
|
||||
@@ -220,12 +220,13 @@ int audio_frame2::get_sample_count()
|
||||
}
|
||||
}
|
||||
|
||||
int audio_frame2::get_sample_rate()
|
||||
int audio_frame2::get_sample_rate() const
|
||||
{
|
||||
return sample_rate;
|
||||
}
|
||||
|
||||
bool audio_frame2::has_same_prop_as(audio_frame2 const &frame) {
|
||||
bool audio_frame2::has_same_prop_as(audio_frame2 const &frame) const
|
||||
{
|
||||
return bps == frame.bps &&
|
||||
sample_rate == frame.sample_rate &&
|
||||
codec == frame.codec &&
|
||||
@@ -514,9 +515,9 @@ void signed2unsigned(char *out, char *in, int in_len)
|
||||
}
|
||||
}
|
||||
|
||||
void audio_channel_demux(audio_frame2 *frame, int index, audio_channel *channel)
|
||||
void audio_channel_demux(const audio_frame2 *frame, int index, audio_channel *channel)
|
||||
{
|
||||
channel->data = (char *) frame->get_data(index);
|
||||
channel->data = frame->get_data(index);
|
||||
channel->data_len = frame->get_data_len(index);
|
||||
channel->codec = frame->get_codec();
|
||||
channel->bps = frame->get_bps();
|
||||
|
||||
@@ -63,7 +63,7 @@ int audio_frame2_get_sample_count(audio_frame2 *frame);
|
||||
void audio_frame2_reset(audio_frame2 *frame);
|
||||
double calculate_rms(audio_frame2 *frame, int channel, double *peak);
|
||||
struct audio_desc audio_desc_from_audio_frame2(audio_frame2 *);
|
||||
void audio_channel_demux(audio_frame2 *, int, audio_channel*);
|
||||
void audio_channel_demux(const audio_frame2 *, int, audio_channel*);
|
||||
void audio_channel_mux(audio_frame2 *, int, audio_channel*);
|
||||
#endif
|
||||
|
||||
|
||||
@@ -513,7 +513,7 @@ int decode_audio_frame(struct coded_data *cdata, void *data)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
audio_frame2 *resampled = resampler_resample(decoder->resampler, decompressed);
|
||||
const audio_frame2 *resampled = resampler_resample(decoder->resampler, decompressed);
|
||||
|
||||
size_t new_data_len = s->buffer.data_len + resampled->get_data_len(0) * output_channels;
|
||||
if(s->buffer.max_size < new_data_len) {
|
||||
|
||||
@@ -67,7 +67,6 @@
|
||||
#include "perf.h"
|
||||
#include "audio/audio.h"
|
||||
#include "audio/codec.h"
|
||||
#include "audio/utils.h"
|
||||
#include "crypto/openssl_encrypt.h"
|
||||
#include "module.h"
|
||||
#include "rtp/fec.h"
|
||||
@@ -633,7 +632,7 @@ tx_send_base(struct tx *tx, struct video_frame *frame, struct rtp *rtp_session,
|
||||
* This multiplication scheme relies upon the fact, that our RTP/pbuf implementation is
|
||||
* not sensitive to packet duplication. Otherwise, we can get into serious problems.
|
||||
*/
|
||||
void audio_tx_send(struct tx* tx, struct rtp *rtp_session, audio_frame2 * buffer)
|
||||
void audio_tx_send(struct tx* tx, struct rtp *rtp_session, const audio_frame2 * buffer)
|
||||
{
|
||||
int pt; /* PT set for audio in our packet format */
|
||||
unsigned int pos = 0u,
|
||||
@@ -794,7 +793,7 @@ void audio_tx_send(struct tx* tx, struct rtp *rtp_session, audio_frame2 * buffer
|
||||
* as the mulaw and A-law standards (dynamic or std PT).
|
||||
*/
|
||||
void audio_tx_send_standard(struct tx* tx, struct rtp *rtp_session,
|
||||
audio_frame2 * buffer) {
|
||||
const audio_frame2 * buffer) {
|
||||
//TODO to be more abstract in order to accept A-law too and other supported standards with such implementation
|
||||
assert(buffer->get_codec() == AC_MULAW || buffer->get_codec() == AC_ALAW);
|
||||
|
||||
|
||||
@@ -86,8 +86,8 @@ void tx_send_h264(struct tx *tx_session, struct video_frame *frame, struct rtp *
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
void audio_tx_send(struct tx *tx_session, struct rtp *rtp_session, audio_frame2 *buffer);
|
||||
void audio_tx_send_standard(struct tx* tx, struct rtp *rtp_session, audio_frame2 * buffer);
|
||||
void audio_tx_send(struct tx *tx_session, struct rtp *rtp_session, const audio_frame2 *buffer);
|
||||
void audio_tx_send_standard(struct tx* tx, struct rtp *rtp_session, const audio_frame2 * buffer);
|
||||
#endif
|
||||
|
||||
#endif // TRANSMIT_H_
|
||||
|
||||
Reference in New Issue
Block a user