AmPlayoutBuffer.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 _AmPlayoutBuffer_h_
00029 #define _AmPlayoutBuffer_h_
00030
00031 #include "SampleArray.h"
00032 #include "AmStats.h"
00033 #include "LowcFE.h"
00034 #include "AmJitterBuffer.h"
00035 #include <set>
00036 using std::multiset;
00037
00038
00039 #define ORDER_STAT_WIN_SIZE 35
00040 #define ORDER_STAT_LOSS_RATE 0.1
00041
00042 #define EXP_THRESHOLD 20
00043 #define SHR_THRESHOLD 180
00044
00045 #define WSOLA_START_OFF 80
00046 #define WSOLA_SCALED_WIN 50
00047
00048
00049
00050 #define MAX_PACKET_SAMPLES 640
00051
00052 #define TEMPLATE_SEG 80
00053
00054
00055
00056 #define PLC_MAX_SAMPLES (160*4)
00057
00058 class AmPLCBuffer;
00059
00061 class AmPlayoutBuffer
00062 {
00063
00064 SampleArrayShort buffer;
00065
00066 protected:
00067 u_int32_t r_ts,w_ts;
00068 AmPLCBuffer *m_plcbuffer;
00069
00070 unsigned int last_ts;
00071 bool last_ts_i;
00072
00074 unsigned int recv_offset;
00076 bool recv_offset_i;
00077
00078 void buffer_put(unsigned int ts, ShortSample* buf, unsigned int len);
00079 void buffer_get(unsigned int ts, ShortSample* buf, unsigned int len);
00080
00081 virtual void write_buffer(u_int32_t ref_ts, u_int32_t ts, int16_t* buf, u_int32_t len);
00082 virtual void direct_write_buffer(unsigned int ts, ShortSample* buf, unsigned int len);
00083 public:
00084 AmPlayoutBuffer(AmPLCBuffer *plcbuffer);
00085 virtual ~AmPlayoutBuffer() {}
00086
00087 virtual void write(u_int32_t ref_ts, u_int32_t ts, int16_t* buf, u_int32_t len, bool begin_talk);
00088 virtual u_int32_t read(u_int32_t ts, int16_t* buf, u_int32_t len);
00089
00090 void clearLastTs() { last_ts_i = false; }
00091 };
00092
00094 class AmAdaptivePlayout: public AmPlayoutBuffer
00095 {
00096
00097 multiset<int32_t> o_stat;
00098 int32_t n_stat[ORDER_STAT_WIN_SIZE];
00099 int idx;
00100 double loss_rate;
00101
00102
00103 u_int32_t wsola_off;
00104 int shr_threshold;
00105 MeanArray short_scaled;
00106
00107
00108 int plc_cnt;
00109 LowcFE fec;
00110
00111
00112
00113 short p_buf[MAX_PACKET_SAMPLES*4];
00114
00115 short merge_buf[TEMPLATE_SEG];
00116
00117 u_int32_t time_scale(u_int32_t ts, float factor, u_int32_t packet_len);
00118 u_int32_t next_delay(u_int32_t ref_ts, u_int32_t ts);
00119
00120 public:
00121
00122 AmAdaptivePlayout(AmPLCBuffer *);
00123
00125 void direct_write_buffer(unsigned int ts, ShortSample* buf, unsigned int len);
00126
00129 void write_buffer(u_int32_t ref_ts, u_int32_t ts, int16_t* buf, u_int32_t len);
00130
00132 u_int32_t read(u_int32_t ts, int16_t* buf, u_int32_t len);
00133
00134 };
00135
00137 class AmJbPlayout : public AmPlayoutBuffer
00138 {
00139 private:
00140 AmJitterBuffer m_jb;
00141 unsigned int m_last_rtp_endts;
00142
00143 protected:
00144 void direct_write_buffer(unsigned int ts, ShortSample* buf, unsigned int len);
00145 void prepare_buffer(unsigned int ts, unsigned int ms);
00146
00147 public:
00148 AmJbPlayout(AmPLCBuffer *plcbuffer);
00149
00150 u_int32_t read(u_int32_t ts, int16_t* buf, u_int32_t len);
00151 void write(u_int32_t ref_ts, u_int32_t rtp_ts, int16_t* buf, u_int32_t len, bool begin_talk);
00152 };
00153
00154
00155 #endif
Generated on Fri May 16 12:02:05 2008 for SEMS by
1.5.1