Merge branch 'master' of github.com:Pulse-Eight/libcec
[deb_libcec.git] / src / lib / CECProcessor.cpp
index 94651fcb45d5c00de77b8323efaca191eb1d38c4..e1e03b868d1ee6925bf319fd26c6f2b29fb801a8 100644 (file)
@@ -406,34 +406,44 @@ bool CCECProcessor::SetHDMIPort(cec_logical_address iBaseDevice, uint8_t iPort,
   AddLog(CEC_LOG_DEBUG, strLog);
 
   uint16_t iPhysicalAddress(0);
-  iPhysicalAddress = m_busDevices[iBaseDevice]->GetPhysicalAddress();
-  uint16_t iPos = 0;
-  if (iPhysicalAddress == 0)
-    iPos = 0x1000;
-  else if (iPhysicalAddress % 0x1000 == 0)
-    iPos = 0x100;
-  else if (iPhysicalAddress % 0x100 == 0)
-    iPos = 0x10;
-  else if (iPhysicalAddress % 0x10 == 0)
-    iPos = 0x1;
-
-  while(!bReturn && iPos > 0)
+  if (iBaseDevice > CECDEVICE_TV)
+    iPhysicalAddress = m_busDevices[iBaseDevice]->GetPhysicalAddress();
+
+  if (iPhysicalAddress == 0xffff)
   {
-    iPhysicalAddress += (uint16_t)(iPort * iPos);
-    strLog.Format("checking physical address %4x", iPhysicalAddress);
-    AddLog(CEC_LOG_DEBUG, strLog);
-    if (PhysicalAddressInUse(iPhysicalAddress))
-    {
-      strLog.Format("physical address %4x is in use", iPhysicalAddress);
-      AddLog(CEC_LOG_DEBUG, strLog);
-      iPos = (iPos == 1) ? 0 : iPos / 0x10;
-    }
-    else
+    SetPhysicalAddress((uint16_t)iPort * 0x1000);
+    bReturn = false;
+  }
+  else
+  {
+    uint16_t iPos = 0;
+    if (iPhysicalAddress == 0)
+      iPos = 0x1000;
+    else if (iPhysicalAddress % 0x1000 == 0)
+      iPos = 0x100;
+    else if (iPhysicalAddress % 0x100 == 0)
+      iPos = 0x10;
+    else if (iPhysicalAddress % 0x10 == 0)
+      iPos = 0x1;
+
+    while(!bReturn && iPos > 0)
     {
-      strLog.Format("physical address %4x is free", iPhysicalAddress);
+      iPhysicalAddress += (uint16_t)(iPort * iPos);
+      strLog.Format("checking physical address %4x", iPhysicalAddress);
       AddLog(CEC_LOG_DEBUG, strLog);
-      SetPhysicalAddress(iPhysicalAddress);
-      bReturn = true;
+      if (PhysicalAddressInUse(iPhysicalAddress))
+      {
+        strLog.Format("physical address %4x is in use", iPhysicalAddress);
+        AddLog(CEC_LOG_DEBUG, strLog);
+        iPos = (iPos == 1) ? 0 : iPos / 0x10;
+      }
+      else
+      {
+        strLog.Format("physical address %4x is free", iPhysicalAddress);
+        AddLog(CEC_LOG_DEBUG, strLog);
+        SetPhysicalAddress(iPhysicalAddress);
+        bReturn = true;
+      }
     }
   }
 
@@ -1325,7 +1335,7 @@ void *CCECBusScan::Process(void)
 
   while (!IsStopped())
   {
-    if (++iCounter < 30)
+    if (++iCounter < 10)
     {
       Sleep(1000);
       continue;
@@ -1355,11 +1365,11 @@ void CCECBusScan::WaitUntilIdle(void)
   if (IsStopped())
     return;
 
-  int64_t iWaitTime = 3000 - (GetTimeMs() - m_processor->GetLastTransmission());
+  int32_t iWaitTime = 3000 - (int32_t)(GetTimeMs() - m_processor->GetLastTransmission());
   while (iWaitTime > 0)
   {
     Sleep(iWaitTime);
-    iWaitTime = 3000 - (GetTimeMs() - m_processor->GetLastTransmission());
+    iWaitTime = 3000 - (int32_t)(GetTimeMs() - m_processor->GetLastTransmission());
   }
 }