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.

151 lines
4.4KB

  1. /*
  2. * Filter layer - format negotiation
  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. AVFilterFormats *avfilter_merge_formats(AVFilterFormats *a, AVFilterFormats *b)
  23. {
  24. AVFilterFormats *ret;
  25. unsigned i, j, k = 0;
  26. ret = av_mallocz(sizeof(AVFilterFormats));
  27. /* merge list of formats */
  28. ret->formats = av_malloc(sizeof(*ret->formats) * FFMIN(a->format_count,
  29. b->format_count));
  30. for(i = 0; i < a->format_count; i ++)
  31. for(j = 0; j < b->format_count; j ++)
  32. if(a->formats[i] == b->formats[j])
  33. ret->formats[k++] = a->formats[i];
  34. /* check that there was at least one common format */
  35. if(!(ret->format_count = k)) {
  36. av_free(ret->formats);
  37. av_free(ret);
  38. return NULL;
  39. }
  40. /* merge and update all the references */
  41. ret->refs = av_malloc(sizeof(AVFilterFormats**)*(a->refcount+b->refcount));
  42. for(i = 0; i < a->refcount; i ++) {
  43. ret->refs[ret->refcount] = a->refs[i];
  44. *ret->refs[ret->refcount++] = ret;
  45. }
  46. for(i = 0; i < b->refcount; i ++) {
  47. ret->refs[ret->refcount] = b->refs[i];
  48. *ret->refs[ret->refcount++] = ret;
  49. }
  50. av_free(a->refs);
  51. av_free(a->formats);
  52. av_free(a);
  53. av_free(b->refs);
  54. av_free(b->formats);
  55. av_free(b);
  56. return ret;
  57. }
  58. AVFilterFormats *avfilter_make_format_list(int len, ...)
  59. {
  60. AVFilterFormats *ret;
  61. int i;
  62. va_list vl;
  63. ret = av_mallocz(sizeof(AVFilterFormats));
  64. ret->formats = av_malloc(sizeof(*ret->formats) * len);
  65. ret->format_count = len;
  66. va_start(vl, len);
  67. for(i = 0; i < len; i ++)
  68. ret->formats[i] = va_arg(vl, int);
  69. va_end(vl);
  70. return ret;
  71. }
  72. AVFilterFormats *avfilter_all_colorspaces(void)
  73. {
  74. return avfilter_make_format_list(35,
  75. PIX_FMT_YUV444P, PIX_FMT_YUV422P, PIX_FMT_YUV420P,
  76. PIX_FMT_YUV411P, PIX_FMT_YUV410P,
  77. PIX_FMT_YUYV422, PIX_FMT_UYVY422, PIX_FMT_UYYVYY411,
  78. PIX_FMT_YUVJ444P, PIX_FMT_YUVJ422P, PIX_FMT_YUVJ420P,
  79. PIX_FMT_YUV440P, PIX_FMT_YUVJ440P,
  80. PIX_FMT_RGB32, PIX_FMT_BGR32,
  81. PIX_FMT_RGB32_1, PIX_FMT_BGR32_1,
  82. PIX_FMT_RGB24, PIX_FMT_BGR24,
  83. PIX_FMT_RGB565, PIX_FMT_BGR565,
  84. PIX_FMT_RGB555, PIX_FMT_BGR555,
  85. PIX_FMT_RGB8, PIX_FMT_BGR8,
  86. PIX_FMT_RGB4_BYTE,PIX_FMT_BGR4_BYTE,
  87. PIX_FMT_GRAY16BE, PIX_FMT_GRAY16LE,
  88. PIX_FMT_GRAY8, PIX_FMT_PAL8,
  89. PIX_FMT_MONOWHITE,PIX_FMT_MONOBLACK,
  90. PIX_FMT_NV12, PIX_FMT_NV21);
  91. }
  92. void avfilter_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
  93. {
  94. *ref = f;
  95. f->refs = av_realloc(f->refs, sizeof(AVFilterFormats**) * ++f->refcount);
  96. f->refs[f->refcount-1] = ref;
  97. }
  98. static int find_ref_index(AVFilterFormats **ref)
  99. {
  100. int i;
  101. for(i = 0; i < (*ref)->refcount; i ++)
  102. if((*ref)->refs[i] == ref)
  103. return i;
  104. return -1;
  105. }
  106. void avfilter_formats_unref(AVFilterFormats **ref)
  107. {
  108. int idx;
  109. if((idx = find_ref_index(ref)) >= 0)
  110. memmove((*ref)->refs + idx, (*ref)->refs + idx+1,
  111. sizeof(AVFilterFormats**) * ((*ref)->refcount-idx-1));
  112. if(!--(*ref)->refcount) {
  113. av_free((*ref)->formats);
  114. av_free((*ref)->refs);
  115. av_free(*ref);
  116. }
  117. *ref = NULL;
  118. }
  119. void avfilter_formats_changeref(AVFilterFormats **oldref,
  120. AVFilterFormats **newref)
  121. {
  122. int idx;
  123. if((idx = find_ref_index(oldref)) >= 0) {
  124. (*oldref)->refs[idx] = newref;
  125. *newref = *oldref;
  126. *oldref = NULL;
  127. }
  128. }