22 #include "libavutil/avassert.h"
23 #include "libavutil/channel_layout.h"
24 #include "libavutil/common.h"
25 #include "libavutil/eval.h"
26 #include "libavutil/pixdesc.h"
27 #include "libavutil/parseutils.h"
32 #define KNOWN(l) (!FF_LAYOUT2COUNT(l))
37 #define MERGE_REF(ret, a, fmts, type, fail) \
42 if (!(tmp = av_realloc(ret->refs, \
43 sizeof(*tmp) * (ret->refcount + a->refcount)))) \
47 for (i = 0; i < a->refcount; i ++) { \
48 ret->refs[ret->refcount] = a->refs[i]; \
49 *ret->refs[ret->refcount++] = ret; \
61 #define MERGE_FORMATS(ret, a, b, fmts, nb, type, fail) \
63 int i, j, k = 0, count = FFMIN(a->nb, b->nb); \
65 if (!(ret = av_mallocz(sizeof(*ret)))) \
69 if (!(ret->fmts = av_malloc(sizeof(*ret->fmts) * count))) \
71 for (i = 0; i < a->nb; i++) \
72 for (j = 0; j < b->nb; j++) \
73 if (a->fmts[i] == b->fmts[j]) { \
74 if(k >= FFMIN(a->nb, b->nb)){ \
75 av_log(NULL, AV_LOG_ERROR, "Duplicate formats in avfilter_merge_formats() detected\n"); \
80 ret->fmts[k++] = a->fmts[i]; \
88 MERGE_REF(ret, a, fmts, type, fail); \
89 MERGE_REF(ret, b, fmts, type, fail); \
97 int alpha1=0, alpha2=0;
98 int chroma1=0, chroma2=0;
124 if (alpha2 > alpha1 || chroma2 > chroma1)
144 if (a == b)
return a;
172 int ret_max, ret_nb = 0, i, j,
round;
174 if (a == b)
return a;
179 FFSWAP(
unsigned, a_all, b_all);
182 if (a_all == 1 && !b_all) {
216 for (round = 0; round < 2; round++) {
219 if (!fmt || !
KNOWN(fmt))
258 for (p = fmts; *p != -1; p++) {
265 #define COPY_INT_LIST(list_copy, list, type) { \
268 for (count = 0; list[count] != -1; count++) \
270 list_copy = av_calloc(count+1, sizeof(type)); \
272 memcpy(list_copy, list, sizeof(type) * count); \
273 list_copy[count] = -1; \
277 #define MAKE_FORMAT_LIST(type, field, count_field) \
281 for (count = 0; fmts[count] != -1; count++) \
283 formats = av_mallocz(sizeof(*formats)); \
284 if (!formats) return NULL; \
285 formats->count_field = count; \
287 formats->field = av_malloc(sizeof(*formats->field)*count); \
288 if (!formats->field) { \
306 channel_layouts, nb_channel_layouts);
308 memcpy(
formats->channel_layouts, fmts,
314 #define ADD_FORMAT(f, fmt, type, list, nb) \
318 if (!(*f) && !(*f = av_mallocz(sizeof(**f)))) \
319 return AVERROR(ENOMEM); \
321 fmts = av_realloc((*f)->list, \
322 sizeof(*(*f)->list) * ((*f)->nb + 1));\
324 return AVERROR(ENOMEM); \
327 (*f)->list[(*f)->nb++] = fmt; \
339 ADD_FORMAT(l, channel_layout, uint64_t, channel_layouts, nb_channel_layouts);
350 for (fmt = 0; fmt < num_formats; fmt++) {
406 #define FORMATS_REF(f, ref) \
409 f->refs = av_realloc(f->refs, sizeof(*f->refs) * ++f->refcount); \
410 f->refs[f->refcount-1] = ref; \
423 #define FIND_REF_INDEX(ref, idx) \
426 for (i = 0; i < (*ref)->refcount; i ++) \
427 if((*ref)->refs[i] == ref) { \
433 #define FORMATS_UNREF(ref, list) \
440 FIND_REF_INDEX(ref, idx); \
443 memmove((*ref)->refs + idx, (*ref)->refs + idx + 1, \
444 sizeof(*(*ref)->refs) * ((*ref)->refcount - idx - 1)); \
446 if(!--(*ref)->refcount) { \
447 av_free((*ref)->list); \
448 av_free((*ref)->refs); \
464 #define FORMATS_CHANGEREF(oldref, newref) \
468 FIND_REF_INDEX(oldref, idx); \
471 (*oldref)->refs[idx] = newref; \
488 #define SET_COMMON_FORMATS(ctx, fmts, in_fmts, out_fmts, ref, list) \
492 for (i = 0; i < ctx->nb_inputs; i++) { \
493 if (ctx->inputs[i] && !ctx->inputs[i]->out_fmts) { \
494 ref(fmts, &ctx->inputs[i]->out_fmts); \
498 for (i = 0; i < ctx->nb_outputs; i++) { \
499 if (ctx->outputs[i] && !ctx->outputs[i]->in_fmts) { \
500 ref(fmts, &ctx->outputs[i]->in_fmts); \
506 av_freep(&fmts->list); \
507 av_freep(&fmts->refs); \
570 pix_fmt = strtol(arg, &tail, 0);
585 sfmt = strtol(arg, &tail, 0);
610 if (*tail || srate < 1 || (
int)srate != srate || srate > INT_MAX) {
623 chlayout = strtol(arg, &tail, 10);
624 if (*tail || chlayout == 0) {
Number of sample formats. DO NOT USE if linking dynamically.
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
static enum AVSampleFormat formats[]
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
struct AVFilterChannelLayouts *** refs
references to this list
void av_freep(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
enum AVSampleFormat av_get_sample_fmt(const char *name)
Return a sample format corresponding to name, or AV_SAMPLE_FMT_NONE on error.
enum AVPixelFormat pix_fmt
double av_strtod(const char *numstr, char **tail)
Parse the string in numstr and return its value as a double.
#define FFSWAP(type, a, b)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
uint64_t * channel_layouts
list of channel layouts
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
Return the number of channels in the channel layout.
static av_always_inline av_const double round(double x)
AVPixelFormat
Pixel format.
char all_counts
accept any channel layout or count
int av_parse_ratio(AVRational *q, const char *str, int max, int log_offset, void *log_ctx)
Parse str and store the parsed ratio in q.
uint8_t nb_components
The number of components each pixel has, (1-4)
void * av_malloc(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
A list of supported channel layouts.
Main libavfilter public API header.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
AVFilterLink ** outputs
array of pointers to output links
#define AV_PIX_FMT_FLAG_HWACCEL
Pixel format is an HW accelerated format.
char all_layouts
accept any known channel layout
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
AVFilterLink ** inputs
array of pointers to input links
rational number numerator/denominator
enum MovChannelLayoutTag * layouts
number of pixel formats, DO NOT USE THIS if you want to link with shared libav* because the number of...
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
enum AVMediaType type
filter media type
int nb_channel_layouts
number of channel layouts
int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt)
Check if the sample format is planar.
uint64_t av_get_channel_layout(const char *name)
Return a channel layout id that matches name, or 0 if no match is found.
int main(int argc, char **argv)
#define AV_PIX_FMT_FLAG_ALPHA
The pixel format has an alpha channel.
void * av_mallocz(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
void av_get_channel_layout_string(char *buf, int buf_size, int nb_channels, uint64_t channel_layout)
Return a description of a channel layout.