summaryrefslogtreecommitdiff
path: root/src
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
parent87bca87ab318ff254fab4b87ac8e469925f44d22 (diff)
Add memory ownership flag to lrtp_enqueue_frame.
Diffstat (limited to 'src')
-rw-r--r--src/lrtp.cc39
-rw-r--r--src/lrtp.h22
-rw-r--r--src/rtp_profile.h1
3 files changed, 40 insertions, 22 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();
diff --git a/src/lrtp.h b/src/lrtp.h
index ec654b9..739f470 100644
--- a/src/lrtp.h
+++ b/src/lrtp.h
@@ -93,6 +93,11 @@ enum lrtp_status_t {
LRTP_BUFFER_TOO_SMALL = -32, ///< Supplied buffer was not big enough.
LRTP_CSRC_ALREADY_ACTIVE= -33, ///< CSrc already in session list.
+
+ LRTP_KEY_TOO_LONG = -34, ///< Supplied key string is longer than 64 bytes
+ LRTP_INVALID_KEY_STRING = -35, ///< Supplied key string is not valid hex.
+ LRTP_KEY_TOO_SHORT = -36, ///< Supplied key string is shorter than 64 bytes.
+
};
struct lrtp_t;
@@ -144,13 +149,21 @@ enum lrtp_status_t lrtp_create_profile(struct lrtp_t *lrtp,
EXPORT
enum lrtp_status_t lrtp_destroy_profile(struct lrtp_t *lrtp, unsigned int csrc);
+enum lrtp_data_flags_t {
+ LRTP_NO_FLAGS = 0,
+ LRTP_TAKE_OWNERSHIP = 1,
+ LRTP_COPY = 2,
+};
+
/**
* Enqueue a media frame for the packetiser.
* @param profile A pointer to profile needed for processing the frame type.
- * @param framedate The frame data that needs encapsulation.
+ * @param framedata The frame data that needs encapsulation.
* @param framesize The size in bytes of the frame data.
+ * @param timestamp TODO: TBD
+ * @param flags Controls the data memory ownership behaviour.
+ * See @ref enum lrtp_data_flags_t for possible values.
* @return TODO: TBD
- * @return 0 on success, or a negative error code on error.
* WARNING: The frame pointer cannot be freed or overwritten until all frame
* data has been handled by lrtp_pack(). Either call lrtp_pack() until it
* returns 0 after each call to lrtp_enqueue_frame or use the
@@ -159,8 +172,9 @@ 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 *framedate, size_t framesize,
- unsigned long int timestamp);
+ char *framedata, size_t framesize,
+ unsigned long int timestamp,
+ int flags);
/**
* Handle frame data from the frame queue and create at most a single sRTP
diff --git a/src/rtp_profile.h b/src/rtp_profile.h
index 6865adb..8a0d2e9 100644
--- a/src/rtp_profile.h
+++ b/src/rtp_profile.h
@@ -40,6 +40,7 @@ typedef struct {
size_t size;
size_t offset;
unsigned long int timestamp;
+ bool owned; // Set to true to for lrtp to not free the data pointer when done.
} inputframe_t;
typedef std::list<inputframe_t *> iframelist_t;