diff --git a/src/ctl/wfd-out-session.c b/src/ctl/wfd-out-session.c index 7000663..953feb3 100644 --- a/src/ctl/wfd-out-session.c +++ b/src/ctl/wfd-out-session.c @@ -30,12 +30,6 @@ struct wfd_out_session struct wfd_session parent; struct wfd_sink *sink; int fd; - - bool sink_has_video: 1; - bool sink_has_audio: 1; - bool sink_has_pref_disp_mode: 1; - bool sink_has_3d: 1; - bool sink_has_uibc: 1; }; static const struct rtsp_dispatch_entry out_session_rtsp_disp_tbl[]; @@ -190,13 +184,13 @@ static void wfd_out_session_distruct(struct wfd_session *s) static int wfd_out_session_initiate_request(struct wfd_session *s) { - return wfd_session_request(s, RTSP_M1_REQUEST_SINK_OPTIONS); + return wfd_session_request(s, + RTSP_M1_REQUEST_SINK_OPTIONS, + &(struct wfd_arg_list) wfd_arg_list(wfd_arg_cstr("SETUP"))); } static int wfd_out_session_handle_get_parameter_reply(struct wfd_session *s, - struct rtsp_message *m, - enum wfd_session_state *new_state, - enum rtsp_message_id *next_request) + struct rtsp_message *m) { struct wfd_video_formats *vformats; struct wfd_audio_codecs *acodecs; @@ -254,12 +248,11 @@ static int wfd_out_session_handle_get_parameter_reply(struct wfd_session *s, s->rtp_ports[1] = rtp_ports[1]; } - *next_request = RTSP_M4_SET_PARAMETER; - return 0; } static int wfd_out_session_request_get_parameter(struct wfd_session *s, + const struct wfd_arg_list *args, struct rtsp_message **out) { _rtsp_message_unref_ struct rtsp_message *m = NULL; @@ -306,9 +299,7 @@ static bool find_strv(const char *str, char **strv) static int wfd_out_session_handle_options_request(struct wfd_session *s, struct rtsp_message *req, - struct rtsp_message **out_rep, - enum wfd_session_state *new_state, - enum rtsp_message_id *next_request) + struct rtsp_message **out_rep) { const char *require; _rtsp_message_unref_ struct rtsp_message *rep = NULL; @@ -344,15 +335,11 @@ static int wfd_out_session_handle_options_request(struct wfd_session *s, *out_rep = rep; rep = NULL; - *next_request = RTSP_M3_GET_PARAMETER; - return 0; } static int wfd_out_session_handle_options_reply(struct wfd_session *s, - struct rtsp_message *m, - enum wfd_session_state *new_state, - enum rtsp_message_id *next_request) + struct rtsp_message *m) { int r; const char *public; @@ -383,6 +370,7 @@ static int wfd_out_session_handle_options_reply(struct wfd_session *s, } static int wfd_out_session_request_options(struct wfd_session *s, + const struct wfd_arg_list *args, struct rtsp_message **out) { _rtsp_message_unref_ struct rtsp_message *m = NULL; @@ -464,7 +452,7 @@ static int wfd_out_session_launch_gst(struct wfd_session *s, pid_t *out) exit(1); } -static int wfd_out_sessoin_handle_gst_term(sd_event_source *source, +static int wfd_out_session_handle_gst_term(sd_event_source *source, const siginfo_t *si, void *userdata) { @@ -482,9 +470,7 @@ static int wfd_out_sessoin_handle_gst_term(sd_event_source *source, static int wfd_out_session_handle_play_request(struct wfd_session *s, struct rtsp_message *req, - struct rtsp_message **out_rep, - enum wfd_session_state *new_state, - enum rtsp_message_id *next_request) + struct rtsp_message **out_rep) { _shl_free_ char *v; _rtsp_message_unref_ struct rtsp_message *m = NULL; @@ -522,7 +508,7 @@ static int wfd_out_session_handle_play_request(struct wfd_session *s, r = sd_event_add_child(ctl_wfd_get_loop(), NULL, gst, WEXITED, - wfd_out_sessoin_handle_gst_term, + wfd_out_session_handle_gst_term, s); if(0 > r) { kill(gst, SIGKILL); @@ -535,16 +521,14 @@ static int wfd_out_session_handle_play_request(struct wfd_session *s, *out_rep = m; m = NULL; - *new_state = WFD_SESSION_STATE_PLAYING; + /**new_state = WFD_SESSION_STATE_PLAYING;*/ return 0; } static int wfd_out_session_handle_setup_request(struct wfd_session *s, struct rtsp_message *req, - struct rtsp_message **out_rep, - enum wfd_session_state *new_state, - enum rtsp_message_id *next_request) + struct rtsp_message **out_rep) { int r; const char *l; @@ -610,52 +594,42 @@ static int wfd_out_session_handle_setup_request(struct wfd_session *s, } static int wfd_out_session_request_trigger(struct wfd_session *s, + const struct wfd_arg_list *args, struct rtsp_message **out) { _rtsp_message_unref_ struct rtsp_message *m = NULL; int r; + const char *method; - switch(wfd_session_get_state(s)) { - case WFD_SESSION_STATE_ESTABLISHED: - r = rtsp_message_new_request(s->rtsp, - &m, - "SET_PARAMETER", - wfd_session_get_stream_url(s)); - if(0 > r) { - return r; - } + assert(args); - r = rtsp_message_append(m, "{}", - "wfd_trigger_method", - "SETUP"); - if(0 > r) { - return r; - } - break; - default: - break; + wfd_arg_list_get(args, 0, &method); + + assert(method); + + r = rtsp_message_new_request(s->rtsp, + &m, + "SET_PARAMETER", + wfd_session_get_stream_url(s)); + if(0 > r) { + return r; } - if(m) { - *out = m; - m = NULL; + r = rtsp_message_append(m, "{}", + "wfd_trigger_method", + method); + if(0 > r) { + return r; } - return 0; -} - -static int wfd_out_session_handle_set_parameter_reply(struct wfd_session *s, - struct rtsp_message *m, - enum wfd_session_state *new_state, - enum rtsp_message_id *next_request) -{ - *new_state = WFD_SESSION_STATE_ESTABLISHED; - *next_request = RTSP_M5_TRIGGER; + *out = m; + m = NULL; return 0; } static int wfd_out_session_request_set_parameter(struct wfd_session *s, + const struct wfd_arg_list *args, struct rtsp_message **out) { _rtsp_message_unref_ struct rtsp_message *m; @@ -715,20 +689,45 @@ const struct wfd_session_vtable session_vtables[] = { }; static const struct rtsp_dispatch_entry out_session_rtsp_disp_tbl[] = { - [RTSP_M1_REQUEST_SINK_OPTIONS] = { + [RTSP_M1_REQUEST_SINK_OPTIONS] = { .request = wfd_out_session_request_options, .handle_reply = wfd_out_session_handle_options_reply }, - [RTSP_M2_REQUEST_SRC_OPTIONS] = { - .handle_request = wfd_out_session_handle_options_request + [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) + ), + ) }, - [RTSP_M3_GET_PARAMETER] = { + [RTSP_M3_GET_PARAMETER] = { .request = wfd_out_session_request_get_parameter, - .handle_reply = wfd_out_session_handle_get_parameter_reply + .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) + ), + ) }, - [RTSP_M4_SET_PARAMETER] = { + [RTSP_M4_SET_PARAMETER] = { .request = wfd_out_session_request_set_parameter, - .handle_reply = wfd_out_session_handle_set_parameter_reply + .rule = wfd_arg_list( + wfd_arg_dict( + wfd_arg_u(WFD_SESSION_ARG_NEXT_REQUEST), + wfd_arg_u(RTSP_M5_TRIGGER) + ), + wfd_arg_dict( + wfd_arg_u(WFD_SESSION_ARG_NEW_STATE), + wfd_arg_u(WFD_SESSION_STATE_ESTABLISHED) + ), + wfd_arg_dict( + wfd_arg_u(WFD_SESSION_ARG_REQUEST_ARGS), + wfd_arg_arg_list(wfd_arg_cstr("SETUP")) + ), + ) }, [RTSP_M5_TRIGGER] = { .request = wfd_out_session_request_trigger, @@ -758,3 +757,10 @@ static const struct rtsp_dispatch_entry out_session_rtsp_disp_tbl[] = { [RTSP_M16_KEEPALIVE] = { }, }; + +struct X +{ + int a; + int b; +}; + diff --git a/src/ctl/wfd-session.c b/src/ctl/wfd-session.c index 2c9a620..d9c6a1d 100644 --- a/src/ctl/wfd-session.c +++ b/src/ctl/wfd-session.c @@ -39,6 +39,7 @@ extern const struct rtsp_dispatch_entry out_session_rtsp_disp_tbl[]; static inline int wfd_session_do_request(struct wfd_session *s, enum rtsp_message_id id, + const struct wfd_arg_list *args, struct rtsp_message **out) { if(!rtsp_message_id_is_valid(id)) { @@ -46,15 +47,13 @@ static inline int wfd_session_do_request(struct wfd_session *s, } assert(s->rtsp_disp_tbl[id].request); - return (*s->rtsp_disp_tbl[id].request)(s, out); + return (*s->rtsp_disp_tbl[id].request)(s, args, out); } static inline int wfd_session_do_handle_request(struct wfd_session *s, enum rtsp_message_id id, struct rtsp_message *req, - struct rtsp_message **out_rep, - enum wfd_session_state *new_state, - enum rtsp_message_id *next_request) + struct rtsp_message **out_rep) { if(!rtsp_message_id_is_valid(id)) { return -EINVAL; @@ -63,16 +62,12 @@ static inline int wfd_session_do_handle_request(struct wfd_session *s, return (*s->rtsp_disp_tbl[id].handle_request)(s, req, - out_rep, - new_state, - next_request); + out_rep); } static inline int wfd_session_do_handle_reply(struct wfd_session *s, enum rtsp_message_id id, - struct rtsp_message *m, - enum wfd_session_state *new_state, - enum rtsp_message_id *next_request) + struct rtsp_message *m) { if(!rtsp_message_id_is_valid(id)) { return -EINVAL; @@ -82,7 +77,7 @@ static inline int wfd_session_do_handle_reply(struct wfd_session *s, return 0; } - return (*s->rtsp_disp_tbl[id].handle_reply)(s, m, new_state, next_request); + return (*s->rtsp_disp_tbl[id].handle_reply)(s, m); } uint64_t wfd_session_get_id(struct wfd_session *s) @@ -292,14 +287,51 @@ 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, + enum rtsp_message_id ror) +{ + const struct wfd_arg_list *args = &s->rtsp_disp_tbl[ror].rule; + enum rtsp_message_id next_request = RTSP_M_UNKNOWN; + enum wfd_session_arg_id arg_id; + enum wfd_session_state new_state; + const struct wfd_arg_list *req_args; + int i; + + if(!args->len) { + return 0; + } + + for(i = 0; i < args->len; i ++) { + wfd_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); + break; + case WFD_SESSION_ARG_NEW_STATE: + wfd_arg_list_get_dictv(args, i, &new_state); + wfd_session_set_state(s, new_state); + break; + case WFD_SESSION_ARG_REQUEST_ARGS: + wfd_arg_list_get_dictv(args, i, &req_args); + default: + break; + } + } + + if(RTSP_M_UNKNOWN != next_request) { + return wfd_session_request(s, next_request, req_args); + } + + return 0; +} + static int wfd_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; - enum rtsp_message_id id, next_request = RTSP_M_UNKNOWN; - enum wfd_session_state new_state = WFD_SESSION_STATE_NULL; + enum rtsp_message_id id; int r; id = wfd_session_message_to_id(s, m); @@ -315,9 +347,7 @@ static int wfd_session_handle_request(struct rtsp *bus, r = wfd_session_do_handle_request(s, id, m, - &rep, - &new_state, - &next_request); + &rep); if(0 > r) { goto error; } @@ -336,15 +366,9 @@ static int wfd_session_handle_request(struct rtsp *bus, id, (char *) rtsp_message_get_raw(rep)); - if(WFD_SESSION_STATE_NULL != new_state) { - wfd_session_set_state(s, new_state); - } - - if(rtsp_message_id_is_valid(next_request)) { - r = wfd_session_request(s, next_request); - if(0 > r) { - goto error; - } + r = wfd_session_post_handle_request_n_reply(s, id); + if(0 > r) { + goto error; } return 0; @@ -363,8 +387,6 @@ static int wfd_session_handle_reply(struct rtsp *bus, int r; enum rtsp_message_id id; struct wfd_session *s = userdata; - enum wfd_session_state new_state = WFD_SESSION_STATE_NULL; - enum rtsp_message_id next_request = RTSP_M_UNKNOWN; if(!m) { r = 0; @@ -383,20 +405,14 @@ 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, &new_state, &next_request); + r = wfd_session_do_handle_reply(s, id, m); if(0 > r) { goto error; } - if(WFD_SESSION_STATE_NULL != new_state) { - wfd_session_set_state(s, new_state); - } - - if(rtsp_message_id_is_valid(next_request)) { - r = wfd_session_request(s, next_request); - if(0 > r) { - goto error; - } + r = wfd_session_post_handle_request_n_reply(s, id); + if(0 > r) { + goto error; } return 0; @@ -406,14 +422,16 @@ error: return r; } -int wfd_session_request(struct wfd_session *s, enum rtsp_message_id id) +int wfd_session_request(struct wfd_session *s, + enum rtsp_message_id id, + const struct wfd_arg_list *args) { int r; _rtsp_message_unref_ struct rtsp_message *m = NULL; assert(s); - r = wfd_session_do_request(s, id, &m); + r = wfd_session_do_request(s, id, args, &m); if(0 > r) { return r; } diff --git a/src/ctl/wfd-session.h b/src/ctl/wfd-session.h index c2e8868..acd4f5a 100644 --- a/src/ctl/wfd-session.h +++ b/src/ctl/wfd-session.h @@ -16,11 +16,12 @@ * You should have received a copy of the GNU Lesser General Public License * along with MiracleCast; If not, see . */ -#ifndef MIRACLE_OUT_SESSION_H -#define MIRACLE_OUT_SESSION_H - #include #include "ctl.h" +#include "wfd-arg.h" + +#ifndef CTL_WFD_SESSION_H +#define CTL_WFD_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)) @@ -58,20 +59,26 @@ enum wfd_stream_id WFD_STREAM_ID_SECONDARY, }; +enum wfd_session_arg_id +{ + WFD_SESSION_ARG_NEXT_REQUEST, + WFD_SESSION_ARG_NEW_STATE, + WFD_SESSION_ARG_REQUEST_ARGS, +}; + struct rtsp_dispatch_entry { union { - int (*request)(struct wfd_session *s, struct rtsp_message **out); + int (*request)(struct wfd_session *s, + const struct wfd_arg_list *args, + struct rtsp_message **out); int (*handle_request)(struct wfd_session *s, struct rtsp_message *req, - struct rtsp_message **out_rep, - enum wfd_session_state *new_state, - enum rtsp_message_id *next_request); + struct rtsp_message **out_rep); }; int (*handle_reply)(struct wfd_session *s, - struct rtsp_message *m, - enum wfd_session_state *new_state, - enum rtsp_message_id *next_request); + struct rtsp_message *m); + struct wfd_arg_list rule; }; struct wfd_session_vtable @@ -107,11 +114,15 @@ struct wfd_session }; int wfd_session_init(struct wfd_session *s); -const char * rtsp_message_id_to_string(enum rtsp_message_id id); -struct wfd_sink * wfd_out_session_get_sink(struct wfd_session *s); -int wfd_session_request(struct wfd_session *s, enum rtsp_message_id id); int wfd_session_gen_stream_url(struct wfd_session *s, const char *local_addr, enum wfd_stream_id id); +int wfd_session_request(struct wfd_session *s, + enum rtsp_message_id id, + const struct wfd_arg_list *args); -#endif /* MIRACLE_OUT_SESSION_H */ +struct wfd_sink * wfd_out_session_get_sink(struct wfd_session *s); + +const char * rtsp_message_id_to_string(enum rtsp_message_id id); + +#endif /* CTL_WFD_SESSION_H */