diff --git a/daemon/codec.c b/daemon/codec.c index e844a970d..0fac155d2 100644 --- a/daemon/codec.c +++ b/daemon/codec.c @@ -35,7 +35,7 @@ static void __ssrc_handler_free(struct codec_ssrc_handler *p); static void __transcode_packet_free(struct transcode_packet *); -static struct rtp_payload_type *__rtp_payload_type_copy(struct rtp_payload_type *pt); +static struct rtp_payload_type *__rtp_payload_type_copy(const struct rtp_payload_type *pt); static void __rtp_payload_type_add_name(GHashTable *, struct rtp_payload_type *pt); @@ -310,13 +310,13 @@ static struct ssrc_entry *__ssrc_handler_new(void *p) { packet_sequencer_init(&ch->sequencer, (GDestroyNotify) __transcode_packet_free); ch->seq_out = random(); ch->ts_offset = random(); - ch->decoder = decoder_new_fmt(h->source_pt.codec_def, h->source_pt.clock_rate, 1, 0); + 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 = { .clockrate = h->dest_pt.clock_rate, .channels = 1, .format = 0 }; + format_t format = { .clockrate = h->dest_pt.clock_rate, .channels = h->dest_pt.channels, .format = 0 }; if (encoder_config(ch->encoder, h->dest_pt.codec_def->avcodec_id, 0, &format, &format)) goto err; return &ch->h; @@ -449,8 +449,7 @@ static struct rtp_payload_type *codec_make_payload_type(const str *codec) { if (!rfc_pt) return NULL; // XXX amend for other codecs - struct rtp_payload_type *ret = g_slice_alloc(sizeof(*ret)); - *ret = *rfc_pt; + struct rtp_payload_type *ret = __rtp_payload_type_copy(rfc_pt); ret->codec_def = dec; return ret; @@ -499,7 +498,7 @@ static void __rtp_payload_type_dup(struct call *call, struct rtp_payload_type *p call_str_cpy(call, &pt->encoding_parameters, &pt->encoding_parameters); call_str_cpy(call, &pt->format_parameters, &pt->format_parameters); } -static struct rtp_payload_type *__rtp_payload_type_copy(struct rtp_payload_type *pt) { +static struct rtp_payload_type *__rtp_payload_type_copy(const struct rtp_payload_type *pt) { struct rtp_payload_type *pt_copy = g_slice_alloc(sizeof(*pt)); *pt_copy = *pt; return pt_copy; diff --git a/daemon/sdp.c b/daemon/sdp.c index 573afe042..6fdaf01b5 100644 --- a/daemon/sdp.c +++ b/daemon/sdp.c @@ -749,9 +749,16 @@ static int parse_attribute_rtpmap(struct sdp_attribute *output) { pt->encoding.len -= a->clock_rate_str.len; str_shift(&a->clock_rate_str, 1); + pt->channels = 1; if (str_chr_str(&pt->encoding_parameters, &a->clock_rate_str, '/')) { a->clock_rate_str.len -= pt->encoding_parameters.len; str_shift(&pt->encoding_parameters, 1); + + if (pt->encoding_parameters.len) { + int channels = strtol(pt->encoding_parameters.s, &ep, 10); + if (channels && (!ep || ep == pt->encoding_parameters.s + pt->encoding_parameters.len)) + pt->channels = channels; + } } if (!a->clock_rate_str.len) diff --git a/lib/rtplib.h b/lib/rtplib.h index 8535c4a40..17a1c4a7e 100644 --- a/lib/rtplib.h +++ b/lib/rtplib.h @@ -22,6 +22,7 @@ struct rtp_payload_type { str encoding; unsigned int clock_rate; str encoding_parameters; + int channels; str format_parameters; const codec_def_t *codec_def;