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.

152 lines
5.3KB

  1. /*
  2. * TAK decoder/demuxer common code
  3. * Copyright (c) 2012 Paul B Mahol
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. /**
  22. * @file
  23. * TAK (Tom's lossless Audio Kompressor) decoder/demuxer common functions
  24. */
  25. #ifndef AVCODEC_TAK_H
  26. #define AVCODEC_TAK_H
  27. #define BITSTREAM_READER_LE
  28. #include "get_bits.h"
  29. #include "avcodec.h"
  30. #define TAK_FORMAT_DATA_TYPE_BITS 3
  31. #define TAK_FORMAT_SAMPLE_RATE_BITS 18
  32. #define TAK_FORMAT_BPS_BITS 5
  33. #define TAK_FORMAT_CHANNEL_BITS 4
  34. #define TAK_FORMAT_VALID_BITS 5
  35. #define TAK_FORMAT_CH_LAYOUT_BITS 6
  36. #define TAK_SIZE_FRAME_DURATION_BITS 4
  37. #define TAK_SIZE_SAMPLES_NUM_BITS 35
  38. #define TAK_LAST_FRAME_POS_BITS 40
  39. #define TAK_LAST_FRAME_SIZE_BITS 24
  40. #define TAK_ENCODER_CODEC_BITS 6
  41. #define TAK_ENCODER_PROFILE_BITS 4
  42. #define TAK_ENCODER_VERSION_BITS 24
  43. #define TAK_SAMPLE_RATE_MIN 6000
  44. #define TAK_CHANNELS_MIN 1
  45. #define TAK_BPS_MIN 8
  46. #define TAK_FRAME_HEADER_FLAGS_BITS 3
  47. #define TAK_FRAME_HEADER_SYNC_ID 0xA0FF
  48. #define TAK_FRAME_HEADER_SYNC_ID_BITS 16
  49. #define TAK_FRAME_HEADER_SAMPLE_COUNT_BITS 14
  50. #define TAK_FRAME_HEADER_NO_BITS 21
  51. #define TAK_FRAME_DURATION_QUANT_SHIFT 5
  52. #define TAK_CRC24_BITS 24
  53. #define TAK_MAX_CHANNELS ( 1 << TAK_FORMAT_CHANNEL_BITS )
  54. #define TAK_MIN_FRAME_HEADER_BITS ( TAK_FRAME_HEADER_SYNC_ID_BITS + \
  55. TAK_FRAME_HEADER_FLAGS_BITS + \
  56. TAK_FRAME_HEADER_NO_BITS + \
  57. TAK_CRC24_BITS )
  58. #define TAK_MIN_FRAME_HEADER_LAST_BITS ( TAK_MIN_FRAME_HEADER_BITS + 2 + \
  59. TAK_FRAME_HEADER_SAMPLE_COUNT_BITS )
  60. #define TAK_ENCODER_BITS ( TAK_ENCODER_CODEC_BITS + \
  61. TAK_ENCODER_PROFILE_BITS )
  62. #define TAK_SIZE_BITS ( TAK_SIZE_SAMPLES_NUM_BITS + \
  63. TAK_SIZE_FRAME_DURATION_BITS )
  64. #define TAK_FORMAT_BITS ( TAK_FORMAT_DATA_TYPE_BITS + \
  65. TAK_FORMAT_SAMPLE_RATE_BITS + \
  66. TAK_FORMAT_BPS_BITS + \
  67. TAK_FORMAT_CHANNEL_BITS + 1 + \
  68. TAK_FORMAT_VALID_BITS + 1 + \
  69. TAK_FORMAT_CH_LAYOUT_BITS * \
  70. TAK_MAX_CHANNELS )
  71. #define TAK_STREAMINFO_BITS ( TAK_ENCODER_BITS + \
  72. TAK_SIZE_BITS + \
  73. TAK_FORMAT_BITS )
  74. #define TAK_MAX_FRAME_HEADER_BITS ( TAK_MIN_FRAME_HEADER_LAST_BITS + \
  75. TAK_STREAMINFO_BITS + 31 )
  76. #define TAK_STREAMINFO_BYTES (( TAK_STREAMINFO_BITS + 7 ) / 8)
  77. #define TAK_MAX_FRAME_HEADER_BYTES (( TAK_MAX_FRAME_HEADER_BITS + 7 ) / 8)
  78. #define TAK_MIN_FRAME_HEADER_BYTES (( TAK_MIN_FRAME_HEADER_BITS + 7 ) / 8)
  79. enum TAKMetaDataType {
  80. TAK_METADATA_END = 0,
  81. TAK_METADATA_STREAMINFO,
  82. TAK_METADATA_SEEKTABLE,
  83. TAK_METADATA_SIMPLE_WAVE_DATA,
  84. TAK_METADATA_ENCODER,
  85. TAK_METADATA_PADDING,
  86. TAK_METADATA_MD5,
  87. TAK_METADATA_LAST_FRAME,
  88. };
  89. enum TAKFrameSizeType {
  90. TAK_FST_94ms = 0,
  91. TAK_FST_125ms,
  92. TAK_FST_188ms,
  93. TAK_FST_250ms,
  94. TAK_FST_4096,
  95. TAK_FST_8192,
  96. TAK_FST_16384,
  97. TAK_FST_512,
  98. TAK_FST_1024,
  99. TAK_FST_2048,
  100. };
  101. typedef struct TAKStreamInfo {
  102. int codec;
  103. int data_type;
  104. int sample_rate;
  105. int channels;
  106. int bps;
  107. int frame_num;
  108. int frame_samples;
  109. int last_frame_samples;
  110. uint64_t ch_layout;
  111. int64_t samples;
  112. } TAKStreamInfo;
  113. void ff_tak_init_crc(void);
  114. int ff_tak_check_crc(const uint8_t *buf, unsigned int buf_size);
  115. /**
  116. * Parse the Streaminfo metadata block
  117. * @param[in] gb pointer to GetBitContext
  118. * @param[out] s where parsed information is stored
  119. */
  120. void avpriv_tak_parse_streaminfo(GetBitContext *gb, TAKStreamInfo *s);
  121. /**
  122. * Validate and decode a frame header.
  123. * @param avctx AVCodecContext to use as av_log() context
  124. * @param[in] gb GetBitContext from which to read frame header
  125. * @param[out] s frame information
  126. * @param log_level_offset log level offset. can be used to silence error messages.
  127. * @return non-zero on error, 0 if ok
  128. */
  129. int ff_tak_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb,
  130. TAKStreamInfo *s, int log_level_offset);
  131. #endif /* AVCODEC_TAK_H */