Browse Source

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

Change-Id: Iffd79b43180c30a9e128a460f7ba85ba49dedeaf
changes/30/27230/5
Richard Fuchs 7 years ago
parent
commit
9d3bb5bffc
8 changed files with 46 additions and 26 deletions
  1. +2
    -2
      daemon/codec.c
  2. +3
    -4
      lib/codeclib.c
  3. +3
    -5
      lib/codeclib.h
  4. +22
    -9
      recording-daemon/decoder.c
  5. +3
    -2
      recording-daemon/decoder.h
  6. +1
    -1
      recording-daemon/packet.c
  7. +10
    -1
      recording-daemon/types.h
  8. +2
    -2
      t/amr-decode-test.c

+ 2
- 2
daemon/codec.c View File

@ -975,7 +975,7 @@ static int __packet_encoded(encoder_t *enc, void *u1, void *u2) {
return 0; 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; struct codec_ssrc_handler *ch = u1;
ilog(LOG_DEBUG, "RTP media successfully decoded: TS %llu, samples %u", 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) 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) { static int handler_func_transcode(struct codec_handler *h, struct media_packet *mp) {


+ 3
- 4
lib/codeclib.c View File

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


+ 3
- 5
lib/codeclib.h View File

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


+ 22
- 9
recording-daemon/decoder.c View File

@ -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; str name;
char *slash = strchr(payload_str, '/'); char *slash = strchr(payload_str, '/');
if (!slash) { 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; 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; metafile_t *metafile = mp;
output_t *output = op; 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, 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], (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 // handle mix output
pthread_mutex_lock(&metafile->mix_lock); pthread_mutex_lock(&metafile->mix_lock);
if (metafile->mix_out) { 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; format_t actual_format;
if (output_config(metafile->mix_out, &dec->out_format, &actual_format)) if (output_config(metafile->mix_out, &dec->out_format, &actual_format))
goto no_mix_out; goto no_mix_out;
mix_config(metafile->mix, &actual_format); mix_config(metafile->mix, &actual_format);
// XXX might be a second resampling to same 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) { if (!dec_frame) {
pthread_mutex_unlock(&metafile->mix_lock); pthread_mutex_unlock(&metafile->mix_lock);
goto err; 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"); ilog(LOG_ERR, "Failed to add decoded packet to mixed output");
} }
no_mix_out: 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);
} }

+ 3
- 2
recording-daemon/decoder.h View File

@ -8,8 +8,9 @@
extern int resample_audio; 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 #endif

+ 1
- 1
recording-daemon/packet.c View File

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


+ 10
- 1
recording-daemon/types.h View File

@ -28,6 +28,8 @@ struct output_s;
typedef struct output_s output_t; typedef struct output_s output_t;
struct mix_s; struct mix_s;
typedef struct mix_s mix_t; typedef struct mix_s mix_t;
struct decode_s;
typedef struct decode_s decode_t;
typedef void handler_func(handler_t *); typedef void handler_func(handler_t *);
@ -71,7 +73,7 @@ struct ssrc_s {
metafile_t *metafile; metafile_t *metafile;
unsigned long ssrc; unsigned long ssrc;
packet_sequencer_t sequencer; packet_sequencer_t sequencer;
decoder_t *decoders[128];
decode_t *decoders[128];
output_t *output; output_t *output;
}; };
typedef struct ssrc_s ssrc_t; 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 #endif

+ 2
- 2
t/amr-decode-test.c View File

@ -8,7 +8,7 @@ static void hexdump(const unsigned char *buf, int len) {
printf("\n"); 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; char **expect = u1;
int *expect_len = u2; int *expect_len = u2;
assert(expect); 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); decoder_t *d = decoder_new_fmtp(def, clockrate, 1, &fmt, fmtp);
assert(d); assert(d);
const str data = { data_s, data_len }; 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(!ret);
assert(expect_s == NULL); assert(expect_s == NULL);
decoder_close(d); decoder_close(d);


Loading…
Cancel
Save