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.

89 lines
2.3KB

  1. /*
  2. * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
  3. *
  4. * This file is part of Libav.
  5. *
  6. * Libav is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * Libav is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with Libav; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include <stdlib.h>
  21. #include <string.h>
  22. #include "avcodec.h"
  23. #include "bsf.h"
  24. #include "libavutil/log.h"
  25. #include "libavutil/mem.h"
  26. #include "libavutil/opt.h"
  27. typedef struct NoiseContext {
  28. const AVClass *class;
  29. int amount;
  30. unsigned int state;
  31. } NoiseContext;
  32. static int noise(AVBSFContext *ctx, AVPacket *out)
  33. {
  34. NoiseContext *s = ctx->priv_data;
  35. AVPacket *in;
  36. int amount = s->amount > 0 ? s->amount : (s->state % 10001 + 1);
  37. int i, ret = 0;
  38. ret = ff_bsf_get_packet(ctx, &in);
  39. if (ret < 0)
  40. return ret;
  41. ret = av_new_packet(out, in->size);
  42. if (ret < 0)
  43. goto fail;
  44. ret = av_packet_copy_props(out, in);
  45. if (ret < 0)
  46. goto fail;
  47. memcpy(out->data, in->data, in->size);
  48. for (i = 0; i < out->size; i++) {
  49. s->state += out->data[i] + 1;
  50. if (s->state % amount == 0)
  51. out->data[i] = s->state;
  52. }
  53. fail:
  54. if (ret < 0)
  55. av_packet_unref(out);
  56. av_packet_free(&in);
  57. return ret;
  58. }
  59. #define OFFSET(x) offsetof(NoiseContext, x)
  60. static const AVOption options[] = {
  61. { "amount", NULL, OFFSET(amount), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX },
  62. { NULL },
  63. };
  64. static const AVClass noise_class = {
  65. .class_name = "noise",
  66. .item_name = av_default_item_name,
  67. .option = options,
  68. .version = LIBAVUTIL_VERSION_INT,
  69. };
  70. const AVBitStreamFilter ff_noise_bsf = {
  71. .name = "noise",
  72. .priv_data_size = sizeof(int),
  73. .priv_class = &noise_class,
  74. .filter = noise,
  75. };