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.

100 lines
3.1KB

  1. /*
  2. * Copyright (C) 2016 foo86
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg 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. * FFmpeg 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 FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #ifndef AVCODEC_DCADEC_H
  21. #define AVCODEC_DCADEC_H
  22. #include "libavutil/common.h"
  23. #include "libavutil/crc.h"
  24. #include "libavutil/float_dsp.h"
  25. #include "avcodec.h"
  26. #include "get_bits.h"
  27. #include "dca.h"
  28. #include "dcadsp.h"
  29. #include "dca_core.h"
  30. #include "dca_exss.h"
  31. #include "dca_xll.h"
  32. #include "dca_lbr.h"
  33. #define DCA_BUFFER_PADDING_SIZE 1024
  34. #define DCA_PACKET_CORE 0x01
  35. #define DCA_PACKET_EXSS 0x02
  36. #define DCA_PACKET_XLL 0x04
  37. #define DCA_PACKET_LBR 0x08
  38. #define DCA_PACKET_MASK 0x0f
  39. #define DCA_PACKET_RECOVERY 0x10 ///< Sync error recovery flag
  40. #define DCA_PACKET_RESIDUAL 0x20 ///< Core valid for residual decoding
  41. typedef struct DCAContext {
  42. const AVClass *class; ///< class for AVOptions
  43. AVCodecContext *avctx;
  44. DCACoreDecoder core; ///< Core decoder context
  45. DCAExssParser exss; ///< EXSS parser context
  46. DCAXllDecoder xll; ///< XLL decoder context
  47. DCALbrDecoder lbr; ///< LBR decoder context
  48. DCADSPContext dcadsp;
  49. const AVCRC *crctab;
  50. uint8_t *buffer; ///< Packet buffer
  51. unsigned int buffer_size;
  52. int packet; ///< Packet flags
  53. int request_channel_layout; ///< Converted from avctx.request_channel_layout
  54. int core_only; ///< Core only decoding flag
  55. } DCAContext;
  56. int ff_dca_set_channel_layout(AVCodecContext *avctx, int *ch_remap, int dca_mask);
  57. void ff_dca_downmix_to_stereo_fixed(DCADSPContext *dcadsp, int32_t **samples,
  58. int *coeff_l, int nsamples, int ch_mask);
  59. void ff_dca_downmix_to_stereo_float(AVFloatDSPContext *fdsp, float **samples,
  60. int *coeff_l, int nsamples, int ch_mask);
  61. static inline int ff_dca_check_crc(AVCodecContext *avctx, GetBitContext *s,
  62. int p1, int p2)
  63. {
  64. DCAContext *dca = avctx->priv_data;
  65. if (!(avctx->err_recognition & (AV_EF_CRCCHECK | AV_EF_CAREFUL)))
  66. return 0;
  67. if (((p1 | p2) & 7) || p1 < 0 || p2 > s->size_in_bits || p2 - p1 < 16)
  68. return -1;
  69. if (av_crc(dca->crctab, 0xffff, s->buffer + p1 / 8, (p2 - p1) / 8))
  70. return -1;
  71. return 0;
  72. }
  73. static inline int ff_dca_seek_bits(GetBitContext *s, int p)
  74. {
  75. if (p < s->index || p > s->size_in_bits)
  76. return -1;
  77. s->index = p;
  78. return 0;
  79. }
  80. #endif