From 60f60cc76e43197a0825ffac9aff0b7007a94175 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Wed, 20 Nov 2013 12:57:17 +0100 Subject: Framework API now complete in its first iteration. So far with support for raw, opus and amrwb. --- src/rtp_profile_raw.cc | 123 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 src/rtp_profile_raw.cc (limited to 'src/rtp_profile_raw.cc') diff --git a/src/rtp_profile_raw.cc b/src/rtp_profile_raw.cc new file mode 100644 index 0000000..cf34186 --- /dev/null +++ b/src/rtp_profile_raw.cc @@ -0,0 +1,123 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set et sw=2 ts=2: */ +/*************************************************************************** + * rtp_profile_raw.cc + * + * Mon Sep 2 14:30:56 CEST 2013 + * Copyright 2013 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of lrtp. + * + * lrtp is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * lrtp is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with lrtp; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "rtp_profile_raw.h" + +#include "rtp_profile.h" + +#include +#include + +struct lrtp_profile_raw_t { + struct lrtp_profile_t profile; // 'Inherit' lrtp_profile_t + + unsigned short int pkg_size; + + // Cache + char *pkg_cache; + int pkg_cache_size; +}; + +int profile_raw_pack(struct lrtp_profile_t *profile, + const char *frame, size_t framesize, + RTP &rtp) +{ + struct lrtp_profile_raw_t *p = (struct lrtp_profile_raw_t *)profile; + + size_t cpsz = p->pkg_size - p->pkg_cache_size; + + if(cpsz > framesize) cpsz = framesize; + + if(cpsz != 0) { + memcpy(p->pkg_cache, frame, cpsz); + p->pkg_cache_size += cpsz; + } + + if(p->pkg_cache_size == p->pkg_size) { + rtp.setPayload(p->pkg_cache, p->pkg_cache_size); + p->pkg_cache_size = 0; + } + + return cpsz; +} + +int profile_raw_unpack(struct lrtp_profile_t *profile, + const RTP &rtp, + std::list &framelist) +{ + struct lrtp_profile_raw_t *p = (struct lrtp_profile_raw_t *)profile; + + outputframe_t *of = new outputframe_t(); + of->size = rtp.payloadSize(); + char *buf = (char*)malloc(of->size); + of->size = rtp.payload(buf, of->size); + of->data = buf; + + framelist.push_back(of); + + return 0; +} + +void profile_raw_destroy(struct lrtp_profile_t *profile) +{ + struct lrtp_profile_raw_t *p = (struct lrtp_profile_raw_t *)profile; + delete p->pkg_cache; + delete p; +} + +struct lrtp_profile_t *profile_raw_create(struct lrtp_t *lrtp, + unsigned int csrc, + va_list vp) +{ + struct lrtp_profile_raw_t *p = new struct lrtp_profile_raw_t; + + p->profile.pack = profile_raw_pack; + p->profile.unpack = profile_raw_unpack; + p->profile.destroy = profile_raw_destroy; + + p->pkg_size = 100; + + while(true) { + int type = va_arg(vp, int); + if(type == OPTION_END) break; + + switch(type) { + case OPTION_RAW_PKG_SIZE: + p->pkg_size = va_arg(vp, int); + break; + default: + // TODO: Unknown arg type + break; + } + } + + p->pkg_cache = new char[p->pkg_size]; + p->pkg_cache_size = 0; + + return &p->profile; +} + -- cgit v1.2.3