mirror of
https://github.com/albfan/miraclecast.git
synced 2025-02-14 23:01:54 +00:00
miracle-dispd: improve session life cycle management
Change-Id: Icb43664439002f76d7f64252f4ba79533d04ba43
This commit is contained in:
parent
8a2b5e19b0
commit
ba10255f70
4 changed files with 46 additions and 81 deletions
|
@ -57,7 +57,7 @@ enum wfd_session_state
|
|||
WFD_SESSION_STATE_PAUSED,
|
||||
WFD_SESSION_STATE_PLAYING,
|
||||
WFD_SESSION_STATE_TEARING_DOWN,
|
||||
WFD_SESSION_STATE_TERMINATING,
|
||||
WFD_SESSION_STATE_DESTROYED,
|
||||
};
|
||||
|
||||
struct wfd_rectangle
|
||||
|
@ -94,7 +94,7 @@ 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_terminate(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);
|
||||
|
|
|
@ -59,6 +59,7 @@ int wfd_out_session_new(struct wfd_session **out,
|
|||
assert_ret(out);
|
||||
assert_ret(id);
|
||||
assert_ret(sink);
|
||||
|
||||
s = calloc(1, sizeof(struct wfd_out_session));
|
||||
if(!s) {
|
||||
return log_ENOMEM();
|
||||
|
@ -76,26 +77,6 @@ int wfd_out_session_new(struct wfd_session **out,
|
|||
os->fd = -1;
|
||||
os->sink = sink;
|
||||
|
||||
//enum wfd_resolution_standard std;
|
||||
//uint32_t mask;
|
||||
// r = vfd_get_mask_from_resolution(width, height, &std, &mask);
|
||||
// if(0 > r) {
|
||||
// return -EINVAL;
|
||||
// }
|
||||
|
||||
// os->mask = mask;
|
||||
// os->std = std;
|
||||
//
|
||||
// if(display_param) {
|
||||
// os->display_param_name = display_param;
|
||||
// display_param = strchr(display_param, '=');
|
||||
// if(!display_param) {
|
||||
// return -EINVAL;
|
||||
// }
|
||||
// *display_param ++ = '\0';
|
||||
// os->display_param_value = display_param;
|
||||
// }
|
||||
|
||||
*out = wfd_session_ref(s);
|
||||
|
||||
return 0;
|
||||
|
@ -350,8 +331,7 @@ static int wfd_out_session_request_get_parameter(struct wfd_session *s,
|
|||
return log_ERR(r);
|
||||
}
|
||||
|
||||
*out = m;
|
||||
m = NULL;
|
||||
*out = (rtsp_message_ref(m), m);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -408,8 +388,7 @@ static int wfd_out_session_handle_options_request(struct wfd_session *s,
|
|||
return log_ERR(r);
|
||||
}
|
||||
|
||||
*out_rep = rep;
|
||||
rep = NULL;
|
||||
*out_rep = (rtsp_message_ref(rep), rep);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -464,8 +443,7 @@ static int wfd_out_session_request_options(struct wfd_session *s,
|
|||
return log_ERR(r);
|
||||
}
|
||||
|
||||
*out = m;
|
||||
m = NULL;
|
||||
*out = (rtsp_message_ref(m), m);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -511,42 +489,21 @@ static int wfd_out_session_handle_pause_request(struct wfd_session *s,
|
|||
|
||||
static int wfd_out_session_handle_teardown_request(struct wfd_session *s,
|
||||
struct rtsp_message *req,
|
||||
struct rtsp_message **out_rep)
|
||||
struct rtsp_message **rep)
|
||||
{
|
||||
// pid_t pid;
|
||||
struct wfd_out_session *os = wfd_out_session(s);
|
||||
// _rtsp_message_unref_ struct rtsp_message *m = NULL;
|
||||
_rtsp_message_unref_ struct rtsp_message *m = NULL;
|
||||
int r;
|
||||
|
||||
// if(!os->encoder_source) {
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
// r = sd_event_source_get_child_pid(os->encoder_source, &pid);
|
||||
// if(0 > r) {
|
||||
// return log_ERRNO();
|
||||
// }
|
||||
|
||||
// log_info("terminating encoder %d", pid);
|
||||
// r = kill(pid, SIGTERM);
|
||||
|
||||
/*r = rtsp_message_new_reply_for(req,*/
|
||||
/*&m,*/
|
||||
/*RTSP_CODE_OK,*/
|
||||
/*NULL);*/
|
||||
/*if(0 > r) {*/
|
||||
/*return log_ERRNO();*/
|
||||
/*}*/
|
||||
|
||||
r = dispd_encoder_stop(os->encoder);
|
||||
|
||||
/**out_rep = m;*/
|
||||
/*m = NULL;*/
|
||||
|
||||
r = rtsp_message_new_reply_for(req,
|
||||
&m,
|
||||
RTSP_CODE_OK,
|
||||
NULL);
|
||||
if(0 > r) {
|
||||
return log_ERR(r);
|
||||
}
|
||||
|
||||
*rep = (rtsp_message_ref(m), m);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -212,33 +212,41 @@ int wfd_session_pause(struct wfd_session *s)
|
|||
|
||||
int wfd_session_teardown(struct wfd_session *s)
|
||||
{
|
||||
int r;
|
||||
assert_ret(wfd_is_session(s));
|
||||
assert_ret(wfd_session_is_established(s));
|
||||
assert_ret(session_vtbl[s->dir].teardown);
|
||||
|
||||
if(wfd_session_is_established(s)) {
|
||||
if(!session_vtbl[s->dir].teardown) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return session_vtbl[s->dir].teardown(s);;
|
||||
}
|
||||
else {
|
||||
/* notify and detach from sink */
|
||||
wfd_session_terminate(s);
|
||||
wfd_fn_out_session_ended(s);
|
||||
r = session_vtbl[s->dir].teardown(s);
|
||||
if(0 > r) {
|
||||
return log_ERR(r);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int wfd_session_terminate(struct wfd_session *s)
|
||||
int wfd_session_destroy(struct wfd_session *s)
|
||||
{
|
||||
assert_ret(wfd_is_session(s));
|
||||
|
||||
if(wfd_session_is_state(s, WFD_SESSION_STATE_DESTROYED)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
wfd_session_set_state(s, WFD_SESSION_STATE_DESTROYED);
|
||||
|
||||
if(session_vtbl[s->dir].destroy) {
|
||||
(*session_vtbl[s->dir].destroy)(s);
|
||||
}
|
||||
|
||||
if(s->rtsp) {
|
||||
if(s->req_cookie) {
|
||||
rtsp_call_async_cancel(s->rtsp, s->req_cookie);
|
||||
wfd_session_unref(s);
|
||||
s->req_cookie = 0;
|
||||
}
|
||||
|
||||
rtsp_remove_match(s->rtsp, wfd_session_handle_request, s);
|
||||
rtsp_detach_event(s->rtsp);
|
||||
rtsp_unref(s->rtsp);
|
||||
|
@ -279,7 +287,7 @@ int wfd_session_terminate(struct wfd_session *s)
|
|||
s->rtp_ports[1] = 0;
|
||||
s->last_request = RTSP_M_UNKNOWN;
|
||||
|
||||
s->state = WFD_SESSION_STATE_TERMINATING;
|
||||
wfd_fn_out_session_ended(s);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -306,7 +314,7 @@ void wfd_session_unref(struct wfd_session *s)
|
|||
return;
|
||||
}
|
||||
|
||||
wfd_session_terminate(s);
|
||||
wfd_session_destroy(s);
|
||||
|
||||
free(s);
|
||||
}
|
||||
|
@ -450,7 +458,7 @@ static int wfd_session_post_handle_request_n_reply(struct wfd_session *s,
|
|||
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;
|
||||
int i, r;
|
||||
int r, i;
|
||||
|
||||
assert_ret(s);
|
||||
assert_ret(RTSP_M_UNKNOWN != ror);
|
||||
|
@ -484,10 +492,6 @@ static int wfd_session_post_handle_request_n_reply(struct wfd_session *s,
|
|||
}
|
||||
}
|
||||
|
||||
if(WFD_SESSION_STATE_TEARING_DOWN == new_state) {
|
||||
wfd_fn_out_session_ended(s);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -562,7 +566,7 @@ static int wfd_session_handle_request(struct rtsp *bus,
|
|||
return 0;
|
||||
|
||||
error:
|
||||
wfd_session_terminate(s);
|
||||
wfd_session_destroy(s);
|
||||
|
||||
return log_ERR(r);
|
||||
}
|
||||
|
@ -575,6 +579,8 @@ static int wfd_session_handle_reply(struct rtsp *bus,
|
|||
enum rtsp_message_id id;
|
||||
struct wfd_session *s = userdata;
|
||||
|
||||
s->req_cookie = 0;
|
||||
|
||||
if(!m) {
|
||||
r = log_EPIPE();
|
||||
goto error;
|
||||
|
@ -607,7 +613,7 @@ static int wfd_session_handle_reply(struct rtsp *bus,
|
|||
goto end;
|
||||
|
||||
error:
|
||||
wfd_session_terminate(s);
|
||||
wfd_session_destroy(s);
|
||||
end:
|
||||
wfd_session_unref(s);
|
||||
|
||||
|
@ -649,9 +655,9 @@ int wfd_session_request(struct wfd_session *s,
|
|||
r = rtsp_call_async(s->rtsp,
|
||||
m,
|
||||
wfd_session_handle_reply,
|
||||
s,
|
||||
wfd_session_ref(s),
|
||||
0,
|
||||
NULL);
|
||||
&s->req_cookie);
|
||||
if(0 > r) {
|
||||
goto error;
|
||||
}
|
||||
|
@ -690,7 +696,7 @@ static int wfd_session_handle_io(sd_event_source *source,
|
|||
}
|
||||
}
|
||||
|
||||
if (mask & EPOLLIN || mask & EPOLLOUT) {
|
||||
if (mask & EPOLLIN) {
|
||||
r = (*session_vtbl[s->dir].handle_io)(s, err, &conn);
|
||||
if(0 > r) {
|
||||
return log_ERRNO();
|
||||
|
@ -722,7 +728,7 @@ static int wfd_session_handle_io(sd_event_source *source,
|
|||
}
|
||||
|
||||
if(mask & EPOLLHUP) {
|
||||
wfd_session_teardown(s);
|
||||
wfd_session_destroy(s);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -762,6 +768,7 @@ int wfd_session_start(struct wfd_session *s)
|
|||
enum wfd_display_server_type wfd_session_get_disp_type(struct wfd_session *s)
|
||||
{
|
||||
assert_retv(s, WFD_DISPLAY_SERVER_TYPE_UNKNOWN);
|
||||
|
||||
return s->disp_type;
|
||||
}
|
||||
|
||||
|
|
|
@ -101,6 +101,7 @@ struct wfd_session
|
|||
|
||||
unsigned int id;
|
||||
struct rtsp *rtsp;
|
||||
uint64_t req_cookie;
|
||||
uint16_t rtp_ports[2];
|
||||
struct wfd_video_formats *vformats;
|
||||
struct wfd_audio_codecs *acodecs;
|
||||
|
|
Loading…
Reference in a new issue