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.

133 lines
3.4KB

  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 "libavutil/avstring.h"
  23. #include "libavutil/eval.h"
  24. #include "libavutil/mathematics.h"
  25. #include "libavutil/parseutils.h"
  26. #include "avfilter.h"
  27. #include "formats.h"
  28. #include "internal.h"
  29. static const char *const var_names[] = {
  30. "E",
  31. "PHI",
  32. "PI",
  33. "AVTB", /* default timebase 1/AV_TIME_BASE */
  34. NULL
  35. };
  36. enum var_name {
  37. VAR_E,
  38. VAR_PHI,
  39. VAR_PI,
  40. VAR_AVTB,
  41. VAR_VARS_NB
  42. };
  43. typedef struct {
  44. int w, h;
  45. char tb_expr[256];
  46. double var_values[VAR_VARS_NB];
  47. } NullContext;
  48. static int init(AVFilterContext *ctx, const char *args)
  49. {
  50. NullContext *priv = ctx->priv;
  51. priv->w = 352;
  52. priv->h = 288;
  53. av_strlcpy(priv->tb_expr, "AVTB", sizeof(priv->tb_expr));
  54. if (args)
  55. sscanf(args, "%d:%d:%255[^:]", &priv->w, &priv->h, priv->tb_expr);
  56. if (priv->w <= 0 || priv->h <= 0) {
  57. av_log(ctx, AV_LOG_ERROR, "Non-positive size values are not acceptable.\n");
  58. return AVERROR(EINVAL);
  59. }
  60. return 0;
  61. }
  62. static int config_props(AVFilterLink *outlink)
  63. {
  64. AVFilterContext *ctx = outlink->src;
  65. NullContext *priv = ctx->priv;
  66. AVRational tb;
  67. int ret;
  68. double res;
  69. priv->var_values[VAR_E] = M_E;
  70. priv->var_values[VAR_PHI] = M_PHI;
  71. priv->var_values[VAR_PI] = M_PI;
  72. priv->var_values[VAR_AVTB] = av_q2d(AV_TIME_BASE_Q);
  73. if ((ret = av_expr_parse_and_eval(&res, priv->tb_expr, var_names, priv->var_values,
  74. NULL, NULL, NULL, NULL, NULL, 0, NULL)) < 0) {
  75. av_log(ctx, AV_LOG_ERROR, "Invalid expression '%s' for timebase.\n", priv->tb_expr);
  76. return ret;
  77. }
  78. tb = av_d2q(res, INT_MAX);
  79. if (tb.num <= 0 || tb.den <= 0) {
  80. av_log(ctx, AV_LOG_ERROR,
  81. "Invalid non-positive value for the timebase %d/%d.\n",
  82. tb.num, tb.den);
  83. return AVERROR(EINVAL);
  84. }
  85. outlink->w = priv->w;
  86. outlink->h = priv->h;
  87. outlink->time_base = tb;
  88. av_log(outlink->src, AV_LOG_INFO, "w:%d h:%d tb:%d/%d\n", priv->w, priv->h,
  89. tb.num, tb.den);
  90. return 0;
  91. }
  92. static int request_frame(AVFilterLink *link)
  93. {
  94. return -1;
  95. }
  96. AVFilter avfilter_vsrc_nullsrc = {
  97. .name = "nullsrc",
  98. .description = NULL_IF_CONFIG_SMALL("Null video source, never return images."),
  99. .init = init,
  100. .priv_size = sizeof(NullContext),
  101. .inputs = (AVFilterPad[]) {{ .name = NULL}},
  102. .outputs = (AVFilterPad[]) {
  103. {
  104. .name = "default",
  105. .type = AVMEDIA_TYPE_VIDEO,
  106. .config_props = config_props,
  107. .request_frame = request_frame,
  108. },
  109. { .name = NULL}
  110. },
  111. };