From 834c3ca0c4338751da0a859bbc18ab44c14ff49f Mon Sep 17 00:00:00 2001 From: Jinkun Jang Date: Sat, 16 Mar 2013 01:16:00 +0900 Subject: [PATCH] merge with master --- libmm-wfd.manifest | 6 ++ server/miracast_server.c | 260 ++++++++++++++++++++++++++-------------------- src/include/mm_wfd.h | 1 + src/include/mm_wfd_priv.h | 1 + src/mm_wfd.c | 16 +++ src/mm_wfd_priv.c | 24 +++++ test/mm_wfd_testsuite.c | 20 ---- 7 files changed, 194 insertions(+), 134 deletions(-) diff --git a/libmm-wfd.manifest b/libmm-wfd.manifest index 9e5b095..bfacb51 100755 --- a/libmm-wfd.manifest +++ b/libmm-wfd.manifest @@ -1,6 +1,12 @@ + + + + + + diff --git a/server/miracast_server.c b/server/miracast_server.c index fd4d1ea..f35b4e0 100755 --- a/server/miracast_server.c +++ b/server/miracast_server.c @@ -1,24 +1,24 @@ -/* - * libmm-wfd - * - * Copyright (c) 2011 - 2013 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: JongHyuk Choi , ByungWook Jang , - * Manoj Kumar K , Hyunil Park - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ +/* + * libmm-wfd + * + * Copyright (c) 2011 - 2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JongHyuk Choi , ByungWook Jang , + * Manoj Kumar K , Hyunil Park + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ /*=========================================================================================== | | @@ -43,7 +43,7 @@ #include #include #include -#include +#include #include #include @@ -148,7 +148,7 @@ int g_current_state; static MMHandleType g_wfd = 0; char *g_err_name = NULL; gboolean quit_pushing; -int socket_id = 0; +int socket_id = 0; /*--------------------------------------------------------------------------- | LOCAL FUNCTION PROTOTYPES: | ---------------------------------------------------------------------------*/ @@ -158,8 +158,8 @@ static void wfd_stop(); void quit_program(); -static void wfd_set_signal(); - +static void wfd_set_signal(); + /*--------------------------------------------------------------------------- | LOCAL FUNCTION DEFINITIONS: | ---------------------------------------------------------------------------*/ @@ -177,7 +177,7 @@ static bool msg_callback(int message, MMMessageParamType *param, void *user_para debug_log ("DESTROY..\n\n"); quit_pushing = TRUE; shutdown (lserver->sockfd, SHUT_RDWR); - debug_log("msg_callback error call quit_program()"); + debug_log("msg_callback error call quit_program()"); quit_program(); } break; @@ -257,10 +257,10 @@ static void input_server_ip_and_port(char *server_ip, char* port, WFDClient *cli debug_log ("input_server_port Error in setting server_port...\n"); return; } - /*set wfd source status*/ - gboolean status = VCONFKEY_MIRACAST_WFD_SOURCE_ON; - if (!vconf_set_bool(VCONFKEY_MIRACAST_WFD_SOURCE_STATUS, status)) { - debug_log ("set VCONFKEY_MIRACAST_WFD_SOURCE_ON"); + /*set wfd source status*/ + gboolean status = VCONFKEY_MIRACAST_WFD_SOURCE_ON; + if (!vconf_set_bool(VCONFKEY_MIRACAST_WFD_SOURCE_STATUS, status)) { + debug_log ("set VCONFKEY_MIRACAST_WFD_SOURCE_ON"); } } static void wfd_connect() @@ -373,18 +373,29 @@ static void wfd_resume() } } +static void wfd_standby() +{ + int ret = MM_ERROR_NONE; + ret = mm_wfd_standby(g_wfd); + if (ret != MM_ERROR_NONE) + { + debug_log ("wfd_standby Error to do standby...\n"); + return; + } +} + void quit_program() { MMTA_ACUM_ITEM_SHOW_RESULT_TO(MMTA_SHOW_STDOUT); MMTA_RELEASE(); debug_log ("quit_program...\n"); - /*set wfd source status*/ - gboolean status = VCONFKEY_MIRACAST_WFD_SOURCE_OFF; - if (!vconf_set_bool(VCONFKEY_MIRACAST_WFD_SOURCE_STATUS, status)) { - debug_log ("set VCONFKEY_MIRACAST_WFD_SOURCE_OFF"); - } - + /*set wfd source status*/ + gboolean status = VCONFKEY_MIRACAST_WFD_SOURCE_OFF; + if (!vconf_set_bool(VCONFKEY_MIRACAST_WFD_SOURCE_STATUS, status)) { + debug_log ("set VCONFKEY_MIRACAST_WFD_SOURCE_OFF"); + } + if (g_wfd) { mm_wfd_unrealize(g_wfd); mm_wfd_destroy(g_wfd); @@ -515,7 +526,7 @@ static void interpret (WFDClient *client, char *cmd) debug_log ("STATE QUERY..demon return\n\n"); quit_pushing = TRUE; shutdown (lserver->sockfd, SHUT_RDWR); - debug_log("interpret calll quit_program()"); + debug_log("interpret calll quit_program()"); quit_program(); } else if (strstr(cmd, "WFD_PROXY_STATE_QUERY")) @@ -577,10 +588,10 @@ static void* wfd_server_thread_function(void * asrc) { int newsockfd; int i=0; - int nSockOpt = 1; + int nSockOpt = 1; WFDServer *pserver = (WFDServer *)asrc; pserver->sockfd = socket(AF_INET, SOCK_STREAM, 0); - debug_log("wfd_proxy_initialize socke is %d", pserver->sockfd); + debug_log("wfd_proxy_initialize socke is %d", pserver->sockfd); if (pserver->sockfd < 0) { debug_log("ERROR opening socket"); @@ -592,8 +603,8 @@ static void* wfd_server_thread_function(void * asrc) pserver->serv_addr.sin_family = AF_INET; pserver->serv_addr.sin_addr.s_addr = INADDR_ANY; pserver->serv_addr.sin_port = htons(pserver->portno); - debug_log("serv_addr = %p sizeof %d ", (struct sockaddr *) &pserver->serv_addr, sizeof(pserver->serv_addr)); - setsockopt(pserver->sockfd, SOL_SOCKET, SO_REUSEADDR, &nSockOpt, sizeof(nSockOpt)); + debug_log("serv_addr = %p sizeof %d ", (struct sockaddr *) &pserver->serv_addr, sizeof(pserver->serv_addr)); + setsockopt(pserver->sockfd, SOL_SOCKET, SO_REUSEADDR, &nSockOpt, sizeof(nSockOpt)); if (bind(pserver->sockfd, (struct sockaddr *) &pserver->serv_addr, sizeof(pserver->serv_addr)) < 0) { debug_log("ERROR on binding"); @@ -605,7 +616,7 @@ static void* wfd_server_thread_function(void * asrc) debug_log("ERROR on socket listen"); goto cleanup; } - wfd_set_signal(); + wfd_set_signal(); MMTA_INIT(); while(!quit_pushing) @@ -628,7 +639,7 @@ static void* wfd_server_thread_function(void * asrc) continue; } client->connfd = newsockfd; - socket_id = newsockfd; + socket_id = newsockfd; client->lock = g_mutex_new (); client->inactive = 0; client->parent = pserver; @@ -652,9 +663,9 @@ cleanup: } g_list_free(pserver->clients); shutdown (pserver->sockfd, SHUT_RDWR); - debug_log("wfd_server_thread_function calll quit_program()"); - quit_program(); - + debug_log("wfd_server_thread_function calll quit_program()"); + quit_program(); + debug_log("wfd_server_thread_function THREAD EXIT \n"); return NULL; @@ -710,71 +721,71 @@ static bool __wfd_server_setup(void* pserver) debug_log("__wfd_server_setup end\n"); return true; } -void wfd_signal_handler(int signo) { - quit_pushing = TRUE; - debug_log("wfd_signal_handler calll quit_program()"); - shutdown (socket_id, SHUT_RDWR); - quit_program(); - exit(1); -} - -static void wfd_set_signal() -{ - - /*refer to signal.h*/ - /*SIGABRT A Process abort signal. - SIGALRM T Alarm clock. - SIGBUS A Access to an undefined portion of a memory object. - SIGCHLD I Child process terminated, stopped, - SIGCONT C Continue executing, if stopped. - SIGFPE A Erroneous arithmetic operation. - SIGHUP T Hangup. - SIGILL A Illegal instruction. - SIGINT T Terminal interrupt signal. - SIGKILL T Kill (cannot be caught or ignored). - SIGPIPE T Write on a pipe with no one to read it. - SIGQUIT A Terminal quit signal. - SIGSEGV A Invalid memory reference. - SIGSTOP S Stop executing (cannot be caught or ignored). - SIGTERM T Termination signal. - SIGTSTP S Terminal stop signal. - SIGTTIN S Background process attempting read. - SIGTTOU S Background process attempting write. - SIGUSR1 T User-defined signal 1. - SIGUSR2 T User-defined signal 2. - SIGPOLL T Pollable event. - SIGPROF T Profiling timer expired. - SIGSYS A Bad system call. - SIGTRAP A Trace/breakpoint trap. - SIGURG I High bandwidth data is available at a socket. - SIGVTALRM T Virtual timer expired. - SIGXCPU A CPU time limit exceeded. - SIGXFSZ A File size limit exceeded. - -The default actions are as follows: -T : Abnormal termination of the process. The process is terminated with all the consequences of _exit() -A : Abnormal termination of the process. -I : Ignore the signal. -S : Stop the process -*/ - struct sigaction act_new; - memset (&act_new, 0, sizeof (struct sigaction)); - - act_new.sa_handler = wfd_signal_handler; - - sigaction(SIGABRT, &act_new, NULL); - sigaction(SIGBUS, &act_new, NULL); - sigaction(SIGINT, &act_new, NULL); // - sigaction(SIGKILL, &act_new, NULL); - sigaction(SIGPIPE, &act_new, NULL); - sigaction(SIGQUIT, &act_new, NULL); // - sigaction(SIGSEGV, &act_new, NULL); - sigaction(SIGTERM, &act_new, NULL); // - sigaction(SIGSYS, &act_new, NULL); - -} - - +void wfd_signal_handler(int signo) { + quit_pushing = TRUE; + debug_log("wfd_signal_handler calll quit_program()"); + shutdown (socket_id, SHUT_RDWR); + quit_program(); + exit(1); +} + +static void wfd_set_signal() +{ + + /*refer to signal.h*/ + /*SIGABRT A Process abort signal. + SIGALRM T Alarm clock. + SIGBUS A Access to an undefined portion of a memory object. + SIGCHLD I Child process terminated, stopped, + SIGCONT C Continue executing, if stopped. + SIGFPE A Erroneous arithmetic operation. + SIGHUP T Hangup. + SIGILL A Illegal instruction. + SIGINT T Terminal interrupt signal. + SIGKILL T Kill (cannot be caught or ignored). + SIGPIPE T Write on a pipe with no one to read it. + SIGQUIT A Terminal quit signal. + SIGSEGV A Invalid memory reference. + SIGSTOP S Stop executing (cannot be caught or ignored). + SIGTERM T Termination signal. + SIGTSTP S Terminal stop signal. + SIGTTIN S Background process attempting read. + SIGTTOU S Background process attempting write. + SIGUSR1 T User-defined signal 1. + SIGUSR2 T User-defined signal 2. + SIGPOLL T Pollable event. + SIGPROF T Profiling timer expired. + SIGSYS A Bad system call. + SIGTRAP A Trace/breakpoint trap. + SIGURG I High bandwidth data is available at a socket. + SIGVTALRM T Virtual timer expired. + SIGXCPU A CPU time limit exceeded. + SIGXFSZ A File size limit exceeded. + +The default actions are as follows: +T : Abnormal termination of the process. The process is terminated with all the consequences of _exit() +A : Abnormal termination of the process. +I : Ignore the signal. +S : Stop the process +*/ + struct sigaction act_new; + memset (&act_new, 0, sizeof (struct sigaction)); + + act_new.sa_handler = wfd_signal_handler; + + sigaction(SIGABRT, &act_new, NULL); + sigaction(SIGBUS, &act_new, NULL); + sigaction(SIGINT, &act_new, NULL); // + sigaction(SIGKILL, &act_new, NULL); + sigaction(SIGPIPE, &act_new, NULL); + sigaction(SIGQUIT, &act_new, NULL); // + sigaction(SIGSEGV, &act_new, NULL); + sigaction(SIGTERM, &act_new, NULL); // + sigaction(SIGSYS, &act_new, NULL); + +} + + static void wifi_direct_state_change_cb(keynode_t *key, void *data) { @@ -787,11 +798,28 @@ static void wifi_direct_state_change_cb(keynode_t *key, void *data) debug_log("wifi disconnected"); quit_pushing = TRUE; shutdown (server->sockfd, SHUT_RDWR); - debug_log("wifi_direct_state_change_cb calll quit_program()"); + debug_log("wifi_direct_state_change_cb calll quit_program()"); quit_program(); } -} - +} + +static void lcd_state_change_cb(keynode_t *key, void *data) +{ + WFDServer *server = (WFDServer *)data; + if(!server) + return; + int state = -1; + state = vconf_keynode_get_int(key); + if (state == VCONFKEY_PM_STATE_NORMAL) { + debug_log("source has woke up time to wake-up-sink"); + wfd_resume(); + } + else if(state == VCONFKEY_PM_STATE_LCDOFF || VCONFKEY_PM_STATE_SLEEP) { + debug_log("source is sleeping time to go to sleep"); + wfd_standby(); + } +} + int main(int argc, char *argv[]) { WFDServer server; @@ -813,6 +841,10 @@ int main(int argc, char *argv[]) if (0 != vconf_notify_key_changed(VCONFKEY_WIFI_DIRECT_STATE, wifi_direct_state_change_cb, &server)) { debug_log("vconf_notify_key_changed() failed"); } + debug_log("set vconf_notify_key_changed about LCD state"); + if (0 != vconf_notify_key_changed(VCONFKEY_PM_STATE, lcd_state_change_cb, &server)) { + debug_log("vconf_notify_key_changed() failed"); + } debug_log("wfd_proxy_initialize run loop \n"); g_main_loop_run(g_loop); g_thread_join(server.thread); diff --git a/src/include/mm_wfd.h b/src/include/mm_wfd.h index b2f2b2b..67ffea1 100755 --- a/src/include/mm_wfd.h +++ b/src/include/mm_wfd.h @@ -138,6 +138,7 @@ int mm_wfd_start(MMHandleType wfd); int mm_wfd_stop(MMHandleType wfd); int mm_wfd_pause (MMHandleType wfd); int mm_wfd_resume (MMHandleType wfd); +int mm_wfd_standby (MMHandleType wfd); int mm_wfd_set_message_callback(MMHandleType wfd, MMMessageCallback callback, void *user_param); int mm_wfd_set_attribute(MMHandleType wfd, char **err_attr_name, const char *first_attribute_name, ...); diff --git a/src/include/mm_wfd_priv.h b/src/include/mm_wfd_priv.h index e3a6633..9551942 100755 --- a/src/include/mm_wfd_priv.h +++ b/src/include/mm_wfd_priv.h @@ -190,6 +190,7 @@ int _mmwfd_start (MMHandleType hwfd); int _mmwfd_stop (MMHandleType hwfd); int _mmwfd_pause (MMHandleType hwfd); int _mmwfd_resume (MMHandleType hwfd); +int _mmwfd_standby (MMHandleType hwfd); int _mmwfd_get_state(MMHandleType hwfd, int* state); gboolean __mmwfd_post_message(mm_wfd_t* wfd, enum MMMessageType msgtype, MMMessageParamType* param); int _mmwfd_set_message_callback(MMHandleType hwfd, MMMessageCallback callback, gpointer user_param); diff --git a/src/mm_wfd.c b/src/mm_wfd.c index 6adee55..3b452c2 100755 --- a/src/mm_wfd.c +++ b/src/mm_wfd.c @@ -237,6 +237,22 @@ int mm_wfd_resume (MMHandleType wfd) return result; } +int mm_wfd_standby (MMHandleType wfd) +{ + int result = MM_ERROR_NONE; + return_val_if_fail(wfd, MM_ERROR_WFD_NOT_INITIALIZED); + + MMWFD_CMD_LOCK( wfd ); + + __ta__("[KPI] standby media wfd service", + result = _mmwfd_standby(wfd); + ) + + MMWFD_CMD_UNLOCK(wfd); + + return result; +} + int mm_wfd_stop(MMHandleType wfd) { int result = MM_ERROR_NONE; diff --git a/src/mm_wfd_priv.c b/src/mm_wfd_priv.c index 82a46f4..45f1cda 100755 --- a/src/mm_wfd_priv.c +++ b/src/mm_wfd_priv.c @@ -346,6 +346,30 @@ int _mmwfd_resume (MMHandleType hwfd) // @ return ret; } +int _mmwfd_standby (MMHandleType hwfd) // @ +{ + mm_wfd_t* wfd = (mm_wfd_t*) hwfd; + gint ret = MM_ERROR_NONE; + + debug_fenter(); + return_val_if_fail ( wfd, MM_ERROR_WFD_NOT_INITIALIZED ); + + /* check current state */ + //MMWFD_CHECK_STATE_RETURN_IF_FAIL( wfd, MMWFD_COMMAND_PLAY ); + + if (!gst_rtsp_server_standby_client (wfd->server, wfd->client)) + { + debug_error ("Error in client standby"); + return MM_ERROR_WFD_INTERNAL; + } + + MMWFD_SET_STATE ( wfd, MM_WFD_STATE_PAUSED); + + debug_fleave(); + + return ret; +} + int _mmwfd_stop (MMHandleType hwfd) // @ { mm_wfd_t* wfd = (mm_wfd_t*) hwfd; diff --git a/test/mm_wfd_testsuite.c b/test/mm_wfd_testsuite.c index 5ef4c9a..5b3b680 100755 --- a/test/mm_wfd_testsuite.c +++ b/test/mm_wfd_testsuite.c @@ -240,26 +240,6 @@ static bool msg_callback(int message, MMMessageParamType *param, void *user_para } //:: break; - case MM_MESSAGE_BEGIN_OF_STREAM: - { - g_print(" ==> [MediaPlayerApp] BOS\n"); - } - break; - - case MM_MESSAGE_RESUMED_BY_REW: - g_print("resumed by fast rewind duing trick play\n"); - break; - case MM_MESSAGE_VIDEO_CAPTURED: - break; - - case MM_MESSAGE_UPDATE_SUBTITLE: - break; - - case MM_MESSAGE_DRM_NOT_AUTHORIZED: - g_print("Got MM_MESSAGE_DRM_NOT_AUTHORIZED\n"); - quit_program (); - break; - default: return FALSE; } -- 2.7.4