diff --git a/src/ctl/ctl.h b/src/ctl/ctl.h index 06a7202..57f5f4c 100644 --- a/src/ctl/ctl.h +++ b/src/ctl/ctl.h @@ -108,20 +108,6 @@ struct ctl_peer *ctl_wifi_find_peer(struct ctl_wifi *w, struct ctl_peer *ctl_wifi_search_peer(struct ctl_wifi *w, const char *real_label); -/* source handling */ - -struct wfd_src; - -int wfd_src_new(struct wfd_src **out, - sd_event *event); -void wfd_src_free(struct wfd_src *s); - -int wfd_src_listen(struct wfd_src *s, const char *local); -void wfd_src_close(struct wfd_src *s); -bool wfd_src_is_connecting(struct wfd_src *s); -bool wfd_src_is_connected(struct wfd_src *s); -bool wfd_src_is_closed(struct wfd_src *s); - /* sink handling */ struct ctl_sink; @@ -136,145 +122,6 @@ bool ctl_sink_is_connecting(struct ctl_sink *s); bool ctl_sink_is_connected(struct ctl_sink *s); bool ctl_sink_is_closed(struct ctl_sink *s); -/* 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_free_ _shl_cleanup_(wfd_session_free_p) - -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_SETING_UP, - WFD_SESSION_STATE_PAUSED, - WFD_SESSION_STATE_PLAYING, - WFD_SESSION_STATE_TEARING_DOWN, -}; - -int wfd_out_session_new(struct wfd_session **out, - struct wfd_sink *sink, - const char *authority, - const char *display, - uint32_t x, - uint32_t y, - uint32_t width, - uint32_t height, - const char *audio_dev); -int wfd_session_start(struct wfd_session *s, uint64_t id); -enum wfd_session_dir wfd_session_get_dir(struct wfd_session *s); -uint64_t wfd_session_get_id(struct wfd_session *s); -const char * wfd_session_get_stream_url(struct wfd_session *s); -enum wfd_session_state wfd_session_get_state(struct wfd_session *s); -int wfd_session_is_established(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); -void wfd_session_free(struct wfd_session *s); -uint64_t wfd_session_get_id(struct wfd_session *s); -struct wfd_sink * wfd_out_session_get_sink(struct wfd_session *s); -void wfd_session_free_p(struct wfd_session **s); -unsigned int * wfd_session_to_htable(struct wfd_session *s); -struct wfd_session * wfd_session_from_htable(unsigned int *e); - -/* 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); - -const char * wfd_sink_get_label(struct wfd_sink *sink); -const union wfd_sube * wfd_sink_get_dev_info(struct wfd_sink *sink); -int wfd_sink_start_session(struct wfd_sink *sink, - struct wfd_session **out, - const char *authority, - const char *display, - uint32_t x, - uint32_t y, - uint32_t width, - uint32_t height, - const char *audio_dev); -void wfd_sink_handle_session_ended(struct wfd_sink *sink); -bool wfd_sink_is_session_started(struct wfd_sink *sink); -static inline void wfd_sink_freep(struct wfd_sink **s) -{ - wfd_sink_free(*s); - *s = NULL; -} - -/* 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; - - sd_event_source *signal_sources[4]; -}; - -struct ctl_wfd * ctl_wfd_get(); -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); -static inline struct sd_event * ctl_wfd_get_loop() -{ - return ctl_wfd_get()->loop; -} - /* CLI handling */ extern unsigned int cli_max_sev; @@ -396,23 +243,11 @@ void ctl_fn_peer_disconnected(struct ctl_peer *p); void ctl_fn_link_new(struct ctl_link *l); void ctl_fn_link_free(struct ctl_link *l); -void wfd_fn_src_setup(struct wfd_src *s); -void wfd_fn_src_playing(struct wfd_src *s); -void wfd_fn_src_connected(struct wfd_src *s); -void wfd_fn_src_disconnected(struct wfd_src *s); - void ctl_fn_sink_connected(struct ctl_sink *s); void ctl_fn_sink_disconnected(struct ctl_sink *s); void ctl_fn_sink_resolution_set(struct ctl_sink *s); void cli_fn_help(void); -int wfd_fn_sink_new(struct wfd_sink *s); -int wfd_fn_sink_free(struct wfd_sink *s); - -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); - #endif /* CTL_CTL_H */ diff --git a/src/ctl/wfd.h b/src/ctl/wfd.h index 02a8432..8443a8f 100644 --- a/src/ctl/wfd.h +++ b/src/ctl/wfd.h @@ -21,6 +21,7 @@ #ifndef WFD_H #define WFD_H +#include #include #include diff --git a/src/disp/disp.h b/src/disp/disp.h new file mode 100644 index 0000000..0ddcc2b --- /dev/null +++ b/src/disp/disp.h @@ -0,0 +1,173 @@ +/* + * MiracleCast - Wifi-Display/Miracast Implementation + * + * Copyright (c) 2013-2014 David Herrmann + * + * 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 . + */ + +#include "wfd.h" +#include "shl_htable.h" +#include + +#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_free_ _shl_cleanup_(wfd_session_free_p) + +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_SETING_UP, + WFD_SESSION_STATE_PAUSED, + WFD_SESSION_STATE_PLAYING, + WFD_SESSION_STATE_TEARING_DOWN, +}; + +int wfd_out_session_new(struct wfd_session **out, + struct wfd_sink *sink, + const char *authority, + const char *display, + uint32_t x, + uint32_t y, + uint32_t width, + uint32_t height, + const char *audio_dev); +int wfd_session_start(struct wfd_session *s, uint64_t id); +enum wfd_session_dir wfd_session_get_dir(struct wfd_session *s); +uint64_t wfd_session_get_id(struct wfd_session *s); +const char * wfd_session_get_stream_url(struct wfd_session *s); +enum wfd_session_state wfd_session_get_state(struct wfd_session *s); +int wfd_session_is_established(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); +void wfd_session_free(struct wfd_session *s); +uint64_t wfd_session_get_id(struct wfd_session *s); +struct wfd_sink * wfd_out_session_get_sink(struct wfd_session *s); +void wfd_session_free_p(struct wfd_session **s); +unsigned int * wfd_session_to_htable(struct wfd_session *s); +struct wfd_session * wfd_session_from_htable(unsigned int *e); + +/* 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); + +const char * wfd_sink_get_label(struct wfd_sink *sink); +const union wfd_sube * wfd_sink_get_dev_info(struct wfd_sink *sink); +int wfd_sink_start_session(struct wfd_sink *sink, + struct wfd_session **out, + const char *authority, + const char *display, + uint32_t x, + uint32_t y, + uint32_t width, + uint32_t height, + const char *audio_dev); +void wfd_sink_handle_session_ended(struct wfd_sink *sink); +bool wfd_sink_is_session_started(struct wfd_sink *sink); +static inline void wfd_sink_freep(struct wfd_sink **s) +{ + wfd_sink_free(*s); + *s = NULL; +} + +/* 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; + + sd_event_source *signal_sources[4]; +}; + +struct ctl_wfd * ctl_wfd_get(); +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); +static inline struct sd_event * ctl_wfd_get_loop() +{ + return ctl_wfd_get()->loop; +} + +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 */ diff --git a/src/disp/dispd.c b/src/disp/dispd.c index 2ecffeb..4d3e673 100644 --- a/src/disp/dispd.c +++ b/src/disp/dispd.c @@ -27,6 +27,7 @@ #include #include #include "ctl.h" +#include "disp.h" #include "wfd.h" #include "wfd-dbus.h" #include "config.h" @@ -300,23 +301,6 @@ end: return r; } -/* Callbacks from ctl-src */ -void wfd_fn_src_connected(struct wfd_src *s) -{ -} - -void wfd_fn_src_disconnected(struct wfd_src *s) -{ -} - -void wfd_fn_src_setup(struct wfd_src *s) -{ -} - -void wfd_fn_src_playing(struct wfd_src *s) -{ -} - void ctl_fn_peer_new(struct ctl_peer *p) { struct wfd_sink *s; diff --git a/src/disp/wfd-dbus.c b/src/disp/wfd-dbus.c index d834585..3cd3fd0 100644 --- a/src/disp/wfd-dbus.c +++ b/src/disp/wfd-dbus.c @@ -20,7 +20,7 @@ #include #include #include -#include "ctl.h" +#include "disp.h" #include "util.h" #include "wfd-dbus.h" diff --git a/src/disp/wfd-out-session.c b/src/disp/wfd-out-session.c index eb28342..6e147ff 100644 --- a/src/disp/wfd-out-session.c +++ b/src/disp/wfd-out-session.c @@ -23,11 +23,13 @@ #include #include #include +#include #include #include #include "wfd-session.h" #include "shl_log.h" #include "rtsp.h" +#include "ctl.h" #define LOCAL_RTP_PORT 16384 #define LOCAL_RTCP_PORT 16385 diff --git a/src/disp/wfd-session.h b/src/disp/wfd-session.h index 548ba17..2c46142 100644 --- a/src/disp/wfd-session.h +++ b/src/disp/wfd-session.h @@ -17,7 +17,7 @@ * along with MiracleCast; If not, see . */ #include -#include "ctl.h" +#include "disp.h" #include "wfd-arg.h" #ifndef CTL_WFD_SESSION_H diff --git a/src/disp/wfd-sink.c b/src/disp/wfd-sink.c index 4d5a3b5..29e6a12 100644 --- a/src/disp/wfd-sink.c +++ b/src/disp/wfd-sink.c @@ -22,6 +22,7 @@ #include #include #include "ctl.h" +#include "disp.h" #include "wfd-dbus.h" static int wfd_sink_set_session(struct wfd_sink *sink,