* #27232: jni: added pjproject checkout as regular git content
We will remove it once the next release of pjsip (with Android support)
comes out and is merged into SFLphone.
diff --git a/jni/pjproject-android/.svn/pristine/16/161eddd3b2e2829efa567bdfc94b8bb74f9e8095.svn-base b/jni/pjproject-android/.svn/pristine/16/161eddd3b2e2829efa567bdfc94b8bb74f9e8095.svn-base
new file mode 100644
index 0000000..78a02e0
--- /dev/null
+++ b/jni/pjproject-android/.svn/pristine/16/161eddd3b2e2829efa567bdfc94b8bb74f9e8095.svn-base
@@ -0,0 +1,691 @@
+/* $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/wav_port.h>
+#include <pjmedia/alaw_ulaw.h>
+#include <pjmedia/errno.h>
+#include <pjmedia/wave.h>
+#include <pj/assert.h>
+#include <pj/file_access.h>
+#include <pj/file_io.h>
+#include <pj/log.h>
+#include <pj/pool.h>
+#include <pj/string.h>
+
+
+#define THIS_FILE "wav_player.c"
+
+
+#define SIGNATURE PJMEDIA_SIG_PORT_WAV_PLAYER
+#define BITS_PER_SAMPLE 16
+
+#if 1
+# define TRACE_(x) PJ_LOG(4,x)
+#else
+# define TRACE_(x)
+#endif
+
+#if defined(PJ_IS_BIG_ENDIAN) && PJ_IS_BIG_ENDIAN!=0
+ static void samples_to_host(pj_int16_t *samples, unsigned count)
+ {
+ unsigned i;
+ for (i=0; i<count; ++i) {
+ samples[i] = pj_swap16(samples[i]);
+ }
+ }
+#else
+# define samples_to_host(samples,count)
+#endif
+
+struct file_reader_port
+{
+ pjmedia_port base;
+ unsigned options;
+ pjmedia_wave_fmt_tag fmt_tag;
+ pj_uint16_t bytes_per_sample;
+ pj_bool_t eof;
+ pj_uint32_t bufsize;
+ char *buf;
+ char *readpos;
+ char *eofpos;
+
+ pj_off_t fsize;
+ unsigned start_data;
+ unsigned data_len;
+ unsigned data_left;
+ pj_off_t fpos;
+ pj_oshandle_t fd;
+
+ pj_status_t (*cb)(pjmedia_port*, void*);
+};
+
+
+static pj_status_t file_get_frame(pjmedia_port *this_port,
+ pjmedia_frame *frame);
+static pj_status_t file_on_destroy(pjmedia_port *this_port);
+
+static struct file_reader_port *create_file_port(pj_pool_t *pool)
+{
+ const pj_str_t name = pj_str("file");
+ struct file_reader_port *port;
+
+ port = PJ_POOL_ZALLOC_T(pool, struct file_reader_port);
+ if (!port)
+ return NULL;
+
+ /* Put in default values.
+ * These will be overriden once the file is read.
+ */
+ pjmedia_port_info_init(&port->base.info, &name, SIGNATURE,
+ 8000, 1, 16, 80);
+
+ port->base.get_frame = &file_get_frame;
+ port->base.on_destroy = &file_on_destroy;
+
+
+ return port;
+}
+
+/*
+ * Fill buffer.
+ */
+static pj_status_t fill_buffer(struct file_reader_port *fport)
+{
+ pj_uint32_t size_left = fport->bufsize;
+ unsigned size_to_read;
+ pj_ssize_t size;
+ pj_status_t status;
+
+ fport->eofpos = NULL;
+
+ while (size_left > 0) {
+
+ /* Calculate how many bytes to read in this run. */
+ size = size_to_read = size_left;
+ status = pj_file_read(fport->fd,
+ &fport->buf[fport->bufsize-size_left],
+ &size);
+ if (status != PJ_SUCCESS)
+ return status;
+ if (size < 0) {
+ /* Should return more appropriate error code here.. */
+ return PJ_ECANCELLED;
+ }
+
+ if (size > (pj_ssize_t)fport->data_left) {
+ /* We passed the end of the data chunk,
+ * only count the portion read from the data chunk.
+ */
+ size = (pj_ssize_t)fport->data_left;
+ }
+
+ size_left -= (pj_uint32_t)size;
+ fport->data_left -= (pj_uint32_t)size;
+ fport->fpos += size;
+
+ /* If size is less than size_to_read, it indicates that we've
+ * encountered EOF. Rewind the file.
+ */
+ if (size < (pj_ssize_t)size_to_read) {
+ fport->eof = PJ_TRUE;
+ fport->eofpos = fport->buf + fport->bufsize - size_left;
+
+ if (fport->options & PJMEDIA_FILE_NO_LOOP) {
+ /* Zero remaining buffer */
+ if (fport->fmt_tag == PJMEDIA_WAVE_FMT_TAG_PCM) {
+ pj_bzero(fport->eofpos, size_left);
+ } else if (fport->fmt_tag == PJMEDIA_WAVE_FMT_TAG_ULAW) {
+ int val = pjmedia_linear2ulaw(0);
+ pj_memset(fport->eofpos, val, size_left);
+ } else if (fport->fmt_tag == PJMEDIA_WAVE_FMT_TAG_ALAW) {
+ int val = pjmedia_linear2alaw(0);
+ pj_memset(fport->eofpos, val, size_left);
+ }
+ size_left = 0;
+ }
+
+ /* Rewind file */
+ fport->fpos = fport->start_data;
+ pj_file_setpos( fport->fd, fport->fpos, PJ_SEEK_SET);
+ fport->data_left = fport->data_len;
+ }
+ }
+
+ /* Convert samples to host rep */
+ samples_to_host((pj_int16_t*)fport->buf,
+ fport->bufsize/fport->bytes_per_sample);
+
+ return PJ_SUCCESS;
+}
+
+
+/*
+ * Create WAVE player port.
+ */
+PJ_DEF(pj_status_t) pjmedia_wav_player_port_create( pj_pool_t *pool,
+ const char *filename,
+ unsigned ptime,
+ unsigned options,
+ pj_ssize_t buff_size,
+ pjmedia_port **p_port )
+{
+ pjmedia_wave_hdr wave_hdr;
+ pj_ssize_t size_to_read, size_read;
+ struct file_reader_port *fport;
+ pjmedia_audio_format_detail *ad;
+ pj_off_t pos;
+ pj_str_t name;
+ unsigned samples_per_frame;
+ pj_status_t status = PJ_SUCCESS;
+
+
+ /* Check arguments. */
+ PJ_ASSERT_RETURN(pool && filename && p_port, PJ_EINVAL);
+
+ /* Check the file really exists. */
+ if (!pj_file_exists(filename)) {
+ return PJ_ENOTFOUND;
+ }
+
+ /* Normalize ptime */
+ if (ptime == 0)
+ ptime = 20;
+
+ /* Normalize buff_size */
+ if (buff_size < 1) buff_size = PJMEDIA_FILE_PORT_BUFSIZE;
+
+
+ /* Create fport instance. */
+ fport = create_file_port(pool);
+ if (!fport) {
+ return PJ_ENOMEM;
+ }
+
+
+ /* Get the file size. */
+ fport->fsize = pj_file_size(filename);
+
+ /* Size must be more than WAVE header size */
+ if (fport->fsize <= sizeof(pjmedia_wave_hdr)) {
+ return PJMEDIA_ENOTVALIDWAVE;
+ }
+
+ /* Open file. */
+ status = pj_file_open( pool, filename, PJ_O_RDONLY, &fport->fd);
+ if (status != PJ_SUCCESS)
+ return status;
+
+ /* Read the file header plus fmt header only. */
+ size_read = size_to_read = sizeof(wave_hdr) - 8;
+ status = pj_file_read( fport->fd, &wave_hdr, &size_read);
+ if (status != PJ_SUCCESS) {
+ pj_file_close(fport->fd);
+ return status;
+ }
+ if (size_read != size_to_read) {
+ pj_file_close(fport->fd);
+ return PJMEDIA_ENOTVALIDWAVE;
+ }
+
+ /* Normalize WAVE header fields values from little-endian to host
+ * byte order.
+ */
+ pjmedia_wave_hdr_file_to_host(&wave_hdr);
+
+ /* Validate WAVE file. */
+ if (wave_hdr.riff_hdr.riff != PJMEDIA_RIFF_TAG ||
+ wave_hdr.riff_hdr.wave != PJMEDIA_WAVE_TAG ||
+ wave_hdr.fmt_hdr.fmt != PJMEDIA_FMT_TAG)
+ {
+ pj_file_close(fport->fd);
+ TRACE_((THIS_FILE,
+ "actual value|expected riff=%x|%x, wave=%x|%x fmt=%x|%x",
+ wave_hdr.riff_hdr.riff, PJMEDIA_RIFF_TAG,
+ wave_hdr.riff_hdr.wave, PJMEDIA_WAVE_TAG,
+ wave_hdr.fmt_hdr.fmt, PJMEDIA_FMT_TAG));
+ return PJMEDIA_ENOTVALIDWAVE;
+ }
+
+ /* Validate format and its attributes (i.e: bits per sample, block align) */
+ switch (wave_hdr.fmt_hdr.fmt_tag) {
+ case PJMEDIA_WAVE_FMT_TAG_PCM:
+ if (wave_hdr.fmt_hdr.bits_per_sample != 16 ||
+ wave_hdr.fmt_hdr.block_align != 2 * wave_hdr.fmt_hdr.nchan)
+ status = PJMEDIA_EWAVEUNSUPP;
+ break;
+
+ case PJMEDIA_WAVE_FMT_TAG_ALAW:
+ case PJMEDIA_WAVE_FMT_TAG_ULAW:
+ if (wave_hdr.fmt_hdr.bits_per_sample != 8 ||
+ wave_hdr.fmt_hdr.block_align != wave_hdr.fmt_hdr.nchan)
+ status = PJMEDIA_ENOTVALIDWAVE;
+ break;
+
+ default:
+ status = PJMEDIA_EWAVEUNSUPP;
+ break;
+ }
+
+ if (status != PJ_SUCCESS) {
+ pj_file_close(fport->fd);
+ return status;
+ }
+
+ fport->fmt_tag = (pjmedia_wave_fmt_tag)wave_hdr.fmt_hdr.fmt_tag;
+ fport->bytes_per_sample = (pj_uint16_t)
+ (wave_hdr.fmt_hdr.bits_per_sample / 8);
+
+ /* If length of fmt_header is greater than 16, skip the remaining
+ * fmt header data.
+ */
+ if (wave_hdr.fmt_hdr.len > 16) {
+ size_to_read = wave_hdr.fmt_hdr.len - 16;
+ status = pj_file_setpos(fport->fd, size_to_read, PJ_SEEK_CUR);
+ if (status != PJ_SUCCESS) {
+ pj_file_close(fport->fd);
+ return status;
+ }
+ }
+
+ /* Repeat reading the WAVE file until we have 'data' chunk */
+ for (;;) {
+ pjmedia_wave_subchunk subchunk;
+ size_read = 8;
+ status = pj_file_read(fport->fd, &subchunk, &size_read);
+ if (status != PJ_SUCCESS || size_read != 8) {
+ pj_file_close(fport->fd);
+ return PJMEDIA_EWAVETOOSHORT;
+ }
+
+ /* Normalize endianness */
+ PJMEDIA_WAVE_NORMALIZE_SUBCHUNK(&subchunk);
+
+ /* Break if this is "data" chunk */
+ if (subchunk.id == PJMEDIA_DATA_TAG) {
+ wave_hdr.data_hdr.data = PJMEDIA_DATA_TAG;
+ wave_hdr.data_hdr.len = subchunk.len;
+ break;
+ }
+
+ /* Otherwise skip the chunk contents */
+ size_to_read = subchunk.len;
+ status = pj_file_setpos(fport->fd, size_to_read, PJ_SEEK_CUR);
+ if (status != PJ_SUCCESS) {
+ pj_file_close(fport->fd);
+ return status;
+ }
+ }
+
+ /* Current file position now points to start of data */
+ status = pj_file_getpos(fport->fd, &pos);
+ fport->start_data = (unsigned)pos;
+ fport->data_len = wave_hdr.data_hdr.len;
+ fport->data_left = wave_hdr.data_hdr.len;
+
+ /* Validate length. */
+ if (wave_hdr.data_hdr.len > fport->fsize - fport->start_data) {
+ pj_file_close(fport->fd);
+ return PJMEDIA_EWAVEUNSUPP;
+ }
+ if (wave_hdr.data_hdr.len < ptime * wave_hdr.fmt_hdr.sample_rate *
+ wave_hdr.fmt_hdr.nchan / 1000)
+ {
+ pj_file_close(fport->fd);
+ return PJMEDIA_EWAVETOOSHORT;
+ }
+
+ /* It seems like we have a valid WAVE file. */
+
+ /* Initialize */
+ fport->options = options;
+
+ /* Update port info. */
+ ad = pjmedia_format_get_audio_format_detail(&fport->base.info.fmt, 1);
+ pj_strdup2(pool, &name, filename);
+ samples_per_frame = ptime * wave_hdr.fmt_hdr.sample_rate *
+ wave_hdr.fmt_hdr.nchan / 1000;
+ pjmedia_port_info_init(&fport->base.info, &name, SIGNATURE,
+ wave_hdr.fmt_hdr.sample_rate,
+ wave_hdr.fmt_hdr.nchan,
+ BITS_PER_SAMPLE,
+ samples_per_frame);
+
+ /* If file is shorter than buffer size, adjust buffer size to file
+ * size. Otherwise EOF callback will be called multiple times when
+ * fill_buffer() is called.
+ */
+ if (wave_hdr.data_hdr.len < (unsigned)buff_size)
+ buff_size = wave_hdr.data_hdr.len;
+
+ /* Create file buffer.
+ */
+ fport->bufsize = (pj_uint32_t)buff_size;
+
+
+ /* samples_per_frame must be smaller than bufsize (because get_frame()
+ * doesn't handle this case).
+ */
+ if (samples_per_frame * fport->bytes_per_sample >= fport->bufsize) {
+ pj_file_close(fport->fd);
+ return PJ_EINVAL;
+ }
+
+ /* Create buffer. */
+ fport->buf = (char*) pj_pool_alloc(pool, fport->bufsize);
+ if (!fport->buf) {
+ pj_file_close(fport->fd);
+ return PJ_ENOMEM;
+ }
+
+ fport->readpos = fport->buf;
+
+ /* Set initial position of the file. */
+ fport->fpos = fport->start_data;
+
+ /* Fill up the buffer. */
+ status = fill_buffer(fport);
+ if (status != PJ_SUCCESS) {
+ pj_file_close(fport->fd);
+ return status;
+ }
+
+ /* Done. */
+
+ *p_port = &fport->base;
+
+
+ PJ_LOG(4,(THIS_FILE,
+ "File player '%.*s' created: samp.rate=%d, ch=%d, bufsize=%uKB, "
+ "filesize=%luKB",
+ (int)fport->base.info.name.slen,
+ fport->base.info.name.ptr,
+ ad->clock_rate,
+ ad->channel_count,
+ fport->bufsize / 1000,
+ (unsigned long)(fport->fsize / 1000)));
+
+ return PJ_SUCCESS;
+}
+
+
+/*
+ * Get the data length, in bytes.
+ */
+PJ_DEF(pj_ssize_t) pjmedia_wav_player_get_len(pjmedia_port *port)
+{
+ struct file_reader_port *fport;
+ pj_ssize_t size;
+
+ /* Sanity check */
+ PJ_ASSERT_RETURN(port, -PJ_EINVAL);
+
+ /* Check that this is really a player port */
+ PJ_ASSERT_RETURN(port->info.signature == SIGNATURE, -PJ_EINVALIDOP);
+
+ fport = (struct file_reader_port*) port;
+
+ size = (pj_ssize_t) fport->fsize;
+ return size - fport->start_data;
+}
+
+
+/*
+ * Set position.
+ */
+PJ_DEF(pj_status_t) pjmedia_wav_player_port_set_pos(pjmedia_port *port,
+ pj_uint32_t bytes )
+{
+ struct file_reader_port *fport;
+ pj_status_t status;
+
+ /* Sanity check */
+ PJ_ASSERT_RETURN(port, PJ_EINVAL);
+
+ /* Check that this is really a player port */
+ PJ_ASSERT_RETURN(port->info.signature == SIGNATURE, PJ_EINVALIDOP);
+
+
+ fport = (struct file_reader_port*) port;
+
+ /* Check that this offset does not pass the audio-data (in case of
+ * extra chunk after audio data chunk
+ */
+ PJ_ASSERT_RETURN(bytes < fport->data_len, PJ_EINVAL);
+
+ fport->fpos = fport->start_data + bytes;
+ fport->data_left = fport->data_len - bytes;
+ pj_file_setpos( fport->fd, fport->fpos, PJ_SEEK_SET);
+
+ fport->eof = PJ_FALSE;
+ status = fill_buffer(fport);
+ if (status != PJ_SUCCESS)
+ return status;
+
+ fport->readpos = fport->buf;
+
+ return PJ_SUCCESS;
+}
+
+
+/*
+ * Get the file play position of WAV player.
+ */
+PJ_DEF(pj_ssize_t) pjmedia_wav_player_port_get_pos( pjmedia_port *port )
+{
+ struct file_reader_port *fport;
+ pj_size_t payload_pos;
+
+ /* Sanity check */
+ PJ_ASSERT_RETURN(port, -PJ_EINVAL);
+
+ /* Check that this is really a player port */
+ PJ_ASSERT_RETURN(port->info.signature == SIGNATURE, -PJ_EINVALIDOP);
+
+ fport = (struct file_reader_port*) port;
+
+ payload_pos = (pj_size_t)(fport->fpos - fport->start_data);
+ if (payload_pos >= fport->bufsize)
+ return payload_pos - fport->bufsize + (fport->readpos - fport->buf);
+ else
+ return (fport->readpos - fport->buf) % payload_pos;
+}
+
+
+
+/*
+ * Register a callback to be called when the file reading has reached the
+ * end of file.
+ */
+PJ_DEF(pj_status_t) pjmedia_wav_player_set_eof_cb( pjmedia_port *port,
+ void *user_data,
+ pj_status_t (*cb)(pjmedia_port *port,
+ void *usr_data))
+{
+ struct file_reader_port *fport;
+
+ /* Sanity check */
+ PJ_ASSERT_RETURN(port, -PJ_EINVAL);
+
+ /* Check that this is really a player port */
+ PJ_ASSERT_RETURN(port->info.signature == SIGNATURE, -PJ_EINVALIDOP);
+
+ fport = (struct file_reader_port*) port;
+
+ fport->base.port_data.pdata = user_data;
+ fport->cb = cb;
+
+ return PJ_SUCCESS;
+}
+
+
+/*
+ * Get frame from file.
+ */
+static pj_status_t file_get_frame(pjmedia_port *this_port,
+ pjmedia_frame *frame)
+{
+ struct file_reader_port *fport = (struct file_reader_port*)this_port;
+ pj_size_t frame_size;
+ pj_status_t status;
+
+ pj_assert(fport->base.info.signature == SIGNATURE);
+ pj_assert(frame->size <= fport->bufsize);
+
+ /* EOF is set and readpos already passed the eofpos */
+ if (fport->eof && fport->readpos >= fport->eofpos) {
+ pj_status_t status = PJ_SUCCESS;
+
+ PJ_LOG(5,(THIS_FILE, "File port %.*s EOF",
+ (int)fport->base.info.name.slen,
+ fport->base.info.name.ptr));
+
+ /* Call callback, if any */
+ if (fport->cb)
+ status = (*fport->cb)(this_port, fport->base.port_data.pdata);
+
+ /* If callback returns non PJ_SUCCESS or 'no loop' is specified,
+ * return immediately (and don't try to access player port since
+ * it might have been destroyed by the callback).
+ */
+ if ((status != PJ_SUCCESS) || (fport->options & PJMEDIA_FILE_NO_LOOP)) {
+ frame->type = PJMEDIA_FRAME_TYPE_NONE;
+ frame->size = 0;
+ return PJ_EEOF;
+ }
+
+ PJ_LOG(5,(THIS_FILE, "File port %.*s rewinding..",
+ (int)fport->base.info.name.slen,
+ fport->base.info.name.ptr));
+
+ fport->eof = PJ_FALSE;
+ }
+
+ //pj_assert(frame->size == fport->base.info.bytes_per_frame);
+ if (fport->fmt_tag == PJMEDIA_WAVE_FMT_TAG_PCM) {
+ frame_size = frame->size;
+ //frame->size = frame_size;
+ } else {
+ /* Must be ULAW or ALAW */
+ pj_assert(fport->fmt_tag == PJMEDIA_WAVE_FMT_TAG_ULAW ||
+ fport->fmt_tag == PJMEDIA_WAVE_FMT_TAG_ALAW);
+
+ frame_size = frame->size >> 1;
+ frame->size = frame_size << 1;
+ }
+
+ /* Copy frame from buffer. */
+ frame->type = PJMEDIA_FRAME_TYPE_AUDIO;
+ frame->timestamp.u64 = 0;
+
+ if ((fport->readpos + frame_size) <= (fport->buf + fport->bufsize))
+ {
+ /* Read contiguous buffer. */
+ pj_memcpy(frame->buf, fport->readpos, frame_size);
+
+ /* Fill up the buffer if all has been read. */
+ fport->readpos += frame_size;
+ if (fport->readpos == fport->buf + fport->bufsize) {
+ fport->readpos = fport->buf;
+
+ status = fill_buffer(fport);
+ if (status != PJ_SUCCESS) {
+ frame->type = PJMEDIA_FRAME_TYPE_NONE;
+ frame->size = 0;
+ fport->readpos = fport->buf + fport->bufsize;
+ return status;
+ }
+ }
+ } else {
+ unsigned endread;
+
+ /* Split read.
+ * First stage: read until end of buffer.
+ */
+ endread = (unsigned)((fport->buf+fport->bufsize) - fport->readpos);
+ pj_memcpy(frame->buf, fport->readpos, endread);
+
+ /* End Of Buffer and EOF and NO LOOP */
+ if (fport->eof && (fport->options & PJMEDIA_FILE_NO_LOOP)) {
+ fport->readpos += endread;
+
+ if (fport->fmt_tag == PJMEDIA_WAVE_FMT_TAG_PCM) {
+ pj_bzero((char*)frame->buf + endread, frame_size - endread);
+ } else if (fport->fmt_tag == PJMEDIA_WAVE_FMT_TAG_ULAW) {
+ int val = pjmedia_linear2ulaw(0);
+ pj_memset((char*)frame->buf + endread, val,
+ frame_size - endread);
+ } else if (fport->fmt_tag == PJMEDIA_WAVE_FMT_TAG_ALAW) {
+ int val = pjmedia_linear2alaw(0);
+ pj_memset((char*)frame->buf + endread, val,
+ frame_size - endread);
+ }
+
+ return PJ_SUCCESS;
+ }
+
+ /* Second stage: fill up buffer, and read from the start of buffer. */
+ status = fill_buffer(fport);
+ if (status != PJ_SUCCESS) {
+ frame->type = PJMEDIA_FRAME_TYPE_NONE;
+ frame->size = 0;
+ fport->readpos = fport->buf + fport->bufsize;
+ return status;
+ }
+
+ pj_memcpy(((char*)frame->buf)+endread, fport->buf, frame_size-endread);
+ fport->readpos = fport->buf + (frame_size - endread);
+ }
+
+ if (fport->fmt_tag == PJMEDIA_WAVE_FMT_TAG_ULAW ||
+ fport->fmt_tag == PJMEDIA_WAVE_FMT_TAG_ALAW)
+ {
+ unsigned i;
+ pj_uint16_t *dst;
+ pj_uint8_t *src;
+
+ dst = (pj_uint16_t*)frame->buf + frame_size - 1;
+ src = (pj_uint8_t*)frame->buf + frame_size - 1;
+
+ if (fport->fmt_tag == PJMEDIA_WAVE_FMT_TAG_ULAW) {
+ for (i = 0; i < frame_size; ++i) {
+ *dst-- = (pj_uint16_t) pjmedia_ulaw2linear(*src--);
+ }
+ } else {
+ for (i = 0; i < frame_size; ++i) {
+ *dst-- = (pj_uint16_t) pjmedia_alaw2linear(*src--);
+ }
+ }
+ }
+
+ return PJ_SUCCESS;
+}
+
+/*
+ * Destroy port.
+ */
+static pj_status_t file_on_destroy(pjmedia_port *this_port)
+{
+ struct file_reader_port *fport = (struct file_reader_port*) this_port;
+
+ pj_assert(this_port->info.signature == SIGNATURE);
+
+ pj_file_close(fport->fd);
+ return PJ_SUCCESS;
+}
+
diff --git a/jni/pjproject-android/.svn/pristine/16/164d60a8d667ed7b61634d2249390882d93c8b06.svn-base b/jni/pjproject-android/.svn/pristine/16/164d60a8d667ed7b61634d2249390882d93c8b06.svn-base
new file mode 100644
index 0000000..e3b4842
--- /dev/null
+++ b/jni/pjproject-android/.svn/pristine/16/164d60a8d667ed7b61634d2249390882d93c8b06.svn-base
@@ -0,0 +1,300 @@
+/* Copyright (C) 2002-2007 Jean-Marc Valin
+ File: modes.c
+
+ Describes the wideband modes of the codec
+
+ 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 Xiph.org Foundation 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 FOUNDATION 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.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "modes.h"
+#include "ltp.h"
+#include "quant_lsp.h"
+#include "cb_search.h"
+#include "sb_celp.h"
+#include "nb_celp.h"
+#include "vbr.h"
+#include "arch.h"
+#include <math.h>
+#include "os_support.h"
+
+
+#ifndef NULL
+#define NULL 0
+#endif
+
+EXPORT const SpeexMode * const speex_mode_list[SPEEX_NB_MODES] = {&speex_nb_mode, &speex_wb_mode, &speex_uwb_mode};
+
+extern const signed char hexc_table[];
+extern const signed char hexc_10_32_table[];
+
+#ifndef DISABLE_WIDEBAND
+
+/* Split-VQ innovation for high-band wideband */
+static const split_cb_params split_cb_high = {
+ 8, /*subvect_size*/
+ 5, /*nb_subvect*/
+ hexc_table, /*shape_cb*/
+ 7, /*shape_bits*/
+ 1,
+};
+
+
+/* Split-VQ innovation for high-band wideband */
+static const split_cb_params split_cb_high_lbr = {
+ 10, /*subvect_size*/
+ 4, /*nb_subvect*/
+ hexc_10_32_table, /*shape_cb*/
+ 5, /*shape_bits*/
+ 0,
+};
+
+#endif
+
+
+static const SpeexSubmode wb_submode1 = {
+ 0,
+ 0,
+ 1,
+ 0,
+ /*LSP quantization*/
+ lsp_quant_high,
+ lsp_unquant_high,
+ /*Pitch quantization*/
+ NULL,
+ NULL,
+ NULL,
+ /*No innovation quantization*/
+ NULL,
+ NULL,
+ NULL,
+ -1,
+ 36
+};
+
+
+static const SpeexSubmode wb_submode2 = {
+ 0,
+ 0,
+ 1,
+ 0,
+ /*LSP quantization*/
+ lsp_quant_high,
+ lsp_unquant_high,
+ /*Pitch quantization*/
+ NULL,
+ NULL,
+ NULL,
+ /*Innovation quantization*/
+ split_cb_search_shape_sign,
+ split_cb_shape_sign_unquant,
+#ifdef DISABLE_WIDEBAND
+ NULL,
+#else
+ &split_cb_high_lbr,
+#endif
+ -1,
+ 112
+};
+
+
+static const SpeexSubmode wb_submode3 = {
+ 0,
+ 0,
+ 1,
+ 0,
+ /*LSP quantization*/
+ lsp_quant_high,
+ lsp_unquant_high,
+ /*Pitch quantization*/
+ NULL,
+ NULL,
+ NULL,
+ /*Innovation quantization*/
+ split_cb_search_shape_sign,
+ split_cb_shape_sign_unquant,
+#ifdef DISABLE_WIDEBAND
+ NULL,
+#else
+ &split_cb_high,
+#endif
+ -1,
+ 192
+};
+
+static const SpeexSubmode wb_submode4 = {
+ 0,
+ 0,
+ 1,
+ 1,
+ /*LSP quantization*/
+ lsp_quant_high,
+ lsp_unquant_high,
+ /*Pitch quantization*/
+ NULL,
+ NULL,
+ NULL,
+ /*Innovation quantization*/
+ split_cb_search_shape_sign,
+ split_cb_shape_sign_unquant,
+#ifdef DISABLE_WIDEBAND
+ NULL,
+#else
+ &split_cb_high,
+#endif
+ -1,
+ 352
+};
+
+
+/* Split-band wideband CELP mode*/
+static const SpeexSBMode sb_wb_mode = {
+ &speex_nb_mode,
+ 160, /*frameSize*/
+ 40, /*subframeSize*/
+ 8, /*lpcSize*/
+#ifdef FIXED_POINT
+ 29491, 19661, /* gamma1, gamma2 */
+#else
+ 0.9, 0.6, /* gamma1, gamma2 */
+#endif
+ QCONST16(.0002,15), /*lpc_floor*/
+ QCONST16(0.9f,15),
+ {NULL, &wb_submode1, &wb_submode2, &wb_submode3, &wb_submode4, NULL, NULL, NULL},
+ 3,
+ {1, 8, 2, 3, 4, 5, 5, 6, 6, 7, 7},
+ {1, 1, 1, 1, 1, 1, 2, 2, 3, 3, 4},
+#ifndef DISABLE_VBR
+ vbr_hb_thresh,
+#endif
+ 5
+};
+
+
+EXPORT const SpeexMode speex_wb_mode = {
+ &sb_wb_mode,
+ wb_mode_query,
+ "wideband (sub-band CELP)",
+ 1,
+ 4,
+ &sb_encoder_init,
+ &sb_encoder_destroy,
+ &sb_encode,
+ &sb_decoder_init,
+ &sb_decoder_destroy,
+ &sb_decode,
+ &sb_encoder_ctl,
+ &sb_decoder_ctl,
+};
+
+
+
+/* "Ultra-wideband" mode stuff */
+
+
+
+/* Split-band "ultra-wideband" (32 kbps) CELP mode*/
+static const SpeexSBMode sb_uwb_mode = {
+ &speex_wb_mode,
+ 320, /*frameSize*/
+ 80, /*subframeSize*/
+ 8, /*lpcSize*/
+#ifdef FIXED_POINT
+ 29491, 19661, /* gamma1, gamma2 */
+#else
+ 0.9, 0.6, /* gamma1, gamma2 */
+#endif
+ QCONST16(.0002,15), /*lpc_floor*/
+ QCONST16(0.7f,15),
+ {NULL, &wb_submode1, NULL, NULL, NULL, NULL, NULL, NULL},
+ 1,
+ {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
+ {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
+#ifndef DISABLE_VBR
+ vbr_uhb_thresh,
+#endif
+ 2
+};
+
+int wb_mode_query(const void *mode, int request, void *ptr)
+{
+ const SpeexSBMode *m = (const SpeexSBMode*)mode;
+
+ switch (request)
+ {
+ case SPEEX_MODE_FRAME_SIZE:
+ *((int*)ptr)=2*m->frameSize;
+ break;
+ case SPEEX_SUBMODE_BITS_PER_FRAME:
+ if (*((int*)ptr)==0)
+ *((int*)ptr) = SB_SUBMODE_BITS+1;
+ else if (m->submodes[*((int*)ptr)]==NULL)
+ *((int*)ptr) = -1;
+ else
+ *((int*)ptr) = m->submodes[*((int*)ptr)]->bits_per_frame;
+ break;
+ default:
+ speex_warning_int("Unknown wb_mode_query request: ", request);
+ return -1;
+ }
+ return 0;
+}
+
+
+EXPORT const SpeexMode speex_uwb_mode = {
+ &sb_uwb_mode,
+ wb_mode_query,
+ "ultra-wideband (sub-band CELP)",
+ 2,
+ 4,
+ &sb_encoder_init,
+ &sb_encoder_destroy,
+ &sb_encode,
+ &sb_decoder_init,
+ &sb_decoder_destroy,
+ &sb_decode,
+ &sb_encoder_ctl,
+ &sb_decoder_ctl,
+};
+
+/* We have defined speex_lib_get_mode() as a macro in speex.h */
+#undef speex_lib_get_mode
+
+EXPORT const SpeexMode * speex_lib_get_mode (int mode)
+{
+ if (mode < 0 || mode >= SPEEX_NB_MODES) return NULL;
+
+ return speex_mode_list[mode];
+}
+
+
+
diff --git a/jni/pjproject-android/.svn/pristine/16/1679431799de69e12f4d82bcb0e61d5ec264b363.svn-base b/jni/pjproject-android/.svn/pristine/16/1679431799de69e12f4d82bcb0e61d5ec264b363.svn-base
new file mode 100644
index 0000000..fb96b5e
--- /dev/null
+++ b/jni/pjproject-android/.svn/pristine/16/1679431799de69e12f4d82bcb0e61d5ec264b363.svn-base
@@ -0,0 +1,54 @@
+/*
+ * prng.h
+ *
+ * pseudorandom source
+ *
+ * David A. McGrew
+ * Cisco Systems, Inc.
+ */
+
+#ifndef PRNG_H
+#define PRNG_H
+
+#include "rand_source.h" /* for rand_source_func_t definition */
+#include "aes.h" /* for aes */
+#include "aes_icm.h" /* for aes ctr */
+
+#define MAX_PRNG_OUT_LEN 0xffffffffU
+
+/*
+ * x917_prng is an ANSI X9.17-like AES-based PRNG
+ */
+
+typedef struct {
+ v128_t state; /* state data */
+ aes_expanded_key_t key; /* secret key */
+ uint32_t octet_count; /* number of octets output since last init */
+ rand_source_func_t rand; /* random source for re-initialization */
+} x917_prng_t;
+
+err_status_t
+x917_prng_init(rand_source_func_t random_source);
+
+err_status_t
+x917_prng_get_octet_string(uint8_t *dest, uint32_t len);
+
+
+/*
+ * ctr_prng is an AES-CTR based PRNG
+ */
+
+typedef struct {
+ uint32_t octet_count; /* number of octets output since last init */
+ aes_icm_ctx_t state; /* state data */
+ rand_source_func_t rand; /* random source for re-initialization */
+} ctr_prng_t;
+
+err_status_t
+ctr_prng_init(rand_source_func_t random_source);
+
+err_status_t
+ctr_prng_get_octet_string(void *dest, uint32_t len);
+
+
+#endif
diff --git a/jni/pjproject-android/.svn/pristine/16/16ab02887b9c54f49c5030b405ed31fa9be9a405.svn-base b/jni/pjproject-android/.svn/pristine/16/16ab02887b9c54f49c5030b405ed31fa9be9a405.svn-base
new file mode 100644
index 0000000..489a52d
--- /dev/null
+++ b/jni/pjproject-android/.svn/pristine/16/16ab02887b9c54f49c5030b405ed31fa9be9a405.svn-base
@@ -0,0 +1,409 @@
+/*
+ * cipher.c
+ *
+ * cipher meta-functions
+ *
+ * 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.
+ *
+ */
+
+#include "cipher.h"
+#include "rand_source.h" /* used in invertibiltiy tests */
+#include "alloc.h" /* for crypto_alloc(), crypto_free() */
+
+debug_module_t mod_cipher = {
+ 0, /* debugging is off by default */
+ "cipher" /* printable module name */
+};
+
+err_status_t
+cipher_output(cipher_t *c, uint8_t *buffer, int num_octets_to_output) {
+
+ /* zeroize the buffer */
+ octet_string_set_to_zero(buffer, num_octets_to_output);
+
+ /* exor keystream into buffer */
+ return cipher_encrypt(c, buffer, (unsigned int *) &num_octets_to_output);
+}
+
+/* some bookkeeping functions */
+
+int
+cipher_get_key_length(const cipher_t *c) {
+ return c->key_len;
+}
+
+/*
+ * cipher_type_self_test(ct) tests a cipher of type ct against test cases
+ * provided in an array of values of key, salt, xtd_seq_num_t,
+ * plaintext, and ciphertext that is known to be good
+ */
+
+#define SELF_TEST_BUF_OCTETS 128
+#define NUM_RAND_TESTS 128
+#define MAX_KEY_LEN 64
+
+err_status_t
+cipher_type_self_test(const cipher_type_t *ct) {
+ const cipher_test_case_t *test_case = ct->test_data;
+ cipher_t *c;
+ err_status_t status;
+ uint8_t buffer[SELF_TEST_BUF_OCTETS];
+ uint8_t buffer2[SELF_TEST_BUF_OCTETS];
+ unsigned int len;
+ int i, j, case_num = 0;
+
+ debug_print(mod_cipher, "running self-test for cipher %s",
+ ct->description);
+
+ /*
+ * check to make sure that we have at least one test case, and
+ * return an error if we don't - we need to be paranoid here
+ */
+ if (test_case == NULL)
+ return err_status_cant_check;
+
+ /*
+ * loop over all test cases, perform known-answer tests of both the
+ * encryption and decryption functions
+ */
+ while (test_case != NULL) {
+
+ /* allocate cipher */
+ status = cipher_type_alloc(ct, &c, test_case->key_length_octets);
+ if (status)
+ return status;
+
+ /*
+ * test the encrypt function
+ */
+ debug_print(mod_cipher, "testing encryption", NULL);
+
+ /* initialize cipher */
+ status = cipher_init(c, test_case->key, direction_encrypt);
+ if (status) {
+ cipher_dealloc(c);
+ return status;
+ }
+
+ /* copy plaintext into test buffer */
+ if (test_case->ciphertext_length_octets > SELF_TEST_BUF_OCTETS) {
+ cipher_dealloc(c);
+ return err_status_bad_param;
+ }
+ for (i=0; i < test_case->plaintext_length_octets; i++)
+ buffer[i] = test_case->plaintext[i];
+
+ debug_print(mod_cipher, "plaintext: %s",
+ octet_string_hex_string(buffer,
+ test_case->plaintext_length_octets));
+
+ /* set the initialization vector */
+ status = cipher_set_iv(c, test_case->idx);
+ if (status) {
+ cipher_dealloc(c);
+ return status;
+ }
+
+ /* encrypt */
+ len = test_case->plaintext_length_octets;
+ status = cipher_encrypt(c, buffer, &len);
+ if (status) {
+ cipher_dealloc(c);
+ return status;
+ }
+
+ debug_print(mod_cipher, "ciphertext: %s",
+ octet_string_hex_string(buffer,
+ test_case->ciphertext_length_octets));
+
+ /* compare the resulting ciphertext with that in the test case */
+ if (len != test_case->ciphertext_length_octets)
+ return err_status_algo_fail;
+ status = err_status_ok;
+ for (i=0; i < test_case->ciphertext_length_octets; i++)
+ if (buffer[i] != test_case->ciphertext[i]) {
+ status = err_status_algo_fail;
+ debug_print(mod_cipher, "test case %d failed", case_num);
+ debug_print(mod_cipher, "(failure at byte %d)", i);
+ break;
+ }
+ if (status) {
+
+ debug_print(mod_cipher, "c computed: %s",
+ octet_string_hex_string(buffer,
+ 2*test_case->plaintext_length_octets));
+ debug_print(mod_cipher, "c expected: %s",
+ octet_string_hex_string(test_case->ciphertext,
+ 2*test_case->plaintext_length_octets));
+
+ cipher_dealloc(c);
+ return err_status_algo_fail;
+ }
+
+ /*
+ * test the decrypt function
+ */
+ debug_print(mod_cipher, "testing decryption", NULL);
+
+ /* re-initialize cipher for decryption */
+ status = cipher_init(c, test_case->key, direction_decrypt);
+ if (status) {
+ cipher_dealloc(c);
+ return status;
+ }
+
+ /* copy ciphertext into test buffer */
+ if (test_case->ciphertext_length_octets > SELF_TEST_BUF_OCTETS) {
+ cipher_dealloc(c);
+ return err_status_bad_param;
+ }
+ for (i=0; i < test_case->ciphertext_length_octets; i++)
+ buffer[i] = test_case->ciphertext[i];
+
+ debug_print(mod_cipher, "ciphertext: %s",
+ octet_string_hex_string(buffer,
+ test_case->plaintext_length_octets));
+
+ /* set the initialization vector */
+ status = cipher_set_iv(c, test_case->idx);
+ if (status) {
+ cipher_dealloc(c);
+ return status;
+ }
+
+ /* decrypt */
+ len = test_case->ciphertext_length_octets;
+ status = cipher_decrypt(c, buffer, &len);
+ if (status) {
+ cipher_dealloc(c);
+ return status;
+ }
+
+ debug_print(mod_cipher, "plaintext: %s",
+ octet_string_hex_string(buffer,
+ test_case->plaintext_length_octets));
+
+ /* compare the resulting plaintext with that in the test case */
+ if (len != test_case->plaintext_length_octets)
+ return err_status_algo_fail;
+ status = err_status_ok;
+ for (i=0; i < test_case->plaintext_length_octets; i++)
+ if (buffer[i] != test_case->plaintext[i]) {
+ status = err_status_algo_fail;
+ debug_print(mod_cipher, "test case %d failed", case_num);
+ debug_print(mod_cipher, "(failure at byte %d)", i);
+ }
+ if (status) {
+
+ debug_print(mod_cipher, "p computed: %s",
+ octet_string_hex_string(buffer,
+ 2*test_case->plaintext_length_octets));
+ debug_print(mod_cipher, "p expected: %s",
+ octet_string_hex_string(test_case->plaintext,
+ 2*test_case->plaintext_length_octets));
+
+ cipher_dealloc(c);
+ return err_status_algo_fail;
+ }
+
+ /* deallocate the cipher */
+ status = cipher_dealloc(c);
+ if (status)
+ return status;
+
+ /*
+ * the cipher passed the test case, so move on to the next test
+ * case in the list; if NULL, we'l proceed to the next test
+ */
+ test_case = test_case->next_test_case;
+ ++case_num;
+ }
+
+ /* now run some random invertibility tests */
+
+ /* allocate cipher, using paramaters from the first test case */
+ test_case = ct->test_data;
+ status = cipher_type_alloc(ct, &c, test_case->key_length_octets);
+ if (status)
+ return status;
+
+ rand_source_init();
+
+ for (j=0; j < NUM_RAND_TESTS; j++) {
+ unsigned length;
+ unsigned plaintext_len;
+ uint8_t key[MAX_KEY_LEN];
+ uint8_t iv[MAX_KEY_LEN];
+
+ /* choose a length at random (leaving room for IV and padding) */
+ length = rand() % (SELF_TEST_BUF_OCTETS - 64);
+ debug_print(mod_cipher, "random plaintext length %d\n", length);
+ status = rand_source_get_octet_string(buffer, length);
+ if (status) return status;
+
+ debug_print(mod_cipher, "plaintext: %s",
+ octet_string_hex_string(buffer, length));
+
+ /* copy plaintext into second buffer */
+ for (i=0; (unsigned int)i < length; i++)
+ buffer2[i] = buffer[i];
+
+ /* choose a key at random */
+ if (test_case->key_length_octets > MAX_KEY_LEN)
+ return err_status_cant_check;
+ status = rand_source_get_octet_string(key, test_case->key_length_octets);
+ if (status) return status;
+
+ /* chose a random initialization vector */
+ status = rand_source_get_octet_string(iv, MAX_KEY_LEN);
+ if (status) return status;
+
+ /* initialize cipher */
+ status = cipher_init(c, key, direction_encrypt);
+ if (status) {
+ cipher_dealloc(c);
+ return status;
+ }
+
+ /* set initialization vector */
+ status = cipher_set_iv(c, test_case->idx);
+ if (status) {
+ cipher_dealloc(c);
+ return status;
+ }
+
+ /* encrypt buffer with cipher */
+ plaintext_len = length;
+ status = cipher_encrypt(c, buffer, &length);
+ if (status) {
+ cipher_dealloc(c);
+ return status;
+ }
+ debug_print(mod_cipher, "ciphertext: %s",
+ octet_string_hex_string(buffer, length));
+
+ /*
+ * re-initialize cipher for decryption, re-set the iv, then
+ * decrypt the ciphertext
+ */
+ status = cipher_init(c, key, direction_decrypt);
+ if (status) {
+ cipher_dealloc(c);
+ return status;
+ }
+ status = cipher_set_iv(c, test_case->idx);
+ if (status) {
+ cipher_dealloc(c);
+ return status;
+ }
+ status = cipher_decrypt(c, buffer, &length);
+ if (status) {
+ cipher_dealloc(c);
+ return status;
+ }
+
+ debug_print(mod_cipher, "plaintext[2]: %s",
+ octet_string_hex_string(buffer, length));
+
+ /* compare the resulting plaintext with the original one */
+ if (length != plaintext_len)
+ return err_status_algo_fail;
+ status = err_status_ok;
+ for (i=0; i < plaintext_len; i++)
+ if (buffer[i] != buffer2[i]) {
+ status = err_status_algo_fail;
+ debug_print(mod_cipher, "random test case %d failed", case_num);
+ debug_print(mod_cipher, "(failure at byte %d)", i);
+ }
+ if (status) {
+ cipher_dealloc(c);
+ return err_status_algo_fail;
+ }
+
+ }
+
+ cipher_dealloc(c);
+
+ return err_status_ok;
+}
+
+
+/*
+ * cipher_bits_per_second(c, l, t) computes (an estimate of) the
+ * number of bits that a cipher implementation can encrypt in a second
+ *
+ * c is a cipher (which MUST be allocated and initialized already), l
+ * is the length in octets of the test data to be encrypted, and t is
+ * the number of trials
+ *
+ * if an error is encountered, the value 0 is returned
+ */
+
+uint64_t
+cipher_bits_per_second(cipher_t *c, int octets_in_buffer, int num_trials) {
+ int i;
+ v128_t nonce;
+ clock_t timer;
+ unsigned char *enc_buf;
+ unsigned int len = octets_in_buffer;
+
+ enc_buf = (unsigned char*) crypto_alloc(octets_in_buffer);
+ if (enc_buf == NULL)
+ return 0; /* indicate bad parameters by returning null */
+
+ /* time repeated trials */
+ v128_set_to_zero(&nonce);
+ timer = clock();
+ for(i=0; i < num_trials; i++, nonce.v32[3] = i) {
+ cipher_set_iv(c, &nonce);
+ cipher_encrypt(c, enc_buf, &len);
+ }
+ timer = clock() - timer;
+
+ crypto_free(enc_buf);
+
+ if (timer == 0) {
+ /* Too fast! */
+ return 0;
+ }
+
+ return (uint64_t)CLOCKS_PER_SEC * num_trials * 8 * octets_in_buffer / timer;
+}
diff --git a/jni/pjproject-android/.svn/pristine/16/16b5ad7cac01f4e28e73f78b7be4531a3e0df1db.svn-base b/jni/pjproject-android/.svn/pristine/16/16b5ad7cac01f4e28e73f78b7be4531a3e0df1db.svn-base
new file mode 100644
index 0000000..2282b6a
--- /dev/null
+++ b/jni/pjproject-android/.svn/pristine/16/16b5ad7cac01f4e28e73f78b7be4531a3e0df1db.svn-base
@@ -0,0 +1,295 @@
+/* $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 "test.h"
+#include <pjsip.h>
+#include <pjlib.h>
+
+#define THIS_FILE "tsx_uas_test.c"
+
+
+static pjsip_module mod_tsx_user;
+
+static int uac_tsx_bench(unsigned working_set, pj_timestamp *p_elapsed)
+{
+ unsigned i;
+ pjsip_tx_data *request;
+ pjsip_transaction **tsx;
+ pj_timestamp t1, t2, elapsed;
+ pjsip_via_hdr *via;
+ pj_status_t status;
+
+ /* Create the request first. */
+ pj_str_t str_target = pj_str("sip:someuser@someprovider.com");
+ pj_str_t str_from = pj_str("\"Local User\" <sip:localuser@serviceprovider.com>");
+ pj_str_t str_to = pj_str("\"Remote User\" <sip:remoteuser@serviceprovider.com>");
+ pj_str_t str_contact = str_from;
+
+ status = pjsip_endpt_create_request(endpt, &pjsip_invite_method,
+ &str_target, &str_from, &str_to,
+ &str_contact, NULL, -1, NULL,
+ &request);
+ if (status != PJ_SUCCESS) {
+ app_perror(" error: unable to create request", status);
+ return status;
+ }
+
+ via = (pjsip_via_hdr*) pjsip_msg_find_hdr(request->msg, PJSIP_H_VIA,
+ NULL);
+
+ /* Create transaction array */
+ tsx = (pjsip_transaction**) pj_pool_zalloc(request->pool, working_set * sizeof(pj_pool_t*));
+
+ pj_bzero(&mod_tsx_user, sizeof(mod_tsx_user));
+ mod_tsx_user.id = -1;
+
+ /* Benchmark */
+ elapsed.u64 = 0;
+ pj_get_timestamp(&t1);
+ for (i=0; i<working_set; ++i) {
+ status = pjsip_tsx_create_uac(&mod_tsx_user, request, &tsx[i]);
+ if (status != PJ_SUCCESS)
+ goto on_error;
+ /* Reset branch param */
+ via->branch_param.slen = 0;
+ }
+ pj_get_timestamp(&t2);
+ pj_sub_timestamp(&t2, &t1);
+ pj_add_timestamp(&elapsed, &t2);
+
+ p_elapsed->u64 = elapsed.u64;
+ status = PJ_SUCCESS;
+
+on_error:
+ for (i=0; i<working_set; ++i) {
+ if (tsx[i]) {
+ pj_timer_heap_t *th;
+
+ pjsip_tsx_terminate(tsx[i], 601);
+ tsx[i] = NULL;
+
+ th = pjsip_endpt_get_timer_heap(endpt);
+ pj_timer_heap_poll(th, NULL);
+ }
+ }
+ pjsip_tx_data_dec_ref(request);
+ flush_events(2000);
+ return status;
+}
+
+
+
+static int uas_tsx_bench(unsigned working_set, pj_timestamp *p_elapsed)
+{
+ unsigned i;
+ pjsip_tx_data *request;
+ pjsip_via_hdr *via;
+ pjsip_rx_data rdata;
+ pj_sockaddr_in remote;
+ pjsip_transaction **tsx;
+ pj_timestamp t1, t2, elapsed;
+ char branch_buf[80] = PJSIP_RFC3261_BRANCH_ID "0000000000";
+ pj_status_t status;
+
+ /* Create the request first. */
+ pj_str_t str_target = pj_str("sip:someuser@someprovider.com");
+ pj_str_t str_from = pj_str("\"Local User\" <sip:localuser@serviceprovider.com>");
+ pj_str_t str_to = pj_str("\"Remote User\" <sip:remoteuser@serviceprovider.com>");
+ pj_str_t str_contact = str_from;
+
+ status = pjsip_endpt_create_request(endpt, &pjsip_invite_method,
+ &str_target, &str_from, &str_to,
+ &str_contact, NULL, -1, NULL,
+ &request);
+ if (status != PJ_SUCCESS) {
+ app_perror(" error: unable to create request", status);
+ return status;
+ }
+
+ /* Create Via */
+ via = pjsip_via_hdr_create(request->pool);
+ via->sent_by.host = pj_str("192.168.0.7");
+ via->sent_by.port = 5061;
+ via->transport = pj_str("udp");
+ via->rport_param = 1;
+ via->recvd_param = pj_str("192.168.0.7");
+ pjsip_msg_insert_first_hdr(request->msg, (pjsip_hdr*)via);
+
+
+ /* Create "dummy" rdata from the tdata */
+ pj_bzero(&rdata, sizeof(pjsip_rx_data));
+ rdata.tp_info.pool = request->pool;
+ rdata.msg_info.msg = request->msg;
+ rdata.msg_info.from = (pjsip_from_hdr*) pjsip_msg_find_hdr(request->msg, PJSIP_H_FROM, NULL);
+ rdata.msg_info.to = (pjsip_to_hdr*) pjsip_msg_find_hdr(request->msg, PJSIP_H_TO, NULL);
+ rdata.msg_info.cseq = (pjsip_cseq_hdr*) pjsip_msg_find_hdr(request->msg, PJSIP_H_CSEQ, NULL);
+ rdata.msg_info.cid = (pjsip_cid_hdr*) pjsip_msg_find_hdr(request->msg, PJSIP_H_FROM, NULL);
+ rdata.msg_info.via = via;
+
+ pj_sockaddr_in_init(&remote, 0, 0);
+ status = pjsip_endpt_acquire_transport(endpt, PJSIP_TRANSPORT_LOOP_DGRAM,
+ &remote, sizeof(pj_sockaddr_in),
+ NULL, &rdata.tp_info.transport);
+ if (status != PJ_SUCCESS) {
+ app_perror(" error: unable to get loop transport", status);
+ return status;
+ }
+
+
+ /* Create transaction array */
+ tsx = (pjsip_transaction**) pj_pool_zalloc(request->pool, working_set * sizeof(pj_pool_t*));
+
+ pj_bzero(&mod_tsx_user, sizeof(mod_tsx_user));
+ mod_tsx_user.id = -1;
+
+
+ /* Benchmark */
+ elapsed.u64 = 0;
+ pj_get_timestamp(&t1);
+ for (i=0; i<working_set; ++i) {
+ via->branch_param.ptr = branch_buf;
+ via->branch_param.slen = PJSIP_RFC3261_BRANCH_LEN +
+ pj_ansi_sprintf(branch_buf+PJSIP_RFC3261_BRANCH_LEN,
+ "-%d", i);
+ status = pjsip_tsx_create_uas(&mod_tsx_user, &rdata, &tsx[i]);
+ if (status != PJ_SUCCESS)
+ goto on_error;
+
+ }
+ pj_get_timestamp(&t2);
+ pj_sub_timestamp(&t2, &t1);
+ pj_add_timestamp(&elapsed, &t2);
+
+ p_elapsed->u64 = elapsed.u64;
+ status = PJ_SUCCESS;
+
+on_error:
+ for (i=0; i<working_set; ++i) {
+ if (tsx[i]) {
+ pj_timer_heap_t *th;
+
+ pjsip_tsx_terminate(tsx[i], 601);
+ tsx[i] = NULL;
+
+ th = pjsip_endpt_get_timer_heap(endpt);
+ pj_timer_heap_poll(th, NULL);
+
+ }
+ }
+ pjsip_tx_data_dec_ref(request);
+ flush_events(2000);
+ return status;
+}
+
+
+
+int tsx_bench(void)
+{
+ enum { WORKING_SET=10000, REPEAT = 4 };
+ unsigned i, speed;
+ pj_timestamp usec[REPEAT], min, freq;
+ char desc[250];
+ int status;
+
+ status = pj_get_timestamp_freq(&freq);
+ if (status != PJ_SUCCESS)
+ return status;
+
+
+ /*
+ * Benchmark UAC
+ */
+ PJ_LOG(3,(THIS_FILE, " benchmarking UAC transaction creation:"));
+ for (i=0; i<REPEAT; ++i) {
+ PJ_LOG(3,(THIS_FILE, " test %d of %d..",
+ i+1, REPEAT));
+ PJ_LOG(3,(THIS_FILE, " number of current tsx: %d",
+ pjsip_tsx_layer_get_tsx_count()));
+ status = uac_tsx_bench(WORKING_SET, &usec[i]);
+ if (status != PJ_SUCCESS)
+ return status;
+ }
+
+ min.u64 = PJ_UINT64(0xFFFFFFFFFFFFFFF);
+ for (i=0; i<REPEAT; ++i) {
+ if (usec[i].u64 < min.u64) min.u64 = usec[i].u64;
+ }
+
+
+ /* Report time */
+ pj_ansi_sprintf(desc, "Time to create %d UAC transactions, in miliseconds",
+ WORKING_SET);
+ report_ival("create-uac-time", (unsigned)(min.u64 * 1000 / freq.u64), "msec", desc);
+
+
+ /* Write speed */
+ speed = (unsigned)(freq.u64 * WORKING_SET / min.u64);
+ PJ_LOG(3,(THIS_FILE, " UAC created at %d tsx/sec", speed));
+
+ pj_ansi_sprintf(desc, "Number of UAC transactions that potentially can be created per second "
+ "with <tt>pjsip_tsx_create_uac()</tt>, based on the time "
+ "to create %d simultaneous transactions above.",
+ WORKING_SET);
+
+ report_ival("create-uac-tsx-per-sec",
+ speed, "tsx/sec", desc);
+
+
+
+ /*
+ * Benchmark UAS
+ */
+ PJ_LOG(3,(THIS_FILE, " benchmarking UAS transaction creation:"));
+ for (i=0; i<REPEAT; ++i) {
+ PJ_LOG(3,(THIS_FILE, " test %d of %d..",
+ i+1, REPEAT));
+ PJ_LOG(3,(THIS_FILE, " number of current tsx: %d",
+ pjsip_tsx_layer_get_tsx_count()));
+ status = uas_tsx_bench(WORKING_SET, &usec[i]);
+ if (status != PJ_SUCCESS)
+ return status;
+ }
+
+ min.u64 = PJ_UINT64(0xFFFFFFFFFFFFFFF);
+ for (i=0; i<REPEAT; ++i) {
+ if (usec[i].u64 < min.u64) min.u64 = usec[i].u64;
+ }
+
+
+ /* Report time */
+ pj_ansi_sprintf(desc, "Time to create %d UAS transactions, in miliseconds",
+ WORKING_SET);
+ report_ival("create-uas-time", (unsigned)(min.u64 * 1000 / freq.u64), "msec", desc);
+
+
+ /* Write speed */
+ speed = (unsigned)(freq.u64 * WORKING_SET / min.u64);
+ PJ_LOG(3,(THIS_FILE, " UAS created at %d tsx/sec", speed));
+
+ pj_ansi_sprintf(desc, "Number of UAS transactions that potentially can be created per second "
+ "with <tt>pjsip_tsx_create_uas()</tt>, based on the time "
+ "to create %d simultaneous transactions above.",
+ WORKING_SET);
+
+ report_ival("create-uas-tsx-per-sec",
+ speed, "tsx/sec", desc);
+
+ return PJ_SUCCESS;
+}
+
diff --git a/jni/pjproject-android/.svn/pristine/16/16c1fc94e5250bafe149a6e5412250a34b1f1f00.svn-base b/jni/pjproject-android/.svn/pristine/16/16c1fc94e5250bafe149a6e5412250a34b1f1f00.svn-base
new file mode 100644
index 0000000..301348b
--- /dev/null
+++ b/jni/pjproject-android/.svn/pristine/16/16c1fc94e5250bafe149a6e5412250a34b1f1f00.svn-base
@@ -0,0 +1,160 @@
+/*
+ * null_auth.c
+ *
+ * implements the do-nothing auth algorithm
+ *
+ * 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.
+ *
+ */
+
+
+#include "null_auth.h"
+#include "alloc.h"
+
+/* null_auth uses the auth debug module */
+
+extern debug_module_t mod_auth;
+
+err_status_t
+null_auth_alloc(auth_t **a, int key_len, int out_len) {
+ extern auth_type_t null_auth;
+ uint8_t *pointer;
+
+ debug_print(mod_auth, "allocating auth func with key length %d", key_len);
+ debug_print(mod_auth, " tag length %d", out_len);
+
+ /* allocate memory for auth and null_auth_ctx_t structures */
+ pointer = (uint8_t*)crypto_alloc(sizeof(null_auth_ctx_t) + sizeof(auth_t));
+ if (pointer == NULL)
+ return err_status_alloc_fail;
+
+ /* set pointers */
+ *a = (auth_t *)pointer;
+ (*a)->type = &null_auth;
+ (*a)->state = pointer + sizeof (auth_t);
+ (*a)->out_len = out_len;
+ (*a)->prefix_len = out_len;
+ (*a)->key_len = key_len;
+
+ /* increment global count of all null_auth uses */
+ null_auth.ref_count++;
+
+ return err_status_ok;
+}
+
+err_status_t
+null_auth_dealloc(auth_t *a) {
+ extern auth_type_t null_auth;
+
+ /* zeroize entire state*/
+ octet_string_set_to_zero((uint8_t *)a,
+ sizeof(null_auth_ctx_t) + sizeof(auth_t));
+
+ /* free memory */
+ crypto_free(a);
+
+ /* decrement global count of all null_auth uses */
+ null_auth.ref_count--;
+
+ return err_status_ok;
+}
+
+err_status_t
+null_auth_init(null_auth_ctx_t *state, const uint8_t *key, int key_len) {
+
+ /* accept any length of key, and do nothing */
+
+ return err_status_ok;
+}
+
+err_status_t
+null_auth_compute(null_auth_ctx_t *state, uint8_t *message,
+ int msg_octets, int tag_len, uint8_t *result) {
+
+ return err_status_ok;
+}
+
+err_status_t
+null_auth_update(null_auth_ctx_t *state, uint8_t *message,
+ int msg_octets) {
+
+ return err_status_ok;
+}
+
+err_status_t
+null_auth_start(null_auth_ctx_t *state) {
+ return err_status_ok;
+}
+
+/*
+ * auth_type_t - defines description, test case, and null_auth
+ * metaobject
+ */
+
+/* begin test case 0 */
+
+auth_test_case_t
+null_auth_test_case_0 = {
+ 0, /* octets in key */
+ NULL, /* key */
+ 0, /* octets in data */
+ NULL, /* data */
+ 0, /* octets in tag */
+ NULL, /* tag */
+ NULL /* pointer to next testcase */
+};
+
+/* end test case 0 */
+
+char null_auth_description[] = "null authentication function";
+
+auth_type_t
+null_auth = {
+ (auth_alloc_func) null_auth_alloc,
+ (auth_dealloc_func) null_auth_dealloc,
+ (auth_init_func) null_auth_init,
+ (auth_compute_func) null_auth_compute,
+ (auth_update_func) null_auth_update,
+ (auth_start_func) null_auth_start,
+ (char *) null_auth_description,
+ (int) 0, /* instance count */
+ (auth_test_case_t *) &null_auth_test_case_0
+};
+
diff --git a/jni/pjproject-android/.svn/pristine/16/16d93d1a6c283890b49d3a8215ffd17abd0ac3d4.svn-base b/jni/pjproject-android/.svn/pristine/16/16d93d1a6c283890b49d3a8215ffd17abd0ac3d4.svn-base
new file mode 100644
index 0000000..384be82
--- /dev/null
+++ b/jni/pjproject-android/.svn/pristine/16/16d93d1a6c283890b49d3a8215ffd17abd0ac3d4.svn-base
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+<!DOCTYPE scenario SYSTEM "sipp.dtd">
+
+
+<scenario name="Multiple Require header fields">
+ <!-- UAC with bad ACK causes assertion with pjsip 1.4 -->
+ <send retrans="500">
+ <![CDATA[
+
+ INVITE sip:[service]@[remote_ip]:[remote_port] SIP/2.0
+ Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
+ From: sipp <sip:sipp@[local_ip]:[local_port]>;tag=[call_number]
+ To: sut <sip:[service]@[remote_ip]:[remote_port]>
+ Call-ID: [call_id]
+ CSeq: 1 INVITE
+ Contact: sip:sipp@[local_ip]:[local_port]
+ Max-Forwards: 70
+ Require: timer
+ Require: toto
+ Subject: Performance Test
+ Content-Type: application/sdp
+ Content-Length: [len]
+
+ v=0
+ o=user1 53655765 2353687637 IN IP[local_ip_type] [local_ip]
+ s=-
+ c=IN IP[media_ip_type] [media_ip]
+ t=0 0
+ m=audio [media_port] RTP/AVP 0
+ a=rtpmap:0 PCMU/8000
+
+ ]]>
+ </send>
+
+ <recv response="100"
+ optional="true">
+ </recv>
+
+ <recv response="420" rtd="true">
+ </recv>
+
+ <send>
+ <![CDATA[
+
+ ACK sip:[service]@[remote_ip]:[remote_port] SIP/2.0
+ Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
+ From: sipp <sip:sipp@[local_ip]:[local_port]>;tag=[call_number]
+ To: sut <sip:[service]@[remote_ip]:[remote_port]>[peer_tag_param]
+ Call-ID: [call_id]
+ CSeq: 1 ACK
+ Contact: sip:sipp@[local_ip]:[local_port]
+ Max-Forwards: 70
+ Subject: Performance Test
+ Content-Length: 0
+
+ ]]>
+ </send>
+
+
+ <!-- definition of the response time repartition table (unit is ms) -->
+ <ResponseTimeRepartition value="10, 20, 30, 40, 50, 100, 150, 200"/>
+
+ <!-- definition of the call length repartition table (unit is ms) -->
+ <CallLengthRepartition value="10, 50, 100, 500, 1000, 5000, 10000"/>
+
+</scenario>
+