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.

83 lines
2.3KB

  1. /*
  2. * codec2 utility functions
  3. * Copyright (c) 2017 Tomas Härdin
  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. #include <string.h>
  22. #include "internal.h"
  23. #include "libavcodec/codec2utils.h"
  24. #if LIBAVCODEC_VERSION_MAJOR < 59
  25. int avpriv_codec2_mode_bit_rate(void *logctx, int mode)
  26. {
  27. int frame_size = avpriv_codec2_mode_frame_size(logctx, mode);
  28. int block_align = avpriv_codec2_mode_block_align(logctx, mode);
  29. if (frame_size <= 0 || block_align <= 0) {
  30. return 0;
  31. }
  32. return 8 * 8000 * block_align / frame_size;
  33. }
  34. int avpriv_codec2_mode_frame_size(void *logctx, int mode)
  35. {
  36. int frame_size_table[CODEC2_MODE_MAX+1] = {
  37. 160, // 3200
  38. 160, // 2400
  39. 320, // 1600
  40. 320, // 1400
  41. 320, // 1300
  42. 320, // 1200
  43. 320, // 700
  44. 320, // 700B
  45. 320, // 700C
  46. };
  47. if (mode < 0 || mode > CODEC2_MODE_MAX) {
  48. av_log(logctx, AV_LOG_ERROR, "unknown codec2 mode %i, can't find frame_size\n", mode);
  49. return 0;
  50. } else {
  51. return frame_size_table[mode];
  52. }
  53. }
  54. int avpriv_codec2_mode_block_align(void *logctx, int mode)
  55. {
  56. int block_align_table[CODEC2_MODE_MAX+1] = {
  57. 8, // 3200
  58. 6, // 2400
  59. 8, // 1600
  60. 7, // 1400
  61. 7, // 1300
  62. 6, // 1200
  63. 4, // 700
  64. 4, // 700B
  65. 4, // 700C
  66. };
  67. if (mode < 0 || mode > CODEC2_MODE_MAX) {
  68. av_log(logctx, AV_LOG_ERROR, "unknown codec2 mode %i, can't find block_align\n", mode);
  69. return 0;
  70. } else {
  71. return block_align_table[mode];
  72. }
  73. }
  74. #endif