diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2014-01-06 08:07:56 +0100 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2014-01-06 08:07:56 +0100 |
commit | 0f900a2b4d7707dddeddadd62ac5a109aed93e7e (patch) | |
tree | c7b125951de8d4e6ee045449d03b3772e84f8bac /src/lrtp.cc | |
parent | 06cd551da9405a220b170ffaf77d6554cbace69d (diff) |
Fix round robin frame selector. Add l16 and jpeg profiles. Add timestamp to lrtp_enqueue_frame.
Diffstat (limited to 'src/lrtp.cc')
-rw-r--r-- | src/lrtp.cc | 91 |
1 files changed, 61 insertions, 30 deletions
diff --git a/src/lrtp.cc b/src/lrtp.cc index da02083..69b9efe 100644 --- a/src/lrtp.cc +++ b/src/lrtp.cc @@ -36,6 +36,8 @@ #include "rtp_profile_amrwb.h" #include "rtp_profile_opus.h" #include "rtp_profile_raw.h" +#include "rtp_profile_l16.h" +#include "rtp_profile_jpeg.h" #include "srtp.h" @@ -68,6 +70,8 @@ static const profile_class_t registered_profiles[] = { { PROFILE_AMRWB, profile_amrwb_create }, { PROFILE_OPUS, profile_opus_create }, { PROFILE_RAW, profile_raw_create }, + { PROFILE_L16, profile_raw_create }, + { PROFILE_JPEG, profile_jpeg_create }, { } }; @@ -91,16 +95,16 @@ void lrtp_close(struct lrtp_t *lrtp) } EXPORT -struct lrtp_profile_t *lrtp_create_profile(struct lrtp_t *lrtp, - lrtp_profile_id_t profile_id, - unsigned int csrc, ...) +int lrtp_create_profile(struct lrtp_t *lrtp, + lrtp_profile_id_t profile_id, + unsigned int csrc, ...) { 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 NULL; + return 1; } va_list ap; @@ -118,15 +122,18 @@ struct lrtp_profile_t *lrtp_create_profile(struct lrtp_t *lrtp, va_end(ap); - if(profile) { - profile->id = PROFILE_RAW; - profile->lrtp = lrtp; - profile->csrc = csrc; - - lrtp->profiles[csrc] = profile; + if(!profile) { + printf("ERROR: Could not find profile [%d]\n", profile_id); + return 1; } - return profile; + profile->id = profile_id; + profile->lrtp = lrtp; + profile->csrc = csrc; + + lrtp->profiles[csrc] = profile; + + return 0; } EXPORT @@ -144,13 +151,23 @@ void lrtp_destroy_profile(struct lrtp_t *lrtp, unsigned int csrc) } EXPORT -int lrtp_enqueue_frame(struct lrtp_profile_t *profile, - const char *data, size_t size) +int lrtp_enqueue_frame(struct lrtp_t *lrtp, unsigned int csrc, + const char *data, size_t size, + unsigned long int timestamp) { + if(lrtp->profiles.find(csrc) == lrtp->profiles.end()) { + // TODO: CSRC not found + printf("ERROR: CSRC not found\n"); + return 1; + } + + struct lrtp_profile_t *profile = lrtp->profiles[csrc]; + inputframe_t *frame = new inputframe_t(); frame->data = data; frame->size = size; frame->offset = 0; + frame->timestamp = timestamp; //printf("lrtp_enqueue_frame: frame->size: %d\n", frame->size); @@ -159,31 +176,46 @@ int lrtp_enqueue_frame(struct lrtp_profile_t *profile, return 0; } -static lrtp_profile_t *get_next_profile(struct lrtp_t *lrtp) +// Assume we have at least one csrc in the list +static csrc_t get_next_csrc(struct lrtp_t *lrtp) { - // TODO: This function /should/ return the next profile containing frame data, - // not just the next profile in the list (regardless of it's framequeue being - // empty!). - - if(lrtp->profiles.size() == 0) return NULL; // No profiles - profile_map_t::iterator i = lrtp->profiles.find(lrtp->next_csrc); if(i == lrtp->profiles.end()) { + // If we haven't got a valid csrc start from the beginning. i = lrtp->profiles.begin(); + } else { + // Otherwise increase the iterator, potentially wrapping. + i++; + if(i == lrtp->profiles.end()) i = lrtp->profiles.begin(); } - struct lrtp_profile_t *profile = i->second; + lrtp->next_csrc = i->second->csrc; + + return lrtp->next_csrc; +} - i++; +static lrtp_profile_t *get_next_profile(struct lrtp_t *lrtp) +{ + if(lrtp->profiles.size() == 0) return NULL; // No profiles - if(i == lrtp->profiles.end()) { - i = lrtp->profiles.begin(); - } - - lrtp->next_csrc = i->second->csrc; + csrc_t start = get_next_csrc(lrtp); + csrc_t cur = start; + do { + if(lrtp->profiles.find(cur) == lrtp->profiles.end()) { + printf("ERROR: This shouldn't happen." + " Selected profile is not in the list\n"); + break; + } - return profile; + struct lrtp_profile_t *profile = lrtp->profiles.find(cur)->second; + if(profile->framelist.size()) return profile; + + cur = get_next_csrc(lrtp); + + } while(cur != start); + + return NULL; } EXPORT @@ -201,7 +233,7 @@ int lrtp_pack(struct lrtp_t *lrtp, char *packet, size_t maxsize) RTP rtp; rtp.setSSrc(lrtp->ssrc); - //rtp.setTimestamp(ts); // TODO... + rtp.setTimestamp(frame->timestamp); rtp.setSeq(lrtp->seq); rtp.addCSrc(profile->csrc); @@ -219,7 +251,6 @@ int lrtp_pack(struct lrtp_t *lrtp, char *packet, size_t maxsize) profile->process_finished(profile, frame->data, profile->process_finished_ptr); } - profile->framelist.pop_front(); delete frame; } |