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.

90 lines
2.8KB

  1. /*
  2. * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg 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. * FFmpeg 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 FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include <string.h>
  21. #include "avcodec.h"
  22. #include "libavutil/atomic.h"
  23. #include "libavutil/mem.h"
  24. static AVBitStreamFilter *first_bitstream_filter = NULL;
  25. AVBitStreamFilter *av_bitstream_filter_next(const AVBitStreamFilter *f)
  26. {
  27. if (f)
  28. return f->next;
  29. else
  30. return first_bitstream_filter;
  31. }
  32. void av_register_bitstream_filter(AVBitStreamFilter *bsf)
  33. {
  34. do {
  35. bsf->next = first_bitstream_filter;
  36. } while(bsf->next != avpriv_atomic_ptr_cas((void * volatile *)&first_bitstream_filter, bsf->next, bsf));
  37. }
  38. AVBitStreamFilterContext *av_bitstream_filter_init(const char *name)
  39. {
  40. AVBitStreamFilter *bsf = NULL;
  41. while (bsf = av_bitstream_filter_next(bsf)) {
  42. if (!strcmp(name, bsf->name)) {
  43. AVBitStreamFilterContext *bsfc =
  44. av_mallocz(sizeof(AVBitStreamFilterContext));
  45. if (!bsfc)
  46. return NULL;
  47. bsfc->filter = bsf;
  48. bsfc->priv_data = NULL;
  49. if (bsf->priv_data_size) {
  50. bsfc->priv_data = av_mallocz(bsf->priv_data_size);
  51. if (!bsfc->priv_data) {
  52. av_freep(&bsfc);
  53. return NULL;
  54. }
  55. }
  56. return bsfc;
  57. }
  58. }
  59. return NULL;
  60. }
  61. void av_bitstream_filter_close(AVBitStreamFilterContext *bsfc)
  62. {
  63. if (!bsfc)
  64. return;
  65. if (bsfc->filter->close)
  66. bsfc->filter->close(bsfc);
  67. av_freep(&bsfc->priv_data);
  68. av_parser_close(bsfc->parser);
  69. av_free(bsfc);
  70. }
  71. int av_bitstream_filter_filter(AVBitStreamFilterContext *bsfc,
  72. AVCodecContext *avctx, const char *args,
  73. uint8_t **poutbuf, int *poutbuf_size,
  74. const uint8_t *buf, int buf_size, int keyframe)
  75. {
  76. *poutbuf = (uint8_t *)buf;
  77. *poutbuf_size = buf_size;
  78. return bsfc->filter->filter(bsfc, avctx, args, poutbuf, poutbuf_size,
  79. buf, buf_size, keyframe);
  80. }