vsrc_nullsrc.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. /**
  19. * @file
  20. * null video source
  21. */
  22. #include <stdio.h>
  23. #include "libavutil/avstring.h"
  24. #include "libavutil/eval.h"
  25. #include "libavutil/internal.h"
  26. #include "libavutil/mathematics.h"
  27. #include "libavutil/opt.h"
  28. #include "libavutil/parseutils.h"
  29. #include "avfilter.h"
  30. #include "formats.h"
  31. #include "internal.h"
  32. static const char *const var_names[] = {
  33. "E",
  34. "PHI",
  35. "PI",
  36. "AVTB", /* default timebase 1/AV_TIME_BASE */
  37. NULL
  38. };
  39. enum var_name {
  40. VAR_E,
  41. VAR_PHI,
  42. VAR_PI,
  43. VAR_AVTB,
  44. VAR_VARS_NB
  45. };
  46. typedef struct NullContext {
  47. const AVClass *class;
  48. int w, h;
  49. char *tb_expr;
  50. double var_values[VAR_VARS_NB];
  51. } NullContext;
  52. static int config_props(AVFilterLink *outlink)
  53. {
  54. AVFilterContext *ctx = outlink->src;
  55. NullContext *priv = ctx->priv;
  56. AVRational tb;
  57. int ret;
  58. double res;
  59. priv->var_values[VAR_E] = M_E;
  60. priv->var_values[VAR_PHI] = M_PHI;
  61. priv->var_values[VAR_PI] = M_PI;
  62. priv->var_values[VAR_AVTB] = av_q2d(AV_TIME_BASE_Q);
  63. if ((ret = av_expr_parse_and_eval(&res, priv->tb_expr, var_names, priv->var_values,
  64. NULL, NULL, NULL, NULL, NULL, 0, NULL)) < 0) {
  65. av_log(ctx, AV_LOG_ERROR, "Invalid expression '%s' for timebase.\n", priv->tb_expr);
  66. return ret;
  67. }
  68. tb = av_d2q(res, INT_MAX);
  69. if (tb.num <= 0 || tb.den <= 0) {
  70. av_log(ctx, AV_LOG_ERROR,
  71. "Invalid non-positive value for the timebase %d/%d.\n",
  72. tb.num, tb.den);
  73. return AVERROR(EINVAL);
  74. }
  75. outlink->w = priv->w;
  76. outlink->h = priv->h;
  77. outlink->time_base = tb;
  78. av_log(outlink->src, AV_LOG_VERBOSE, "w:%d h:%d tb:%d/%d\n", priv->w, priv->h,
  79. tb.num, tb.den);
  80. return 0;
  81. }
  82. static int request_frame(AVFilterLink *link)
  83. {
  84. return -1;
  85. }
  86. #define OFFSET(x) offsetof(NullContext, x)
  87. #define FLAGS AV_OPT_FLAG_VIDEO_PARAM
  88. static const AVOption options[] = {
  89. { "width", NULL, OFFSET(w), AV_OPT_TYPE_INT, { .i64 = 352 }, 1, INT_MAX, FLAGS },
  90. { "height", NULL, OFFSET(h), AV_OPT_TYPE_INT, { .i64 = 288 }, 1, INT_MAX, FLAGS },
  91. { "timebase", NULL, OFFSET(tb_expr), AV_OPT_TYPE_STRING, { .str = "AVTB" }, 0, 0, FLAGS },
  92. { NULL },
  93. };
  94. static const AVClass nullsrc_class = {
  95. .class_name = "nullsrc",
  96. .item_name = av_default_item_name,
  97. .option = options,
  98. .version = LIBAVUTIL_VERSION_INT,
  99. };
  100. static const AVFilterPad avfilter_vsrc_nullsrc_outputs[] = {
  101. {
  102. .name = "default",
  103. .type = AVMEDIA_TYPE_VIDEO,
  104. .config_props = config_props,
  105. .request_frame = request_frame,
  106. },
  107. { NULL }
  108. };
  109. AVFilter ff_vsrc_nullsrc = {
  110. .name = "nullsrc",
  111. .description = NULL_IF_CONFIG_SMALL("Null video source, never return images."),
  112. .priv_size = sizeof(NullContext),
  113. .priv_class = &nullsrc_class,
  114. .inputs = NULL,
  115. .outputs = avfilter_vsrc_nullsrc_outputs,
  116. };