View Full Version : How does get_frame() in x264 work?
stoneiii
14th June 2011, 06:31
In late version of x264, I find a new function
112 static int get_frame( hnd_t handle, cli_pic_t *output, int frame )
in cache.c.
But when I debug the x264 source codes, the function is not called.
and then when to call this function?
Moreover, there is another function with the same name
57 static int get_frame( hnd_t handle, cli_pic_t *output, int frame )
in source.c. This one is called by Encode() in x264.c.
How does the caller differentiate these two functions?
Thank you.
kypec
14th June 2011, 09:20
Huh? The examples you posted are two distinct functions,
release_frame and get_frame so I've no idea what are you talking about same names...
stoneiii
14th June 2011, 09:56
Huh? The examples you posted are two distinct functions,
release_frame and get_frame so I've no idea what are you talking about same names...
sorry, it's a mistake. I have corrected it now.
LoRd_MuldeR
14th June 2011, 11:31
As you can see, these functions are declared as "static". In this context the "static" keyword makes the function have "internal" linkage rather than "external" linkage.
This means that static functions are only "visible" within the current source file, but they cannot be called from another one.
Therefore you won't have any name conflicts, even if several static functions of the same name exist in different source files. The caller calls the one in "his" source file.
See also:
http://publications.gbdirect.co.uk/c_book/chapter4/linkage.html
kemuri-_9
14th June 2011, 13:14
As LoRd_MuldeR has already indicated, the functions are statically defined in each of the filter source files, this prevents naming conflicts against other source files that have functions with the same names.
with which you have noticed, each of the filter's source files usually use the same function names.
the functions are instead exposed externally as part of the cli_vid_filter_t definition at the end of each of the filter source file, e.g.
cache.c:
cli_vid_filter_t cache_filter = { NAME, NULL, init, get_frame, release_frame, free_filter, NULL };
source.c
cli_vid_filter_t source_filter = { "source", NULL, init, get_frame, release_frame, free_filter, NULL };
in source.c. This one is called by Encode() in x264.c.
How does the caller differentiate these two functions?
the function pointers to each separate function are stored in the cli_vid_filter_t that is being called from, so from a cli_vid_filter_t you will know which file's functions are being called.
so source's get_frame may not necessarily called by x264.c's Encode(), as it could be called by a get_frame() function in another filter instead...
vBulletin® v3.8.11, Copyright ©2000-2025, vBulletin Solutions Inc.