網頁

2016年1月29日 星期五

VLC CLI snapshot command 程式追蹤

share/lua/modules/common.lua
function snapshot()
    local vout = vlc.object.vout()
    if not vout then return end
    vlc.var.set(vout,"video-snapshot",nil)
end

以下是啟動時建立物件
modules/lua/intf.c
static int Start_LuaIntf( vlc_object_t *p_this, const char *name )
-> luaopen_object( L );
-> luaopen_vlm( L );

modules/lua/libs/objects.c
static const luaL_Reg vlclua_object_reg[] = {
    { "input", vlclua_get_input },
    { "playlist", vlclua_get_playlist },
    { "libvlc", vlclua_get_libvlc },
    { "find", vlclua_object_find },
    { "vout", vlclua_get_vout},
    { "aout", vlclua_get_aout},
    { NULL, NULL }
};
void luaopen_object( lua_State *L )
{
    lua_newtable( L );
    luaL_register( L, NULL, vlclua_object_reg );
    lua_setfield( L, -2, "object" );
}

src/video_output/video_output.c
vout_thread_t *vout_Request(vlc_object_t *object, const vout_configuration_t *cfg)
-> VoutCreate(object, cfg);
static vout_thread_t *VoutCreate(vlc_object_t *object, const vout_configuration_t *cfg)
-> vout_IntfInit(vout);
在此宣告出 SnapshotCallback
void vout_IntfInit( vout_thread_t *p_vout )
-> var_Create( p_vout, "video-snapshot", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
-> var_Change( p_vout, "video-snapshot", VLC_VAR_SETTEXT, &text, NULL );
-> var_AddCallback( p_vout, "video-snapshot", SnapshotCallback, NULL );

以下是執行 snapshot 命令
./modules/lua/libs/variables.c
{ "trigger_callback", vlclua_trigger_callback },
{ "set", vlclua_var_set },
static int vlclua_var_set( lua_State *L )
-> var_Set( *pp_obj, psz_var, val );
static int vlclua_trigger_callback( lua_State *L )
-> var_TriggerCallback( *pp_obj, psz_var );

很多地方都使用 var_TriggerCallback 執行 snapshot
./lib/video.c
-> var_TriggerCallback( p_vout, "video-snapshot" );
./modules/control/oldrc.c
-> psz_variable = "video-snapshot";
-> var_TriggerCallback( p_vout, psz_variable );
./modules/control/hotkeys.c
-> case ACTIONID_SNAPSHOT:
-> var_TriggerCallback( p_vout, "video-snapshot" );

./src/misc/variables.c
var_TriggerCallback -> TriggerCallback
var_Set -> var_SetChecked -> TriggerCallback

src/video_output/vout_intf.c
static int SnapshotCallback( vlc_object_t *p_this, char const *psz_cmd, vlc_value_t oldval, vlc_value_t newval, void *p_data )
SnapshotCallback -> VoutSaveSnapshot -> vout_snapshot_SaveImage
SnapshotCallback -> VoutSaveSnapshot -> VoutOsdSnapshot
msg_Dbg( p_vout, "snapshot taken (%s)", psz_filename );


沒有留言:

張貼留言