mirror of
https://github.com/albfan/miraclecast.git
synced 2025-03-09 23:38:56 +00:00
miracle-dispd: rename files and class names to make naming consistent
Change-Id: Id2f5a8d6bbfbbd205dbe25e8b8bc0ddd289591e5
This commit is contained in:
parent
0648bb70a9
commit
c388985345
22 changed files with 1365 additions and 1360 deletions
|
@ -27,7 +27,7 @@ The MiracleCast projects requires the following software to be installed:
|
|||
|
||||
- **gstreamer**: MiracleCast rely on gstreamer to show cast its output. You can test if all needed is installed launching [res/test-viewer.sh](https://github.com/albfan/miraclecast/blob/master/res/test-viewer.sh).
|
||||
|
||||
- gstreamer plugins: here are the gstreamer plugins you need in order to run sinkctl or wfdctl
|
||||
- gstreamer plugins: here are the gstreamer plugins you need in order to run sinkctl or dispctl
|
||||
- gstreamer-plugins-base
|
||||
- gstreamer-plugins-good
|
||||
- gstreamer-plugins-bad
|
||||
|
|
|
@ -36,13 +36,13 @@ target_link_libraries(
|
|||
)
|
||||
|
||||
vala_precompile(
|
||||
WFDCTL_SRC wfdctl
|
||||
wfdctl.vala
|
||||
DISPCTL_SRC dispctl
|
||||
dispctl.vala
|
||||
networkmanager.vala
|
||||
miracle-wifi.vala
|
||||
miracle-wfd.vala
|
||||
GENERATE_HEADER
|
||||
wfdctl.h
|
||||
dispctl.h
|
||||
CUSTOM_VAPIS
|
||||
sigint.vapi
|
||||
OPTIONS
|
||||
|
@ -52,14 +52,14 @@ vala_precompile(
|
|||
gio-2.0
|
||||
gdk-3.0
|
||||
)
|
||||
add_executable(miracle-wfdctl ${WFDCTL_SRC} sigint.c)
|
||||
target_link_libraries(miracle-wfdctl ${GIO2_LIBRARIES} ${GDK3_LIBRARIES})
|
||||
add_executable(miracle-dispctl ${DISPCTL_SRC} sigint.c)
|
||||
target_link_libraries(miracle-dispctl ${GIO2_LIBRARIES} ${GDK3_LIBRARIES})
|
||||
|
||||
########### install files ###############
|
||||
|
||||
install(TARGETS gstencoder DESTINATION bin)
|
||||
|
||||
install(TARGETS miracle-wfdctl DESTINATION bin)
|
||||
install(TARGETS miracle-dispctl DESTINATION bin)
|
||||
|
||||
execute_process(
|
||||
COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=system_bus_services_dir dbus-1
|
||||
|
|
|
@ -35,7 +35,7 @@ const string IFACE_PEER = "org.freedesktop.miracle.wifi.Peer";
|
|||
const string IFACE_SINK = "org.freedesktop.miracle.wfd.Sink";
|
||||
const string IFACE_SESSION = "org.freedesktop.miracle.wfd.Session";
|
||||
|
||||
errordomain WfdCtlError
|
||||
errordomain DispCtlError
|
||||
{
|
||||
NO_SUCH_NIC,
|
||||
TIMEOUT,
|
||||
|
@ -70,7 +70,7 @@ private string decode_path(string s)
|
|||
return d.str;
|
||||
}
|
||||
|
||||
private class WfdCtl : GLib.Application
|
||||
private class DispCtl : GLib.Application
|
||||
{
|
||||
static string opt_iface;
|
||||
static string opt_wfd_subelems;
|
||||
|
@ -120,9 +120,9 @@ private class WfdCtl : GLib.Application
|
|||
{ null },
|
||||
};
|
||||
|
||||
public WfdCtl()
|
||||
public DispCtl()
|
||||
{
|
||||
Object(application_id: "org.freedesktop.miracle.WfdCtl",
|
||||
Object(application_id: "org.freedesktop.miracle.DispCtl",
|
||||
flags: ApplicationFlags.FLAGS_NONE);
|
||||
|
||||
devices = new HashTable<string, Device>(str_hash, str_equal);
|
||||
|
@ -341,7 +341,7 @@ private class WfdCtl : GLib.Application
|
|||
|
||||
Link l = find_link_by_name(opt_iface);
|
||||
if(null == l) {
|
||||
throw new WfdCtlError.NO_SUCH_NIC("no such wireless adapter: %s",
|
||||
throw new DispCtlError.NO_SUCH_NIC("no such wireless adapter: %s",
|
||||
opt_iface);
|
||||
}
|
||||
|
||||
|
@ -367,7 +367,7 @@ private class WfdCtl : GLib.Application
|
|||
}
|
||||
|
||||
if(-1 == l.p2p_state) {
|
||||
throw new WfdCtlError.NO_P2P_SUPPORT("link %s has no P2P supporting", l.interface_name);
|
||||
throw new DispCtlError.NO_P2P_SUPPORT("link %s has no P2P supporting", l.interface_name);
|
||||
}
|
||||
else if(0 == l.p2p_state) {
|
||||
info("wait for P2P supporting status...");
|
||||
|
@ -441,7 +441,7 @@ private class WfdCtl : GLib.Application
|
|||
}
|
||||
|
||||
if(null == m) {
|
||||
throw new WfdCtlError.MONITOR_GONE("specified monitor disappeared");
|
||||
throw new DispCtlError.MONITOR_GONE("specified monitor disappeared");
|
||||
}
|
||||
|
||||
g = m.geometry;
|
||||
|
@ -455,7 +455,7 @@ private class WfdCtl : GLib.Application
|
|||
: opt_monitor_num;
|
||||
|
||||
if(s.get_n_monitors() <= m) {
|
||||
throw new WfdCtlError.MONITOR_GONE("specified monitor disappeared");
|
||||
throw new DispCtlError.MONITOR_GONE("specified monitor disappeared");
|
||||
}
|
||||
|
||||
s.get_monitor_geometry(m, out g);
|
||||
|
@ -523,7 +523,7 @@ private class WfdCtl : GLib.Application
|
|||
Error error = null;
|
||||
var timeout_src = new TimeoutSource(10);
|
||||
timeout_src.set_callback(() => {
|
||||
error = new WfdCtlError.TIMEOUT("failed to establish session");
|
||||
error = new DispCtlError.TIMEOUT("failed to establish session");
|
||||
Idle.add(establish_session.callback);
|
||||
return false;
|
||||
});
|
||||
|
@ -561,7 +561,7 @@ private class WfdCtl : GLib.Application
|
|||
|
||||
Link l = find_link_by_name(opt_iface);
|
||||
if(null == l) {
|
||||
throw new WfdCtlError.NO_SUCH_NIC("no such wireless adapter: %s",
|
||||
throw new DispCtlError.NO_SUCH_NIC("no such wireless adapter: %s",
|
||||
opt_iface);
|
||||
}
|
||||
|
||||
|
@ -731,7 +731,7 @@ private class WfdCtl : GLib.Application
|
|||
|
||||
private async void wait_prop_changed<T>(T o,
|
||||
string name,
|
||||
uint timeout = 1) throws WfdCtlError
|
||||
uint timeout = 1) throws DispCtlError
|
||||
{
|
||||
ulong prop_changed_id = (o as DBusProxy).g_properties_changed.connect((props) => {
|
||||
string k;
|
||||
|
@ -764,7 +764,7 @@ private class WfdCtl : GLib.Application
|
|||
(o as DBusProxy).disconnect(prop_changed_id);
|
||||
|
||||
if(timed_out) {
|
||||
throw new WfdCtlError.TIMEOUT("timeout to wait for property %s change",
|
||||
throw new DispCtlError.TIMEOUT("timeout to wait for property %s change",
|
||||
name);
|
||||
}
|
||||
}
|
||||
|
@ -777,10 +777,10 @@ int main(string[]? argv)
|
|||
Environment.set_prgname(Path.get_basename(argv[0]));
|
||||
|
||||
|
||||
Application app = new WfdCtl();
|
||||
Application app = new DispCtl();
|
||||
app.set_default();
|
||||
|
||||
Sigint.add_watch((app as WfdCtl).stop_wireless_display);
|
||||
Sigint.add_watch((app as DispCtl).stop_wireless_display);
|
||||
|
||||
try {
|
||||
app.register();
|
|
@ -60,14 +60,14 @@ executable('gstencoder', 'gstencoder.vala',
|
|||
install: true,
|
||||
vala_args: ['--pkg=posix'])
|
||||
|
||||
miracle_wfdctl_src = ['wfdctl.vala',
|
||||
miracle_dispctl_src = ['dispctl.vala',
|
||||
'sigint.vapi',
|
||||
'sigint.c',
|
||||
'networkmanager.vala',
|
||||
'miracle-wifi.vala',
|
||||
'miracle-wfd.vala'
|
||||
]
|
||||
executable('miracle-wfdctl', miracle_wfdctl_src,
|
||||
executable('miracle-dispctl', miracle_dispctl_src,
|
||||
dependencies: [gio2, gdk3],
|
||||
vala_args: valac_extra_args,
|
||||
install: true
|
||||
|
|
|
@ -1,18 +1,21 @@
|
|||
set(miracle-dispd_SRCS ../ctl/ctl-cli.c
|
||||
../ctl/ctl-wifi.c
|
||||
wfd-sink.c
|
||||
wfd-dbus.c
|
||||
wfd-session.c
|
||||
wfd-out-session.c
|
||||
dispd.c
|
||||
dispd-encoder.c
|
||||
../ctl/wfd.c
|
||||
wfd-arg.c)
|
||||
set(miracle-dispd_SRCS
|
||||
../ctl/ctl-cli.c
|
||||
../ctl/ctl-wifi.c
|
||||
../ctl/wfd.c
|
||||
dispd-sink.c
|
||||
dispd-dbus.c
|
||||
dispd-session.c
|
||||
dispd-out-session.c
|
||||
dispd.c
|
||||
dispd-encoder.c
|
||||
dispd-arg.c
|
||||
)
|
||||
|
||||
include_directories(${CMAKE_SOURCE_DIR}/src/ctl
|
||||
${CMAKE_BINARY_DIR}
|
||||
${CMAKE_SOURCE_DIR}/src
|
||||
${CMAKE_SOURCE_DIR}/src/shared)
|
||||
${CMAKE_SOURCE_DIR}/src/shared
|
||||
)
|
||||
|
||||
add_executable(miracle-dispd ${miracle-dispd_SRCS})
|
||||
|
||||
|
@ -22,11 +25,13 @@ if(READLINE_FOUND)
|
|||
message(STATUS "Compiling with Readline support")
|
||||
set_property(TARGET miracle-dispd
|
||||
APPEND
|
||||
PROPERTY COMPILE_DEFINITIONS HAVE_READLINE)
|
||||
PROPERTY COMPILE_DEFINITIONS HAVE_READLINE
|
||||
)
|
||||
target_link_libraries(miracle-dispd ${READLINE_LIBRARY})
|
||||
endif(READLINE_FOUND)
|
||||
|
||||
target_link_libraries(miracle-dispd
|
||||
miracle-shared
|
||||
${READLINE_LIBRARY})
|
||||
${READLINE_LIBRARY}
|
||||
)
|
||||
|
||||
|
|
220
src/disp/disp.h
220
src/disp/disp.h
|
@ -1,220 +0,0 @@
|
|||
/*
|
||||
* MiracleCast - Wifi-Display/Miracast Implementation
|
||||
*
|
||||
* Copyright (c) 2013-2014 David Herrmann <dh.herrmann@gmail.com>
|
||||
*
|
||||
* MiracleCast is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* MiracleCast is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with MiracleCast; If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <systemd/sd-event.h>
|
||||
#include "shl_htable.h"
|
||||
#include "ctl.h"
|
||||
#include "wfd.h"
|
||||
|
||||
#ifndef DISP_DISP_H
|
||||
#define DISP_DISP_H
|
||||
|
||||
/* wfd session */
|
||||
#define wfd_session(s) ((struct wfd_session *) (s))
|
||||
#define wfd_is_session(s) ( \
|
||||
(s) && \
|
||||
(WFD_SESSION_DIR_OUT == wfd_session(s)->dir || \
|
||||
WFD_SESSION_DIR_IN == wfd_session(s)->dir) \
|
||||
)
|
||||
#define wfd_session_has_id(s) (0 < wfd_session_get_id(s))
|
||||
#define wfd_is_out_session(s) (WFD_SESSION_DIR_OUT == wfd_session_get_dir(s))
|
||||
#define wfd_is_in_session(s) (WFD_SESSION_DIR_IN == wfd_session_get_dir(s))
|
||||
#define _wfd_session_unref_ _shl_cleanup_(wfd_session_unrefp)
|
||||
|
||||
struct wfd_sink;
|
||||
struct wfd_session;
|
||||
struct rtsp_dispatch_entry;
|
||||
|
||||
enum wfd_session_dir
|
||||
{
|
||||
WFD_SESSION_DIR_OUT,
|
||||
WFD_SESSION_DIR_IN,
|
||||
};
|
||||
|
||||
enum wfd_session_state
|
||||
{
|
||||
WFD_SESSION_STATE_NULL,
|
||||
WFD_SESSION_STATE_CONNECTING,
|
||||
WFD_SESSION_STATE_CAPS_EXCHANGING,
|
||||
WFD_SESSION_STATE_ESTABLISHED,
|
||||
WFD_SESSION_STATE_SETTING_UP,
|
||||
WFD_SESSION_STATE_PAUSED,
|
||||
WFD_SESSION_STATE_PLAYING,
|
||||
WFD_SESSION_STATE_TEARING_DOWN,
|
||||
WFD_SESSION_STATE_DESTROYED,
|
||||
};
|
||||
|
||||
struct wfd_rectangle
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
int width;
|
||||
int height;
|
||||
};
|
||||
|
||||
enum wfd_display_server_type
|
||||
{
|
||||
WFD_DISPLAY_SERVER_TYPE_UNKNOWN = 0,
|
||||
WFD_DISPLAY_SERVER_TYPE_X,
|
||||
};
|
||||
|
||||
enum wfd_audio_server_type
|
||||
{
|
||||
WFD_AUDIO_SERVER_TYPE_UNKNOWN = 0,
|
||||
WFD_AUDIO_SERVER_TYPE_PULSE_AUDIO,
|
||||
};
|
||||
|
||||
int wfd_out_session_new(struct wfd_session **out,
|
||||
unsigned int id,
|
||||
struct wfd_sink *sink);
|
||||
struct wfd_session * _wfd_session_ref(struct wfd_session *s);
|
||||
#define wfd_session_ref(s) ( \
|
||||
log_debug("wfd_session_ref(%p): %d => %d", (s), *(int *) s, 1 + *(int *) s), \
|
||||
_wfd_session_ref(s) \
|
||||
)
|
||||
void _wfd_session_unref(struct wfd_session *s);
|
||||
#define wfd_session_unref(s) { \
|
||||
log_debug("wfd_session_unref(%p): %d => %d", (s), *(int *) s, *(int *) s - 1); \
|
||||
_wfd_session_unref(s); \
|
||||
}
|
||||
|
||||
void wfd_session_unrefp(struct wfd_session **s);
|
||||
unsigned int * wfd_session_to_htable(struct wfd_session *s);
|
||||
struct wfd_session * wfd_session_from_htable(unsigned int *e);
|
||||
|
||||
int wfd_session_start(struct wfd_session *s);
|
||||
int wfd_session_resume(struct wfd_session *s);
|
||||
int wfd_session_pause(struct wfd_session *s);
|
||||
int wfd_session_teardown(struct wfd_session *s);
|
||||
int wfd_session_destroy(struct wfd_session *s);
|
||||
|
||||
bool wfd_session_is_established(struct wfd_session *s);
|
||||
unsigned int wfd_session_get_id(struct wfd_session *s);
|
||||
const char * wfd_session_get_stream_url(struct wfd_session *s);
|
||||
bool wfd_session_is_state(struct wfd_session *s, enum wfd_session_state state);
|
||||
enum wfd_session_state wfd_session_get_state(struct wfd_session *s);
|
||||
enum wfd_session_dir wfd_session_get_dir(struct wfd_session *s);
|
||||
struct wfd_sink * wfd_out_session_get_sink(struct wfd_session *s);
|
||||
|
||||
enum wfd_display_server_type wfd_session_get_disp_type(struct wfd_session *s);
|
||||
int wfd_session_set_disp_type(struct wfd_session *s, enum wfd_display_server_type);
|
||||
const char * wfd_session_get_disp_name(struct wfd_session *s);
|
||||
int wfd_session_set_disp_name(struct wfd_session *s, const char *disp_name);
|
||||
const char * wfd_session_get_disp_params(struct wfd_session *s);
|
||||
int wfd_session_set_disp_params(struct wfd_session *s, const char *disp_params);
|
||||
const char * wfd_session_get_disp_auth(struct wfd_session *s);
|
||||
int wfd_session_set_disp_auth(struct wfd_session *s, const char *disp_auth);
|
||||
const struct wfd_rectangle * wfd_session_get_disp_dimension(struct wfd_session *s);
|
||||
int wfd_session_set_disp_dimension(struct wfd_session *s, const struct wfd_rectangle *rect);
|
||||
enum wfd_audio_server_type wfd_session_get_audio_type(struct wfd_session *s);
|
||||
int wfd_session_set_audio_type(struct wfd_session *s, enum wfd_audio_server_type audio_type);
|
||||
const char * wfd_session_get_audio_dev_name(struct wfd_session *s);
|
||||
int wfd_session_set_audio_dev_name(struct wfd_session *s, const char *audio_dev_name);
|
||||
const char * wfd_session_get_runtime_path(struct wfd_session *s);
|
||||
int wfd_session_set_runtime_path(struct wfd_session *s,
|
||||
const char *runtime_path);
|
||||
uid_t wfd_session_get_client_uid(struct wfd_session *s);
|
||||
int wfd_session_set_client_uid(struct wfd_session *s, uid_t uid);
|
||||
uid_t wfd_session_get_client_gid(struct wfd_session *s);
|
||||
int wfd_session_set_client_gid(struct wfd_session *s, uid_t gid);
|
||||
pid_t wfd_session_get_client_pid(struct wfd_session *s);
|
||||
int wfd_session_set_client_pid(struct wfd_session *s, pid_t pid);
|
||||
|
||||
/* wfd sink */
|
||||
#define _wfd_sink_free_ _shl_cleanup_(wfd_sink_freep)
|
||||
#define wfd_sink_to_htable(s) (&(s)->label)
|
||||
#define wfd_sink_from_htable(s) shl_htable_entry(s, struct wfd_sink, label)
|
||||
|
||||
struct wfd_sink
|
||||
{
|
||||
struct ctl_peer *peer;
|
||||
union wfd_sube dev_info;
|
||||
char *label;
|
||||
struct wfd_session *session;
|
||||
|
||||
sd_event_source *session_cleanup_source;
|
||||
};
|
||||
|
||||
int wfd_sink_new(struct wfd_sink **out,
|
||||
struct ctl_peer *peer,
|
||||
union wfd_sube *sube);
|
||||
void wfd_sink_free(struct wfd_sink *sink);
|
||||
static inline void wfd_sink_freep(struct wfd_sink **s)
|
||||
{
|
||||
wfd_sink_free(*s);
|
||||
*s = NULL;
|
||||
}
|
||||
|
||||
int wfd_sink_create_session(struct wfd_sink *sink, struct wfd_session **out);
|
||||
|
||||
const char * wfd_sink_get_label(struct wfd_sink *sink);
|
||||
const union wfd_sube * wfd_sink_get_dev_info(struct wfd_sink *sink);
|
||||
bool wfd_sink_is_session_started(struct wfd_sink *sink);
|
||||
|
||||
void wfd_sink_handle_session_ended(struct wfd_sink *sink);
|
||||
|
||||
/* wfd handling */
|
||||
#define ctl_wfd_foreach_sink(_i, _w) \
|
||||
SHL_HTABLE_FOREACH_MACRO(_i, \
|
||||
&(_w)->sinks, \
|
||||
wfd_sink_from_htable)
|
||||
#define ctl_wfd_foreach_session(_i, _w) \
|
||||
SHL_HTABLE_FOREACH_MACRO(_i, \
|
||||
&(_w)->sessions, \
|
||||
wfd_session_from_htable)
|
||||
|
||||
struct ctl_wfd
|
||||
{
|
||||
sd_event *loop;
|
||||
struct ctl_wifi *wifi;
|
||||
struct shl_htable sinks;
|
||||
size_t n_sinks;
|
||||
struct shl_htable sessions;
|
||||
size_t n_sessions;
|
||||
unsigned int id_pool;
|
||||
};
|
||||
|
||||
struct ctl_wfd * ctl_wfd_get();
|
||||
void ctl_wfd_shutdown(struct ctl_wfd *wfd);
|
||||
|
||||
static inline struct sd_event * ctl_wfd_get_loop()
|
||||
{
|
||||
return ctl_wfd_get()->loop;
|
||||
}
|
||||
|
||||
int ctl_wfd_find_sink_by_label(struct ctl_wfd *wfd,
|
||||
const char *label,
|
||||
struct wfd_sink **out);
|
||||
int ctl_wfd_add_session(struct ctl_wfd *wfd, struct wfd_session *s);
|
||||
int ctl_wfd_find_session_by_id(struct ctl_wfd *wfd,
|
||||
unsigned int id,
|
||||
struct wfd_session **out);
|
||||
int ctl_wfd_remove_session_by_id(struct ctl_wfd *wfd,
|
||||
unsigned int id,
|
||||
struct wfd_session **out);
|
||||
unsigned int ctl_wfd_alloc_session_id(struct ctl_wfd *wfd);
|
||||
|
||||
int wfd_fn_session_new(struct wfd_session *s);
|
||||
int wfd_fn_session_free(struct wfd_session *s);
|
||||
int wfd_fn_out_session_ended(struct wfd_session *s);
|
||||
|
||||
int wfd_fn_sink_new(struct wfd_sink *s);
|
||||
int wfd_fn_sink_free(struct wfd_sink *s);
|
||||
|
||||
#endif /* DISP_DISP_H */
|
|
@ -19,13 +19,13 @@
|
|||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include "wfd-arg.h"
|
||||
#include "dispd-arg.h"
|
||||
|
||||
int wfd_arg_list_new(struct wfd_arg_list **out)
|
||||
int dispd_arg_list_new(struct dispd_arg_list **out)
|
||||
{
|
||||
assert(out);
|
||||
|
||||
struct wfd_arg_list *l = calloc(1, sizeof(struct wfd_arg_list));
|
||||
struct dispd_arg_list *l = calloc(1, sizeof(struct dispd_arg_list));
|
||||
if(!l) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
@ -37,10 +37,10 @@ int wfd_arg_list_new(struct wfd_arg_list **out)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void wfd_arg_list_clear(struct wfd_arg_list *l)
|
||||
void dispd_arg_list_clear(struct dispd_arg_list *l)
|
||||
{
|
||||
int i;
|
||||
struct wfd_arg *arg;
|
||||
struct dispd_arg *arg;
|
||||
|
||||
if(!l || !l->dynamic) {
|
||||
return;
|
||||
|
@ -48,7 +48,7 @@ void wfd_arg_list_clear(struct wfd_arg_list *l)
|
|||
|
||||
arg = l->discrete ? l->argv : l->args;
|
||||
for(i = 0; i < l->len; i ++) {
|
||||
if((WFD_ARG_STR == arg->type || WFD_ARG_PTR == arg->type)
|
||||
if((DISPD_ARG_STR == arg->type || DISPD_ARG_PTR == arg->type)
|
||||
&& arg->ptr && arg->free) {
|
||||
(*arg->free)(arg->ptr);
|
||||
}
|
242
src/disp/dispd-arg.h
Normal file
242
src/disp/dispd-arg.h
Normal file
|
@ -0,0 +1,242 @@
|
|||
/*
|
||||
* MiracleCast - Wifi-Display/Miracast Implementation
|
||||
*
|
||||
* Copyright (c) 2013-2014 David Herrmann <dh.herrmann@gmail.com>
|
||||
*
|
||||
* MiracleCast is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* MiracleCast is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with MiracleCast; If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "shl_macro.h"
|
||||
|
||||
#ifndef DISPD_ARG_H
|
||||
#define DISPD_ARG_H
|
||||
|
||||
#define dispd_arg_i8(_v) { .type = DISPD_ARG_I8, .i8 = (_v) }
|
||||
#define dispd_arg_u8(_v) { .type = DISPD_ARG_U8, .u8 = (_v) }
|
||||
#define dispd_arg_i16(_v) { .type = DISPD_ARG_I16, .i16 = (_v) }
|
||||
#define dispd_arg_u16(_v) { .type = DISPD_ARG_U16, .u16 = (_v) }
|
||||
#define dispd_arg_i32(_v) { .type = DISPD_ARG_I32, .i32 = (_v) }
|
||||
#define dispd_arg_u32(_v) { .type = DISPD_ARG_U32, .u32 = (_v) }
|
||||
#define dispd_arg_i64(_v) { .type = DISPD_ARG_I64, .i64 = (_v) }
|
||||
#define dispd_arg_u64(_v) { .type = DISPD_ARG_U64, .u64 = (_v) }
|
||||
#define dispd_arg_cstr(_v) { .type = DISPD_ARG_CSTR, .ptr = (_v) }
|
||||
#define dispd_arg_cptr(_v) { .type = DISPD_ARG_CPTR, .ptr = (_v) }
|
||||
#define dispd_arg_arg_list(_v) { \
|
||||
.type = DISPD_ARG_ARG_LIST, \
|
||||
.ptr = &(struct dispd_arg_list) dispd_arg_list(_v) \
|
||||
}
|
||||
#define dispd_arg_dict(_k, _v) { \
|
||||
.type = DISPD_ARG_DICT, \
|
||||
.k = (struct dispd_arg[]){_k}, \
|
||||
.v = (struct dispd_arg[]){_v} \
|
||||
}
|
||||
|
||||
#if INT_MAX == INT64_MAX
|
||||
#define dispd_arg_i(_v) dispd_arg_i64(_v)
|
||||
#define dispd_arg_u(_v) dispd_arg_u64(_v)
|
||||
#elif INT_MAX == INT32_MAX
|
||||
#define dispd_arg_i(_v) dispd_arg_i32(_v)
|
||||
#define dispd_arg_u(_v) dispd_arg_u32(_v)
|
||||
#else
|
||||
#error unsupported int size
|
||||
#endif
|
||||
|
||||
#define dispd_arg_type_id(_t) _Generic((_t), \
|
||||
int8_t: DISPD_ARG_I8, \
|
||||
uint8_t: DISPD_ARG_U8, \
|
||||
int16_t: DISPD_ARG_I16, \
|
||||
uint16_t: DISPD_ARG_U16, \
|
||||
int32_t: DISPD_ARG_I32, \
|
||||
uint32_t: DISPD_ARG_U32, \
|
||||
int64_t: DISPD_ARG_I64, \
|
||||
uint64_t: DISPD_ARG_U64, \
|
||||
const char *: DISPD_ARG_CSTR, \
|
||||
const dispd_arg_list *: DISPD_ARG_ARG_LIST, \
|
||||
char *: DISPD_ARG_STR, \
|
||||
void *: DISPD_ARG_PTR, \
|
||||
default: DISPD_ARG_CPTR \
|
||||
)
|
||||
|
||||
#define dispd_arg_list(...) { \
|
||||
.argv = (struct dispd_arg[]) { \
|
||||
__VA_ARGS__ \
|
||||
}, \
|
||||
.discrete = true, \
|
||||
.dynamic = false, \
|
||||
.len = (sizeof((struct dispd_arg[]){ __VA_ARGS__ })/sizeof(struct dispd_arg)) \
|
||||
}
|
||||
|
||||
#define dispd_arg_get(_a, _v) ({ \
|
||||
*(_v) = _Generic(*(_v), \
|
||||
int8_t: dispd_arg_get_i8, \
|
||||
uint8_t: dispd_arg_get_u8, \
|
||||
int16_t: dispd_arg_get_i16, \
|
||||
uint16_t: dispd_arg_get_u16, \
|
||||
int32_t: dispd_arg_get_i32, \
|
||||
uint32_t: dispd_arg_get_u32, \
|
||||
int64_t: dispd_arg_get_i64, \
|
||||
uint64_t: dispd_arg_get_u64, \
|
||||
char *: dispd_arg_get_str, \
|
||||
const struct dispd_arg_list *: dispd_arg_get_arg_list, \
|
||||
const char *: dispd_arg_get_cstr, \
|
||||
void *: dispd_arg_get_ptr, \
|
||||
default: dispd_arg_get_cptr \
|
||||
)(_a); \
|
||||
})
|
||||
|
||||
#define dispd_arg_get_dictk(_a, _k) ({ \
|
||||
assert(_a); \
|
||||
assert(DISPD_ARG_DICT == (_a)->type); \
|
||||
dispd_arg_get((_a)->k, (_k)); \
|
||||
})
|
||||
|
||||
#define dispd_arg_get_dictv(_a, _v) ({ \
|
||||
assert(_a); \
|
||||
assert(DISPD_ARG_DICT == (_a)->type); \
|
||||
dispd_arg_get((_a)->v, (_v)); \
|
||||
})
|
||||
|
||||
#define dispd_arg_get_dict(_a, _k, _v) ({ \
|
||||
assert(_a); \
|
||||
assert(DISPD_ARG_DICT == (_a)->type); \
|
||||
dispd_arg_get_dictk(_a, _k); \
|
||||
dispd_arg_get_dictv(_a, _v); \
|
||||
})
|
||||
|
||||
#define dispd_arg_list_get(_l, _i, _v) ({ \
|
||||
dispd_arg_get(dispd_arg_list_at((_l), (_i)), (_v)); \
|
||||
})
|
||||
|
||||
#define dispd_arg_list_get_dictk(_l, _i, _k) ({ \
|
||||
dispd_arg_get_dictk(dispd_arg_list_at((_l), (_i)), (_k)); \
|
||||
})
|
||||
|
||||
#define dispd_arg_list_get_dictv(_l, _i, _v) ({ \
|
||||
dispd_arg_get_dictv(dispd_arg_list_at((_l), (_i)), (_v)); \
|
||||
})
|
||||
|
||||
#define dispd_arg_list_get_dict(_l, _i, _k, _v) ({ \
|
||||
dispd_arg_get_dict(dispd_arg_list_at((_l), (_i)), (_k), (_v)); \
|
||||
})
|
||||
|
||||
enum dispd_arg_type
|
||||
{
|
||||
DISPD_ARG_NONE,
|
||||
DISPD_ARG_I8,
|
||||
DISPD_ARG_I16,
|
||||
DISPD_ARG_I32,
|
||||
DISPD_ARG_I64,
|
||||
DISPD_ARG_U8,
|
||||
DISPD_ARG_U16,
|
||||
DISPD_ARG_U32,
|
||||
DISPD_ARG_U64,
|
||||
DISPD_ARG_STR,
|
||||
DISPD_ARG_CSTR,
|
||||
DISPD_ARG_PTR,
|
||||
DISPD_ARG_CPTR,
|
||||
DISPD_ARG_DICT,
|
||||
DISPD_ARG_ARG_LIST,
|
||||
};
|
||||
|
||||
struct dispd_arg
|
||||
{
|
||||
enum dispd_arg_type type;
|
||||
union
|
||||
{
|
||||
int8_t i8;
|
||||
uint8_t u8;
|
||||
int16_t i16;
|
||||
uint16_t u16;
|
||||
int32_t i32;
|
||||
uint32_t u32;
|
||||
int64_t i64;
|
||||
uint64_t u64;
|
||||
struct {
|
||||
void *ptr;
|
||||
void (*free)(void *);
|
||||
};
|
||||
struct {
|
||||
struct dispd_arg *k;
|
||||
struct dispd_arg *v;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
struct dispd_arg_list
|
||||
{
|
||||
size_t len: sizeof(size_t) - 2;
|
||||
bool discrete: 1;
|
||||
bool dynamic: 1;
|
||||
|
||||
union {
|
||||
struct dispd_arg * argv;
|
||||
struct dispd_arg args[0];
|
||||
};
|
||||
};
|
||||
|
||||
int dispd_arg_list_new(struct dispd_arg_list **out);
|
||||
void dispd_arg_list_clear(struct dispd_arg_list *l);
|
||||
static inline void dispd_arg_list_free(struct dispd_arg_list *l);
|
||||
static inline const struct dispd_arg * dispd_arg_list_at(const struct dispd_arg_list *l,
|
||||
int i);
|
||||
|
||||
static inline enum dispd_arg_type dispd_arg_get_type(struct dispd_arg *a);
|
||||
static inline void dispd_arg_free_ptr(struct dispd_arg *a);
|
||||
static inline void dispd_arg_clear(struct dispd_arg *a);
|
||||
|
||||
static inline int8_t dispd_arg_get_i8(const struct dispd_arg *a);
|
||||
static inline void dispd_arg_set_i8(struct dispd_arg *a, int8_t v);
|
||||
|
||||
static inline uint8_t dispd_arg_get_u8(const struct dispd_arg *a);
|
||||
static inline void dispd_arg_set_u8(struct dispd_arg *a, uint8_t v);
|
||||
|
||||
static inline int16_t dispd_arg_get_i16(const struct dispd_arg *a);
|
||||
static inline void dispd_arg_set_i16(struct dispd_arg *a, int16_t v);
|
||||
|
||||
static inline uint16_t dispd_arg_get_u16(const struct dispd_arg *a);
|
||||
static inline void dispd_arg_set_u16(struct dispd_arg *a, uint16_t v);
|
||||
|
||||
static inline int32_t dispd_arg_get_i32(const struct dispd_arg *a);
|
||||
static inline void dispd_arg_set_i32(struct dispd_arg *a, int32_t v);
|
||||
|
||||
static inline uint32_t dispd_arg_get_u32(const struct dispd_arg *a);
|
||||
static inline void dispd_arg_set_u32(struct dispd_arg *a, uint32_t v);
|
||||
|
||||
static inline int64_t dispd_arg_get_i64(const struct dispd_arg *a);
|
||||
static inline void dispd_arg_set_i64(struct dispd_arg *a, int64_t v);
|
||||
|
||||
static inline uint64_t dispd_arg_get_u64(const struct dispd_arg *a);
|
||||
static inline void dispd_arg_set_u64(struct dispd_arg *a, uint64_t v);
|
||||
|
||||
static inline const char * dispd_arg_get_cstr(const struct dispd_arg *a);
|
||||
static inline void dispd_arg_set_cstr(struct dispd_arg *a, const char * v);
|
||||
|
||||
static inline void dispd_arg_take_str(struct dispd_arg *a, char *v);
|
||||
static inline char * dispd_arg_get_str(const struct dispd_arg *a);
|
||||
static inline int dispd_arg_set_str(struct dispd_arg *a, const char *v);;
|
||||
|
||||
static inline const void * dispd_arg_get_cptr(const struct dispd_arg *a);
|
||||
static inline void dispd_arg_set_cptr(struct dispd_arg *a, const void * v);
|
||||
|
||||
static inline void dispd_arg_take_ptr(struct dispd_arg *a, void *v, void (*f)(void *));
|
||||
static inline void * dispd_arg_get_ptr(const struct dispd_arg *a);
|
||||
|
||||
static inline void dispd_arg_take_arg_list(struct dispd_arg *a, struct dispd_arg_list *l);
|
||||
static inline const struct dispd_arg_list * dispd_arg_get_arg_list(const struct dispd_arg *a);
|
||||
|
||||
#include "dispd-arg.inc"
|
||||
|
||||
#endif /* DISPD_ARG_H */
|
192
src/disp/dispd-arg.inc
Normal file
192
src/disp/dispd-arg.inc
Normal file
|
@ -0,0 +1,192 @@
|
|||
/*
|
||||
* MiracleCast - Wifi-Display/Miracast Implementation
|
||||
*
|
||||
* Copyright (c) 2013-2014 David Herrmann <dh.herrmann@gmail.com>
|
||||
*
|
||||
* MiracleCast is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* MiracleCast is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with MiracleCast; If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#define dispd_arg_getter(_t, _s, _S) \
|
||||
static inline _t dispd_arg_get_##_s(const struct dispd_arg *a) \
|
||||
{ \
|
||||
assert(a); \
|
||||
assert(DISPD_ARG_##_S == a->type); \
|
||||
return a->_s; \
|
||||
}
|
||||
|
||||
#define dispd_arg_setter(_t, _s, _S) \
|
||||
static inline void dispd_arg_set_##_s(struct dispd_arg *a, _t v) \
|
||||
{ \
|
||||
assert(a); \
|
||||
assert(!a->type || DISPD_ARG_##_S == a->type); \
|
||||
*a = (struct dispd_arg) { .type = DISPD_ARG_##_S, ._s = v }; \
|
||||
}
|
||||
|
||||
dispd_arg_getter(int8_t, i8, I8)
|
||||
dispd_arg_setter(int8_t, i8, I8)
|
||||
dispd_arg_getter(uint8_t, u8, U8)
|
||||
dispd_arg_setter(uint8_t, u8, U8)
|
||||
dispd_arg_getter(int16_t, i16, I16)
|
||||
dispd_arg_setter(int16_t, i16, I16)
|
||||
dispd_arg_getter(uint16_t, u16, U16)
|
||||
dispd_arg_setter(uint16_t, u16, U16)
|
||||
dispd_arg_getter(int32_t, i32, I32)
|
||||
dispd_arg_setter(int32_t, i32, I32)
|
||||
dispd_arg_getter(uint32_t, u32, U32)
|
||||
dispd_arg_setter(uint32_t, u32, U32)
|
||||
dispd_arg_getter(int64_t, i64, I64)
|
||||
dispd_arg_setter(int64_t, i64, I64)
|
||||
dispd_arg_getter(uint64_t, u64, U64)
|
||||
dispd_arg_setter(uint64_t, u64, U64)
|
||||
|
||||
static inline void dispd_arg_list_free(struct dispd_arg_list *l)
|
||||
{
|
||||
dispd_arg_list_clear(l);
|
||||
free(l);
|
||||
}
|
||||
|
||||
static inline const struct dispd_arg * dispd_arg_list_at(const struct dispd_arg_list *l,
|
||||
int i)
|
||||
{
|
||||
assert(l);
|
||||
assert(i >= 0 && i < l->len);
|
||||
return l->discrete ? &l->argv[i] : &l->args[i];
|
||||
}
|
||||
|
||||
static inline enum dispd_arg_type dispd_arg_get_type(struct dispd_arg *a)
|
||||
{
|
||||
assert(a);
|
||||
|
||||
return a->type;
|
||||
}
|
||||
|
||||
static inline void dispd_arg_free_ptr(struct dispd_arg *a)
|
||||
{
|
||||
if(!a || (DISPD_ARG_STR != a->type && DISPD_ARG_PTR != a->type)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(a->ptr && a->free) {
|
||||
(*a->free)(a->ptr);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void dispd_arg_clear(struct dispd_arg *a)
|
||||
{
|
||||
if(a) {
|
||||
dispd_arg_free_ptr(a);
|
||||
memset(a, 0, sizeof(*a));
|
||||
}
|
||||
}
|
||||
|
||||
static inline const char * dispd_arg_get_cstr(const struct dispd_arg *a)
|
||||
{
|
||||
assert(a);
|
||||
assert(DISPD_ARG_CSTR == a->type || DISPD_ARG_STR == a->type);
|
||||
|
||||
return a->ptr;
|
||||
}
|
||||
|
||||
static inline void dispd_arg_set_cstr(struct dispd_arg *a, const char * v)
|
||||
{
|
||||
assert(a);
|
||||
assert(!a->type || DISPD_ARG_CSTR == a->type);
|
||||
|
||||
*a = (struct dispd_arg) { .type = DISPD_ARG_CSTR, .ptr = (void *) v };
|
||||
}
|
||||
|
||||
static inline char * dispd_arg_get_str(const struct dispd_arg *a)
|
||||
{
|
||||
assert(a);
|
||||
assert(DISPD_ARG_STR == a->type);
|
||||
|
||||
return a->ptr;
|
||||
}
|
||||
|
||||
static inline void dispd_arg_take_str(struct dispd_arg *a, char *v)
|
||||
{
|
||||
assert(a);
|
||||
assert(!a->type || DISPD_ARG_STR == a->type || DISPD_ARG_CSTR == a->type);
|
||||
|
||||
dispd_arg_free_ptr(a);
|
||||
*a = (struct dispd_arg) { .type = DISPD_ARG_STR, .ptr = v, .free = free };
|
||||
}
|
||||
|
||||
static inline int dispd_arg_set_str(struct dispd_arg *a, const char *v)
|
||||
{
|
||||
char *s;
|
||||
|
||||
assert(a);
|
||||
assert(!a->type || DISPD_ARG_STR == a->type);
|
||||
|
||||
s = strdup(v);
|
||||
if(!s) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
dispd_arg_take_str(a, s);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline const void * dispd_arg_get_cptr(const struct dispd_arg *a)
|
||||
{
|
||||
assert(a);
|
||||
assert(DISPD_ARG_PTR <= a->type && DISPD_ARG_CPTR == a->type);
|
||||
|
||||
return a->ptr;
|
||||
}
|
||||
|
||||
static inline void dispd_arg_set_cptr(struct dispd_arg *a, const void * v)
|
||||
{
|
||||
assert(a);
|
||||
assert(!a->type || DISPD_ARG_CSTR == a->type);
|
||||
|
||||
*a = (struct dispd_arg) { .type = DISPD_ARG_CPTR, .ptr = (void *) v };
|
||||
}
|
||||
|
||||
static inline void * dispd_arg_get_ptr(const struct dispd_arg *a)
|
||||
{
|
||||
assert(a);
|
||||
assert(DISPD_ARG_PTR == a->type || DISPD_ARG_STR == a->type);
|
||||
|
||||
return a->ptr;
|
||||
}
|
||||
|
||||
static inline void dispd_arg_take_ptr(struct dispd_arg *a, void *v, void (*f)(void *))
|
||||
{
|
||||
assert(a);
|
||||
assert(!a->type || DISPD_ARG_PTR == a->type);
|
||||
|
||||
dispd_arg_free_ptr(a);
|
||||
*a = (struct dispd_arg) { .type = DISPD_ARG_PTR, .ptr = v, .free = f };
|
||||
}
|
||||
|
||||
static inline void dispd_arg_take_arg_list(struct dispd_arg *a, struct dispd_arg_list *l)
|
||||
{
|
||||
assert(a);
|
||||
assert(!a->type || DISPD_ARG_ARG_LIST == a->type);
|
||||
|
||||
dispd_arg_free_ptr(a);
|
||||
*a = (struct dispd_arg) { .type = DISPD_ARG_ARG_LIST,
|
||||
.ptr = l,
|
||||
.free = (void (*)(void *)) dispd_arg_list_free };
|
||||
}
|
||||
|
||||
static inline const struct dispd_arg_list * dispd_arg_get_arg_list(const struct dispd_arg *a)
|
||||
{
|
||||
assert(a);
|
||||
assert(DISPD_ARG_ARG_LIST == a->type);
|
||||
|
||||
return a->ptr;
|
||||
}
|
|
@ -20,27 +20,27 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <systemd/sd-bus.h>
|
||||
#include "disp.h"
|
||||
#include "dispd.h"
|
||||
#include "util.h"
|
||||
#include "shl_log.h"
|
||||
#include "wfd-dbus.h"
|
||||
#include "dispd-dbus.h"
|
||||
|
||||
#define wfd_dbus_object_added(o, argv...) ({ \
|
||||
#define dispd_dbus_object_added(o, argv...) ({ \
|
||||
const char *ifaces[] = { argv }; \
|
||||
_wfd_dbus_object_added(wfd_dbus_get(), \
|
||||
_dispd_dbus_object_added(dispd_dbus_get(), \
|
||||
(o), \
|
||||
ifaces, \
|
||||
SHL_ARRAY_LENGTH(ifaces)); \
|
||||
})
|
||||
#define wfd_dbus_object_removed(o, argv...) ({ \
|
||||
#define dispd_dbus_object_removed(o, argv...) ({ \
|
||||
const char *ifaces[] = { argv }; \
|
||||
_wfd_dbus_object_removed(wfd_dbus_get(), \
|
||||
_dispd_dbus_object_removed(dispd_dbus_get(), \
|
||||
(o), \
|
||||
ifaces, \
|
||||
SHL_ARRAY_LENGTH(ifaces)); \
|
||||
})
|
||||
|
||||
struct wfd_dbus
|
||||
struct dispd_dbus
|
||||
{
|
||||
sd_bus *bus;
|
||||
sd_event *loop;
|
||||
|
@ -48,46 +48,46 @@ struct wfd_dbus
|
|||
bool exposed : 1;
|
||||
};
|
||||
|
||||
int wfd_dbus_new(struct wfd_dbus **out, sd_event *loop, sd_bus *bus)
|
||||
int dispd_dbus_new(struct dispd_dbus **out, sd_event *loop, sd_bus *bus)
|
||||
{
|
||||
struct wfd_dbus *wfd_dbus = calloc(1, sizeof(struct wfd_dbus));
|
||||
if(!wfd_dbus) {
|
||||
struct dispd_dbus *dispd_dbus = calloc(1, sizeof(struct dispd_dbus));
|
||||
if(!dispd_dbus) {
|
||||
return log_ENOMEM();
|
||||
}
|
||||
|
||||
wfd_dbus->bus = sd_bus_ref(bus);
|
||||
wfd_dbus->loop = sd_event_ref(loop);
|
||||
dispd_dbus->bus = sd_bus_ref(bus);
|
||||
dispd_dbus->loop = sd_event_ref(loop);
|
||||
|
||||
*out = wfd_dbus;
|
||||
*out = dispd_dbus;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void wfd_dbus_free(struct wfd_dbus *wfd_dbus)
|
||||
void dispd_dbus_free(struct dispd_dbus *dispd_dbus)
|
||||
{
|
||||
if(!wfd_dbus) {
|
||||
if(!dispd_dbus) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(wfd_dbus->exposed) {
|
||||
sd_bus_release_name(wfd_dbus->bus, "org.freedesktop.miracle.wfd");
|
||||
if(dispd_dbus->exposed) {
|
||||
sd_bus_release_name(dispd_dbus->bus, "org.freedesktop.miracle.wfd");
|
||||
}
|
||||
|
||||
if(wfd_dbus->bus) {
|
||||
sd_bus_unref(wfd_dbus->bus);
|
||||
if(dispd_dbus->bus) {
|
||||
sd_bus_unref(dispd_dbus->bus);
|
||||
}
|
||||
|
||||
if(wfd_dbus->loop) {
|
||||
sd_event_unref(wfd_dbus->loop);
|
||||
if(dispd_dbus->loop) {
|
||||
sd_event_unref(dispd_dbus->loop);
|
||||
}
|
||||
|
||||
free(wfd_dbus);
|
||||
free(dispd_dbus);
|
||||
}
|
||||
|
||||
static inline int wfd_dbus_get_sink_path(struct wfd_sink *s, char **out)
|
||||
static inline int dispd_dbus_get_sink_path(struct dispd_sink *s, char **out)
|
||||
{
|
||||
int r = sd_bus_path_encode("/org/freedesktop/miracle/wfd/sink",
|
||||
wfd_sink_get_label(s),
|
||||
dispd_sink_get_label(s),
|
||||
out);
|
||||
if(0 > r) {
|
||||
return log_ERRNO();
|
||||
|
@ -96,10 +96,10 @@ static inline int wfd_dbus_get_sink_path(struct wfd_sink *s, char **out)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static inline int wfd_dbus_get_session_path(struct wfd_session *s, char **out)
|
||||
static inline int dispd_dbus_get_session_path(struct dispd_session *s, char **out)
|
||||
{
|
||||
char buf[64];
|
||||
int r = snprintf(buf, sizeof(buf), "%u", wfd_session_get_id(s));
|
||||
int r = snprintf(buf, sizeof(buf), "%u", dispd_session_get_id(s));
|
||||
if(0 > r) {
|
||||
return log_ERRNO();
|
||||
}
|
||||
|
@ -114,7 +114,7 @@ static inline int wfd_dbus_get_session_path(struct wfd_session *s, char **out)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int wfd_dbus_enum(sd_bus *bus,
|
||||
static int dispd_dbus_enum(sd_bus *bus,
|
||||
const char *path,
|
||||
void *userdata,
|
||||
char ***out,
|
||||
|
@ -122,33 +122,33 @@ static int wfd_dbus_enum(sd_bus *bus,
|
|||
{
|
||||
int r = 0, i = 0;
|
||||
char **nodes, *node;
|
||||
struct wfd_sink *sink;
|
||||
struct wfd_session *session;
|
||||
struct ctl_wfd *wfd = ctl_wfd_get();
|
||||
struct dispd_sink *sink;
|
||||
struct dispd_session *session;
|
||||
struct dispd *dispd = dispd_get();
|
||||
|
||||
if(strcmp("/org/freedesktop/miracle/wfd", path)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(!wfd->n_sinks) {
|
||||
if(!dispd->n_sinks) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
nodes = malloc((wfd->n_sinks + wfd->n_sessions + 1) * sizeof(char *));
|
||||
nodes = malloc((dispd->n_sinks + dispd->n_sessions + 1) * sizeof(char *));
|
||||
if(!nodes) {
|
||||
return log_ENOMEM();
|
||||
}
|
||||
|
||||
ctl_wfd_foreach_sink(sink, wfd) {
|
||||
r = wfd_dbus_get_sink_path(sink, &node);
|
||||
dispd_foreach_sink(sink, dispd) {
|
||||
r = dispd_dbus_get_sink_path(sink, &node);
|
||||
if(0 > r) {
|
||||
goto free_nodes;
|
||||
}
|
||||
nodes[i ++] = node;
|
||||
}
|
||||
|
||||
ctl_wfd_foreach_session(session, wfd) {
|
||||
r = wfd_dbus_get_session_path(session, &node);
|
||||
dispd_foreach_session(session, dispd) {
|
||||
r = dispd_dbus_get_session_path(session, &node);
|
||||
if(0 > r) {
|
||||
goto free_nodes;
|
||||
}
|
||||
|
@ -168,7 +168,7 @@ free_nodes:
|
|||
return log_ERRNO();
|
||||
}
|
||||
|
||||
int _wfd_dbus_object_removed(struct wfd_dbus *wfd_dbus,
|
||||
int _dispd_dbus_object_removed(struct dispd_dbus *dispd_dbus,
|
||||
const char *path,
|
||||
const char **ifaces,
|
||||
size_t n_ifaces)
|
||||
|
@ -176,11 +176,11 @@ int _wfd_dbus_object_removed(struct wfd_dbus *wfd_dbus,
|
|||
int i, r;
|
||||
_sd_bus_message_unref_ sd_bus_message *m = NULL;
|
||||
|
||||
if(!wfd_dbus) {
|
||||
if(!dispd_dbus) {
|
||||
return -ECANCELED;
|
||||
}
|
||||
|
||||
r = sd_bus_message_new_signal(wfd_dbus->bus,
|
||||
r = sd_bus_message_new_signal(dispd_dbus->bus,
|
||||
&m,
|
||||
"/org/freedesktop/miracle/wfd",
|
||||
"org.freedesktop.DBus.ObjectManager",
|
||||
|
@ -211,7 +211,7 @@ int _wfd_dbus_object_removed(struct wfd_dbus *wfd_dbus,
|
|||
return log_ERRNO();
|
||||
}
|
||||
|
||||
r = sd_bus_send(wfd_dbus->bus, m, NULL);
|
||||
r = sd_bus_send(dispd_dbus->bus, m, NULL);
|
||||
if(0 > r) {
|
||||
return log_ERRNO();
|
||||
}
|
||||
|
@ -219,7 +219,7 @@ int _wfd_dbus_object_removed(struct wfd_dbus *wfd_dbus,
|
|||
return 0;
|
||||
}
|
||||
|
||||
int _wfd_dbus_object_added(struct wfd_dbus *wfd_dbus,
|
||||
int _dispd_dbus_object_added(struct dispd_dbus *dispd_dbus,
|
||||
const char *path,
|
||||
const char **ifaces,
|
||||
size_t n_ifaces)
|
||||
|
@ -227,11 +227,11 @@ int _wfd_dbus_object_added(struct wfd_dbus *wfd_dbus,
|
|||
int i, r;
|
||||
_sd_bus_message_unref_ sd_bus_message *m = NULL;
|
||||
|
||||
if(!wfd_dbus) {
|
||||
if(!dispd_dbus) {
|
||||
return -ECANCELED;
|
||||
}
|
||||
|
||||
r = sd_bus_message_new_signal(wfd_dbus->bus,
|
||||
r = sd_bus_message_new_signal(dispd_dbus->bus,
|
||||
&m,
|
||||
"/org/freedesktop/miracle/wfd",
|
||||
"org.freedesktop.DBus.ObjectManager",
|
||||
|
@ -262,7 +262,7 @@ int _wfd_dbus_object_added(struct wfd_dbus *wfd_dbus,
|
|||
return log_ERRNO();
|
||||
}
|
||||
|
||||
r = sd_bus_send(wfd_dbus->bus, m, NULL);
|
||||
r = sd_bus_send(dispd_dbus->bus, m, NULL);
|
||||
if(0 > r) {
|
||||
return log_ERRNO();
|
||||
}
|
||||
|
@ -270,15 +270,15 @@ int _wfd_dbus_object_added(struct wfd_dbus *wfd_dbus,
|
|||
return 0;
|
||||
}
|
||||
|
||||
int wfd_fn_sink_new(struct wfd_sink *s)
|
||||
int dispd_fn_sink_new(struct dispd_sink *s)
|
||||
{
|
||||
_shl_free_ char *path = NULL;
|
||||
int r = wfd_dbus_get_sink_path(s, &path);
|
||||
int r = dispd_dbus_get_sink_path(s, &path);
|
||||
if(0 > r) {
|
||||
return log_ERRNO();
|
||||
}
|
||||
|
||||
r = wfd_dbus_object_added(path, "org.freedesktop.miracle.wfd.Sink");
|
||||
r = dispd_dbus_object_added(path, "org.freedesktop.miracle.wfd.Sink");
|
||||
if(0 > r) {
|
||||
return log_ERRNO();
|
||||
}
|
||||
|
@ -286,15 +286,15 @@ int wfd_fn_sink_new(struct wfd_sink *s)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int wfd_fn_sink_free(struct wfd_sink *s)
|
||||
int dispd_fn_sink_free(struct dispd_sink *s)
|
||||
{
|
||||
_shl_free_ char *path = NULL;
|
||||
int r = wfd_dbus_get_sink_path(s, &path);
|
||||
int r = dispd_dbus_get_sink_path(s, &path);
|
||||
if(0 > r) {
|
||||
return log_ERRNO();
|
||||
}
|
||||
|
||||
r = wfd_dbus_object_removed(path, "org.freedesktop.miracle.wfd.Sink");
|
||||
r = dispd_dbus_object_removed(path, "org.freedesktop.miracle.wfd.Sink");
|
||||
if(0 > r) {
|
||||
return log_ERRNO();
|
||||
}
|
||||
|
@ -302,22 +302,22 @@ int wfd_fn_sink_free(struct wfd_sink *s)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int _wfd_fn_sink_properties_changed(struct wfd_sink *s, char **names)
|
||||
int _dispd_fn_sink_properties_changed(struct dispd_sink *s, char **names)
|
||||
{
|
||||
_shl_free_ char *path = NULL;
|
||||
int r;
|
||||
struct wfd_dbus *wfd_dbus = wfd_dbus_get();
|
||||
struct dispd_dbus *dispd_dbus = dispd_dbus_get();
|
||||
|
||||
if(!wfd_dbus) {
|
||||
if(!dispd_dbus) {
|
||||
return log_ERR(-ECANCELED);
|
||||
}
|
||||
|
||||
r = wfd_dbus_get_sink_path(s, &path);
|
||||
r = dispd_dbus_get_sink_path(s, &path);
|
||||
if(0 > r) {
|
||||
return log_ERR(r);
|
||||
}
|
||||
|
||||
r = sd_bus_emit_properties_changed_strv(wfd_dbus->bus,
|
||||
r = sd_bus_emit_properties_changed_strv(dispd_dbus->bus,
|
||||
path,
|
||||
"org.freedesktop.miracle.wfd.Sink",
|
||||
names);
|
||||
|
@ -328,7 +328,7 @@ int _wfd_fn_sink_properties_changed(struct wfd_sink *s, char **names)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int wfd_dbus_find_sink(sd_bus *bus,
|
||||
static int dispd_dbus_find_sink(sd_bus *bus,
|
||||
const char *path,
|
||||
const char *interface,
|
||||
void *userdata,
|
||||
|
@ -336,7 +336,7 @@ static int wfd_dbus_find_sink(sd_bus *bus,
|
|||
sd_bus_error *ret_error)
|
||||
{
|
||||
_shl_free_ char *node = NULL;
|
||||
struct wfd_sink *sink;
|
||||
struct dispd_sink *sink;
|
||||
int r = sd_bus_path_decode(path,
|
||||
"/org/freedesktop/miracle/wfd/sink",
|
||||
&node);
|
||||
|
@ -344,7 +344,7 @@ static int wfd_dbus_find_sink(sd_bus *bus,
|
|||
return r;
|
||||
}
|
||||
|
||||
r = ctl_wfd_find_sink_by_label(ctl_wfd_get(), node, &sink);
|
||||
r = dispd_find_sink_by_label(dispd_get(), node, &sink);
|
||||
if(r) {
|
||||
*ret_found = sink;
|
||||
}
|
||||
|
@ -352,15 +352,15 @@ static int wfd_dbus_find_sink(sd_bus *bus,
|
|||
return r;
|
||||
}
|
||||
|
||||
int wfd_fn_session_new(struct wfd_session *s)
|
||||
int dispd_fn_session_new(struct dispd_session *s)
|
||||
{
|
||||
_shl_free_ char *path = NULL;
|
||||
int r = wfd_dbus_get_session_path(s, &path);
|
||||
int r = dispd_dbus_get_session_path(s, &path);
|
||||
if(0 > r) {
|
||||
return log_ERRNO();
|
||||
}
|
||||
|
||||
r = wfd_dbus_object_added(path, "org.freedesktop.miracle.wfd.Session");
|
||||
r = dispd_dbus_object_added(path, "org.freedesktop.miracle.wfd.Session");
|
||||
if(0 > r) {
|
||||
return log_ERRNO();
|
||||
}
|
||||
|
@ -368,15 +368,15 @@ int wfd_fn_session_new(struct wfd_session *s)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int wfd_fn_session_free(struct wfd_session *s)
|
||||
int dispd_fn_session_free(struct dispd_session *s)
|
||||
{
|
||||
_shl_free_ char *path = NULL;
|
||||
int r = wfd_dbus_get_session_path(s, &path);
|
||||
int r = dispd_dbus_get_session_path(s, &path);
|
||||
if(0 > r) {
|
||||
return log_ERRNO();
|
||||
}
|
||||
|
||||
r = wfd_dbus_object_removed(path, "org.freedesktop.miracle.wfd.Session");
|
||||
r = dispd_dbus_object_removed(path, "org.freedesktop.miracle.wfd.Session");
|
||||
if(0 > r) {
|
||||
return log_ERRNO();
|
||||
}
|
||||
|
@ -384,14 +384,14 @@ int wfd_fn_session_free(struct wfd_session *s)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int wfd_dbus_find_session(sd_bus *bus,
|
||||
static int dispd_dbus_find_session(sd_bus *bus,
|
||||
const char *path,
|
||||
const char *interface,
|
||||
void *userdata,
|
||||
void **ret_found,
|
||||
sd_bus_error *ret_error)
|
||||
{
|
||||
struct wfd_session *s;
|
||||
struct dispd_session *s;
|
||||
_shl_free_ char *node = NULL;
|
||||
int r = sd_bus_path_decode(path,
|
||||
"/org/freedesktop/miracle/wfd/session",
|
||||
|
@ -400,7 +400,7 @@ static int wfd_dbus_find_session(sd_bus *bus,
|
|||
return log_ERRNO();
|
||||
}
|
||||
|
||||
r = ctl_wfd_find_session_by_id(ctl_wfd_get(),
|
||||
r = dispd_find_session_by_id(dispd_get(),
|
||||
strtoull(node, NULL, 10),
|
||||
&s);
|
||||
if(r) {
|
||||
|
@ -455,19 +455,19 @@ static int get_user_runtime_path(char **out, sd_bus *bus, uid_t uid)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int wfd_dbus_sink_start_session(sd_bus_message *m,
|
||||
static int dispd_dbus_sink_start_session(sd_bus_message *m,
|
||||
void *userdata,
|
||||
sd_bus_error *ret_error)
|
||||
{
|
||||
_wfd_session_unref_ struct wfd_session *sess = NULL;
|
||||
_dispd_session_unref_ struct dispd_session *sess = NULL;
|
||||
_shl_free_ char *path = NULL, *disp_type_name = NULL, *disp_name = NULL;
|
||||
_sd_bus_creds_unref_ sd_bus_creds *creds = NULL;
|
||||
_shl_free_ char *runtime_path = NULL;
|
||||
struct wfd_sink *sink = userdata;
|
||||
struct dispd_sink *sink = userdata;
|
||||
char *disp_params;
|
||||
const char *disp, *disp_auth;
|
||||
const char *audio_dev;
|
||||
struct wfd_rectangle rect;
|
||||
struct dispd_rectangle rect;
|
||||
pid_t pid;
|
||||
uid_t uid;
|
||||
gid_t gid;
|
||||
|
@ -497,12 +497,12 @@ static int wfd_dbus_sink_start_session(sd_bus_message *m,
|
|||
return log_EINVAL();
|
||||
}
|
||||
|
||||
r = wfd_sink_create_session(sink, &sess);
|
||||
r = dispd_sink_create_session(sink, &sess);
|
||||
if(0 > r) {
|
||||
return log_ERR(r);
|
||||
}
|
||||
|
||||
wfd_session_set_disp_type(sess, WFD_DISPLAY_SERVER_TYPE_X);
|
||||
dispd_session_set_disp_type(sess, DISPD_DISPLAY_SERVER_TYPE_X);
|
||||
if(0 > r) {
|
||||
return log_ERR(r);
|
||||
}
|
||||
|
@ -512,32 +512,32 @@ static int wfd_dbus_sink_start_session(sd_bus_message *m,
|
|||
*disp_params ++ = '\0';
|
||||
}
|
||||
|
||||
r = wfd_session_set_disp_name(sess, disp_name);
|
||||
r = dispd_session_set_disp_name(sess, disp_name);
|
||||
if(0 > r) {
|
||||
return log_ERR(r);
|
||||
}
|
||||
|
||||
r = wfd_session_set_disp_params(sess, disp_params);
|
||||
r = dispd_session_set_disp_params(sess, disp_params);
|
||||
if(0 > r) {
|
||||
return log_ERR(r);
|
||||
}
|
||||
|
||||
r = wfd_session_set_disp_auth(sess, disp_auth);
|
||||
r = dispd_session_set_disp_auth(sess, disp_auth);
|
||||
if(0 > r) {
|
||||
return log_ERR(r);
|
||||
}
|
||||
|
||||
r = wfd_session_set_disp_dimension(sess, &rect);
|
||||
r = dispd_session_set_disp_dimension(sess, &rect);
|
||||
if(0 > r) {
|
||||
return log_ERR(r);
|
||||
}
|
||||
|
||||
r = wfd_session_set_audio_type(sess, WFD_AUDIO_SERVER_TYPE_PULSE_AUDIO);
|
||||
r = dispd_session_set_audio_type(sess, DISPD_AUDIO_SERVER_TYPE_PULSE_AUDIO);
|
||||
if(0 > r) {
|
||||
return log_ERR(r);
|
||||
}
|
||||
|
||||
r = wfd_session_set_audio_dev_name(sess, audio_dev);
|
||||
r = dispd_session_set_audio_dev_name(sess, audio_dev);
|
||||
if(0 > r) {
|
||||
return log_ERR(r);
|
||||
}
|
||||
|
@ -561,19 +561,19 @@ static int wfd_dbus_sink_start_session(sd_bus_message *m,
|
|||
if(0 > r) {
|
||||
return log_ERR(r);
|
||||
}
|
||||
wfd_session_set_client_pid(sess, gid);
|
||||
dispd_session_set_client_pid(sess, gid);
|
||||
|
||||
r = sd_bus_creds_get_uid(creds, &uid);
|
||||
if(0 > r) {
|
||||
return log_ERR(r);
|
||||
}
|
||||
wfd_session_set_client_uid(sess, uid);
|
||||
dispd_session_set_client_uid(sess, uid);
|
||||
|
||||
sd_bus_creds_get_gid(creds, &gid);
|
||||
if(0 > r) {
|
||||
return log_ERR(r);
|
||||
}
|
||||
wfd_session_set_client_gid(sess, gid);
|
||||
dispd_session_set_client_gid(sess, gid);
|
||||
|
||||
r = get_user_runtime_path(&runtime_path,
|
||||
sd_bus_message_get_bus(m),
|
||||
|
@ -582,17 +582,17 @@ static int wfd_dbus_sink_start_session(sd_bus_message *m,
|
|||
return log_ERR(r);
|
||||
}
|
||||
|
||||
r = wfd_session_set_runtime_path(sess, runtime_path);
|
||||
r = dispd_session_set_runtime_path(sess, runtime_path);
|
||||
if(0 > r) {
|
||||
return log_ERR(r);
|
||||
}
|
||||
|
||||
r = wfd_session_start(sess);
|
||||
r = dispd_session_start(sess);
|
||||
if(0 > r) {
|
||||
return log_ERR(r);
|
||||
}
|
||||
|
||||
r = wfd_dbus_get_session_path(sess, &path);
|
||||
r = dispd_dbus_get_session_path(sess, &path);
|
||||
if(0 > r) {
|
||||
return log_ERR(r);
|
||||
}
|
||||
|
@ -605,7 +605,7 @@ static int wfd_dbus_sink_start_session(sd_bus_message *m,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int wfd_dbus_sink_get_session(sd_bus *bus,
|
||||
static int dispd_dbus_sink_get_session(sd_bus *bus,
|
||||
const char *path,
|
||||
const char *interface,
|
||||
const char *property,
|
||||
|
@ -613,12 +613,12 @@ static int wfd_dbus_sink_get_session(sd_bus *bus,
|
|||
void *userdata,
|
||||
sd_bus_error *ret_error)
|
||||
{
|
||||
struct wfd_sink *s = userdata;
|
||||
struct dispd_sink *s = userdata;
|
||||
_shl_free_ char *session_path = NULL;
|
||||
int r;
|
||||
|
||||
if(s->session) {
|
||||
r = wfd_dbus_get_session_path(s->session, &session_path);
|
||||
r = dispd_dbus_get_session_path(s->session, &session_path);
|
||||
if(0 > r) {
|
||||
return log_ERRNO();
|
||||
}
|
||||
|
@ -638,7 +638,7 @@ static int wfd_dbus_sink_get_session(sd_bus *bus,
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int wfd_dbus_sink_get_peer(sd_bus *bus,
|
||||
static int dispd_dbus_sink_get_peer(sd_bus *bus,
|
||||
const char *path,
|
||||
const char *interface,
|
||||
const char *property,
|
||||
|
@ -646,7 +646,7 @@ static int wfd_dbus_sink_get_peer(sd_bus *bus,
|
|||
void *userdata,
|
||||
sd_bus_error *ret_error)
|
||||
{
|
||||
struct wfd_sink *s = userdata;
|
||||
struct dispd_sink *s = userdata;
|
||||
_shl_free_ char *peer_path = NULL;
|
||||
int r = sd_bus_path_encode("/org/freedesktop/miracle/wifi/peer",
|
||||
s->label,
|
||||
|
@ -663,7 +663,7 @@ static int wfd_dbus_sink_get_peer(sd_bus *bus,
|
|||
return 1;
|
||||
}
|
||||
|
||||
//static int wfd_dbus_sink_has_audio(sd_bus *bus,
|
||||
//static int dispd_dbus_sink_has_audio(sd_bus *bus,
|
||||
// const char *path,
|
||||
// const char *interface,
|
||||
// const char *property,
|
||||
|
@ -673,15 +673,15 @@ static int wfd_dbus_sink_get_peer(sd_bus *bus,
|
|||
//{
|
||||
// return 0;
|
||||
//}
|
||||
static int wfd_dbus_session_resume(sd_bus_message *m,
|
||||
static int dispd_dbus_session_resume(sd_bus_message *m,
|
||||
void *userdata,
|
||||
sd_bus_error *ret_error)
|
||||
{
|
||||
struct wfd_session *s = userdata;
|
||||
struct dispd_session *s = userdata;
|
||||
int r;
|
||||
|
||||
if(wfd_session_is_established(s)) {
|
||||
r = wfd_session_resume(s);
|
||||
if(dispd_session_is_established(s)) {
|
||||
r = dispd_session_resume(s);
|
||||
if(0 > r) {
|
||||
return log_ERRNO();
|
||||
}
|
||||
|
@ -698,15 +698,15 @@ static int wfd_dbus_session_resume(sd_bus_message *m,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int wfd_dbus_session_pause(sd_bus_message *m,
|
||||
static int dispd_dbus_session_pause(sd_bus_message *m,
|
||||
void *userdata,
|
||||
sd_bus_error *ret_error)
|
||||
{
|
||||
struct wfd_session *s = userdata;
|
||||
struct dispd_session *s = userdata;
|
||||
int r;
|
||||
|
||||
if(wfd_session_is_established(s)) {
|
||||
r = wfd_session_pause(s);
|
||||
if(dispd_session_is_established(s)) {
|
||||
r = dispd_session_pause(s);
|
||||
if(0 > r) {
|
||||
return log_ERRNO();
|
||||
}
|
||||
|
@ -723,12 +723,12 @@ static int wfd_dbus_session_pause(sd_bus_message *m,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int wfd_dbus_session_teardown(sd_bus_message *m,
|
||||
static int dispd_dbus_session_teardown(sd_bus_message *m,
|
||||
void *userdata,
|
||||
sd_bus_error *ret_error)
|
||||
{
|
||||
struct wfd_session *s = userdata;
|
||||
int r = wfd_session_teardown(s);
|
||||
struct dispd_session *s = userdata;
|
||||
int r = dispd_session_teardown(s);
|
||||
if(0 > r) {
|
||||
return log_ERRNO();
|
||||
}
|
||||
|
@ -741,7 +741,7 @@ static int wfd_dbus_session_teardown(sd_bus_message *m,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int wfd_dbus_session_get_sink(sd_bus *bus,
|
||||
static int dispd_dbus_session_get_sink(sd_bus *bus,
|
||||
const char *path,
|
||||
const char *interface,
|
||||
const char *property,
|
||||
|
@ -749,15 +749,15 @@ static int wfd_dbus_session_get_sink(sd_bus *bus,
|
|||
void *userdata,
|
||||
sd_bus_error *ret_error)
|
||||
{
|
||||
struct wfd_session *s = userdata;
|
||||
struct dispd_session *s = userdata;
|
||||
_shl_free_ char *sink_path = NULL;
|
||||
int r;
|
||||
|
||||
if(wfd_session_get_dir(s) != WFD_SESSION_DIR_OUT) {
|
||||
if(dispd_session_get_dir(s) != DISPD_SESSION_DIR_OUT) {
|
||||
sink_path = strdup("/");
|
||||
}
|
||||
else {
|
||||
wfd_dbus_get_sink_path(wfd_out_session_get_sink(s), &sink_path);
|
||||
dispd_dbus_get_sink_path(dispd_out_session_get_sink(s), &sink_path);
|
||||
}
|
||||
if(!sink_path) {
|
||||
return log_ENOMEM();
|
||||
|
@ -771,7 +771,7 @@ static int wfd_dbus_session_get_sink(sd_bus *bus,
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int wfd_dbus_get_session_presentation_url(sd_bus *bus,
|
||||
static int dispd_dbus_get_session_presentation_url(sd_bus *bus,
|
||||
const char *path,
|
||||
const char *interface,
|
||||
const char *property,
|
||||
|
@ -779,10 +779,10 @@ static int wfd_dbus_get_session_presentation_url(sd_bus *bus,
|
|||
void *userdata,
|
||||
sd_bus_error *ret_error)
|
||||
{
|
||||
struct wfd_session *s = userdata;
|
||||
struct dispd_session *s = userdata;
|
||||
int r = sd_bus_message_append(reply,
|
||||
"s",
|
||||
wfd_session_get_stream_url(s) ? : "");
|
||||
dispd_session_get_stream_url(s) ? : "");
|
||||
if(0 > r) {
|
||||
return log_ERRNO();
|
||||
}
|
||||
|
@ -790,7 +790,7 @@ static int wfd_dbus_get_session_presentation_url(sd_bus *bus,
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int wfd_dbus_get_session_state(sd_bus *bus,
|
||||
static int dispd_dbus_get_session_state(sd_bus *bus,
|
||||
const char *path,
|
||||
const char *interface,
|
||||
const char *property,
|
||||
|
@ -798,8 +798,8 @@ static int wfd_dbus_get_session_state(sd_bus *bus,
|
|||
void *userdata,
|
||||
sd_bus_error *ret_error)
|
||||
{
|
||||
struct wfd_session *s = userdata;
|
||||
int r = sd_bus_message_append(reply, "i", wfd_session_get_state(s));
|
||||
struct dispd_session *s = userdata;
|
||||
int r = sd_bus_message_append(reply, "i", dispd_session_get_state(s));
|
||||
if(0 > r) {
|
||||
return log_ERRNO();
|
||||
}
|
||||
|
@ -807,22 +807,22 @@ static int wfd_dbus_get_session_state(sd_bus *bus,
|
|||
return 1;
|
||||
}
|
||||
|
||||
int _wfd_fn_session_properties_changed(struct wfd_session *s, char **names)
|
||||
int _dispd_fn_session_properties_changed(struct dispd_session *s, char **names)
|
||||
{
|
||||
_shl_free_ char *path = NULL;
|
||||
int r;
|
||||
struct wfd_dbus *wfd_dbus = wfd_dbus_get();
|
||||
struct dispd_dbus *dispd_dbus = dispd_dbus_get();
|
||||
|
||||
if(!wfd_dbus) {
|
||||
if(!dispd_dbus) {
|
||||
return -ECANCELED;
|
||||
}
|
||||
|
||||
r = wfd_dbus_get_session_path(s, &path);
|
||||
r = dispd_dbus_get_session_path(s, &path);
|
||||
if(0 > r) {
|
||||
return log_ERRNO();
|
||||
}
|
||||
|
||||
r = sd_bus_emit_properties_changed_strv(wfd_dbus_get()->bus,
|
||||
r = sd_bus_emit_properties_changed_strv(dispd_dbus_get()->bus,
|
||||
path,
|
||||
"org.freedesktop.miracle.wfd.Session",
|
||||
names);
|
||||
|
@ -833,13 +833,13 @@ int _wfd_fn_session_properties_changed(struct wfd_session *s, char **names)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int wfd_dbus_shutdown(sd_bus_message *m,
|
||||
static int dispd_dbus_shutdown(sd_bus_message *m,
|
||||
void *userdata,
|
||||
sd_bus_error *ret_error)
|
||||
{
|
||||
int r;
|
||||
|
||||
ctl_wfd_shutdown(ctl_wfd_get());
|
||||
dispd_shutdown(dispd_get());
|
||||
|
||||
r = sd_bus_reply_method_return(m, NULL);
|
||||
if(0 > r) {
|
||||
|
@ -849,86 +849,86 @@ static int wfd_dbus_shutdown(sd_bus_message *m,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static const sd_bus_vtable wfd_dbus_vtable[] = {
|
||||
static const sd_bus_vtable dispd_dbus_vtable[] = {
|
||||
SD_BUS_VTABLE_START(0),
|
||||
SD_BUS_METHOD("Shutdown", NULL, NULL, wfd_dbus_shutdown, SD_BUS_VTABLE_UNPRIVILEGED),
|
||||
SD_BUS_METHOD("Shutdown", NULL, NULL, dispd_dbus_shutdown, SD_BUS_VTABLE_UNPRIVILEGED),
|
||||
SD_BUS_VTABLE_END,
|
||||
};
|
||||
|
||||
static const sd_bus_vtable wfd_dbus_sink_vtable[] = {
|
||||
static const sd_bus_vtable dispd_dbus_sink_vtable[] = {
|
||||
SD_BUS_VTABLE_START(0),
|
||||
SD_BUS_METHOD("StartSession", "ssuuuus", "o", wfd_dbus_sink_start_session, SD_BUS_VTABLE_UNPRIVILEGED),
|
||||
/*SD_BUS_PROPERTY("AudioFormats", "a{sv}", wfd_dbus_sink_get_audio_formats, 0, SD_BUS_VTABLE_PROPERTY_CONST),*/
|
||||
/*SD_BUS_PROPERTY("VideoFormats", "a{sv}", wfd_dbus_sink_get_video_formats, 0, SD_BUS_VTABLE_PROPERTY_CONST),*/
|
||||
/*SD_BUS_PROPERTY("HasAudio", "b", wfd_dbus_sink_has_audio, 0, SD_BUS_VTABLE_PROPERTY_CONST),*/
|
||||
/*SD_BUS_PROPERTY("HasVideo", "b", wfd_dbus_sink_has_video, 0, SD_BUS_VTABLE_PROPERTY_CONST),*/
|
||||
SD_BUS_PROPERTY("Session", "o", wfd_dbus_sink_get_session, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
SD_BUS_PROPERTY("Peer", "o", wfd_dbus_sink_get_peer, 0, SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_METHOD("StartSession", "ssuuuus", "o", dispd_dbus_sink_start_session, SD_BUS_VTABLE_UNPRIVILEGED),
|
||||
/*SD_BUS_PROPERTY("AudioFormats", "a{sv}", dispd_dbus_sink_get_audio_formats, 0, SD_BUS_VTABLE_PROPERTY_CONST),*/
|
||||
/*SD_BUS_PROPERTY("VideoFormats", "a{sv}", dispd_dbus_sink_get_video_formats, 0, SD_BUS_VTABLE_PROPERTY_CONST),*/
|
||||
/*SD_BUS_PROPERTY("HasAudio", "b", dispd_dbus_sink_has_audio, 0, SD_BUS_VTABLE_PROPERTY_CONST),*/
|
||||
/*SD_BUS_PROPERTY("HasVideo", "b", dispd_dbus_sink_has_video, 0, SD_BUS_VTABLE_PROPERTY_CONST),*/
|
||||
SD_BUS_PROPERTY("Session", "o", dispd_dbus_sink_get_session, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
SD_BUS_PROPERTY("Peer", "o", dispd_dbus_sink_get_peer, 0, SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_VTABLE_END,
|
||||
};
|
||||
|
||||
static const sd_bus_vtable wfd_dbus_session_vtable[] = {
|
||||
static const sd_bus_vtable dispd_dbus_session_vtable[] = {
|
||||
SD_BUS_VTABLE_START(0),
|
||||
SD_BUS_METHOD("Resume", NULL, NULL, wfd_dbus_session_resume, SD_BUS_VTABLE_UNPRIVILEGED),
|
||||
SD_BUS_METHOD("Pause", NULL, NULL, wfd_dbus_session_pause, SD_BUS_VTABLE_UNPRIVILEGED),
|
||||
SD_BUS_METHOD("Teardown", NULL, NULL, wfd_dbus_session_teardown, SD_BUS_VTABLE_UNPRIVILEGED),
|
||||
SD_BUS_PROPERTY("Sink", "o", wfd_dbus_session_get_sink, 0, SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("Url", "s", wfd_dbus_get_session_presentation_url, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
SD_BUS_PROPERTY("State", "i", wfd_dbus_get_session_state, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
SD_BUS_METHOD("Resume", NULL, NULL, dispd_dbus_session_resume, SD_BUS_VTABLE_UNPRIVILEGED),
|
||||
SD_BUS_METHOD("Pause", NULL, NULL, dispd_dbus_session_pause, SD_BUS_VTABLE_UNPRIVILEGED),
|
||||
SD_BUS_METHOD("Teardown", NULL, NULL, dispd_dbus_session_teardown, SD_BUS_VTABLE_UNPRIVILEGED),
|
||||
SD_BUS_PROPERTY("Sink", "o", dispd_dbus_session_get_sink, 0, SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("Url", "s", dispd_dbus_get_session_presentation_url, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
SD_BUS_PROPERTY("State", "i", dispd_dbus_get_session_state, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
SD_BUS_VTABLE_END,
|
||||
};
|
||||
|
||||
int wfd_dbus_expose(struct wfd_dbus *wfd_dbus)
|
||||
int dispd_dbus_expose(struct dispd_dbus *dispd_dbus)
|
||||
{
|
||||
int r = sd_bus_add_object_vtable(wfd_dbus->bus,
|
||||
int r = sd_bus_add_object_vtable(dispd_dbus->bus,
|
||||
NULL,
|
||||
"/org/freedesktop/miracle/wfd",
|
||||
"org.freedesktop.miracle.wfd",
|
||||
wfd_dbus_vtable,
|
||||
wfd_dbus);
|
||||
dispd_dbus_vtable,
|
||||
dispd_dbus);
|
||||
if(0 > r) {
|
||||
return r;
|
||||
}
|
||||
|
||||
r = sd_bus_add_fallback_vtable(wfd_dbus->bus,
|
||||
r = sd_bus_add_fallback_vtable(dispd_dbus->bus,
|
||||
NULL,
|
||||
"/org/freedesktop/miracle/wfd/sink",
|
||||
"org.freedesktop.miracle.wfd.Sink",
|
||||
wfd_dbus_sink_vtable,
|
||||
wfd_dbus_find_sink,
|
||||
wfd_dbus);
|
||||
dispd_dbus_sink_vtable,
|
||||
dispd_dbus_find_sink,
|
||||
dispd_dbus);
|
||||
if(0 > r) {
|
||||
return r;
|
||||
}
|
||||
|
||||
r = sd_bus_add_fallback_vtable(wfd_dbus->bus,
|
||||
r = sd_bus_add_fallback_vtable(dispd_dbus->bus,
|
||||
NULL,
|
||||
"/org/freedesktop/miracle/wfd/session",
|
||||
"org.freedesktop.miracle.wfd.Session",
|
||||
wfd_dbus_session_vtable,
|
||||
wfd_dbus_find_session,
|
||||
wfd_dbus);
|
||||
dispd_dbus_session_vtable,
|
||||
dispd_dbus_find_session,
|
||||
dispd_dbus);
|
||||
if(0 > r) {
|
||||
return r;
|
||||
}
|
||||
|
||||
r = sd_bus_add_node_enumerator(wfd_dbus->bus,
|
||||
r = sd_bus_add_node_enumerator(dispd_dbus->bus,
|
||||
NULL,
|
||||
"/org/freedesktop/miracle/wfd",
|
||||
wfd_dbus_enum,
|
||||
wfd_dbus);
|
||||
dispd_dbus_enum,
|
||||
dispd_dbus);
|
||||
if(0 > r) {
|
||||
return r;
|
||||
}
|
||||
|
||||
r = sd_bus_add_object_manager(wfd_dbus->bus, NULL, "/org/freedesktop/miracle/wfd");
|
||||
r = sd_bus_add_object_manager(dispd_dbus->bus, NULL, "/org/freedesktop/miracle/wfd");
|
||||
if(0 > r) {
|
||||
return r;
|
||||
}
|
||||
|
||||
r = sd_bus_request_name(wfd_dbus->bus, "org.freedesktop.miracle.wfd", 0);
|
||||
r = sd_bus_request_name(dispd_dbus->bus, "org.freedesktop.miracle.wfd", 0);
|
||||
if(0 < r) {
|
||||
wfd_dbus->exposed = true;
|
||||
dispd_dbus->exposed = true;
|
||||
}
|
||||
|
||||
return r;
|
|
@ -22,26 +22,26 @@
|
|||
#ifndef CTL_WFD_DBUS_H
|
||||
#define CTL_WFD_DBUS_H
|
||||
|
||||
#define wfd_fn_sink_properties_changed(s, namev...) ({ \
|
||||
#define dispd_fn_sink_properties_changed(s, namev...) ({ \
|
||||
char *names[] = { namev, NULL }; \
|
||||
_wfd_fn_sink_properties_changed((s), names); \
|
||||
_dispd_fn_sink_properties_changed((s), names); \
|
||||
})
|
||||
|
||||
#define wfd_fn_session_properties_changed(s, namev...) ({ \
|
||||
#define dispd_fn_session_properties_changed(s, namev...) ({ \
|
||||
char *names[] = { namev, NULL }; \
|
||||
_wfd_fn_session_properties_changed((s), names); \
|
||||
_dispd_fn_session_properties_changed((s), names); \
|
||||
})
|
||||
|
||||
struct wfd_dbus;
|
||||
struct wfd_session;
|
||||
struct wfd_sink;
|
||||
struct dispd_dbus;
|
||||
struct dispd_session;
|
||||
struct dispd_sink;
|
||||
|
||||
struct wfd_dbus * wfd_dbus_get();
|
||||
int wfd_dbus_new(struct wfd_dbus **out, sd_event *loop, sd_bus *bus);
|
||||
void wfd_dbus_free(struct wfd_dbus *wfd_dbus);
|
||||
int wfd_dbus_expose(struct wfd_dbus *wfd_dbus);
|
||||
int _wfd_fn_sink_properties_changed(struct wfd_sink *s, char **names);
|
||||
int _wfd_fn_session_properties_changed(struct wfd_session *s, char **names);
|
||||
struct dispd_dbus * dispd_dbus_get();
|
||||
int dispd_dbus_new(struct dispd_dbus **out, sd_event *loop, sd_bus *bus);
|
||||
void dispd_dbus_free(struct dispd_dbus *dispd_dbus);
|
||||
int dispd_dbus_expose(struct dispd_dbus *dispd_dbus);
|
||||
int _dispd_fn_sink_properties_changed(struct dispd_sink *s, char **names);
|
||||
int _dispd_fn_session_properties_changed(struct dispd_session *s, char **names);
|
||||
|
||||
#endif
|
||||
|
|
@ -27,8 +27,8 @@
|
|||
#include "dispd-encoder.h"
|
||||
#include "shl_macro.h"
|
||||
#include "shl_log.h"
|
||||
#include "wfd-session.h"
|
||||
#include "disp.h"
|
||||
#include "dispd-session.h"
|
||||
#include "dispd.h"
|
||||
#include "util.h"
|
||||
|
||||
struct dispd_encoder
|
||||
|
@ -63,7 +63,7 @@ static int on_bus_info_readable(sd_event_source *source,
|
|||
static void dispd_encoder_set_state(struct dispd_encoder *e,
|
||||
enum dispd_encoder_state state);
|
||||
|
||||
static void dispd_encoder_exec(const char *cmd, int fd, struct wfd_session *s)
|
||||
static void dispd_encoder_exec(const char *cmd, int fd, struct dispd_session *s)
|
||||
{
|
||||
int r;
|
||||
sigset_t mask;
|
||||
|
@ -75,8 +75,8 @@ static void dispd_encoder_exec(const char *cmd, int fd, struct wfd_session *s)
|
|||
sigemptyset(&mask);
|
||||
sigprocmask(SIG_SETMASK, &mask, NULL);
|
||||
|
||||
snprintf(disp, sizeof(disp), "DISPLAY=%s", wfd_session_get_disp_name(s));
|
||||
snprintf(runtime_path, sizeof(runtime_path), "XDG_RUNTIME_DIR=%s", wfd_session_get_runtime_path(s));
|
||||
snprintf(disp, sizeof(disp), "DISPLAY=%s", dispd_session_get_disp_name(s));
|
||||
snprintf(runtime_path, sizeof(runtime_path), "XDG_RUNTIME_DIR=%s", dispd_session_get_runtime_path(s));
|
||||
|
||||
/* after encoder connected to DBus, write unique name to fd 3,
|
||||
* so we can controll it through DBus
|
||||
|
@ -92,13 +92,13 @@ static void dispd_encoder_exec(const char *cmd, int fd, struct wfd_session *s)
|
|||
}
|
||||
|
||||
// TODO drop caps and don't let user raises thier caps
|
||||
r = setgid(wfd_session_get_client_gid(s));
|
||||
r = setgid(dispd_session_get_client_gid(s));
|
||||
if(0 > r) {
|
||||
log_vERRNO();
|
||||
goto error;
|
||||
}
|
||||
|
||||
r = setuid(wfd_session_get_client_uid(s));
|
||||
r = setuid(dispd_session_get_client_uid(s));
|
||||
if(0 > r) {
|
||||
log_vERRNO();
|
||||
goto error;
|
||||
|
@ -222,7 +222,7 @@ static int on_child_terminated(sd_event_source *source,
|
|||
return 0;
|
||||
}
|
||||
|
||||
int dispd_encoder_spawn(struct dispd_encoder **out, struct wfd_session *s)
|
||||
int dispd_encoder_spawn(struct dispd_encoder **out, struct dispd_session *s)
|
||||
{
|
||||
_dispd_encoder_unref_ struct dispd_encoder *e = NULL;
|
||||
int fds[2] = { -1, -1 };
|
||||
|
@ -233,8 +233,8 @@ int dispd_encoder_spawn(struct dispd_encoder **out, struct wfd_session *s)
|
|||
assert_ret(s);
|
||||
|
||||
r = dispd_encoder_new(&e,
|
||||
wfd_session_get_client_uid(s),
|
||||
wfd_session_get_client_gid(s));
|
||||
dispd_session_get_client_uid(s),
|
||||
dispd_session_get_client_gid(s));
|
||||
if(0 > r) {
|
||||
goto end;
|
||||
}
|
||||
|
@ -255,7 +255,7 @@ int dispd_encoder_spawn(struct dispd_encoder **out, struct wfd_session *s)
|
|||
dispd_encoder_exec("gstencoder", fds[1], s);
|
||||
}
|
||||
|
||||
r = sd_event_add_child(ctl_wfd_get_loop(),
|
||||
r = sd_event_add_child(dispd_get_loop(),
|
||||
&e->child_source,
|
||||
pid,
|
||||
WEXITED,
|
||||
|
@ -265,7 +265,7 @@ int dispd_encoder_spawn(struct dispd_encoder **out, struct wfd_session *s)
|
|||
goto close_pipe;
|
||||
}
|
||||
|
||||
r = sd_event_add_io(ctl_wfd_get_loop(),
|
||||
r = sd_event_add_io(dispd_get_loop(),
|
||||
&e->pipe_source,
|
||||
fds[0],
|
||||
EPOLLIN,
|
||||
|
@ -604,7 +604,7 @@ static int on_bus_info_readable(sd_event_source *source,
|
|||
goto error;
|
||||
}
|
||||
|
||||
r = sd_bus_attach_event(e->bus, ctl_wfd_get_loop(), 0);
|
||||
r = sd_bus_attach_event(e->bus, dispd_get_loop(), 0);
|
||||
if(0 > r) {
|
||||
log_vERR(r);
|
||||
goto error;
|
||||
|
@ -731,19 +731,19 @@ static int config_append(sd_bus_message *m,
|
|||
return 0;
|
||||
}
|
||||
|
||||
int dispd_encoder_configure(struct dispd_encoder *e, struct wfd_session *s)
|
||||
int dispd_encoder_configure(struct dispd_encoder *e, struct dispd_session *s)
|
||||
{
|
||||
_cleanup_sd_bus_message_ sd_bus_message *call = NULL;
|
||||
_cleanup_sd_bus_message_ sd_bus_message *reply = NULL;
|
||||
_cleanup_sd_bus_error_ sd_bus_error error = SD_BUS_ERROR_NULL;
|
||||
const struct wfd_rectangle *rect;
|
||||
struct wfd_sink *sink;
|
||||
const struct dispd_rectangle *rect;
|
||||
struct dispd_sink *sink;
|
||||
int r;
|
||||
|
||||
assert_ret(e);
|
||||
assert_ret(e->bus);
|
||||
assert_ret(s);
|
||||
assert_ret(wfd_is_out_session(s));
|
||||
assert_ret(dispd_is_out_session(s));
|
||||
|
||||
r = sd_bus_message_new_method_call(e->bus,
|
||||
&call,
|
||||
|
@ -760,7 +760,7 @@ int dispd_encoder_configure(struct dispd_encoder *e, struct wfd_session *s)
|
|||
return log_ERR(r);
|
||||
}
|
||||
|
||||
sink = wfd_out_session_get_sink(s);
|
||||
sink = dispd_out_session_get_sink(s);
|
||||
r = config_append(call,
|
||||
WFD_ENCODER_CONFIG_PEER_ADDRESS,
|
||||
"s",
|
||||
|
@ -805,7 +805,7 @@ int dispd_encoder_configure(struct dispd_encoder *e, struct wfd_session *s)
|
|||
}
|
||||
}
|
||||
|
||||
rect = wfd_session_get_disp_dimension(s);
|
||||
rect = dispd_session_get_disp_dimension(s);
|
||||
if(rect) {
|
||||
r = config_append(call,
|
||||
WFD_ENCODER_CONFIG_X,
|
||||
|
@ -939,7 +939,7 @@ int dispd_encoder_stop(struct dispd_encoder *e)
|
|||
return r;
|
||||
}
|
||||
|
||||
loop = ctl_wfd_get_loop();
|
||||
loop = dispd_get_loop();
|
||||
r = sd_event_now(loop, CLOCK_MONOTONIC, &now);
|
||||
if(0 > r) {
|
||||
log_vERR(r);
|
||||
|
|
|
@ -61,19 +61,19 @@ enum dispd_encoder_state
|
|||
DISPD_ENCODER_STATE_TERMINATED,
|
||||
};
|
||||
|
||||
struct wfd_session;
|
||||
struct dispd_session;
|
||||
struct dispd_encoder;
|
||||
|
||||
typedef void (*dispd_encoder_state_change_handler)(struct dispd_encoder *e,
|
||||
enum dispd_encoder_state state,
|
||||
void *userdata);
|
||||
|
||||
int dispd_encoder_spawn(struct dispd_encoder **out, struct wfd_session *s);
|
||||
int dispd_encoder_spawn(struct dispd_encoder **out, struct dispd_session *s);
|
||||
struct dispd_encoder * dispd_encoder_ref(struct dispd_encoder *e);
|
||||
void dispd_encoder_unref(struct dispd_encoder *e);
|
||||
void dispd_encoder_unrefp(struct dispd_encoder **e);
|
||||
|
||||
int dispd_encoder_configure(struct dispd_encoder *e, struct wfd_session *s);
|
||||
int dispd_encoder_configure(struct dispd_encoder *e, struct dispd_session *s);
|
||||
int dispd_encoder_start(struct dispd_encoder *e);
|
||||
int dispd_encoder_pause(struct dispd_encoder *e);
|
||||
int dispd_encoder_stop(struct dispd_encoder *e);
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include "wfd-session.h"
|
||||
#include "dispd-session.h"
|
||||
#include "shl_log.h"
|
||||
#include "util.h"
|
||||
#include "rtsp.h"
|
||||
|
@ -34,10 +34,10 @@
|
|||
#define LOCAL_RTCP_PORT 16385
|
||||
#define KEEP_ALIVE_INTERVAL 30
|
||||
|
||||
struct wfd_out_session
|
||||
struct dispd_out_session
|
||||
{
|
||||
struct wfd_session parent;
|
||||
struct wfd_sink *sink;
|
||||
struct dispd_session parent;
|
||||
struct dispd_sink *sink;
|
||||
int fd;
|
||||
|
||||
struct dispd_encoder *encoder;
|
||||
|
@ -48,57 +48,57 @@ struct wfd_out_session
|
|||
static void on_encoder_state_changed(struct dispd_encoder *e,
|
||||
enum dispd_encoder_state state,
|
||||
void *userdata);
|
||||
static void wfd_out_session_cancel_sink_alive_checking(struct wfd_session *s);
|
||||
static void dispd_out_session_cancel_sink_alive_checking(struct dispd_session *s);
|
||||
|
||||
static const struct rtsp_dispatch_entry out_session_rtsp_disp_tbl[];
|
||||
|
||||
int wfd_out_session_new(struct wfd_session **out,
|
||||
int dispd_out_session_new(struct dispd_session **out,
|
||||
unsigned int id,
|
||||
struct wfd_sink *sink)
|
||||
struct dispd_sink *sink)
|
||||
{
|
||||
_wfd_session_unref_ struct wfd_session *s;
|
||||
_dispd_session_unref_ struct dispd_session *s;
|
||||
int r;
|
||||
|
||||
assert_ret(out);
|
||||
assert_ret(id);
|
||||
assert_ret(sink);
|
||||
|
||||
s = calloc(1, sizeof(struct wfd_out_session));
|
||||
s = calloc(1, sizeof(struct dispd_out_session));
|
||||
if(!s) {
|
||||
return log_ENOMEM();
|
||||
}
|
||||
|
||||
r = wfd_session_init(s,
|
||||
r = dispd_session_init(s,
|
||||
id,
|
||||
WFD_SESSION_DIR_OUT,
|
||||
DISPD_SESSION_DIR_OUT,
|
||||
out_session_rtsp_disp_tbl);
|
||||
if(0 > r) {
|
||||
return log_ERR(r);
|
||||
}
|
||||
|
||||
wfd_out_session(s)->fd = -1;
|
||||
wfd_out_session(s)->sink = sink;
|
||||
dispd_out_session(s)->fd = -1;
|
||||
dispd_out_session(s)->sink = sink;
|
||||
|
||||
*out = wfd_session_ref(s);
|
||||
*out = dispd_session_ref(s);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct wfd_sink * wfd_out_session_get_sink(struct wfd_session *s)
|
||||
struct dispd_sink * dispd_out_session_get_sink(struct dispd_session *s)
|
||||
{
|
||||
assert(wfd_is_out_session(s));
|
||||
assert(dispd_is_out_session(s));
|
||||
|
||||
return wfd_out_session(s)->sink;
|
||||
return dispd_out_session(s)->sink;
|
||||
}
|
||||
|
||||
int wfd_out_session_handle_io(struct wfd_session *s,
|
||||
int dispd_out_session_handle_io(struct dispd_session *s,
|
||||
int error,
|
||||
int *out_fd)
|
||||
{
|
||||
socklen_t len;
|
||||
struct sockaddr_storage addr;
|
||||
_shl_close_ int fd = -1;
|
||||
struct wfd_out_session *os = wfd_out_session(s);
|
||||
struct dispd_out_session *os = dispd_out_session(s);
|
||||
|
||||
log_debug("accepting incoming RTSP connection\n");
|
||||
|
||||
|
@ -121,11 +121,11 @@ int wfd_out_session_handle_io(struct wfd_session *s,
|
|||
return 0;
|
||||
}
|
||||
|
||||
int wfd_out_session_initiate_io(struct wfd_session *s,
|
||||
int dispd_out_session_initiate_io(struct dispd_session *s,
|
||||
int *out_fd,
|
||||
uint32_t *out_mask)
|
||||
{
|
||||
struct wfd_out_session *os = wfd_out_session(s);
|
||||
struct dispd_out_session *os = dispd_out_session(s);
|
||||
union wfd_sube sube;
|
||||
struct sockaddr_in addr = {};
|
||||
struct ctl_peer *p = os->sink->peer;
|
||||
|
@ -200,36 +200,36 @@ int wfd_out_session_initiate_io(struct wfd_session *s,
|
|||
return 0;
|
||||
}
|
||||
|
||||
int wfd_out_session_resume(struct wfd_session *s)
|
||||
int dispd_out_session_resume(struct dispd_session *s)
|
||||
{
|
||||
return wfd_session_request(s,
|
||||
return dispd_session_request(s,
|
||||
RTSP_M5_TRIGGER,
|
||||
&(struct wfd_arg_list) wfd_arg_list(wfd_arg_cstr("PLAY")));
|
||||
&(struct dispd_arg_list) dispd_arg_list(dispd_arg_cstr("PLAY")));
|
||||
}
|
||||
|
||||
int wfd_out_session_pause(struct wfd_session *s)
|
||||
int dispd_out_session_pause(struct dispd_session *s)
|
||||
{
|
||||
return wfd_session_request(s,
|
||||
return dispd_session_request(s,
|
||||
RTSP_M5_TRIGGER,
|
||||
&(struct wfd_arg_list) wfd_arg_list(wfd_arg_cstr("PAUSE")));
|
||||
&(struct dispd_arg_list) dispd_arg_list(dispd_arg_cstr("PAUSE")));
|
||||
}
|
||||
|
||||
int wfd_out_session_teardown(struct wfd_session *s)
|
||||
int dispd_out_session_teardown(struct dispd_session *s)
|
||||
{
|
||||
return wfd_session_request(s,
|
||||
return dispd_session_request(s,
|
||||
RTSP_M5_TRIGGER,
|
||||
&(struct wfd_arg_list) wfd_arg_list(wfd_arg_cstr("TEARDOWN")));
|
||||
&(struct dispd_arg_list) dispd_arg_list(dispd_arg_cstr("TEARDOWN")));
|
||||
}
|
||||
|
||||
void wfd_out_session_destroy(struct wfd_session *s)
|
||||
void dispd_out_session_destroy(struct dispd_session *s)
|
||||
{
|
||||
struct wfd_out_session *os;
|
||||
struct dispd_out_session *os;
|
||||
|
||||
assert_vret(s);
|
||||
|
||||
os = wfd_out_session(s);
|
||||
os = dispd_out_session(s);
|
||||
|
||||
wfd_out_session_cancel_sink_alive_checking(s);
|
||||
dispd_out_session_cancel_sink_alive_checking(s);
|
||||
|
||||
if(0 <= os->fd) {
|
||||
close(os->fd);
|
||||
|
@ -246,14 +246,14 @@ void wfd_out_session_destroy(struct wfd_session *s)
|
|||
os->sink = NULL;
|
||||
}
|
||||
|
||||
int wfd_out_session_initiate_request(struct wfd_session *s)
|
||||
int dispd_out_session_initiate_request(struct dispd_session *s)
|
||||
{
|
||||
return wfd_session_request(s,
|
||||
return dispd_session_request(s,
|
||||
RTSP_M1_REQUEST_SINK_OPTIONS,
|
||||
NULL);
|
||||
}
|
||||
|
||||
static int wfd_out_session_handle_get_parameter_reply(struct wfd_session *s,
|
||||
static int dispd_out_session_handle_get_parameter_reply(struct dispd_session *s,
|
||||
struct rtsp_message *m)
|
||||
{
|
||||
struct wfd_video_formats *vformats;
|
||||
|
@ -315,9 +315,9 @@ static int wfd_out_session_handle_get_parameter_reply(struct wfd_session *s,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int wfd_out_session_request_get_parameter(struct wfd_session *s,
|
||||
static int dispd_out_session_request_get_parameter(struct dispd_session *s,
|
||||
struct rtsp *bus,
|
||||
const struct wfd_arg_list *args,
|
||||
const struct dispd_arg_list *args,
|
||||
struct rtsp_message **out)
|
||||
{
|
||||
_rtsp_message_unref_ struct rtsp_message *m = NULL;
|
||||
|
@ -356,7 +356,7 @@ static bool find_strv(const char *str, char **strv)
|
|||
return false;
|
||||
}
|
||||
|
||||
static int wfd_out_session_handle_options_request(struct wfd_session *s,
|
||||
static int dispd_out_session_handle_options_request(struct dispd_session *s,
|
||||
struct rtsp_message *req,
|
||||
struct rtsp_message **out_rep)
|
||||
{
|
||||
|
@ -401,7 +401,7 @@ static int wfd_out_session_handle_options_request(struct wfd_session *s,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int wfd_out_session_handle_options_reply(struct wfd_session *s,
|
||||
static int dispd_out_session_handle_options_reply(struct dispd_session *s,
|
||||
struct rtsp_message *m)
|
||||
{
|
||||
int r;
|
||||
|
@ -432,9 +432,9 @@ static int wfd_out_session_handle_options_reply(struct wfd_session *s,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int wfd_out_session_request_options(struct wfd_session *s,
|
||||
static int dispd_out_session_request_options(struct dispd_session *s,
|
||||
struct rtsp *bus,
|
||||
const struct wfd_arg_list *args,
|
||||
const struct dispd_arg_list *args,
|
||||
struct rtsp_message **out)
|
||||
{
|
||||
_rtsp_message_unref_ struct rtsp_message *m = NULL;
|
||||
|
@ -471,14 +471,14 @@ inline static char * quote_str(const char *s, char *d, size_t len)
|
|||
return d;
|
||||
}
|
||||
|
||||
static int wfd_out_session_handle_pause_request(struct wfd_session *s,
|
||||
static int dispd_out_session_handle_pause_request(struct dispd_session *s,
|
||||
struct rtsp_message *req,
|
||||
struct rtsp_message **out_rep)
|
||||
{
|
||||
_rtsp_message_unref_ struct rtsp_message *m = NULL;
|
||||
int r;
|
||||
|
||||
r = dispd_encoder_pause(wfd_out_session(s)->encoder);
|
||||
r = dispd_encoder_pause(dispd_out_session(s)->encoder);
|
||||
if(0 > r) {
|
||||
return log_ERR(r);
|
||||
}
|
||||
|
@ -496,7 +496,7 @@ static int wfd_out_session_handle_pause_request(struct wfd_session *s,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int wfd_out_session_handle_teardown_request(struct wfd_session *s,
|
||||
static int dispd_out_session_handle_teardown_request(struct dispd_session *s,
|
||||
struct rtsp_message *req,
|
||||
struct rtsp_message **rep)
|
||||
{
|
||||
|
@ -516,7 +516,7 @@ static int wfd_out_session_handle_teardown_request(struct wfd_session *s,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int wfd_out_session_handle_play_request(struct wfd_session *s,
|
||||
static int dispd_out_session_handle_play_request(struct dispd_session *s,
|
||||
struct rtsp_message *req,
|
||||
struct rtsp_message **out_rep)
|
||||
{
|
||||
|
@ -534,7 +534,7 @@ static int wfd_out_session_handle_play_request(struct wfd_session *s,
|
|||
return log_ERR(r);
|
||||
}
|
||||
|
||||
r = asprintf(&v, "%X", wfd_session_get_id(s));
|
||||
r = asprintf(&v, "%X", dispd_session_get_id(s));
|
||||
if(0 > r) {
|
||||
return log_ERR(r);
|
||||
}
|
||||
|
@ -543,12 +543,12 @@ static int wfd_out_session_handle_play_request(struct wfd_session *s,
|
|||
return log_ERR(r);
|
||||
}
|
||||
|
||||
r = sd_event_now(ctl_wfd_get_loop(), CLOCK_MONOTONIC, &now);
|
||||
r = sd_event_now(dispd_get_loop(), CLOCK_MONOTONIC, &now);
|
||||
if(0 > r) {
|
||||
return log_ERR(r);
|
||||
}
|
||||
|
||||
e = wfd_out_session(s)->encoder;
|
||||
e = dispd_out_session(s)->encoder;
|
||||
if(DISPD_ENCODER_STATE_CONFIGURED <= dispd_encoder_get_state(e)) {
|
||||
r = dispd_encoder_start(e);
|
||||
if(0 > r) {
|
||||
|
@ -566,19 +566,19 @@ static void on_encoder_state_changed(struct dispd_encoder *e,
|
|||
void *userdata)
|
||||
{
|
||||
int r = 0;
|
||||
struct wfd_session *s = userdata;
|
||||
struct dispd_session *s = userdata;
|
||||
|
||||
switch(state) {
|
||||
case DISPD_ENCODER_STATE_SPAWNED:
|
||||
if(wfd_session_is_state(s, WFD_SESSION_STATE_SETTING_UP)) {
|
||||
r = dispd_encoder_configure(wfd_out_session(s)->encoder, s);
|
||||
if(dispd_session_is_state(s, DISPD_SESSION_STATE_SETTING_UP)) {
|
||||
r = dispd_encoder_configure(dispd_out_session(s)->encoder, s);
|
||||
if(0 > r) {
|
||||
log_vERR(r);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case DISPD_ENCODER_STATE_CONFIGURED:
|
||||
if(wfd_session_is_state(s, WFD_SESSION_STATE_SETTING_UP)) {
|
||||
if(dispd_session_is_state(s, DISPD_SESSION_STATE_SETTING_UP)) {
|
||||
r = dispd_encoder_start(e);
|
||||
if(0 > r) {
|
||||
log_vERR(r);
|
||||
|
@ -588,13 +588,13 @@ static void on_encoder_state_changed(struct dispd_encoder *e,
|
|||
case DISPD_ENCODER_STATE_READY:
|
||||
break;
|
||||
case DISPD_ENCODER_STATE_STARTED:
|
||||
wfd_session_set_state(s, WFD_SESSION_STATE_PLAYING);
|
||||
dispd_session_set_state(s, DISPD_SESSION_STATE_PLAYING);
|
||||
break;
|
||||
case DISPD_ENCODER_STATE_PAUSED:
|
||||
wfd_session_set_state(s, WFD_SESSION_STATE_PAUSED);
|
||||
dispd_session_set_state(s, DISPD_SESSION_STATE_PAUSED);
|
||||
break;
|
||||
case DISPD_ENCODER_STATE_TERMINATED:
|
||||
wfd_session_teardown(s);
|
||||
dispd_session_teardown(s);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -603,9 +603,9 @@ static void on_encoder_state_changed(struct dispd_encoder *e,
|
|||
return;
|
||||
}
|
||||
|
||||
static int wfd_out_session_request_keep_alive(struct wfd_session *s,
|
||||
static int dispd_out_session_request_keep_alive(struct dispd_session *s,
|
||||
struct rtsp *bus,
|
||||
const struct wfd_arg_list *args,
|
||||
const struct dispd_arg_list *args,
|
||||
struct rtsp_message **out)
|
||||
{
|
||||
_rtsp_message_unref_ struct rtsp_message *m = NULL;
|
||||
|
@ -620,7 +620,7 @@ static int wfd_out_session_request_keep_alive(struct wfd_session *s,
|
|||
return log_ERR(r);
|
||||
}
|
||||
|
||||
r = asprintf(&sess, "%X", wfd_session_get_id(s));
|
||||
r = asprintf(&sess, "%X", dispd_session_get_id(s));
|
||||
if(0 > r) {
|
||||
return log_ERR(r);
|
||||
}
|
||||
|
@ -635,20 +635,20 @@ static int wfd_out_session_request_keep_alive(struct wfd_session *s,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int wfd_out_session_check_sink_alive(sd_event_source *source,
|
||||
static int dispd_out_session_check_sink_alive(sd_event_source *source,
|
||||
uint64_t usec,
|
||||
void *userdata)
|
||||
{
|
||||
struct wfd_session *s = userdata;
|
||||
struct dispd_session *s = userdata;
|
||||
|
||||
wfd_session_request(s, RTSP_M16_KEEPALIVE, NULL);
|
||||
dispd_session_request(s, RTSP_M16_KEEPALIVE, NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int wfd_out_session_init_sink_alive_checking(struct wfd_session *s)
|
||||
static int dispd_out_session_init_sink_alive_checking(struct dispd_session *s)
|
||||
{
|
||||
struct wfd_out_session *os = wfd_out_session(s);
|
||||
struct dispd_out_session *os = dispd_out_session(s);
|
||||
uint64_t now;
|
||||
int r;
|
||||
|
||||
|
@ -658,7 +658,7 @@ static int wfd_out_session_init_sink_alive_checking(struct wfd_session *s)
|
|||
return 0;
|
||||
}
|
||||
|
||||
r = sd_event_now(ctl_wfd_get_loop(), CLOCK_MONOTONIC, &now);
|
||||
r = sd_event_now(dispd_get_loop(), CLOCK_MONOTONIC, &now);
|
||||
if(0 > r) {
|
||||
return log_ERR(r);
|
||||
}
|
||||
|
@ -669,13 +669,13 @@ static int wfd_out_session_init_sink_alive_checking(struct wfd_session *s)
|
|||
* RTSP M16 request messages shall be smaller than the timeout value set by
|
||||
* the RTSP M6
|
||||
* response message minus 5 seconds. */
|
||||
r = sd_event_add_time(ctl_wfd_get_loop(),
|
||||
r = sd_event_add_time(dispd_get_loop(),
|
||||
&os->keep_alive_timer,
|
||||
CLOCK_MONOTONIC,
|
||||
now + (KEEP_ALIVE_INTERVAL - 5) * 1000 * 1000,
|
||||
0,
|
||||
wfd_out_session_check_sink_alive,
|
||||
wfd_session_ref(s));
|
||||
dispd_out_session_check_sink_alive,
|
||||
dispd_session_ref(s));
|
||||
if(0 > r) {
|
||||
return log_ERR(r);
|
||||
}
|
||||
|
@ -683,9 +683,9 @@ static int wfd_out_session_init_sink_alive_checking(struct wfd_session *s)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void wfd_out_session_cancel_sink_alive_checking(struct wfd_session *s)
|
||||
static void dispd_out_session_cancel_sink_alive_checking(struct dispd_session *s)
|
||||
{
|
||||
struct wfd_out_session *os = wfd_out_session(s);
|
||||
struct dispd_out_session *os = dispd_out_session(s);
|
||||
|
||||
assert_vret(s);
|
||||
|
||||
|
@ -697,16 +697,16 @@ static void wfd_out_session_cancel_sink_alive_checking(struct wfd_session *s)
|
|||
sd_event_source_unref(os->keep_alive_timer);
|
||||
os->keep_alive_timer = NULL;
|
||||
|
||||
wfd_session_unref(s);
|
||||
dispd_session_unref(s);
|
||||
}
|
||||
|
||||
static int wfd_out_session_handle_setup_request(struct wfd_session *s,
|
||||
static int dispd_out_session_handle_setup_request(struct dispd_session *s,
|
||||
struct rtsp_message *req,
|
||||
struct rtsp_message **out_rep)
|
||||
{
|
||||
int r;
|
||||
char *l;
|
||||
struct wfd_out_session *os = wfd_out_session(s);
|
||||
struct dispd_out_session *os = dispd_out_session(s);
|
||||
_rtsp_message_unref_ struct rtsp_message *m = NULL;
|
||||
_shl_free_ char *sess = NULL, *trans = NULL;
|
||||
|
||||
|
@ -753,7 +753,7 @@ static int wfd_out_session_handle_setup_request(struct wfd_session *s,
|
|||
}
|
||||
|
||||
r = asprintf(&sess, "%X;timeout=%d",
|
||||
wfd_session_get_id(s),
|
||||
dispd_session_get_id(s),
|
||||
KEEP_ALIVE_INTERVAL);
|
||||
if(0 > r) {
|
||||
return log_ERRNO();
|
||||
|
@ -782,14 +782,14 @@ static int wfd_out_session_handle_setup_request(struct wfd_session *s,
|
|||
dispd_encoder_configure(os->encoder, s);
|
||||
}
|
||||
|
||||
wfd_out_session_init_sink_alive_checking(s);
|
||||
dispd_out_session_init_sink_alive_checking(s);
|
||||
|
||||
*out_rep = (rtsp_message_ref(m), m);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int wfd_out_session_handle_idr_request(struct wfd_session *s,
|
||||
static int dispd_out_session_handle_idr_request(struct dispd_session *s,
|
||||
struct rtsp_message *req,
|
||||
struct rtsp_message **out_rep)
|
||||
{
|
||||
|
@ -804,9 +804,9 @@ static int wfd_out_session_handle_idr_request(struct wfd_session *s,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int wfd_out_session_request_trigger(struct wfd_session *s,
|
||||
static int dispd_out_session_request_trigger(struct dispd_session *s,
|
||||
struct rtsp *bus,
|
||||
const struct wfd_arg_list *args,
|
||||
const struct dispd_arg_list *args,
|
||||
struct rtsp_message **out)
|
||||
{
|
||||
_rtsp_message_unref_ struct rtsp_message *m = NULL;
|
||||
|
@ -815,14 +815,14 @@ static int wfd_out_session_request_trigger(struct wfd_session *s,
|
|||
|
||||
assert(args);
|
||||
|
||||
wfd_arg_list_get(args, 0, &method);
|
||||
dispd_arg_list_get(args, 0, &method);
|
||||
|
||||
assert(method);
|
||||
|
||||
r = rtsp_message_new_request(bus,
|
||||
&m,
|
||||
"SET_PARAMETER",
|
||||
wfd_session_get_stream_url(s));
|
||||
dispd_session_get_stream_url(s));
|
||||
if(0 > r) {
|
||||
return log_ERRNO();
|
||||
}
|
||||
|
@ -839,7 +839,7 @@ static int wfd_out_session_request_trigger(struct wfd_session *s,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int wfd_out_session_request_not_implement(struct wfd_session *s,
|
||||
static int dispd_out_session_request_not_implement(struct dispd_session *s,
|
||||
struct rtsp_message *req,
|
||||
struct rtsp_message **out_rep)
|
||||
{
|
||||
|
@ -849,23 +849,23 @@ static int wfd_out_session_request_not_implement(struct wfd_session *s,
|
|||
NULL);
|
||||
}
|
||||
|
||||
static int wfd_out_session_request_set_parameter(struct wfd_session *s,
|
||||
static int dispd_out_session_request_set_parameter(struct dispd_session *s,
|
||||
struct rtsp *bus,
|
||||
const struct wfd_arg_list *args,
|
||||
const struct dispd_arg_list *args,
|
||||
struct rtsp_message **out)
|
||||
{
|
||||
_rtsp_message_unref_ struct rtsp_message *m = NULL;
|
||||
_shl_free_ char *body = NULL;
|
||||
int r;
|
||||
|
||||
r = wfd_session_gen_stream_url(s,
|
||||
wfd_out_session(s)->sink->peer->local_address,
|
||||
WFD_STREAM_ID_PRIMARY);
|
||||
r = dispd_session_gen_stream_url(s,
|
||||
dispd_out_session(s)->sink->peer->local_address,
|
||||
DISPD_STREAM_ID_PRIMARY);
|
||||
if(0 > r) {
|
||||
return log_ERRNO();
|
||||
}
|
||||
|
||||
s->stream.id = WFD_STREAM_ID_PRIMARY;
|
||||
s->stream.id = DISPD_STREAM_ID_PRIMARY;
|
||||
|
||||
r = asprintf(&body,
|
||||
"wfd_video_formats: 00 00 02 10 %08X %08X %08X 00 0000 0000 00 none none\n"
|
||||
|
@ -877,7 +877,7 @@ static int wfd_out_session_request_set_parameter(struct wfd_session *s,
|
|||
0x80,
|
||||
0,
|
||||
0,
|
||||
wfd_session_get_stream_url(s),
|
||||
dispd_session_get_stream_url(s),
|
||||
s->rtp_ports[0],
|
||||
s->rtp_ports[1]);
|
||||
if(0 > r) {
|
||||
|
@ -904,90 +904,90 @@ static int wfd_out_session_request_set_parameter(struct wfd_session *s,
|
|||
|
||||
static const struct rtsp_dispatch_entry out_session_rtsp_disp_tbl[] = {
|
||||
[RTSP_M1_REQUEST_SINK_OPTIONS] = {
|
||||
.request = wfd_out_session_request_options,
|
||||
.handle_reply = wfd_out_session_handle_options_reply
|
||||
.request = dispd_out_session_request_options,
|
||||
.handle_reply = dispd_out_session_handle_options_reply
|
||||
},
|
||||
[RTSP_M2_REQUEST_SRC_OPTIONS] = {
|
||||
.handle_request = wfd_out_session_handle_options_request,
|
||||
.rule = wfd_arg_list(
|
||||
wfd_arg_dict(
|
||||
wfd_arg_u(WFD_SESSION_ARG_NEXT_REQUEST),
|
||||
wfd_arg_u(RTSP_M3_GET_PARAMETER)
|
||||
.handle_request = dispd_out_session_handle_options_request,
|
||||
.rule = dispd_arg_list(
|
||||
dispd_arg_dict(
|
||||
dispd_arg_u(DISPD_SESSION_ARG_NEXT_REQUEST),
|
||||
dispd_arg_u(RTSP_M3_GET_PARAMETER)
|
||||
),
|
||||
)
|
||||
},
|
||||
[RTSP_M3_GET_PARAMETER] = {
|
||||
.request = wfd_out_session_request_get_parameter,
|
||||
.handle_reply = wfd_out_session_handle_get_parameter_reply,
|
||||
.rule = wfd_arg_list(
|
||||
wfd_arg_dict(
|
||||
wfd_arg_u(WFD_SESSION_ARG_NEXT_REQUEST),
|
||||
wfd_arg_u(RTSP_M4_SET_PARAMETER)
|
||||
.request = dispd_out_session_request_get_parameter,
|
||||
.handle_reply = dispd_out_session_handle_get_parameter_reply,
|
||||
.rule = dispd_arg_list(
|
||||
dispd_arg_dict(
|
||||
dispd_arg_u(DISPD_SESSION_ARG_NEXT_REQUEST),
|
||||
dispd_arg_u(RTSP_M4_SET_PARAMETER)
|
||||
),
|
||||
)
|
||||
},
|
||||
[RTSP_M4_SET_PARAMETER] = {
|
||||
.request = wfd_out_session_request_set_parameter,
|
||||
.rule = wfd_arg_list(
|
||||
wfd_arg_dict(
|
||||
wfd_arg_u(WFD_SESSION_ARG_NEXT_REQUEST),
|
||||
wfd_arg_u(RTSP_M5_TRIGGER)
|
||||
.request = dispd_out_session_request_set_parameter,
|
||||
.rule = dispd_arg_list(
|
||||
dispd_arg_dict(
|
||||
dispd_arg_u(DISPD_SESSION_ARG_NEXT_REQUEST),
|
||||
dispd_arg_u(RTSP_M5_TRIGGER)
|
||||
),
|
||||
wfd_arg_dict(
|
||||
wfd_arg_u(WFD_SESSION_ARG_NEW_STATE),
|
||||
wfd_arg_u(WFD_SESSION_STATE_ESTABLISHED)
|
||||
dispd_arg_dict(
|
||||
dispd_arg_u(DISPD_SESSION_ARG_NEW_STATE),
|
||||
dispd_arg_u(DISPD_SESSION_STATE_ESTABLISHED)
|
||||
),
|
||||
wfd_arg_dict(
|
||||
wfd_arg_u(WFD_SESSION_ARG_REQUEST_ARGS),
|
||||
wfd_arg_arg_list(wfd_arg_cstr("SETUP"))
|
||||
dispd_arg_dict(
|
||||
dispd_arg_u(DISPD_SESSION_ARG_REQUEST_ARGS),
|
||||
dispd_arg_arg_list(dispd_arg_cstr("SETUP"))
|
||||
),
|
||||
)
|
||||
},
|
||||
[RTSP_M5_TRIGGER] = {
|
||||
.request = wfd_out_session_request_trigger,
|
||||
.request = dispd_out_session_request_trigger,
|
||||
},
|
||||
[RTSP_M6_SETUP] = {
|
||||
.handle_request = wfd_out_session_handle_setup_request,
|
||||
.rule = wfd_arg_list(
|
||||
wfd_arg_dict(
|
||||
wfd_arg_u(WFD_SESSION_ARG_NEW_STATE),
|
||||
wfd_arg_u(WFD_SESSION_STATE_SETTING_UP)
|
||||
.handle_request = dispd_out_session_handle_setup_request,
|
||||
.rule = dispd_arg_list(
|
||||
dispd_arg_dict(
|
||||
dispd_arg_u(DISPD_SESSION_ARG_NEW_STATE),
|
||||
dispd_arg_u(DISPD_SESSION_STATE_SETTING_UP)
|
||||
),
|
||||
)
|
||||
},
|
||||
[RTSP_M7_PLAY] = {
|
||||
.handle_request = wfd_out_session_handle_play_request,
|
||||
.handle_request = dispd_out_session_handle_play_request,
|
||||
},
|
||||
[RTSP_M8_TEARDOWN] = {
|
||||
.handle_request = wfd_out_session_handle_teardown_request,
|
||||
.rule = wfd_arg_list(
|
||||
wfd_arg_dict(
|
||||
wfd_arg_u(WFD_SESSION_ARG_NEW_STATE),
|
||||
wfd_arg_u(WFD_SESSION_STATE_TEARING_DOWN)
|
||||
.handle_request = dispd_out_session_handle_teardown_request,
|
||||
.rule = dispd_arg_list(
|
||||
dispd_arg_dict(
|
||||
dispd_arg_u(DISPD_SESSION_ARG_NEW_STATE),
|
||||
dispd_arg_u(DISPD_SESSION_STATE_TEARING_DOWN)
|
||||
),
|
||||
)
|
||||
},
|
||||
[RTSP_M9_PAUSE] = {
|
||||
.handle_request = wfd_out_session_handle_pause_request,
|
||||
.handle_request = dispd_out_session_handle_pause_request,
|
||||
},
|
||||
[RTSP_M10_SET_ROUTE] = {
|
||||
.handle_request = wfd_out_session_request_not_implement
|
||||
.handle_request = dispd_out_session_request_not_implement
|
||||
},
|
||||
[RTSP_M11_SET_CONNECTOR_TYPE] = {
|
||||
.handle_request = wfd_out_session_request_not_implement
|
||||
.handle_request = dispd_out_session_request_not_implement
|
||||
},
|
||||
[RTSP_M12_SET_STANDBY] = {
|
||||
.handle_request = wfd_out_session_request_not_implement
|
||||
.handle_request = dispd_out_session_request_not_implement
|
||||
},
|
||||
[RTSP_M13_REQUEST_IDR] = {
|
||||
.handle_request = wfd_out_session_handle_idr_request,
|
||||
.handle_request = dispd_out_session_handle_idr_request,
|
||||
},
|
||||
[RTSP_M14_ESTABLISH_UIBC] = {
|
||||
},
|
||||
[RTSP_M15_ENABLE_UIBC] = {
|
||||
.handle_request = wfd_out_session_request_not_implement
|
||||
.handle_request = dispd_out_session_request_not_implement
|
||||
},
|
||||
[RTSP_M16_KEEPALIVE] = {
|
||||
.request = wfd_out_session_request_keep_alive,
|
||||
.request = dispd_out_session_request_keep_alive,
|
||||
},
|
||||
};
|
|
@ -19,8 +19,8 @@
|
|||
#include <time.h>
|
||||
#include "ctl.h"
|
||||
#include "rtsp.h"
|
||||
#include "wfd-dbus.h"
|
||||
#include "wfd-session.h"
|
||||
#include "dispd-dbus.h"
|
||||
#include "dispd-session.h"
|
||||
#include "shl_macro.h"
|
||||
#include "shl_log.h"
|
||||
|
||||
|
@ -28,42 +28,42 @@
|
|||
(_id) >= RTSP_M1_REQUEST_SINK_OPTIONS && \
|
||||
(_id) <= RTSP_M16_KEEPALIVE \
|
||||
)
|
||||
#define wfd_stream_id_is_valid(_id) ( \
|
||||
(_id) >= WFD_STREAM_ID_PRIMARY && \
|
||||
(_id) <= WFD_STREAM_ID_SECONDARY \
|
||||
#define dispd_stream_id_is_valid(_id) ( \
|
||||
(_id) >= DISPD_STREAM_ID_PRIMARY && \
|
||||
(_id) <= DISPD_STREAM_ID_SECONDARY \
|
||||
)
|
||||
|
||||
static const char *rtsp_message_names[];
|
||||
extern const struct rtsp_dispatch_entry out_session_rtsp_disp_tbl[];
|
||||
|
||||
extern int wfd_out_session_initiate_io(struct wfd_session *s, int *out_fd, uint32_t *out_mask);
|
||||
extern int wfd_out_session_handle_io(struct wfd_session *s, int error, int *out_fd);
|
||||
extern int wfd_out_session_initiate_request(struct wfd_session *);
|
||||
extern int wfd_out_session_resume(struct wfd_session *);
|
||||
extern int wfd_out_session_pause(struct wfd_session *);
|
||||
extern int wfd_out_session_teardown(struct wfd_session *);
|
||||
extern void wfd_out_session_end(struct wfd_session *);
|
||||
extern void wfd_out_session_destroy(struct wfd_session *);
|
||||
extern int dispd_out_session_initiate_io(struct dispd_session *s, int *out_fd, uint32_t *out_mask);
|
||||
extern int dispd_out_session_handle_io(struct dispd_session *s, int error, int *out_fd);
|
||||
extern int dispd_out_session_initiate_request(struct dispd_session *);
|
||||
extern int dispd_out_session_resume(struct dispd_session *);
|
||||
extern int dispd_out_session_pause(struct dispd_session *);
|
||||
extern int dispd_out_session_teardown(struct dispd_session *);
|
||||
extern void dispd_out_session_end(struct dispd_session *);
|
||||
extern void dispd_out_session_destroy(struct dispd_session *);
|
||||
static const char * rtsp_message_id_to_string(enum rtsp_message_id id);
|
||||
static int wfd_session_handle_request(struct rtsp *bus,
|
||||
static int dispd_session_handle_request(struct rtsp *bus,
|
||||
struct rtsp_message *m,
|
||||
void *userdata);
|
||||
|
||||
const struct wfd_session_vtable session_vtbl[] = {
|
||||
[WFD_SESSION_DIR_OUT] = {
|
||||
.initiate_io = wfd_out_session_initiate_io,
|
||||
.handle_io = wfd_out_session_handle_io,
|
||||
.initiate_request = wfd_out_session_initiate_request,
|
||||
.resume = wfd_out_session_resume,
|
||||
.pause = wfd_out_session_pause,
|
||||
.teardown = wfd_out_session_teardown,
|
||||
.destroy = wfd_out_session_destroy,
|
||||
const struct dispd_session_vtable session_vtbl[] = {
|
||||
[DISPD_SESSION_DIR_OUT] = {
|
||||
.initiate_io = dispd_out_session_initiate_io,
|
||||
.handle_io = dispd_out_session_handle_io,
|
||||
.initiate_request = dispd_out_session_initiate_request,
|
||||
.resume = dispd_out_session_resume,
|
||||
.pause = dispd_out_session_pause,
|
||||
.teardown = dispd_out_session_teardown,
|
||||
.destroy = dispd_out_session_destroy,
|
||||
}
|
||||
};
|
||||
|
||||
static int wfd_session_do_request(struct wfd_session *s,
|
||||
static int dispd_session_do_request(struct dispd_session *s,
|
||||
enum rtsp_message_id id,
|
||||
const struct wfd_arg_list *args,
|
||||
const struct dispd_arg_list *args,
|
||||
struct rtsp_message **out)
|
||||
{
|
||||
int r;
|
||||
|
@ -81,7 +81,7 @@ static int wfd_session_do_request(struct wfd_session *s,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int wfd_session_do_handle_request(struct wfd_session *s,
|
||||
static int dispd_session_do_handle_request(struct dispd_session *s,
|
||||
enum rtsp_message_id id,
|
||||
struct rtsp_message *req,
|
||||
struct rtsp_message **rep)
|
||||
|
@ -104,7 +104,7 @@ static int wfd_session_do_handle_request(struct wfd_session *s,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int wfd_session_do_handle_reply(struct wfd_session *s,
|
||||
static int dispd_session_do_handle_reply(struct dispd_session *s,
|
||||
enum rtsp_message_id id,
|
||||
struct rtsp_message *rep)
|
||||
{
|
||||
|
@ -126,31 +126,31 @@ static int wfd_session_do_handle_reply(struct wfd_session *s,
|
|||
return 0;
|
||||
}
|
||||
|
||||
unsigned int wfd_session_get_id(struct wfd_session *s)
|
||||
unsigned int dispd_session_get_id(struct dispd_session *s)
|
||||
{
|
||||
assert_retv(s, (unsigned int) -1);
|
||||
|
||||
return s->id;
|
||||
}
|
||||
|
||||
bool wfd_session_is_state(struct wfd_session *s, enum wfd_session_state state)
|
||||
bool dispd_session_is_state(struct dispd_session *s, enum dispd_session_state state)
|
||||
{
|
||||
assert_retv(s, false);
|
||||
|
||||
return state == s->state;
|
||||
}
|
||||
|
||||
enum wfd_session_state wfd_session_get_state(struct wfd_session *s)
|
||||
enum dispd_session_state dispd_session_get_state(struct dispd_session *s)
|
||||
{
|
||||
assert_retv(s, WFD_SESSION_STATE_NULL);
|
||||
assert_retv(s, DISPD_SESSION_STATE_NULL);
|
||||
|
||||
return s->state;
|
||||
}
|
||||
|
||||
void wfd_session_set_state(struct wfd_session *s,
|
||||
enum wfd_session_state state)
|
||||
void dispd_session_set_state(struct dispd_session *s,
|
||||
enum dispd_session_state state)
|
||||
{
|
||||
assert_vret(wfd_is_session(s));
|
||||
assert_vret(dispd_is_session(s));
|
||||
|
||||
if(state == s->state) {
|
||||
return;
|
||||
|
@ -158,24 +158,24 @@ void wfd_session_set_state(struct wfd_session *s,
|
|||
|
||||
s->state = state;
|
||||
|
||||
wfd_fn_session_properties_changed(s, "State");
|
||||
dispd_fn_session_properties_changed(s, "State");
|
||||
}
|
||||
|
||||
bool wfd_session_is_established(struct wfd_session *s)
|
||||
bool dispd_session_is_established(struct dispd_session *s)
|
||||
{
|
||||
assert_retv(wfd_is_session(s), false);
|
||||
assert_retv(dispd_is_session(s), false);
|
||||
|
||||
return WFD_SESSION_STATE_ESTABLISHED <= s->state;
|
||||
return DISPD_SESSION_STATE_ESTABLISHED <= s->state;
|
||||
}
|
||||
|
||||
int wfd_session_resume(struct wfd_session *s)
|
||||
int dispd_session_resume(struct dispd_session *s)
|
||||
{
|
||||
assert_ret(wfd_is_session(s));
|
||||
assert_ret(dispd_is_session(s));
|
||||
|
||||
if(WFD_SESSION_STATE_PLAYING == s->state) {
|
||||
if(DISPD_SESSION_STATE_PLAYING == s->state) {
|
||||
return 0;
|
||||
}
|
||||
else if(WFD_SESSION_STATE_PAUSED != s->state) {
|
||||
else if(DISPD_SESSION_STATE_PAUSED != s->state) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
|
@ -186,14 +186,14 @@ int wfd_session_resume(struct wfd_session *s)
|
|||
return session_vtbl[s->dir].resume(s);;
|
||||
}
|
||||
|
||||
int wfd_session_pause(struct wfd_session *s)
|
||||
int dispd_session_pause(struct dispd_session *s)
|
||||
{
|
||||
assert_ret(wfd_is_session(s));
|
||||
assert_ret(dispd_is_session(s));
|
||||
|
||||
if(WFD_SESSION_STATE_PAUSED == s->state) {
|
||||
if(DISPD_SESSION_STATE_PAUSED == s->state) {
|
||||
return 0;
|
||||
}
|
||||
else if(WFD_SESSION_STATE_PLAYING != s->state) {
|
||||
else if(DISPD_SESSION_STATE_PLAYING != s->state) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
|
@ -204,11 +204,11 @@ int wfd_session_pause(struct wfd_session *s)
|
|||
return session_vtbl[s->dir].pause(s);;
|
||||
}
|
||||
|
||||
int wfd_session_teardown(struct wfd_session *s)
|
||||
int dispd_session_teardown(struct dispd_session *s)
|
||||
{
|
||||
int r;
|
||||
assert_ret(wfd_is_session(s));
|
||||
assert_ret(wfd_session_is_established(s));
|
||||
assert_ret(dispd_is_session(s));
|
||||
assert_ret(dispd_session_is_established(s));
|
||||
assert_ret(session_vtbl[s->dir].teardown);
|
||||
|
||||
r = session_vtbl[s->dir].teardown(s);
|
||||
|
@ -219,17 +219,17 @@ int wfd_session_teardown(struct wfd_session *s)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int wfd_session_destroy(struct wfd_session *s)
|
||||
int dispd_session_destroy(struct dispd_session *s)
|
||||
{
|
||||
assert_ret(wfd_is_session(s));
|
||||
assert_ret(dispd_is_session(s));
|
||||
|
||||
if(wfd_session_is_state(s, WFD_SESSION_STATE_DESTROYED)) {
|
||||
if(dispd_session_is_state(s, DISPD_SESSION_STATE_DESTROYED)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
wfd_session_set_state(s, WFD_SESSION_STATE_DESTROYED);
|
||||
dispd_session_set_state(s, DISPD_SESSION_STATE_DESTROYED);
|
||||
|
||||
wfd_fn_out_session_ended(s);
|
||||
dispd_fn_out_session_ended(s);
|
||||
|
||||
if(session_vtbl[s->dir].destroy) {
|
||||
(*session_vtbl[s->dir].destroy)(s);
|
||||
|
@ -238,11 +238,11 @@ int wfd_session_destroy(struct wfd_session *s)
|
|||
if(s->rtsp) {
|
||||
if(s->req_cookie) {
|
||||
rtsp_call_async_cancel(s->rtsp, s->req_cookie);
|
||||
wfd_session_unref(s);
|
||||
dispd_session_unref(s);
|
||||
s->req_cookie = 0;
|
||||
}
|
||||
|
||||
rtsp_remove_match(s->rtsp, wfd_session_handle_request, s);
|
||||
rtsp_remove_match(s->rtsp, dispd_session_handle_request, s);
|
||||
rtsp_detach_event(s->rtsp);
|
||||
rtsp_unref(s->rtsp);
|
||||
s->rtsp = NULL;
|
||||
|
@ -290,7 +290,7 @@ int wfd_session_destroy(struct wfd_session *s)
|
|||
return 0;
|
||||
}
|
||||
|
||||
struct wfd_session * _wfd_session_ref(struct wfd_session *s)
|
||||
struct dispd_session * _dispd_session_ref(struct dispd_session *s)
|
||||
{
|
||||
if(s) {
|
||||
++ s->ref;
|
||||
|
@ -299,7 +299,7 @@ struct wfd_session * _wfd_session_ref(struct wfd_session *s)
|
|||
return s;
|
||||
}
|
||||
|
||||
void _wfd_session_unref(struct wfd_session *s)
|
||||
void _dispd_session_unref(struct dispd_session *s)
|
||||
{
|
||||
if(!s) {
|
||||
return;
|
||||
|
@ -312,49 +312,49 @@ void _wfd_session_unref(struct wfd_session *s)
|
|||
return;
|
||||
}
|
||||
|
||||
wfd_session_destroy(s);
|
||||
dispd_session_destroy(s);
|
||||
|
||||
free(s);
|
||||
}
|
||||
|
||||
enum wfd_session_dir wfd_session_get_dir(struct wfd_session *s)
|
||||
enum dispd_session_dir dispd_session_get_dir(struct dispd_session *s)
|
||||
{
|
||||
assert_retv(s, WFD_SESSION_DIR_OUT);
|
||||
assert_retv(s, DISPD_SESSION_DIR_OUT);
|
||||
|
||||
return s->dir;
|
||||
}
|
||||
|
||||
unsigned int * wfd_session_to_htable(struct wfd_session *s)
|
||||
unsigned int * dispd_session_to_htable(struct dispd_session *s)
|
||||
{
|
||||
assert_retv(s, NULL);
|
||||
|
||||
return &s->id;
|
||||
}
|
||||
|
||||
struct wfd_session * wfd_session_from_htable(unsigned int *e)
|
||||
struct dispd_session * dispd_session_from_htable(unsigned int *e)
|
||||
{
|
||||
assert_retv(e, NULL);
|
||||
|
||||
return shl_htable_entry(e, struct wfd_session, id);
|
||||
return shl_htable_entry(e, struct dispd_session, id);
|
||||
}
|
||||
|
||||
const char * wfd_session_get_stream_url(struct wfd_session *s)
|
||||
const char * dispd_session_get_stream_url(struct dispd_session *s)
|
||||
{
|
||||
assert_retv(wfd_is_session(s), NULL);
|
||||
assert_retv(dispd_is_session(s), NULL);
|
||||
|
||||
return s->stream.url;
|
||||
}
|
||||
|
||||
int wfd_session_gen_stream_url(struct wfd_session *s,
|
||||
int dispd_session_gen_stream_url(struct dispd_session *s,
|
||||
const char *local_addr,
|
||||
enum wfd_stream_id id)
|
||||
enum dispd_stream_id id)
|
||||
{
|
||||
char *url;
|
||||
int r;
|
||||
|
||||
assert_ret(wfd_is_session(s));
|
||||
assert_ret(dispd_is_session(s));
|
||||
assert_ret(local_addr);
|
||||
assert_ret(wfd_stream_id_is_valid(id));
|
||||
assert_ret(dispd_stream_id_is_valid(id));
|
||||
|
||||
r = asprintf(&url, "rtsp://%s/wfd1.0/streamid=%d", local_addr, id);
|
||||
if(0 > r) {
|
||||
|
@ -367,13 +367,13 @@ int wfd_session_gen_stream_url(struct wfd_session *s,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static enum rtsp_message_id wfd_session_message_to_id(struct wfd_session *s,
|
||||
static enum rtsp_message_id dispd_session_message_to_id(struct dispd_session *s,
|
||||
struct rtsp_message *m)
|
||||
{
|
||||
|
||||
const char *method;
|
||||
|
||||
assert_retv(wfd_is_session(s), RTSP_M_UNKNOWN);
|
||||
assert_retv(dispd_is_session(s), RTSP_M_UNKNOWN);
|
||||
|
||||
method = m ? rtsp_message_get_method(m) : NULL;
|
||||
if(!method) {
|
||||
|
@ -405,7 +405,7 @@ static enum rtsp_message_id wfd_session_message_to_id(struct wfd_session *s,
|
|||
return RTSP_M13_REQUEST_IDR;
|
||||
}
|
||||
|
||||
if(WFD_SESSION_STATE_CAPS_EXCHANGING == s->state) {
|
||||
if(DISPD_SESSION_STATE_CAPS_EXCHANGING == s->state) {
|
||||
return RTSP_M4_SET_PARAMETER;
|
||||
}
|
||||
|
||||
|
@ -417,7 +417,7 @@ static enum rtsp_message_id wfd_session_message_to_id(struct wfd_session *s,
|
|||
}
|
||||
|
||||
if(!strcmp(method, "OPTIONS")) {
|
||||
return wfd_is_out_session(s)
|
||||
return dispd_is_out_session(s)
|
||||
? (RTSP_MESSAGE_REPLY == rtsp_message_get_type(m))
|
||||
? RTSP_M1_REQUEST_SINK_OPTIONS
|
||||
: RTSP_M2_REQUEST_SRC_OPTIONS
|
||||
|
@ -448,14 +448,14 @@ static enum rtsp_message_id wfd_session_message_to_id(struct wfd_session *s,
|
|||
return RTSP_M_UNKNOWN;
|
||||
}
|
||||
|
||||
static int wfd_session_post_handle_request_n_reply(struct wfd_session *s,
|
||||
static int dispd_session_post_handle_request_n_reply(struct dispd_session *s,
|
||||
enum rtsp_message_id ror)
|
||||
{
|
||||
const struct wfd_arg_list *args;
|
||||
const struct dispd_arg_list *args;
|
||||
enum rtsp_message_id next_request = RTSP_M_UNKNOWN;
|
||||
enum wfd_session_arg_id arg_id;
|
||||
enum wfd_session_state new_state = WFD_SESSION_STATE_NULL;
|
||||
const struct wfd_arg_list *req_args = NULL;
|
||||
enum dispd_session_arg_id arg_id;
|
||||
enum dispd_session_state new_state = DISPD_SESSION_STATE_NULL;
|
||||
const struct dispd_arg_list *req_args = NULL;
|
||||
int r, i;
|
||||
|
||||
assert_ret(s);
|
||||
|
@ -467,24 +467,24 @@ static int wfd_session_post_handle_request_n_reply(struct wfd_session *s,
|
|||
}
|
||||
|
||||
for(i = 0; i < args->len; i ++) {
|
||||
wfd_arg_list_get_dictk(args, i, &arg_id);
|
||||
dispd_arg_list_get_dictk(args, i, &arg_id);
|
||||
switch(arg_id) {
|
||||
case WFD_SESSION_ARG_NEXT_REQUEST:
|
||||
wfd_arg_list_get_dictv(args, i, &next_request);
|
||||
case DISPD_SESSION_ARG_NEXT_REQUEST:
|
||||
dispd_arg_list_get_dictv(args, i, &next_request);
|
||||
break;
|
||||
case WFD_SESSION_ARG_NEW_STATE:
|
||||
wfd_arg_list_get_dictv(args, i, &new_state);
|
||||
wfd_session_set_state(s, new_state);
|
||||
case DISPD_SESSION_ARG_NEW_STATE:
|
||||
dispd_arg_list_get_dictv(args, i, &new_state);
|
||||
dispd_session_set_state(s, new_state);
|
||||
break;
|
||||
case WFD_SESSION_ARG_REQUEST_ARGS:
|
||||
wfd_arg_list_get_dictv(args, i, &req_args);
|
||||
case DISPD_SESSION_ARG_REQUEST_ARGS:
|
||||
dispd_arg_list_get_dictv(args, i, &req_args);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(RTSP_M_UNKNOWN != next_request) {
|
||||
r = wfd_session_request(s, next_request, req_args);
|
||||
r = dispd_session_request(s, next_request, req_args);
|
||||
if(0 > r) {
|
||||
return log_ERR(r);
|
||||
}
|
||||
|
@ -496,20 +496,20 @@ static int wfd_session_post_handle_request_n_reply(struct wfd_session *s,
|
|||
static int defered_destroy(struct sd_event_source *source,
|
||||
void *userdata)
|
||||
{
|
||||
struct wfd_session *s = userdata;
|
||||
struct dispd_session *s = userdata;
|
||||
|
||||
wfd_session_destroy(s);
|
||||
wfd_session_unref(s);
|
||||
dispd_session_destroy(s);
|
||||
dispd_session_unref(s);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int schedule_defered_destroy(struct wfd_session *s)
|
||||
static inline int schedule_defered_destroy(struct dispd_session *s)
|
||||
{
|
||||
int r = sd_event_add_defer(ctl_wfd_get_loop(),
|
||||
int r = sd_event_add_defer(dispd_get_loop(),
|
||||
NULL,
|
||||
defered_destroy,
|
||||
wfd_session_ref(s));
|
||||
dispd_session_ref(s));
|
||||
if(0 > r) {
|
||||
return log_ERR(r);
|
||||
}
|
||||
|
@ -517,12 +517,12 @@ static inline int schedule_defered_destroy(struct wfd_session *s)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int wfd_session_handle_request(struct rtsp *bus,
|
||||
static int dispd_session_handle_request(struct rtsp *bus,
|
||||
struct rtsp_message *m,
|
||||
void *userdata)
|
||||
{
|
||||
_rtsp_message_unref_ struct rtsp_message *rep = NULL;
|
||||
struct wfd_session *s = userdata;
|
||||
struct dispd_session *s = userdata;
|
||||
enum rtsp_message_id id;
|
||||
char date[64];
|
||||
uint64_t usec;
|
||||
|
@ -530,14 +530,14 @@ static int wfd_session_handle_request(struct rtsp *bus,
|
|||
int r;
|
||||
|
||||
if(!m && rtsp_is_dead(bus)) {
|
||||
if(WFD_SESSION_STATE_TEARING_DOWN != wfd_session_get_state(s)) {
|
||||
if(DISPD_SESSION_STATE_TEARING_DOWN != dispd_session_get_state(s)) {
|
||||
log_info("rtsp disconnected");
|
||||
r = log_EPIPE();
|
||||
}
|
||||
goto error;
|
||||
}
|
||||
|
||||
id = wfd_session_message_to_id(s, m);
|
||||
id = dispd_session_message_to_id(s, m);
|
||||
if(RTSP_M_UNKNOWN == id) {
|
||||
log_debug("unable to map request to id: %s",
|
||||
(char *) rtsp_message_get_raw(m));
|
||||
|
@ -549,7 +549,7 @@ static int wfd_session_handle_request(struct rtsp *bus,
|
|||
id,
|
||||
(char *) rtsp_message_get_raw(m));
|
||||
|
||||
r = wfd_session_do_handle_request(s,
|
||||
r = dispd_session_do_handle_request(s,
|
||||
id,
|
||||
m,
|
||||
&rep);
|
||||
|
@ -558,7 +558,7 @@ static int wfd_session_handle_request(struct rtsp *bus,
|
|||
goto error;
|
||||
}
|
||||
|
||||
r = sd_event_now(ctl_wfd_get_loop(), CLOCK_REALTIME, &usec);
|
||||
r = sd_event_now(dispd_get_loop(), CLOCK_REALTIME, &usec);
|
||||
if(0 > r) {
|
||||
log_vERR(r);
|
||||
goto error;
|
||||
|
@ -591,7 +591,7 @@ static int wfd_session_handle_request(struct rtsp *bus,
|
|||
id,
|
||||
(char *) rtsp_message_get_raw(rep));
|
||||
|
||||
r = wfd_session_post_handle_request_n_reply(s, id);
|
||||
r = dispd_session_post_handle_request_n_reply(s, id);
|
||||
if(0 > r) {
|
||||
log_vERR(r);
|
||||
goto error;
|
||||
|
@ -605,13 +605,13 @@ error:
|
|||
return r;
|
||||
}
|
||||
|
||||
static int wfd_session_handle_reply(struct rtsp *bus,
|
||||
static int dispd_session_handle_reply(struct rtsp *bus,
|
||||
struct rtsp_message *m,
|
||||
void *userdata)
|
||||
{
|
||||
int r;
|
||||
enum rtsp_message_id id;
|
||||
struct wfd_session *s = userdata;
|
||||
struct dispd_session *s = userdata;
|
||||
|
||||
s->req_cookie = 0;
|
||||
|
||||
|
@ -632,13 +632,13 @@ static int wfd_session_handle_reply(struct rtsp *bus,
|
|||
id,
|
||||
(char *) rtsp_message_get_raw(m));
|
||||
|
||||
r = wfd_session_do_handle_reply(s, id, m);
|
||||
r = dispd_session_do_handle_reply(s, id, m);
|
||||
if(0 > r) {
|
||||
log_vERR(r);
|
||||
goto error;
|
||||
}
|
||||
|
||||
r = wfd_session_post_handle_request_n_reply(s, id);
|
||||
r = dispd_session_post_handle_request_n_reply(s, id);
|
||||
if(0 > r) {
|
||||
log_vERR(r);
|
||||
goto error;
|
||||
|
@ -649,14 +649,14 @@ static int wfd_session_handle_reply(struct rtsp *bus,
|
|||
error:
|
||||
schedule_defered_destroy(s);
|
||||
end:
|
||||
wfd_session_unref(s);
|
||||
dispd_session_unref(s);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
int wfd_session_init(struct wfd_session *s,
|
||||
int dispd_session_init(struct dispd_session *s,
|
||||
unsigned int id,
|
||||
enum wfd_session_dir dir,
|
||||
enum dispd_session_dir dir,
|
||||
const struct rtsp_dispatch_entry *disp_tbl)
|
||||
{
|
||||
s->ref = 1;
|
||||
|
@ -670,16 +670,16 @@ int wfd_session_init(struct wfd_session *s,
|
|||
return 0;
|
||||
}
|
||||
|
||||
int wfd_session_request(struct wfd_session *s,
|
||||
int dispd_session_request(struct dispd_session *s,
|
||||
enum rtsp_message_id id,
|
||||
const struct wfd_arg_list *args)
|
||||
const struct dispd_arg_list *args)
|
||||
{
|
||||
int r;
|
||||
_rtsp_message_unref_ struct rtsp_message *m = NULL;
|
||||
|
||||
assert_ret(s);
|
||||
|
||||
r = wfd_session_do_request(s, id, args, &m);
|
||||
r = dispd_session_do_request(s, id, args, &m);
|
||||
if(0 > r) {
|
||||
goto error;
|
||||
}
|
||||
|
@ -691,8 +691,8 @@ int wfd_session_request(struct wfd_session *s,
|
|||
|
||||
r = rtsp_call_async(s->rtsp,
|
||||
m,
|
||||
wfd_session_handle_reply,
|
||||
wfd_session_ref(s),
|
||||
dispd_session_handle_reply,
|
||||
dispd_session_ref(s),
|
||||
0,
|
||||
&s->req_cookie);
|
||||
if(0 > r) {
|
||||
|
@ -713,14 +713,14 @@ error:
|
|||
return r;
|
||||
}
|
||||
|
||||
static int wfd_session_handle_io(sd_event_source *source,
|
||||
static int dispd_session_handle_io(sd_event_source *source,
|
||||
int fd,
|
||||
uint32_t mask,
|
||||
void *userdata)
|
||||
{
|
||||
int r = 0, err = 0, conn;
|
||||
socklen_t len;
|
||||
struct wfd_session *s = userdata;
|
||||
struct dispd_session *s = userdata;
|
||||
_rtsp_unref_ struct rtsp *rtsp = NULL;
|
||||
|
||||
sd_event_source_set_enabled(source, SD_EVENT_OFF);
|
||||
|
@ -746,12 +746,12 @@ static int wfd_session_handle_io(sd_event_source *source,
|
|||
|
||||
conn = -1;
|
||||
|
||||
r = rtsp_attach_event(rtsp, ctl_wfd_get_loop(), 0);
|
||||
r = rtsp_attach_event(rtsp, dispd_get_loop(), 0);
|
||||
if (0 > r) {
|
||||
return log_ERRNO();
|
||||
}
|
||||
|
||||
r = rtsp_add_match(rtsp, wfd_session_handle_request, s);
|
||||
r = rtsp_add_match(rtsp, dispd_session_handle_request, s);
|
||||
if (0 > r) {
|
||||
return log_ERRNO();
|
||||
}
|
||||
|
@ -759,37 +759,37 @@ static int wfd_session_handle_io(sd_event_source *source,
|
|||
s->rtsp = rtsp;
|
||||
rtsp = NULL;
|
||||
|
||||
wfd_session_set_state(s, WFD_SESSION_STATE_CAPS_EXCHANGING);
|
||||
dispd_session_set_state(s, DISPD_SESSION_STATE_CAPS_EXCHANGING);
|
||||
|
||||
r = (*session_vtbl[s->dir].initiate_request)(s);
|
||||
}
|
||||
|
||||
if(mask & EPOLLHUP) {
|
||||
wfd_session_destroy(s);
|
||||
dispd_session_destroy(s);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int wfd_session_start(struct wfd_session *s)
|
||||
int dispd_session_start(struct dispd_session *s)
|
||||
{
|
||||
int r;
|
||||
_shl_close_ int fd = -1;
|
||||
uint32_t mask;
|
||||
|
||||
assert_ret(wfd_is_session(s));
|
||||
assert_retv(wfd_session_is_state(s, WFD_SESSION_STATE_NULL), -EINPROGRESS);
|
||||
assert_ret(dispd_is_session(s));
|
||||
assert_retv(dispd_session_is_state(s, DISPD_SESSION_STATE_NULL), -EINPROGRESS);
|
||||
|
||||
r = (*session_vtbl[s->dir].initiate_io)(s, &fd, &mask);
|
||||
if(0 > r) {
|
||||
return log_ERR(r);
|
||||
}
|
||||
|
||||
r = sd_event_add_io(ctl_wfd_get_loop(),
|
||||
r = sd_event_add_io(dispd_get_loop(),
|
||||
NULL,
|
||||
fd,
|
||||
mask,
|
||||
wfd_session_handle_io,
|
||||
dispd_session_handle_io,
|
||||
s);
|
||||
if (r < 0) {
|
||||
return log_ERRNO();
|
||||
|
@ -797,19 +797,19 @@ int wfd_session_start(struct wfd_session *s)
|
|||
|
||||
fd = -1;
|
||||
|
||||
wfd_session_set_state(s, WFD_SESSION_STATE_CONNECTING);
|
||||
dispd_session_set_state(s, DISPD_SESSION_STATE_CONNECTING);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
enum wfd_display_server_type wfd_session_get_disp_type(struct wfd_session *s)
|
||||
enum dispd_display_server_type dispd_session_get_disp_type(struct dispd_session *s)
|
||||
{
|
||||
assert_retv(s, WFD_DISPLAY_SERVER_TYPE_UNKNOWN);
|
||||
assert_retv(s, DISPD_DISPLAY_SERVER_TYPE_UNKNOWN);
|
||||
|
||||
return s->disp_type;
|
||||
}
|
||||
|
||||
int wfd_session_set_disp_type(struct wfd_session *s, enum wfd_display_server_type disp_type)
|
||||
int dispd_session_set_disp_type(struct dispd_session *s, enum dispd_display_server_type disp_type)
|
||||
{
|
||||
assert_ret(s);
|
||||
|
||||
|
@ -818,14 +818,14 @@ int wfd_session_set_disp_type(struct wfd_session *s, enum wfd_display_server_typ
|
|||
return 0;
|
||||
}
|
||||
|
||||
const char * wfd_session_get_disp_name(struct wfd_session *s)
|
||||
const char * dispd_session_get_disp_name(struct dispd_session *s)
|
||||
{
|
||||
assert_retv(s, "");
|
||||
|
||||
return s->disp_name;
|
||||
}
|
||||
|
||||
int wfd_session_set_disp_name(struct wfd_session *s, const char *disp_name)
|
||||
int dispd_session_set_disp_name(struct dispd_session *s, const char *disp_name)
|
||||
{
|
||||
char *name;
|
||||
|
||||
|
@ -845,14 +845,14 @@ int wfd_session_set_disp_name(struct wfd_session *s, const char *disp_name)
|
|||
return 0;
|
||||
}
|
||||
|
||||
const char * wfd_session_get_disp_params(struct wfd_session *s)
|
||||
const char * dispd_session_get_disp_params(struct dispd_session *s)
|
||||
{
|
||||
assert_retv(s, "");
|
||||
|
||||
return s->disp_params;
|
||||
}
|
||||
|
||||
int wfd_session_set_disp_params(struct wfd_session *s, const char *disp_params)
|
||||
int dispd_session_set_disp_params(struct dispd_session *s, const char *disp_params)
|
||||
{
|
||||
char *params;
|
||||
|
||||
|
@ -872,14 +872,14 @@ int wfd_session_set_disp_params(struct wfd_session *s, const char *disp_params)
|
|||
return 0;
|
||||
}
|
||||
|
||||
const char * wfd_session_get_disp_auth(struct wfd_session *s)
|
||||
const char * dispd_session_get_disp_auth(struct dispd_session *s)
|
||||
{
|
||||
assert_retv(s, "");
|
||||
|
||||
return s->disp_auth;
|
||||
}
|
||||
|
||||
int wfd_session_set_disp_auth(struct wfd_session *s, const char *disp_auth)
|
||||
int dispd_session_set_disp_auth(struct dispd_session *s, const char *disp_auth)
|
||||
{
|
||||
char *auth;
|
||||
|
||||
|
@ -899,14 +899,14 @@ int wfd_session_set_disp_auth(struct wfd_session *s, const char *disp_auth)
|
|||
return 0;
|
||||
}
|
||||
|
||||
const struct wfd_rectangle * wfd_session_get_disp_dimension(struct wfd_session *s)
|
||||
const struct dispd_rectangle * dispd_session_get_disp_dimension(struct dispd_session *s)
|
||||
{
|
||||
assert_retv(s, NULL);
|
||||
|
||||
return &s->disp_dimen;
|
||||
}
|
||||
|
||||
int wfd_session_set_disp_dimension(struct wfd_session *s, const struct wfd_rectangle *rect)
|
||||
int dispd_session_set_disp_dimension(struct dispd_session *s, const struct dispd_rectangle *rect)
|
||||
{
|
||||
assert_ret(s);
|
||||
assert_ret(rect);
|
||||
|
@ -918,14 +918,14 @@ int wfd_session_set_disp_dimension(struct wfd_session *s, const struct wfd_recta
|
|||
return 0;
|
||||
}
|
||||
|
||||
enum wfd_audio_server_type wfd_session_get_audio_type(struct wfd_session *s)
|
||||
enum dispd_audio_server_type dispd_session_get_audio_type(struct dispd_session *s)
|
||||
{
|
||||
assert_retv(s, WFD_AUDIO_SERVER_TYPE_UNKNOWN);
|
||||
assert_retv(s, DISPD_AUDIO_SERVER_TYPE_UNKNOWN);
|
||||
|
||||
return s->audio_type;
|
||||
}
|
||||
|
||||
int wfd_session_set_audio_type(struct wfd_session *s, enum wfd_audio_server_type audio_type)
|
||||
int dispd_session_set_audio_type(struct dispd_session *s, enum dispd_audio_server_type audio_type)
|
||||
{
|
||||
assert_ret(s);
|
||||
|
||||
|
@ -934,14 +934,14 @@ int wfd_session_set_audio_type(struct wfd_session *s, enum wfd_audio_server_type
|
|||
return 0;
|
||||
}
|
||||
|
||||
const char * wfd_session_get_audio_dev_name(struct wfd_session *s)
|
||||
const char * dispd_session_get_audio_dev_name(struct dispd_session *s)
|
||||
{
|
||||
assert_retv(s, "");
|
||||
|
||||
return s->audio_dev_name;
|
||||
}
|
||||
|
||||
int wfd_session_set_audio_dev_name(struct wfd_session *s,
|
||||
int dispd_session_set_audio_dev_name(struct dispd_session *s,
|
||||
const char *audio_dev_name)
|
||||
{
|
||||
char *name;
|
||||
|
@ -962,14 +962,14 @@ int wfd_session_set_audio_dev_name(struct wfd_session *s,
|
|||
return 0;
|
||||
}
|
||||
|
||||
const char * wfd_session_get_runtime_path(struct wfd_session *s)
|
||||
const char * dispd_session_get_runtime_path(struct dispd_session *s)
|
||||
{
|
||||
assert_retv(s, "");
|
||||
|
||||
return s->runtime_path;
|
||||
}
|
||||
|
||||
int wfd_session_set_runtime_path(struct wfd_session *s,
|
||||
int dispd_session_set_runtime_path(struct dispd_session *s,
|
||||
const char *runtime_path)
|
||||
{
|
||||
char *path;
|
||||
|
@ -990,14 +990,14 @@ int wfd_session_set_runtime_path(struct wfd_session *s,
|
|||
return 0;
|
||||
}
|
||||
|
||||
uid_t wfd_session_get_client_uid(struct wfd_session *s)
|
||||
uid_t dispd_session_get_client_uid(struct dispd_session *s)
|
||||
{
|
||||
assert_retv(s, -1);
|
||||
|
||||
return s->client_uid;
|
||||
}
|
||||
|
||||
int wfd_session_set_client_uid(struct wfd_session *s, uid_t uid)
|
||||
int dispd_session_set_client_uid(struct dispd_session *s, uid_t uid)
|
||||
{
|
||||
assert_ret(s);
|
||||
|
||||
|
@ -1006,14 +1006,14 @@ int wfd_session_set_client_uid(struct wfd_session *s, uid_t uid)
|
|||
return 0;
|
||||
}
|
||||
|
||||
gid_t wfd_session_get_client_gid(struct wfd_session *s)
|
||||
gid_t dispd_session_get_client_gid(struct dispd_session *s)
|
||||
{
|
||||
assert_retv(s, -1);
|
||||
|
||||
return s->client_gid;
|
||||
}
|
||||
|
||||
int wfd_session_set_client_gid(struct wfd_session *s, gid_t gid)
|
||||
int dispd_session_set_client_gid(struct dispd_session *s, gid_t gid)
|
||||
{
|
||||
assert_ret(s);
|
||||
|
||||
|
@ -1022,14 +1022,14 @@ int wfd_session_set_client_gid(struct wfd_session *s, gid_t gid)
|
|||
return 0;
|
||||
}
|
||||
|
||||
pid_t wfd_session_get_client_pid(struct wfd_session *s)
|
||||
pid_t dispd_session_get_client_pid(struct dispd_session *s)
|
||||
{
|
||||
assert_retv(s, -1);
|
||||
|
||||
return s->client_pid;
|
||||
}
|
||||
|
||||
int wfd_session_set_client_pid(struct wfd_session *s, pid_t pid)
|
||||
int dispd_session_set_client_pid(struct dispd_session *s, pid_t pid)
|
||||
{
|
||||
assert_ret(s);
|
||||
|
||||
|
@ -1038,10 +1038,10 @@ int wfd_session_set_client_pid(struct wfd_session *s, pid_t pid)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void wfd_session_unrefp(struct wfd_session **s)
|
||||
void dispd_session_unrefp(struct dispd_session **s)
|
||||
{
|
||||
if(s && *s) {
|
||||
wfd_session_unref(*s);
|
||||
dispd_session_unref(*s);
|
||||
}
|
||||
}
|
||||
|
|
@ -17,17 +17,17 @@
|
|||
* along with MiracleCast; If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <unistd.h>
|
||||
#include "disp.h"
|
||||
#include "wfd-arg.h"
|
||||
#include "dispd.h"
|
||||
#include "dispd-arg.h"
|
||||
|
||||
#ifndef CTL_WFD_SESSION_H
|
||||
#define CTL_WFD_SESSION_H
|
||||
#ifndef DISPD_SESSION_H
|
||||
#define DISPD_SESSION_H
|
||||
|
||||
#define wfd_out_session(s) (assert(wfd_is_out_session(s)), (struct wfd_out_session *) (s))
|
||||
#define wfd_in_session(s) (assert(wfd_is_in_session(s)), (struct wfd_in_session *) (s))
|
||||
#define dispd_out_session(s) (assert(dispd_is_out_session(s)), (struct dispd_out_session *) (s))
|
||||
#define dispd_in_session(s) (assert(dispd_is_in_session(s)), (struct dispd_in_session *) (s))
|
||||
|
||||
struct wfd_session;
|
||||
struct wfd_sink;
|
||||
struct dispd_session;
|
||||
struct dispd_sink;
|
||||
struct rtsp;
|
||||
struct rtsp_message;
|
||||
|
||||
|
@ -52,51 +52,51 @@ enum rtsp_message_id
|
|||
RTSP_M16_KEEPALIVE,
|
||||
};
|
||||
|
||||
enum wfd_stream_id
|
||||
enum dispd_stream_id
|
||||
{
|
||||
WFD_STREAM_ID_PRIMARY,
|
||||
WFD_STREAM_ID_SECONDARY,
|
||||
DISPD_STREAM_ID_PRIMARY,
|
||||
DISPD_STREAM_ID_SECONDARY,
|
||||
};
|
||||
|
||||
enum wfd_session_arg_id
|
||||
enum dispd_session_arg_id
|
||||
{
|
||||
WFD_SESSION_ARG_NEXT_REQUEST,
|
||||
WFD_SESSION_ARG_NEW_STATE,
|
||||
WFD_SESSION_ARG_REQUEST_ARGS,
|
||||
DISPD_SESSION_ARG_NEXT_REQUEST,
|
||||
DISPD_SESSION_ARG_NEW_STATE,
|
||||
DISPD_SESSION_ARG_REQUEST_ARGS,
|
||||
};
|
||||
|
||||
struct rtsp_dispatch_entry
|
||||
{
|
||||
union {
|
||||
int (*request)(struct wfd_session *s,
|
||||
int (*request)(struct dispd_session *s,
|
||||
struct rtsp *bus,
|
||||
const struct wfd_arg_list *args,
|
||||
const struct dispd_arg_list *args,
|
||||
struct rtsp_message **out);
|
||||
int (*handle_request)(struct wfd_session *s,
|
||||
int (*handle_request)(struct dispd_session *s,
|
||||
struct rtsp_message *req,
|
||||
struct rtsp_message **out_rep);
|
||||
};
|
||||
int (*handle_reply)(struct wfd_session *s,
|
||||
int (*handle_reply)(struct dispd_session *s,
|
||||
struct rtsp_message *m);
|
||||
struct wfd_arg_list rule;
|
||||
struct dispd_arg_list rule;
|
||||
};
|
||||
|
||||
struct wfd_session_vtable
|
||||
struct dispd_session_vtable
|
||||
{
|
||||
int (*initiate_io)(struct wfd_session *s, int *out_fd, uint32_t *out_mask);
|
||||
int (*handle_io)(struct wfd_session *s, int error, int *out_fd);
|
||||
int (*initiate_request)(struct wfd_session *s);
|
||||
int (*resume)(struct wfd_session *);
|
||||
int (*pause)(struct wfd_session *);
|
||||
int (*teardown)(struct wfd_session *);
|
||||
void (*destroy)(struct wfd_session *s);
|
||||
int (*initiate_io)(struct dispd_session *s, int *out_fd, uint32_t *out_mask);
|
||||
int (*handle_io)(struct dispd_session *s, int error, int *out_fd);
|
||||
int (*initiate_request)(struct dispd_session *s);
|
||||
int (*resume)(struct dispd_session *);
|
||||
int (*pause)(struct dispd_session *);
|
||||
int (*teardown)(struct dispd_session *);
|
||||
void (*destroy)(struct dispd_session *s);
|
||||
};
|
||||
|
||||
struct wfd_session
|
||||
struct dispd_session
|
||||
{
|
||||
int ref;
|
||||
enum wfd_session_dir dir;
|
||||
enum wfd_session_state state;
|
||||
enum dispd_session_dir dir;
|
||||
enum dispd_session_state state;
|
||||
enum rtsp_message_id last_request;
|
||||
const struct rtsp_dispatch_entry *rtsp_disp_tbl;
|
||||
|
||||
|
@ -108,18 +108,18 @@ struct wfd_session
|
|||
struct wfd_audio_codecs *acodecs;
|
||||
|
||||
struct {
|
||||
enum wfd_stream_id id;
|
||||
enum dispd_stream_id id;
|
||||
char *url;
|
||||
uint16_t rtp_port;
|
||||
uint16_t rtcp_port;
|
||||
} stream;
|
||||
|
||||
enum wfd_display_server_type disp_type;
|
||||
enum dispd_display_server_type disp_type;
|
||||
char *disp_name;
|
||||
char *disp_params;
|
||||
char *disp_auth;
|
||||
struct wfd_rectangle disp_dimen;
|
||||
enum wfd_audio_server_type audio_type;
|
||||
struct dispd_rectangle disp_dimen;
|
||||
enum dispd_audio_server_type audio_type;
|
||||
char *audio_dev_name;
|
||||
|
||||
uid_t client_uid;
|
||||
|
@ -128,19 +128,19 @@ struct wfd_session
|
|||
char *runtime_path;
|
||||
};
|
||||
|
||||
int wfd_session_init(struct wfd_session *s,
|
||||
int dispd_session_init(struct dispd_session *s,
|
||||
unsigned int id,
|
||||
enum wfd_session_dir dir,
|
||||
enum dispd_session_dir dir,
|
||||
const struct rtsp_dispatch_entry *disp_tbl);
|
||||
int wfd_session_gen_stream_url(struct wfd_session *s,
|
||||
int dispd_session_gen_stream_url(struct dispd_session *s,
|
||||
const char *local_addr,
|
||||
enum wfd_stream_id id);
|
||||
int wfd_session_request(struct wfd_session *s,
|
||||
enum dispd_stream_id id);
|
||||
int dispd_session_request(struct dispd_session *s,
|
||||
enum rtsp_message_id id,
|
||||
const struct wfd_arg_list *args);
|
||||
void wfd_session_end(struct wfd_session *s);
|
||||
struct wfd_sink * wfd_out_session_get_sink(struct wfd_session *s);
|
||||
void wfd_session_set_state(struct wfd_session *s,
|
||||
enum wfd_session_state state);
|
||||
const struct dispd_arg_list *args);
|
||||
void dispd_session_end(struct dispd_session *s);
|
||||
struct dispd_sink * dispd_out_session_get_sink(struct dispd_session *s);
|
||||
void dispd_session_set_state(struct dispd_session *s,
|
||||
enum dispd_session_state state);
|
||||
|
||||
#endif /* CTL_WFD_SESSION_H */
|
||||
#endif /* DISPD_SESSION_H */
|
|
@ -19,11 +19,11 @@
|
|||
#include <time.h>
|
||||
#include <systemd/sd-event.h>
|
||||
#include "ctl.h"
|
||||
#include "disp.h"
|
||||
#include "wfd-dbus.h"
|
||||
#include "dispd.h"
|
||||
#include "dispd-dbus.h"
|
||||
|
||||
static int wfd_sink_set_session(struct wfd_sink *sink,
|
||||
struct wfd_session *session)
|
||||
static int dispd_sink_set_session(struct dispd_sink *sink,
|
||||
struct dispd_session *session)
|
||||
{
|
||||
int r;
|
||||
|
||||
|
@ -34,44 +34,44 @@ static int wfd_sink_set_session(struct wfd_sink *sink,
|
|||
}
|
||||
|
||||
if(session) {
|
||||
r = ctl_wfd_add_session(ctl_wfd_get(), session);
|
||||
r = dispd_add_session(dispd_get(), session);
|
||||
if(0 > r) {
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
if(sink->session) {
|
||||
ctl_wfd_remove_session_by_id(ctl_wfd_get(),
|
||||
wfd_session_get_id(sink->session),
|
||||
dispd_remove_session_by_id(dispd_get(),
|
||||
dispd_session_get_id(sink->session),
|
||||
NULL);
|
||||
wfd_session_unref(sink->session);
|
||||
dispd_session_unref(sink->session);
|
||||
}
|
||||
|
||||
sink->session = session ? wfd_session_ref(session) : NULL;
|
||||
wfd_fn_sink_properties_changed(sink, "Session");
|
||||
sink->session = session ? dispd_session_ref(session) : NULL;
|
||||
dispd_fn_sink_properties_changed(sink, "Session");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int wfd_sink_new(struct wfd_sink **out,
|
||||
int dispd_sink_new(struct dispd_sink **out,
|
||||
struct ctl_peer *peer,
|
||||
union wfd_sube *sube)
|
||||
{
|
||||
struct wfd_sink *sink;
|
||||
struct dispd_sink *sink;
|
||||
|
||||
assert_ret(out);
|
||||
assert_ret(peer);
|
||||
assert_ret(sube);
|
||||
assert_ret(wfd_sube_device_is_sink(sube));
|
||||
|
||||
sink = calloc(1, sizeof(struct wfd_sink));
|
||||
sink = calloc(1, sizeof(struct dispd_sink));
|
||||
if(!sink) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
sink->label = strdup(peer->label);
|
||||
if(!sink->label) {
|
||||
wfd_sink_free(sink);
|
||||
dispd_sink_free(sink);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
|
@ -83,13 +83,13 @@ int wfd_sink_new(struct wfd_sink **out,
|
|||
return 0;
|
||||
}
|
||||
|
||||
void wfd_sink_free(struct wfd_sink *sink)
|
||||
void dispd_sink_free(struct dispd_sink *sink)
|
||||
{
|
||||
if(!sink) {
|
||||
return;
|
||||
}
|
||||
|
||||
wfd_sink_set_session(sink, NULL);
|
||||
dispd_sink_set_session(sink, NULL);
|
||||
|
||||
if(sink->label) {
|
||||
free(sink->label);
|
||||
|
@ -98,68 +98,68 @@ void wfd_sink_free(struct wfd_sink *sink)
|
|||
free(sink);
|
||||
}
|
||||
|
||||
const char * wfd_sink_get_label(struct wfd_sink *sink)
|
||||
const char * dispd_sink_get_label(struct dispd_sink *sink)
|
||||
{
|
||||
assert_retv(sink, NULL);
|
||||
|
||||
return sink->label;
|
||||
}
|
||||
|
||||
const union wfd_sube * wfd_sink_get_dev_info(struct wfd_sink *sink)
|
||||
const union wfd_sube * dispd_sink_get_dev_info(struct dispd_sink *sink)
|
||||
{
|
||||
assert_retv(sink, NULL);
|
||||
|
||||
return &sink->dev_info;
|
||||
}
|
||||
|
||||
struct ctl_peer * wfd_sink_get_peer(struct wfd_sink *sink)
|
||||
struct ctl_peer * dispd_sink_get_peer(struct dispd_sink *sink)
|
||||
{
|
||||
assert_retv(sink, NULL);
|
||||
|
||||
return sink->peer;
|
||||
}
|
||||
|
||||
int wfd_sink_create_session(struct wfd_sink *sink, struct wfd_session **out)
|
||||
int dispd_sink_create_session(struct dispd_sink *sink, struct dispd_session **out)
|
||||
{
|
||||
int r;
|
||||
_wfd_session_unref_ struct wfd_session *sess = NULL;
|
||||
_dispd_session_unref_ struct dispd_session *sess = NULL;
|
||||
|
||||
assert_ret(sink);
|
||||
assert_ret(out);
|
||||
|
||||
if(wfd_sink_is_session_started(sink)) {
|
||||
if(dispd_sink_is_session_started(sink)) {
|
||||
return -EALREADY;
|
||||
}
|
||||
|
||||
r = wfd_out_session_new(&sess,
|
||||
ctl_wfd_alloc_session_id(ctl_wfd_get()),
|
||||
r = dispd_out_session_new(&sess,
|
||||
dispd_alloc_session_id(dispd_get()),
|
||||
sink);
|
||||
if(0 > r) {
|
||||
return r;
|
||||
}
|
||||
|
||||
r = wfd_sink_set_session(sink, sess);
|
||||
r = dispd_sink_set_session(sink, sess);
|
||||
if(0 > r) {
|
||||
return r;
|
||||
}
|
||||
|
||||
*out = wfd_session_ref(sess);
|
||||
*out = dispd_session_ref(sess);
|
||||
|
||||
wfd_fn_sink_properties_changed(sink, "Session");
|
||||
dispd_fn_sink_properties_changed(sink, "Session");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int wfd_fn_out_session_ended(struct wfd_session *s)
|
||||
int dispd_fn_out_session_ended(struct dispd_session *s)
|
||||
{
|
||||
assert_ret(wfd_is_out_session(s));
|
||||
assert_ret(dispd_is_out_session(s));
|
||||
|
||||
wfd_sink_set_session(wfd_out_session_get_sink(s), NULL);
|
||||
dispd_sink_set_session(dispd_out_session_get_sink(s), NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool wfd_sink_is_session_started(struct wfd_sink *sink)
|
||||
bool dispd_sink_is_session_started(struct dispd_sink *sink)
|
||||
{
|
||||
assert_retv(sink, false);
|
||||
|
216
src/disp/dispd.c
216
src/disp/dispd.c
|
@ -28,113 +28,113 @@
|
|||
#include <systemd/sd-event.h>
|
||||
#include <systemd/sd-daemon.h>
|
||||
#include "ctl.h"
|
||||
#include "disp.h"
|
||||
#include "dispd.h"
|
||||
#include "wfd.h"
|
||||
#include "wfd-dbus.h"
|
||||
#include "dispd-dbus.h"
|
||||
#include "config.h"
|
||||
|
||||
static int ctl_wfd_init(struct ctl_wfd *wfd, sd_bus *bus);
|
||||
static void ctl_wfd_free(struct ctl_wfd *wfd);
|
||||
static int dispd_init(struct dispd *dispd, sd_bus *bus);
|
||||
static void dispd_free(struct dispd *dispd);
|
||||
|
||||
static struct ctl_wfd *wfd = NULL;
|
||||
static struct wfd_dbus *wfd_dbus = NULL;
|
||||
static struct dispd_dbus *dispd_dbus = NULL;
|
||||
|
||||
struct wfd_dbus * wfd_dbus_get()
|
||||
struct dispd_dbus * dispd_dbus_get()
|
||||
{
|
||||
return wfd_dbus;
|
||||
return dispd_dbus;
|
||||
}
|
||||
static struct dispd *dispd = NULL;
|
||||
|
||||
struct dispd * dispd_get()
|
||||
{
|
||||
return dispd;
|
||||
}
|
||||
|
||||
struct ctl_wfd * ctl_wfd_get()
|
||||
{
|
||||
return wfd;
|
||||
}
|
||||
|
||||
int ctl_wfd_new(struct ctl_wfd **out, sd_event *loop, sd_bus *bus)
|
||||
int dispd_new(struct dispd **out, sd_event *loop, sd_bus *bus)
|
||||
{
|
||||
int r;
|
||||
struct ctl_wfd *wfd = calloc(1, sizeof(struct ctl_wfd));
|
||||
if(!wfd) {
|
||||
struct dispd *dispd = calloc(1, sizeof(struct dispd));
|
||||
if(!dispd) {
|
||||
r = -ENOMEM;
|
||||
goto error;
|
||||
}
|
||||
|
||||
shl_htable_init_str(&wfd->sinks);
|
||||
shl_htable_init_uint(&wfd->sessions);
|
||||
wfd->loop = sd_event_ref(loop);
|
||||
shl_htable_init_str(&dispd->sinks);
|
||||
shl_htable_init_uint(&dispd->sessions);
|
||||
dispd->loop = sd_event_ref(loop);
|
||||
|
||||
r = ctl_wfd_init(wfd, bus);
|
||||
r = dispd_init(dispd, bus);
|
||||
if(0 > r) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
*out = wfd;
|
||||
*out = dispd;
|
||||
|
||||
return 0;
|
||||
|
||||
error:
|
||||
ctl_wfd_free(wfd);
|
||||
dispd_free(dispd);
|
||||
return log_ERR(r);
|
||||
}
|
||||
|
||||
static void ctl_wfd_free(struct ctl_wfd *wfd)
|
||||
static void dispd_free(struct dispd *dispd)
|
||||
{
|
||||
if(!wfd) {
|
||||
if(!dispd) {
|
||||
return;
|
||||
}
|
||||
|
||||
ctl_wifi_free(wfd->wifi);
|
||||
wfd->wifi = NULL;
|
||||
shl_htable_clear_str(&wfd->sinks, NULL, NULL);
|
||||
shl_htable_clear_uint(&wfd->sessions, NULL, NULL);
|
||||
ctl_wifi_free(dispd->wifi);
|
||||
dispd->wifi = NULL;
|
||||
shl_htable_clear_str(&dispd->sinks, NULL, NULL);
|
||||
shl_htable_clear_uint(&dispd->sessions, NULL, NULL);
|
||||
|
||||
if(wfd->loop) {
|
||||
sd_event_unref(wfd->loop);
|
||||
if(dispd->loop) {
|
||||
sd_event_unref(dispd->loop);
|
||||
}
|
||||
|
||||
free(wfd);
|
||||
free(dispd);
|
||||
}
|
||||
|
||||
static int ctl_wfd_handle_shutdown(sd_event_source *s,
|
||||
static int dispd_handle_shutdown(sd_event_source *s,
|
||||
uint64_t usec,
|
||||
void *userdata)
|
||||
{
|
||||
struct ctl_wfd *wfd = userdata;
|
||||
struct dispd *dispd = userdata;
|
||||
|
||||
sd_event_exit(wfd->loop, 0);
|
||||
sd_event_exit(dispd->loop, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ctl_wfd_shutdown(struct ctl_wfd *wfd)
|
||||
void dispd_shutdown(struct dispd *dispd)
|
||||
{
|
||||
uint64_t now;
|
||||
int r = sd_event_now(ctl_wfd_get_loop(), CLOCK_MONOTONIC, &now);
|
||||
int r = sd_event_now(dispd_get_loop(), CLOCK_MONOTONIC, &now);
|
||||
if(0 > r) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
r = sd_event_add_time(ctl_wfd_get_loop(),
|
||||
r = sd_event_add_time(dispd_get_loop(),
|
||||
NULL,
|
||||
CLOCK_MONOTONIC,
|
||||
now + 100 * 1000,
|
||||
0,
|
||||
ctl_wfd_handle_shutdown,
|
||||
wfd);
|
||||
dispd_handle_shutdown,
|
||||
dispd);
|
||||
if(0 <= r) {
|
||||
return;
|
||||
}
|
||||
|
||||
error:
|
||||
sd_event_exit(wfd->loop, 0);
|
||||
sd_event_exit(dispd->loop, 0);
|
||||
}
|
||||
|
||||
int ctl_wfd_add_sink(struct ctl_wfd *wfd,
|
||||
int dispd_add_sink(struct dispd *dispd,
|
||||
struct ctl_peer *p,
|
||||
union wfd_sube *sube,
|
||||
struct wfd_sink **out)
|
||||
struct dispd_sink **out)
|
||||
{
|
||||
_wfd_sink_free_ struct wfd_sink *s = NULL;
|
||||
int r = shl_htable_lookup_str(&wfd->sinks,
|
||||
_dispd_sink_free_ struct dispd_sink *s = NULL;
|
||||
int r = shl_htable_lookup_str(&dispd->sinks,
|
||||
p->label,
|
||||
NULL,
|
||||
NULL);
|
||||
|
@ -142,111 +142,111 @@ int ctl_wfd_add_sink(struct ctl_wfd *wfd,
|
|||
return -EEXIST;
|
||||
}
|
||||
|
||||
r = wfd_sink_new(&s, p, sube);
|
||||
r = dispd_sink_new(&s, p, sube);
|
||||
if(0 > r) {
|
||||
return log_ERR(r);
|
||||
}
|
||||
|
||||
r = shl_htable_insert_str(&wfd->sinks,
|
||||
wfd_sink_to_htable(s),
|
||||
r = shl_htable_insert_str(&dispd->sinks,
|
||||
dispd_sink_to_htable(s),
|
||||
NULL);
|
||||
if(0 > r) {
|
||||
return log_ERR(r);
|
||||
}
|
||||
|
||||
++wfd->n_sinks;
|
||||
++dispd->n_sinks;
|
||||
*out = s;
|
||||
s = NULL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ctl_wfd_find_sink_by_label(struct ctl_wfd *wfd,
|
||||
int dispd_find_sink_by_label(struct dispd *dispd,
|
||||
const char *label,
|
||||
struct wfd_sink **out)
|
||||
struct dispd_sink **out)
|
||||
{
|
||||
char **entry;
|
||||
int r = shl_htable_lookup_str(&wfd->sinks, label, NULL, &entry);
|
||||
int r = shl_htable_lookup_str(&dispd->sinks, label, NULL, &entry);
|
||||
if(r && out) {
|
||||
*out = wfd_sink_from_htable(entry);
|
||||
*out = dispd_sink_from_htable(entry);
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static int ctl_wfd_remove_sink_by_label(struct ctl_wfd *wfd,
|
||||
static int dispd_remove_sink_by_label(struct dispd *dispd,
|
||||
const char *label,
|
||||
struct wfd_sink **out)
|
||||
struct dispd_sink **out)
|
||||
{
|
||||
char **entry;
|
||||
int r = shl_htable_remove_str(&wfd->sinks, label, NULL, &entry);
|
||||
int r = shl_htable_remove_str(&dispd->sinks, label, NULL, &entry);
|
||||
if(!r) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
--wfd->n_sinks;
|
||||
--dispd->n_sinks;
|
||||
|
||||
if(out) {
|
||||
*out = wfd_sink_from_htable(entry);
|
||||
*out = dispd_sink_from_htable(entry);
|
||||
}
|
||||
|
||||
end:
|
||||
return r;
|
||||
}
|
||||
|
||||
unsigned int ctl_wfd_alloc_session_id(struct ctl_wfd *wfd)
|
||||
unsigned int dispd_alloc_session_id(struct dispd *dispd)
|
||||
{
|
||||
return ++wfd->id_pool;
|
||||
return ++dispd->id_pool;
|
||||
}
|
||||
|
||||
int ctl_wfd_add_session(struct ctl_wfd *wfd, struct wfd_session *s)
|
||||
int dispd_add_session(struct dispd *dispd, struct dispd_session *s)
|
||||
{
|
||||
int r;
|
||||
|
||||
assert(wfd);
|
||||
assert(s && wfd_session_get_id(s));
|
||||
assert(!ctl_wfd_find_session_by_id(wfd, wfd_session_get_id(s), NULL));
|
||||
assert(dispd);
|
||||
assert(s && dispd_session_get_id(s));
|
||||
assert(!dispd_find_session_by_id(dispd, dispd_session_get_id(s), NULL));
|
||||
|
||||
r = shl_htable_insert_uint(&wfd->sessions, wfd_session_to_htable(s));
|
||||
r = shl_htable_insert_uint(&dispd->sessions, dispd_session_to_htable(s));
|
||||
if(0 > r) {
|
||||
return log_ERR(r);
|
||||
}
|
||||
|
||||
++wfd->n_sessions;
|
||||
++dispd->n_sessions;
|
||||
|
||||
wfd_fn_session_new(s);
|
||||
dispd_fn_session_new(s);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ctl_wfd_find_session_by_id(struct ctl_wfd *wfd,
|
||||
int dispd_find_session_by_id(struct dispd *dispd,
|
||||
unsigned int id,
|
||||
struct wfd_session **out)
|
||||
struct dispd_session **out)
|
||||
{
|
||||
unsigned int *entry;
|
||||
int r = shl_htable_lookup_uint(&wfd->sessions, id, &entry);
|
||||
int r = shl_htable_lookup_uint(&dispd->sessions, id, &entry);
|
||||
if(r && out) {
|
||||
*out = wfd_session_from_htable(entry);
|
||||
*out = dispd_session_from_htable(entry);
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
int ctl_wfd_remove_session_by_id(struct ctl_wfd *wfd,
|
||||
int dispd_remove_session_by_id(struct dispd *dispd,
|
||||
unsigned int id,
|
||||
struct wfd_session **out)
|
||||
struct dispd_session **out)
|
||||
{
|
||||
unsigned int *entry;
|
||||
struct wfd_session *s;
|
||||
int r = shl_htable_remove_uint(&wfd->sessions, id, &entry);
|
||||
struct dispd_session *s;
|
||||
int r = shl_htable_remove_uint(&dispd->sessions, id, &entry);
|
||||
if(!r) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
--wfd->n_sessions;
|
||||
--dispd->n_sessions;
|
||||
|
||||
s = wfd_session_from_htable(entry);
|
||||
wfd_fn_session_free(s);
|
||||
s = dispd_session_from_htable(entry);
|
||||
dispd_fn_session_free(s);
|
||||
if(out) {
|
||||
*out = s;
|
||||
}
|
||||
|
@ -254,30 +254,30 @@ int ctl_wfd_remove_session_by_id(struct ctl_wfd *wfd,
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int ctl_wfd_fetch_info(sd_event_source *s, void *userdata)
|
||||
static int dispd_fetch_info(sd_event_source *s, void *userdata)
|
||||
{
|
||||
struct ctl_wfd *wfd = userdata;
|
||||
struct dispd *dispd = userdata;
|
||||
int r;
|
||||
|
||||
sd_event_source_unref(s);
|
||||
|
||||
r = ctl_wifi_fetch(wfd->wifi);
|
||||
r = ctl_wifi_fetch(dispd->wifi);
|
||||
if(0 > r) {
|
||||
log_warning("failed to fetch information about links and peers: %s",
|
||||
strerror(errno));
|
||||
sd_event_exit(wfd->loop, r);
|
||||
sd_event_exit(dispd->loop, r);
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static int ctl_wfd_handle_signal(sd_event_source *s,
|
||||
static int dispd_handle_signal(sd_event_source *s,
|
||||
const struct signalfd_siginfo *ssi,
|
||||
void *userdata)
|
||||
{
|
||||
int r;
|
||||
siginfo_t siginfo;
|
||||
struct ctl_wfd *wfd = userdata;
|
||||
struct dispd *dispd = userdata;
|
||||
|
||||
if(ssi->ssi_signo == SIGCHLD) {
|
||||
r = waitid(P_PID, ssi->ssi_pid, &siginfo, WNOHANG | WEXITED);
|
||||
|
@ -292,10 +292,10 @@ static int ctl_wfd_handle_signal(sd_event_source *s,
|
|||
return 0;
|
||||
}
|
||||
|
||||
return sd_event_exit(wfd->loop, 0);
|
||||
return sd_event_exit(dispd->loop, 0);
|
||||
}
|
||||
|
||||
static int ctl_wfd_init(struct ctl_wfd *wfd, sd_bus *bus)
|
||||
static int dispd_init(struct dispd *dispd, sd_bus *bus)
|
||||
{
|
||||
int i, r;
|
||||
const int signals[] = {
|
||||
|
@ -312,11 +312,11 @@ static int ctl_wfd_init(struct ctl_wfd *wfd, sd_bus *bus)
|
|||
break;
|
||||
}
|
||||
|
||||
r = sd_event_add_signal(wfd->loop,
|
||||
r = sd_event_add_signal(dispd->loop,
|
||||
NULL,
|
||||
signals[i],
|
||||
ctl_wfd_handle_signal,
|
||||
wfd);
|
||||
dispd_handle_signal,
|
||||
dispd);
|
||||
if(0 > r) {
|
||||
break;
|
||||
}
|
||||
|
@ -328,7 +328,7 @@ static int ctl_wfd_init(struct ctl_wfd *wfd, sd_bus *bus)
|
|||
goto end;
|
||||
}
|
||||
|
||||
r = sd_event_add_defer(wfd->loop, NULL, ctl_wfd_fetch_info, wfd);
|
||||
r = sd_event_add_defer(dispd->loop, NULL, dispd_fetch_info, dispd);
|
||||
if(0 > r) {
|
||||
log_vERRNO();
|
||||
|
||||
|
@ -336,7 +336,7 @@ static int ctl_wfd_init(struct ctl_wfd *wfd, sd_bus *bus)
|
|||
goto end;
|
||||
}
|
||||
|
||||
wfd->wifi = wifi;
|
||||
dispd->wifi = wifi;
|
||||
|
||||
end:
|
||||
return r;
|
||||
|
@ -344,7 +344,7 @@ end:
|
|||
|
||||
void ctl_fn_peer_new(struct ctl_peer *p)
|
||||
{
|
||||
struct wfd_sink *s;
|
||||
struct dispd_sink *s;
|
||||
union wfd_sube sube;
|
||||
int r;
|
||||
|
||||
|
@ -365,7 +365,7 @@ void ctl_fn_peer_new(struct ctl_peer *p)
|
|||
}
|
||||
|
||||
if(wfd_sube_device_is_sink(&sube)) {
|
||||
r = ctl_wfd_add_sink(ctl_wfd_get(), p, &sube, &s);
|
||||
r = dispd_add_sink(dispd_get(), p, &sube, &s);
|
||||
if(0 > r) {
|
||||
log_warning("failed to add sink (%s, '%s'): %s",
|
||||
p->friendly_name,
|
||||
|
@ -374,10 +374,10 @@ void ctl_fn_peer_new(struct ctl_peer *p)
|
|||
return log_vERRNO();
|
||||
}
|
||||
|
||||
r = wfd_fn_sink_new(s);
|
||||
r = dispd_fn_sink_new(s);
|
||||
if(0 > r) {
|
||||
log_warning("failed to publish newly added sink (%s): %s",
|
||||
wfd_sink_get_label(s),
|
||||
dispd_sink_get_label(s),
|
||||
strerror(errno));
|
||||
return log_vERRNO();
|
||||
}
|
||||
|
@ -392,14 +392,14 @@ void ctl_fn_peer_new(struct ctl_peer *p)
|
|||
|
||||
void ctl_fn_peer_free(struct ctl_peer *p)
|
||||
{
|
||||
struct wfd_sink *s;
|
||||
struct dispd_sink *s;
|
||||
int r;
|
||||
|
||||
r = ctl_wfd_remove_sink_by_label(wfd, p->label, &s);
|
||||
r = dispd_remove_sink_by_label(dispd, p->label, &s);
|
||||
if(r) {
|
||||
wfd_fn_sink_free(s);
|
||||
dispd_fn_sink_free(s);
|
||||
log_info("sink %s removed", s->label);
|
||||
wfd_sink_free(s);
|
||||
dispd_sink_free(s);
|
||||
}
|
||||
|
||||
log_info("peer %s down", p->label);
|
||||
|
@ -477,37 +477,37 @@ int main(int argc, char **argv)
|
|||
goto unref_bus;
|
||||
}
|
||||
|
||||
r = wfd_dbus_new(&wfd_dbus, event, bus);
|
||||
r = dispd_dbus_new(&dispd_dbus, event, bus);
|
||||
if(0 > r) {
|
||||
goto bus_detach_event;
|
||||
}
|
||||
|
||||
r = ctl_wfd_new(&wfd, event, bus);
|
||||
r = dispd_new(&dispd, event, bus);
|
||||
if(0 > r) {
|
||||
goto free_wfd_dbus;
|
||||
goto free_dispd_dbus;
|
||||
}
|
||||
|
||||
r = wfd_dbus_expose(wfd_dbus);
|
||||
r = dispd_dbus_expose(dispd_dbus);
|
||||
if(0 > r) {
|
||||
log_warning("unable to publish WFD service: %s", strerror(errno));
|
||||
goto free_ctl_wfd;
|
||||
goto free_dispd;
|
||||
}
|
||||
|
||||
r = sd_notify(false, "READY=1\n"
|
||||
"STATUS=Running..");
|
||||
if (0 > r) {
|
||||
log_warning("unable to notify systemd that we are ready: %s", strerror(errno));
|
||||
goto free_wfd_dbus;
|
||||
goto free_dispd_dbus;
|
||||
}
|
||||
|
||||
sd_event_loop(event);
|
||||
|
||||
sd_notify(false, "STATUS=Exiting..");
|
||||
|
||||
free_ctl_wfd:
|
||||
ctl_wfd_free(wfd);
|
||||
free_wfd_dbus:
|
||||
wfd_dbus_free(wfd_dbus);
|
||||
free_dispd:
|
||||
dispd_free(dispd);
|
||||
free_dispd_dbus:
|
||||
dispd_dbus_free(dispd_dbus);
|
||||
bus_detach_event:
|
||||
sd_bus_detach_event(bus);
|
||||
unref_bus:
|
||||
|
|
220
src/disp/dispd.h
Normal file
220
src/disp/dispd.h
Normal file
|
@ -0,0 +1,220 @@
|
|||
/*
|
||||
* MiracleCast - Wifi-Display/Miracast Implementation
|
||||
*
|
||||
* Copyright (c) 2013-2014 David Herrmann <dh.herrmann@gmail.com>
|
||||
*
|
||||
* MiracleCast is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* MiracleCast is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with MiracleCast; If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <systemd/sd-event.h>
|
||||
#include "shl_htable.h"
|
||||
#include "ctl.h"
|
||||
#include "wfd.h"
|
||||
|
||||
#ifndef DISP_DISP_H
|
||||
#define DISP_DISP_H
|
||||
|
||||
/* dispd session */
|
||||
#define dispd_session(s) ((struct dispd_session *) (s))
|
||||
#define dispd_is_session(s) ( \
|
||||
(s) && \
|
||||
(DISPD_SESSION_DIR_OUT == dispd_session(s)->dir || \
|
||||
DISPD_SESSION_DIR_IN == dispd_session(s)->dir) \
|
||||
)
|
||||
#define dispd_session_has_id(s) (0 < dispd_session_get_id(s))
|
||||
#define dispd_is_out_session(s) (DISPD_SESSION_DIR_OUT == dispd_session_get_dir(s))
|
||||
#define dispd_is_in_session(s) (DISPD_SESSION_DIR_IN == dispd_session_get_dir(s))
|
||||
#define _dispd_session_unref_ _shl_cleanup_(dispd_session_unrefp)
|
||||
|
||||
struct dispd_sink;
|
||||
struct dispd_session;
|
||||
struct rtsp_dispatch_entry;
|
||||
|
||||
enum dispd_session_dir
|
||||
{
|
||||
DISPD_SESSION_DIR_OUT,
|
||||
DISPD_SESSION_DIR_IN,
|
||||
};
|
||||
|
||||
enum dispd_session_state
|
||||
{
|
||||
DISPD_SESSION_STATE_NULL,
|
||||
DISPD_SESSION_STATE_CONNECTING,
|
||||
DISPD_SESSION_STATE_CAPS_EXCHANGING,
|
||||
DISPD_SESSION_STATE_ESTABLISHED,
|
||||
DISPD_SESSION_STATE_SETTING_UP,
|
||||
DISPD_SESSION_STATE_PAUSED,
|
||||
DISPD_SESSION_STATE_PLAYING,
|
||||
DISPD_SESSION_STATE_TEARING_DOWN,
|
||||
DISPD_SESSION_STATE_DESTROYED,
|
||||
};
|
||||
|
||||
struct dispd_rectangle
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
int width;
|
||||
int height;
|
||||
};
|
||||
|
||||
enum dispd_display_server_type
|
||||
{
|
||||
DISPD_DISPLAY_SERVER_TYPE_UNKNOWN = 0,
|
||||
DISPD_DISPLAY_SERVER_TYPE_X,
|
||||
};
|
||||
|
||||
enum dispd_audio_server_type
|
||||
{
|
||||
DISPD_AUDIO_SERVER_TYPE_UNKNOWN = 0,
|
||||
DISPD_AUDIO_SERVER_TYPE_PULSE_AUDIO,
|
||||
};
|
||||
|
||||
int dispd_out_session_new(struct dispd_session **out,
|
||||
unsigned int id,
|
||||
struct dispd_sink *sink);
|
||||
struct dispd_session * _dispd_session_ref(struct dispd_session *s);
|
||||
#define dispd_session_ref(s) ( \
|
||||
log_debug("dispd_session_ref(%p): %d => %d", (s), *(int *) s, 1 + *(int *) s), \
|
||||
_dispd_session_ref(s) \
|
||||
)
|
||||
void _dispd_session_unref(struct dispd_session *s);
|
||||
#define dispd_session_unref(s) { \
|
||||
log_debug("dispd_session_unref(%p): %d => %d", (s), *(int *) s, *(int *) s - 1); \
|
||||
_dispd_session_unref(s); \
|
||||
}
|
||||
|
||||
void dispd_session_unrefp(struct dispd_session **s);
|
||||
unsigned int * dispd_session_to_htable(struct dispd_session *s);
|
||||
struct dispd_session * dispd_session_from_htable(unsigned int *e);
|
||||
|
||||
int dispd_session_start(struct dispd_session *s);
|
||||
int dispd_session_resume(struct dispd_session *s);
|
||||
int dispd_session_pause(struct dispd_session *s);
|
||||
int dispd_session_teardown(struct dispd_session *s);
|
||||
int dispd_session_destroy(struct dispd_session *s);
|
||||
|
||||
bool dispd_session_is_established(struct dispd_session *s);
|
||||
unsigned int dispd_session_get_id(struct dispd_session *s);
|
||||
const char * dispd_session_get_stream_url(struct dispd_session *s);
|
||||
bool dispd_session_is_state(struct dispd_session *s, enum dispd_session_state state);
|
||||
enum dispd_session_state dispd_session_get_state(struct dispd_session *s);
|
||||
enum dispd_session_dir dispd_session_get_dir(struct dispd_session *s);
|
||||
struct dispd_sink * dispd_out_session_get_sink(struct dispd_session *s);
|
||||
|
||||
enum dispd_display_server_type dispd_session_get_disp_type(struct dispd_session *s);
|
||||
int dispd_session_set_disp_type(struct dispd_session *s, enum dispd_display_server_type);
|
||||
const char * dispd_session_get_disp_name(struct dispd_session *s);
|
||||
int dispd_session_set_disp_name(struct dispd_session *s, const char *disp_name);
|
||||
const char * dispd_session_get_disp_params(struct dispd_session *s);
|
||||
int dispd_session_set_disp_params(struct dispd_session *s, const char *disp_params);
|
||||
const char * dispd_session_get_disp_auth(struct dispd_session *s);
|
||||
int dispd_session_set_disp_auth(struct dispd_session *s, const char *disp_auth);
|
||||
const struct dispd_rectangle * dispd_session_get_disp_dimension(struct dispd_session *s);
|
||||
int dispd_session_set_disp_dimension(struct dispd_session *s, const struct dispd_rectangle *rect);
|
||||
enum dispd_audio_server_type dispd_session_get_audio_type(struct dispd_session *s);
|
||||
int dispd_session_set_audio_type(struct dispd_session *s, enum dispd_audio_server_type audio_type);
|
||||
const char * dispd_session_get_audio_dev_name(struct dispd_session *s);
|
||||
int dispd_session_set_audio_dev_name(struct dispd_session *s, const char *audio_dev_name);
|
||||
const char * dispd_session_get_runtime_path(struct dispd_session *s);
|
||||
int dispd_session_set_runtime_path(struct dispd_session *s,
|
||||
const char *runtime_path);
|
||||
uid_t dispd_session_get_client_uid(struct dispd_session *s);
|
||||
int dispd_session_set_client_uid(struct dispd_session *s, uid_t uid);
|
||||
uid_t dispd_session_get_client_gid(struct dispd_session *s);
|
||||
int dispd_session_set_client_gid(struct dispd_session *s, uid_t gid);
|
||||
pid_t dispd_session_get_client_pid(struct dispd_session *s);
|
||||
int dispd_session_set_client_pid(struct dispd_session *s, pid_t pid);
|
||||
|
||||
/* dispd sink */
|
||||
#define _dispd_sink_free_ _shl_cleanup_(dispd_sink_freep)
|
||||
#define dispd_sink_to_htable(s) (&(s)->label)
|
||||
#define dispd_sink_from_htable(s) shl_htable_entry(s, struct dispd_sink, label)
|
||||
|
||||
struct dispd_sink
|
||||
{
|
||||
struct ctl_peer *peer;
|
||||
union wfd_sube dev_info;
|
||||
char *label;
|
||||
struct dispd_session *session;
|
||||
|
||||
sd_event_source *session_cleanup_source;
|
||||
};
|
||||
|
||||
int dispd_sink_new(struct dispd_sink **out,
|
||||
struct ctl_peer *peer,
|
||||
union wfd_sube *sube);
|
||||
void dispd_sink_free(struct dispd_sink *sink);
|
||||
static inline void dispd_sink_freep(struct dispd_sink **s)
|
||||
{
|
||||
dispd_sink_free(*s);
|
||||
*s = NULL;
|
||||
}
|
||||
|
||||
int dispd_sink_create_session(struct dispd_sink *sink, struct dispd_session **out);
|
||||
|
||||
const char * dispd_sink_get_label(struct dispd_sink *sink);
|
||||
const union wfd_sube * dispd_sink_get_dev_info(struct dispd_sink *sink);
|
||||
bool dispd_sink_is_session_started(struct dispd_sink *sink);
|
||||
|
||||
void dispd_sink_handle_session_ended(struct dispd_sink *sink);
|
||||
|
||||
/* wfd handling */
|
||||
#define dispd_foreach_sink(_i, _w) \
|
||||
SHL_HTABLE_FOREACH_MACRO(_i, \
|
||||
&(_w)->sinks, \
|
||||
dispd_sink_from_htable)
|
||||
#define dispd_foreach_session(_i, _w) \
|
||||
SHL_HTABLE_FOREACH_MACRO(_i, \
|
||||
&(_w)->sessions, \
|
||||
dispd_session_from_htable)
|
||||
|
||||
struct dispd
|
||||
{
|
||||
sd_event *loop;
|
||||
struct ctl_wifi *wifi;
|
||||
struct shl_htable sinks;
|
||||
size_t n_sinks;
|
||||
struct shl_htable sessions;
|
||||
size_t n_sessions;
|
||||
unsigned int id_pool;
|
||||
};
|
||||
|
||||
struct dispd * dispd_get();
|
||||
void dispd_shutdown(struct dispd *wfd);
|
||||
|
||||
static inline struct sd_event * dispd_get_loop()
|
||||
{
|
||||
return dispd_get()->loop;
|
||||
}
|
||||
|
||||
int dispd_find_sink_by_label(struct dispd *wfd,
|
||||
const char *label,
|
||||
struct dispd_sink **out);
|
||||
int dispd_add_session(struct dispd *wfd, struct dispd_session *s);
|
||||
int dispd_find_session_by_id(struct dispd *wfd,
|
||||
unsigned int id,
|
||||
struct dispd_session **out);
|
||||
int dispd_remove_session_by_id(struct dispd *wfd,
|
||||
unsigned int id,
|
||||
struct dispd_session **out);
|
||||
unsigned int dispd_alloc_session_id(struct dispd *wfd);
|
||||
|
||||
int dispd_fn_session_new(struct dispd_session *s);
|
||||
int dispd_fn_session_free(struct dispd_session *s);
|
||||
int dispd_fn_out_session_ended(struct dispd_session *s);
|
||||
|
||||
int dispd_fn_sink_new(struct dispd_sink *s);
|
||||
int dispd_fn_sink_free(struct dispd_sink *s);
|
||||
|
||||
#endif /* DISP_DISP_H */
|
|
@ -8,13 +8,13 @@ endif
|
|||
|
||||
miracle_dispd_src = ['../ctl/ctl-cli.c',
|
||||
'../ctl/ctl-wifi.c',
|
||||
'wfd-sink.c',
|
||||
'wfd-dbus.c',
|
||||
'wfd-session.c',
|
||||
'wfd-out-session.c',
|
||||
'dispd.c',
|
||||
'../ctl/wfd.c',
|
||||
'wfd-arg.c',
|
||||
'dispd.c',
|
||||
'dispd-sink.c',
|
||||
'dispd-dbus.c',
|
||||
'dispd-session.c',
|
||||
'dispd-out-session.c',
|
||||
'dispd-arg.c',
|
||||
'dispd-encoder.c'
|
||||
]
|
||||
executable('miracle-dispd',
|
||||
|
|
|
@ -1,242 +0,0 @@
|
|||
/*
|
||||
* MiracleCast - Wifi-Display/Miracast Implementation
|
||||
*
|
||||
* Copyright (c) 2013-2014 David Herrmann <dh.herrmann@gmail.com>
|
||||
*
|
||||
* MiracleCast is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* MiracleCast is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with MiracleCast; If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "shl_macro.h"
|
||||
|
||||
#ifndef CTL_ARG_H
|
||||
#define CTL_ARG_H
|
||||
|
||||
#define wfd_arg_i8(_v) { .type = WFD_ARG_I8, .i8 = (_v) }
|
||||
#define wfd_arg_u8(_v) { .type = WFD_ARG_U8, .u8 = (_v) }
|
||||
#define wfd_arg_i16(_v) { .type = WFD_ARG_I16, .i16 = (_v) }
|
||||
#define wfd_arg_u16(_v) { .type = WFD_ARG_U16, .u16 = (_v) }
|
||||
#define wfd_arg_i32(_v) { .type = WFD_ARG_I32, .i32 = (_v) }
|
||||
#define wfd_arg_u32(_v) { .type = WFD_ARG_U32, .u32 = (_v) }
|
||||
#define wfd_arg_i64(_v) { .type = WFD_ARG_I64, .i64 = (_v) }
|
||||
#define wfd_arg_u64(_v) { .type = WFD_ARG_U64, .u64 = (_v) }
|
||||
#define wfd_arg_cstr(_v) { .type = WFD_ARG_CSTR, .ptr = (_v) }
|
||||
#define wfd_arg_cptr(_v) { .type = WFD_ARG_CPTR, .ptr = (_v) }
|
||||
#define wfd_arg_arg_list(_v) { \
|
||||
.type = WFD_ARG_ARG_LIST, \
|
||||
.ptr = &(struct wfd_arg_list) wfd_arg_list(_v) \
|
||||
}
|
||||
#define wfd_arg_dict(_k, _v) { \
|
||||
.type = WFD_ARG_DICT, \
|
||||
.k = (struct wfd_arg[]){_k}, \
|
||||
.v = (struct wfd_arg[]){_v} \
|
||||
}
|
||||
|
||||
#if INT_MAX == INT64_MAX
|
||||
#define wfd_arg_i(_v) wfd_arg_i64(_v)
|
||||
#define wfd_arg_u(_v) wfd_arg_u64(_v)
|
||||
#elif INT_MAX == INT32_MAX
|
||||
#define wfd_arg_i(_v) wfd_arg_i32(_v)
|
||||
#define wfd_arg_u(_v) wfd_arg_u32(_v)
|
||||
#else
|
||||
#error unsupported int size
|
||||
#endif
|
||||
|
||||
#define wfd_arg_type_id(_t) _Generic((_t), \
|
||||
int8_t: WFD_ARG_I8, \
|
||||
uint8_t: WFD_ARG_U8, \
|
||||
int16_t: WFD_ARG_I16, \
|
||||
uint16_t: WFD_ARG_U16, \
|
||||
int32_t: WFD_ARG_I32, \
|
||||
uint32_t: WFD_ARG_U32, \
|
||||
int64_t: WFD_ARG_I64, \
|
||||
uint64_t: WFD_ARG_U64, \
|
||||
const char *: WFD_ARG_CSTR, \
|
||||
const wfd_arg_list *: WFD_ARG_ARG_LIST, \
|
||||
char *: WFD_ARG_STR, \
|
||||
void *: WFD_ARG_PTR, \
|
||||
default: WFD_ARG_CPTR \
|
||||
)
|
||||
|
||||
#define wfd_arg_list(...) { \
|
||||
.argv = (struct wfd_arg[]) { \
|
||||
__VA_ARGS__ \
|
||||
}, \
|
||||
.discrete = true, \
|
||||
.dynamic = false, \
|
||||
.len = (sizeof((struct wfd_arg[]){ __VA_ARGS__ })/sizeof(struct wfd_arg)) \
|
||||
}
|
||||
|
||||
#define wfd_arg_get(_a, _v) ({ \
|
||||
*(_v) = _Generic(*(_v), \
|
||||
int8_t: wfd_arg_get_i8, \
|
||||
uint8_t: wfd_arg_get_u8, \
|
||||
int16_t: wfd_arg_get_i16, \
|
||||
uint16_t: wfd_arg_get_u16, \
|
||||
int32_t: wfd_arg_get_i32, \
|
||||
uint32_t: wfd_arg_get_u32, \
|
||||
int64_t: wfd_arg_get_i64, \
|
||||
uint64_t: wfd_arg_get_u64, \
|
||||
char *: wfd_arg_get_str, \
|
||||
const struct wfd_arg_list *: wfd_arg_get_arg_list, \
|
||||
const char *: wfd_arg_get_cstr, \
|
||||
void *: wfd_arg_get_ptr, \
|
||||
default: wfd_arg_get_cptr \
|
||||
)(_a); \
|
||||
})
|
||||
|
||||
#define wfd_arg_get_dictk(_a, _k) ({ \
|
||||
assert(_a); \
|
||||
assert(WFD_ARG_DICT == (_a)->type); \
|
||||
wfd_arg_get((_a)->k, (_k)); \
|
||||
})
|
||||
|
||||
#define wfd_arg_get_dictv(_a, _v) ({ \
|
||||
assert(_a); \
|
||||
assert(WFD_ARG_DICT == (_a)->type); \
|
||||
wfd_arg_get((_a)->v, (_v)); \
|
||||
})
|
||||
|
||||
#define wfd_arg_get_dict(_a, _k, _v) ({ \
|
||||
assert(_a); \
|
||||
assert(WFD_ARG_DICT == (_a)->type); \
|
||||
wfd_arg_get_dictk(_a, _k); \
|
||||
wfd_arg_get_dictv(_a, _v); \
|
||||
})
|
||||
|
||||
#define wfd_arg_list_get(_l, _i, _v) ({ \
|
||||
wfd_arg_get(wfd_arg_list_at((_l), (_i)), (_v)); \
|
||||
})
|
||||
|
||||
#define wfd_arg_list_get_dictk(_l, _i, _k) ({ \
|
||||
wfd_arg_get_dictk(wfd_arg_list_at((_l), (_i)), (_k)); \
|
||||
})
|
||||
|
||||
#define wfd_arg_list_get_dictv(_l, _i, _v) ({ \
|
||||
wfd_arg_get_dictv(wfd_arg_list_at((_l), (_i)), (_v)); \
|
||||
})
|
||||
|
||||
#define wfd_arg_list_get_dict(_l, _i, _k, _v) ({ \
|
||||
wfd_arg_get_dict(wfd_arg_list_at((_l), (_i)), (_k), (_v)); \
|
||||
})
|
||||
|
||||
enum wfd_arg_type
|
||||
{
|
||||
WFD_ARG_NONE,
|
||||
WFD_ARG_I8,
|
||||
WFD_ARG_I16,
|
||||
WFD_ARG_I32,
|
||||
WFD_ARG_I64,
|
||||
WFD_ARG_U8,
|
||||
WFD_ARG_U16,
|
||||
WFD_ARG_U32,
|
||||
WFD_ARG_U64,
|
||||
WFD_ARG_STR,
|
||||
WFD_ARG_CSTR,
|
||||
WFD_ARG_PTR,
|
||||
WFD_ARG_CPTR,
|
||||
WFD_ARG_DICT,
|
||||
WFD_ARG_ARG_LIST,
|
||||
};
|
||||
|
||||
struct wfd_arg
|
||||
{
|
||||
enum wfd_arg_type type;
|
||||
union
|
||||
{
|
||||
int8_t i8;
|
||||
uint8_t u8;
|
||||
int16_t i16;
|
||||
uint16_t u16;
|
||||
int32_t i32;
|
||||
uint32_t u32;
|
||||
int64_t i64;
|
||||
uint64_t u64;
|
||||
struct {
|
||||
void *ptr;
|
||||
void (*free)(void *);
|
||||
};
|
||||
struct {
|
||||
struct wfd_arg *k;
|
||||
struct wfd_arg *v;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
struct wfd_arg_list
|
||||
{
|
||||
size_t len: sizeof(size_t) - 2;
|
||||
bool discrete: 1;
|
||||
bool dynamic: 1;
|
||||
|
||||
union {
|
||||
struct wfd_arg * argv;
|
||||
struct wfd_arg args[0];
|
||||
};
|
||||
};
|
||||
|
||||
int wfd_arg_list_new(struct wfd_arg_list **out);
|
||||
void wfd_arg_list_clear(struct wfd_arg_list *l);
|
||||
static inline void wfd_arg_list_free(struct wfd_arg_list *l);
|
||||
static inline const struct wfd_arg * wfd_arg_list_at(const struct wfd_arg_list *l,
|
||||
int i);
|
||||
|
||||
static inline enum wfd_arg_type wfd_arg_get_type(struct wfd_arg *a);
|
||||
static inline void wfd_arg_free_ptr(struct wfd_arg *a);
|
||||
static inline void wfd_arg_clear(struct wfd_arg *a);
|
||||
|
||||
static inline int8_t wfd_arg_get_i8(const struct wfd_arg *a);
|
||||
static inline void wfd_arg_set_i8(struct wfd_arg *a, int8_t v);
|
||||
|
||||
static inline uint8_t wfd_arg_get_u8(const struct wfd_arg *a);
|
||||
static inline void wfd_arg_set_u8(struct wfd_arg *a, uint8_t v);
|
||||
|
||||
static inline int16_t wfd_arg_get_i16(const struct wfd_arg *a);
|
||||
static inline void wfd_arg_set_i16(struct wfd_arg *a, int16_t v);
|
||||
|
||||
static inline uint16_t wfd_arg_get_u16(const struct wfd_arg *a);
|
||||
static inline void wfd_arg_set_u16(struct wfd_arg *a, uint16_t v);
|
||||
|
||||
static inline int32_t wfd_arg_get_i32(const struct wfd_arg *a);
|
||||
static inline void wfd_arg_set_i32(struct wfd_arg *a, int32_t v);
|
||||
|
||||
static inline uint32_t wfd_arg_get_u32(const struct wfd_arg *a);
|
||||
static inline void wfd_arg_set_u32(struct wfd_arg *a, uint32_t v);
|
||||
|
||||
static inline int64_t wfd_arg_get_i64(const struct wfd_arg *a);
|
||||
static inline void wfd_arg_set_i64(struct wfd_arg *a, int64_t v);
|
||||
|
||||
static inline uint64_t wfd_arg_get_u64(const struct wfd_arg *a);
|
||||
static inline void wfd_arg_set_u64(struct wfd_arg *a, uint64_t v);
|
||||
|
||||
static inline const char * wfd_arg_get_cstr(const struct wfd_arg *a);
|
||||
static inline void wfd_arg_set_cstr(struct wfd_arg *a, const char * v);
|
||||
|
||||
static inline void wfd_arg_take_str(struct wfd_arg *a, char *v);
|
||||
static inline char * wfd_arg_get_str(const struct wfd_arg *a);
|
||||
static inline int wfd_arg_set_str(struct wfd_arg *a, const char *v);;
|
||||
|
||||
static inline const void * wfd_arg_get_cptr(const struct wfd_arg *a);
|
||||
static inline void wfd_arg_set_cptr(struct wfd_arg *a, const void * v);
|
||||
|
||||
static inline void wfd_arg_take_ptr(struct wfd_arg *a, void *v, void (*f)(void *));
|
||||
static inline void * wfd_arg_get_ptr(const struct wfd_arg *a);
|
||||
|
||||
static inline void wfd_arg_take_arg_list(struct wfd_arg *a, struct wfd_arg_list *l);
|
||||
static inline const struct wfd_arg_list * wfd_arg_get_arg_list(const struct wfd_arg *a);
|
||||
|
||||
#include "wfd-arg.inc"
|
||||
|
||||
#endif /* CTL_ARG_H */
|
|
@ -1,192 +0,0 @@
|
|||
/*
|
||||
* MiracleCast - Wifi-Display/Miracast Implementation
|
||||
*
|
||||
* Copyright (c) 2013-2014 David Herrmann <dh.herrmann@gmail.com>
|
||||
*
|
||||
* MiracleCast is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* MiracleCast is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with MiracleCast; If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#define wfd_arg_getter(_t, _s, _S) \
|
||||
static inline _t wfd_arg_get_##_s(const struct wfd_arg *a) \
|
||||
{ \
|
||||
assert(a); \
|
||||
assert(WFD_ARG_##_S == a->type); \
|
||||
return a->_s; \
|
||||
}
|
||||
|
||||
#define wfd_arg_setter(_t, _s, _S) \
|
||||
static inline void wfd_arg_set_##_s(struct wfd_arg *a, _t v) \
|
||||
{ \
|
||||
assert(a); \
|
||||
assert(!a->type || WFD_ARG_##_S == a->type); \
|
||||
*a = (struct wfd_arg) { .type = WFD_ARG_##_S, ._s = v }; \
|
||||
}
|
||||
|
||||
wfd_arg_getter(int8_t, i8, I8)
|
||||
wfd_arg_setter(int8_t, i8, I8)
|
||||
wfd_arg_getter(uint8_t, u8, U8)
|
||||
wfd_arg_setter(uint8_t, u8, U8)
|
||||
wfd_arg_getter(int16_t, i16, I16)
|
||||
wfd_arg_setter(int16_t, i16, I16)
|
||||
wfd_arg_getter(uint16_t, u16, U16)
|
||||
wfd_arg_setter(uint16_t, u16, U16)
|
||||
wfd_arg_getter(int32_t, i32, I32)
|
||||
wfd_arg_setter(int32_t, i32, I32)
|
||||
wfd_arg_getter(uint32_t, u32, U32)
|
||||
wfd_arg_setter(uint32_t, u32, U32)
|
||||
wfd_arg_getter(int64_t, i64, I64)
|
||||
wfd_arg_setter(int64_t, i64, I64)
|
||||
wfd_arg_getter(uint64_t, u64, U64)
|
||||
wfd_arg_setter(uint64_t, u64, U64)
|
||||
|
||||
static inline void wfd_arg_list_free(struct wfd_arg_list *l)
|
||||
{
|
||||
wfd_arg_list_clear(l);
|
||||
free(l);
|
||||
}
|
||||
|
||||
static inline const struct wfd_arg * wfd_arg_list_at(const struct wfd_arg_list *l,
|
||||
int i)
|
||||
{
|
||||
assert(l);
|
||||
assert(i >= 0 && i < l->len);
|
||||
return l->discrete ? &l->argv[i] : &l->args[i];
|
||||
}
|
||||
|
||||
static inline enum wfd_arg_type wfd_arg_get_type(struct wfd_arg *a)
|
||||
{
|
||||
assert(a);
|
||||
|
||||
return a->type;
|
||||
}
|
||||
|
||||
static inline void wfd_arg_free_ptr(struct wfd_arg *a)
|
||||
{
|
||||
if(!a || (WFD_ARG_STR != a->type && WFD_ARG_PTR != a->type)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(a->ptr && a->free) {
|
||||
(*a->free)(a->ptr);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void wfd_arg_clear(struct wfd_arg *a)
|
||||
{
|
||||
if(a) {
|
||||
wfd_arg_free_ptr(a);
|
||||
memset(a, 0, sizeof(*a));
|
||||
}
|
||||
}
|
||||
|
||||
static inline const char * wfd_arg_get_cstr(const struct wfd_arg *a)
|
||||
{
|
||||
assert(a);
|
||||
assert(WFD_ARG_CSTR == a->type || WFD_ARG_STR == a->type);
|
||||
|
||||
return a->ptr;
|
||||
}
|
||||
|
||||
static inline void wfd_arg_set_cstr(struct wfd_arg *a, const char * v)
|
||||
{
|
||||
assert(a);
|
||||
assert(!a->type || WFD_ARG_CSTR == a->type);
|
||||
|
||||
*a = (struct wfd_arg) { .type = WFD_ARG_CSTR, .ptr = (void *) v };
|
||||
}
|
||||
|
||||
static inline char * wfd_arg_get_str(const struct wfd_arg *a)
|
||||
{
|
||||
assert(a);
|
||||
assert(WFD_ARG_STR == a->type);
|
||||
|
||||
return a->ptr;
|
||||
}
|
||||
|
||||
static inline void wfd_arg_take_str(struct wfd_arg *a, char *v)
|
||||
{
|
||||
assert(a);
|
||||
assert(!a->type || WFD_ARG_STR == a->type || WFD_ARG_CSTR == a->type);
|
||||
|
||||
wfd_arg_free_ptr(a);
|
||||
*a = (struct wfd_arg) { .type = WFD_ARG_STR, .ptr = v, .free = free };
|
||||
}
|
||||
|
||||
static inline int wfd_arg_set_str(struct wfd_arg *a, const char *v)
|
||||
{
|
||||
char *s;
|
||||
|
||||
assert(a);
|
||||
assert(!a->type || WFD_ARG_STR == a->type);
|
||||
|
||||
s = strdup(v);
|
||||
if(!s) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
wfd_arg_take_str(a, s);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline const void * wfd_arg_get_cptr(const struct wfd_arg *a)
|
||||
{
|
||||
assert(a);
|
||||
assert(WFD_ARG_PTR <= a->type && WFD_ARG_CPTR == a->type);
|
||||
|
||||
return a->ptr;
|
||||
}
|
||||
|
||||
static inline void wfd_arg_set_cptr(struct wfd_arg *a, const void * v)
|
||||
{
|
||||
assert(a);
|
||||
assert(!a->type || WFD_ARG_CSTR == a->type);
|
||||
|
||||
*a = (struct wfd_arg) { .type = WFD_ARG_CPTR, .ptr = (void *) v };
|
||||
}
|
||||
|
||||
static inline void * wfd_arg_get_ptr(const struct wfd_arg *a)
|
||||
{
|
||||
assert(a);
|
||||
assert(WFD_ARG_PTR == a->type || WFD_ARG_STR == a->type);
|
||||
|
||||
return a->ptr;
|
||||
}
|
||||
|
||||
static inline void wfd_arg_take_ptr(struct wfd_arg *a, void *v, void (*f)(void *))
|
||||
{
|
||||
assert(a);
|
||||
assert(!a->type || WFD_ARG_PTR == a->type);
|
||||
|
||||
wfd_arg_free_ptr(a);
|
||||
*a = (struct wfd_arg) { .type = WFD_ARG_PTR, .ptr = v, .free = f };
|
||||
}
|
||||
|
||||
static inline void wfd_arg_take_arg_list(struct wfd_arg *a, struct wfd_arg_list *l)
|
||||
{
|
||||
assert(a);
|
||||
assert(!a->type || WFD_ARG_ARG_LIST == a->type);
|
||||
|
||||
wfd_arg_free_ptr(a);
|
||||
*a = (struct wfd_arg) { .type = WFD_ARG_ARG_LIST,
|
||||
.ptr = l,
|
||||
.free = (void (*)(void *)) wfd_arg_list_free };
|
||||
}
|
||||
|
||||
static inline const struct wfd_arg_list * wfd_arg_get_arg_list(const struct wfd_arg *a)
|
||||
{
|
||||
assert(a);
|
||||
assert(WFD_ARG_ARG_LIST == a->type);
|
||||
|
||||
return a->ptr;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue