You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
2.2KB

  1. /*
  2. * tables and functions for demuxing SIPR audio muxed RealMedia style
  3. *
  4. * This file is part of Libav.
  5. *
  6. * Libav is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * Libav is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with Libav; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include <stdint.h>
  21. #include "rmsipr.h"
  22. const unsigned char ff_sipr_subpk_size[4] = { 29, 19, 37, 20 };
  23. static const unsigned char sipr_swaps[38][2] = {
  24. { 0, 63 }, { 1, 22 }, { 2, 44 }, { 3, 90 },
  25. { 5, 81 }, { 7, 31 }, { 8, 86 }, { 9, 58 },
  26. { 10, 36 }, { 12, 68 }, { 13, 39 }, { 14, 73 },
  27. { 15, 53 }, { 16, 69 }, { 17, 57 }, { 19, 88 },
  28. { 20, 34 }, { 21, 71 }, { 24, 46 }, { 25, 94 },
  29. { 26, 54 }, { 28, 75 }, { 29, 50 }, { 32, 70 },
  30. { 33, 92 }, { 35, 74 }, { 38, 85 }, { 40, 56 },
  31. { 42, 87 }, { 43, 65 }, { 45, 59 }, { 48, 79 },
  32. { 49, 93 }, { 51, 89 }, { 55, 95 }, { 61, 76 },
  33. { 67, 83 }, { 77, 80 }
  34. };
  35. /* This can be optimized, e.g. use memcpy() if data blocks are aligned. */
  36. void ff_rm_reorder_sipr_data(uint8_t *buf, int sub_packet_h, int framesize)
  37. {
  38. int n, bs = sub_packet_h * framesize * 2 / 96; // nibbles per subpacket
  39. for (n = 0; n < 38; n++) {
  40. int j;
  41. int i = bs * sipr_swaps[n][0];
  42. int o = bs * sipr_swaps[n][1];
  43. /* swap 4bit-nibbles of block 'i' with 'o' */
  44. for (j = 0; j < bs; j++, i++, o++) {
  45. int x = (buf[i >> 1] >> (4 * (i & 1))) & 0xF,
  46. y = (buf[o >> 1] >> (4 * (o & 1))) & 0xF;
  47. buf[o >> 1] = (x << (4 * (o & 1))) |
  48. (buf[o >> 1] & (0xF << (4 * !(o & 1))));
  49. buf[i >> 1] = (y << (4 * (i & 1))) |
  50. (buf[i >> 1] & (0xF << (4 * !(i & 1))));
  51. }
  52. }
  53. }