Skip to content

Commit

Permalink
Merge pull request rdkcentral#5471 from yuvaramachandran-gurusamy/spr…
Browse files Browse the repository at this point in the history
…int/24Q3/Miracast

RDKTV-31210 RDKTV-30775 RDKTV-31401 - Miracast Fixes
  • Loading branch information
apatel859 authored Jul 1, 2024
2 parents 0dc90c1 + fb63752 commit 65e4e2a
Show file tree
Hide file tree
Showing 7 changed files with 773 additions and 73 deletions.
106 changes: 74 additions & 32 deletions Miracast/MiracastService/MiracastController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,12 +487,12 @@ void MiracastController::checkAndInitiateP2PBackendDiscovery(void)
{
MIRACASTLOG_INFO("!!! BACKEND P2P DISCOVERY HAS BEEN STARTED !!!");
/* Enabled the Device Discovery to allow other device to cast */
discover_devices();
discover_devices(false);
}
else
{
MIRACASTLOG_INFO("!!! BACKEND P2P DISCOVERY HAS DISABLED !!!");
stop_discover_devices();
stop_discover_devices(false);
}
}

Expand Down Expand Up @@ -538,23 +538,31 @@ MiracastError MiracastController::set_WFDParameters(void)
return ret;
}

MiracastError MiracastController::discover_devices(void)
MiracastError MiracastController::discover_devices(bool isNotificationRequired)
{
MIRACASTLOG_TRACE("Entering...");
MiracastError ret = MIRACAST_FAIL;
if (nullptr != m_p2p_ctrl_obj){
ret = m_p2p_ctrl_obj->discover_devices();
if ((nullptr != m_notify_handler) && (isNotificationRequired))
{
m_notify_handler->onStateChange(MIRACAST_SERVICE_STATE_DISCOVERABLE);
}
}
MIRACASTLOG_TRACE("Exiting...");
return ret;
}

