1
0
Fork 0
mirror of https://github.com/albfan/miraclecast.git synced 2025-03-09 23:38:56 +00:00

move definitions related to miracle-dispd from src/ctl to src/disp

This commit is contained in:
Derek Dai 2017-03-25 15:37:57 +08:00
parent 0a7517d8e9
commit a0d0c9bc8c
No known key found for this signature in database
GPG key ID: E109CC97553EF009
8 changed files with 180 additions and 184 deletions

View file

@ -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, struct ctl_peer *ctl_wifi_search_peer(struct ctl_wifi *w,
const char *real_label); 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 */ /* sink handling */
struct ctl_sink; 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_connected(struct ctl_sink *s);
bool ctl_sink_is_closed(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 */ /* CLI handling */
extern unsigned int cli_max_sev; 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_new(struct ctl_link *l);
void ctl_fn_link_free(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_connected(struct ctl_sink *s);
void ctl_fn_sink_disconnected(struct ctl_sink *s); void ctl_fn_sink_disconnected(struct ctl_sink *s);
void ctl_fn_sink_resolution_set(struct ctl_sink *s); void ctl_fn_sink_resolution_set(struct ctl_sink *s);
void cli_fn_help(void); 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 */ #endif /* CTL_CTL_H */

View file

@ -21,6 +21,7 @@
#ifndef WFD_H #ifndef WFD_H
#define WFD_H #define WFD_H
#include <stdbool.h>
#include <assert.h> #include <assert.h>
#include <stdlib.h> #include <stdlib.h>

173
src/disp/disp.h Normal file
View file

@ -0,0 +1,173 @@
/*
* 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 "wfd.h"
#include "shl_htable.h"
#include <systemd/sd-event.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_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 */

View file

@ -27,6 +27,7 @@
#include <glib.h> #include <glib.h>
#include <gst/gst.h> #include <gst/gst.h>
#include "ctl.h" #include "ctl.h"
#include "disp.h"
#include "wfd.h" #include "wfd.h"
#include "wfd-dbus.h" #include "wfd-dbus.h"
#include "config.h" #include "config.h"
@ -300,23 +301,6 @@ end:
return r; 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) void ctl_fn_peer_new(struct ctl_peer *p)
{ {
struct wfd_sink *s; struct wfd_sink *s;

View file

@ -20,7 +20,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <systemd/sd-bus.h> #include <systemd/sd-bus.h>
#include "ctl.h" #include "disp.h"
#include "util.h" #include "util.h"
#include "wfd-dbus.h" #include "wfd-dbus.h"

View file

@ -23,11 +23,13 @@
#include <arpa/inet.h> #include <arpa/inet.h>
#include <unistd.h> #include <unistd.h>
#include <time.h> #include <time.h>
#include <stdio.h>
#include <gst/gst.h> #include <gst/gst.h>
#include <gst/base/base.h> #include <gst/base/base.h>
#include "wfd-session.h" #include "wfd-session.h"
#include "shl_log.h" #include "shl_log.h"
#include "rtsp.h" #include "rtsp.h"
#include "ctl.h"
#define LOCAL_RTP_PORT 16384 #define LOCAL_RTP_PORT 16384
#define LOCAL_RTCP_PORT 16385 #define LOCAL_RTCP_PORT 16385

View file

@ -17,7 +17,7 @@
* along with MiracleCast; If not, see <http://www.gnu.org/licenses/>. * along with MiracleCast; If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <unistd.h> #include <unistd.h>
#include "ctl.h" #include "disp.h"
#include "wfd-arg.h" #include "wfd-arg.h"
#ifndef CTL_WFD_SESSION_H #ifndef CTL_WFD_SESSION_H

View file

@ -22,6 +22,7 @@
#include <time.h> #include <time.h>
#include <systemd/sd-event.h> #include <systemd/sd-event.h>
#include "ctl.h" #include "ctl.h"
#include "disp.h"
#include "wfd-dbus.h" #include "wfd-dbus.h"
static int wfd_sink_set_session(struct wfd_sink *sink, static int wfd_sink_set_session(struct wfd_sink *sink,