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.

119 lines
3.7KB

  1. /*
  2. * Filter layer - default implementations
  3. * copyright (c) 2007 Bobby Bingham
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include "avfilter.h"
  22. /* TODO: buffer pool. see comment for avfilter_default_get_video_buffer() */
  23. void avfilter_default_free_video_buffer(AVFilterPic *pic)
  24. {
  25. avpicture_free((AVPicture *) pic);
  26. av_free(pic);
  27. }
  28. /* TODO: set the buffer's priv member to a context structure for the whole
  29. * filter chain. This will allow for a buffer pool instead of the constant
  30. * alloc & free cycle currently implemented. */
  31. AVFilterPicRef *avfilter_default_get_video_buffer(AVFilterLink *link, int perms)
  32. {
  33. AVFilterPic *pic = av_mallocz(sizeof(AVFilterPic));
  34. AVFilterPicRef *ref = av_mallocz(sizeof(AVFilterPicRef));
  35. ref->pic = pic;
  36. ref->w = link->w;
  37. ref->h = link->h;
  38. ref->perms = perms;
  39. pic->refcount = 1;
  40. pic->format = link->format;
  41. pic->free = avfilter_default_free_video_buffer;
  42. avpicture_alloc((AVPicture *)pic, pic->format, ref->w, ref->h);
  43. memcpy(ref->data, pic->data, sizeof(pic->data));
  44. memcpy(ref->linesize, pic->linesize, sizeof(pic->linesize));
  45. return ref;
  46. }
  47. void avfilter_default_start_frame(AVFilterLink *link, AVFilterPicRef *picref)
  48. {
  49. AVFilterLink *out = NULL;
  50. if(link->dst->output_count)
  51. out = link->dst->outputs[0];
  52. link->cur_pic = picref;
  53. if(out) {
  54. out->outpic = avfilter_get_video_buffer(out, AV_PERM_WRITE);
  55. out->outpic->pts = picref->pts;
  56. avfilter_start_frame(out, avfilter_ref_pic(out->outpic, ~0));
  57. }
  58. }
  59. void avfilter_default_end_frame(AVFilterLink *link)
  60. {
  61. AVFilterLink *out = NULL;
  62. if(link->dst->output_count)
  63. out = link->dst->outputs[0];
  64. avfilter_unref_pic(link->cur_pic);
  65. link->cur_pic = NULL;
  66. if(out) {
  67. avfilter_unref_pic(out->outpic);
  68. out->outpic = NULL;
  69. avfilter_end_frame(out);
  70. }
  71. }
  72. /**
  73. * default config_link() implementation for output video links to simplify
  74. * the implementation of one input one output video filters */
  75. int avfilter_default_config_output_link(AVFilterLink *link)
  76. {
  77. if(link->src->input_count && link->src->inputs[0]) {
  78. link->w = link->src->inputs[0]->w;
  79. link->h = link->src->inputs[0]->h;
  80. } else {
  81. /* XXX: any non-simple filter which would cause this branch to be taken
  82. * really should implement its own config_props() for this link. */
  83. link->w =
  84. link->h = 0;
  85. }
  86. return 0;
  87. }
  88. /**
  89. * default query_formats() implementation for output video links to simplify
  90. * the implementation of one input one output video filters */
  91. int *avfilter_default_query_output_formats(AVFilterLink *link)
  92. {
  93. if(link->src->input_count && link->src->inputs[0])
  94. return avfilter_make_format_list(1, link->src->inputs[0]->format);
  95. else
  96. /* XXX: any non-simple filter which would cause this branch to be taken
  97. * really should implement its own query_formats() for this link */
  98. return avfilter_make_format_list(0);
  99. }