1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2007-2008 the VideoLAN team
7 * Authors: Antoine Cellerier <dionoea at videolan tod org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
35 #include <vlc_common.h>
37 #include <vlc_charset.h>
39 #include <vlc_playlist.h>
41 #include <lua.h> /* Low level lua C API */
42 #include <lauxlib.h> /* Higher level C API */
49 input_thread_t * vlclua_get_input_internal( lua_State *L )
51 playlist_t *p_playlist = vlclua_get_playlist_internal( L );
52 input_thread_t *p_input = p_playlist->p_input;
53 if( p_input ) vlc_object_yield( p_input );
54 pl_Release( p_playlist );
58 static int vlclua_input_info( lua_State *L )
60 input_thread_t * p_input = vlclua_get_input_internal( L );
63 if( !p_input ) return vlclua_error( L );
64 //vlc_mutex_lock( &input_GetItem(p_input)->lock );
65 i_cat = input_GetItem(p_input)->i_categories;
66 lua_createtable( L, 0, i_cat );
67 for( i = 0; i < i_cat; i++ )
69 info_category_t *p_category = input_GetItem(p_input)->pp_categories[i];
70 int i_infos = p_category->i_infos;
72 lua_pushstring( L, p_category->psz_name );
73 lua_createtable( L, 0, i_infos );
74 for( j = 0; j < i_infos; j++ )
76 info_t *p_info = p_category->pp_infos[j];
77 lua_pushstring( L, p_info->psz_name );
78 lua_pushstring( L, p_info->psz_value );
79 lua_settable( L, -3 );
81 lua_settable( L, -3 );
83 //vlc_object_release( p_input );
87 static int vlclua_is_playing( lua_State *L )
89 input_thread_t * p_input = vlclua_get_input_internal( L );
90 lua_pushboolean( L, !!p_input );
94 static int vlclua_get_title( lua_State *L )
96 input_thread_t *p_input = vlclua_get_input_internal( L );
101 lua_pushstring( L, input_GetItem(p_input)->psz_name );
102 vlc_object_release( p_input );
107 static int vlclua_input_stats( lua_State *L )
109 input_thread_t *p_input = vlclua_get_input_internal( L );
110 input_item_t *p_item = p_input && p_input->p ? input_GetItem( p_input ) : NULL;
114 #define STATS_INT( n ) lua_pushinteger( L, p_item->p_stats->i_ ## n ); \
115 lua_setfield( L, -2, #n );
116 #define STATS_FLOAT( n ) lua_pushnumber( L, p_item->p_stats->f_ ## n ); \
117 lua_setfield( L, -2, #n );
118 STATS_INT( read_bytes )
119 STATS_FLOAT( input_bitrate )
120 STATS_INT( demux_read_bytes )
121 STATS_FLOAT( demux_bitrate )
122 STATS_INT( decoded_video )
123 STATS_INT( displayed_pictures )
124 STATS_INT( lost_pictures )
125 STATS_INT( decoded_audio )
126 STATS_INT( played_abuffers )
127 STATS_INT( lost_abuffers )
128 STATS_INT( sent_packets )
129 STATS_INT( sent_bytes )
130 STATS_FLOAT( send_bitrate )
137 /*****************************************************************************
139 *****************************************************************************/
140 static const luaL_Reg vlclua_input_reg[] = {
141 { "info", vlclua_input_info },
142 { "is_playing", vlclua_is_playing },
143 { "get_title", vlclua_get_title },
144 { "stats", vlclua_input_stats },
148 void luaopen_input( lua_State *L )
151 luaL_register( L, NULL, vlclua_input_reg );
152 lua_setfield( L, -2, "input" );