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.

88 lines
3.3KB

  1. /*
  2. * This file is part of Libav.
  3. *
  4. * Libav is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * Libav is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with Libav; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include "libavcodec/mpeg12.h"
  19. #include "libavcodec/mpeg12data.h"
  20. int main(void)
  21. {
  22. int i;
  23. #define TEST_MATCH(frame_rate, code, ext_n, ext_d) do { \
  24. AVRational fr = frame_rate; \
  25. int c, n, d; \
  26. ff_mpeg12_find_best_frame_rate(fr, &c, &n, &d, 0); \
  27. if (c != code || n != ext_n || d != ext_d) { \
  28. av_log(NULL, AV_LOG_ERROR, "Failed to match %d/%d: " \
  29. "code = %d, ext_n = %d, ext_d = %d.\n", \
  30. fr.num, fr.den, c, n, d); \
  31. return 1; \
  32. } \
  33. } while (0)
  34. #define TEST_EXACT(frn, frd) do { \
  35. AVRational fr = (AVRational) { frn, frd }; \
  36. int c, n, d; \
  37. ff_mpeg12_find_best_frame_rate(fr, &c, &n, &d, 0); \
  38. if (av_cmp_q(fr, av_mul_q(ff_mpeg12_frame_rate_tab[c], \
  39. (AVRational) { n + 1, d + 1 })) != 0) { \
  40. av_log(NULL, AV_LOG_ERROR, "Failed to find exact %d/%d: " \
  41. "code = %d, ext_n = %d, ext_d = %d.\n", \
  42. fr.num, fr.den, c, n, d); \
  43. return 1; \
  44. } \
  45. } while (0)
  46. // Framerates in the table must be chosen exactly.
  47. for (i = 1; i <= 8; i++)
  48. TEST_MATCH(ff_mpeg12_frame_rate_tab[i], i, 0, 0);
  49. // As should the same ones with small perturbations.
  50. // (1/1000 used here to be smaller than half the difference
  51. // between 24 and 24000/1001.)
  52. for (i = 1; i <= 8; i++) {
  53. TEST_MATCH(av_sub_q(ff_mpeg12_frame_rate_tab[i],
  54. (AVRational) { 1, 1000 }), i, 0, 0);
  55. TEST_MATCH(av_add_q(ff_mpeg12_frame_rate_tab[i],
  56. (AVRational) { 1, 1000 }), i, 0, 0);
  57. }
  58. // Exactly constructable framerates should be exact. Note that some
  59. // values can be made in multiple ways (e.g. 12 = 24 / 2 == 60 / 5),
  60. // and there is no reason to favour any particular choice.
  61. TEST_EXACT( 1, 1);
  62. TEST_EXACT( 2, 1);
  63. TEST_EXACT( 12, 1);
  64. TEST_EXACT( 15000, 1001);
  65. TEST_EXACT( 15, 1);
  66. TEST_EXACT( 120, 1);
  67. TEST_EXACT(120000, 1001);
  68. TEST_EXACT( 200, 1);
  69. TEST_EXACT( 240, 1);
  70. // Values higher than 240 (the highest representable, as 60 * 4 / 1)
  71. // should be mapped to 240.
  72. for (i = 240; i < 1000; i += 10)
  73. TEST_MATCH(((AVRational) { i, 1 }), 8, 3, 0);
  74. // Values lower than 24000/32032 (the lowest representable, as
  75. // 24000/1001 * 1 / 32) should be mapped to 24000/32032.
  76. for (i = 74; i > 0; i--)
  77. TEST_MATCH(((AVRational) { i, 100 }), 1, 0, 31);
  78. return 0;
  79. }