video.c 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Copyright 2007 Bobby Bingham
  3. * Copyright Stefano Sabatini <stefasab gmail com>
  4. * Copyright Vitor Sessak <vitor1001 gmail com>
  5. *
  6. * This file is part of FFmpeg.
  7. *
  8. * FFmpeg is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * FFmpeg is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with FFmpeg; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. #include <string.h>
  23. #include <stdio.h>
  24. #include "libavutil/avassert.h"
  25. #include "libavutil/buffer.h"
  26. #include "libavutil/imgutils.h"
  27. #include "libavutil/mem.h"
  28. #include "avfilter.h"
  29. #include "internal.h"
  30. #include "video.h"
  31. #define BUFFER_ALIGN 32
  32. AVFrame *ff_null_get_video_buffer(AVFilterLink *link, int w, int h)
  33. {
  34. return ff_get_video_buffer(link->dst->outputs[0], w, h);
  35. }
  36. AVFrame *ff_default_get_video_buffer(AVFilterLink *link, int w, int h)
  37. {
  38. int pool_width = 0;
  39. int pool_height = 0;
  40. int pool_align = 0;
  41. enum AVPixelFormat pool_format = AV_PIX_FMT_NONE;
  42. if (!link->video_frame_pool) {
  43. link->video_frame_pool = ff_video_frame_pool_init(av_buffer_allocz, w, h,
  44. link->format, BUFFER_ALIGN);
  45. if (!link->video_frame_pool)
  46. return NULL;
  47. } else {
  48. if (ff_video_frame_pool_get_config(link->video_frame_pool,
  49. &pool_width, &pool_height,
  50. &pool_format, &pool_align) < 0) {
  51. return NULL;
  52. }
  53. if (pool_width != w || pool_height != h ||
  54. pool_format != link->format || pool_align != BUFFER_ALIGN) {
  55. ff_video_frame_pool_uninit((FFVideoFramePool **)&link->video_frame_pool);
  56. link->video_frame_pool = ff_video_frame_pool_init(av_buffer_allocz, w, h,
  57. link->format, BUFFER_ALIGN);
  58. if (!link->video_frame_pool)
  59. return NULL;
  60. }
  61. }
  62. return ff_video_frame_pool_get(link->video_frame_pool);
  63. }
  64. AVFrame *ff_get_video_buffer(AVFilterLink *link, int w, int h)
  65. {
  66. AVFrame *ret = NULL;
  67. FF_TPRINTF_START(NULL, get_video_buffer); ff_tlog_link(NULL, link, 0);
  68. if (link->dstpad->get_video_buffer)
  69. ret = link->dstpad->get_video_buffer(link, w, h);
  70. if (!ret)
  71. ret = ff_default_get_video_buffer(link, w, h);
  72. return ret;
  73. }