cec: added SetStreamPath()/cec_set_stream_path_logical()/cec_set_stream_path_physical...
authorLars Op den Kamp <lars@opdenkamp.eu>
Mon, 6 Feb 2012 11:47:34 +0000 (12:47 +0100)
committerLars Op den Kamp <lars@opdenkamp.eu>
Mon, 6 Feb 2012 12:11:25 +0000 (13:11 +0100)
include/cec.h
include/cecc.h
src/lib/CECProcessor.cpp
src/lib/CECProcessor.h
src/lib/LibCEC.cpp
src/lib/LibCEC.h
src/lib/LibCECC.cpp
src/lib/implementations/CECCommandHandler.cpp
src/lib/implementations/CECCommandHandler.h
src/testclient/main.cpp

index c083777f94a1482e8f28c923e2ab8466cb96d935..97e75a46f8e778b7d05471c9ea1e3f58afa81c97 100644 (file)
@@ -350,6 +350,20 @@ namespace CEC
      */
     virtual bool IsActiveSource(cec_logical_address iAddress) = 0;
 
+    /*!
+     * @brief Sets the stream path to the device on the given logical address.
+     * @param iAddress The address to activate.
+     * @return True when the command was sent, false otherwise.
+     */
+    virtual bool SetStreamPath(cec_logical_address iAddress) = 0;
+
+    /*!
+     * @brief Sets the stream path to the device on the given logical address.
+     * @param iPhysicalAddress The address to activate.
+     * @return True when the command was sent, false otherwise.
+     */
+    virtual bool SetStreamPath(uint16_t iPhysicalAddress) = 0;
+
     virtual const char *ToString(const cec_menu_state state) = 0;
     virtual const char *ToString(const cec_version version) = 0;
     virtual const char *ToString(const cec_power_status status) = 0;
index 5a49b0964c6af013ddaa9d2439b5edb66951cc7b..dc4b7953e0484c4b773cef9951f5af5bdd3bd250 100644 (file)
@@ -259,6 +259,14 @@ extern DECLSPEC cec_osd_name cec_get_device_osd_name(cec_logical_address iAddres
 
 extern DECLSPEC int cec_enable_physical_address_detection(void);
 
+#ifdef __cplusplus
+extern DECLSPEC int cec_set_stream_path_logical(CEC::cec_logical_address iAddress);
+#else
+extern DECLSPEC int cec_set_stream_path_logical(cec_logical_address iAddress);
+#endif
+
+extern DECLSPEC int cec_set_stream_path_physical(uint16_t iPhysicalAddress);
+
 #ifdef __cplusplus
 };
 #endif
index e45eda0ac8428ee5ccb78245caaf22e76cc985e4..78d24360b6da344ed7471379b9e7b96ee097c118 100644 (file)
@@ -1332,3 +1332,9 @@ bool CCECProcessor::HandleReceiveFailed(cec_logical_address initiator)
 {
   return !m_busDevices[initiator]->HandleReceiveFailed();
 }
+
+bool CCECProcessor::SetStreamPath(uint16_t iPhysicalAddress)
+{
+  // stream path changes are sent by the TV
+  return m_busDevices[CECDEVICE_TV]->GetHandler()->TransmitSetStreamPath(iPhysicalAddress);
+}
index 0d2446acd065fa57a0b69cfbc6ab1a1cc83c7207..c21110d29568080039a5942c14c18147d973ccdb 100644 (file)
@@ -77,6 +77,7 @@ namespace CEC
       virtual cec_logical_address   GetActiveSource(void);
       virtual bool                  IsActiveSource(cec_logical_address iAddress);
       virtual bool                  IsInitialised(void);
+      virtual bool                  SetStreamPath(uint16_t iPhysicalAddress);
 
       virtual bool SetActiveView(void);
       virtual bool SetActiveSource(cec_device_type type = CEC_DEVICE_TYPE_RESERVED);
index 2562cfd7026df0d957b903a5633a15cde9ad1f2a..7022def6242c824ea837af4cc3ddfcb77bd36eb1 100644 (file)
@@ -435,6 +435,19 @@ void CLibCEC::CheckKeypressTimeout(void)
   }
 }
 
+bool CLibCEC::SetStreamPath(cec_logical_address iAddress)
+{
+  uint16_t iPhysicalAddress = GetDevicePhysicalAddress(iAddress);
+  if (iPhysicalAddress != 0xFFFF)
+    return SetStreamPath(iPhysicalAddress);
+  return false;
+}
+
+bool CLibCEC::SetStreamPath(uint16_t iPhysicalAddress)
+{
+  return m_cec->SetStreamPath(iPhysicalAddress);
+}
+
 static CLibCEC *g_libCEC_instance(NULL);
 CLibCEC *CLibCEC::GetInstance(void)
 {
index a0cc25405802654a8fda197e966547fcb95f405b..6cc2514d561b0df852ad9626c11733b39ab7b653 100644 (file)
@@ -99,6 +99,8 @@ namespace CEC
       virtual bool EnablePhysicalAddressDetection(void);
       virtual cec_logical_address GetActiveSource(void);
       virtual bool IsActiveSource(cec_logical_address iAddress);
+      virtual bool SetStreamPath(cec_logical_address iAddress);
+      virtual bool SetStreamPath(uint16_t iPhysicalAddress);
 
       const char *ToString(const cec_menu_state state);
       const char *ToString(const cec_version version);
index edc30d234223b160212b38078bc27f2ed4052db9..3711686e3685e56f907699e1c974f14fde0bf177 100644 (file)
@@ -371,4 +371,14 @@ int cec_enable_physical_address_detection(void)
   return cec_parser ? (cec_parser->EnablePhysicalAddressDetection() ? 1 : 0) : -1;
 }
 
