LibCecSharp: fixed - set the primary LA in CecLogicalAddresses
[deb_libcec.git] / src / lib / implementations / VLCommandHandler.cpp
index c347649c9c0b9989ca7be74fc82b3fee8713f804..e78f942d6436ce01080a9d9d5ce3672a40d57b2d 100644 (file)
  *     http://www.pulse-eight.net/
  */
 
+#include "env.h"
 #include "VLCommandHandler.h"
-#include "../devices/CECBusDevice.h"
-#include "../devices/CECPlaybackDevice.h"
-#include "../devices/CECTV.h"
-#include "../CECProcessor.h"
-#include "../LibCEC.h"
-#include "../CECClient.h"
+
+#include "lib/devices/CECBusDevice.h"
+#include "lib/devices/CECPlaybackDevice.h"
+#include "lib/devices/CECTV.h"
+#include "lib/CECProcessor.h"
+#include "lib/LibCEC.h"
+#include "lib/CECClient.h"
 
 #define VL_POWER_CHANGE 0x20
 #define VL_POWERED_UP   0x00
 #define VL_POWERED_DOWN 0x01
+#define VL_UNKNOWN1     0x06
 
 using namespace CEC;
 using namespace PLATFORM;
@@ -51,8 +54,12 @@ using namespace PLATFORM;
 // wait this amount of ms before trying to switch sources after receiving the message from the TV that it's powered on
 #define SOURCE_SWITCH_DELAY_MS 1000
 
-CVLCommandHandler::CVLCommandHandler(CCECBusDevice *busDevice) :
-    CCECCommandHandler(busDevice),
+CVLCommandHandler::CVLCommandHandler(CCECBusDevice *busDevice,
+                                     int32_t iTransmitTimeout /* = CEC_DEFAULT_TRANSMIT_TIMEOUT */,
+                                     int32_t iTransmitWait /* = CEC_DEFAULT_TRANSMIT_WAIT */,
+                                     int8_t iTransmitRetries /* = CEC_DEFAULT_TRANSMIT_RETRIES */,
+                                     int64_t iActiveSourcePending /* = 0 */) :
+    CCECCommandHandler(busDevice, iTransmitTimeout, iTransmitWait, iTransmitRetries, iActiveSourcePending),
     m_iPowerUpEventReceived(0)
 {
   m_vendorId = CEC_VENDOR_PANASONIC;
@@ -90,6 +97,18 @@ int CVLCommandHandler::HandleDeviceVendorCommandWithId(const cec_command &comman
     return CEC_ABORT_REASON_INVALID_OPERAND;
 
   if (command.initiator == CECDEVICE_TV &&
+      command.parameters.At(3) == VL_UNKNOWN1)
+  {
+    // set the power up event time
+    {
+      CLockObject lock(m_mutex);
+      if (m_iPowerUpEventReceived == 0)
+        m_iPowerUpEventReceived = GetTimeMs();
+    }
+    // mark the TV as powered on
+    m_processor->GetTV()->SetPowerStatus(CEC_POWER_STATUS_ON);
+  }
+  else if (command.initiator == CECDEVICE_TV &&
       command.destination == CECDEVICE_BROADCAST &&
       command.parameters.At(3) == VL_POWER_CHANGE)
   {
@@ -183,7 +202,7 @@ int CVLCommandHandler::HandleVendorCommand(const cec_command &command)
     uint8_t iResponseData[] = {0x10, 0x02, 0xFF, 0xFF, 0x00, 0x05, 0x05, 0x45, 0x55, 0x5c, 0x58, 0x32};
     response.PushArray(12, iResponseData);
 
-    Transmit(response, true);
+    Transmit(response, false, true);
 
     return COMMAND_HANDLED;
   }
@@ -195,3 +214,20 @@ bool CVLCommandHandler::SourceSwitchAllowed(void)
 {
   return PowerUpEventReceived();
 }
+
+int CVLCommandHandler::HandleSystemAudioModeRequest(const cec_command &command)
+{
+  if (command.initiator == CECDEVICE_TV)
+  {
+    // set the power up event time
+    {
+      CLockObject lock(m_mutex);
+      if (m_iPowerUpEventReceived == 0)
+        m_iPowerUpEventReceived = GetTimeMs();
+    }
+    // mark the TV as powered on
+    m_processor->GetTV()->SetPowerStatus(CEC_POWER_STATUS_ON);
+  }
+
+  return CCECCommandHandler::HandleSystemAudioModeRequest(command);
+}