| 1 | /* Copyright (C) 2002 Jean-Marc Valin |
| 2 | File: speex_jitter.h |
| 3 | |
| 4 | Adaptive jitter buffer for Speex |
| 5 | |
| 6 | Redistribution and use in source and binary forms, with or without |
| 7 | modification, are permitted provided that the following conditions |
| 8 | are met: |
| 9 | |
| 10 | - Redistributions of source code must retain the above copyright |
| 11 | notice, this list of conditions and the following disclaimer. |
| 12 | |
| 13 | - Redistributions in binary form must reproduce the above copyright |
| 14 | notice, this list of conditions and the following disclaimer in the |
| 15 | documentation and/or other materials provided with the distribution. |
| 16 | |
| 17 | - Neither the name of the Xiph.org Foundation nor the names of its |
| 18 | contributors may be used to endorse or promote products derived from |
| 19 | this software without specific prior written permission. |
| 20 | |
| 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 22 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 23 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 24 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR |
| 25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 26 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 27 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 28 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 29 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 30 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 31 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 32 | |
| 33 | */ |
| 34 | |
| 35 | #ifndef SPEEX_JITTER_H |
| 36 | #define SPEEX_JITTER_H |
| 37 | |
| 38 | #include "speex.h" |
| 39 | #include "speex_bits.h" |
| 40 | |
| 41 | #ifdef __cplusplus |
| 42 | extern "C" { |
| 43 | #endif |
| 44 | |
| 45 | #define SPEEX_JITTER_MAX_PACKET_SIZE 1500 |
| 46 | #define SPEEX_JITTER_MAX_BUFFER_SIZE 20 |
| 47 | |
| 48 | #define MAX_MARGIN 12 |
| 49 | |
| 50 | typedef struct SpeexJitter { |
| 51 | int buffer_size; |
| 52 | int pointer_timestamp; |
| 53 | |
| 54 | SpeexBits current_packet; |
| 55 | int valid_bits; |
| 56 | |
| 57 | char buf[SPEEX_JITTER_MAX_BUFFER_SIZE][SPEEX_JITTER_MAX_PACKET_SIZE]; |
| 58 | int timestamp[SPEEX_JITTER_MAX_BUFFER_SIZE]; |
| 59 | int len[SPEEX_JITTER_MAX_BUFFER_SIZE]; |
| 60 | |
| 61 | void *dec; |
| 62 | int frame_size; |
| 63 | int frame_time; |
| 64 | int reset_state; |
| 65 | |
| 66 | int lost_count; |
| 67 | float shortterm_margin[MAX_MARGIN]; |
| 68 | float longterm_margin[MAX_MARGIN]; |
| 69 | float loss_rate; |
| 70 | } SpeexJitter; |
| 71 | |
| 72 | void speex_jitter_init(SpeexJitter *jitter, void *decoder, int sampling_rate); |
| 73 | |
| 74 | void speex_jitter_destroy(SpeexJitter *jitter); |
| 75 | |
| 76 | void speex_jitter_put(SpeexJitter *jitter, char *packet, int len, int time); |
| 77 | |
| 78 | void speex_jitter_get(SpeexJitter *jitter, short *out, int *current_timestamp); |
| 79 | |
| 80 | int speex_jitter_get_pointer_timestamp(SpeexJitter *jitter); |
| 81 | |
| 82 | #ifdef __cplusplus |
| 83 | } |
| 84 | #endif |
| 85 | |
| 86 | |
| 87 | #endif |