Skip to content
This repository

[cec] activate source when playback starts #1419

Merged
merged 5 commits into from over 1 year ago

2 participants

Lars Op den Kamp Matthias Kortstiege
Lars Op den Kamp
Collaborator

optional, configurable via peripheral settings, and enabled by default

Matthias Kortstiege
Collaborator

Looks good to me. Always wondered why there's no ping on playback start.

Lars Op den Kamp
Collaborator

included a fix for this issue: https://github.com/Pulse-Eight/libcec/issues/48 (deadlock when switching the TV to XBMC when the screensaver was active)

Lars Op den Kamp opdenkamp merged commit ed8746c into from October 01, 2012
Lars Op den Kamp opdenkamp closed this October 01, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
69  xbmc/peripherals/devices/PeripheralCecAdapter.cpp
@@ -88,7 +88,9 @@ CPeripheralCecAdapter::CPeripheralCecAdapter(const PeripheralType type, const Pe
88 88
   m_bIsMuted(false), // TODO fetch the correct initial value when system audiostatus is implemented in libCEC
89 89
   m_bGoingToStandby(false),
90 90
   m_bIsRunning(false),
91  
-  m_bDeviceRemoved(false)
  91
+  m_bDeviceRemoved(false),
  92
+  m_bActiveSourcePending(false),
  93
+  m_bStandbyPending(false)
92 94
 {
93 95
   m_currentButton.iButton = 0;
94 96
   m_currentButton.iDuration = 0;
@@ -138,15 +140,10 @@ void CPeripheralCecAdapter::Announce(AnnouncementFlag flag, const char *sender,
138 140
       if (bIgnoreDeactivate)
139 141
         CLog::Log(LOGDEBUG, "%s - ignoring OnScreensaverDeactivated for power action", __FUNCTION__);
140 142
     }
141  
-    if (m_configuration.bPowerOffScreensaver == 1 && !bIgnoreDeactivate)
  143
+    if (m_configuration.bPowerOffScreensaver == 1 && !bIgnoreDeactivate &&
  144
+        m_configuration.bActivateSource == 1)
142 145
     {
143  
-      // power off/on on screensaver is set, and devices to wake are set
144  
-      if (!m_configuration.wakeDevices.IsEmpty())
145  
-        m_cecAdapter->PowerOnDevices(CECDEVICE_BROADCAST);
146  
-
147  
-      // the option to make XBMC the active source is set
148  
-      if (m_configuration.bActivateSource == 1)
149  
-        m_cecAdapter->SetActiveSource();
  146
+      ActivateSource();
150 147
     }
151 148
   }
152 149
   else if (flag == GUI && !strcmp(sender, "xbmc") && !strcmp(message, "OnScreensaverActivated") && m_bIsReady)
@@ -157,7 +154,7 @@ void CPeripheralCecAdapter::Announce(AnnouncementFlag flag, const char *sender,
157 154
       m_screensaverLastActivated = CDateTime::GetCurrentDateTime();
158 155
       // only power off when we're the active source
159 156
       if (m_cecAdapter->IsLibCECActiveSource())
160  
-        m_cecAdapter->StandbyDevices(CECDEVICE_BROADCAST);
  157
+        StandbyDevices();
161 158
     }
162 159
   }
163 160
   else if (flag == System && !strcmp(sender, "xbmc") && !strcmp(message, "OnSleep"))
@@ -174,6 +171,12 @@ void CPeripheralCecAdapter::Announce(AnnouncementFlag flag, const char *sender,
174 171
     CLog::Log(LOGDEBUG, "%s - reconnecting to the CEC adapter after standby mode", __FUNCTION__);
175 172
     ReopenConnection();
176 173
   }
  174
+  else if (flag == Player && !strcmp(sender, "xbmc") && !strcmp(message, "OnPlay"))
  175
+  {
  176
+    // activate the source when playback started, and the option is enabled
  177
+    if (m_configuration.bActivateSource)
  178
+      ActivateSource();
  179
+  }
177 180
 }
178 181
 
179 182
 bool CPeripheralCecAdapter::InitialiseFeature(const PeripheralFeature feature)
@@ -371,6 +374,12 @@ void CPeripheralCecAdapter::Process(void)
371 374
       ProcessVolumeChange();
372 375
 
373 376
     if (!m_bStop)
  377
+      ProcessActivateSource();
  378
+
  379
+    if (!m_bStop)
  380
+      ProcessStandbyDevices();
  381
+
  382
+    if (!m_bStop)
374 383
       Sleep(5);
375 384
   }
376 385
 
@@ -1610,4 +1619,44 @@ void CPeripheralCecAdapter::ReopenConnection(void)
1610 1619
   Create();
1611 1620
 }
1612 1621
 
  1622
+void CPeripheralCecAdapter::ActivateSource(void)
  1623
+{
  1624
+  CSingleLock lock(m_critSection);
  1625
+  m_bActiveSourcePending = true;
  1626
+}
  1627
+
  1628
+void CPeripheralCecAdapter::ProcessActivateSource(void)
  1629
+{
  1630
+  bool bActivate(false);
  1631
+
  1632
+  {
  1633
+    CSingleLock lock(m_critSection);
  1634
+    bActivate = m_bActiveSourcePending;
  1635
+    m_bActiveSourcePending = false;
  1636
+  }
  1637
+
  1638
+  if (bActivate)
  1639
+    m_cecAdapter->SetActiveSource();
  1640
+}
  1641
+
  1642
+void CPeripheralCecAdapter::StandbyDevices(void)
  1643
+{
  1644
+  CSingleLock lock(m_critSection);
  1645
+  m_bStandbyPending = true;
  1646
+}
  1647
+
  1648
+void CPeripheralCecAdapter::ProcessStandbyDevices(void)
  1649
+{
  1650
+  bool bStandby(false);
  1651
+
  1652
+  {
  1653
+    CSingleLock lock(m_critSection);
  1654
+    bStandby = m_bStandbyPending;
  1655
+    m_bStandbyPending = false;
  1656
+  }
  1657
+
  1658
+  if (bStandby)
  1659
+    m_cecAdapter->StandbyDevices(CECDEVICE_BROADCAST);
  1660
+}
  1661
+
1613 1662
 #endif
7  xbmc/peripherals/devices/PeripheralCecAdapter.h
@@ -110,6 +110,9 @@ namespace PERIPHERALS
110 110
 
111 111
     void PushCecKeypress(const CEC::cec_keypress &key);
112 112
 
  113
+    void ActivateSource(void);
  114
+    void StandbyDevices(void);
  115
+
113 116
   protected:
114 117
     bool OpenConnection(void);
115 118
     void SetConfigurationFromSettings(void);
@@ -125,6 +128,8 @@ namespace PERIPHERALS
125 128
     static void CecSourceActivated(void *param, const CEC::cec_logical_address address, const uint8_t activated);
126 129
     bool IsRunning(void) const;
127 130
     void ReopenConnection(void);
  131
+    void ProcessActivateSource(void);
  132
+    void ProcessStandbyDevices(void);
128 133
 
129 134
     void GetNextKey(void);
130 135
     bool InitialiseFeature(const PeripheralFeature feature);
@@ -156,6 +161,8 @@ namespace PERIPHERALS
156 161
     CEC::ICECCallbacks                m_callbacks;
157 162
     CCriticalSection                  m_critSection;
158 163
     CEC::libcec_configuration         m_configuration;
  164
+    bool                              m_bActiveSourcePending;
  165
+    bool                              m_bStandbyPending;
159 166
   };
160 167
 
161 168
   class CPeripheralCecAdapterUpdateThread : public CThread
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.