MiracastError MiracastController::stop_discover_devices(void)
MiracastError MiracastController::stop_discover_devices(bool isNotificationRequired)
{
MIRACASTLOG_TRACE("Entering...");
MiracastError ret = MIRACAST_FAIL;
if (nullptr != m_p2p_ctrl_obj){
ret = m_p2p_ctrl_obj->stop_discover_devices();
if ((nullptr != m_notify_handler) && (isNotificationRequired))
{
m_notify_handler->onStateChange(MIRACAST_SERVICE_STATE_IDLE);
}
}
MIRACASTLOG_TRACE("Exiting...");
return ret;
Expand Down Expand Up @@ -929,7 +937,8 @@ void MiracastController::Controller_Thread(void *args)
sink_dev_ip = "";
std::string modelName = "Miracast-Source",
authType = "pbc",
deviceType = "unknown";
deviceType = "unknown",
result = "";
m_groupInfo = new GroupInfo;
size_t found = event_buffer.find("client");
size_t found_space = event_buffer.find(" ");
Expand All @@ -952,7 +961,7 @@ void MiracastController::Controller_Thread(void *args)
std::size_t secondDash = m_groupInfo->SSID.find("-", firstDash + 1);
if (secondDash != std::string::npos)
{
std::string result = m_groupInfo->SSID.substr(secondDash + 1);
result = m_groupInfo->SSID.substr(secondDash + 1);
if (!result.empty())
{
modelName.clear();
Expand Down Expand Up @@ -1184,38 +1193,39 @@ void MiracastController::Controller_Thread(void *args)
MIRACASTLOG_TRACE("CONTRLR_FW_MSG type received");
switch (controller_msgq_data.state)
{
// Start and Stop Discovering initiated directly from Thunder request. So this is unused and commenting out here
#if 0
case CONTROLLER_START_DISCOVERING:
{
MIRACASTLOG_INFO("CONTROLLER_START_DISCOVERING Received\n");
set_WFDParameters();
discover_devices();
m_start_discovering_enabled = true;
}
break;
case CONTROLLER_STOP_DISCOVERING:
{
MIRACASTLOG_INFO("CONTROLLER_STOP_DISCOVERING Received\n");
stop_session(true);
m_start_discovering_enabled = false;
}
break;
#endif
case CONTROLLER_RESTART_DISCOVERING:
{
std::string cached_mac_address = get_NewSourceMACAddress(),
mac_address = controller_msgq_data.source_dev_mac;
MIRACASTLOG_INFO("CONTROLLER_RESTART_DISCOVERING Received\n");
m_connectionStatus = false;

if ((!cached_mac_address.empty()) && ( 0 == mac_address.compare(cached_mac_address)))
if (CONTROLLER_START_DISCOVERING == controller_msgq_data.state)
{
reset_NewSourceMACAddress();
reset_NewSourceName();
MIRACASTLOG_INFO("[%s] Cached Device info removed...",cached_mac_address.c_str());
MIRACASTLOG_INFO("CONTROLLER_START_DISCOVERING Received\n");
set_WFDParameters();
discover_devices();
m_start_discovering_enabled = true;
}
else if (CONTROLLER_STOP_DISCOVERING == controller_msgq_data.state)
{
MIRACASTLOG_INFO("CONTROLLER_STOP_DISCOVERING Received\n");
stop_session(true);
m_start_discovering_enabled = false;
sleep(2);
}
else
{
std::string cached_mac_address = get_NewSourceMACAddress(),
mac_address = controller_msgq_data.source_dev_mac;
MIRACASTLOG_INFO("CONTROLLER_RESTART_DISCOVERING Received\n");
m_connectionStatus = false;

if ((!cached_mac_address.empty()) && ( 0 == mac_address.compare(cached_mac_address)))
{
reset_NewSourceMACAddress();
reset_NewSourceName();
MIRACASTLOG_INFO("[%s] Cached Device info removed...",cached_mac_address.c_str());
}
restart_session(m_start_discovering_enabled);
}
restart_session(m_start_discovering_enabled);
new_thunder_req_client_connection_sent = false;
another_thunder_req_client_connection_sent = false;
session_restart_required = true;
Expand Down Expand Up @@ -1422,6 +1432,38 @@ void MiracastController::switch_launch_request_context(std::string& source_dev_i
MIRACASTLOG_TRACE("Exiting...");
}

void MiracastController::start_discoveryAsync(void)
{
CONTROLLER_MSGQ_STRUCT controller_msgq_data = {0};
MIRACASTLOG_TRACE("Entering...");
MIRACASTLOG_INFO("MIRACAST_SERVICE_WFD_START");
controller_msgq_data.state = CONTROLLER_START_DISCOVERING;
send_thundermsg_to_controller_thread(controller_msgq_data);
MIRACASTLOG_TRACE("Exiting...");
}

void MiracastController::stop_discoveryAsync(void)
{
CONTROLLER_MSGQ_STRUCT controller_msgq_data = {0};
MIRACASTLOG_TRACE("Entering...");
MIRACASTLOG_INFO("MIRACAST_SERVICE_WFD_STOP");
controller_msgq_data.state = CONTROLLER_STOP_DISCOVERING;
send_thundermsg_to_controller_thread(controller_msgq_data);
MIRACASTLOG_TRACE("Exiting...");
}

void MiracastController::restart_discoveryAsync(void)
{
CONTROLLER_MSGQ_STRUCT controller_msgq_data = {0};
MIRACASTLOG_TRACE("Entering...");
MIRACASTLOG_INFO("MIRACAST_SERVICE_WFD_RESTART");
controller_msgq_data.state = CONTROLLER_STOP_DISCOVERING;
send_thundermsg_to_controller_thread(controller_msgq_data);
controller_msgq_data.state = CONTROLLER_START_DISCOVERING;
send_thundermsg_to_controller_thread(controller_msgq_data);
MIRACASTLOG_TRACE("Exiting...");
}

void MiracastController::set_WFDSourceMACAddress(std::string MAC_Addr)
{
m_connected_mac_addr = MAC_Addr;
Expand Down
7 changes: 5 additions & 2 deletions Miracast/MiracastService/MiracastController.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class MiracastController

void event_handler(P2P_EVENTS eventId, void *data, size_t len );

MiracastError discover_devices();
MiracastError discover_devices(bool isNotificationRequired = true);
MiracastError connect_device(std::string device_mac , std::string device_name );

std::string get_localIp();
Expand All @@ -76,7 +76,7 @@ class MiracastController
void send_msgto_test_notifier_thread( MIRACAST_SERVICE_TEST_NOTIFIER_MSGQ_ST stMsgQ );
#endif /* ENABLE_MIRACAST_SERVICE_TEST_NOTIFIER */

MiracastError stop_discover_devices();
MiracastError stop_discover_devices(bool isNotificationRequired = true);
MiracastError set_WFDParameters(void);
void restart_session_discovery(std::string& mac_address);
void flush_current_session(void);
Expand Down Expand Up @@ -106,6 +106,9 @@ class MiracastController

void setP2PBackendDiscovery(bool is_enabled);
void switch_launch_request_context(std::string& source_dev_ip,std::string& source_dev_mac,std::string& source_dev_name,std::string& sink_dev_ip);
void start_discoveryAsync(void);
void stop_discoveryAsync(void);
void restart_discoveryAsync(void);

private:
static MiracastController *m_miracast_ctrl_obj;
Expand Down
Loading

0 comments on commit 65e4e2a

Please sign in to comment.