31 #define MERGE_REF(ret, a, fmts, type, fail) \
36 if (!(tmp = av_realloc(ret->refs, \
37 sizeof(*tmp) * (ret->refcount + a->refcount)))) \
41 for (i = 0; i < a->refcount; i ++) { \
42 ret->refs[ret->refcount] = a->refs[i]; \
43 *ret->refs[ret->refcount++] = ret; \
55 #define MERGE_FORMATS(ret, a, b, fmts, nb, type, fail) \
57 int i, j, k = 0, count = FFMIN(a->nb, b->nb); \
59 if (!(ret = av_mallocz(sizeof(*ret)))) \
63 if (!(ret->fmts = av_malloc(sizeof(*ret->fmts) * count))) \
65 for (i = 0; i < a->nb; i++) \
66 for (j = 0; j < b->nb; j++) \
67 if (a->fmts[i] == b->fmts[j]) \
68 ret->fmts[k++] = a->fmts[i]; \
76 MERGE_REF(ret, a, fmts, type, fail); \
77 MERGE_REF(ret, b, fmts, type, fail); \
104 if (a == b)
return a;
131 if (a == b)
return a;
134 MERGE_FORMATS(ret, a, b, channel_layouts, nb_channel_layouts,
170 for (count = 0; fmts[count] != -1; count++)
177 memcpy(formats->
formats, fmts,
sizeof(*formats->
formats) * count);
182 #define ADD_FORMAT(f, fmt, type, list, nb) \
186 if (!(*f) && !(*f = av_mallocz(sizeof(**f)))) \
187 return AVERROR(ENOMEM); \
189 fmts = av_realloc((*f)->list, \
190 sizeof(*(*f)->list) * ((*f)->nb + 1));\
192 return AVERROR(ENOMEM); \
195 (*f)->list[(*f)->nb++] = fmt; \
206 ADD_FORMAT(l, channel_layout, uint64_t, channel_layouts, nb_channel_layouts);
216 for (fmt = 0; fmt < num_formats; fmt++) {
250 #define FORMATS_REF(f, ref) \
253 f->refs = av_realloc(f->refs, sizeof(*f->refs) * ++f->refcount); \
254 f->refs[f->refcount-1] = ref; \
267 #define FIND_REF_INDEX(ref, idx) \
270 for (i = 0; i < (*ref)->refcount; i ++) \
271 if((*ref)->refs[i] == ref) { \
277 #define FORMATS_UNREF(ref, list) \
284 FIND_REF_INDEX(ref, idx); \
287 memmove((*ref)->refs + idx, (*ref)->refs + idx + 1, \
288 sizeof(*(*ref)->refs) * ((*ref)->refcount - idx - 1)); \
290 if(!--(*ref)->refcount) { \
291 av_free((*ref)->list); \
292 av_free((*ref)->refs); \
308 #define FORMATS_CHANGEREF(oldref, newref) \
312 FIND_REF_INDEX(oldref, idx); \
315 (*oldref)->refs[idx] = newref; \
332 #define SET_COMMON_FORMATS(ctx, fmts, in_fmts, out_fmts, ref, list) \
336 for (i = 0; i < ctx->nb_inputs; i++) { \
337 if (ctx->inputs[i]) { \
338 ref(fmts, &ctx->inputs[i]->out_fmts); \
342 for (i = 0; i < ctx->nb_outputs; i++) { \
343 if (ctx->outputs[i]) { \
344 ref(fmts, &ctx->outputs[i]->in_fmts); \
350 av_freep(&fmts->list); \
351 av_freep(&fmts->refs); \