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.

67 lines
2.0KB

  1. /*
  2. * DCA compatible decoder data
  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 <string.h>
  22. #include "put_bits.h"
  23. #include "dca.h"
  24. const uint32_t avpriv_dca_sample_rates[16] =
  25. {
  26. 0, 8000, 16000, 32000, 0, 0, 11025, 22050, 44100, 0, 0,
  27. 12000, 24000, 48000, 96000, 192000
  28. };
  29. int ff_dca_convert_bitstream(const uint8_t *src, int src_size, uint8_t *dst,
  30. int max_size)
  31. {
  32. uint32_t mrk;
  33. int i, tmp;
  34. const uint16_t *ssrc = (const uint16_t *) src;
  35. uint16_t *sdst = (uint16_t *) dst;
  36. PutBitContext pb;
  37. if ((unsigned) src_size > (unsigned) max_size)
  38. src_size = max_size;
  39. mrk = AV_RB32(src);
  40. switch (mrk) {
  41. case DCA_MARKER_RAW_BE:
  42. memcpy(dst, src, src_size);
  43. return src_size;
  44. case DCA_MARKER_RAW_LE:
  45. for (i = 0; i < (src_size + 1) >> 1; i++)
  46. *sdst++ = av_bswap16(*ssrc++);
  47. return src_size;
  48. case DCA_MARKER_14B_BE:
  49. case DCA_MARKER_14B_LE:
  50. init_put_bits(&pb, dst, max_size);
  51. for (i = 0; i < (src_size + 1) >> 1; i++, src += 2) {
  52. tmp = ((mrk == DCA_MARKER_14B_BE) ? AV_RB16(src) : AV_RL16(src)) & 0x3FFF;
  53. put_bits(&pb, 14, tmp);
  54. }
  55. flush_put_bits(&pb);
  56. return (put_bits_count(&pb) + 7) >> 3;
  57. default:
  58. return AVERROR_INVALIDDATA;
  59. }
  60. }