//var callback注册流程 /***************************************************************************** * This function creates a new input, and returns a pointer * to its description. On error, it returns NULL. * * XXX Do not forget to update vlc_input.h if you add new variables. *****************************************************************************/ static input_thread_t *Create( vlc_object_t *p_parent, input_item_t *p_item, const char *psz_header, bool b_preparsing, input_resource_t *p_resource, vlc_renderer_item_t *p_renderer ) {
...... //这里的var是vlc内部用的,建议不要set /* Create Object Variables for private use only */ input_ConfigVarInit( p_input ); //这些var是公开的,可以get和set,time变量就是在这里创建并注册的回调函数 /* Create Objects variables for public Get and Set */ input_ControlVarInit( p_input ); ...... } /***************************************************************************** * input_ControlVarInit: * Create all control object variables with their callbacks *****************************************************************************/ void input_ControlVarInit ( input_thread_t *p_input ) {
...... //创建time var /* Time */ var_Create( p_input, "time" , VLC_VAR_INTEGER ); ...... //注册回调函数,var一旦改变就会调用 /* Add all callbacks * XXX we put callback only in non preparsing mode. We need to create the variable * unless someone want to check all var_Get/var_Change return value ... */ if ( !input_priv(p_input)->b_preparsing ) InputAddCallbacks( p_input, p_input_callbacks ); } /***************************************************************************** * Callbacks managements: *****************************************************************************/ static void InputAddCallbacks( input_thread_t *p_input, const vlc_input_callback_t *p_callbacks ) {
int i; for ( i = 0 ; p_callbacks[i].psz_name != NULL; i++ ) var_AddCallback( p_input, p_callbacks[i].psz_name, p_callbacks[i].callback, NULL ); } //input添加的全部回调如下 /* List all callbacks added by input */ #define CALLBACK(name,cb) { name, cb } static const vlc_input_callback_t p_input_callbacks[] = {
CALLBACK( "state" , StateCallback ), CALLBACK( "rate" , RateCallback ), CALLBACK( "position" , PositionCallback ), CALLBACK( "time" , TimeCallback ), CALLBACK( "time-offset" , TimeOffsetCallback ), CALLBACK( "bookmark" , BookmarkCallback ), CALLBACK( "program" , ProgramCallback ), CALLBACK( "title" , TitleCallback ), CALLBACK( "chapter" , SeekpointCallback ), CALLBACK( "audio-delay" , EsDelayCallback ), CALLBACK( "spu-delay" , EsDelayCallback ), CALLBACK( "video-es" , EsVideoCallback ), CALLBACK( "audio-es" , EsAudioCallback ), CALLBACK( "spu-es" , EsSpuCallback ), CALLBACK( "record" , RecordCallback ), CALLBACK( "frame-next" , FrameNextCallback ), CALLBACK( NULL, NULL ) }; |