|
|
|
@ -21,7 +21,7 @@ int resample_audio; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
decoder_t *decoder_new(const char *payload_str, output_t *outp) { |
|
|
|
decode_t *decoder_new(const char *payload_str, output_t *outp) { |
|
|
|
str name; |
|
|
|
char *slash = strchr(payload_str, '/'); |
|
|
|
if (!slash) { |
|
|
|
@ -69,13 +69,20 @@ decoder_t *decoder_new(const char *payload_str, output_t *outp) { |
|
|
|
outp->encoder->requested_format.format = out_format.format; |
|
|
|
} |
|
|
|
|
|
|
|
return decoder_new_fmt(def, clockrate, channels, &out_format); |
|
|
|
decoder_t *dec = decoder_new_fmt(def, clockrate, channels, &out_format); |
|
|
|
if (!dec) |
|
|
|
return NULL; |
|
|
|
decode_t *deco = g_slice_alloc0(sizeof(decode_t)); |
|
|
|
deco->dec = dec; |
|
|
|
deco->mixer_idx = (unsigned int) -1; |
|
|
|
return deco; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static int decoder_got_frame(decoder_t *dec, AVFrame *frame, void *op, void *mp) { |
|
|
|
static int decoder_got_frame(decoder_t *dec, AVFrame *frame, void *op, void *mp, void *dp) { |
|
|
|
metafile_t *metafile = mp; |
|
|
|
output_t *output = op; |
|
|
|
decode_t *deco = dp; |
|
|
|
|
|
|
|
dbg("got frame pts %llu samples %u contents %02x%02x%02x%02x...", (unsigned long long) frame->pts, frame->nb_samples, |
|
|
|
(unsigned int) frame->extended_data[0][0], |
|
|
|
@ -86,19 +93,19 @@ static int decoder_got_frame(decoder_t *dec, AVFrame *frame, void *op, void *mp) |
|
|
|
// handle mix output |
|
|
|
pthread_mutex_lock(&metafile->mix_lock); |
|
|
|
if (metafile->mix_out) { |
|
|
|
if (G_UNLIKELY(dec->mixer_idx == (unsigned int) -1)) |
|
|
|
dec->mixer_idx = mix_get_index(metafile->mix); |
|
|
|
if (G_UNLIKELY(deco->mixer_idx == (unsigned int) -1)) |
|
|
|
deco->mixer_idx = mix_get_index(metafile->mix); |
|
|
|
format_t actual_format; |
|
|
|
if (output_config(metafile->mix_out, &dec->out_format, &actual_format)) |
|
|
|
goto no_mix_out; |
|
|
|
mix_config(metafile->mix, &actual_format); |
|
|
|
// XXX might be a second resampling to same format |
|
|
|
AVFrame *dec_frame = resample_frame(&dec->mix_resampler, frame, &actual_format); |
|
|
|
AVFrame *dec_frame = resample_frame(&deco->mix_resampler, frame, &actual_format); |
|
|
|
if (!dec_frame) { |
|
|
|
pthread_mutex_unlock(&metafile->mix_lock); |
|
|
|
goto err; |
|
|
|
} |
|
|
|
if (mix_add(metafile->mix, dec_frame, dec->mixer_idx, metafile->mix_out)) |
|
|
|
if (mix_add(metafile->mix, dec_frame, deco->mixer_idx, metafile->mix_out)) |
|
|
|
ilog(LOG_ERR, "Failed to add decoded packet to mixed output"); |
|
|
|
} |
|
|
|
no_mix_out: |
|
|
|
@ -120,6 +127,12 @@ err: |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int decoder_input(decoder_t *dec, const str *data, unsigned long ts, output_t *output, metafile_t *metafile) { |
|
|
|
return decoder_input_data(dec, data, ts, decoder_got_frame, output, metafile); |
|
|
|
int decoder_input(decode_t *deco, const str *data, unsigned long ts, output_t *output, metafile_t *metafile) { |
|
|
|
return decoder_input_data(deco->dec, data, ts, decoder_got_frame, output, metafile, deco); |
|
|
|
} |
|
|
|
|
|
|
|
void decoder_free(decode_t *deco) { |
|
|
|
decoder_close(deco->dec); |
|
|
|
resample_shutdown(&deco->mix_resampler); |
|
|
|
g_slice_free1(sizeof(*deco), deco); |
|
|
|
} |