v210dec.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Copyright (c) 2019 James Darnley
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (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
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. */
  20. #include <string.h>
  21. #include "checkasm.h"
  22. #include "libavcodec/v210dec_init.h"
  23. static uint32_t get_v210(void)
  24. {
  25. uint32_t t0 = rnd() & 0x3ff,
  26. t1 = rnd() & 0x3ff,
  27. t2 = rnd() & 0x3ff;
  28. uint32_t value = t0
  29. | (t1 << 10)
  30. | (t2 << 20);
  31. return value;
  32. }
  33. #define NUM_SAMPLES 2048
  34. static void randomize_buffers(uint32_t *src0, uint32_t *src1, int len)
  35. {
  36. for (int i = 0; i < len; i++) {
  37. uint32_t value = get_v210();
  38. src0[i] = value;
  39. src1[i] = value;
  40. }
  41. }
  42. void checkasm_check_v210dec(void)
  43. {
  44. V210DecContext h;
  45. h.aligned_input = 0;
  46. ff_v210dec_init(&h);
  47. if (check_func(h.unpack_frame, "v210_unpack")) {
  48. uint32_t src0[NUM_SAMPLES/3];
  49. uint32_t src1[NUM_SAMPLES/3];
  50. uint16_t y0[NUM_SAMPLES/2 + 26];
  51. uint16_t y1[NUM_SAMPLES/2 + 26];
  52. uint16_t u0[NUM_SAMPLES/4 + 13];
  53. uint16_t u1[NUM_SAMPLES/4 + 13];
  54. uint16_t v0[NUM_SAMPLES/4 + 13];
  55. uint16_t v1[NUM_SAMPLES/4 + 13];
  56. declare_func(void, const uint32_t *src, uint16_t *y, uint16_t *u, uint16_t *v, int width);
  57. const int pixels = NUM_SAMPLES / 2 / 6 * 6;
  58. randomize_buffers(src0, src1, NUM_SAMPLES/3);
  59. call_ref(src0, y0, u0, v0, pixels);
  60. call_new(src1, y1, u1, v1, pixels);
  61. if (memcmp(src0, src1, NUM_SAMPLES/3 * sizeof src0[0])
  62. || memcmp(y0, y1, pixels * sizeof y0[0])
  63. || memcmp(u0, u1, pixels/2 * sizeof u0[0])
  64. || memcmp(v0, v1, pixels/2 * sizeof v0[0]))
  65. fail();
  66. bench_new(src1, y1, u1, v1, pixels);
  67. }
  68. report("v210_unpack");
  69. }