mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2024-12-27 18:02:11 +00:00
avfilter/formats: Avoid code duplication when merging samplerates
Right now, ff_merge_samplerates() contains three instances of the MERGE_REF() macro, a macro which reallocates an array, updates some pointers in a loop and frees several buffers. This commit makes it possible to contain only one instance of said macro in the function, thereby reducing codesize. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
This commit is contained in:
parent
621e2625e0
commit
363f93460f
@ -56,11 +56,21 @@ do { \
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Add all formats common to a and b to a, add b's refs to a and destroy b.
|
* Add all formats common to a and b to a, add b's refs to a and destroy b.
|
||||||
|
* If empty_allowed is set and one of a,b->nb is zero, the lists are
|
||||||
|
* merged; otherwise, it is treated as error.
|
||||||
*/
|
*/
|
||||||
#define MERGE_FORMATS(a, b, fmts, nb, type, fail_statement) \
|
#define MERGE_FORMATS(a, b, fmts, nb, type, fail_statement, empty_allowed) \
|
||||||
do { \
|
do { \
|
||||||
int i, j, k = 0; \
|
int i, j, k = 0, skip = 0; \
|
||||||
\
|
\
|
||||||
|
if (empty_allowed) { \
|
||||||
|
if (!a->nb || !b->nb) { \
|
||||||
|
if (!a->nb) \
|
||||||
|
FFSWAP(type *, a, b); \
|
||||||
|
skip = 1; \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
if (!skip) { \
|
||||||
for (i = 0; i < a->nb; i++) \
|
for (i = 0; i < a->nb; i++) \
|
||||||
for (j = 0; j < b->nb; j++) \
|
for (j = 0; j < b->nb; j++) \
|
||||||
if (a->fmts[i] == b->fmts[j]) { \
|
if (a->fmts[i] == b->fmts[j]) { \
|
||||||
@ -72,7 +82,8 @@ do {
|
|||||||
if (!k) \
|
if (!k) \
|
||||||
{ fail_statement } \
|
{ fail_statement } \
|
||||||
a->nb = k; \
|
a->nb = k; \
|
||||||
\
|
} \
|
||||||
|
\
|
||||||
MERGE_REF(a, b, fmts, type, fail_statement); \
|
MERGE_REF(a, b, fmts, type, fail_statement); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
@ -110,7 +121,7 @@ AVFilterFormats *ff_merge_formats(AVFilterFormats *a, AVFilterFormats *b,
|
|||||||
if (alpha2 > alpha1 || chroma2 > chroma1)
|
if (alpha2 > alpha1 || chroma2 > chroma1)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
MERGE_FORMATS(a, b, formats, nb_formats, AVFilterFormats, return NULL;);
|
MERGE_FORMATS(a, b, formats, nb_formats, AVFilterFormats, return NULL;, 0);
|
||||||
|
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
@ -120,16 +131,8 @@ AVFilterFormats *ff_merge_samplerates(AVFilterFormats *a,
|
|||||||
{
|
{
|
||||||
if (a == b) return a;
|
if (a == b) return a;
|
||||||
|
|
||||||
if (a->nb_formats && b->nb_formats) {
|
MERGE_FORMATS(a, b, formats, nb_formats, AVFilterFormats, return NULL;, 1);
|
||||||
MERGE_FORMATS(a, b, formats, nb_formats, AVFilterFormats, return NULL;);
|
return a;
|
||||||
return a;
|
|
||||||
} else if (a->nb_formats) {
|
|
||||||
MERGE_REF(a, b, formats, AVFilterFormats, return NULL;);
|
|
||||||
return a;
|
|
||||||
} else {
|
|
||||||
MERGE_REF(b, a, formats, AVFilterFormats, return NULL;);
|
|
||||||
return b;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AVFilterChannelLayouts *ff_merge_channel_layouts(AVFilterChannelLayouts *a,
|
AVFilterChannelLayouts *ff_merge_channel_layouts(AVFilterChannelLayouts *a,
|
||||||
|
Loading…
Reference in New Issue
Block a user