Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
videolan
vlc
Commits
bfe17fd3
Commit
bfe17fd3
authored
Mar 24, 2014
by
Rémi Denis-Courmont
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lua: vector out files descriptable table code
parent
6da72c20
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
87 additions
and
70 deletions
+87
-70
modules/lua/intf.c
modules/lua/intf.c
+8
-18
modules/lua/libs.h
modules/lua/libs.h
+0
-1
modules/lua/libs/net.c
modules/lua/libs/net.c
+62
-42
modules/lua/vlc.h
modules/lua/vlc.h
+17
-9
No files found.
modules/lua/intf.c
View file @
bfe17fd3
...
...
@@ -223,8 +223,6 @@ static int Start_LuaIntf( vlc_object_t *p_this, const char *name )
}
p_intf
->
p_sys
=
p_sys
;
vlclua_fd_init
(
p_sys
);
p_sys
->
psz_filename
=
vlclua_find_file
(
"intf"
,
name
);
if
(
!
p_sys
->
psz_filename
)
{
...
...
@@ -255,7 +253,11 @@ static int Start_LuaIntf( vlc_object_t *p_this, const char *name )
luaopen_input
(
L
);
luaopen_msg
(
L
);
luaopen_misc
(
L
);
luaopen_net_intf
(
L
);
if
(
vlclua_fd_init
(
L
,
&
p_sys
->
dtable
)
)
{
lua_close
(
L
);
goto
error
;
}
luaopen_object
(
L
);
luaopen_osd
(
L
);
luaopen_playlist
(
L
);
...
...
@@ -364,20 +366,9 @@ static int Start_LuaIntf( vlc_object_t *p_this, const char *name )
p_sys
->
L
=
L
;
#ifndef _WIN32
if
(
vlc_pipe
(
p_sys
->
fd
)
)
{
lua_close
(
p_sys
->
L
);
goto
error
;
}
#else
# define close(fd) (void)0
#endif
if
(
vlc_clone
(
&
p_sys
->
thread
,
Run
,
p_intf
,
VLC_THREAD_PRIORITY_LOW
)
)
{
close
(
p_sys
->
fd
[
1
]
);
close
(
p_sys
->
fd
[
0
]
);
vlclua_fd_cleanup
(
&
p_sys
->
dtable
);
lua_close
(
p_sys
->
L
);
goto
error
;
}
...
...
@@ -396,12 +387,11 @@ void Close_LuaIntf( vlc_object_t *p_this )
intf_thread_t
*
p_intf
=
(
intf_thread_t
*
)
p_this
;
intf_sys_t
*
p_sys
=
p_intf
->
p_sys
;
close
(
p_sys
->
fd
[
1
]
);
vlclua_fd_interrupt
(
&
p_sys
->
dtable
);
vlc_join
(
p_sys
->
thread
,
NULL
);
vlclua_fd_cleanup
(
&
p_sys
->
dtable
);
lua_close
(
p_sys
->
L
);
close
(
p_sys
->
fd
[
0
]
);
vlclua_fd_destroy
(
p_sys
);
free
(
p_sys
->
psz_filename
);
free
(
p_sys
);
}
...
...
modules/lua/libs.h
View file @
bfe17fd3
...
...
@@ -31,7 +31,6 @@ void luaopen_input( lua_State * );
void
luaopen_msg
(
lua_State
*
);
void
luaopen_misc
(
lua_State
*
);
void
luaopen_net_generic
(
lua_State
*
);
void
luaopen_net_intf
(
lua_State
*
);
void
luaopen_object
(
lua_State
*
);
void
luaopen_osd
(
lua_State
*
);
void
luaopen_playlist
(
lua_State
*
);
...
...
modules/lua/libs/net.c
View file @
bfe17fd3
...
...
@@ -42,50 +42,40 @@
#include <vlc_network.h>
#include <vlc_url.h>
#include <vlc_fs.h>
#include <vlc_interface.h>
#include "../vlc.h"
#include "../libs.h"
#include "misc.h"
void
vlclua_fd_init
(
intf_sys_t
*
sys
)
static
vlclua_dtable_t
*
vlclua_get_dtable
(
lua_State
*
L
)
{
sys
->
fdv
=
NULL
;
sys
->
fdc
=
0
;
}
/** Releases all (leaked) VLC Lua file descriptors. */
void
vlclua_fd_destroy
(
intf_sys_t
*
sys
)
{
for
(
unsigned
i
=
0
;
i
<
sys
->
fdc
;
i
++
)
net_Close
(
sys
->
fdv
[
i
]
);
free
(
sys
->
fdv
);
return
vlclua_get_object
(
L
,
vlclua_get_dtable
);
}
/** Maps an OS file descriptor to a VLC Lua file descriptor */
static
int
vlclua_fd_map
(
lua_State
*
L
,
int
fd
)
{
intf_thread_t
*
intf
=
(
intf_thread_t
*
)
vlclua_get_this
(
L
);
intf_sys_t
*
sys
=
intf
->
p_sys
;
vlclua_dtable_t
*
dt
=
vlclua_get_dtable
(
L
);
if
(
(
unsigned
)
fd
<
3u
)
return
-
1
;
#ifndef NDEBUG
for
(
unsigned
i
=
0
;
i
<
sys
->
fdc
;
i
++
)
assert
(
sys
->
fdv
[
i
]
!=
fd
);
for
(
unsigned
i
=
0
;
i
<
dt
->
fdc
;
i
++
)
assert
(
dt
->
fdv
[
i
]
!=
fd
);
#endif
if
(
sys
->
fdc
>=
64
)
if
(
dt
->
fdc
>=
64
)
return
-
1
;
int
*
fdv
=
realloc
(
sys
->
fdv
,
(
sys
->
fdc
+
1
)
*
sizeof
(
sys
->
fdv
[
0
])
);
int
*
fdv
=
realloc
(
dt
->
fdv
,
(
dt
->
fdc
+
1
)
*
sizeof
(
dt
->
fdv
[
0
])
);
if
(
unlikely
(
fdv
==
NULL
)
)
return
-
1
;
sys
->
fdv
=
fdv
;
sys
->
fdv
[
sys
->
fdc
]
=
fd
;
fd
=
3
+
sys
->
fdc
;
sys
->
fdc
++
;
dt
->
fdv
=
fdv
;
dt
->
fdv
[
dt
->
fdc
]
=
fd
;
fd
=
3
+
dt
->
fdc
;
dt
->
fdc
++
;
return
fd
;
}
...
...
@@ -100,25 +90,23 @@ static int vlclua_fd_map_safe( lua_State *L, int fd )
/** Gets the OS file descriptor mapped to a VLC Lua file descriptor */
static
int
vlclua_fd_get
(
lua_State
*
L
,
unsigned
idx
)
{
intf_thread_t
*
intf
=
(
intf_thread_t
*
)
vlclua_get_this
(
L
);
intf_sys_t
*
sys
=
intf
->
p_sys
;
vlclua_dtable_t
*
dt
=
vlclua_get_dtable
(
L
);
if
(
idx
<
3u
)
return
idx
;
idx
-=
3
;
return
(
idx
<
sys
->
fdc
)
?
sys
->
fdv
[
idx
]
:
-
1
;
return
(
idx
<
dt
->
fdc
)
?
dt
->
fdv
[
idx
]
:
-
1
;
}
/** Gets the VLC Lua file descriptor mapped from an OS file descriptor */
static
int
vlclua_fd_get_lua
(
lua_State
*
L
,
int
fd
)
{
intf_thread_t
*
intf
=
(
intf_thread_t
*
)
vlclua_get_this
(
L
);
intf_sys_t
*
sys
=
intf
->
p_sys
;
vlclua_dtable_t
*
dt
=
vlclua_get_dtable
(
L
);
if
(
(
unsigned
)
fd
<
3u
)
return
fd
;
for
(
unsigned
i
=
0
;
i
<
sys
->
fdc
;
i
++
)
if
(
sys
->
fdv
[
i
]
==
fd
)
for
(
unsigned
i
=
0
;
i
<
dt
->
fdc
;
i
++
)
if
(
dt
->
fdv
[
i
]
==
fd
)
return
3
+
i
;
return
-
1
;
}
...
...
@@ -126,25 +114,24 @@ static int vlclua_fd_get_lua( lua_State *L, int fd )
/** Unmaps an OS file descriptor from VLC Lua */
static
void
vlclua_fd_unmap
(
lua_State
*
L
,
unsigned
idx
)
{
intf_thread_t
*
intf
=
(
intf_thread_t
*
)
vlclua_get_this
(
L
);
intf_sys_t
*
sys
=
intf
->
p_sys
;
vlclua_dtable_t
*
dt
=
vlclua_get_dtable
(
L
);
int
fd
=
-
1
;
if
(
idx
<
3u
)
return
;
/* Never close stdin/stdout/stderr. */
idx
-=
3
;
if
(
idx
>=
sys
->
fdc
)
if
(
idx
>=
dt
->
fdc
)
return
;
fd
=
sys
->
fdv
[
idx
];
sys
->
fdc
--
;
memmove
(
sys
->
fdv
+
idx
,
sys
->
fdv
+
idx
+
1
,
(
sys
->
fdc
-
idx
)
*
sizeof
(
sys
->
fdv
[
0
])
);
fd
=
dt
->
fdv
[
idx
];
dt
->
fdc
--
;
memmove
(
dt
->
fdv
+
idx
,
dt
->
fdv
+
idx
+
1
,
(
dt
->
fdc
-
idx
)
*
sizeof
(
dt
->
fdv
[
0
])
);
/* realloc() not really needed */
#ifndef NDEBUG
for
(
unsigned
i
=
0
;
i
<
sys
->
fdc
;
i
++
)
assert
(
sys
->
fdv
[
i
]
!=
fd
);
for
(
unsigned
i
=
0
;
i
<
dt
->
fdc
;
i
++
)
assert
(
dt
->
fdv
[
i
]
!=
fd
);
#endif
}
...
...
@@ -322,8 +309,7 @@ static int vlclua_net_recv( lua_State *L )
/* Takes a { fd : events } table as first arg and modifies it to { fd : revents } */
static
int
vlclua_net_poll
(
lua_State
*
L
)
{
intf_thread_t
*
intf
=
(
intf_thread_t
*
)
vlclua_get_this
(
L
);
intf_sys_t
*
sys
=
intf
->
p_sys
;
vlclua_dtable_t
*
dt
=
vlclua_get_dtable
(
L
);
luaL_checktype
(
L
,
1
,
LUA_TTABLE
);
...
...
@@ -340,7 +326,7 @@ static int vlclua_net_poll( lua_State *L )
lua_pushnil
(
L
);
int
i
=
1
;
p_fds
[
0
].
fd
=
sys
->
fd
[
0
];
p_fds
[
0
].
fd
=
dt
->
fd
[
0
];
p_fds
[
0
].
events
=
POLLIN
;
while
(
lua_next
(
L
,
1
)
)
{
...
...
@@ -509,7 +495,7 @@ static const luaL_Reg vlclua_net_intf_reg[] = {
{
NULL
,
NULL
}
};
void
luaopen_net_intf
(
lua_State
*
L
)
static
void
luaopen_net_intf
(
lua_State
*
L
)
{
lua_newtable
(
L
);
luaL_register
(
L
,
NULL
,
vlclua_net_intf_reg
);
...
...
@@ -525,6 +511,40 @@ void luaopen_net_intf( lua_State *L )
lua_setfield
(
L
,
-
2
,
"net"
);
}
int
vlclua_fd_init
(
lua_State
*
L
,
vlclua_dtable_t
*
dt
)
{
#ifndef _WIN32
if
(
vlc_pipe
(
dt
->
fd
)
)
return
-
1
;
#endif
dt
->
fdv
=
NULL
;
dt
->
fdc
=
0
;
vlclua_set_object
(
L
,
vlclua_get_dtable
,
dt
);
luaopen_net_intf
(
L
);
return
0
;
}
void
vlclua_fd_interrupt
(
vlclua_dtable_t
*
dt
)
{
#ifndef _WIN32
close
(
dt
->
fd
[
1
]
);
dt
->
fd
[
1
]
=
-
1
;
#endif
}
/** Releases all (leaked) VLC Lua file descriptors. */
void
vlclua_fd_cleanup
(
vlclua_dtable_t
*
dt
)
{
for
(
unsigned
i
=
0
;
i
<
dt
->
fdc
;
i
++
)
net_Close
(
dt
->
fdv
[
i
]
);
free
(
dt
->
fdv
);
#ifndef _WIN32
if
(
dt
->
fd
[
1
]
!=
-
1
)
close
(
dt
->
fd
[
1
]
);
close
(
dt
->
fd
[
0
]
);
#endif
}
static
const
luaL_Reg
vlclua_net_generic_reg
[]
=
{
{
"url_parse"
,
vlclua_url_parse
},
{
"stat"
,
vlclua_stat
},
/* Not really "net" */
...
...
modules/lua/vlc.h
View file @
bfe17fd3
...
...
@@ -155,23 +155,31 @@ int vlclua_playlist_add_internal( vlc_object_t *, lua_State *, playlist_t *,
int
vlclua_add_modules_path
(
lua_State
*
,
const
char
*
psz_filename
);
/**
*
Per-interface private stat
e
*
File descriptors tabl
e
*/
struct
intf_sys_
t
typedef
struc
t
{
char
*
psz_filename
;
lua_State
*
L
;
int
*
fdv
;
unsigned
fdc
;
#ifndef _WIN32
int
fd
[
2
];
#endif
int
*
fdv
;
unsigned
fdc
;
}
vlclua_dtable_t
;
int
vlclua_fd_init
(
lua_State
*
,
vlclua_dtable_t
*
);
void
vlclua_fd_interrupt
(
vlclua_dtable_t
*
);
void
vlclua_fd_cleanup
(
vlclua_dtable_t
*
);
/**
* Per-interface private state
*/
struct
intf_sys_t
{
char
*
psz_filename
;
lua_State
*
L
;
vlc_thread_t
thread
;
vlclua_dtable_t
dtable
;
};
void
vlclua_fd_init
(
struct
intf_sys_t
*
);
void
vlclua_fd_destroy
(
struct
intf_sys_t
*
);
#endif
/* VLC_LUA_H */
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment