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.

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