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