avdct.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * Copyright (c) 2014 Michael Niedermayer <michaelni@gmx.at>
  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. #include "avcodec.h"
  21. #include "idctdsp.h"
  22. #include "fdctdsp.h"
  23. #include "pixblockdsp.h"
  24. #include "avdct.h"
  25. #define OFFSET(x) offsetof(AVDCT,x)
  26. #define DEFAULT 0 //should be NAN but it does not work as it is not a constant in glibc as required by ANSI/ISO C
  27. //these names are too long to be readable
  28. #define V AV_OPT_FLAG_VIDEO_PARAM
  29. #define A AV_OPT_FLAG_AUDIO_PARAM
  30. #define E AV_OPT_FLAG_ENCODING_PARAM
  31. #define D AV_OPT_FLAG_DECODING_PARAM
  32. static const AVOption avdct_options[] = {
  33. {"dct", "DCT algorithm", OFFSET(dct_algo), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, 0, INT_MAX, V|E, "dct"},
  34. {"auto", "autoselect a good one", 0, AV_OPT_TYPE_CONST, {.i64 = FF_DCT_AUTO }, INT_MIN, INT_MAX, V|E, "dct"},
  35. {"fastint", "fast integer (experimental / for debugging)", 0, AV_OPT_TYPE_CONST, {.i64 = FF_DCT_FASTINT }, INT_MIN, INT_MAX, V|E, "dct"},
  36. {"int", "accurate integer", 0, AV_OPT_TYPE_CONST, {.i64 = FF_DCT_INT }, INT_MIN, INT_MAX, V|E, "dct"},
  37. {"mmx", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_DCT_MMX }, INT_MIN, INT_MAX, V|E, "dct"},
  38. {"altivec", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_DCT_ALTIVEC }, INT_MIN, INT_MAX, V|E, "dct"},
  39. {"faan", "floating point AAN DCT (experimental / for debugging)", 0, AV_OPT_TYPE_CONST, {.i64 = FF_DCT_FAAN }, INT_MIN, INT_MAX, V|E, "dct"},
  40. {"idct", "select IDCT implementation", OFFSET(idct_algo), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, 0, INT_MAX, V|E|D, "idct"},
  41. {"auto", "autoselect a good one", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_AUTO }, INT_MIN, INT_MAX, V|E|D, "idct"},
  42. {"int", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_INT }, INT_MIN, INT_MAX, V|E|D, "idct"},
  43. {"simple", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_SIMPLE }, INT_MIN, INT_MAX, V|E|D, "idct"},
  44. {"simplemmx", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_SIMPLEMMX }, INT_MIN, INT_MAX, V|E|D, "idct"},
  45. {"arm", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_ARM }, INT_MIN, INT_MAX, V|E|D, "idct"},
  46. {"altivec", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_ALTIVEC }, INT_MIN, INT_MAX, V|E|D, "idct"},
  47. {"simplearm", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_SIMPLEARM }, INT_MIN, INT_MAX, V|E|D, "idct"},
  48. {"simplearmv5te", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_SIMPLEARMV5TE }, INT_MIN, INT_MAX, V|E|D, "idct"},
  49. {"simplearmv6", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_SIMPLEARMV6 }, INT_MIN, INT_MAX, V|E|D, "idct"},
  50. {"simpleneon", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_SIMPLENEON }, INT_MIN, INT_MAX, V|E|D, "idct"},
  51. {"xvid", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_XVID }, INT_MIN, INT_MAX, V|E|D, "idct"},
  52. {"xvidmmx", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_XVID }, INT_MIN, INT_MAX, V|E|D, "idct"},
  53. {"faani", "floating point AAN IDCT (experimental / for debugging)", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_FAAN }, INT_MIN, INT_MAX, V|D|E, "idct"},
  54. {"simpleauto", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_SIMPLEAUTO }, INT_MIN, INT_MAX, V|E|D, "idct"},
  55. {"bits_per_sample", "", OFFSET(bits_per_sample), AV_OPT_TYPE_INT, {.i64 = 8 }, 0, 14, 0,},
  56. {NULL},
  57. };
  58. static const AVClass avdct_class = {
  59. .class_name = "AVDCT",
  60. .option = avdct_options,
  61. .version = LIBAVUTIL_VERSION_INT,
  62. };
  63. const AVClass *avcodec_dct_get_class(void)
  64. {
  65. return &avdct_class;
  66. }
  67. AVDCT *avcodec_dct_alloc(void)
  68. {
  69. AVDCT *dsp = av_mallocz(sizeof(AVDCT));
  70. if (!dsp)
  71. return NULL;
  72. dsp->av_class = &avdct_class;
  73. av_opt_set_defaults(dsp);
  74. return dsp;
  75. }
  76. int avcodec_dct_init(AVDCT *dsp)
  77. {
  78. AVCodecContext *avctx = avcodec_alloc_context3(NULL);
  79. if (!avctx)
  80. return AVERROR(ENOMEM);
  81. avctx->idct_algo = dsp->idct_algo;
  82. avctx->dct_algo = dsp->dct_algo;
  83. avctx->bits_per_raw_sample = dsp->bits_per_sample;
  84. #define COPY(src, name) memcpy(&dsp->name, &src.name, sizeof(dsp->name))
  85. #if CONFIG_IDCTDSP
  86. {
  87. IDCTDSPContext idsp = {0};
  88. ff_idctdsp_init(&idsp, avctx);
  89. COPY(idsp, idct);
  90. COPY(idsp, idct_permutation);
  91. }
  92. #endif
  93. #if CONFIG_FDCTDSP
  94. {
  95. FDCTDSPContext fdsp;
  96. ff_fdctdsp_init(&fdsp, avctx);
  97. COPY(fdsp, fdct);
  98. }
  99. #endif
  100. #if CONFIG_PIXBLOCKDSP
  101. {
  102. PixblockDSPContext pdsp;
  103. ff_pixblockdsp_init(&pdsp, avctx);
  104. COPY(pdsp, get_pixels);
  105. }
  106. #endif
  107. avcodec_free_context(&avctx);
  108. return 0;
  109. }