[vlc-devel] [PATCH] lua: Expose media tracks through lua bindings
Hugo Beauzée-Luyssen
hugo at beauzee.fr
Tue Jan 3 10:59:15 CET 2017
On 01/02/2017 06:01 PM, Rémi Denis-Courmont wrote:
> Le lundi 2 janvier 2017, 16:31:21 Hugo Beauzée-Luyssen a écrit :
>> ---
>> modules/lua/libs/input.c | 123
>> ++++++++++++++++++++++++++++++++++++++++++++++- share/lua/README.txt |
>> 28 +++++++++++
>> 2 files changed, 150 insertions(+), 1 deletion(-)
>>
>> diff --git a/modules/lua/libs/input.c b/modules/lua/libs/input.c
>> index 6d14ebce78..9fd49dbc36 100644
>> --- a/modules/lua/libs/input.c
>> +++ b/modules/lua/libs/input.c
>> @@ -382,6 +382,127 @@ static int vlclua_input_item_set_meta( lua_State *L )
>> return 1;
>> }
>>
>> +#define PUSH_INT( val, name ) \
>> + lua_pushinteger( L, val ); \
>> + lua_setfield( L, -2, name );
>> +
>> +#define PUSH_STR( val, name ) \
>> + lua_pushstring( L, val ); \
>> + lua_setfield( L, -2, name );
>> +
>> +#define PUSH_NUM( val, name ) \
>> + lua_pushnumber( L, val ); \
>> + lua_setfield( L, -2, name );
>> +
>> +static const char* orientation_to_str(video_orientation_t orient)
>> +{
>> + switch (orient)
>> + {
>> + case ORIENT_TOP_LEFT:
>> + return "topleft";
>> + case ORIENT_TOP_RIGHT:
>> + return "topright";
>> + case ORIENT_BOTTOM_LEFT:
>> + return "bottomleft";
>> + case ORIENT_BOTTOM_RIGHT:
>> + return "bottomright";
>> + case ORIENT_LEFT_TOP:
>> + return "lefttop";
>> + case ORIENT_LEFT_BOTTOM:
>> + return "leftbottom";
>> + case ORIENT_RIGHT_TOP:
>> + return "righttop";
>> + case ORIENT_RIGHT_BOTTOM:
>> + return "rightbottom";
>> + default:
>> + vlc_assert_unreachable();
>> + }
>> +}
>> +
>> +static const char* projection_to_str(video_projection_mode_t proj)
>> +{
>> + switch (proj)
>> + {
>> + case PROJECTION_MODE_RECTANGULAR:
>> + return "rectangular";
>> + case PROJECTION_MODE_EQUIRECTANGULAR:
>> + return "equirectangular";
>> + case PROJECTION_MODE_CUBEMAP_LAYOUT_STANDARD:
>> + return "cubemap";
>> + default:
>> + vlc_assert_unreachable();
>> + }
>> +}
>> +
>> +static int vlclua_input_item_tracks( lua_State *L )
>> +{
>> + input_item_t *p_item = vlclua_input_item_get_internal( L );
>> + lua_newtable( L );
>> +
>> + vlc_mutex_lock( &p_item->lock );
>> + for ( int i = 0; i < p_item->i_es; ++i )
>> + {
>> + const es_format_t* p_es = p_item->es[i];
>> +
>> + lua_newtable( L );
>> +
>> + lua_pushlstring( L, (const char*)&p_es->i_codec, 4 );
>> + lua_setfield( L, -2, "codec" );
>> + lua_pushlstring( L, (const char*)&p_es->i_original_fourcc, 4 );
>> + lua_setfield( L, -2, "original_fourcc" );
>> + PUSH_INT( p_es->i_id, "id" );
>
> In general I consider ES signed integer IDs as broken by design, and I am not
> very keen on exposing them any further than backward compatibility requires.
>
> Can't we have proper a Lua object per ES, not expose the ID to Lua code and
> limit the use of IDs to the back-end? Then we can fix the implementation later
> without breaking Lua scripts.
I guess it's doable, but I was mostly trying to have something that
mimics libvlc. I'll check what can be done for that
>
> (On top of my head, the ID is really only useful to select a track as of now.)
>
That's exactly the use case here.
>
>> + PUSH_INT( p_es->i_profile, "profile" );
>> + PUSH_INT( p_es->i_level, "level" );
>> + PUSH_INT( p_es->i_bitrate, "bitrate" );
>> + PUSH_STR( p_es->psz_language, "language" );
>> + PUSH_STR( p_es->psz_description, "description" );
>
More information about the vlc-devel
mailing list