Browse Source

TT#31198 add resampling support

Change-Id: Ib691e62d9ff6fc5663cea275663efc9134d78188
changes/62/18662/12
Richard Fuchs 8 years ago
parent
commit
ad4a5d10ef
5 changed files with 52 additions and 30 deletions
  1. +2
    -2
      daemon/call.c
  2. +19
    -11
      daemon/codec.c
  3. +12
    -7
      lib/codeclib.c
  4. +3
    -3
      lib/codeclib.h
  5. +16
    -7
      recording-daemon/decoder.c

+ 2
- 2
daemon/call.c View File

@ -1848,7 +1848,7 @@ void call_destroy(struct call *c) {
char *addr = sockaddr_print_buf(&ps->endpoint.address);
char *local_addr = ps->selected_sfd ? sockaddr_print_buf(&ps->selected_sfd->socket.local.address) : "0.0.0.0";
ilog(LOG_INFO, "--------- Port %15s:%-5u <> %15s:%-5u%s, SSRC %" PRIu32 ", "
ilog(LOG_INFO, "--------- Port %15s:%-5u <> %15s:%-5u%s, SSRC %" PRIx32 ", "
""UINT64F" p, "UINT64F" b, "UINT64F" e, "UINT64F" ts",
local_addr,
(unsigned int) (ps->selected_sfd ? ps->selected_sfd->socket.local.port : 0),
@ -1875,7 +1875,7 @@ void call_destroy(struct call *c) {
if (!se->stats_blocks.length || !se->lowest_mos || !se->highest_mos)
continue;
ilog(LOG_INFO, "--- SSRC %" PRIu32 "", se->h.ssrc);
ilog(LOG_INFO, "--- SSRC %" PRIx32 "", se->h.ssrc);
ilog(LOG_INFO, "------ Average MOS %" PRIu64 ".%" PRIu64 ", "
"lowest MOS %" PRIu64 ".%" PRIu64 " (at %u:%02u), "
"highest MOS %" PRIu64 ".%" PRIu64 " (at %u:%02u)",


+ 19
- 11
daemon/codec.c View File

@ -17,6 +17,7 @@ struct codec_ssrc_handler {
packet_sequencer_t sequencer;
decoder_t *decoder;
encoder_t *encoder;
format_t encoder_format;
unsigned long ts_offset;
u_int32_t ssrc_out;
u_int16_t seq_out;
@ -321,7 +322,8 @@ static struct ssrc_entry *__ssrc_handler_new(void *p) {
struct codec_handler *h = p;
u_int32_t ssrc_out = random();
ilog(LOG_DEBUG, "Creating SSRC handler to transcode from %s/%u/%i to SSRC %x %s/%u/%i",
ilog(LOG_DEBUG, "Creating SSRC transcoder from %s/%u/%i to "
"SSRC %" PRIx32 " %s/%u/%i",
h->source_pt.codec_def->rtpname, h->source_pt.clock_rate,
h->source_pt.channels,
ntohl(ssrc_out),
@ -335,18 +337,24 @@ static struct ssrc_entry *__ssrc_handler_new(void *p) {
ch->seq_out = random();
ch->ssrc_out = ssrc_out;
ch->ts_offset = random();
ch->decoder = decoder_new_fmt(h->source_pt.codec_def, h->source_pt.clock_rate, h->source_pt.channels, 0);
if (!ch->decoder)
goto err;
ch->encoder = encoder_new();
if (!ch->encoder)
goto err;
format_t format = {
format_t enc_format = {
.clockrate = h->dest_pt.clock_rate * h->dest_pt.codec_def->clockrate_mult,
.channels = h->dest_pt.channels,
.format = 0
.format = -1,
};
if (encoder_config(ch->encoder, h->dest_pt.codec_def->avcodec_id, 0, &format, &format))
ch->encoder = encoder_new();
if (!ch->encoder)
goto err;
if (encoder_config(ch->encoder, h->dest_pt.codec_def->avcodec_id, 0, &enc_format, &ch->encoder_format))
goto err;
ilog(LOG_DEBUG, "Encoder created with clockrate %i, %i channels, using sample format %i",
ch->encoder_format.clockrate, ch->encoder_format.channels, ch->encoder_format.format);
ch->decoder = decoder_new_fmt(h->source_pt.codec_def, h->source_pt.clock_rate, h->source_pt.channels,
&ch->encoder_format);
if (!ch->decoder)
goto err;
return &ch->h;
@ -418,7 +426,7 @@ static int handler_func_transcode(struct codec_handler *h, struct call_media *me
// create new packet and insert it into sequencer queue
ilog(LOG_DEBUG, "Received RTP packet: SSRC %x, PT %u, seq %u, TS %u, len %i",
ilog(LOG_DEBUG, "Received RTP packet: SSRC %" PRIx32 ", PT %u, seq %u, TS %u, len %i",
ntohl(mp->rtp->ssrc), mp->rtp->m_pt, ntohs(mp->rtp->seq_num),
ntohl(mp->rtp->timestamp), mp->payload.len);


+ 12
- 7
lib/codeclib.c View File

@ -80,7 +80,7 @@ const codec_def_t *codec_find(const str *name) {
decoder_t *decoder_new_fmt(const codec_def_t *def, int clockrate, int channels, int resample) {
decoder_t *decoder_new_fmt(const codec_def_t *def, int clockrate, int channels, const format_t *resample_fmt) {
const char *err = NULL;
clockrate *= def->clockrate_mult;
@ -92,8 +92,8 @@ decoder_t *decoder_new_fmt(const codec_def_t *def, int clockrate, int channels,
ret->in_format.clockrate = clockrate;
// output defaults to same as input
ret->out_format = ret->in_format;
if (resample)
ret->out_format.clockrate = resample;
if (resample_fmt)
ret->out_format = *resample_fmt;
// sample format to be determined later when decoded frames arrive
AVCodec *codec = NULL;
@ -147,8 +147,8 @@ void decoder_close(decoder_t *dec) {
avcodec_close(dec->avcctx);
av_free(dec->avcctx);
#endif
resample_shutdown(&dec->mix_resample);
resample_shutdown(&dec->output_resample);
resample_shutdown(&dec->resampler);
resample_shutdown(&dec->mix_resampler);
g_slice_free1(sizeof(*dec), dec);
}
@ -255,9 +255,14 @@ int decoder_input_data(decoder_t *dec, const str *data, unsigned long ts,
frame->pts = dec->avpkt.pts;
dec->avpkt.pts += frame->nb_samples;
if (callback(dec, frame, u1, u2))
err = "resampling failed";
AVFrame *rsmp_frame = resample_frame(&dec->resampler, frame, &dec->out_format);
if (!rsmp_frame)
goto err;
if (callback(dec, rsmp_frame, u1, u2))
return -1;
frame = NULL;
av_frame_free(&frame);
}
} while (keep_going);


+ 3
- 3
lib/codeclib.h View File

@ -49,8 +49,8 @@ struct decoder_s {
format_t in_format,
out_format;
resample_t mix_resample,
output_resample;
resample_t resampler,
mix_resampler; // XXX move this out of here - specific to recording-daemon
AVCodecContext *avcctx;
AVPacket avpkt;
@ -86,7 +86,7 @@ void codeclib_init(void);
const codec_def_t *codec_find(const str *name);
decoder_t *decoder_new_fmt(const codec_def_t *def, int clockrate, int channels, int resample);
decoder_t *decoder_new_fmt(const codec_def_t *def, int clockrate, int channels, const format_t *resample_fmt);
void decoder_close(decoder_t *dec);
int decoder_input_data(decoder_t *dec, const str *data, unsigned long ts,
int (*callback)(decoder_t *, AVFrame *, void *u1, void *u2), void *u1, void *u2);


+ 16
- 7
recording-daemon/decoder.c View File

@ -48,7 +48,16 @@ decoder_t *decoder_new(const char *payload_str) {
}
clockrate *= def->clockrate_mult;
return decoder_new_fmt(def, clockrate, channels, resample_audio);
if (!resample_audio)
return decoder_new_fmt(def, clockrate, channels, NULL);
format_t out_format = {
.clockrate = resample_audio,
.channels = channels,
.format = 0
};
return decoder_new_fmt(def, clockrate, channels, &out_format);
}
@ -75,7 +84,7 @@ static int decoder_got_frame(decoder_t *dec, AVFrame *frame, void *op, void *mp)
if (output_config(metafile->mix_out, &dec->out_format, &actual_format))
goto no_mix_out;
mix_config(metafile->mix, &actual_format);
AVFrame *dec_frame = resample_frame(&dec->mix_resample, frame, &actual_format);
AVFrame *dec_frame = resample_frame(&dec->mix_resampler, frame, &actual_format);
if (!dec_frame) {
pthread_mutex_unlock(&metafile->mix_lock);
goto err;
@ -91,12 +100,12 @@ no_mix_out:
format_t actual_format;
if (output_config(output, &dec->out_format, &actual_format))
goto err;
AVFrame *dec_frame = resample_frame(&dec->output_resample, frame, &actual_format);
if (!dec_frame)
goto err;
if (output_add(output, dec_frame))
// AVFrame *dec_frame = resample_frame(&dec->output_resample, frame, &actual_format);
// if (!dec_frame)
// goto err;
if (output_add(output, frame))
ilog(LOG_ERR, "Failed to add decoded packet to individual output");
av_frame_free(&dec_frame);
// av_frame_free(&dec_frame);
}
av_frame_free(&frame);


Loading…
Cancel
Save