aboutsummaryrefslogtreecommitdiffstats
path: root/openbsc/src/libmgcp/mgcp_protocol.c
diff options
context:
space:
mode:
authorJacob Erlbeck <jerlbeck@sysmocom.de>2013-12-04 10:30:11 +0100
committerJacob Erlbeck <jerlbeck@sysmocom.de>2013-12-10 11:17:44 +0100
commitf6ec0e9fc4261d2173286e9b23fd19060040d1d1 (patch)
treef0dbbb3581da797161cbc4a713781333a15439e0 /openbsc/src/libmgcp/mgcp_protocol.c
parent58340e5b5bfa37b09a61d544904330c1932ccfec (diff)
mgcp/rtp: Refactored packet_duration computation
Since the packet duration is given in ms with the 'ptime' RTP media attribute and also with the 'p' MGCP local connection option, the computation is changed to use this value (if present). The computation assumes, that there are N complete frames in a packet and takes into account, that the ptime value possibly had been rounded towards the next ms value (which is never the case with a frame length of exact 20ms). Sponsored-by: On-Waves ehf
Diffstat (limited to 'openbsc/src/libmgcp/mgcp_protocol.c')
-rw-r--r--openbsc/src/libmgcp/mgcp_protocol.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/openbsc/src/libmgcp/mgcp_protocol.c b/openbsc/src/libmgcp/mgcp_protocol.c
index b8e1ecde4..ab941645e 100644
--- a/openbsc/src/libmgcp/mgcp_protocol.c
+++ b/openbsc/src/libmgcp/mgcp_protocol.c
@@ -75,7 +75,7 @@ char *strline_r(char *str, char **saveptr)
/* Assume audio frame length of 20ms */
#define DEFAULT_RTP_AUDIO_FRAME_DUR_NUM 20
#define DEFAULT_RTP_AUDIO_FRAME_DUR_DEN 1000
-#define DEFAULT_RTP_AUDIO_FRAMES_PER_PACKET 1
+#define DEFAULT_RTP_AUDIO_PACKET_DURATION_MS 20
#define DEFAULT_RTP_AUDIO_DEFAULT_RATE 8000
static void mgcp_rtp_end_reset(struct mgcp_rtp_end *end);
@@ -631,6 +631,23 @@ void mgcp_rtp_end_config(struct mgcp_endpoint *endp, int expect_ssrc_change,
rtp->force_constant_ssrc ? ", force constant ssrc" : "");
}
+uint32_t mgcp_rtp_packet_duration(struct mgcp_endpoint *endp,
+ struct mgcp_rtp_end *rtp)
+{
+ int f = 0;
+
+ /* Get the number of frames per channel and packet */
+ if (rtp->frames_per_packet)
+ f = rtp->frames_per_packet;
+ else if (rtp->packet_duration_ms && rtp->frame_duration_num) {
+ int den = 1000 * rtp->frame_duration_num;
+ f = (rtp->packet_duration_ms * rtp->frame_duration_den + den/2)
+ / den;
+ }
+
+ return rtp->rate * f * rtp->frame_duration_num / rtp->frame_duration_den;
+}
+
static struct msgb *handle_create_con(struct mgcp_parse_data *p)
{
struct mgcp_trunk_config *tcfg;
@@ -1086,8 +1103,9 @@ static void mgcp_rtp_end_reset(struct mgcp_rtp_end *end)
/* Set default values */
end->frame_duration_num = DEFAULT_RTP_AUDIO_FRAME_DUR_NUM;
end->frame_duration_den = DEFAULT_RTP_AUDIO_FRAME_DUR_DEN;
- end->frames_per_packet = DEFAULT_RTP_AUDIO_FRAMES_PER_PACKET;
- end->rate = DEFAULT_RTP_AUDIO_DEFAULT_RATE;
+ end->frames_per_packet = 0; /* unknown */
+ end->packet_duration_ms = DEFAULT_RTP_AUDIO_PACKET_DURATION_MS;
+ end->rate = DEFAULT_RTP_AUDIO_DEFAULT_RATE;
}
static void mgcp_rtp_end_init(struct mgcp_rtp_end *end)