vsrc_nullsrc.c 3.3 KB

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