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.

113 lines
3.3KB

  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/hwcontext.h"
  27. #include "libavutil/imgutils.h"
  28. #include "libavutil/mem.h"
  29. #include "avfilter.h"
  30. #include "internal.h"
  31. #include "video.h"
  32. #define BUFFER_ALIGN 32
  33. AVFrame *ff_null_get_video_buffer(AVFilterLink *link, int w, int h)
  34. {
  35. return ff_get_video_buffer(link->dst->outputs[0], w, h);
  36. }
  37. AVFrame *ff_default_get_video_buffer(AVFilterLink *link, int w, int h)
  38. {
  39. AVFrame *frame = NULL;
  40. int pool_width = 0;
  41. int pool_height = 0;
  42. int pool_align = 0;
  43. enum AVPixelFormat pool_format = AV_PIX_FMT_NONE;
  44. if (link->hw_frames_ctx &&
  45. ((AVHWFramesContext*)link->hw_frames_ctx->data)->format == link->format) {
  46. int ret;
  47. AVFrame *frame = av_frame_alloc();
  48. if (!frame)
  49. return NULL;
  50. ret = av_hwframe_get_buffer(link->hw_frames_ctx, frame, 0);
  51. if (ret < 0)
  52. av_frame_free(&frame);
  53. return frame;
  54. }
  55. if (!link->frame_pool) {
  56. link->frame_pool = ff_frame_pool_video_init(av_buffer_allocz, w, h,
  57. link->format, BUFFER_ALIGN);
  58. if (!link->frame_pool)
  59. return NULL;
  60. } else {
  61. if (ff_frame_pool_get_video_config(link->frame_pool,
  62. &pool_width, &pool_height,
  63. &pool_format, &pool_align) < 0) {
  64. return NULL;
  65. }
  66. if (pool_width != w || pool_height != h ||
  67. pool_format != link->format || pool_align != BUFFER_ALIGN) {
  68. ff_frame_pool_uninit((FFFramePool **)&link->frame_pool);
  69. link->frame_pool = ff_frame_pool_video_init(av_buffer_allocz, w, h,
  70. link->format, BUFFER_ALIGN);
  71. if (!link->frame_pool)
  72. return NULL;
  73. }
  74. }
  75. frame = ff_frame_pool_get(link->frame_pool);
  76. if (!frame)
  77. return NULL;
  78. frame->sample_aspect_ratio = link->sample_aspect_ratio;
  79. return frame;
  80. }
  81. AVFrame *ff_get_video_buffer(AVFilterLink *link, int w, int h)
  82. {
  83. AVFrame *ret = NULL;
  84. FF_TPRINTF_START(NULL, get_video_buffer); ff_tlog_link(NULL, link, 0);
  85. if (link->dstpad->get_video_buffer)
  86. ret = link->dstpad->get_video_buffer(link, w, h);
  87. if (!ret)
  88. ret = ff_default_get_video_buffer(link, w, h);
  89. return ret;
  90. }