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