diff options
-rw-r--r-- | src/rtp.cc | 16 | ||||
-rw-r--r-- | src/rtp.h | 8 |
2 files changed, 17 insertions, 7 deletions
@@ -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() @@ -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); |