MT#54294 more generic packet_encoded_rtp

and packet_encoded_packetize

Change-Id: Ie74b831de7ef72018bb034c23207f736c1087b6e
pull/1692/head
Richard Fuchs 2 years ago
parent 7a2b7d57c0
commit 3ad63ba8ed

@ -3840,15 +3840,17 @@ static void __free_ssrc_handler(void *chp) {
}
void packet_encoded_packetize(encoder_t *enc, struct codec_ssrc_handler *ch, struct media_packet *mp,
void (*fn)(encoder_t *, struct codec_ssrc_handler *, struct media_packet *, str *,
char *, unsigned int))
void packet_encoded_packetize(AVPacket *pkt, struct codec_ssrc_handler *ch, struct media_packet *mp,
packetizer_f pkt_f, void *pkt_f_data, const struct fraction *cr_fact,
void (*tx_f)(AVPacket *, struct codec_ssrc_handler *, struct media_packet *, str *,
char *, unsigned int, const struct fraction *cr_fact))
{
AVPacket *in_pkt = enc->avpkt;
// run this through our packetizer
AVPacket *in_pkt = pkt;
while (true) {
// figure out how big of a buffer we need
unsigned int payload_len = MAX(MAX(enc->avpkt->size, ch->bytes_per_packet),
unsigned int payload_len = MAX(MAX(pkt->size, ch->bytes_per_packet),
sizeof(struct telephone_event_payload));
unsigned int pkt_len = sizeof(struct rtp_header) + payload_len + RTP_BUFFER_TAIL_ROOM;
// prepare our buffers
@ -3860,10 +3862,10 @@ void packet_encoded_packetize(encoder_t *enc, struct codec_ssrc_handler *ch, str
// and request a packet
if (in_pkt)
ilogs(transcoding, LOG_DEBUG, "Adding %i bytes to packetizer", in_pkt->size);
int ret = enc->def->packetizer(in_pkt,
ch->sample_buffer, &inout, enc);
int ret = pkt_f(in_pkt,
ch->sample_buffer, &inout, pkt_f_data);
if (G_UNLIKELY(ret == -1 || enc->avpkt->pts == AV_NOPTS_VALUE)) {
if (G_UNLIKELY(ret == -1 || pkt->pts == AV_NOPTS_VALUE)) {
// nothing
free(buf);
break;
@ -3871,7 +3873,7 @@ void packet_encoded_packetize(encoder_t *enc, struct codec_ssrc_handler *ch, str
ilogs(transcoding, LOG_DEBUG, "Received packet of %zu bytes from packetizer", inout.len);
fn(enc, ch, mp, &inout, buf, pkt_len);
tx_f(pkt, ch, mp, &inout, buf, pkt_len, cr_fact);
if (ret == 0) {
// no more to go
@ -3883,9 +3885,8 @@ void packet_encoded_packetize(encoder_t *enc, struct codec_ssrc_handler *ch, str
}
}
static void packet_encoded_tx(encoder_t *enc, struct codec_ssrc_handler *ch, struct media_packet *mp,
str *inout, char *buf, unsigned int pkt_len);
static void packet_encoded_tx(AVPacket *pkt, struct codec_ssrc_handler *ch, struct media_packet *mp,
str *inout, char *buf, unsigned int pkt_len, const struct fraction *cr_fact);
static int packet_encoded_rtp(encoder_t *enc, void *u1, void *u2) {
struct codec_ssrc_handler *ch = u1;
@ -3894,14 +3895,14 @@ static int packet_encoded_rtp(encoder_t *enc, void *u1, void *u2) {
ilogs(transcoding, LOG_DEBUG, "RTP media successfully encoded: TS %llu, len %i",
(unsigned long long) enc->avpkt->pts, enc->avpkt->size);
// run this through our packetizer
packet_encoded_packetize(enc, ch, mp, packet_encoded_tx);
packet_encoded_packetize(enc->avpkt, ch, mp, enc->def->packetizer, enc, &enc->clockrate_fact,
packet_encoded_tx);
return 0;
}
static void packet_encoded_tx(encoder_t *enc, struct codec_ssrc_handler *ch, struct media_packet *mp,
str *inout, char *buf, unsigned int pkt_len)
static void packet_encoded_tx(AVPacket *pkt, struct codec_ssrc_handler *ch, struct media_packet *mp,
str *inout, char *buf, unsigned int pkt_len, const struct fraction *cr_fact)
{
// check special payloads
@ -3913,7 +3914,7 @@ static void packet_encoded_tx(encoder_t *enc, struct codec_ssrc_handler *ch, str
int is_dtmf = 0;
if (dtmf_pt != -1)
is_dtmf = dtmf_event_payload(inout, (uint64_t *) &enc->avpkt->pts, enc->avpkt->duration,
is_dtmf = dtmf_event_payload(inout, (uint64_t *) &pkt->pts, pkt->duration,
&ch->dtmf_event, &ch->dtmf_events);
if (is_dtmf) {
payload_type = dtmf_pt;
@ -3923,7 +3924,7 @@ static void packet_encoded_tx(encoder_t *enc, struct codec_ssrc_handler *ch, str
repeats = 2; // DTMF end event
}
else {
if (is_silence_event(inout, &ch->silence_events, enc->avpkt->pts, enc->avpkt->duration))
if (is_silence_event(inout, &ch->silence_events, pkt->pts, pkt->duration))
payload_type = ch->handler->cn_payload_type;
}
@ -3937,7 +3938,7 @@ static void packet_encoded_tx(encoder_t *enc, struct codec_ssrc_handler *ch, str
memcpy(send_buf, buf, pkt_len);
}
codec_output_rtp(mp, &ch->csch, ch->handler, send_buf, inout->len, ch->csch.first_ts
+ fraction_divl(enc->avpkt->pts, &enc->clockrate_fact),
+ fraction_divl(pkt->pts, cr_fact),
ch->rtp_mark ? 1 : 0, -1, 0,
payload_type, 0);
mp->ssrc_out->parent->seq_diff++;

@ -604,8 +604,8 @@ static void media_player_cache_entry_decoder_thread(void *p) {
ilog(LOG_DEBUG, "Decoder thread for %s finished", entry->info_str);
}
static void packet_encoded_cache(encoder_t *enc, struct codec_ssrc_handler *ch, struct media_packet *mp,
str *s, char *buf, unsigned int pkt_len)
static void packet_encoded_cache(AVPacket *pkt, struct codec_ssrc_handler *ch, struct media_packet *mp,
str *s, char *buf, unsigned int pkt_len, const struct fraction *cr_fact)
{
struct media_player_cache_entry *entry = mp->cache_entry;
@ -614,9 +614,9 @@ static void packet_encoded_cache(encoder_t *enc, struct codec_ssrc_handler *ch,
*ep = (__typeof__(*ep)) {
.buf = buf,
.s = *s,
.pts = enc->avpkt->pts,
.duration_ts = enc->avpkt->duration,
.duration = (long long) enc->avpkt->duration * 1000000LL
.pts = pkt->pts,
.duration_ts = pkt->duration,
.duration = (long long) pkt->duration * 1000000LL
/ entry->coder.handler->dest_pt.clock_rate,
};
@ -631,7 +631,8 @@ static int media_player_packet_cache(encoder_t *enc, void *u1, void *u2) {
struct codec_ssrc_handler *ch = u1;
struct media_packet *mp = u2;
packet_encoded_packetize(enc, ch, mp, packet_encoded_cache);
packet_encoded_packetize(enc->avpkt, ch, mp, enc->def->packetizer, enc, &enc->clockrate_fact,
packet_encoded_cache);
return 0;
}

@ -160,9 +160,10 @@ void codec_tracker_update(struct codec_store *);
void codec_handlers_stop(GQueue *);
void packet_encoded_packetize(encoder_t *enc, struct codec_ssrc_handler *ch, struct media_packet *mp,
void (*fn)(encoder_t *, struct codec_ssrc_handler *, struct media_packet *, str *,
char *, unsigned int));
void packet_encoded_packetize(AVPacket *pkt, struct codec_ssrc_handler *ch, struct media_packet *mp,
packetizer_f pkt_f, void *pkt_f_data, const struct fraction *cr_fact,
void (*tx_f)(AVPacket *, struct codec_ssrc_handler *, struct media_packet *, str *,
char *, unsigned int, const struct fraction *cr_fact));
void codec_output_rtp(struct media_packet *mp, struct codec_scheduler *,
struct codec_handler *handler, // normally == ch->handler except for DTMF
char *buf, // malloc'd, room for rtp_header + filled-in payload

Loading…
Cancel
Save