1
0
Fork 0
mirror of https://github.com/albfan/miraclecast.git synced 2025-02-15 04:42:06 +00:00

miracle-wfdctl: handle gst messages and reflect state onto session

This commit is contained in:
Derek Dai 2017-03-17 15:12:45 +08:00
parent afec924d49
commit 49f3e5fbaa
No known key found for this signature in database
GPG key ID: E109CC97553EF009
3 changed files with 47 additions and 18 deletions

View file

@ -165,8 +165,8 @@ enum wfd_session_state
WFD_SESSION_STATE_CAPS_EXCHANGING, WFD_SESSION_STATE_CAPS_EXCHANGING,
WFD_SESSION_STATE_ESTABLISHED, WFD_SESSION_STATE_ESTABLISHED,
WFD_SESSION_STATE_SETING_UP, WFD_SESSION_STATE_SETING_UP,
WFD_SESSION_STATE_PLAYING,
WFD_SESSION_STATE_PAUSED, WFD_SESSION_STATE_PAUSED,
WFD_SESSION_STATE_PLAYING,
WFD_SESSION_STATE_TEARING_DOWN, WFD_SESSION_STATE_TEARING_DOWN,
}; };

View file

@ -322,7 +322,7 @@ void wfd_out_session_destroy(struct wfd_session *s)
} }
if(os->bus) { if(os->bus) {
gst_bus_remove_signal_watch(os->bus); gst_bus_remove_watch(os->bus);
g_object_unref(os->bus); g_object_unref(os->bus);
os->bus = NULL; os->bus = NULL;
} }
@ -545,6 +545,44 @@ static int wfd_out_session_request_options(struct wfd_session *s,
return 0; return 0;
} }
static gboolean wfd_out_session_handle_gst_message(GstBus *bus,
GstMessage *m,
gpointer userdata)
{
struct wfd_session *s = userdata;
struct wfd_out_session *os = userdata;
GstState old_state, new_state;
switch(GST_MESSAGE_TYPE(m)) {
case GST_MESSAGE_STATE_CHANGED:
if(os->pipeline != (void *) GST_MESSAGE_SRC(m)) {
break;
}
gst_message_parse_state_changed(m, &old_state, &new_state, NULL);
if(GST_STATE_PLAYING == new_state) {
log_info("stream is playing");
wfd_session_set_state(s, WFD_SESSION_STATE_PLAYING);
}
else if(GST_STATE_PLAYING == old_state &&
GST_STATE_PAUSED == new_state) {
log_info("stream is paused");
wfd_session_set_state(s, WFD_SESSION_STATE_PAUSED);
}
break;
case GST_MESSAGE_EOS:
case GST_MESSAGE_ERROR:
log_warning("%s encounter unexpected error or EOS",
GST_MESSAGE_SRC_NAME(m));
wfd_session_teardown(s);
break;
default:
break;
}
return TRUE;
}
inline static char * uint16_to_str(uint16_t i, char *buf, size_t len) inline static char * uint16_to_str(uint16_t i, char *buf, size_t len)
{ {
snprintf(buf, len, "%u", i); snprintf(buf, len, "%u", i);
@ -704,14 +742,14 @@ static int wfd_out_session_create_pipeline(struct wfd_session *s)
g_object_unref(vsrc); g_object_unref(vsrc);
vsrc = NULL; vsrc = NULL;
r = gst_element_set_state(pipeline, GST_STATE_READY); r = gst_element_set_state(pipeline, GST_STATE_PAUSED);
if(GST_STATE_CHANGE_FAILURE == r) { if(GST_STATE_CHANGE_FAILURE == r) {
g_object_unref(pipeline); g_object_unref(pipeline);
return -1; return -1;
} }
bus = gst_element_get_bus(pipeline); bus = gst_element_get_bus(pipeline);
gst_bus_add_signal_watch(bus); gst_bus_add_watch(bus, wfd_out_session_handle_gst_message, s);
os->pipeline = pipeline; os->pipeline = pipeline;
os->bus = bus; os->bus = bus;
@ -726,7 +764,10 @@ static int wfd_out_session_handle_pause_request(struct wfd_session *s,
_rtsp_message_unref_ struct rtsp_message *m = NULL; _rtsp_message_unref_ struct rtsp_message *m = NULL;
int r; int r;
gst_element_set_state(wfd_out_session(s)->pipeline, GST_STATE_READY); r = gst_element_set_state(wfd_out_session(s)->pipeline, GST_STATE_READY);
if(GST_STATE_CHANGE_FAILURE == r) {
return -1;
}
r = rtsp_message_new_reply_for(req, r = rtsp_message_new_reply_for(req,
&m, &m,
@ -1075,12 +1116,6 @@ static const struct rtsp_dispatch_entry out_session_rtsp_disp_tbl[] = {
}, },
[RTSP_M7_PLAY] = { [RTSP_M7_PLAY] = {
.handle_request = wfd_out_session_handle_play_request, .handle_request = wfd_out_session_handle_play_request,
/*.rule = wfd_arg_list(*/
/*wfd_arg_dict(*/
/*wfd_arg_u(WFD_SESSION_ARG_NEW_STATE),*/
/*wfd_arg_u(WFD_SESSION_STATE_PLAYING)*/
/*),*/
/*)*/
}, },
[RTSP_M8_TEARDOWN] = { [RTSP_M8_TEARDOWN] = {
.handle_request = wfd_out_session_handle_teardown_request, .handle_request = wfd_out_session_handle_teardown_request,
@ -1093,12 +1128,6 @@ static const struct rtsp_dispatch_entry out_session_rtsp_disp_tbl[] = {
}, },
[RTSP_M9_PAUSE] = { [RTSP_M9_PAUSE] = {
.handle_request = wfd_out_session_handle_pause_request, .handle_request = wfd_out_session_handle_pause_request,
/*.rule = wfd_arg_list(*/
/*wfd_arg_dict(*/
/*wfd_arg_u(WFD_SESSION_ARG_NEW_STATE),*/
/*wfd_arg_u(WFD_SESSION_STATE_PAUSED)*/
/*),*/
/*)*/
}, },
[RTSP_M10_SET_ROUTE] = { [RTSP_M10_SET_ROUTE] = {
.handle_request = wfd_out_session_request_not_implement .handle_request = wfd_out_session_request_not_implement

View file

@ -120,7 +120,7 @@ enum wfd_session_state wfd_session_get_state(struct wfd_session *s)
return s->state; return s->state;
} }
static void wfd_session_set_state(struct wfd_session *s, void wfd_session_set_state(struct wfd_session *s,
enum wfd_session_state state) enum wfd_session_state state)
{ {
if(state == s->state) { if(state == s->state) {