+int cec_set_stream_path_logical(CEC::cec_logical_address iAddress)
+{
+  return cec_parser ? (cec_parser->SetStreamPath(iAddress) ? 1 : 0) : -1;
+}
+
+int cec_set_stream_path_physical(uint16_t iPhysicalAddress)
+{
+  return cec_parser ? (cec_parser->SetStreamPath(iPhysicalAddress) ? 1 : 0) : -1;
+}
+
 //@}
index 7be147d8ab49f1775b10b87538bb8d361cc7bcb2..0f006272e2d2d45d1a426350013f114ecf60489c 100644 (file)
@@ -899,6 +899,16 @@ bool CCECCommandHandler::TransmitSetSystemAudioMode(const cec_logical_address iI
   return Transmit(command, false);
 }
 
+bool CCECCommandHandler::TransmitSetStreamPath(uint16_t iStreamPath)
+{
+  cec_command command;
+  cec_command::Format(command, m_busDevice->GetLogicalAddress(), CECDEVICE_BROADCAST, CEC_OPCODE_SET_STREAM_PATH);
+  command.parameters.PushBack((uint8_t) ((iStreamPath >> 8) & 0xFF));
+  command.parameters.PushBack((uint8_t) (iStreamPath        & 0xFF));
+
+  return Transmit(command, false);
+}
+
 bool CCECCommandHandler::TransmitSystemAudioModeStatus(const cec_logical_address iInitiator, const cec_logical_address iDestination, cec_system_audio_status state)
 {
   cec_command command;
index 409591be7c95b4e37d4d01eb18250eb5a56da857..e26530214617e4d90165fe86202ac1d20de72edc 100644 (file)
@@ -80,6 +80,7 @@ namespace CEC
     virtual bool TransmitDeckStatus(const cec_logical_address iInitiator, const cec_logical_address iDestination, cec_deck_info state);
     virtual bool TransmitKeypress(const cec_logical_address iInitiator, const cec_logical_address iDestination, cec_user_control_code key, bool bWait = true);
     virtual bool TransmitKeyRelease(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bWait = true);
+    virtual bool TransmitSetStreamPath(uint16_t iStreamPath);
 
     virtual void MarkBusy(void);
     virtual bool MarkReady(void);
index cbdeddf7c8053714835f5427b40264353a9a8f12..c8e6819f091ba6741d06e9e685ee41fd5e7d406f 100644 (file)
@@ -273,6 +273,8 @@ void ShowHelpConsole(void)
   "[lad]                     lists active devices on the bus" << endl <<
   "[ad] {addr}               checks whether the specified device is active." << endl <<
   "[at] {type}               checks whether the specified device type is active." << endl <<
+  "[sp] {addr}               makes the specified physical address active." << endl <<
+  "[spl] {addr}              makes the specified logical address active." << endl <<
   "[volup]                   send a volume up command to the amp if present" << endl <<
   "[voldown]                 send a volume down command to the amp if present" << endl <<
   "[mute]                    send a mute/unmute command to the amp if present" << endl <<
@@ -289,6 +291,42 @@ void ShowHelpConsole(void)
   "================================================================================" << endl;
 }
 
+bool ProcessCommandSP(ICECAdapter *parser, const string &command, string &arguments)
+{
+  if (command == "sp")
+  {
+    string strAddress;
+    int iAddress;
+    if (GetWord(arguments, strAddress))
+    {
+      sscanf(strAddress.c_str(), "%x", &iAddress);
+      if (iAddress >= 0 && iAddress <= 0xFFFF)
+        parser->SetStreamPath((uint16_t)iAddress);
+      return true;
+    }
+  }
+
+  return false;
+}
+
+bool ProcessCommandSPL(ICECAdapter *parser, const string &command, string &arguments)
+{
+  if (command == "spl")
+  {
+    string strAddress;
+    cec_logical_address iAddress;
+    if (GetWord(arguments, strAddress))
+    {
+      iAddress = (cec_logical_address)atoi(strAddress.c_str());
+      if (iAddress >= CECDEVICE_TV && iAddress < CECDEVICE_BROADCAST)
+        parser->SetStreamPath(iAddress);
+      return true;
+    }
+  }
+
+  return false;
+}
+
 bool ProcessCommandTX(ICECAdapter *parser, const string &command, string &arguments)
 {
   if (command == "tx" || command == "txn")
@@ -828,7 +866,9 @@ bool ProcessConsoleCommand(ICECAdapter *parser, string &input)
       ProcessCommandR(parser, command, input) ||
       ProcessCommandH(parser, command, input) ||
       ProcessCommandLOG(parser, command, input) ||
-      ProcessCommandSCAN(parser, command, input);
+      ProcessCommandSCAN(parser, command, input) ||
+      ProcessCommandSP(parser, command, input) ||
+      ProcessCommandSPL(parser, command, input);
     }
   }
   return true;