testjitter.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #ifdef HAVE_CONFIG_H
  2. #include "config.h"
  3. #endif
  4. #include <speex/speex_jitter.h>
  5. #include <stdio.h>
  6. union jbpdata {
  7. unsigned int idx;
  8. unsigned char data[4];
  9. };
  10. void synthIn(JitterBufferPacket *in, int idx, int span) {
  11. union jbpdata d;
  12. d.idx = idx;
  13. in->data = d.data;
  14. in->len = sizeof(d);
  15. in->timestamp = idx * 10;
  16. in->span = span * 10;
  17. in->sequence = idx;
  18. in->user_data = 0;
  19. }
  20. void jitterFill(JitterBuffer *jb) {
  21. char buffer[65536];
  22. JitterBufferPacket in, out;
  23. int i;
  24. out.data = buffer;
  25. jitter_buffer_reset(jb);
  26. for(i=0;i<100;++i) {
  27. synthIn(&in, i, 1);
  28. jitter_buffer_put(jb, &in);
  29. out.len = 65536;
  30. if (jitter_buffer_get(jb, &out, 10, NULL) != JITTER_BUFFER_OK) {
  31. printf("Fill test failed iteration %d\n", i);
  32. }
  33. if (out.timestamp != i * 10) {
  34. printf("Fill test expected %d got %d\n", i*10, out.timestamp);
  35. }
  36. jitter_buffer_tick(jb);
  37. }
  38. }
  39. int main()
  40. {
  41. char buffer[65536];
  42. JitterBufferPacket in, out;
  43. int i;
  44. JitterBuffer *jb = jitter_buffer_init(10);
  45. out.data = buffer;
  46. /* Frozen sender case */
  47. jitterFill(jb);
  48. for(i=0;i<100;++i) {
  49. out.len = 65536;
  50. jitter_buffer_get(jb, &out, 10, NULL);
  51. jitter_buffer_tick(jb);
  52. }
  53. synthIn(&in, 100, 1);
  54. jitter_buffer_put(jb, &in);
  55. out.len = 65536;
  56. if (jitter_buffer_get(jb, &out, 10, NULL) != JITTER_BUFFER_OK) {
  57. printf("Failed frozen sender resynchronize\n");
  58. } else {
  59. printf("Frozen sender: Jitter %d\n", out.timestamp - 100*10);
  60. }
  61. return 0;
  62. }