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 );
53 input_thread_t *p_input = p_playlist->p_input;
54 if( p_input ) vlc_object_hold( p_input );
56 vlclua_release_playlist_internal( p_playlist );
60 static int vlclua_input_info( lua_State *L )
62 input_thread_t * p_input = vlclua_get_input_internal( L );
63 vlc_object_lock( p_input );
66 if( !p_input ) return vlclua_error( L );
67 //vlc_mutex_lock( &input_GetItem(p_input)->lock );
68 i_cat = input_GetItem(p_input)->i_categories;
69 lua_createtable( L, 0, i_cat );
70 for( i = 0; i < i_cat; i++ )
72 info_category_t *p_category = input_GetItem(p_input)->pp_categories[i];
73 int i_infos = p_category->i_infos;
75 lua_pushstring( L, p_category->psz_name );
76 lua_createtable( L, 0, i_infos );
77 for( j = 0; j < i_infos; j++ )
79 info_t *p_info = p_category->pp_infos[j];
80 lua_pushstring( L, p_info->psz_name );
81 lua_pushstring( L, p_info->psz_value );
82 lua_settable( L, -3 );
84 lua_settable( L, -3 );
86 vlc_object_unlock( p_input );
87 vlc_object_release( p_input );
91 static int vlclua_is_playing( lua_State *L )
93 input_thread_t * p_input = vlclua_get_input_internal( L );
94 lua_pushboolean( L, !!p_input );
98 static int vlclua_get_title( lua_State *L )
100 input_thread_t *p_input = vlclua_get_input_internal( L );
105 lua_pushstring( L, input_GetItem(p_input)->psz_name );
106 vlc_object_release( p_input );
111 static int vlclua_input_stats( lua_State *L )
113 input_thread_t *p_input = vlclua_get_input_internal( L );
114 input_item_t *p_item = p_input && p_input->p ? input_GetItem( p_input ) : NULL;
118 #define STATS_INT( n ) lua_pushinteger( L, p_item->p_stats->i_ ## n ); \
119 lua_setfield( L, -2, #n );
120 #define STATS_FLOAT( n ) lua_pushnumber( L, p_item->p_stats->f_ ## n ); \
121 lua_setfield( L, -2, #n );
122 STATS_INT( read_bytes )
123 STATS_FLOAT( input_bitrate )
124 STATS_INT( demux_read_bytes )
125 STATS_FLOAT( demux_bitrate )
126 STATS_INT( decoded_video )
127 STATS_INT( displayed_pictures )
128 STATS_INT( lost_pictures )
129 STATS_INT( decoded_audio )
130 STATS_INT( played_abuffers )
131 STATS_INT( lost_abuffers )
132 STATS_INT( sent_packets )
133 STATS_INT( sent_bytes )
134 STATS_FLOAT( send_bitrate )
141 /*****************************************************************************
143 *****************************************************************************/
144 static const luaL_Reg vlclua_input_reg[] = {
145 { "info", vlclua_input_info },
146 { "is_playing", vlclua_is_playing },
147 { "get_title", vlclua_get_title },
148 { "stats", vlclua_input_stats },
152 void luaopen_input( lua_State *L )
155 luaL_register( L, NULL, vlclua_input_reg );
156 lua_setfield( L, -2, "input" );