TT#52651 extract/move unrelated old legacy decoder struct members

Change-Id: Iffd79b43180c30a9e128a460f7ba85ba49dedeaf
changes/30/27230/5
Richard Fuchs 6 years ago
parent 1bc38e4201
commit 9d3bb5bffc

@ -975,7 +975,7 @@ static int __packet_encoded(encoder_t *enc, void *u1, void *u2) {
return 0;
}
static int __packet_decoded(decoder_t *decoder, AVFrame *frame, void *u1, void *u2) {
static int __packet_decoded(decoder_t *decoder, AVFrame *frame, void *u1, void *u2, void *u3) {
struct codec_ssrc_handler *ch = u1;
ilog(LOG_DEBUG, "RTP media successfully decoded: TS %llu, samples %u",
@ -989,7 +989,7 @@ static int __packet_decoded(decoder_t *decoder, AVFrame *frame, void *u1, void *
static int packet_decode(struct codec_ssrc_handler *ch, struct transcode_packet *packet, struct media_packet *mp)
{
return decoder_input_data(ch->decoder, packet->payload, packet->ts, __packet_decoded, ch, mp);
return decoder_input_data(ch->decoder, packet->payload, packet->ts, __packet_decoded, ch, mp, NULL);
}
static int handler_func_transcode(struct codec_handler *h, struct media_packet *mp) {

@ -456,7 +456,6 @@ decoder_t *decoder_new_fmtp(const codec_def_t *def, int clockrate, int channels,
ret->pts = (uint64_t) -1LL;
ret->rtp_ts = (unsigned long) -1L;
ret->mixer_idx = (unsigned int) -1;
return ret;
@ -488,7 +487,6 @@ void decoder_close(decoder_t *dec) {
dec->def->codec_type->decoder_close(dec);
resample_shutdown(&dec->resampler);
resample_shutdown(&dec->mix_resampler);
g_slice_free1(sizeof(*dec), dec);
}
@ -593,7 +591,8 @@ err:
}
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)
int (*callback)(decoder_t *, AVFrame *, void *u1, void *u2, void *u3),
void *u1, void *u2, void *u3)
{
GQueue frames = G_QUEUE_INIT;
@ -635,7 +634,7 @@ int decoder_input_data(decoder_t *dec, const str *data, unsigned long ts,
ret = -1;
}
else {
if (callback(dec, rsmp_frame, u1, u2))
if (callback(dec, rsmp_frame, u1, u2, u3))
ret = -1;
}
av_frame_free(&frame);

@ -131,8 +131,7 @@ struct decoder_s {
format_t in_format,
out_format;
resample_t resampler,
mix_resampler; // XXX move this out of here - specific to recording-daemon
resample_t resampler;
union {
struct {
@ -146,8 +145,6 @@ struct decoder_s {
unsigned long rtp_ts;
uint64_t pts;
unsigned int mixer_idx;
};
struct encoder_s {
@ -202,7 +199,8 @@ decoder_t *decoder_new_fmtp(const codec_def_t *def, int clockrate, int channels,
const str *fmtp);
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);
int (*callback)(decoder_t *, AVFrame *, void *u1, void *u2, void *u3),
void *u1, void *u2, void *u3);
encoder_t *encoder_new();

@ -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);
}

@ -8,8 +8,9 @@
extern int resample_audio;
decoder_t *decoder_new(const char *payload_str, output_t *);
int decoder_input(decoder_t *, const str *, unsigned long ts, output_t *, metafile_t *);
decode_t *decoder_new(const char *payload_str, output_t *);
int decoder_input(decode_t *, const str *, unsigned long ts, output_t *, metafile_t *);
void decoder_free(decode_t *);
#endif

@ -29,7 +29,7 @@ void ssrc_free(void *p) {
packet_sequencer_destroy(&s->sequencer);
output_close(s->output);
for (int i = 0; i < G_N_ELEMENTS(s->decoders); i++)
decoder_close(s->decoders[i]);
decoder_free(s->decoders[i]);
g_slice_free1(sizeof(*s), s);
}

@ -28,6 +28,8 @@ struct output_s;
typedef struct output_s output_t;
struct mix_s;
typedef struct mix_s mix_t;
struct decode_s;
typedef struct decode_s decode_t;
typedef void handler_func(handler_t *);
@ -71,7 +73,7 @@ struct ssrc_s {
metafile_t *metafile;
unsigned long ssrc;
packet_sequencer_t sequencer;
decoder_t *decoders[128];
decode_t *decoders[128];
output_t *output;
};
typedef struct ssrc_s ssrc_t;
@ -135,5 +137,12 @@ struct output_s {
};
struct decode_s {
decoder_t *dec;
resample_t mix_resampler;
unsigned int mixer_idx;
};
#endif

@ -8,7 +8,7 @@ static void hexdump(const unsigned char *buf, int len) {
printf("\n");
}
static int frame_cb(decoder_t *dec, AVFrame *frame, void *u1, void *u2) {
static int frame_cb(decoder_t *dec, AVFrame *frame, void *u1, void *u2, void *u3) {
char **expect = u1;
int *expect_len = u2;
assert(expect);
@ -54,7 +54,7 @@ static void do_test_amr_xx(const char *file, int line,
decoder_t *d = decoder_new_fmtp(def, clockrate, 1, &fmt, fmtp);
assert(d);
const str data = { data_s, data_len };
int ret = decoder_input_data(d, &data, 1, frame_cb, &expect_s, &expect_len);
int ret = decoder_input_data(d, &data, 1, frame_cb, &expect_s, &expect_len, NULL);
assert(!ret);
assert(expect_s == NULL);
decoder_close(d);

Loading…
Cancel
Save