vsrc_nullsrc.c 3.2 KB

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