AmJitterBuffer.h

Go to the documentation of this file.
00001 /*
00002  * $Id: AmDtmfDetector.h,v 1.1.2.1 2005/06/01 12:00:24 rco Exp $
00003  *
00004  * Copyright (C) 2006 Sippy Software, Inc.
00005  *
00006  * This file is part of sems, a free SIP media server.
00007  *
00008  * sems is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version
00012  *
00013  * For a license to use the ser software under conditions
00014  * other than those described here, or to purchase support for this
00015  * software, please contact iptel.org by e-mail at the following addresses:
00016  *    info@iptel.org
00017  *
00018  * sems is distributed in the hope that it will be useful,
00019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021  * GNU General Public License for more details.
00022  *
00023  * You should have received a copy of the GNU General Public License 
00024  * along with this program; if not, write to the Free Software 
00025  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00026  */
00028 #ifndef _AmJitterBuffer_h_
00029 #define _AmJitterBuffer_h_
00030 
00031 #include "amci/amci.h"
00032 #include "AmThread.h"
00033 #include "SampleArray.h"
00034 
00035 #define INITIAL_JITTER      640 // 80 miliseconds
00036 #define MAX_JITTER          16000 // 2 seconds
00037 #define RESYNC_THRESHOLD    2
00038 
00039 class Packet {
00040   ShortSample m_data[AUDIO_BUFFER_SIZE * 2];
00041   unsigned int m_size;
00042   unsigned int m_ts;
00043  public:
00044   Packet *m_next;
00045   Packet *m_prev;
00046   void init(const ShortSample *data, unsigned int size, unsigned int ts);
00047 
00048   unsigned int size() const { return m_size; }
00049   unsigned int ts() const { return m_ts; }
00050   ShortSample *data() { return m_data; }
00051 
00052   bool operator < (const Packet&) const;
00053 };
00054 
00055 class PacketAllocator
00056 {
00057  private:
00058   Packet m_packets[MAX_JITTER / 80];
00059   Packet *m_free_packets;
00060 
00061  public:
00062   PacketAllocator();
00063   Packet *alloc(const ShortSample *data, unsigned int size, unsigned int ts);
00064   void free(Packet *p);
00065 };
00066 
00067 class AmJitterBuffer
00068 {
00069  private:
00070   AmMutex m_mutex;
00071   PacketAllocator m_allocator;
00072   Packet *m_head;
00073   Packet *m_tail;
00074   bool m_tsInited;
00075   unsigned int m_lastTs;
00076   unsigned int m_lastResyncTs;
00077   unsigned int m_lastAudioTs;
00078   unsigned int m_tsDelta;
00079   bool m_tsDeltaInited;
00080   int m_delayCount;
00081   unsigned int m_jitter;
00082   //    AmRtpStream *m_owner;
00083   bool m_forceResync;
00084 
00085 #ifdef DEBUG_PLAYOUTBUF
00086   unsigned int m_tsDeltaStart;
00087 #endif
00088 
00089  public:
00090   AmJitterBuffer();
00091   void put(const ShortSample *data, unsigned int size, unsigned int ts, bool begin_talk);
00092   bool get(unsigned int ts, unsigned int ms, ShortSample *out, unsigned int *size, unsigned int *out_ts);
00093 };
00094 
00095 #endif // _AmJitterBuffer_h_

Generated on Fri May 16 12:02:05 2008 for SEMS by  doxygen 1.5.1
Home |  Recent changes |  Search |  Glossary |  Sitemap |  Login