34 #define MERGE_REF(ret, a, fmts, type, fail) \
39 if (!(tmp = av_realloc(ret->refs, \
40 sizeof(*tmp) * (ret->refcount + a->refcount)))) \
44 for (i = 0; i < a->refcount; i ++) { \
45 ret->refs[ret->refcount] = a->refs[i]; \
46 *ret->refs[ret->refcount++] = ret; \
58 #define MERGE_FORMATS(ret, a, b, fmts, nb, type, fail) \
60 int i, j, k = 0, count = FFMIN(a->nb, b->nb); \
62 if (!(ret = av_mallocz(sizeof(*ret)))) \
66 if (!(ret->fmts = av_malloc(sizeof(*ret->fmts) * count))) \
68 for (i = 0; i < a->nb; i++) \
69 for (j = 0; j < b->nb; j++) \
70 if (a->fmts[i] == b->fmts[j]) { \
71 if(k >= FFMIN(a->nb, b->nb)){ \
72 av_log(NULL, AV_LOG_ERROR, "Duplicate formats in avfilter_merge_formats() detected\n"); \
77 ret->fmts[k++] = a->fmts[i]; \
85 MERGE_REF(ret, a, fmts, type, fail); \
86 MERGE_REF(ret, b, fmts, type, fail); \
113 if (a == b)
return a;
140 if (a == b)
return a;
143 MERGE_FORMATS(ret, a, b, channel_layouts, nb_channel_layouts,
167 for (p = fmts; *p != -1; p++) {
174 #define COPY_INT_LIST(list_copy, list, type) { \
177 for (count = 0; list[count] != -1; count++) \
179 list_copy = av_calloc(count+1, sizeof(type)); \
181 memcpy(list_copy, list, sizeof(type) * count); \
182 list_copy[count] = -1; \
200 #define MAKE_FORMAT_LIST(type, field, count_field) \
204 for (count = 0; fmts[count] != -1; count++) \
206 formats = av_mallocz(sizeof(*formats)); \
207 if (!formats) return NULL; \
208 formats->count_field = count; \
210 formats->field = av_malloc(sizeof(*formats->field)*count); \
211 if (!formats->field) { \
221 formats->formats[count] = fmts[count];
229 channel_layouts, nb_channel_layouts);
231 memcpy(
formats->channel_layouts, fmts,
232 sizeof(*
formats->channel_layouts) * count);
237 #define ADD_FORMAT(f, fmt, type, list, nb) \
241 if (!(*f) && !(*f = av_mallocz(sizeof(**f)))) \
242 return AVERROR(ENOMEM); \
244 fmts = av_realloc((*f)->list, \
245 sizeof(*(*f)->list) * ((*f)->nb + 1));\
247 return AVERROR(ENOMEM); \
250 (*f)->list[(*f)->nb++] = fmt; \
261 ADD_FORMAT(l, channel_layout, uint64_t, channel_layouts, nb_channel_layouts);
271 for (fmt = 0; fmt < num_formats; fmt++) {
315 #define FORMATS_REF(f, ref) \
318 f->refs = av_realloc(f->refs, sizeof(*f->refs) * ++f->refcount); \
319 f->refs[f->refcount-1] = ref; \
332 #define FIND_REF_INDEX(ref, idx) \
335 for (i = 0; i < (*ref)->refcount; i ++) \
336 if((*ref)->refs[i] == ref) { \
342 #define FORMATS_UNREF(ref, list) \
349 FIND_REF_INDEX(ref, idx); \
352 memmove((*ref)->refs + idx, (*ref)->refs + idx + 1, \
353 sizeof(*(*ref)->refs) * ((*ref)->refcount - idx - 1)); \
355 if(!--(*ref)->refcount) { \
356 av_free((*ref)->list); \
357 av_free((*ref)->refs); \
373 #define FORMATS_CHANGEREF(oldref, newref) \
377 FIND_REF_INDEX(oldref, idx); \
380 (*oldref)->refs[idx] = newref; \
397 #define SET_COMMON_FORMATS(ctx, fmts, in_fmts, out_fmts, ref, list) \
401 for (i = 0; i < ctx->nb_inputs; i++) { \
402 if (ctx->inputs[i] && !ctx->inputs[i]->out_fmts) { \
403 ref(fmts, &ctx->inputs[i]->out_fmts); \
407 for (i = 0; i < ctx->nb_outputs; i++) { \
408 if (ctx->outputs[i] && !ctx->outputs[i]->in_fmts) { \
409 ref(fmts, &ctx->outputs[i]->in_fmts); \
415 av_freep(&fmts->list); \
416 av_freep(&fmts->refs); \
468 pix_fmt = strtol(arg, &tail, 0);
483 sfmt = strtol(arg, &tail, 0);
508 if (*tail || srate < 1 || (
int)srate != srate || srate > INT_MAX) {
521 chlayout = strtol(arg, &tail, 10);
522 if (*tail || chlayout == 0) {