Reputation: 180
I am to port h264
codec in an embedded device. The ffmpeg source code uses the following construction:
#undef CHROMA_IDC
#define CHROMA_IDC 3
#include "h264_mc_template.c"
static av_noinline void FUNC(hl_decode_mb_444)(const H264Context *h, H264SliceContext *sl)
{
...
}
Why do I need to include such a source file? Isn't that used only for the header?
Upvotes: 2
Views: 89
Reputation: 140196
the "template" suffix hints at the fact that the code depends on some preprocessor directives.
I checked the source and at the beginning there's
#if CHROMA_IDC == 1
# define MCFUNC(n) FUNC(n ## _420)
#elif CHROMA_IDC == 2
# define MCFUNC(n) FUNC(n ## _422)
#elif CHROMA_IDC == 3
# define MCFUNC(n) FUNC(n ## _444)
#endif
note that you have #define CHROMA_IDC 3
before including this file.
This tells the preprocessor to use define MCFUNC(n) FUNC(n ## _444)
in the included file.
the source could have been left alone in the makefile but with a -DCHROMA_IDC=3
directive, and in that case, the template cannot be reused for other source files because of multiple redefinition (the functions in this source file are static
to avoid multiple redefinition if the template is instanciated more than once)
Why using a template? probably for performance issues, to avoid a call chain and some tests to branch on the required behaviour. ffmpeg
cannot afford to be slow on the encoding functions.
Upvotes: 4