AmJitterBuffer.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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
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
1.5.1