src/spandsp/jitter.h

Go to the documentation of this file.
00001 /*
00002  * SpanDSP - a series of DSP components for telephony
00003  *
00004  * jitterbuffer.h - 
00005  *
00006  * Written by Steve Underwood <steveu@coppice.org>
00007  *
00008  * Copyright (C) 2007 Steve Underwood
00009  *
00010  * All rights reserved.
00011  *
00012  * This program is free software; you can redistribute it and/or modify
00013  * it under the terms of the GNU Lesser General Public License version 2.1,
00014  * as published by the Free Software Foundation.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU Lesser General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU Lesser General Public
00022  * License along with this program; if not, write to the Free Software
00023  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00024  *
00025  * $Id$
00026  */
00027 
00028 /*! \file */
00029 
00030 #if !defined(_SPANDSP_JITTERBUFFER_H_)
00031 #define _SPANDSP_JITTERBUFFER_H_
00032 
00033 /*! \page jitterbuffer_page Jitter buffering
00034 
00035 \section jitterbuffer_page_sec_1 What does it do?
00036 
00037 \section jitterbuffer_page_sec_2 How does it work?
00038 */
00039 
00040 #define INITIAL_JITTER      640 // 80 miliseconds
00041 #define MAX_JITTER          16000 // 2 seconds
00042 #define RESYNC_THRESHOLD    2
00043 
00044 typedef struct
00045 {
00046     int16_t data[AUDIO_BUFFER_SIZE*2];
00047     uint32_t size;
00048     uint32_t ts;
00049 public:
00050     packet_t *next;
00051     packet_t *prev;
00052     void init(const int16_t *data, uint32_t size, uint32_t ts);
00053 
00054     uint32_t size() const { return size; }
00055     int16_t *data() { return data; }
00056 
00057     bool operator < (const Packet&) const;
00058 } packet_t;
00059 
00060 typedef struct
00061 {
00062 private:
00063     packet_t packets[MAX_JITTER/80];
00064     packet_t *free_packets;
00065 
00066 public:
00067     packet_allocator(void);
00068     packet_t *alloc(const int16_t *data, uint32_t size, uint32_t ts);
00069 } packet_allocator_t;
00070 
00071 typedef struct
00072 {
00073     packet_allocator_t allocator;
00074     packet_t *head;
00075     packet_t *tail;
00076     int ts_inited;
00077     timestamp_t last_ts;
00078     timestamp_t last_resync_ts;
00079     timestamp_t last_audio_ts;
00080     timestamp_t ts_delta;
00081     int ts_delta_inited;
00082     int delay_count;
00083     uint32_t jitter;
00084     int force_resync;
00085 #ifdef DEBUG_PLAYOUTBUF
00086     uint32_t ts_delta_start;
00087 #endif
00088 } playout_state_t;
00089 
00090 #if defined(__cplusplus)
00091 extern "C"
00092 {
00093 #endif
00094 
00095 void playout_put(playout_state_t *s, const int16_t *data, timestamp_t size, timestamp_t ts, int begin_talk);
00096 int playout_get(playout_state_t *s, timestamp_t ts, uint32_t ms, int16_t *out, uint32_t *size, timestamp_t *out_ts);
00097 
00098 #if defined(__cplusplus)
00099 }
00100 #endif
00101 
00102 #endif
00103 /*- End of file ------------------------------------------------------------*/

Generated on Tue Oct 7 20:25:46 2008 for spandsp by  doxygen 1.5.6