* #36737: switch back to svn repo, remove assert in sip_transaction.c
diff --git a/jni/pjproject-android/.svn/pristine/81/811af78c55ce52ce88312106b7b71aea693c2c69.svn-base b/jni/pjproject-android/.svn/pristine/81/811af78c55ce52ce88312106b7b71aea693c2c69.svn-base
new file mode 100644
index 0000000..3a79ae3
--- /dev/null
+++ b/jni/pjproject-android/.svn/pristine/81/811af78c55ce52ce88312106b7b71aea693c2c69.svn-base
@@ -0,0 +1,883 @@
+/* $Id$ */
+/*
+ * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
+ * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+#include <pjmedia-codec/ilbc.h>
+#include <pjmedia-codec/types.h>
+#include <pjmedia/codec.h>
+#include <pjmedia/errno.h>
+#include <pjmedia/endpoint.h>
+#include <pjmedia/plc.h>
+#include <pjmedia/port.h>
+#include <pjmedia/silencedet.h>
+#include <pj/assert.h>
+#include <pj/log.h>
+#include <pj/pool.h>
+#include <pj/string.h>
+#include <pj/os.h>
+
+#if defined(PJMEDIA_ILBC_CODEC_USE_COREAUDIO)&& PJMEDIA_ILBC_CODEC_USE_COREAUDIO
+ #include <AudioToolbox/AudioToolbox.h>
+ #define iLBC_Enc_Inst_t AudioConverterRef
+ #define iLBC_Dec_Inst_t AudioConverterRef
+ #define BLOCKL_MAX 1
+#else
+ #include "../../third_party/ilbc/iLBC_encode.h"
+ #include "../../third_party/ilbc/iLBC_decode.h"
+#endif
+
+/*
+ * Only build this file if PJMEDIA_HAS_ILBC_CODEC != 0
+ */
+#if defined(PJMEDIA_HAS_ILBC_CODEC) && PJMEDIA_HAS_ILBC_CODEC != 0
+
+
+#define THIS_FILE "ilbc.c"
+#define CLOCK_RATE 8000
+#define DEFAULT_MODE 30
+
+
+/* Prototypes for iLBC factory */
+static pj_status_t ilbc_test_alloc(pjmedia_codec_factory *factory,
+ const pjmedia_codec_info *id );
+static pj_status_t ilbc_default_attr(pjmedia_codec_factory *factory,
+ const pjmedia_codec_info *id,
+ pjmedia_codec_param *attr );
+static pj_status_t ilbc_enum_codecs(pjmedia_codec_factory *factory,
+ unsigned *count,
+ pjmedia_codec_info codecs[]);
+static pj_status_t ilbc_alloc_codec(pjmedia_codec_factory *factory,
+ const pjmedia_codec_info *id,
+ pjmedia_codec **p_codec);
+static pj_status_t ilbc_dealloc_codec(pjmedia_codec_factory *factory,
+ pjmedia_codec *codec );
+
+/* Prototypes for iLBC implementation. */
+static pj_status_t ilbc_codec_init(pjmedia_codec *codec,
+ pj_pool_t *pool );
+static pj_status_t ilbc_codec_open(pjmedia_codec *codec,
+ pjmedia_codec_param *attr );
+static pj_status_t ilbc_codec_close(pjmedia_codec *codec );
+static pj_status_t ilbc_codec_modify(pjmedia_codec *codec,
+ const pjmedia_codec_param *attr );
+static pj_status_t ilbc_codec_parse(pjmedia_codec *codec,
+ void *pkt,
+ pj_size_t pkt_size,
+ const pj_timestamp *ts,
+ unsigned *frame_cnt,
+ pjmedia_frame frames[]);
+static pj_status_t ilbc_codec_encode(pjmedia_codec *codec,
+ const struct pjmedia_frame *input,
+ unsigned output_buf_len,
+ struct pjmedia_frame *output);
+static pj_status_t ilbc_codec_decode(pjmedia_codec *codec,
+ const struct pjmedia_frame *input,
+ unsigned output_buf_len,
+ struct pjmedia_frame *output);
+static pj_status_t ilbc_codec_recover(pjmedia_codec *codec,
+ unsigned output_buf_len,
+ struct pjmedia_frame *output);
+
+/* Definition for iLBC codec operations. */
+static pjmedia_codec_op ilbc_op =
+{
+ &ilbc_codec_init,
+ &ilbc_codec_open,
+ &ilbc_codec_close,
+ &ilbc_codec_modify,
+ &ilbc_codec_parse,
+ &ilbc_codec_encode,
+ &ilbc_codec_decode,
+ &ilbc_codec_recover
+};
+
+/* Definition for iLBC codec factory operations. */
+static pjmedia_codec_factory_op ilbc_factory_op =
+{
+ &ilbc_test_alloc,
+ &ilbc_default_attr,
+ &ilbc_enum_codecs,
+ &ilbc_alloc_codec,
+ &ilbc_dealloc_codec,
+ &pjmedia_codec_ilbc_deinit
+};
+
+/* iLBC factory */
+static struct ilbc_factory
+{
+ pjmedia_codec_factory base;
+ pjmedia_endpt *endpt;
+
+ int mode;
+ int bps;
+} ilbc_factory;
+
+
+/* iLBC codec private data. */
+struct ilbc_codec
+{
+ pjmedia_codec base;
+ pj_pool_t *pool;
+ char obj_name[PJ_MAX_OBJ_NAME];
+ pjmedia_silence_det *vad;
+ pj_bool_t vad_enabled;
+ pj_bool_t plc_enabled;
+ pj_timestamp last_tx;
+
+
+ pj_bool_t enc_ready;
+ iLBC_Enc_Inst_t enc;
+ unsigned enc_frame_size;
+ unsigned enc_samples_per_frame;
+ float enc_block[BLOCKL_MAX];
+
+ pj_bool_t dec_ready;
+ iLBC_Dec_Inst_t dec;
+ unsigned dec_frame_size;
+ unsigned dec_samples_per_frame;
+ float dec_block[BLOCKL_MAX];
+
+#if defined(PJMEDIA_ILBC_CODEC_USE_COREAUDIO)&& PJMEDIA_ILBC_CODEC_USE_COREAUDIO
+ unsigned enc_total_packets;
+ char *enc_buffer;
+ unsigned enc_buffer_offset;
+
+ unsigned dec_total_packets;
+ char *dec_buffer;
+ unsigned dec_buffer_offset;
+#endif
+};
+
+static pj_str_t STR_MODE = {"mode", 4};
+
+/*
+ * Initialize and register iLBC codec factory to pjmedia endpoint.
+ */
+PJ_DEF(pj_status_t) pjmedia_codec_ilbc_init( pjmedia_endpt *endpt,
+ int mode )
+{
+ pjmedia_codec_mgr *codec_mgr;
+ pj_status_t status;
+
+ PJ_ASSERT_RETURN(endpt != NULL, PJ_EINVAL);
+ PJ_ASSERT_RETURN(mode==0 || mode==20 || mode==30, PJ_EINVAL);
+
+ /* Create iLBC codec factory. */
+ ilbc_factory.base.op = &ilbc_factory_op;
+ ilbc_factory.base.factory_data = NULL;
+ ilbc_factory.endpt = endpt;
+
+ if (mode == 0)
+ mode = DEFAULT_MODE;
+
+ ilbc_factory.mode = mode;
+
+ if (mode == 20) {
+ ilbc_factory.bps = 15200;
+ } else {
+ ilbc_factory.bps = 13333;
+ }
+
+ /* Get the codec manager. */
+ codec_mgr = pjmedia_endpt_get_codec_mgr(endpt);
+ if (!codec_mgr)
+ return PJ_EINVALIDOP;
+
+ /* Register codec factory to endpoint. */
+ status = pjmedia_codec_mgr_register_factory(codec_mgr,
+ &ilbc_factory.base);
+ if (status != PJ_SUCCESS)
+ return status;
+
+
+ /* Done. */
+ return PJ_SUCCESS;
+}
+
+
+
+/*
+ * Unregister iLBC codec factory from pjmedia endpoint and deinitialize
+ * the iLBC codec library.
+ */
+PJ_DEF(pj_status_t) pjmedia_codec_ilbc_deinit(void)
+{
+ pjmedia_codec_mgr *codec_mgr;
+ pj_status_t status;
+
+
+ /* Get the codec manager. */
+ codec_mgr = pjmedia_endpt_get_codec_mgr(ilbc_factory.endpt);
+ if (!codec_mgr)
+ return PJ_EINVALIDOP;
+
+ /* Unregister iLBC codec factory. */
+ status = pjmedia_codec_mgr_unregister_factory(codec_mgr,
+ &ilbc_factory.base);
+
+ return status;
+}
+
+/*
+ * Check if factory can allocate the specified codec.
+ */
+static pj_status_t ilbc_test_alloc( pjmedia_codec_factory *factory,
+ const pjmedia_codec_info *info )
+{
+ const pj_str_t ilbc_tag = { "iLBC", 4};
+
+ PJ_UNUSED_ARG(factory);
+ PJ_ASSERT_RETURN(factory==&ilbc_factory.base, PJ_EINVAL);
+
+
+ /* Type MUST be audio. */
+ if (info->type != PJMEDIA_TYPE_AUDIO)
+ return PJMEDIA_CODEC_EUNSUP;
+
+ /* Check encoding name. */
+ if (pj_stricmp(&info->encoding_name, &ilbc_tag) != 0)
+ return PJMEDIA_CODEC_EUNSUP;
+
+ /* Check clock-rate */
+ if (info->clock_rate != CLOCK_RATE)
+ return PJMEDIA_CODEC_EUNSUP;
+
+ /* Channel count must be one */
+ if (info->channel_cnt != 1)
+ return PJMEDIA_CODEC_EUNSUP;
+
+ /* Yes, this should be iLBC! */
+ return PJ_SUCCESS;
+}
+
+
+/*
+ * Generate default attribute.
+ */
+static pj_status_t ilbc_default_attr (pjmedia_codec_factory *factory,
+ const pjmedia_codec_info *id,
+ pjmedia_codec_param *attr )
+{
+ PJ_UNUSED_ARG(factory);
+ PJ_ASSERT_RETURN(factory==&ilbc_factory.base, PJ_EINVAL);
+
+ PJ_UNUSED_ARG(id);
+ PJ_ASSERT_RETURN(pj_stricmp2(&id->encoding_name, "iLBC")==0, PJ_EINVAL);
+
+ pj_bzero(attr, sizeof(pjmedia_codec_param));
+
+ attr->info.clock_rate = CLOCK_RATE;
+ attr->info.channel_cnt = 1;
+ attr->info.avg_bps = ilbc_factory.bps;
+ attr->info.max_bps = 15200;
+ attr->info.pcm_bits_per_sample = 16;
+ attr->info.frm_ptime = (short)ilbc_factory.mode;
+ attr->info.pt = PJMEDIA_RTP_PT_ILBC;
+
+ attr->setting.frm_per_pkt = 1;
+ attr->setting.vad = 1;
+ attr->setting.plc = 1;
+ attr->setting.penh = 1;
+ attr->setting.dec_fmtp.cnt = 1;
+ attr->setting.dec_fmtp.param[0].name = STR_MODE;
+ if (ilbc_factory.mode == 30)
+ attr->setting.dec_fmtp.param[0].val = pj_str("30");
+ else
+ attr->setting.dec_fmtp.param[0].val = pj_str("20");
+
+ return PJ_SUCCESS;
+}
+
+/*
+ * Enum codecs supported by this factory (i.e. only iLBC!).
+ */
+static pj_status_t ilbc_enum_codecs(pjmedia_codec_factory *factory,
+ unsigned *count,
+ pjmedia_codec_info codecs[])
+{
+ PJ_UNUSED_ARG(factory);
+ PJ_ASSERT_RETURN(factory==&ilbc_factory.base, PJ_EINVAL);
+
+ PJ_ASSERT_RETURN(codecs && *count > 0, PJ_EINVAL);
+
+ pj_bzero(&codecs[0], sizeof(pjmedia_codec_info));
+
+ codecs[0].encoding_name = pj_str("iLBC");
+ codecs[0].pt = PJMEDIA_RTP_PT_ILBC;
+ codecs[0].type = PJMEDIA_TYPE_AUDIO;
+ codecs[0].clock_rate = 8000;
+ codecs[0].channel_cnt = 1;
+
+ *count = 1;
+
+ return PJ_SUCCESS;
+}
+
+/*
+ * Allocate a new iLBC codec instance.
+ */
+static pj_status_t ilbc_alloc_codec(pjmedia_codec_factory *factory,
+ const pjmedia_codec_info *id,
+ pjmedia_codec **p_codec)
+{
+ pj_pool_t *pool;
+ struct ilbc_codec *codec;
+
+ PJ_ASSERT_RETURN(factory && id && p_codec, PJ_EINVAL);
+ PJ_ASSERT_RETURN(factory == &ilbc_factory.base, PJ_EINVAL);
+
+ pool = pjmedia_endpt_create_pool(ilbc_factory.endpt, "iLBC%p",
+ 2000, 2000);
+ PJ_ASSERT_RETURN(pool != NULL, PJ_ENOMEM);
+
+ codec = PJ_POOL_ZALLOC_T(pool, struct ilbc_codec);
+ codec->base.op = &ilbc_op;
+ codec->base.factory = factory;
+ codec->pool = pool;
+
+ pj_ansi_snprintf(codec->obj_name, sizeof(codec->obj_name),
+ "ilbc%p", codec);
+
+ *p_codec = &codec->base;
+ return PJ_SUCCESS;
+}
+
+
+/*
+ * Free codec.
+ */
+static pj_status_t ilbc_dealloc_codec( pjmedia_codec_factory *factory,
+ pjmedia_codec *codec )
+{
+ struct ilbc_codec *ilbc_codec;
+
+ PJ_ASSERT_RETURN(factory && codec, PJ_EINVAL);
+ PJ_UNUSED_ARG(factory);
+ PJ_ASSERT_RETURN(factory == &ilbc_factory.base, PJ_EINVAL);
+
+ ilbc_codec = (struct ilbc_codec*) codec;
+
+#if defined(PJMEDIA_ILBC_CODEC_USE_COREAUDIO)&& PJMEDIA_ILBC_CODEC_USE_COREAUDIO
+ if (ilbc_codec->enc) {
+ AudioConverterDispose(ilbc_codec->enc);
+ ilbc_codec->enc = NULL;
+ }
+ if (ilbc_codec->dec) {
+ AudioConverterDispose(ilbc_codec->dec);
+ ilbc_codec->dec = NULL;
+ }
+#endif
+
+ pj_pool_release(ilbc_codec->pool);
+
+ return PJ_SUCCESS;
+}
+
+/*
+ * Init codec.
+ */
+static pj_status_t ilbc_codec_init(pjmedia_codec *codec,
+ pj_pool_t *pool )
+{
+ PJ_UNUSED_ARG(codec);
+ PJ_UNUSED_ARG(pool);
+ return PJ_SUCCESS;
+}
+
+/*
+ * Open codec.
+ */
+static pj_status_t ilbc_codec_open(pjmedia_codec *codec,
+ pjmedia_codec_param *attr )
+{
+ struct ilbc_codec *ilbc_codec = (struct ilbc_codec*)codec;
+ pj_status_t status;
+ unsigned i;
+ pj_uint16_t dec_fmtp_mode = DEFAULT_MODE,
+ enc_fmtp_mode = DEFAULT_MODE;
+
+#if defined(PJMEDIA_ILBC_CODEC_USE_COREAUDIO)&& PJMEDIA_ILBC_CODEC_USE_COREAUDIO
+ AudioStreamBasicDescription srcFormat, dstFormat;
+ UInt32 size;
+
+ srcFormat.mSampleRate = attr->info.clock_rate;
+ srcFormat.mFormatID = kAudioFormatLinearPCM;
+ srcFormat.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger
+ | kLinearPCMFormatFlagIsPacked;
+ srcFormat.mBitsPerChannel = attr->info.pcm_bits_per_sample;
+ srcFormat.mChannelsPerFrame = attr->info.channel_cnt;
+ srcFormat.mBytesPerFrame = srcFormat.mChannelsPerFrame
+ * srcFormat.mBitsPerChannel >> 3;
+ srcFormat.mFramesPerPacket = 1;
+ srcFormat.mBytesPerPacket = srcFormat.mBytesPerFrame *
+ srcFormat.mFramesPerPacket;
+
+ memset(&dstFormat, 0, sizeof(dstFormat));
+ dstFormat.mSampleRate = attr->info.clock_rate;
+ dstFormat.mFormatID = kAudioFormatiLBC;
+ dstFormat.mChannelsPerFrame = attr->info.channel_cnt;
+#endif
+
+ pj_assert(ilbc_codec != NULL);
+ pj_assert(ilbc_codec->enc_ready == PJ_FALSE &&
+ ilbc_codec->dec_ready == PJ_FALSE);
+
+ /* Get decoder mode */
+ for (i = 0; i < attr->setting.dec_fmtp.cnt; ++i) {
+ if (pj_stricmp(&attr->setting.dec_fmtp.param[i].name, &STR_MODE) == 0)
+ {
+ dec_fmtp_mode = (pj_uint16_t)
+ pj_strtoul(&attr->setting.dec_fmtp.param[i].val);
+ break;
+ }
+ }
+
+ /* Decoder mode must be set */
+ PJ_ASSERT_RETURN(dec_fmtp_mode == 20 || dec_fmtp_mode == 30,
+ PJMEDIA_CODEC_EINMODE);
+
+ /* Get encoder mode */
+ for (i = 0; i < attr->setting.enc_fmtp.cnt; ++i) {
+ if (pj_stricmp(&attr->setting.enc_fmtp.param[i].name, &STR_MODE) == 0)
+ {
+ enc_fmtp_mode = (pj_uint16_t)
+ pj_strtoul(&attr->setting.enc_fmtp.param[i].val);
+ break;
+ }
+ }
+
+ PJ_ASSERT_RETURN(enc_fmtp_mode==20 || enc_fmtp_mode==30,
+ PJMEDIA_CODEC_EINMODE);
+
+ /* Both sides of a bi-directional session MUST use the same "mode" value.
+ * In this point, possible values are only 20 or 30, so when encoder and
+ * decoder modes are not same, just use the default mode, it is 30.
+ */
+ if (enc_fmtp_mode != dec_fmtp_mode) {
+ enc_fmtp_mode = dec_fmtp_mode = DEFAULT_MODE;
+ PJ_LOG(4,(ilbc_codec->obj_name,
+ "Normalized iLBC encoder and decoder modes to %d",
+ DEFAULT_MODE));
+ }
+
+ /* Update some attributes based on negotiated mode. */
+ attr->info.avg_bps = (dec_fmtp_mode == 30? 13333 : 15200);
+ attr->info.frm_ptime = dec_fmtp_mode;
+
+ /* Create encoder */
+#if defined(PJMEDIA_ILBC_CODEC_USE_COREAUDIO)&& PJMEDIA_ILBC_CODEC_USE_COREAUDIO
+ dstFormat.mFramesPerPacket = CLOCK_RATE * enc_fmtp_mode / 1000;
+ dstFormat.mBytesPerPacket = (enc_fmtp_mode == 20? 38 : 50);
+
+ /* Use AudioFormat API to fill out the rest of the description */
+ size = sizeof(dstFormat);
+ AudioFormatGetProperty(kAudioFormatProperty_FormatInfo,
+ 0, NULL, &size, &dstFormat);
+
+ if (AudioConverterNew(&srcFormat, &dstFormat, &ilbc_codec->enc) != noErr)
+ return PJMEDIA_CODEC_EFAILED;
+ ilbc_codec->enc_frame_size = (enc_fmtp_mode == 20? 38 : 50);
+#else
+ ilbc_codec->enc_frame_size = initEncode(&ilbc_codec->enc, enc_fmtp_mode);
+#endif
+ ilbc_codec->enc_samples_per_frame = CLOCK_RATE * enc_fmtp_mode / 1000;
+ ilbc_codec->enc_ready = PJ_TRUE;
+
+ /* Create decoder */
+#if defined(PJMEDIA_ILBC_CODEC_USE_COREAUDIO)&& PJMEDIA_ILBC_CODEC_USE_COREAUDIO
+ if (AudioConverterNew(&dstFormat, &srcFormat, &ilbc_codec->dec) != noErr)
+ return PJMEDIA_CODEC_EFAILED;
+ ilbc_codec->dec_samples_per_frame = CLOCK_RATE * dec_fmtp_mode / 1000;
+#else
+ ilbc_codec->dec_samples_per_frame = initDecode(&ilbc_codec->dec,
+ dec_fmtp_mode,
+ attr->setting.penh);
+#endif
+ ilbc_codec->dec_frame_size = (dec_fmtp_mode == 20? 38 : 50);
+ ilbc_codec->dec_ready = PJ_TRUE;
+
+ /* Save plc flags */
+ ilbc_codec->plc_enabled = (attr->setting.plc != 0);
+
+ /* Create silence detector. */
+ ilbc_codec->vad_enabled = (attr->setting.vad != 0);
+ status = pjmedia_silence_det_create(ilbc_codec->pool, CLOCK_RATE,
+ ilbc_codec->enc_samples_per_frame,
+ &ilbc_codec->vad);
+ if (status != PJ_SUCCESS)
+ return status;
+
+ /* Init last_tx (not necessary because of zalloc, but better
+ * be safe in case someone remove zalloc later.
+ */
+ pj_set_timestamp32(&ilbc_codec->last_tx, 0, 0);
+
+ PJ_LOG(5,(ilbc_codec->obj_name,
+ "iLBC codec opened, mode=%d", dec_fmtp_mode));
+
+ return PJ_SUCCESS;
+}
+
+
+/*
+ * Close codec.
+ */
+static pj_status_t ilbc_codec_close( pjmedia_codec *codec )
+{
+ struct ilbc_codec *ilbc_codec = (struct ilbc_codec*)codec;
+
+ PJ_UNUSED_ARG(codec);
+
+ PJ_LOG(5,(ilbc_codec->obj_name, "iLBC codec closed"));
+
+ return PJ_SUCCESS;
+}
+
+/*
+ * Modify codec settings.
+ */
+static pj_status_t ilbc_codec_modify(pjmedia_codec *codec,
+ const pjmedia_codec_param *attr )
+{
+ struct ilbc_codec *ilbc_codec = (struct ilbc_codec*)codec;
+
+ ilbc_codec->plc_enabled = (attr->setting.plc != 0);
+ ilbc_codec->vad_enabled = (attr->setting.vad != 0);
+
+ return PJ_SUCCESS;
+}
+
+/*
+ * Get frames in the packet.
+ */
+static pj_status_t ilbc_codec_parse( pjmedia_codec *codec,
+ void *pkt,
+ pj_size_t pkt_size,
+ const pj_timestamp *ts,
+ unsigned *frame_cnt,
+ pjmedia_frame frames[])
+{
+ struct ilbc_codec *ilbc_codec = (struct ilbc_codec*)codec;
+ unsigned count;
+
+ PJ_ASSERT_RETURN(frame_cnt, PJ_EINVAL);
+
+ count = 0;
+ while (pkt_size >= ilbc_codec->dec_frame_size && count < *frame_cnt) {
+ frames[count].type = PJMEDIA_FRAME_TYPE_AUDIO;
+ frames[count].buf = pkt;
+ frames[count].size = ilbc_codec->dec_frame_size;
+ frames[count].timestamp.u64 = ts->u64 + count *
+ ilbc_codec->dec_samples_per_frame;
+
+ pkt = ((char*)pkt) + ilbc_codec->dec_frame_size;
+ pkt_size -= ilbc_codec->dec_frame_size;
+
+ ++count;
+ }
+
+ *frame_cnt = count;
+ return PJ_SUCCESS;
+}
+
+#if defined(PJMEDIA_ILBC_CODEC_USE_COREAUDIO)&& PJMEDIA_ILBC_CODEC_USE_COREAUDIO
+static OSStatus encodeDataProc (
+ AudioConverterRef inAudioConverter,
+ UInt32 *ioNumberDataPackets,
+ AudioBufferList *ioData,
+ AudioStreamPacketDescription **outDataPacketDescription,
+ void *inUserData
+)
+{
+ struct ilbc_codec *ilbc_codec = (struct ilbc_codec*)inUserData;
+
+ /* Initialize in case of failure */
+ ioData->mBuffers[0].mData = NULL;
+ ioData->mBuffers[0].mDataByteSize = 0;
+
+ if (ilbc_codec->enc_total_packets < *ioNumberDataPackets) {
+ *ioNumberDataPackets = ilbc_codec->enc_total_packets;
+ }
+
+ if (*ioNumberDataPackets) {
+ ioData->mBuffers[0].mData = ilbc_codec->enc_buffer +
+ ilbc_codec->enc_buffer_offset;
+ ioData->mBuffers[0].mDataByteSize = *ioNumberDataPackets *
+ ilbc_codec->enc_samples_per_frame
+ << 1;
+ ilbc_codec->enc_buffer_offset += ioData->mBuffers[0].mDataByteSize;
+ }
+
+ ilbc_codec->enc_total_packets -= *ioNumberDataPackets;
+ return noErr;
+}
+
+static OSStatus decodeDataProc (
+ AudioConverterRef inAudioConverter,
+ UInt32 *ioNumberDataPackets,
+ AudioBufferList *ioData,
+ AudioStreamPacketDescription **outDataPacketDescription,
+ void *inUserData
+)
+{
+ struct ilbc_codec *ilbc_codec = (struct ilbc_codec*)inUserData;
+
+ /* Initialize in case of failure */
+ ioData->mBuffers[0].mData = NULL;
+ ioData->mBuffers[0].mDataByteSize = 0;
+
+ if (ilbc_codec->dec_total_packets < *ioNumberDataPackets) {
+ *ioNumberDataPackets = ilbc_codec->dec_total_packets;
+ }
+
+ if (*ioNumberDataPackets) {
+ ioData->mBuffers[0].mData = ilbc_codec->dec_buffer +
+ ilbc_codec->dec_buffer_offset;
+ ioData->mBuffers[0].mDataByteSize = *ioNumberDataPackets *
+ ilbc_codec->dec_frame_size;
+ ilbc_codec->dec_buffer_offset += ioData->mBuffers[0].mDataByteSize;
+ }
+
+ ilbc_codec->dec_total_packets -= *ioNumberDataPackets;
+ return noErr;
+}
+#endif
+
+/*
+ * Encode frame.
+ */
+static pj_status_t ilbc_codec_encode(pjmedia_codec *codec,
+ const struct pjmedia_frame *input,
+ unsigned output_buf_len,
+ struct pjmedia_frame *output)
+{
+ struct ilbc_codec *ilbc_codec = (struct ilbc_codec*)codec;
+ pj_int16_t *pcm_in;
+ pj_size_t nsamples;
+#if defined(PJMEDIA_ILBC_CODEC_USE_COREAUDIO)&& PJMEDIA_ILBC_CODEC_USE_COREAUDIO
+ UInt32 npackets;
+ OSStatus err;
+ AudioBufferList theABL;
+#endif
+
+ pj_assert(ilbc_codec && input && output);
+
+ pcm_in = (pj_int16_t*)input->buf;
+ nsamples = input->size >> 1;
+
+ PJ_ASSERT_RETURN(nsamples % ilbc_codec->enc_samples_per_frame == 0,
+ PJMEDIA_CODEC_EPCMFRMINLEN);
+ PJ_ASSERT_RETURN(output_buf_len >= ilbc_codec->enc_frame_size * nsamples /
+ ilbc_codec->enc_samples_per_frame,
+ PJMEDIA_CODEC_EFRMTOOSHORT);
+
+ /* Detect silence */
+ if (ilbc_codec->vad_enabled) {
+ pj_bool_t is_silence;
+ pj_int32_t silence_period;
+
+ silence_period = pj_timestamp_diff32(&ilbc_codec->last_tx,
+ &input->timestamp);
+
+ is_silence = pjmedia_silence_det_detect(ilbc_codec->vad,
+ (const pj_int16_t*)input->buf,
+ (input->size >> 1),
+ NULL);
+ if (is_silence &&
+ (PJMEDIA_CODEC_MAX_SILENCE_PERIOD == -1 ||
+ silence_period < PJMEDIA_CODEC_MAX_SILENCE_PERIOD*8000/1000))
+ {
+ output->type = PJMEDIA_FRAME_TYPE_NONE;
+ output->buf = NULL;
+ output->size = 0;
+ output->timestamp = input->timestamp;
+ return PJ_SUCCESS;
+ } else {
+ ilbc_codec->last_tx = input->timestamp;
+ }
+ }
+
+ /* Encode */
+ output->size = 0;
+#if defined(PJMEDIA_ILBC_CODEC_USE_COREAUDIO)&& PJMEDIA_ILBC_CODEC_USE_COREAUDIO
+ npackets = nsamples / ilbc_codec->enc_samples_per_frame;
+
+ theABL.mNumberBuffers = 1;
+ theABL.mBuffers[0].mNumberChannels = 1;
+ theABL.mBuffers[0].mDataByteSize = output_buf_len;
+ theABL.mBuffers[0].mData = output->buf;
+
+ ilbc_codec->enc_total_packets = npackets;
+ ilbc_codec->enc_buffer = (char *)input->buf;
+ ilbc_codec->enc_buffer_offset = 0;
+
+ err = AudioConverterFillComplexBuffer(ilbc_codec->enc, encodeDataProc,
+ ilbc_codec, &npackets,
+ &theABL, NULL);
+ if (err == noErr) {
+ output->size = npackets * ilbc_codec->enc_frame_size;
+ }
+#else
+ while (nsamples >= ilbc_codec->enc_samples_per_frame) {
+ unsigned i;
+
+ /* Convert to float */
+ for (i=0; i<ilbc_codec->enc_samples_per_frame; ++i) {
+ ilbc_codec->enc_block[i] = (float) (*pcm_in++);
+ }
+
+ iLBC_encode((unsigned char *)output->buf + output->size,
+ ilbc_codec->enc_block,
+ &ilbc_codec->enc);
+
+ output->size += ilbc_codec->enc.no_of_bytes;
+ nsamples -= ilbc_codec->enc_samples_per_frame;
+ }
+#endif
+
+ output->type = PJMEDIA_FRAME_TYPE_AUDIO;
+ output->timestamp = input->timestamp;
+
+ return PJ_SUCCESS;
+}
+
+/*
+ * Decode frame.
+ */
+static pj_status_t ilbc_codec_decode(pjmedia_codec *codec,
+ const struct pjmedia_frame *input,
+ unsigned output_buf_len,
+ struct pjmedia_frame *output)
+{
+ struct ilbc_codec *ilbc_codec = (struct ilbc_codec*)codec;
+#if defined(PJMEDIA_ILBC_CODEC_USE_COREAUDIO)&& PJMEDIA_ILBC_CODEC_USE_COREAUDIO
+ UInt32 npackets;
+ OSStatus err;
+ AudioBufferList theABL;
+#else
+ unsigned i;
+#endif
+
+ pj_assert(ilbc_codec != NULL);
+ PJ_ASSERT_RETURN(input && output, PJ_EINVAL);
+
+ if (output_buf_len < (ilbc_codec->dec_samples_per_frame << 1))
+ return PJMEDIA_CODEC_EPCMTOOSHORT;
+
+ if (input->size != ilbc_codec->dec_frame_size)
+ return PJMEDIA_CODEC_EFRMINLEN;
+
+ /* Decode to temporary buffer */
+#if defined(PJMEDIA_ILBC_CODEC_USE_COREAUDIO)&& PJMEDIA_ILBC_CODEC_USE_COREAUDIO
+ npackets = input->size / ilbc_codec->dec_frame_size *
+ ilbc_codec->dec_samples_per_frame;
+
+ theABL.mNumberBuffers = 1;
+ theABL.mBuffers[0].mNumberChannels = 1;
+ theABL.mBuffers[0].mDataByteSize = output_buf_len;
+ theABL.mBuffers[0].mData = output->buf;
+
+ ilbc_codec->dec_total_packets = npackets;
+ ilbc_codec->dec_buffer = (char *)input->buf;
+ ilbc_codec->dec_buffer_offset = 0;
+
+ err = AudioConverterFillComplexBuffer(ilbc_codec->dec, decodeDataProc,
+ ilbc_codec, &npackets,
+ &theABL, NULL);
+ if (err == noErr) {
+ output->size = npackets * (ilbc_codec->dec_samples_per_frame << 1);
+ }
+#else
+ iLBC_decode(ilbc_codec->dec_block, (unsigned char*) input->buf,
+ &ilbc_codec->dec, 1);
+
+ /* Convert decodec samples from float to short */
+ for (i=0; i<ilbc_codec->dec_samples_per_frame; ++i) {
+ ((short*)output->buf)[i] = (short)ilbc_codec->dec_block[i];
+ }
+ output->size = (ilbc_codec->dec_samples_per_frame << 1);
+#endif
+
+ output->type = PJMEDIA_FRAME_TYPE_AUDIO;
+ output->timestamp = input->timestamp;
+
+ return PJ_SUCCESS;
+}
+
+
+/*
+ * Recover lost frame.
+ */
+static pj_status_t ilbc_codec_recover(pjmedia_codec *codec,
+ unsigned output_buf_len,
+ struct pjmedia_frame *output)
+{
+ struct ilbc_codec *ilbc_codec = (struct ilbc_codec*)codec;
+#if defined(PJMEDIA_ILBC_CODEC_USE_COREAUDIO)&& PJMEDIA_ILBC_CODEC_USE_COREAUDIO
+ UInt32 npackets;
+ OSStatus err;
+ AudioBufferList theABL;
+#else
+ unsigned i;
+#endif
+
+ pj_assert(ilbc_codec != NULL);
+ PJ_ASSERT_RETURN(output, PJ_EINVAL);
+
+ if (output_buf_len < (ilbc_codec->dec_samples_per_frame << 1))
+ return PJMEDIA_CODEC_EPCMTOOSHORT;
+
+ /* Decode to temporary buffer */
+#if defined(PJMEDIA_ILBC_CODEC_USE_COREAUDIO)&& PJMEDIA_ILBC_CODEC_USE_COREAUDIO
+ npackets = 1;
+
+ theABL.mNumberBuffers = 1;
+ theABL.mBuffers[0].mNumberChannels = 1;
+ theABL.mBuffers[0].mDataByteSize = output_buf_len;
+ theABL.mBuffers[0].mData = output->buf;
+
+ ilbc_codec->dec_total_packets = npackets;
+ ilbc_codec->dec_buffer_offset = 0;
+ if (ilbc_codec->dec_buffer) {
+ err = AudioConverterFillComplexBuffer(ilbc_codec->dec, decodeDataProc,
+ ilbc_codec, &npackets,
+ &theABL, NULL);
+ if (err == noErr) {
+ output->size = npackets *
+ (ilbc_codec->dec_samples_per_frame << 1);
+ }
+ } else {
+ output->size = npackets * (ilbc_codec->dec_samples_per_frame << 1);
+ pj_bzero(output->buf, output->size);
+ }
+#else
+ iLBC_decode(ilbc_codec->dec_block, NULL, &ilbc_codec->dec, 0);
+
+ /* Convert decodec samples from float to short */
+ for (i=0; i<ilbc_codec->dec_samples_per_frame; ++i) {
+ ((short*)output->buf)[i] = (short)ilbc_codec->dec_block[i];
+ }
+ output->size = (ilbc_codec->dec_samples_per_frame << 1);
+#endif
+ output->type = PJMEDIA_FRAME_TYPE_AUDIO;
+
+ return PJ_SUCCESS;
+}
+
+
+#endif /* PJMEDIA_HAS_ILBC_CODEC */
diff --git a/jni/pjproject-android/.svn/pristine/81/8126b1f6621867d9174035d4173836823a2dcc12.svn-base b/jni/pjproject-android/.svn/pristine/81/8126b1f6621867d9174035d4173836823a2dcc12.svn-base
new file mode 100644
index 0000000..a5e86ea
--- /dev/null
+++ b/jni/pjproject-android/.svn/pristine/81/8126b1f6621867d9174035d4173836823a2dcc12.svn-base
@@ -0,0 +1,871 @@
+/* $Id$ */
+/*
+ * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
+ * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+#ifndef __PJMEDIA_VID_CODEC_H__
+#define __PJMEDIA_VID_CODEC_H__
+
+
+/**
+ * @file vid_codec.h
+ * @brief Video codec framework.
+ */
+
+#include <pjmedia/codec.h>
+#include <pjmedia/event.h>
+#include <pjmedia/format.h>
+#include <pjmedia/types.h>
+#include <pj/list.h>
+#include <pj/pool.h>
+
+PJ_BEGIN_DECL
+
+/**
+ * @defgroup PJMEDIA_VID_CODEC Video Codecs
+ * @ingroup PJMEDIA_CODEC
+ * @{
+ */
+
+#define PJMEDIA_VID_CODEC_MAX_DEC_FMT_CNT 8
+#define PJMEDIA_VID_CODEC_MAX_FPS_CNT 16
+
+/**
+ * This enumeration specifies the packetization property of video encoding
+ * process. The value is bitmask, and smaller value will have higher priority
+ * to be used.
+ */
+typedef enum pjmedia_vid_packing
+{
+ /**
+ * This specifies that the packetization is unknown, or if nothing
+ * is supported.
+ */
+ PJMEDIA_VID_PACKING_UNKNOWN,
+
+ /**
+ * This specifies that the result of video encoding process will be
+ * segmented into packets, which is suitable for RTP transmission.
+ * The maximum size of the packets is set in \a enc_mtu field of
+ * pjmedia_vid_codec_param.
+ */
+ PJMEDIA_VID_PACKING_PACKETS = 1,
+
+ /**
+ * This specifies that video encoding function will produce a whole
+ * or full frame from the source frame. This is normally used for
+ * encoding video for offline storage such as to an AVI file. The
+ * maximum size of the packets is set in \a enc_mtu field of
+ * pjmedia_vid_codec_param.
+ */
+ PJMEDIA_VID_PACKING_WHOLE = 2
+
+} pjmedia_vid_packing;
+
+
+/**
+ * Enumeration of video frame info flag for the bit_info field in the
+ * pjmedia_frame.
+ */
+typedef enum pjmedia_vid_frm_bit_info
+{
+ /**
+ * The video frame is keyframe.
+ */
+ PJMEDIA_VID_FRM_KEYFRAME = 1
+
+} pjmedia_vid_frm_bit_info;
+
+
+/**
+ * Encoding option.
+ */
+typedef struct pjmedia_vid_encode_opt
+{
+ /**
+ * Flag to force the encoder to generate keyframe for the specified input
+ * frame. When this flag is set, application can verify the result by
+ * examining PJMEDIA_VID_FRM_KEYFRAME flag in the bit_info field of the
+ * output frame.
+ */
+ pj_bool_t force_keyframe;
+
+} pjmedia_vid_encode_opt;
+
+
+/**
+ * Identification used to search for codec factory that supports specific
+ * codec specification.
+ */
+typedef struct pjmedia_vid_codec_info
+{
+ pjmedia_format_id fmt_id; /**< Encoded format ID */
+ unsigned pt; /**< Payload type */
+ pj_str_t encoding_name; /**< Encoding name */
+ pj_str_t encoding_desc; /**< Encoding desc */
+ unsigned clock_rate; /**< Clock rate */
+ pjmedia_dir dir; /**< Direction */
+ unsigned dec_fmt_id_cnt; /**< # of supported encoding source
+ format IDs */
+ pjmedia_format_id dec_fmt_id[PJMEDIA_VID_CODEC_MAX_DEC_FMT_CNT];
+ /**< Supported encoding source
+ format IDs */
+ unsigned packings; /**< Supported or requested packings,
+ strategies, bitmask from
+ pjmedia_vid_packing */
+ unsigned fps_cnt; /**< # of supported frame-rates, can be
+ zero (support any frame-rate) */
+ pjmedia_ratio fps[PJMEDIA_VID_CODEC_MAX_FPS_CNT];
+ /**< Supported frame-rates */
+
+} pjmedia_vid_codec_info;
+
+
+/**
+ * Detailed codec attributes used in configuring a codec and in querying
+ * the capability of codec factories. Default attributes of any codecs could
+ * be queried using #pjmedia_vid_codec_mgr_get_default_param() and modified
+ * using #pjmedia_vid_codec_mgr_set_default_param().
+ *
+ * Please note that codec parameter also contains SDP specific setting,
+ * #dec_fmtp and #enc_fmtp, which may need to be set appropriately based on
+ * the effective setting. See each codec documentation for more detail.
+ */
+typedef struct pjmedia_vid_codec_param
+{
+ pjmedia_dir dir; /**< Direction */
+ pjmedia_vid_packing packing; /**< Packetization strategy. */
+
+ pjmedia_format enc_fmt; /**< Encoded format */
+ pjmedia_codec_fmtp enc_fmtp; /**< Encoder fmtp params */
+ unsigned enc_mtu; /**< MTU or max payload size setting*/
+
+ pjmedia_format dec_fmt; /**< Decoded format */
+ pjmedia_codec_fmtp dec_fmtp; /**< Decoder fmtp params */
+
+ pj_bool_t ignore_fmtp; /**< Ignore fmtp params. If set to
+ PJ_TRUE, the codec will apply
+ format settings specified in
+ enc_fmt and dec_fmt only. */
+
+} pjmedia_vid_codec_param;
+
+
+/**
+ * Duplicate video codec parameter.
+ *
+ * @param pool The pool.
+ * @param src The video codec parameter to be duplicated.
+ *
+ * @return Duplicated codec parameter.
+ */
+PJ_DECL(pjmedia_vid_codec_param*) pjmedia_vid_codec_param_clone(
+ pj_pool_t *pool,
+ const pjmedia_vid_codec_param *src);
+
+/**
+ * Forward declaration for video codec.
+ */
+typedef struct pjmedia_vid_codec pjmedia_vid_codec;
+
+
+/**
+ * This structure describes codec operations. Each codec MUST implement
+ * all of these functions.
+ */
+typedef struct pjmedia_vid_codec_op
+{
+ /**
+ * See #pjmedia_vid_codec_init().
+ */
+ pj_status_t (*init)(pjmedia_vid_codec *codec,
+ pj_pool_t *pool );
+
+ /**
+ * See #pjmedia_vid_codec_open().
+ */
+ pj_status_t (*open)(pjmedia_vid_codec *codec,
+ pjmedia_vid_codec_param *param );
+
+ /**
+ * See #pjmedia_vid_codec_close().
+ */
+ pj_status_t (*close)(pjmedia_vid_codec *codec);
+
+ /**
+ * See #pjmedia_vid_codec_modify().
+ */
+ pj_status_t (*modify)(pjmedia_vid_codec *codec,
+ const pjmedia_vid_codec_param *param);
+
+ /**
+ * See #pjmedia_vid_codec_get_param().
+ */
+ pj_status_t (*get_param)(pjmedia_vid_codec *codec,
+ pjmedia_vid_codec_param *param);
+
+ /**
+ * See #pjmedia_vid_codec_encode_begin().
+ */
+ pj_status_t (*encode_begin)(pjmedia_vid_codec *codec,
+ const pjmedia_vid_encode_opt *opt,
+ const pjmedia_frame *input,
+ unsigned out_size,
+ pjmedia_frame *output,
+ pj_bool_t *has_more);
+
+ /**
+ * See #pjmedia_vid_codec_encode_more()
+ */
+ pj_status_t (*encode_more)(pjmedia_vid_codec *codec,
+ unsigned out_size,
+ pjmedia_frame *output,
+ pj_bool_t *has_more);
+
+
+ /*
+ * See #pjmedia_vid_codec_decode().
+ */
+ pj_status_t (*decode)(pjmedia_vid_codec *codec,
+ pj_size_t count,
+ pjmedia_frame packets[],
+ unsigned out_size,
+ pjmedia_frame *output);
+
+ /**
+ * See #pjmedia_vid_codec_recover()
+ */
+ pj_status_t (*recover)(pjmedia_vid_codec *codec,
+ unsigned out_size,
+ pjmedia_frame *output);
+
+} pjmedia_vid_codec_op;
+
+
+
+/*
+ * Forward declaration for pjmedia_vid_codec_factory.
+ */
+typedef struct pjmedia_vid_codec_factory pjmedia_vid_codec_factory;
+
+
+/**
+ * This structure describes a video codec instance. Codec implementers
+ * should use #pjmedia_vid_codec_init() to initialize this structure with
+ * default values.
+ */
+struct pjmedia_vid_codec
+{
+ /** Entries to put this codec instance in codec factory's list. */
+ PJ_DECL_LIST_MEMBER(struct pjmedia_vid_codec);
+
+ /** Codec's private data. */
+ void *codec_data;
+
+ /** Codec factory where this codec was allocated. */
+ pjmedia_vid_codec_factory *factory;
+
+ /** Operations to codec. */
+ pjmedia_vid_codec_op *op;
+};
+
+
+
+/**
+ * This structure describes operations that must be supported by codec
+ * factories.
+ */
+typedef struct pjmedia_vid_codec_factory_op
+{
+ /**
+ * Check whether the factory can create codec with the specified
+ * codec info.
+ *
+ * @param factory The codec factory.
+ * @param info The codec info.
+ *
+ * @return PJ_SUCCESS if this factory is able to create an
+ * instance of codec with the specified info.
+ */
+ pj_status_t (*test_alloc)(pjmedia_vid_codec_factory *factory,
+ const pjmedia_vid_codec_info *info );
+
+ /**
+ * Create default attributes for the specified codec ID. This function
+ * can be called by application to get the capability of the codec.
+ *
+ * @param factory The codec factory.
+ * @param info The codec info.
+ * @param attr The attribute to be initialized.
+ *
+ * @return PJ_SUCCESS if success.
+ */
+ pj_status_t (*default_attr)(pjmedia_vid_codec_factory *factory,
+ const pjmedia_vid_codec_info *info,
+ pjmedia_vid_codec_param *attr );
+
+ /**
+ * Enumerate supported codecs that can be created using this factory.
+ *
+ * @param factory The codec factory.
+ * @param count On input, specifies the number of elements in
+ * the array. On output, the value will be set to
+ * the number of elements that have been initialized
+ * by this function.
+ * @param info The codec info array, which contents will be
+ * initialized upon return.
+ *
+ * @return PJ_SUCCESS on success.
+ */
+ pj_status_t (*enum_info)(pjmedia_vid_codec_factory *factory,
+ unsigned *count,
+ pjmedia_vid_codec_info codecs[]);
+
+ /**
+ * Create one instance of the codec with the specified codec info.
+ *
+ * @param factory The codec factory.
+ * @param info The codec info.
+ * @param p_codec Pointer to receive the codec instance.
+ *
+ * @return PJ_SUCCESS on success.
+ */
+ pj_status_t (*alloc_codec)(pjmedia_vid_codec_factory *factory,
+ const pjmedia_vid_codec_info *info,
+ pjmedia_vid_codec **p_codec);
+
+ /**
+ * This function is called by codec manager to return a particular
+ * instance of codec back to the codec factory.
+ *
+ * @param factory The codec factory.
+ * @param codec The codec instance to be returned.
+ *
+ * @return PJ_SUCCESS on success.
+ */
+ pj_status_t (*dealloc_codec)(pjmedia_vid_codec_factory *factory,
+ pjmedia_vid_codec *codec );
+
+} pjmedia_vid_codec_factory_op;
+
+
+
+/**
+ * Codec factory describes a module that is able to create codec with specific
+ * capabilities. These capabilities can be queried by codec manager to create
+ * instances of codec.
+ */
+struct pjmedia_vid_codec_factory
+{
+ /** Entries to put this structure in the codec manager list. */
+ PJ_DECL_LIST_MEMBER(struct pjmedia_vid_codec_factory);
+
+ /** The factory's private data. */
+ void *factory_data;
+
+ /** Operations to the factory. */
+ pjmedia_vid_codec_factory_op *op;
+
+};
+
+
+/**
+ * Opaque declaration for codec manager.
+ */
+typedef struct pjmedia_vid_codec_mgr pjmedia_vid_codec_mgr;
+
+/**
+ * Declare maximum codecs
+ */
+#define PJMEDIA_VID_CODEC_MGR_MAX_CODECS 32
+
+
+/**
+ * Initialize codec manager. If there is no the default video codec manager,
+ * this function will automatically set the default video codec manager to
+ * the new codec manager instance. Normally this function is called by pjmedia
+ * endpoint's initialization code.
+ *
+ * @param pool The pool instance.
+ * @param mgr The pointer to the new codec manager instance.
+ *
+ * @return PJ_SUCCESS on success.
+ */
+PJ_DECL(pj_status_t) pjmedia_vid_codec_mgr_create(pj_pool_t *pool,
+ pjmedia_vid_codec_mgr **mgr);
+
+
+/**
+ * Destroy codec manager. Normally this function is called by pjmedia
+ * endpoint's deinitialization code.
+ *
+ * @param mgr Codec manager instance. If NULL, it is the default codec
+ * manager instance will be destroyed.
+ *
+ * @return PJ_SUCCESS on success.
+ */
+PJ_DECL(pj_status_t) pjmedia_vid_codec_mgr_destroy(pjmedia_vid_codec_mgr *mgr);
+
+
+/**
+ * Get the default codec manager instance.
+ *
+ * @return The default codec manager instance or NULL if none.
+ */
+PJ_DECL(pjmedia_vid_codec_mgr*) pjmedia_vid_codec_mgr_instance(void);
+
+
+/**
+ * Set the default codec manager instance.
+ *
+ * @param mgr The codec manager instance.
+ */
+PJ_DECL(void) pjmedia_vid_codec_mgr_set_instance(pjmedia_vid_codec_mgr* mgr);
+
+
+/**
+ * Register codec factory to codec manager. This will also register
+ * all supported codecs in the factory to the codec manager.
+ *
+ * @param mgr The codec manager instance. If NULL, the default codec
+ * manager instance will be used.
+ * @param factory The codec factory to be registered.
+ *
+ * @return PJ_SUCCESS on success.
+ */
+PJ_DECL(pj_status_t)
+pjmedia_vid_codec_mgr_register_factory( pjmedia_vid_codec_mgr *mgr,
+ pjmedia_vid_codec_factory *factory);
+
+/**
+ * Unregister codec factory from the codec manager. This will also
+ * remove all the codecs registered by the codec factory from the
+ * codec manager's list of supported codecs.
+ *
+ * @param mgr The codec manager instance. If NULL, the default codec
+ * manager instance will be used.
+ * @param factory The codec factory to be unregistered.
+ *
+ * @return PJ_SUCCESS on success.
+ */
+PJ_DECL(pj_status_t)
+pjmedia_vid_codec_mgr_unregister_factory( pjmedia_vid_codec_mgr *mgr,
+ pjmedia_vid_codec_factory *factory);
+
+/**
+ * Enumerate all supported codecs that have been registered to the
+ * codec manager by codec factories.
+ *
+ * @param mgr The codec manager instance. If NULL, the default codec
+ * manager instance will be used.
+ * @param count On input, specifies the number of elements in
+ * the array. On output, the value will be set to
+ * the number of elements that have been initialized
+ * by this function.
+ * @param info The codec info array, which contents will be
+ * initialized upon return.
+ * @param prio Optional pointer to receive array of codec priorities.
+ *
+ * @return PJ_SUCCESS on success.
+ */
+PJ_DECL(pj_status_t)
+pjmedia_vid_codec_mgr_enum_codecs(pjmedia_vid_codec_mgr *mgr,
+ unsigned *count,
+ pjmedia_vid_codec_info info[],
+ unsigned *prio);
+
+
+/**
+ * Get codec info for the specified payload type. The payload type must be
+ * static or locally defined in #pjmedia_video_pt.
+ *
+ * @param mgr The codec manager instance. If NULL, the default codec
+ * manager instance will be used.
+ * @param pt The payload type/number.
+ * @param info Pointer to receive codec info.
+ *
+ * @return PJ_SUCCESS on success.
+ */
+PJ_DECL(pj_status_t)
+pjmedia_vid_codec_mgr_get_codec_info( pjmedia_vid_codec_mgr *mgr,
+ unsigned pt,
+ const pjmedia_vid_codec_info **info);
+
+
+/**
+ * Get codec info for the specified format ID.
+ *
+ * @param mgr The codec manager instance. If NULL, the default codec
+ * manager instance will be used.
+ * @param fmt_id Format ID. See #pjmedia_format_id
+ * @param info Pointer to receive codec info.
+ *
+ * @return PJ_SUCCESS on success.
+ */
+PJ_DECL(pj_status_t)
+pjmedia_vid_codec_mgr_get_codec_info2(pjmedia_vid_codec_mgr *mgr,
+ pjmedia_format_id fmt_id,
+ const pjmedia_vid_codec_info **info);
+
+
+/**
+ * Convert codec info struct into a unique codec identifier.
+ * A codec identifier looks something like "H263/90000".
+ *
+ * @param info The codec info
+ * @param id Buffer to put the codec info string.
+ * @param max_len The length of the buffer.
+ *
+ * @return The null terminated codec info string, or NULL if
+ * the buffer is not long enough.
+ */
+PJ_DECL(char*) pjmedia_vid_codec_info_to_id(const pjmedia_vid_codec_info *info,
+ char *id, unsigned max_len );
+
+
+/**
+ * Find codecs by the unique codec identifier. This function will find
+ * all codecs that match the codec identifier prefix. For example, if
+ * "H26" is specified, then it will find "H263/90000", "H264/90000",
+ * and so on, up to the maximum count specified in the argument.
+ *
+ * @param mgr The codec manager instance. If NULL, the default codec
+ * manager instance will be used.
+ * @param codec_id The full codec ID or codec ID prefix. If an empty
+ * string is given, it will match all codecs.
+ * @param count Maximum number of codecs to find. On return, it
+ * contains the actual number of codecs found.
+ * @param p_info Array of pointer to codec info to be filled. This
+ * argument may be NULL, which in this case, only
+ * codec count will be returned.
+ * @param prio Optional array of codec priorities.
+ *
+ * @return PJ_SUCCESS if at least one codec info is found.
+ */
+PJ_DECL(pj_status_t)
+pjmedia_vid_codec_mgr_find_codecs_by_id(pjmedia_vid_codec_mgr *mgr,
+ const pj_str_t *codec_id,
+ unsigned *count,
+ const pjmedia_vid_codec_info *p_info[],
+ unsigned prio[]);
+
+
+/**
+ * Set codec priority. The codec priority determines the order of
+ * the codec in the SDP created by the endpoint. If more than one codecs
+ * are found with the same codec_id prefix, then the function sets the
+ * priorities of all those codecs.
+ *
+ * @param mgr The codec manager instance. If NULL, the default codec
+ * manager instance will be used.
+ * @param codec_id The full codec ID or codec ID prefix. If an empty
+ * string is given, it will match all codecs.
+ * @param prio Priority to be set. The priority can have any value
+ * between 1 to 255. When the priority is set to zero,
+ * the codec will be disabled.
+ *
+ * @return PJ_SUCCESS if at least one codec info is found.
+ */
+PJ_DECL(pj_status_t)
+pjmedia_vid_codec_mgr_set_codec_priority(pjmedia_vid_codec_mgr *mgr,
+ const pj_str_t *codec_id,
+ pj_uint8_t prio);
+
+
+/**
+ * Get default codec param for the specified codec info.
+ *
+ * @param mgr The codec manager instance. If NULL, the default codec
+ * manager instance will be used.
+ * @param info The codec info, which default parameter's is being
+ * queried.
+ * @param param On return, will be filled with the default codec
+ * parameter.
+ *
+ * @return PJ_SUCCESS on success.
+ */
+PJ_DECL(pj_status_t)
+pjmedia_vid_codec_mgr_get_default_param(pjmedia_vid_codec_mgr *mgr,
+ const pjmedia_vid_codec_info *info,
+ pjmedia_vid_codec_param *param);
+
+
+/**
+ * Set default codec param for the specified codec info.
+ *
+ * @param mgr The codec manager instance. If NULL, the default codec
+ * manager instance will be used.
+ * @param pool The pool instance.
+ * @param info The codec info, which default parameter's is being
+ * updated.
+ * @param param The new default codec parameter. Set to NULL to reset
+ * codec parameter to library default settings.
+ *
+ * @return PJ_SUCCESS on success.
+ */
+PJ_DECL(pj_status_t)
+pjmedia_vid_codec_mgr_set_default_param(pjmedia_vid_codec_mgr *mgr,
+ const pjmedia_vid_codec_info *info,
+ const pjmedia_vid_codec_param *param);
+
+
+/**
+ * Request the codec manager to allocate one instance of codec with the
+ * specified codec info. The codec will enumerate all codec factories
+ * until it finds factory that is able to create the specified codec.
+ *
+ * @param mgr The codec manager instance. If NULL, the default codec
+ * manager instance will be used.
+ * @param info The information about the codec to be created.
+ * @param p_codec Pointer to receive the codec instance.
+ *
+ * @return PJ_SUCCESS on success.
+ */
+PJ_DECL(pj_status_t)
+pjmedia_vid_codec_mgr_alloc_codec( pjmedia_vid_codec_mgr *mgr,
+ const pjmedia_vid_codec_info *info,
+ pjmedia_vid_codec **p_codec);
+
+/**
+ * Deallocate the specified codec instance. The codec manager will return
+ * the instance of the codec back to its factory.
+ *
+ * @param mgr The codec manager instance. If NULL, the default codec
+ * manager instance will be used.
+ * @param codec The codec instance.
+ *
+ * @return PJ_SUCESS on success.
+ */
+PJ_DECL(pj_status_t) pjmedia_vid_codec_mgr_dealloc_codec(
+ pjmedia_vid_codec_mgr *mgr,
+ pjmedia_vid_codec *codec);
+
+
+
+/**
+ * Initialize codec using the specified attribute.
+ *
+ * @param codec The codec instance.
+ * @param pool Pool to use when the codec needs to allocate
+ * some memory.
+ *
+ * @return PJ_SUCCESS on success.
+ */
+PJ_INLINE(pj_status_t) pjmedia_vid_codec_init( pjmedia_vid_codec *codec,
+ pj_pool_t *pool )
+{
+ return (*codec->op->init)(codec, pool);
+}
+
+
+/**
+ * Open the codec and initialize with the specified parameter.
+ * Upon successful initialization, the codec may modify the parameter
+ * and fills in the unspecified values (such as size or frame rate of
+ * the encoder format, as it may need to be negotiated with remote
+ * preferences via SDP fmtp).
+ *
+ * @param codec The codec instance.
+ * @param param Codec initialization parameter.
+ *
+ * @return PJ_SUCCESS on success.
+ */
+PJ_INLINE(pj_status_t) pjmedia_vid_codec_open(pjmedia_vid_codec *codec,
+ pjmedia_vid_codec_param *param)
+{
+ return (*codec->op->open)(codec, param);
+}
+
+
+/**
+ * Close and shutdown codec, releasing all resources allocated by
+ * this codec, if any.
+ *
+ * @param codec The codec instance.
+ *
+ * @return PJ_SUCCESS on success.
+ */
+PJ_INLINE(pj_status_t) pjmedia_vid_codec_close( pjmedia_vid_codec *codec )
+{
+ return (*codec->op->close)(codec);
+}
+
+
+/**
+ * Modify the codec parameter after the codec is open.
+ * Note that not all codec parameters can be modified during run-time.
+ * When the parameter cannot be changed, this function will return
+ * non-PJ_SUCCESS, and the original parameters will not be changed.
+ *
+ * @param codec The codec instance.
+ * @param param The new codec parameter.
+ *
+ * @return PJ_SUCCESS on success.
+ */
+PJ_INLINE(pj_status_t)
+pjmedia_vid_codec_modify(pjmedia_vid_codec *codec,
+ const pjmedia_vid_codec_param *param)
+{
+ return (*codec->op->modify)(codec, param);
+}
+
+
+/**
+ * Get the codec parameter after the codec is opened.
+ *
+ * @param codec The codec instance.
+ * @param param The codec parameter.
+ *
+ * @return PJ_SUCCESS on success.
+ */
+PJ_INLINE(pj_status_t)
+pjmedia_vid_codec_get_param(pjmedia_vid_codec *codec,
+ pjmedia_vid_codec_param *param)
+{
+ return (*codec->op->get_param)(codec, param);
+}
+
+/**
+ * Encode the specified input frame. The input MUST contain only one picture
+ * with the appropriate format as specified when opening the codec. Depending
+ * on the packing or packetization set in the \a packing param, the process
+ * may produce multiple encoded packets or payloads to represent the picture.
+ * This is true for example for PJMEDIA_VID_PACKING_PACKETS packing. In this
+ * case, the \a has_more field will be set to PJ_TRUE, and application should
+ * call pjmedia_vid_codec_encode_more() to get the remaining results from the
+ * codec.
+ *
+ * @param codec The codec instance.
+ * @param opt Optional encoding options.
+ * @param input The input frame.
+ * @param out_size The length of buffer in the output frame. This
+ * should be at least the same as the configured
+ * encoding MTU of the codec.
+ * @param output The output frame.
+ * @param has_more PJ_TRUE if more payloads are available; application
+ * should then call pjmedia_vid_codec_encode_more()
+ * to retrieve the remaining results.
+ *
+ * @return PJ_SUCCESS on success;
+ */
+PJ_INLINE(pj_status_t)
+pjmedia_vid_codec_encode_begin( pjmedia_vid_codec *codec,
+ const pjmedia_vid_encode_opt *opt,
+ const pjmedia_frame *input,
+ unsigned out_size,
+ pjmedia_frame *output,
+ pj_bool_t *has_more)
+{
+ return (*codec->op->encode_begin)(codec, opt, input, out_size, output,
+ has_more);
+}
+
+/**
+ * Retrieve more encoded packets/payloads from the codec. Application
+ * should call this function repeatedly until \a has_more flag is set
+ * to PJ_FALSE.
+ *
+ * @param codec The codec instance.
+ * @param out_size The length of buffer in the output frame. This
+ * should be at least the same as as the configured
+ * encoding MTU of the codec.
+ * @param output The output frame.
+ * @param has_more PJ_TRUE if more payloads are available, which in
+ * this case application should call \a encode_more()
+ * to retrieve them.
+ *
+ * @return PJ_SUCCESS on success;
+ */
+PJ_INLINE(pj_status_t)
+pjmedia_vid_codec_encode_more( pjmedia_vid_codec *codec,
+ unsigned out_size,
+ pjmedia_frame *output,
+ pj_bool_t *has_more)
+{
+ return (*codec->op->encode_more)(codec, out_size, output, has_more);
+}
+
+/**
+ * Decode the input packets into one picture. If the packing is set to
+ * PJMEDIA_VID_PACKING_PACKETS when opening the codec, the codec is set
+ * to decode multiple encoded packets into one picture. These encoded
+ * packets are typically retrieved from the jitter buffer. If the packing
+ * is set to PJMEDIA_VID_PACKING_WHOLE, then this decode function can only
+ * accept one frame as the input.
+ *
+ * Note that the decoded picture format may different to the configured
+ * setting (i.e. the format specified in the #pjmedia_vid_codec_param when
+ * opening the codec), in this case the PJMEDIA_EVENT_FMT_CHANGED event will
+ * be emitted by the codec to notify the event. The codec parameter will
+ * also be updated, and application can query the format by using
+ * pjmedia_vid_codec_get_param().
+ *
+ * @param codec The codec instance.
+ * @param pkt_count Number of packets in the input.
+ * @param packets Array of input packets, each containing an encoded
+ * frame.
+ * @param out_size The length of buffer in the output frame.
+ * @param output The output frame.
+ *
+ * @return PJ_SUCCESS on success;
+ */
+PJ_INLINE(pj_status_t) pjmedia_vid_codec_decode(pjmedia_vid_codec *codec,
+ pj_size_t pkt_count,
+ pjmedia_frame packets[],
+ unsigned out_size,
+ pjmedia_frame *output)
+{
+ return (*codec->op->decode)(codec, pkt_count, packets, out_size, output);
+}
+
+/**
+ * Recover a missing frame.
+ *
+ * @param codec The codec instance.
+ * @param out_size The length of buffer in the output frame.
+ * @param output The output frame where generated signal
+ * will be placed.
+ *
+ * @return PJ_SUCCESS on success;
+ */
+PJ_INLINE(pj_status_t) pjmedia_vid_codec_recover(pjmedia_vid_codec *codec,
+ unsigned out_size,
+ pjmedia_frame *output)
+{
+ if (codec->op && codec->op->recover)
+ return (*codec->op->recover)(codec, out_size, output);
+ else
+ return PJ_ENOTSUP;
+}
+
+
+/**
+ * @}
+ */
+
+/**
+ * @defgroup PJMEDIA_CODEC_VID_CODECS Supported video codecs
+ * @ingroup PJMEDIA_VID_CODEC
+ */
+
+
+
+
+PJ_END_DECL
+
+
+#endif /* __PJMEDIA_VID_CODEC_H__ */
diff --git a/jni/pjproject-android/.svn/pristine/81/814c12421dd1725653de5828ab1f0aa15b035fb0.svn-base b/jni/pjproject-android/.svn/pristine/81/814c12421dd1725653de5828ab1f0aa15b035fb0.svn-base
new file mode 100644
index 0000000..262c0e2
--- /dev/null
+++ b/jni/pjproject-android/.svn/pristine/81/814c12421dd1725653de5828ab1f0aa15b035fb0.svn-base
@@ -0,0 +1,78 @@
+/*
+ * hmac.h
+ *
+ * interface to hmac auth_type_t
+ *
+ * David A. McGrew
+ * Cisco Systems, Inc.
+ *
+ */
+/*
+ *
+ * Copyright (c) 2001-2006, Cisco Systems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * Neither the name of the Cisco Systems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef HMAC_H
+#define HMAC_H
+
+#include "auth.h"
+#include "sha1.h"
+
+typedef struct {
+ uint8_t opad[64];
+ sha1_ctx_t ctx;
+ sha1_ctx_t init_ctx;
+} hmac_ctx_t;
+
+err_status_t
+hmac_alloc(auth_t **a, int key_len, int out_len);
+
+err_status_t
+hmac_dealloc(auth_t *a);
+
+err_status_t
+hmac_init(hmac_ctx_t *state, const uint8_t *key, int key_len);
+
+err_status_t
+hmac_start(hmac_ctx_t *state);
+
+err_status_t
+hmac_update(hmac_ctx_t *state, const uint8_t *message, int msg_octets);
+
+err_status_t
+hmac_compute(hmac_ctx_t *state, const void *message,
+ int msg_octets, int tag_len, uint8_t *result);
+
+
+#endif /* HMAC_H */
diff --git a/jni/pjproject-android/.svn/pristine/81/81b66f9155082e766d60cd20a3214501672e0c73.svn-base b/jni/pjproject-android/.svn/pristine/81/81b66f9155082e766d60cd20a3214501672e0c73.svn-base
new file mode 100644
index 0000000..3f7bf8f
--- /dev/null
+++ b/jni/pjproject-android/.svn/pristine/81/81b66f9155082e766d60cd20a3214501672e0c73.svn-base
@@ -0,0 +1,953 @@
+/* $Id$ */
+/*
+ * Copyright (C) 2012-2012 Teluu Inc. (http://www.teluu.com)
+ * Contributed by Regis Montoya (aka r3gis - www.r3gis.fr)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <pjmedia-codec/silk.h>
+#include <pjmedia/codec.h>
+#include <pjmedia/delaybuf.h>
+#include <pjmedia/endpoint.h>
+#include <pjmedia/errno.h>
+#include <pjmedia/port.h>
+#include <pj/pool.h>
+#include <pj/string.h>
+#include <pj/assert.h>
+#include <pj/log.h>
+
+#if defined(PJMEDIA_HAS_SILK_CODEC) && (PJMEDIA_HAS_SILK_CODEC!=0)
+
+#include "SKP_Silk_SDK_API.h"
+
+#define THIS_FILE "silk.c"
+
+#ifndef PJMEDIA_SILK_DELAY_BUF_OPTIONS
+ #define PJMEDIA_SILK_DELAY_BUF_OPTIONS PJMEDIA_DELAY_BUF_SIMPLE_FIFO
+#endif
+
+#define FRAME_LENGTH_MS 20
+#define SILK_ENC_CTL_PACKET_LOSS_PCT 10
+#define SILK_MIN_BITRATE 5000
+#define CALC_BITRATE_QUALITY(quality, max_br) \
+ (quality * max_br / 10)
+#define CALC_BITRATE(max_br) \
+ CALC_BITRATE_QUALITY(PJMEDIA_CODEC_SILK_DEFAULT_QUALITY, \
+ max_br);
+
+
+/* Prototypes for SILK factory */
+static pj_status_t silk_test_alloc( pjmedia_codec_factory *factory,
+ const pjmedia_codec_info *id );
+static pj_status_t silk_default_attr( pjmedia_codec_factory *factory,
+ const pjmedia_codec_info *id,
+ pjmedia_codec_param *attr );
+static pj_status_t silk_enum_codecs ( pjmedia_codec_factory *factory,
+ unsigned *count,
+ pjmedia_codec_info codecs[]);
+static pj_status_t silk_alloc_codec( pjmedia_codec_factory *factory,
+ const pjmedia_codec_info *id,
+ pjmedia_codec **p_codec);
+static pj_status_t silk_dealloc_codec( pjmedia_codec_factory *factory,
+ pjmedia_codec *codec );
+
+/* Prototypes for SILK implementation. */
+static pj_status_t silk_codec_init( pjmedia_codec *codec,
+ pj_pool_t *pool );
+static pj_status_t silk_codec_open( pjmedia_codec *codec,
+ pjmedia_codec_param *attr );
+static pj_status_t silk_codec_close( pjmedia_codec *codec );
+static pj_status_t silk_codec_modify( pjmedia_codec *codec,
+ const pjmedia_codec_param *attr );
+static pj_status_t silk_codec_parse( pjmedia_codec *codec,
+ void *pkt,
+ pj_size_t pkt_size,
+ const pj_timestamp *timestamp,
+ unsigned *frame_cnt,
+ pjmedia_frame frames[]);
+static pj_status_t silk_codec_encode( pjmedia_codec *codec,
+ const struct pjmedia_frame *input,
+ unsigned output_buf_len,
+ struct pjmedia_frame *output);
+static pj_status_t silk_codec_decode( pjmedia_codec *codec,
+ const struct pjmedia_frame *input,
+ unsigned output_buf_len,
+ struct pjmedia_frame *output);
+static pj_status_t silk_codec_recover( pjmedia_codec *codec,
+ unsigned output_buf_len,
+ struct pjmedia_frame *output);
+
+
+typedef enum
+{
+ PARAM_NB, /* Index for narrowband parameter. */
+ PARAM_MB, /* Index for medium parameter. */
+ PARAM_WB, /* Index for wideband parameter. */
+ PARAM_SWB, /* Index for super-wideband parameter */
+} silk_mode;
+
+
+/* Silk default parameter */
+typedef struct silk_param
+{
+ int enabled; /* Is this mode enabled? */
+ int pt; /* Payload type. */
+ unsigned clock_rate; /* Default sampling rate to be used. */
+ pj_uint16_t ptime; /* packet length (in ms). */
+ pj_uint32_t bitrate; /* Bit rate for current mode. */
+ pj_uint32_t max_bitrate; /* Max bit rate for current mode. */
+ int complexity; /* Complexity mode: 0/lowest to 2. */
+} silk_param;
+
+
+/* Definition for SILK codec operations. */
+static pjmedia_codec_op silk_op =
+{
+ &silk_codec_init,
+ &silk_codec_open,
+ &silk_codec_close,
+ &silk_codec_modify,
+ &silk_codec_parse,
+ &silk_codec_encode,
+ &silk_codec_decode,
+ &silk_codec_recover
+};
+
+/* Definition for SILK codec factory operations. */
+static pjmedia_codec_factory_op silk_factory_op =
+{
+ &silk_test_alloc,
+ &silk_default_attr,
+ &silk_enum_codecs,
+ &silk_alloc_codec,
+ &silk_dealloc_codec,
+ &pjmedia_codec_silk_deinit
+};
+
+
+/* SILK factory private data */
+static struct silk_factory
+{
+ pjmedia_codec_factory base;
+ pjmedia_endpt *endpt;
+ pj_pool_t *pool;
+ pj_mutex_t *mutex;
+ struct silk_param silk_param[4];
+} silk_factory;
+
+
+/* SILK codec private data. */
+typedef struct silk_private
+{
+ silk_mode mode; /**< Silk mode. */
+ pj_pool_t *pool; /**< Pool for each instance. */
+ unsigned samples_per_frame;
+ pj_uint8_t pcm_bytes_per_sample;
+
+ pj_bool_t enc_ready;
+ SKP_SILK_SDK_EncControlStruct enc_ctl;
+ void *enc_st;
+
+ pj_bool_t dec_ready;
+ SKP_SILK_SDK_DecControlStruct dec_ctl;
+ void *dec_st;
+
+ /* Buffer to hold decoded frames. */
+ void *dec_buf[SILK_MAX_FRAMES_PER_PACKET-1];
+ SKP_int16 dec_buf_size[SILK_MAX_FRAMES_PER_PACKET-1];
+ pj_size_t dec_buf_sz;
+ unsigned dec_buf_cnt;
+ pj_uint32_t pkt_info; /**< Packet info for buffered frames. */
+} silk_private;
+
+
+silk_mode silk_get_mode_from_clock_rate(unsigned clock_rate) {
+ if (clock_rate <= silk_factory.silk_param[PARAM_NB].clock_rate) {
+ return PARAM_NB;
+ } else if (clock_rate <= silk_factory.silk_param[PARAM_MB].clock_rate) {
+ return PARAM_MB;
+ } else if (clock_rate <= silk_factory.silk_param[PARAM_WB].clock_rate) {
+ return PARAM_WB;
+ }
+ return PARAM_SWB;
+}
+
+
+PJ_DEF(pj_status_t) pjmedia_codec_silk_init(pjmedia_endpt *endpt)
+{
+ pjmedia_codec_mgr *codec_mgr;
+ silk_param *sp;
+ pj_status_t status;
+
+ if (silk_factory.endpt != NULL) {
+ /* Already initialized. */
+ return PJ_SUCCESS;
+ }
+
+ /* Init factory */
+ pj_bzero(&silk_factory, sizeof(silk_factory));
+ silk_factory.base.op = &silk_factory_op;
+ silk_factory.base.factory_data = NULL;
+ silk_factory.endpt = endpt;
+
+ /* Create pool */
+ silk_factory.pool = pjmedia_endpt_create_pool(endpt, "silk", 4000, 4000);
+ if (!silk_factory.pool)
+ return PJ_ENOMEM;
+
+ /* Create mutex. */
+ status = pj_mutex_create_simple(silk_factory.pool, "silk",
+ &silk_factory.mutex);
+ if (status != PJ_SUCCESS)
+ goto on_error;
+
+ /* Initialize default codec params */
+
+ /* From SILK docs:
+ - SILK bitrate tables:
+ +----------------+---------+-----------+
+ | | fs (Hz) | BR (kbps) |
+ +----------------+---------+-----------+
+ | Narrowband | 8000 | 6 - 20 |
+ | Mediumband | 12000 | 7 - 25 |
+ | Wideband | 16000 | 8 - 30 |
+ | Super Wideband | 24000 | 12 - 40 |
+ +----------------+---------+-----------+
+ - The upper limits of the bit rate ranges in this table are
+ recommended values.
+ */
+
+ sp = &silk_factory.silk_param[PARAM_NB];
+ sp->pt = PJMEDIA_RTP_PT_SILK_NB;
+ sp->clock_rate = 8000;
+ sp->max_bitrate = 22000;
+ sp->bitrate = CALC_BITRATE(sp->max_bitrate);
+ sp->ptime = FRAME_LENGTH_MS;
+ sp->complexity = PJMEDIA_CODEC_SILK_DEFAULT_COMPLEXITY;
+ sp->enabled = 1;
+
+ sp = &silk_factory.silk_param[PARAM_MB];
+ sp->pt = PJMEDIA_RTP_PT_SILK_MB;
+ sp->clock_rate = 12000;
+ sp->max_bitrate = 28000;
+ sp->bitrate = CALC_BITRATE(sp->max_bitrate);
+ sp->ptime = FRAME_LENGTH_MS;
+ sp->complexity = PJMEDIA_CODEC_SILK_DEFAULT_COMPLEXITY;
+ sp->enabled = 0;
+
+ sp = &silk_factory.silk_param[PARAM_WB];
+ sp->pt = PJMEDIA_RTP_PT_SILK_WB;
+ sp->clock_rate = 16000;
+ sp->max_bitrate = 36000;
+ sp->bitrate = CALC_BITRATE(sp->max_bitrate);
+ sp->ptime = FRAME_LENGTH_MS;
+ sp->complexity = PJMEDIA_CODEC_SILK_DEFAULT_COMPLEXITY;
+ sp->enabled = 1;
+
+ sp = &silk_factory.silk_param[PARAM_SWB];
+ sp->pt = PJMEDIA_RTP_PT_SILK_SWB;
+ sp->clock_rate = 24000;
+ sp->max_bitrate = 46000;
+ sp->bitrate = CALC_BITRATE(sp->max_bitrate);
+ sp->ptime = FRAME_LENGTH_MS;
+ sp->complexity = PJMEDIA_CODEC_SILK_DEFAULT_COMPLEXITY;
+ sp->enabled = 0;
+
+
+ /* Get the codec manager. */
+ codec_mgr = pjmedia_endpt_get_codec_mgr(endpt);
+ if (!codec_mgr) {
+ return PJ_EINVALIDOP;
+ }
+
+ /* Register codec factory to endpoint. */
+ status = pjmedia_codec_mgr_register_factory(codec_mgr,
+ &silk_factory.base);
+ if (status != PJ_SUCCESS)
+ return status;
+
+ PJ_LOG(4,(THIS_FILE, "SILK codec version %s initialized",
+ SKP_Silk_SDK_get_version()));
+ return PJ_SUCCESS;
+
+on_error:
+ if (silk_factory.mutex) {
+ pj_mutex_destroy(silk_factory.mutex);
+ silk_factory.mutex = NULL;
+ }
+ if (silk_factory.pool) {
+ pj_pool_release(silk_factory.pool);
+ silk_factory.pool = NULL;
+ }
+
+ return status;
+}
+
+
+/*
+ * Change the configuration setting of the SILK codec for the specified
+ * clock rate.
+ */
+PJ_DEF(pj_status_t) pjmedia_codec_silk_set_config(
+ unsigned clock_rate,
+ const pjmedia_codec_silk_setting *opt)
+{
+ unsigned i;
+
+ /* Look up in factory modes table */
+ for (i = 0; i < sizeof(silk_factory.silk_param)/
+ sizeof(silk_factory.silk_param[0]); ++i)
+ {
+ if (silk_factory.silk_param[i].clock_rate == clock_rate) {
+ int quality = PJMEDIA_CODEC_SILK_DEFAULT_QUALITY;
+ int complexity = PJMEDIA_CODEC_SILK_DEFAULT_COMPLEXITY;
+
+ silk_factory.silk_param[i].enabled = opt->enabled;
+ if (opt->complexity >= 0)
+ complexity = opt->complexity;
+ silk_factory.silk_param[i].complexity = complexity;
+ if (opt->quality >= 0)
+ quality = opt->quality;
+ silk_factory.silk_param[i].bitrate =
+ CALC_BITRATE_QUALITY(quality,
+ silk_factory.silk_param[i].max_bitrate);
+ if (silk_factory.silk_param[i].bitrate < SILK_MIN_BITRATE)
+ silk_factory.silk_param[i].bitrate = SILK_MIN_BITRATE;
+
+ return PJ_SUCCESS;
+ }
+ }
+
+ return PJ_ENOTFOUND;
+}
+
+
+/*
+ * Unregister SILK codec factory from pjmedia endpoint and deinitialize
+ * the SILK codec library.
+ */
+PJ_DEF(pj_status_t) pjmedia_codec_silk_deinit(void)
+{
+ pjmedia_codec_mgr *codec_mgr;
+ pj_status_t status;
+
+ if (silk_factory.endpt == NULL) {
+ /* Not registered. */
+ return PJ_SUCCESS;
+ }
+
+ /* Lock mutex. */
+ pj_mutex_lock(silk_factory.mutex);
+
+ /* Get the codec manager. */
+ codec_mgr = pjmedia_endpt_get_codec_mgr(silk_factory.endpt);
+ if (!codec_mgr) {
+ silk_factory.endpt = NULL;
+ pj_mutex_unlock(silk_factory.mutex);
+ return PJ_EINVALIDOP;
+ }
+
+ /* Unregister silk codec factory. */
+ status = pjmedia_codec_mgr_unregister_factory(codec_mgr,
+ &silk_factory.base);
+ silk_factory.endpt = NULL;
+
+ /* Destroy mutex. */
+ pj_mutex_destroy(silk_factory.mutex);
+ silk_factory.mutex = NULL;
+
+
+ /* Release pool. */
+ pj_pool_release(silk_factory.pool);
+ silk_factory.pool = NULL;
+
+ return status;
+}
+
+
+/*
+ * Check if factory can allocate the specified codec.
+ */
+static pj_status_t silk_test_alloc(pjmedia_codec_factory *factory,
+ const pjmedia_codec_info *info )
+{
+ const pj_str_t silk_tag = {"SILK", 4};
+ unsigned i;
+
+ PJ_UNUSED_ARG(factory);
+ PJ_ASSERT_RETURN(factory==&silk_factory.base, PJ_EINVAL);
+
+ /* Type MUST be audio. */
+ if (info->type != PJMEDIA_TYPE_AUDIO)
+ return PJMEDIA_CODEC_EUNSUP;
+
+ /* Check encoding name. */
+ if (pj_stricmp(&info->encoding_name, &silk_tag) != 0)
+ return PJMEDIA_CODEC_EUNSUP;
+
+ /* Channel count must be one */
+ if (info->channel_cnt != 1)
+ return PJMEDIA_CODEC_EUNSUP;
+
+ /* Check clock-rate */
+ for (i=0; i<PJ_ARRAY_SIZE(silk_factory.silk_param); ++i) {
+ silk_param *sp = &silk_factory.silk_param[i];
+ if (sp->enabled && info->clock_rate == sp->clock_rate)
+ {
+ return PJ_SUCCESS;
+ }
+ }
+ /* Clock rate not supported */
+ return PJMEDIA_CODEC_EUNSUP;
+}
+
+
+/*
+ * Generate default attribute.
+ */
+static pj_status_t silk_default_attr( pjmedia_codec_factory *factory,
+ const pjmedia_codec_info *id,
+ pjmedia_codec_param *attr )
+{
+ silk_param *sp;
+ int i;
+
+ PJ_ASSERT_RETURN(factory==&silk_factory.base, PJ_EINVAL);
+
+ i = silk_get_mode_from_clock_rate(id->clock_rate);
+ pj_assert(i >= PARAM_NB && i <= PARAM_SWB);
+
+ sp = &silk_factory.silk_param[i];
+
+ pj_bzero(attr, sizeof(pjmedia_codec_param));
+ attr->info.channel_cnt = 1;
+ attr->info.clock_rate = sp->clock_rate;
+ attr->info.avg_bps = sp->bitrate;
+ attr->info.max_bps = sp->max_bitrate;
+ attr->info.frm_ptime = sp->ptime;
+ attr->info.pcm_bits_per_sample = 16;
+ attr->info.pt = (pj_uint8_t) sp->pt;
+ attr->setting.frm_per_pkt = 1;
+ attr->setting.vad = 0; /* DTX is not recommended for quality reason */
+ attr->setting.plc = 1;
+
+ i = 0;
+ attr->setting.dec_fmtp.param[i].name = pj_str("useinbandfec");
+ attr->setting.dec_fmtp.param[i++].val = pj_str("0");
+ /*
+ attr->setting.dec_fmtp.param[i].name = pj_str("maxaveragebitrate");
+ attr->setting.dec_fmtp.param[i++].val = pj_str(mode->bitrate_str);
+ */
+ attr->setting.dec_fmtp.cnt = (pj_uint8_t)i;
+
+ return PJ_SUCCESS;
+}
+
+
+/*
+ * Enum codecs supported by this factory.
+ */
+static pj_status_t silk_enum_codecs(pjmedia_codec_factory *factory,
+ unsigned *count,
+ pjmedia_codec_info codecs[])
+{
+ unsigned max;
+ int i;
+
+ PJ_ASSERT_RETURN(factory==&silk_factory.base, PJ_EINVAL);
+ PJ_ASSERT_RETURN(codecs && *count > 0, PJ_EINVAL);
+
+ max = *count;
+ *count = 0;
+
+ for (i = 0; i<PJ_ARRAY_SIZE(silk_factory.silk_param) && *count<max; ++i)
+ {
+ silk_param *sp = &silk_factory.silk_param[i];
+
+ if (!sp->enabled)
+ continue;
+
+ pj_bzero(&codecs[*count], sizeof(pjmedia_codec_info));
+ codecs[*count].encoding_name = pj_str("SILK");
+ codecs[*count].pt = sp->pt;
+ codecs[*count].type = PJMEDIA_TYPE_AUDIO;
+ codecs[*count].clock_rate = sp->clock_rate;
+ codecs[*count].channel_cnt = 1;
+
+ ++*count;
+ }
+
+ return PJ_SUCCESS;
+}
+
+
+/*
+ * Allocate a new SILK codec instance.
+ */
+static pj_status_t silk_alloc_codec(pjmedia_codec_factory *factory,
+ const pjmedia_codec_info *id,
+ pjmedia_codec **p_codec)
+{
+ pj_pool_t *pool;
+ pjmedia_codec *codec;
+ silk_private *silk;
+
+ PJ_ASSERT_RETURN(factory && id && p_codec, PJ_EINVAL);
+ PJ_ASSERT_RETURN(factory == &silk_factory.base, PJ_EINVAL);
+
+ /* Create pool for codec instance */
+ pool = pjmedia_endpt_create_pool(silk_factory.endpt, "silk", 512, 512);
+
+ /* Allocate codec */
+ codec = PJ_POOL_ZALLOC_T(pool, pjmedia_codec);
+ codec->op = &silk_op;
+ codec->factory = factory;
+ codec->codec_data = PJ_POOL_ZALLOC_T(pool, silk_private);
+ silk = (silk_private*) codec->codec_data;
+ silk->pool = pool;
+ silk->enc_ready = PJ_FALSE;
+ silk->dec_ready = PJ_FALSE;
+ silk->mode = silk_get_mode_from_clock_rate(id->clock_rate);
+
+ *p_codec = codec;
+ return PJ_SUCCESS;
+}
+
+
+/*
+ * Free codec.
+ */
+static pj_status_t silk_dealloc_codec( pjmedia_codec_factory *factory,
+ pjmedia_codec *codec )
+{
+ silk_private *silk;
+
+ PJ_ASSERT_RETURN(factory && codec, PJ_EINVAL);
+ PJ_ASSERT_RETURN(factory == &silk_factory.base, PJ_EINVAL);
+
+ silk = (silk_private*)codec->codec_data;
+
+ /* Close codec, if it's not closed. */
+ if (silk->enc_ready == PJ_TRUE || silk->dec_ready == PJ_TRUE) {
+ silk_codec_close(codec);
+ }
+
+ pj_pool_release(silk->pool);
+
+ return PJ_SUCCESS;
+}
+
+
+/*
+ * Init codec.
+ */
+static pj_status_t silk_codec_init(pjmedia_codec *codec,
+ pj_pool_t *pool )
+{
+ PJ_UNUSED_ARG(codec);
+ PJ_UNUSED_ARG(pool);
+ return PJ_SUCCESS;
+}
+
+
+/*
+ * Open codec.
+ */
+static pj_status_t silk_codec_open(pjmedia_codec *codec,
+ pjmedia_codec_param *attr )
+{
+
+ silk_private *silk;
+ silk_param *sp;
+ SKP_int st_size, err;
+ pj_bool_t enc_use_fec;
+ unsigned enc_bitrate, i;
+
+ PJ_ASSERT_RETURN(codec && attr, PJ_EINVAL);
+
+ silk = (silk_private*)codec->codec_data;
+ sp = &silk_factory.silk_param[silk->mode];
+
+ /* Already opened? */
+ if (silk->enc_ready || silk->dec_ready)
+ return PJ_SUCCESS;
+
+ /* Allocate and initialize encoder */
+ err = SKP_Silk_SDK_Get_Encoder_Size(&st_size);
+ if (err) {
+ PJ_LOG(3,(THIS_FILE, "Failed to get encoder state size (err=%d)",
+ err));
+ return PJMEDIA_CODEC_EFAILED;
+ }
+ silk->enc_st = pj_pool_zalloc(silk->pool, st_size);
+ err = SKP_Silk_SDK_InitEncoder(silk->enc_st, &silk->enc_ctl);
+ if (err) {
+ PJ_LOG(3,(THIS_FILE, "Failed to init encoder (err=%d)", err));
+ return PJMEDIA_CODEC_EFAILED;
+ }
+
+ /* Check fmtp params */
+ enc_use_fec = PJ_TRUE;
+ enc_bitrate = sp->bitrate;
+ for (i = 0; i < attr->setting.enc_fmtp.cnt; ++i) {
+ pjmedia_codec_fmtp *fmtp = &attr->setting.enc_fmtp;
+ const pj_str_t STR_USEINBANDFEC = {"useinbandfec", 12};
+ const pj_str_t STR_MAXAVERAGEBITRATE = {"maxaveragebitrate", 17};
+
+ if (!pj_stricmp(&fmtp->param[i].name, &STR_USEINBANDFEC)) {
+ enc_use_fec = pj_strtoul(&fmtp->param[i].val) != 0;
+ } else if (!pj_stricmp(&fmtp->param[i].name, &STR_MAXAVERAGEBITRATE)) {
+ enc_bitrate = pj_strtoul(&fmtp->param[i].val);
+ if (enc_bitrate > sp->max_bitrate) {
+ enc_bitrate = sp->max_bitrate;
+ }
+ }
+ }
+
+ /* Setup encoder control for encoding process */
+ silk->enc_ready = PJ_TRUE;
+ silk->samples_per_frame = FRAME_LENGTH_MS *
+ attr->info.clock_rate / 1000;
+ silk->pcm_bytes_per_sample = attr->info.pcm_bits_per_sample / 8;
+
+ silk->enc_ctl.API_sampleRate = attr->info.clock_rate;
+ silk->enc_ctl.maxInternalSampleRate = attr->info.clock_rate;
+ silk->enc_ctl.packetSize = attr->setting.frm_per_pkt *
+ silk->samples_per_frame;
+ /* For useInBandFEC setting to be useful, we need to set
+ * packetLossPercentage greater than LBRR_LOSS_THRES (1)
+ */
+ silk->enc_ctl.packetLossPercentage = SILK_ENC_CTL_PACKET_LOSS_PCT;
+ silk->enc_ctl.useInBandFEC = enc_use_fec;
+ silk->enc_ctl.useDTX = attr->setting.vad;
+ silk->enc_ctl.complexity = sp->complexity;
+ silk->enc_ctl.bitRate = enc_bitrate;
+
+
+ /* Allocate and initialize decoder */
+ err = SKP_Silk_SDK_Get_Decoder_Size(&st_size);
+ if (err) {
+ PJ_LOG(3,(THIS_FILE, "Failed to get decoder state size (err=%d)",
+ err));
+ return PJMEDIA_CODEC_EFAILED;
+ }
+ silk->dec_st = pj_pool_zalloc(silk->pool, st_size);
+ err = SKP_Silk_SDK_InitDecoder(silk->dec_st);
+ if (err) {
+ PJ_LOG(3,(THIS_FILE, "Failed to init decoder (err=%d)", err));
+ return PJMEDIA_CODEC_EFAILED;
+ }
+
+ /* Setup decoder control for decoding process */
+ silk->dec_ctl.API_sampleRate = attr->info.clock_rate;
+ silk->dec_ctl.framesPerPacket = 1; /* for proper PLC at start */
+ silk->dec_ready = PJ_TRUE;
+ silk->dec_buf_sz = attr->info.clock_rate * attr->info.channel_cnt *
+ attr->info.frm_ptime / 1000 *
+ silk->pcm_bytes_per_sample;
+
+ /* Inform the stream to prepare a larger buffer since we cannot parse
+ * SILK packets and split it into individual frames.
+ */
+ attr->info.max_rx_frame_size = attr->info.max_bps *
+ attr->info.frm_ptime / 8 / 1000;
+ if ((attr->info.max_bps * attr->info.frm_ptime) % 8000 != 0)
+ {
+ ++attr->info.max_rx_frame_size;
+ }
+ attr->info.max_rx_frame_size *= SILK_MAX_FRAMES_PER_PACKET;
+
+ return PJ_SUCCESS;
+}
+
+
+/*
+ * Close codec.
+ */
+static pj_status_t silk_codec_close( pjmedia_codec *codec )
+{
+ silk_private *silk;
+ silk = (silk_private*)codec->codec_data;
+
+ silk->enc_ready = PJ_FALSE;
+ silk->dec_ready = PJ_FALSE;
+
+ return PJ_SUCCESS;
+}
+
+
+/*
+ * Modify codec settings.
+ */
+static pj_status_t silk_codec_modify(pjmedia_codec *codec,
+ const pjmedia_codec_param *attr )
+{
+ PJ_TODO(implement_silk_codec_modify);
+
+ PJ_UNUSED_ARG(codec);
+ PJ_UNUSED_ARG(attr);
+
+ return PJ_SUCCESS;
+}
+
+
+/*
+ * Encode frame.
+ */
+static pj_status_t silk_codec_encode(pjmedia_codec *codec,
+ const struct pjmedia_frame *input,
+ unsigned output_buf_len,
+ struct pjmedia_frame *output)
+{
+ silk_private *silk;
+ SKP_int err;
+ unsigned nsamples;
+ SKP_int16 out_size;
+
+ PJ_ASSERT_RETURN(codec && input && output_buf_len && output, PJ_EINVAL);
+ silk = (silk_private*)codec->codec_data;
+
+ /* Check frame in size */
+ nsamples = input->size >> 1;
+ PJ_ASSERT_RETURN(nsamples % silk->samples_per_frame == 0,
+ PJMEDIA_CODEC_EPCMFRMINLEN);
+
+ /* Encode */
+ output->size = 0;
+ out_size = (SKP_int16)output_buf_len;
+ err = SKP_Silk_SDK_Encode(silk->enc_st, &silk->enc_ctl,
+ (SKP_int16*)input->buf, nsamples,
+ (SKP_uint8*)output->buf, &out_size);
+ if (err) {
+ PJ_LOG(3, (THIS_FILE, "Failed to encode frame (err=%d)", err));
+ output->type = PJMEDIA_FRAME_TYPE_NONE;
+ if (err == SKP_SILK_ENC_PAYLOAD_BUF_TOO_SHORT)
+ return PJMEDIA_CODEC_EFRMTOOSHORT;
+ return PJMEDIA_CODEC_EFAILED;
+ }
+
+ output->size = out_size;
+ output->type = PJMEDIA_FRAME_TYPE_AUDIO;
+ output->timestamp = input->timestamp;
+
+ return PJ_SUCCESS;
+}
+
+
+/*
+ * Get frames in the packet.
+ */
+static pj_status_t silk_codec_parse( pjmedia_codec *codec,
+ void *pkt,
+ pj_size_t pkt_size,
+ const pj_timestamp *ts,
+ unsigned *frame_cnt,
+ pjmedia_frame frames[])
+{
+ silk_private *silk;
+ SKP_Silk_TOC_struct toc;
+ unsigned i, count;
+
+ PJ_ASSERT_RETURN(codec && ts && frames && frame_cnt, PJ_EINVAL);
+ silk = (silk_private*)codec->codec_data;
+
+ SKP_Silk_SDK_get_TOC(pkt, pkt_size, &toc);
+ count = toc.framesInPacket;
+ pj_assert(count <= SILK_MAX_FRAMES_PER_PACKET);
+
+ for (i = 0; i < count; i++) {
+ frames[i].type = PJMEDIA_FRAME_TYPE_AUDIO;
+ frames[i].bit_info = (((unsigned)ts->u64 & 0xFFFF) << 16) |
+ (((unsigned)pkt & 0xFF) << 8) |
+ (toc.framesInPacket << 4) | i;
+ frames[i].buf = pkt;
+ frames[i].size = pkt_size;
+ frames[i].timestamp.u64 = ts->u64 + i * silk->samples_per_frame;
+ }
+
+ *frame_cnt = count;
+ return PJ_SUCCESS;
+}
+
+static pj_status_t silk_codec_decode(pjmedia_codec *codec,
+ const struct pjmedia_frame *input,
+ unsigned output_buf_len,
+ struct pjmedia_frame *output)
+{
+ silk_private *silk;
+ SKP_int16 out_size;
+ SKP_Silk_TOC_struct toc;
+ SKP_int err = 0;
+ unsigned pkt_info, frm_info;
+
+ PJ_ASSERT_RETURN(codec && input && output_buf_len && output, PJ_EINVAL);
+ silk = (silk_private*)codec->codec_data;
+ PJ_ASSERT_RETURN(output_buf_len >= silk->dec_buf_sz, PJ_ETOOSMALL);
+
+ SKP_Silk_SDK_get_TOC(input->buf, input->size, &toc);
+ pkt_info = input->bit_info & 0xFFFFFF00;
+ frm_info = input->bit_info & 0xF;
+
+ if (toc.framesInPacket == 0) {
+ /* In SILK ARM version, the table of content can indicate
+ * that the number of frames in the packet is 0.
+ * Try to get the number of frames in packet that we save
+ * in the frame instead.
+ */
+ toc.framesInPacket = (input->bit_info & 0xF0) >> 4;
+ }
+
+ if (toc.framesInPacket == 0) {
+ output->size = 0;
+ } else if (silk->pkt_info != pkt_info || input->bit_info == 0) {
+ unsigned i;
+ SKP_int16 nsamples;
+
+ silk->pkt_info = pkt_info;
+ nsamples = (SKP_int16)silk->dec_buf_sz / silk->pcm_bytes_per_sample;
+
+ if (toc.framesInPacket-1 > (SKP_int)silk->dec_buf_cnt) {
+ /* Grow the buffer */
+ for (i = silk->dec_buf_cnt+1; i < (unsigned)toc.framesInPacket;
+ i++)
+ {
+ silk->dec_buf[i-1] = pj_pool_alloc(silk->pool,
+ silk->dec_buf_sz);
+ }
+ silk->dec_buf_cnt = toc.framesInPacket-1;
+ }
+
+ /* We need to decode all the frames in the packet. */
+ for (i = 0; i < (unsigned)toc.framesInPacket;) {
+ void *buf;
+ SKP_int16 *size;
+
+ if (i == 0 || i == frm_info) {
+ buf = output->buf;
+ size = &out_size;
+ } else {
+ buf = silk->dec_buf[i-1];
+ size = &silk->dec_buf_size[i-1];
+ }
+
+ *size = nsamples;
+ err = SKP_Silk_SDK_Decode(silk->dec_st, &silk->dec_ctl,
+ 0, /* Normal frame flag */
+ input->buf, input->size,
+ buf, size);
+ if (err) {
+ PJ_LOG(3, (THIS_FILE, "Failed to decode frame (err=%d)",
+ err));
+ *size = 0;
+ } else {
+ *size = *size * silk->pcm_bytes_per_sample;
+ }
+
+ if (i == frm_info) {
+ output->size = *size;
+ }
+
+ i++;
+ if (!silk->dec_ctl.moreInternalDecoderFrames &&
+ i < (unsigned)toc.framesInPacket)
+ {
+ /* It turns out that the packet does not have
+ * the number of frames as mentioned in the TOC.
+ */
+ for (; i < (unsigned)toc.framesInPacket; i++) {
+ silk->dec_buf_size[i-1] = 0;
+ if (i == frm_info) {
+ output->size = 0;
+ }
+ }
+ }
+ }
+ } else {
+ /* We have already decoded this packet. */
+ if (frm_info == 0 || silk->dec_buf_size[frm_info-1] == 0) {
+ /* The decoding was a failure. */
+ output->size = 0;
+ } else {
+ /* Copy the decoded frame from the buffer. */
+ pj_assert(frm_info-1 < silk->dec_buf_cnt);
+ if (frm_info-1 >= silk->dec_buf_cnt) {
+ output->size = 0;
+ } else {
+ pj_memcpy(output->buf, silk->dec_buf[frm_info-1],
+ silk->dec_buf_size[frm_info-1]);
+ output->size = silk->dec_buf_size[frm_info-1];
+ }
+ }
+ }
+
+ if (output->size == 0) {
+ output->type = PJMEDIA_TYPE_NONE;
+ output->buf = NULL;
+ return PJMEDIA_CODEC_EFAILED;
+ }
+
+ output->type = PJMEDIA_TYPE_AUDIO;
+ output->timestamp = input->timestamp;
+
+ return PJ_SUCCESS;
+}
+
+
+/*
+ * Recover lost frame.
+ */
+static pj_status_t silk_codec_recover(pjmedia_codec *codec,
+ unsigned output_buf_len,
+ struct pjmedia_frame *output)
+{
+ silk_private *silk;
+ SKP_int16 out_size;
+ SKP_int err;
+
+ PJ_ASSERT_RETURN(codec && output_buf_len && output, PJ_EINVAL);
+ silk = (silk_private*)codec->codec_data;
+
+ out_size = (SKP_int16)output_buf_len / silk->pcm_bytes_per_sample;
+ err = SKP_Silk_SDK_Decode(silk->dec_st, &silk->dec_ctl,
+ 1, /* Lost frame flag */
+ NULL,
+ 0,
+ output->buf,
+ &out_size);
+ if (err) {
+ PJ_LOG(3, (THIS_FILE, "Failed to conceal lost frame (err=%d)", err));
+ output->type = PJMEDIA_FRAME_TYPE_NONE;
+ output->buf = NULL;
+ output->size = 0;
+ return PJMEDIA_CODEC_EFAILED;
+ }
+
+ output->size = out_size * silk->pcm_bytes_per_sample;
+ output->type = PJMEDIA_FRAME_TYPE_AUDIO;
+
+ return PJ_SUCCESS;
+}
+
+#if defined(_MSC_VER)
+# if PJ_DEBUG
+# pragma comment(lib, "SKP_Silk_FLP_Win32_debug.lib")
+# else
+# pragma comment(lib, "SKP_Silk_FLP_Win32_mt.lib")
+# endif
+#endif
+
+
+#endif /* PJMEDIA_HAS_SILK_CODEC */
diff --git a/jni/pjproject-android/.svn/pristine/81/81c8ad4485a5f52558faef2f0b2bf0e4faeeb65b.svn-base b/jni/pjproject-android/.svn/pristine/81/81c8ad4485a5f52558faef2f0b2bf0e4faeeb65b.svn-base
new file mode 100644
index 0000000..ab36012
--- /dev/null
+++ b/jni/pjproject-android/.svn/pristine/81/81c8ad4485a5f52558faef2f0b2bf0e4faeeb65b.svn-base
@@ -0,0 +1,37 @@
+/*
+ * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
+ * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
+ * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
+ */
+
+/*$Header: /tmp_amd/presto/export/kbs/jutta/src/gsm/RCS/config.h,v 1.5 1996/07/02 11:26:20 jutta Exp $*/
+
+#ifndef CONFIG_H
+#define CONFIG_H
+
+/*efine SIGHANDLER_T int * signal handlers are void */
+/*efine HAS_SYSV_SIGNAL 1 * sigs not blocked/reset? */
+
+#define HAS_STDLIB_H 1 /* /usr/include/stdlib.h */
+#define HAS_LIMITS_H 1 /* /usr/include/limits.h */
+#define HAS_FCNTL_H 1 /* /usr/include/fcntl.h */
+#define HAS_ERRNO_DECL 1 /* errno.h declares errno */
+
+#define HAS_FSTAT 1 /* fstat syscall */
+#define HAS_FCHMOD 1 /* fchmod syscall */
+#define HAS_CHMOD 1 /* chmod syscall */
+#define HAS_FCHOWN 1 /* fchown syscall */
+#define HAS_CHOWN 1 /* chown syscall */
+/*efine HAS__FSETMODE 1 * _fsetmode -- set file mode */
+
+#define HAS_STRING_H 1 /* /usr/include/string.h */
+/*efine HAS_STRINGS_H 1 * /usr/include/strings.h */
+
+#define HAS_UNISTD_H 1 /* /usr/include/unistd.h */
+#define HAS_UTIME 1 /* POSIX utime(path, times) */
+/*efine HAS_UTIMES 1 * use utimes() syscall instead */
+#define HAS_UTIME_H 1 /* UTIME header file */
+#define HAS_UTIMBUF 1 /* struct utimbuf */
+/*efine HAS_UTIMEUSEC 1 * microseconds in utimbuf? */
+
+#endif /* CONFIG_H */