2 * Filter layer - format negotiation
3 * copyright (c) 2007 Bobby Bingham
5 * This file is part of FFmpeg.
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 * Add all refs from a to ret and destroy a.
27 static void merge_ref(AVFilterFormats
*ret
, AVFilterFormats
*a
)
31 for(i
= 0; i
< a
->refcount
; i
++) {
32 ret
->refs
[ret
->refcount
] = a
->refs
[i
];
33 *ret
->refs
[ret
->refcount
++] = ret
;
41 AVFilterFormats
*avfilter_merge_formats(AVFilterFormats
*a
, AVFilterFormats
*b
)
46 ret
= av_mallocz(sizeof(AVFilterFormats
));
48 /* merge list of formats */
49 ret
->formats
= av_malloc(sizeof(*ret
->formats
) * FFMIN(a
->format_count
,
51 for(i
= 0; i
< a
->format_count
; i
++)
52 for(j
= 0; j
< b
->format_count
; j
++)
53 if(a
->formats
[i
] == b
->formats
[j
])
54 ret
->formats
[k
++] = a
->formats
[i
];
56 ret
->format_count
= k
;
57 /* check that there was at least one common format */
58 if(!ret
->format_count
) {
59 av_free(ret
->formats
);
64 ret
->refs
= av_malloc(sizeof(AVFilterFormats
**)*(a
->refcount
+b
->refcount
));
72 AVFilterFormats
*avfilter_make_format_list(int len
, ...)
78 ret
= av_mallocz(sizeof(AVFilterFormats
));
79 ret
->formats
= av_malloc(sizeof(*ret
->formats
) * len
);
80 ret
->format_count
= len
;
83 for(i
= 0; i
< len
; i
++)
84 ret
->formats
[i
] = va_arg(vl
, int);
90 AVFilterFormats
*avfilter_all_colorspaces(void)
95 ret
= av_mallocz(sizeof(AVFilterFormats
));
96 ret
->formats
= av_malloc(sizeof(*ret
->formats
) * PIX_FMT_NB
);
97 ret
->format_count
= PIX_FMT_NB
;
99 for(i
= 0; i
< PIX_FMT_NB
; i
++)
105 void avfilter_formats_ref(AVFilterFormats
*f
, AVFilterFormats
**ref
)
108 f
->refs
= av_realloc(f
->refs
, sizeof(AVFilterFormats
**) * ++f
->refcount
);
109 f
->refs
[f
->refcount
-1] = ref
;
112 static int find_ref_index(AVFilterFormats
**ref
)
115 for(i
= 0; i
< (*ref
)->refcount
; i
++)
116 if((*ref
)->refs
[i
] == ref
)
121 void avfilter_formats_unref(AVFilterFormats
**ref
)
123 int idx
= find_ref_index(ref
);
126 memmove((*ref
)->refs
+ idx
, (*ref
)->refs
+ idx
+1,
127 sizeof(AVFilterFormats
**) * ((*ref
)->refcount
-idx
-1));
129 if(!--(*ref
)->refcount
) {
130 av_free((*ref
)->formats
);
131 av_free((*ref
)->refs
);
137 void avfilter_formats_changeref(AVFilterFormats
**oldref
,
138 AVFilterFormats
**newref
)
140 int idx
= find_ref_index(oldref
);
143 (*oldref
)->refs
[idx
] = newref
;