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.

158 lines
4.6KB

  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. AVFrame *ff_null_get_video_buffer(AVFilterLink *link, int w, int h)
  32. {
  33. return ff_get_video_buffer(link->dst->outputs[0], w, h);
  34. }
  35. /* TODO: set the buffer's priv member to a context structure for the whole
  36. * filter chain. This will allow for a buffer pool instead of the constant
  37. * alloc & free cycle currently implemented. */
  38. AVFrame *ff_default_get_video_buffer(AVFilterLink *link, int w, int h)
  39. {
  40. AVFrame *frame = av_frame_alloc();
  41. int ret;
  42. #if 0 //POOL
  43. AVFilterPool *pool = link->pool;
  44. if (pool) {
  45. for (i = 0; i < POOL_SIZE; i++) {
  46. picref = pool->pic[i];
  47. if (picref && picref->buf->format == link->format && picref->buf->w == w && picref->buf->h == h) {
  48. AVFilterBuffer *pic = picref->buf;
  49. pool->pic[i] = NULL;
  50. pool->count--;
  51. av_assert0(!picref->video->qp_table);
  52. picref->video->w = w;
  53. picref->video->h = h;
  54. picref->perms = full_perms;
  55. picref->format = link->format;
  56. pic->refcount = 1;
  57. memcpy(picref->data, pic->data, sizeof(picref->data));
  58. memcpy(picref->linesize, pic->linesize, sizeof(picref->linesize));
  59. pool->refcount++;
  60. return picref;
  61. }
  62. }
  63. } else {
  64. pool = link->pool = av_mallocz(sizeof(AVFilterPool));
  65. pool->refcount = 1;
  66. }
  67. #endif
  68. if (!frame)
  69. return NULL;
  70. frame->width = w;
  71. frame->height = h;
  72. frame->format = link->format;
  73. ret = av_frame_get_buffer(frame, 32);
  74. if (ret < 0)
  75. av_frame_free(&frame);
  76. #if 0 //POOL
  77. memset(data[0], 128, i);
  78. picref->buf->priv = pool;
  79. picref->buf->free = NULL;
  80. pool->refcount++;
  81. #endif
  82. return frame;
  83. }
  84. #if FF_API_AVFILTERBUFFER
  85. AVFilterBufferRef *
  86. avfilter_get_video_buffer_ref_from_arrays(uint8_t * const data[4], const int linesize[4], int perms,
  87. int w, int h, enum AVPixelFormat format)
  88. {
  89. AVFilterBuffer *pic = av_mallocz(sizeof(AVFilterBuffer));
  90. AVFilterBufferRef *picref = av_mallocz(sizeof(AVFilterBufferRef));
  91. if (!pic || !picref)
  92. goto fail;
  93. picref->buf = pic;
  94. picref->buf->free = ff_avfilter_default_free_buffer;
  95. if (!(picref->video = av_mallocz(sizeof(AVFilterBufferRefVideoProps))))
  96. goto fail;
  97. pic->w = picref->video->w = w;
  98. pic->h = picref->video->h = h;
  99. /* make sure the buffer gets read permission or it's useless for output */
  100. picref->perms = perms | AV_PERM_READ;
  101. pic->refcount = 1;
  102. picref->type = AVMEDIA_TYPE_VIDEO;
  103. pic->format = picref->format = format;
  104. memcpy(pic->data, data, 4*sizeof(data[0]));
  105. memcpy(pic->linesize, linesize, 4*sizeof(linesize[0]));
  106. memcpy(picref->data, pic->data, sizeof(picref->data));
  107. memcpy(picref->linesize, pic->linesize, sizeof(picref->linesize));
  108. pic-> extended_data = pic->data;
  109. picref->extended_data = picref->data;
  110. picref->pts = AV_NOPTS_VALUE;
  111. return picref;
  112. fail:
  113. if (picref && picref->video)
  114. av_free(picref->video);
  115. av_free(picref);
  116. av_free(pic);
  117. return NULL;
  118. }
  119. #endif
  120. AVFrame *ff_get_video_buffer(AVFilterLink *link, int w, int h)
  121. {
  122. AVFrame *ret = NULL;
  123. av_unused char buf[16];
  124. FF_TPRINTF_START(NULL, get_video_buffer); ff_tlog_link(NULL, link, 0);
  125. if (link->dstpad->get_video_buffer)
  126. ret = link->dstpad->get_video_buffer(link, w, h);
  127. if (!ret)
  128. ret = ff_default_get_video_buffer(link, w, h);
  129. return ret;
  130. }