ex
Fork of mbed-os-example-mbed5-blinky by
DuerOS-Light-SDK-v1.1.0/duer-os-light/external/speex/include/speex/speex_jitter.h@47:9e361da97763, 2017-07-18 (annotated)
- Committer:
- TMBOY
- Date:
- Tue Jul 18 16:54:45 2017 +0800
- Revision:
- 47:9e361da97763
?
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| TMBOY | 47:9e361da97763 | 1 | /* Copyright (C) 2002 Jean-Marc Valin */ |
| TMBOY | 47:9e361da97763 | 2 | /** |
| TMBOY | 47:9e361da97763 | 3 | @file speex_jitter.h |
| TMBOY | 47:9e361da97763 | 4 | @brief Adaptive jitter buffer for Speex |
| TMBOY | 47:9e361da97763 | 5 | */ |
| TMBOY | 47:9e361da97763 | 6 | /* |
| TMBOY | 47:9e361da97763 | 7 | Redistribution and use in source and binary forms, with or without |
| TMBOY | 47:9e361da97763 | 8 | modification, are permitted provided that the following conditions |
| TMBOY | 47:9e361da97763 | 9 | are met: |
| TMBOY | 47:9e361da97763 | 10 | |
| TMBOY | 47:9e361da97763 | 11 | - Redistributions of source code must retain the above copyright |
| TMBOY | 47:9e361da97763 | 12 | notice, this list of conditions and the following disclaimer. |
| TMBOY | 47:9e361da97763 | 13 | |
| TMBOY | 47:9e361da97763 | 14 | - Redistributions in binary form must reproduce the above copyright |
| TMBOY | 47:9e361da97763 | 15 | notice, this list of conditions and the following disclaimer in the |
| TMBOY | 47:9e361da97763 | 16 | documentation and/or other materials provided with the distribution. |
| TMBOY | 47:9e361da97763 | 17 | |
| TMBOY | 47:9e361da97763 | 18 | - Neither the name of the Xiph.org Foundation nor the names of its |
| TMBOY | 47:9e361da97763 | 19 | contributors may be used to endorse or promote products derived from |
| TMBOY | 47:9e361da97763 | 20 | this software without specific prior written permission. |
| TMBOY | 47:9e361da97763 | 21 | |
| TMBOY | 47:9e361da97763 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| TMBOY | 47:9e361da97763 | 23 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| TMBOY | 47:9e361da97763 | 24 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| TMBOY | 47:9e361da97763 | 25 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR |
| TMBOY | 47:9e361da97763 | 26 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| TMBOY | 47:9e361da97763 | 27 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| TMBOY | 47:9e361da97763 | 28 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| TMBOY | 47:9e361da97763 | 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| TMBOY | 47:9e361da97763 | 30 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| TMBOY | 47:9e361da97763 | 31 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| TMBOY | 47:9e361da97763 | 32 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| TMBOY | 47:9e361da97763 | 33 | |
| TMBOY | 47:9e361da97763 | 34 | */ |
| TMBOY | 47:9e361da97763 | 35 | |
| TMBOY | 47:9e361da97763 | 36 | #ifndef SPEEX_JITTER_H |
| TMBOY | 47:9e361da97763 | 37 | #define SPEEX_JITTER_H |
| TMBOY | 47:9e361da97763 | 38 | /** @defgroup JitterBuffer JitterBuffer: Adaptive jitter buffer |
| TMBOY | 47:9e361da97763 | 39 | * This is the jitter buffer that reorders UDP/RTP packets and adjusts the buffer size |
| TMBOY | 47:9e361da97763 | 40 | * to maintain good quality and low latency. |
| TMBOY | 47:9e361da97763 | 41 | * @{ |
| TMBOY | 47:9e361da97763 | 42 | */ |
| TMBOY | 47:9e361da97763 | 43 | |
| TMBOY | 47:9e361da97763 | 44 | #include "speex.h" |
| TMBOY | 47:9e361da97763 | 45 | #include "speex_bits.h" |
| TMBOY | 47:9e361da97763 | 46 | |
| TMBOY | 47:9e361da97763 | 47 | #ifdef __cplusplus |
| TMBOY | 47:9e361da97763 | 48 | extern "C" { |
| TMBOY | 47:9e361da97763 | 49 | #endif |
| TMBOY | 47:9e361da97763 | 50 | |
| TMBOY | 47:9e361da97763 | 51 | /** Generic adaptive jitter buffer state */ |
| TMBOY | 47:9e361da97763 | 52 | struct JitterBuffer_; |
| TMBOY | 47:9e361da97763 | 53 | |
| TMBOY | 47:9e361da97763 | 54 | /** Generic adaptive jitter buffer state */ |
| TMBOY | 47:9e361da97763 | 55 | typedef struct JitterBuffer_ JitterBuffer; |
| TMBOY | 47:9e361da97763 | 56 | |
| TMBOY | 47:9e361da97763 | 57 | /** Definition of an incoming packet */ |
| TMBOY | 47:9e361da97763 | 58 | typedef struct _JitterBufferPacket JitterBufferPacket; |
| TMBOY | 47:9e361da97763 | 59 | |
| TMBOY | 47:9e361da97763 | 60 | /** Definition of an incoming packet */ |
| TMBOY | 47:9e361da97763 | 61 | struct _JitterBufferPacket { |
| TMBOY | 47:9e361da97763 | 62 | char *data; /**< Data bytes contained in the packet */ |
| TMBOY | 47:9e361da97763 | 63 | spx_uint32_t len; /**< Length of the packet in bytes */ |
| TMBOY | 47:9e361da97763 | 64 | spx_uint32_t timestamp; /**< Timestamp for the packet */ |
| TMBOY | 47:9e361da97763 | 65 | spx_uint32_t span; /**< Time covered by the packet (same units as timestamp) */ |
| TMBOY | 47:9e361da97763 | 66 | }; |
| TMBOY | 47:9e361da97763 | 67 | |
| TMBOY | 47:9e361da97763 | 68 | /** Packet has been retrieved */ |
| TMBOY | 47:9e361da97763 | 69 | #define JITTER_BUFFER_OK 0 |
| TMBOY | 47:9e361da97763 | 70 | /** Packet is missing */ |
| TMBOY | 47:9e361da97763 | 71 | #define JITTER_BUFFER_MISSING 1 |
| TMBOY | 47:9e361da97763 | 72 | /** Packet is incomplete (does not cover the entive tick */ |
| TMBOY | 47:9e361da97763 | 73 | #define JITTER_BUFFER_INCOMPLETE 2 |
| TMBOY | 47:9e361da97763 | 74 | /** There was an error in the jitter buffer */ |
| TMBOY | 47:9e361da97763 | 75 | #define JITTER_BUFFER_INTERNAL_ERROR -1 |
| TMBOY | 47:9e361da97763 | 76 | /** Invalid argument */ |
| TMBOY | 47:9e361da97763 | 77 | #define JITTER_BUFFER_BAD_ARGUMENT -2 |
| TMBOY | 47:9e361da97763 | 78 | |
| TMBOY | 47:9e361da97763 | 79 | |
| TMBOY | 47:9e361da97763 | 80 | /** Set minimum amount of extra buffering required (margin) */ |
| TMBOY | 47:9e361da97763 | 81 | #define JITTER_BUFFER_SET_MARGIN 0 |
| TMBOY | 47:9e361da97763 | 82 | /** Get minimum amount of extra buffering required (margin) */ |
| TMBOY | 47:9e361da97763 | 83 | #define JITTER_BUFFER_GET_MARGIN 1 |
| TMBOY | 47:9e361da97763 | 84 | /* JITTER_BUFFER_SET_AVALIABLE_COUNT wouldn't make sense */ |
| TMBOY | 47:9e361da97763 | 85 | /** Get the amount of avaliable packets currently buffered */ |
| TMBOY | 47:9e361da97763 | 86 | #define JITTER_BUFFER_GET_AVALIABLE_COUNT 3 |
| TMBOY | 47:9e361da97763 | 87 | |
| TMBOY | 47:9e361da97763 | 88 | #define JITTER_BUFFER_ADJUST_INTERPOLATE -1 |
| TMBOY | 47:9e361da97763 | 89 | #define JITTER_BUFFER_ADJUST_OK 0 |
| TMBOY | 47:9e361da97763 | 90 | #define JITTER_BUFFER_ADJUST_DROP 1 |
| TMBOY | 47:9e361da97763 | 91 | |
| TMBOY | 47:9e361da97763 | 92 | /** Initialises jitter buffer |
| TMBOY | 47:9e361da97763 | 93 | * |
| TMBOY | 47:9e361da97763 | 94 | * @param tick Number of samples per "tick", i.e. the time period of the elements that will be retrieved |
| TMBOY | 47:9e361da97763 | 95 | * @return Newly created jitter buffer state |
| TMBOY | 47:9e361da97763 | 96 | */ |
| TMBOY | 47:9e361da97763 | 97 | JitterBuffer *jitter_buffer_init(int tick); |
| TMBOY | 47:9e361da97763 | 98 | |
| TMBOY | 47:9e361da97763 | 99 | /** Restores jitter buffer to its original state |
| TMBOY | 47:9e361da97763 | 100 | * |
| TMBOY | 47:9e361da97763 | 101 | * @param jitter Jitter buffer state |
| TMBOY | 47:9e361da97763 | 102 | */ |
| TMBOY | 47:9e361da97763 | 103 | void jitter_buffer_reset(JitterBuffer *jitter); |
| TMBOY | 47:9e361da97763 | 104 | |
| TMBOY | 47:9e361da97763 | 105 | /** Destroys jitter buffer |
| TMBOY | 47:9e361da97763 | 106 | * |
| TMBOY | 47:9e361da97763 | 107 | * @param jitter Jitter buffer state |
| TMBOY | 47:9e361da97763 | 108 | */ |
| TMBOY | 47:9e361da97763 | 109 | void jitter_buffer_destroy(JitterBuffer *jitter); |
| TMBOY | 47:9e361da97763 | 110 | |
| TMBOY | 47:9e361da97763 | 111 | /** Put one packet into the jitter buffer |
| TMBOY | 47:9e361da97763 | 112 | * |
| TMBOY | 47:9e361da97763 | 113 | * @param jitter Jitter buffer state |
| TMBOY | 47:9e361da97763 | 114 | * @param packet Incoming packet |
| TMBOY | 47:9e361da97763 | 115 | */ |
| TMBOY | 47:9e361da97763 | 116 | void jitter_buffer_put(JitterBuffer *jitter, const JitterBufferPacket *packet); |
| TMBOY | 47:9e361da97763 | 117 | |
| TMBOY | 47:9e361da97763 | 118 | /** Get one packet from the jitter buffer |
| TMBOY | 47:9e361da97763 | 119 | * |
| TMBOY | 47:9e361da97763 | 120 | * @param jitter Jitter buffer state |
| TMBOY | 47:9e361da97763 | 121 | * @param packet Returned packet |
| TMBOY | 47:9e361da97763 | 122 | * @param current_timestamp Timestamp for the returned packet |
| TMBOY | 47:9e361da97763 | 123 | */ |
| TMBOY | 47:9e361da97763 | 124 | int jitter_buffer_get(JitterBuffer *jitter, JitterBufferPacket *packet, spx_int32_t *start_offset); |
| TMBOY | 47:9e361da97763 | 125 | |
| TMBOY | 47:9e361da97763 | 126 | /** Get pointer timestamp of jitter buffer |
| TMBOY | 47:9e361da97763 | 127 | * |
| TMBOY | 47:9e361da97763 | 128 | * @param jitter Jitter buffer state |
| TMBOY | 47:9e361da97763 | 129 | */ |
| TMBOY | 47:9e361da97763 | 130 | int jitter_buffer_get_pointer_timestamp(JitterBuffer *jitter); |
| TMBOY | 47:9e361da97763 | 131 | |
| TMBOY | 47:9e361da97763 | 132 | /** Advance by one tick |
| TMBOY | 47:9e361da97763 | 133 | * |
| TMBOY | 47:9e361da97763 | 134 | * @param jitter Jitter buffer state |
| TMBOY | 47:9e361da97763 | 135 | */ |
| TMBOY | 47:9e361da97763 | 136 | void jitter_buffer_tick(JitterBuffer *jitter); |
| TMBOY | 47:9e361da97763 | 137 | |
| TMBOY | 47:9e361da97763 | 138 | /** Used like the ioctl function to control the jitter buffer parameters |
| TMBOY | 47:9e361da97763 | 139 | * |
| TMBOY | 47:9e361da97763 | 140 | * @param jitter Jitter buffer state |
| TMBOY | 47:9e361da97763 | 141 | * @param request ioctl-type request (one of the JITTER_BUFFER_* macros) |
| TMBOY | 47:9e361da97763 | 142 | * @param ptr Data exchanged to-from function |
| TMBOY | 47:9e361da97763 | 143 | * @return 0 if no error, -1 if request in unknown |
| TMBOY | 47:9e361da97763 | 144 | */ |
| TMBOY | 47:9e361da97763 | 145 | int jitter_buffer_ctl(JitterBuffer *jitter, int request, void *ptr); |
| TMBOY | 47:9e361da97763 | 146 | |
| TMBOY | 47:9e361da97763 | 147 | int jitter_buffer_update_delay(JitterBuffer *jitter, JitterBufferPacket *packet, spx_int32_t *start_offset); |
| TMBOY | 47:9e361da97763 | 148 | |
| TMBOY | 47:9e361da97763 | 149 | /* @} */ |
| TMBOY | 47:9e361da97763 | 150 | |
| TMBOY | 47:9e361da97763 | 151 | /** @defgroup SpeexJitter SpeexJitter: Adaptive jitter buffer specifically for Speex |
| TMBOY | 47:9e361da97763 | 152 | * This is the jitter buffer that reorders UDP/RTP packets and adjusts the buffer size |
| TMBOY | 47:9e361da97763 | 153 | * to maintain good quality and low latency. This is a simplified version that works only |
| TMBOY | 47:9e361da97763 | 154 | * with Speex, but is much easier to use. |
| TMBOY | 47:9e361da97763 | 155 | * @{ |
| TMBOY | 47:9e361da97763 | 156 | */ |
| TMBOY | 47:9e361da97763 | 157 | |
| TMBOY | 47:9e361da97763 | 158 | /** Speex jitter-buffer state. Never use it directly! */ |
| TMBOY | 47:9e361da97763 | 159 | typedef struct SpeexJitter { |
| TMBOY | 47:9e361da97763 | 160 | SpeexBits current_packet; /**< Current Speex packet */ |
| TMBOY | 47:9e361da97763 | 161 | int valid_bits; /**< True if Speex bits are valid */ |
| TMBOY | 47:9e361da97763 | 162 | JitterBuffer *packets; /**< Generic jitter buffer state */ |
| TMBOY | 47:9e361da97763 | 163 | void *dec; /**< Pointer to Speex decoder */ |
| TMBOY | 47:9e361da97763 | 164 | spx_int32_t frame_size; /**< Frame size of Speex decoder */ |
| TMBOY | 47:9e361da97763 | 165 | } SpeexJitter; |
| TMBOY | 47:9e361da97763 | 166 | |
| TMBOY | 47:9e361da97763 | 167 | /** Initialise jitter buffer |
| TMBOY | 47:9e361da97763 | 168 | * |
| TMBOY | 47:9e361da97763 | 169 | * @param jitter State of the Speex jitter buffer |
| TMBOY | 47:9e361da97763 | 170 | * @param decoder Speex decoder to call |
| TMBOY | 47:9e361da97763 | 171 | * @param sampling_rate Sampling rate used by the decoder |
| TMBOY | 47:9e361da97763 | 172 | */ |
| TMBOY | 47:9e361da97763 | 173 | void speex_jitter_init(SpeexJitter *jitter, void *decoder, int sampling_rate); |
| TMBOY | 47:9e361da97763 | 174 | |
| TMBOY | 47:9e361da97763 | 175 | /** Destroy jitter buffer */ |
| TMBOY | 47:9e361da97763 | 176 | void speex_jitter_destroy(SpeexJitter *jitter); |
| TMBOY | 47:9e361da97763 | 177 | |
| TMBOY | 47:9e361da97763 | 178 | /** Put one packet into the jitter buffer */ |
| TMBOY | 47:9e361da97763 | 179 | void speex_jitter_put(SpeexJitter *jitter, char *packet, int len, int timestamp); |
| TMBOY | 47:9e361da97763 | 180 | |
| TMBOY | 47:9e361da97763 | 181 | /** Get one packet from the jitter buffer */ |
| TMBOY | 47:9e361da97763 | 182 | void speex_jitter_get(SpeexJitter *jitter, spx_int16_t *out, int *start_offset); |
| TMBOY | 47:9e361da97763 | 183 | |
| TMBOY | 47:9e361da97763 | 184 | /** Get pointer timestamp of jitter buffer */ |
| TMBOY | 47:9e361da97763 | 185 | int speex_jitter_get_pointer_timestamp(SpeexJitter *jitter); |
| TMBOY | 47:9e361da97763 | 186 | |
| TMBOY | 47:9e361da97763 | 187 | #ifdef __cplusplus |
| TMBOY | 47:9e361da97763 | 188 | } |
| TMBOY | 47:9e361da97763 | 189 | #endif |
| TMBOY | 47:9e361da97763 | 190 | |
| TMBOY | 47:9e361da97763 | 191 | /* @} */ |
| TMBOY | 47:9e361da97763 | 192 | #endif |
