00001 #ifndef _AmPlayoutBuffer_h_
00002 #define _AmPlayoutBuffer_h_
00003
00004 #include "SampleArray.h"
00005 #include "AmStats.h"
00006 #include "LowcFE.h"
00007 #include "AmJitterBuffer.h"
00008 #include <set>
00009 using std::multiset;
00010
00011 #define ORDER_STAT_WIN_SIZE 35
00012 #define ORDER_STAT_LOSS_RATE 0.1
00013
00014 #define EXP_THRESHOLD 20
00015 #define SHR_THRESHOLD 180
00016
00017 #define WSOLA_START_OFF 80
00018 #define WSOLA_SCALED_WIN 50
00019
00020
00021
00022 #define MAX_PACKET_SAMPLES 640
00023
00024 #define TEMPLATE_SEG 80
00025
00026
00027
00028 #define PLC_MAX_SAMPLES (160*4)
00029
00030 class AmPLCBuffer;
00031
00032
00033 class AmPlayoutBuffer
00034 {
00035
00036 SampleArrayShort buffer;
00037
00038 protected:
00039 uint32_t r_ts;
00040 uint32_t w_ts;
00041 AmPLCBuffer *m_plcbuffer;
00042
00043 uint32_t last_ts;
00044 bool last_ts_i;
00045
00046
00047 uint32_t recv_offset;
00048
00049 bool recv_offset_i;
00050
00051 void buffer_put(uint32_t ts, int16_t *buf, int len);
00052 void buffer_get(uint32_t ts, int16_t *buf, int len);
00053
00054 virtual void write_buffer(uint32_t ref_ts, uint32_t ts, int16_t *buf, int len);
00055 virtual void direct_write_buffer(uint32_t ts, int16_t *buf, int len);
00056 public:
00057 AmPlayoutBuffer(AmPLCBuffer *plcbuffer);
00058 virtual ~AmPlayoutBuffer() {}
00059
00060 virtual void write(uint32_t ref_ts, uint32_t ts, int16_t *buf, int len, bool begin_talk);
00061 virtual uint32_t read(uint32_t ts, int16_t *buf, int len);
00062
00063 void clearLastTs() {last_ts_i = false;}
00064 };
00065
00066
00067 class AmAdaptivePlayout: public AmPlayoutBuffer
00068 {
00069
00070 multiset<int32_t> o_stat;
00071 int32_t n_stat[ORDER_STAT_WIN_SIZE];
00072 int idx;
00073 double loss_rate;
00074
00075
00076 uint32_t wsola_off;
00077 int shr_threshold;
00078 MeanArray short_scaled;
00079
00080
00081 int plc_cnt;
00082 LowcFE fec;
00083
00084
00085
00086 int16_t p_buf[MAX_PACKET_SAMPLES*4];
00087
00088 int16_t merge_buf[TEMPLATE_SEG];
00089
00090 uint32_t time_scale(uint32_t ts, float factor, uint32_t packet_len);
00091 uint32_t next_delay(uint32_t ref_ts, uint32_t ts);
00092
00093 public:
00094 AmAdaptivePlayout(AmPLCBuffer *);
00095
00096
00097 void direct_write_buffer(unsigned int ts, int16_t *buf, unsigned int len);
00098
00099
00100
00101 void write_buffer(uint32_t ref_ts, uint32_t ts, int16_t *buf, uint32_t len);
00102
00103
00104 uint32_t read(uint32_t ts, int16_t *buf, uint32_t len);
00105 };
00106
00107
00108 class AmJbPlayout : public AmPlayoutBuffer
00109 {
00110 private:
00111 AmJitterBuffer m_jb;
00112 unsigned int m_last_rtp_endts;
00113
00114 protected:
00115 void direct_write_buffer(unsigned int ts, int16_t *buf, unsigned int len);
00116 void prepare_buffer(unsigned int ts, unsigned int ms);
00117
00118 public:
00119 AmJbPlayout(AmPLCBuffer *plcbuffer);
00120
00121 uint32_t read(uint32_t ts, int16_t *buf, uint32_t len);
00122 void write(uint32_t ref_ts, uint32_t rtp_ts, int16_t *buf, uint32_t len, bool begin_talk);
00123 };
00124
00125 #endif