vsrc_nullsrc.c 3.4 KB

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