summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRiza Sulistyo <riza@teluu.com>2016-10-13 11:49:57 +0000
committerRiza Sulistyo <riza@teluu.com>2016-10-13 11:49:57 +0000
commit956ad951f5033d14d32e2fd620cb779cbe0102ca (patch)
treedcd08629e481f023b10f04c4a14509249856c358
parent0d6c202512251a16c81973761bdb049ad2308502 (diff)
Re #1970: Implement function pjmedia_rtp_decode_rtp2().
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@5460 74dad513-b988-da41-8d7b-12977e46ad98
-rw-r--r--pjmedia/include/pjmedia/rtp.h49
-rw-r--r--pjmedia/src/pjmedia/rtp.c28
2 files changed, 72 insertions, 5 deletions
diff --git a/pjmedia/include/pjmedia/rtp.h b/pjmedia/include/pjmedia/rtp.h
index 66983d81..7a360f9d 100644
--- a/pjmedia/include/pjmedia/rtp.h
+++ b/pjmedia/include/pjmedia/rtp.h
@@ -113,7 +113,7 @@ typedef struct pjmedia_rtp_hdr pjmedia_rtp_hdr;
/**
- * RTP extendsion header.
+ * RTP extension header.
*/
struct pjmedia_rtp_ext_hdr
{
@@ -126,6 +126,21 @@ struct pjmedia_rtp_ext_hdr
*/
typedef struct pjmedia_rtp_ext_hdr pjmedia_rtp_ext_hdr;
+/**
+ * This will contain the RTP header decode output.
+ */
+struct pjmedia_rtp_dec_hdr
+{
+ /* RTP extension header output decode */
+ pjmedia_rtp_ext_hdr *ext_hdr;
+ pj_uint32_t *ext;
+ unsigned ext_len;
+};
+
+/**
+ * @see pjmedia_rtp_dec_hdr
+ */
+typedef struct pjmedia_rtp_dec_hdr pjmedia_rtp_dec_hdr;
#pragma pack(1)
@@ -321,6 +336,38 @@ PJ_DECL(pj_status_t) pjmedia_rtp_decode_rtp( pjmedia_rtp_session *ses,
const void **payload,
unsigned *payloadlen);
+
+/**
+ * This function decodes incoming packet into RTP header and payload.
+ * The decode function is guaranteed to point the payload to the correct
+ * position regardless of any options present in the RTP packet.
+ *
+ * Note that this function does not modify the returned RTP header to
+ * host byte order.
+ *
+ * @param ses The session.
+ * @param pkt The received RTP packet.
+ * @param pkt_len The length of the packet.
+ * @param hdr Upon return will point to the location of the RTP
+ * header inside the packet. Note that the RTP header
+ * will be given back as is, meaning that the fields
+ * will be in network byte order.
+ * @param dec_hdr Upon return will point to the location of the
+ * additional RTP header inside the packet, if any.
+ * @param payload Upon return will point to the location of the
+ * payload inside the packet.
+ * @param payloadlen Upon return will indicate the size of the payload.
+ *
+ * @return PJ_SUCCESS if successfull.
+ */
+PJ_DECL(pj_status_t) pjmedia_rtp_decode_rtp2(
+ pjmedia_rtp_session *ses,
+ const void *pkt, int pkt_len,
+ const pjmedia_rtp_hdr **hdr,
+ pjmedia_rtp_dec_hdr *dec_hdr,
+ const void **payload,
+ unsigned *payloadlen);
+
/**
* Call this function everytime an RTP packet is received to check whether
* the packet can be received and to let the RTP session performs its internal
diff --git a/pjmedia/src/pjmedia/rtp.c b/pjmedia/src/pjmedia/rtp.c
index 5a19c37e..3aa13e92 100644
--- a/pjmedia/src/pjmedia/rtp.c
+++ b/pjmedia/src/pjmedia/rtp.c
@@ -149,6 +149,21 @@ PJ_DEF(pj_status_t) pjmedia_rtp_decode_rtp( pjmedia_rtp_session *ses,
const void **payload,
unsigned *payloadlen)
{
+ pjmedia_rtp_dec_hdr dec_hdr;
+
+ return pjmedia_rtp_decode_rtp2(ses, pkt, pkt_len, hdr, &dec_hdr,
+ payload, payloadlen);
+}
+
+
+PJ_DEF(pj_status_t) pjmedia_rtp_decode_rtp2(
+ pjmedia_rtp_session *ses,
+ const void *pkt, int pkt_len,
+ const pjmedia_rtp_hdr **hdr,
+ pjmedia_rtp_dec_hdr *dec_hdr,
+ const void **payload,
+ unsigned *payloadlen)
+{
int offset;
PJ_UNUSED_ARG(ses);
@@ -164,11 +179,16 @@ PJ_DEF(pj_status_t) pjmedia_rtp_decode_rtp( pjmedia_rtp_session *ses,
/* Payload is located right after header plus CSRC */
offset = sizeof(pjmedia_rtp_hdr) + ((*hdr)->cc * sizeof(pj_uint32_t));
- /* Adjust offset if RTP extension is used. */
+ /* Decode RTP extension. */
if ((*hdr)->x) {
- pjmedia_rtp_ext_hdr *ext = (pjmedia_rtp_ext_hdr*)
- (((pj_uint8_t*)pkt) + offset);
- offset += ((pj_ntohs(ext->length)+1) * sizeof(pj_uint32_t));
+ dec_hdr->ext_hdr = (pjmedia_rtp_ext_hdr*)(((pj_uint8_t*)pkt) + offset);
+ dec_hdr->ext = (pj_uint32_t*)(dec_hdr->ext_hdr + 1);
+ dec_hdr->ext_len = pj_ntohs((dec_hdr->ext_hdr)->length);
+ offset += ((dec_hdr->ext_len + 1) * sizeof(pj_uint32_t));
+ } else {
+ dec_hdr->ext_hdr = NULL;
+ dec_hdr->ext = NULL;
+ dec_hdr->ext_len = 0;
}
/* Check that offset is less than packet size */