summaryrefslogtreecommitdiff
path: root/src/lrtp.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2014-05-30 10:53:59 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2014-05-30 10:53:59 +0200
commit7fc1b8f300b2ce2e7f8bd573f02b8650213c2be9 (patch)
tree3104c20c48598e3be0a9131b8280f0641771216e /src/lrtp.cc
parent87bca87ab318ff254fab4b87ac8e469925f44d22 (diff)
Add memory ownership flag to lrtp_enqueue_frame.
Diffstat (limited to 'src/lrtp.cc')
-rw-r--r--src/lrtp.cc39
1 files changed, 21 insertions, 18 deletions
diff --git a/src/lrtp.cc b/src/lrtp.cc
index 71854f0..5875a81 100644
--- a/src/lrtp.cc
+++ b/src/lrtp.cc
@@ -91,6 +91,8 @@ struct lrtp_t *lrtp_init(enum lrtp_status_t *status,
{
if(status == NULL) return NULL;
+ *status = LRTP_OK;
+
struct lrtp_t *lrtp = new (std::nothrow) struct lrtp_t;
if(!lrtp) {
*status = LRTP_OUT_OF_MEMORY;
@@ -148,8 +150,6 @@ enum lrtp_status_t lrtp_create_profile(struct lrtp_t *lrtp,
struct lrtp_profile_t *profile = NULL;
if(lrtp->profiles.find(csrc) != lrtp->profiles.end()) {
- // TODO: CSRC already active
- printf("ERROR: CSRC already active\n");
return LRTP_CSRC_ALREADY_ACTIVE;
}
@@ -169,7 +169,6 @@ enum lrtp_status_t lrtp_create_profile(struct lrtp_t *lrtp,
va_end(ap);
if(!profile) {
- printf("ERROR: Could not find profile [%d]\n", profile_id);
return LRTP_MISSING_PROFILE;
}
@@ -201,7 +200,8 @@ enum lrtp_status_t lrtp_destroy_profile(struct lrtp_t *lrtp, unsigned int csrc)
EXPORT
enum lrtp_status_t lrtp_enqueue_frame(struct lrtp_t *lrtp, unsigned int csrc,
char *data, size_t size,
- unsigned long int timestamp)
+ unsigned long int timestamp,
+ int flags)
{
CHECK_HANDLE(lrtp);
@@ -212,7 +212,19 @@ enum lrtp_status_t lrtp_enqueue_frame(struct lrtp_t *lrtp, unsigned int csrc,
struct lrtp_profile_t *profile = lrtp->profiles[csrc];
inputframe_t *frame = new inputframe_t();
- frame->data = data;
+
+ if((flags & LRTP_TAKE_OWNERSHIP) == LRTP_TAKE_OWNERSHIP) {
+ frame->owned = true;
+ frame->data = data;
+ } else if((flags & LRTP_COPY) == LRTP_COPY) {
+ frame->owned = true;
+ frame->data = (char*)malloc(size);
+ memcpy(frame->data, data, size);
+ } else {
+ frame->owned = false;
+ frame->data = data;
+ }
+
frame->size = size;
frame->offset = 0;
frame->timestamp = timestamp;
@@ -271,10 +283,6 @@ int lrtp_pack(struct lrtp_t *lrtp, char *packet, size_t maxsize)
{
CHECK_HANDLE(lrtp);
- //if(!profile) return PACK_MISSING_PROFILE;
-
- // TODO: Check profile magic word
-
struct lrtp_profile_t *profile = get_next_profile(lrtp);
if(profile == NULL || profile->framelist.size() == 0) return 0;
@@ -302,15 +310,13 @@ int lrtp_pack(struct lrtp_t *lrtp, char *packet, size_t maxsize)
profile->process_finished_ptr);
}
profile->framelist.pop_front();
- free(frame->data);
+ if(frame->owned) free(frame->data);
delete frame;
}
if(rtp.isValid()) {
size_t size = rtp.packet(packet, maxsize);
-#ifndef SKIP_SRTP
size = lrtp->srtp->encrypt(packet, size);
-#endif/*SKIP_SRTP*/
lrtp->seq++;
return size;
}
@@ -337,8 +343,8 @@ int lrtp_dequeue_frame(struct lrtp_t *lrtp,
size_t framesize = f->size;
memcpy(frame, f->data, f->size);
- *csrc = f->csrc;
- *ts = f->ts;
+ if(csrc) *csrc = f->csrc;
+ if(ts) *ts = f->ts;
lrtp->framelist.pop_front();
@@ -361,17 +367,14 @@ enum lrtp_status_t lrtp_unpack(struct lrtp_t *lrtp,
int ret = 0;
-#ifndef SKIP_SRTP
try {
ret = lrtp->srtp->decrypt(pkg, size);
+ size = ret;
} catch(enum lrtp_status_t s) {
free(pkg);
return s;
}
- size = ret;
-#endif/*SKIP_SRTP*/
-
RTP rtp;
rtp.fromPacket(pkg, size);
std::list<csrc_t> csrcs = rtp.getCSrcs();