Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "avfilter.h"
00023
00027 static void merge_ref(AVFilterFormats *ret, AVFilterFormats *a)
00028 {
00029 int i;
00030
00031 for(i = 0; i < a->refcount; i ++) {
00032 ret->refs[ret->refcount] = a->refs[i];
00033 *ret->refs[ret->refcount++] = ret;
00034 }
00035
00036 av_free(a->refs);
00037 av_free(a->formats);
00038 av_free(a);
00039 }
00040
00041 AVFilterFormats *avfilter_merge_formats(AVFilterFormats *a, AVFilterFormats *b)
00042 {
00043 AVFilterFormats *ret;
00044 unsigned i, j, k = 0;
00045
00046 if (a == b)
00047 return a;
00048
00049 if (a == b)
00050 return a;
00051
00052 ret = av_mallocz(sizeof(AVFilterFormats));
00053
00054
00055 ret->formats = av_malloc(sizeof(*ret->formats) * FFMIN(a->format_count,
00056 b->format_count));
00057 for(i = 0; i < a->format_count; i ++)
00058 for(j = 0; j < b->format_count; j ++)
00059 if(a->formats[i] == b->formats[j])
00060 ret->formats[k++] = a->formats[i];
00061
00062 ret->format_count = k;
00063
00064 if(!ret->format_count) {
00065 av_free(ret->formats);
00066 av_free(ret);
00067 return NULL;
00068 }
00069
00070 ret->refs = av_malloc(sizeof(AVFilterFormats**)*(a->refcount+b->refcount));
00071
00072 merge_ref(ret, a);
00073 merge_ref(ret, b);
00074
00075 return ret;
00076 }
00077
00078 AVFilterFormats *avfilter_make_format_list(int len, ...)
00079 {
00080 AVFilterFormats *ret;
00081 int i;
00082 va_list vl;
00083
00084 ret = av_mallocz(sizeof(AVFilterFormats));
00085 ret->formats = av_malloc(sizeof(*ret->formats) * len);
00086 ret->format_count = len;
00087
00088 va_start(vl, len);
00089 for(i = 0; i < len; i ++)
00090 ret->formats[i] = va_arg(vl, int);
00091 va_end(vl);
00092
00093 return ret;
00094 }
00095
00096 AVFilterFormats *avfilter_all_colorspaces(void)
00097 {
00098 AVFilterFormats *ret;
00099 int i;
00100
00101 ret = av_mallocz(sizeof(AVFilterFormats));
00102 ret->formats = av_malloc(sizeof(*ret->formats) * PIX_FMT_NB);
00103 ret->format_count = PIX_FMT_NB;
00104
00105 for(i = 0; i < PIX_FMT_NB; i ++)
00106 ret->formats[i] = i;
00107
00108 return ret;
00109 }
00110
00111 void avfilter_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
00112 {
00113 *ref = f;
00114 f->refs = av_realloc(f->refs, sizeof(AVFilterFormats**) * ++f->refcount);
00115 f->refs[f->refcount-1] = ref;
00116 }
00117
00118 static int find_ref_index(AVFilterFormats **ref)
00119 {
00120 int i;
00121 for(i = 0; i < (*ref)->refcount; i ++)
00122 if((*ref)->refs[i] == ref)
00123 return i;
00124 return -1;
00125 }
00126
00127 void avfilter_formats_unref(AVFilterFormats **ref)
00128 {
00129 int idx = find_ref_index(ref);
00130
00131 if(idx >= 0)
00132 memmove((*ref)->refs + idx, (*ref)->refs + idx+1,
00133 sizeof(AVFilterFormats**) * ((*ref)->refcount-idx-1));
00134
00135 if(!--(*ref)->refcount) {
00136 av_free((*ref)->formats);
00137 av_free((*ref)->refs);
00138 av_free(*ref);
00139 }
00140 *ref = NULL;
00141 }
00142
00143 void avfilter_formats_changeref(AVFilterFormats **oldref,
00144 AVFilterFormats **newref)
00145 {
00146 int idx = find_ref_index(oldref);
00147
00148 if(idx >= 0) {
00149 (*oldref)->refs[idx] = newref;
00150 *newref = *oldref;
00151 *oldref = NULL;
00152 }
00153 }
00154