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 ret = av_mallocz(sizeof(AVFilterFormats));
00050
00051
00052 ret->formats = av_malloc(sizeof(*ret->formats) * FFMIN(a->format_count,
00053 b->format_count));
00054 for(i = 0; i < a->format_count; i ++)
00055 for(j = 0; j < b->format_count; j ++)
00056 if(a->formats[i] == b->formats[j])
00057 ret->formats[k++] = a->formats[i];
00058
00059 ret->format_count = k;
00060
00061 if(!ret->format_count) {
00062 av_free(ret->formats);
00063 av_free(ret);
00064 return NULL;
00065 }
00066
00067 ret->refs = av_malloc(sizeof(AVFilterFormats**)*(a->refcount+b->refcount));
00068
00069 merge_ref(ret, a);
00070 merge_ref(ret, b);
00071
00072 return ret;
00073 }
00074
00075 AVFilterFormats *avfilter_make_format_list(int len, ...)
00076 {
00077 AVFilterFormats *ret;
00078 int i;
00079 va_list vl;
00080
00081 ret = av_mallocz(sizeof(AVFilterFormats));
00082 ret->formats = av_malloc(sizeof(*ret->formats) * len);
00083 ret->format_count = len;
00084
00085 va_start(vl, len);
00086 for(i = 0; i < len; i ++)
00087 ret->formats[i] = va_arg(vl, int);
00088 va_end(vl);
00089
00090 return ret;
00091 }
00092
00093 AVFilterFormats *avfilter_all_colorspaces(void)
00094 {
00095 AVFilterFormats *ret;
00096 int i;
00097
00098 ret = av_mallocz(sizeof(AVFilterFormats));
00099 ret->formats = av_malloc(sizeof(*ret->formats) * PIX_FMT_NB);
00100 ret->format_count = PIX_FMT_NB;
00101
00102 for(i = 0; i < PIX_FMT_NB; i ++)
00103 ret->formats[i] = i;
00104
00105 return ret;
00106 }
00107
00108 void avfilter_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
00109 {
00110 *ref = f;
00111 f->refs = av_realloc(f->refs, sizeof(AVFilterFormats**) * ++f->refcount);
00112 f->refs[f->refcount-1] = ref;
00113 }
00114
00115 static int find_ref_index(AVFilterFormats **ref)
00116 {
00117 int i;
00118 for(i = 0; i < (*ref)->refcount; i ++)
00119 if((*ref)->refs[i] == ref)
00120 return i;
00121 return -1;
00122 }
00123
00124 void avfilter_formats_unref(AVFilterFormats **ref)
00125 {
00126 int idx = find_ref_index(ref);
00127
00128 if(idx >= 0)
00129 memmove((*ref)->refs + idx, (*ref)->refs + idx+1,
00130 sizeof(AVFilterFormats**) * ((*ref)->refcount-idx-1));
00131
00132 if(!--(*ref)->refcount) {
00133 av_free((*ref)->formats);
00134 av_free((*ref)->refs);
00135 av_free(*ref);
00136 }
00137 *ref = NULL;
00138 }
00139
00140 void avfilter_formats_changeref(AVFilterFormats **oldref,
00141 AVFilterFormats **newref)
00142 {
00143 int idx = find_ref_index(oldref);
00144
00145 if(idx >= 0) {
00146 (*oldref)->refs[idx] = newref;
00147 *newref = *oldref;
00148 *oldref = NULL;
00149 }
00150 }
00151