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 "libavutil/pixdesc.h"
00023 #include "avfilter.h"
00024 #include "internal.h"
00025
00029 static void merge_ref(AVFilterFormats *ret, AVFilterFormats *a)
00030 {
00031 int i;
00032
00033 for(i = 0; i < a->refcount; i ++) {
00034 ret->refs[ret->refcount] = a->refs[i];
00035 *ret->refs[ret->refcount++] = ret;
00036 }
00037
00038 av_free(a->refs);
00039 av_free(a->formats);
00040 av_free(a);
00041 }
00042
00043 AVFilterFormats *avfilter_merge_formats(AVFilterFormats *a, AVFilterFormats *b)
00044 {
00045 AVFilterFormats *ret;
00046 unsigned i, j, k = 0, m_count;
00047
00048 ret = av_mallocz(sizeof(AVFilterFormats));
00049
00050
00051 m_count = FFMIN(a->format_count, b->format_count);
00052 if (m_count) {
00053 ret->formats = av_malloc(sizeof(*ret->formats) * m_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
00062 if(!ret->format_count) {
00063 av_free(ret->formats);
00064 av_free(ret);
00065 return NULL;
00066 }
00067
00068 ret->refs = av_malloc(sizeof(AVFilterFormats**)*(a->refcount+b->refcount));
00069
00070 merge_ref(ret, a);
00071 merge_ref(ret, b);
00072
00073 return ret;
00074 }
00075
00076 int ff_fmt_is_in(int fmt, const int *fmts)
00077 {
00078 const int *p;
00079
00080 for (p = fmts; *p != PIX_FMT_NONE; p++) {
00081 if (fmt == *p)
00082 return 1;
00083 }
00084 return 0;
00085 }
00086
00087 AVFilterFormats *avfilter_make_format_list(const int *fmts)
00088 {
00089 AVFilterFormats *formats;
00090 int count;
00091
00092 for (count = 0; fmts[count] != -1; count++)
00093 ;
00094
00095 formats = av_mallocz(sizeof(AVFilterFormats));
00096 if (count)
00097 formats->formats = av_malloc(sizeof(*formats->formats) * count);
00098 formats->format_count = count;
00099 memcpy(formats->formats, fmts, sizeof(*formats->formats) * count);
00100
00101 return formats;
00102 }
00103
00104 int avfilter_add_format(AVFilterFormats **avff, int fmt)
00105 {
00106 int *fmts;
00107
00108 if (!(*avff) && !(*avff = av_mallocz(sizeof(AVFilterFormats))))
00109 return AVERROR(ENOMEM);
00110
00111 fmts = av_realloc((*avff)->formats,
00112 sizeof(*(*avff)->formats) * ((*avff)->format_count+1));
00113 if (!fmts)
00114 return AVERROR(ENOMEM);
00115
00116 (*avff)->formats = fmts;
00117 (*avff)->formats[(*avff)->format_count++] = fmt;
00118 return 0;
00119 }
00120
00121 AVFilterFormats *avfilter_all_formats(enum AVMediaType type)
00122 {
00123 AVFilterFormats *ret = NULL;
00124 int fmt;
00125 int num_formats = type == AVMEDIA_TYPE_VIDEO ? PIX_FMT_NB :
00126 type == AVMEDIA_TYPE_AUDIO ? AV_SAMPLE_FMT_NB : 0;
00127
00128 for (fmt = 0; fmt < num_formats; fmt++)
00129 if ((type != AVMEDIA_TYPE_VIDEO) ||
00130 (type == AVMEDIA_TYPE_VIDEO && !(av_pix_fmt_descriptors[fmt].flags & PIX_FMT_HWACCEL)))
00131 avfilter_add_format(&ret, fmt);
00132
00133 return ret;
00134 }
00135
00136 void avfilter_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
00137 {
00138 *ref = f;
00139 f->refs = av_realloc(f->refs, sizeof(AVFilterFormats**) * ++f->refcount);
00140 f->refs[f->refcount-1] = ref;
00141 }
00142
00143 static int find_ref_index(AVFilterFormats **ref)
00144 {
00145 int i;
00146 for(i = 0; i < (*ref)->refcount; i ++)
00147 if((*ref)->refs[i] == ref)
00148 return i;
00149 return -1;
00150 }
00151
00152 void avfilter_formats_unref(AVFilterFormats **ref)
00153 {
00154 int idx;
00155
00156 if (!*ref)
00157 return;
00158
00159 idx = find_ref_index(ref);
00160
00161 if(idx >= 0)
00162 memmove((*ref)->refs + idx, (*ref)->refs + idx+1,
00163 sizeof(AVFilterFormats**) * ((*ref)->refcount-idx-1));
00164
00165 if(!--(*ref)->refcount) {
00166 av_free((*ref)->formats);
00167 av_free((*ref)->refs);
00168 av_free(*ref);
00169 }
00170 *ref = NULL;
00171 }
00172
00173 void avfilter_formats_changeref(AVFilterFormats **oldref,
00174 AVFilterFormats **newref)
00175 {
00176 int idx = find_ref_index(oldref);
00177
00178 if(idx >= 0) {
00179 (*oldref)->refs[idx] = newref;
00180 *newref = *oldref;
00181 *oldref = NULL;
00182 }
00183 }
00184