Revert "audio transmit: new sending API"

This reverts commit bf35242e78.
This commit is contained in:
Martin Pulec
2023-10-16 10:14:32 +02:00
parent cdef66a141
commit 68eeafca5e
6 changed files with 32 additions and 75 deletions

View File

@@ -1132,8 +1132,7 @@ static void *audio_sender_thread(void *arg)
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);
audio_tx_send(s->tx_session, s->audio_network_device, &to_send);
uncompressed = NULL;
}
}else if(s->sender == NET_STANDARD){

View File

@@ -358,8 +358,7 @@ void state_audio_mixer::worker()
for (auto & p : participants) {
audio_frame2 *uncompressed = &participant_frames[participant_index];
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);
audio_tx_send(p.second.m_tx_session, p.second.m_network_device, &compressed);
uncompressed = nullptr;
}

View File

@@ -370,22 +370,3 @@ bool audio_frame2::resample(audio_frame2_resampler & resampler_state, int new_sa
return true;
}
audio_tx_data
audio_frame2::get_tx_data()
{
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) {
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 ret;
}

View File

@@ -128,24 +128,6 @@ typedef struct
double duration;
} audio_channel;
enum {
TX_MAX_AUDIO_PACKETS = 16,
};
struct audio_tx_pkt {
char *data;
int len;
struct fec_desc fec_desc;
};
struct audio_tx_channel {
int pkt_count;
struct audio_tx_pkt pkts[TX_MAX_AUDIO_PACKETS];
};
struct audio_tx_data {
struct audio_desc desc;
int64_t timestamp; ///< -1 if not valid
struct audio_tx_channel *channels;
};
#ifdef __cplusplus
#include <memory>
#include <tuple>
@@ -209,9 +191,9 @@ public:
* @retval false if SpeexDSP was not compiled in
*/
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 get_tx_data();
private:
struct channel {
std::unique_ptr<char []> data;
@@ -225,7 +207,6 @@ 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;

View File

@@ -773,9 +773,8 @@ tx_send_base(struct tx *tx, struct video_frame *frame, struct rtp *rtp_session,
}
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);
uint32_t timestamp, const audio_frame2 *buffer,
int channel, bool send_m);
/*
* This multiplication scheme relies upon the fact, that our RTP/pbuf implementation is
@@ -783,7 +782,7 @@ static void audio_tx_send_chan(struct tx *tx, struct rtp *rtp_session,
*/
void
audio_tx_send(struct tx *tx, struct rtp *rtp_session,
const struct audio_tx_data *buffer)
const audio_frame2 *buffer)
{
if (!rtp_has_receiver(rtp_session)) {
return;
@@ -792,17 +791,16 @@ audio_tx_send(struct tx *tx, struct rtp *rtp_session,
fec_check_messages(tx);
const uint32_t timestamp =
incompatible_features && buffer->timestamp != -1
? get_local_mediatime_offset() + buffer->timestamp
incompatible_features && buffer->get_timestamp() != -1
? get_local_mediatime_offset() + buffer->get_timestamp()
: get_local_mediatime();
for (int iter = 0; iter < tx->mult_count; ++iter) {
for (int chan = 0; chan < buffer->desc.ch_count; ++chan) {
for (int chan = 0; chan < buffer->get_channel_count(); ++chan) {
bool send_m = iter == tx->mult_count - 1 &&
chan == buffer->desc.ch_count - 1;
assert(buffer->channels[chan].pkt_count == 1);
chan == buffer->get_channel_count() - 1;
audio_tx_send_chan(tx, rtp_session, timestamp, buffer,
chan, 0, send_m);
chan, send_m);
}
}
@@ -811,12 +809,10 @@ audio_tx_send(struct tx *tx, struct rtp *rtp_session,
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)
const audio_frame2 *buffer, int channel, bool send_m)
{
const struct audio_tx_pkt *pkt = &buffer->channels[channel].pkts[packet];
int pt = fec_pt_from_fec_type(
TX_MEDIA_AUDIO, pkt->fec_desc.type,
TX_MEDIA_AUDIO, buffer->get_fec_params(0).type,
tx->encryption); /* PT set for audio in our packet format */
unsigned m = 0U;
// see definition in rtp_callback.h
@@ -824,16 +820,17 @@ audio_tx_send_chan(struct tx *tx, struct rtp *rtp_session, uint32_t timestamp,
int rtp_hdr_len = 0;
int hdrs_len = get_tx_hdr_len(rtp_is_ipv6(rtp_session));
const unsigned int fec_symbol_size = pkt->fec_desc.symbol_size;
unsigned int fec_symbol_size =
buffer->get_fec_params(channel).symbol_size;
const char *chan_data = pkt->data;
const unsigned len = pkt->len;
unsigned pos = 0U;
const char *chan_data = buffer->get_data(channel);
unsigned pos = 0U;
if (pkt->fec_desc.type == FEC_NONE) {
if (buffer->get_fec_params(0).type == FEC_NONE) {
hdrs_len += (sizeof(audio_payload_hdr_t));
rtp_hdr_len = sizeof(audio_payload_hdr_t);
format_audio_header(buffer->desc, channel, len, tx->buffer,
format_audio_header(buffer->get_desc(), channel,
buffer->get_data_len(channel), tx->buffer,
rtp_hdr);
} else {
hdrs_len += (sizeof(fec_payload_hdr_t));
@@ -842,11 +839,11 @@ audio_tx_send_chan(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(len);
rtp_hdr[3] = htonl(pkt->fec_desc.k << 19 |
pkt->fec_desc.m << 6 |
pkt->fec_desc.c);
rtp_hdr[4] = htonl(pkt->fec_desc.seed);
rtp_hdr[2] = htonl(buffer->get_data_len(channel));
rtp_hdr[3] = htonl(buffer->get_fec_params(channel).k << 19 |
buffer->get_fec_params(channel).m << 6 |
buffer->get_fec_params(channel).c);
rtp_hdr[4] = htonl(buffer->get_fec_params(channel).seed);
}
if (tx->encryption) {
@@ -857,16 +854,17 @@ audio_tx_send_chan(struct tx *tx, struct rtp *rtp_session, uint32_t timestamp,
rtp_hdr_len += sizeof(crypto_payload_hdr_t);
}
if (pkt->fec_desc.type != FEC_NONE) {
if (buffer->get_fec_params(0).type != FEC_NONE) {
check_symbol_size(fec_symbol_size, tx->mtu - hdrs_len);
}
long data_sent = 0;
do {
const char *data = chan_data + pos;
unsigned data_len = tx->mtu - hdrs_len;
if (pos + data_len >= len) {
data_len = len - pos;
int data_len = tx->mtu - hdrs_len;
if (pos + data_len >=
(unsigned int) buffer->get_data_len(channel)) {
data_len = buffer->get_data_len(channel) - pos;
if (send_m) {
m = 1;
}
@@ -892,7 +890,7 @@ audio_tx_send_chan(struct tx *tx, struct rtp *rtp_session, uint32_t timestamp,
(char *) rtp_hdr, rtp_hdr_len,
const_cast<char *>(data), data_len, 0, 0, 0);
} while (pos < len);
} while (pos < buffer->get_data_len(channel));
report_stats(tx, rtp_session, data_sent);
}

View File

@@ -89,8 +89,6 @@ int tx_get_buffer_id(struct tx *tx_session);
void format_audio_header(struct audio_desc desc, int channel,
size_t data_len, int buffer_idx, uint32_t *audio_hdr);
void audio_tx_send(struct tx *tx, struct rtp *rtp_session,
const struct audio_tx_data *buffer);
#ifdef __cplusplus
}
@@ -98,6 +96,7 @@ void audio_tx_send(struct tx *tx, struct rtp *rtp_session,
#ifdef __cplusplus
class audio_frame2;
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