mirror of
https://github.com/outbackdingo/UltraGrid.git
synced 2026-03-21 08:40:19 +00:00
@@ -60,7 +60,6 @@
|
||||
#include <cstring>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
@@ -1053,43 +1052,6 @@ static int find_codec_sample_rate(int sample_rate, const int *supported) {
|
||||
return rate_hi > 0 ? rate_hi : rate_lo;
|
||||
}
|
||||
|
||||
void
|
||||
audio_compress_send_native(struct rtp *audio_network_device,
|
||||
struct audio_codec_state *audio_encoder,
|
||||
struct tx *tx_session, void *fec_state,
|
||||
audio_frame2 *uncompressed)
|
||||
{
|
||||
auto *fec_ = (fec *) fec_state;
|
||||
if (incompatible_features) {
|
||||
audio_tx_data *data = nullptr;
|
||||
list<audio_frame2> buffers; // retain ptrs referenced by data
|
||||
while (audio_frame2 to_send =
|
||||
audio_codec_compress(audio_encoder, uncompressed)) {
|
||||
if (fec_state != nullptr) {
|
||||
to_send = fec_->encode(to_send);
|
||||
}
|
||||
data = to_send.append_tx_data(data);
|
||||
buffers.push_back(std::move(to_send));
|
||||
uncompressed = nullptr;
|
||||
}
|
||||
if (data != nullptr) {
|
||||
audio_tx_send(tx_session, audio_network_device, data);
|
||||
audio_tx_data_cleanup(data);
|
||||
}
|
||||
} else {
|
||||
while (audio_frame2 to_send =
|
||||
audio_codec_compress(audio_encoder, uncompressed)) {
|
||||
if (fec_state != nullptr) {
|
||||
to_send = fec_->encode(to_send);
|
||||
}
|
||||
audio_tx_data *data = to_send.append_tx_data(nullptr);
|
||||
audio_tx_send(tx_session, audio_network_device, data);
|
||||
audio_tx_data_cleanup(data);
|
||||
uncompressed = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void *audio_sender_thread(void *arg)
|
||||
{
|
||||
set_thread_name(__func__);
|
||||
@@ -1165,9 +1127,15 @@ static void *audio_sender_thread(void *arg)
|
||||
process_statistics(s, &bf_n);
|
||||
// SEND
|
||||
if(s->sender == NET_NATIVE) {
|
||||
audio_compress_send_native(
|
||||
s->audio_network_device, s->audio_encoder,
|
||||
s->tx_session, s->fec_state, &bf_n);
|
||||
audio_frame2 *uncompressed = &bf_n;
|
||||
while (audio_frame2 to_send = audio_codec_compress(s->audio_encoder, uncompressed)) {
|
||||
if (s->fec_state != nullptr) {
|
||||
to_send = s->fec_state->encode(to_send);
|
||||
}
|
||||
audio_tx_data tx = to_send.get_tx_data();
|
||||
audio_tx_send(s->tx_session, s->audio_network_device, &tx);
|
||||
uncompressed = NULL;
|
||||
}
|
||||
}else if(s->sender == NET_STANDARD){
|
||||
audio_frame2 *uncompressed = &bf_n;
|
||||
while (audio_frame2 compressed = audio_codec_compress(s->audio_encoder, uncompressed)) {
|
||||
|
||||
@@ -84,11 +84,6 @@ int audio_init(struct state_audio **state, struct module *parent,
|
||||
long long int bitrate, volatile int *audio_delay,
|
||||
time_ns_t start_time,
|
||||
int mtu, int ttl, struct exporter *exporter);
|
||||
|
||||
void audio_compress_send_native(struct rtp *audio_network_device,
|
||||
struct audio_codec_state *audio_encoder,
|
||||
struct tx *tx_session, void *fec_state,
|
||||
audio_frame2 *uncompressed);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -42,7 +42,6 @@
|
||||
#include "config_win32.h"
|
||||
#endif
|
||||
|
||||
#include "audio/audio.h"
|
||||
#include "audio/audio_capture.h"
|
||||
#include "audio/audio_playback.h"
|
||||
#include "audio/codec.h"
|
||||
@@ -358,9 +357,11 @@ void state_audio_mixer::worker()
|
||||
participant_index = 0;
|
||||
for (auto & p : participants) {
|
||||
audio_frame2 *uncompressed = &participant_frames[participant_index];
|
||||
audio_compress_send_native(
|
||||
p.second.m_network_device, p.second.m_audio_coder,
|
||||
p.second.m_tx_session, nullptr, uncompressed);
|
||||
while (audio_frame2 compressed = audio_codec_compress(p.second.m_audio_coder, uncompressed)) {
|
||||
audio_tx_data tx = compressed.get_tx_data();
|
||||
audio_tx_send(p.second.m_tx_session, p.second.m_network_device, &tx);
|
||||
uncompressed = nullptr;
|
||||
}
|
||||
|
||||
participant_index++;
|
||||
}
|
||||
|
||||
@@ -49,7 +49,6 @@
|
||||
#include "host.h"
|
||||
#include "utils/macros.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <chrono>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
@@ -372,37 +371,21 @@ bool audio_frame2::resample(audio_frame2_resampler & resampler_state, int new_sa
|
||||
return true;
|
||||
}
|
||||
|
||||
audio_tx_data *
|
||||
audio_frame2::append_tx_data(audio_tx_data *src)
|
||||
audio_tx_data
|
||||
audio_frame2::get_tx_data()
|
||||
{
|
||||
if (src == nullptr) {
|
||||
src = new audio_tx_data;
|
||||
src->timestamp = get_timestamp();
|
||||
src->desc = get_desc();
|
||||
src->channels = new audio_tx_channel[get_channel_count()];
|
||||
for (int i = 0; i < get_channel_count(); ++i) {
|
||||
src->channels[i].pkt_count = 0;
|
||||
}
|
||||
} else {
|
||||
assert(src->desc == get_desc());
|
||||
}
|
||||
tx_channels.resize(get_channel_count());
|
||||
audio_tx_data ret{};
|
||||
ret.desc = get_desc();
|
||||
ret.timestamp = get_timestamp();
|
||||
ret.channels = tx_channels.data();
|
||||
|
||||
for (int i = 0; i < get_channel_count(); ++i) {
|
||||
const int idx = src->channels[i].pkt_count;
|
||||
assert(idx < TX_MAX_AUDIO_PACKETS);
|
||||
|
||||
src->channels[i].pkts[idx].data = get_data(i);
|
||||
src->channels[i].pkts[idx].len = (int) get_data_len(i);
|
||||
src->channels[i].pkts[idx].fec_desc = get_fec_params(i);
|
||||
src->channels[i].pkt_count += 1;
|
||||
ret.channels[i].pkt_count = 1;
|
||||
ret.channels[i].pkts[0].data = get_data(i);
|
||||
ret.channels[i].pkts[0].len = (int) get_data_len(i);
|
||||
ret.channels[i].pkts[0].fec_desc = get_fec_params(i);
|
||||
}
|
||||
|
||||
return src;
|
||||
}
|
||||
|
||||
void
|
||||
audio_tx_data_cleanup(audio_tx_data *d)
|
||||
{
|
||||
delete d->channels;
|
||||
delete d;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -145,7 +145,6 @@ struct audio_tx_data {
|
||||
int64_t timestamp; ///< -1 if not valid
|
||||
struct audio_tx_channel *channels;
|
||||
};
|
||||
void audio_tx_data_cleanup(struct audio_tx_data *d);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <memory>
|
||||
@@ -212,7 +211,7 @@ public:
|
||||
bool resample(audio_frame2_resampler &resampler_state, int new_sample_rate);
|
||||
///@ resamples to new sample rate while keeping nominal sample rate intact
|
||||
std::tuple<bool, audio_frame2> resample_fake(audio_frame2_resampler & resampler_state, int new_sample_rate_num, int new_sample_rate_den);
|
||||
audio_tx_data *append_tx_data(audio_tx_data *src);
|
||||
audio_tx_data get_tx_data();
|
||||
private:
|
||||
struct channel {
|
||||
std::unique_ptr<char []> data;
|
||||
@@ -226,6 +225,7 @@ private:
|
||||
std::vector<channel> channels; /* data should be at least 4B aligned */
|
||||
double duration = 0.0; ///< for compressed formats where this cannot be directly determined from samples/sample_rate
|
||||
int64_t timestamp = -1;
|
||||
std::vector<audio_tx_channel> tx_channels;
|
||||
|
||||
friend class audio_frame2_resampler;
|
||||
friend class soxr_resampler;
|
||||
|
||||
@@ -772,10 +772,10 @@ tx_send_base(struct tx *tx, struct video_frame *frame, struct rtp *rtp_session,
|
||||
free(rtp_headers);
|
||||
}
|
||||
|
||||
static void audio_tx_send_pkt(struct tx *tx, struct rtp *rtp_session,
|
||||
uint32_t timestamp,
|
||||
const struct audio_tx_data *buffer, int channel,
|
||||
int packet, int buflen, int pktoff, bool send_m);
|
||||
static void audio_tx_send_chan(struct tx *tx, struct rtp *rtp_session,
|
||||
uint32_t timestamp,
|
||||
const struct audio_tx_data *buffer, int channel,
|
||||
int packet, bool send_m);
|
||||
|
||||
/*
|
||||
* This multiplication scheme relies upon the fact, that our RTP/pbuf implementation is
|
||||
@@ -798,37 +798,20 @@ audio_tx_send(struct tx *tx, struct rtp *rtp_session,
|
||||
|
||||
for (int iter = 0; iter < tx->mult_count; ++iter) {
|
||||
for (int chan = 0; chan < buffer->desc.ch_count; ++chan) {
|
||||
int buflen = 0;
|
||||
for (int pkt = 0; pkt < buffer->channels[chan].pkt_count;
|
||||
++pkt) {
|
||||
buflen += buffer->channels[chan].pkts[pkt].len;
|
||||
}
|
||||
int pktoff = 0;
|
||||
for (int pkt = 0; pkt < buffer->channels[chan].pkt_count;
|
||||
++pkt) {
|
||||
bool send_m =
|
||||
iter == tx->mult_count - 1 &&
|
||||
chan == buffer->desc.ch_count - 1 &&
|
||||
pkt == buffer->channels[chan].pkt_count - 1;
|
||||
audio_tx_send_pkt(tx, rtp_session, timestamp,
|
||||
buffer, chan, pkt, buflen,
|
||||
pktoff, send_m);
|
||||
pktoff += buffer->channels[chan].pkts[pkt].len;
|
||||
}
|
||||
bool send_m = iter == tx->mult_count - 1 &&
|
||||
chan == buffer->desc.ch_count - 1;
|
||||
assert(buffer->channels[chan].pkt_count == 1);
|
||||
audio_tx_send_chan(tx, rtp_session, timestamp, buffer,
|
||||
chan, 0, send_m);
|
||||
}
|
||||
}
|
||||
|
||||
tx->buffer++;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param buflen aggregate size of all audio packages to be sent
|
||||
* @param pktoff offset of the audio packet inside the buffer
|
||||
*/
|
||||
static void
|
||||
audio_tx_send_pkt(struct tx *tx, struct rtp *rtp_session, uint32_t timestamp,
|
||||
const struct audio_tx_data *buffer, int channel, int packet,
|
||||
int buflen, int pktoff, bool send_m)
|
||||
audio_tx_send_chan(struct tx *tx, struct rtp *rtp_session, uint32_t timestamp,
|
||||
const struct audio_tx_data *buffer, int channel, int packet, bool send_m)
|
||||
{
|
||||
const struct audio_tx_pkt *pkt = &buffer->channels[channel].pkts[packet];
|
||||
|
||||
@@ -850,7 +833,7 @@ audio_tx_send_pkt(struct tx *tx, struct rtp *rtp_session, uint32_t timestamp,
|
||||
if (pkt->fec_desc.type == FEC_NONE) {
|
||||
hdrs_len += (sizeof(audio_payload_hdr_t));
|
||||
rtp_hdr_len = sizeof(audio_payload_hdr_t);
|
||||
format_audio_header(buffer->desc, channel, buflen, tx->buffer,
|
||||
format_audio_header(buffer->desc, channel, len, tx->buffer,
|
||||
rtp_hdr);
|
||||
} else {
|
||||
hdrs_len += (sizeof(fec_payload_hdr_t));
|
||||
@@ -859,7 +842,7 @@ audio_tx_send_pkt(struct tx *tx, struct rtp *rtp_session, uint32_t timestamp,
|
||||
tmp |= 0x3fffff & tx->buffer;
|
||||
// see definition in rtp_callback.h
|
||||
rtp_hdr[0] = htonl(tmp);
|
||||
rtp_hdr[2] = htonl(buflen);
|
||||
rtp_hdr[2] = htonl(len);
|
||||
rtp_hdr[3] = htonl(pkt->fec_desc.k << 19 |
|
||||
pkt->fec_desc.m << 6 |
|
||||
pkt->fec_desc.c);
|
||||
@@ -888,7 +871,7 @@ audio_tx_send_pkt(struct tx *tx, struct rtp *rtp_session, uint32_t timestamp,
|
||||
m = 1;
|
||||
}
|
||||
}
|
||||
rtp_hdr[1] = htonl(pktoff + pos);
|
||||
rtp_hdr[1] = htonl(pos);
|
||||
pos += data_len;
|
||||
|
||||
char encrypted_data[data_len + MAX_CRYPTO_EXCEED];
|
||||
|
||||
Reference in New Issue
Block a user