summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2013-12-03 12:59:22 +0100
committerBent Bisballe Nyeng <deva@aasimon.org>2013-12-03 12:59:22 +0100
commitfdc8530a082d2e65fe4739a5ccacf1de6b839f23 (patch)
tree54686dded935a7b02cdec71c5d4207ef9df65ecb
parent3ab4a8c1c040480b81860a07f58aeb3a02a1c33b (diff)
Report errors in rtpSetPayload/fromPacket methods.
-rw-r--r--src/rtp.cc16
-rw-r--r--src/rtp.h8
2 files changed, 17 insertions, 7 deletions
diff --git a/src/rtp.cc b/src/rtp.cc
index 28a9203..767a506 100644
--- a/src/rtp.cc
+++ b/src/rtp.cc
@@ -137,17 +137,21 @@ void RTP::clearCSrcs()
header.cc = csrcs.size();
}
-void RTP::setPayload(const char *pl, size_t size)
+int RTP::setPayload(const char *pl, size_t size)
{
if(size > MAX_RTP_PAYLOAD_SIZE) {
- printf("ERROR: Payload is too big for RTP pakcet.\n");
+ printf("ERROR: Payload is too big for RTP packet (%d bytes, max is %d).\n",
+ size, MAX_RTP_PAYLOAD_SIZE);
// TODO: Report error.
+ return -1;
}
memcpy(pload, pl, size);
pload_size = size;
setValid(true);
+
+ return size;
}
size_t RTP::payload(char *payload, size_t maxsize) const
@@ -215,13 +219,13 @@ size_t RTP::packet(char *packet, size_t maxsize) const
return p - packet;
}
-void RTP::fromPacket(const char *packet, size_t size)
+int RTP::fromPacket(const char *packet, size_t size)
{
rtp_header_t *hdr = (rtp_header_t *)packet;
if(hdr->version != 2) {
printf("ERROR: Wrong RTP header version.\n");
- return; // TODO: Invalid RTP version error
+ return -1; // TODO: Invalid RTP version error
}
setMarker(hdr->m);
@@ -246,9 +250,11 @@ void RTP::fromPacket(const char *packet, size_t size)
// Read out payload
size_t plsz = size - (sizeof(rtp_header_t) + hdr->cc*sizeof(csrc_t) + pads);
char *pl = (char*)pcsrc;
- setPayload(pl, plsz);
+ if(setPayload(pl, plsz) < 0) return -1;
setValid(true);
+
+ return size;
}
bool RTP::isValid()
diff --git a/src/rtp.h b/src/rtp.h
index b7aa8b4..350eddc 100644
--- a/src/rtp.h
+++ b/src/rtp.h
@@ -89,13 +89,17 @@ public:
void removeCSrc(csrc_t csrc);
void clearCSrcs();
- void setPayload(const char *payload, size_t size);
+ /**
+ * @return Number of bytes put in payload, or -1 on error.
+ * (data too big to fit inside rtp payload)
+ */
+ int setPayload(const char *payload, size_t size);
size_t payload(char *payload, size_t maxsize) const;
size_t payloadSize() const;
const char *payloadData() const;
size_t packet(char *packet, size_t maxsize) const;
- void fromPacket(const char *packet, size_t size);
+ int fromPacket(const char *packet, size_t size);
bool isValid();
void setValid(bool valid);