Skip to content

Commit

Permalink
fixed: send an active source message when a routing change has been r…
Browse files Browse the repository at this point in the history
…eceived with libCEC's address as new route and no active source message has been sent yet. issue #309 #205 #233
  • Loading branch information
opdenkamp committed Mar 15, 2017
1 parent e1df683 commit 67d444d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/libcec/devices/CECBusDevice.cpp
Expand Up @@ -153,7 +153,8 @@ CCECBusDevice::CCECBusDevice(CCECProcessor *processor, cec_logical_address iLogi
m_bAwaitingReceiveFailed(false),
m_bVendorIdRequested (false),
m_waitForResponse (new CWaitForResponse),
m_bImageViewOnSent (false)
m_bImageViewOnSent (false),
m_bActiveSourceSent (false)
{
m_handler = new CCECCommandHandler(this);
m_strDeviceName = ToString(m_iLogicalAddress);
Expand Down Expand Up @@ -685,6 +686,9 @@ void CCECBusDevice::SetPowerStatus(const cec_power_status powerStatus)
m_iLastPowerStateUpdate = GetTimeMs();
LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s (%X): power status changed from '%s' to '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(m_powerStatus), ToString(powerStatus));
m_powerStatus = powerStatus;

if (m_iLogicalAddress == CECDEVICE_TV)
m_processor->GetDevices()->ResetActiveSourceSent();
}
}

Expand Down Expand Up @@ -1141,6 +1145,7 @@ bool CCECBusDevice::TransmitActiveSource(bool bIsReply)
if (bSendActiveSource)
{
MarkBusy();
SetActiveSourceSent(true);
bActiveSourceSent = m_handler->TransmitActiveSource(m_iLogicalAddress, iPhysicalAddress, bIsReply);
MarkReady();
}
Expand Down Expand Up @@ -1215,7 +1220,7 @@ void CCECBusDevice::SetActiveRoute(uint16_t iRoute)
return;

CCECBusDevice* newRoute = m_processor->GetDeviceByPhysicalAddress(iRoute, true);
if (newRoute && newRoute->IsHandledByLibCEC() && !newRoute->IsActiveSource())
if (newRoute && newRoute->IsHandledByLibCEC() && (!ActiveSourceSent() || !newRoute->IsActiveSource()))
{
// we were made the active source, send notification
newRoute->ActivateSource();
Expand Down Expand Up @@ -1498,3 +1503,13 @@ bool CCECBusDevice::TransmitMuteAudio(const cec_logical_address source)
return TransmitKeypress(source, CEC_USER_CONTROL_CODE_MUTE) &&
TransmitKeyRelease(source);
}

void CCECBusDevice::SetActiveSourceSent(bool setto = true)
{
m_bActiveSource = setto;
}

bool CCECBusDevice::ActiveSourceSent(void) const
{
return m_bActiveSourceSent;
}
4 changes: 4 additions & 0 deletions src/libcec/devices/CECBusDevice.h
Expand Up @@ -199,6 +199,9 @@ namespace CEC
void SignalOpcode(cec_opcode opcode);
bool WaitForOpcode(cec_opcode opcode);

void SetActiveSourceSent(bool setto = true);
bool ActiveSourceSent(void) const;

CCECAudioSystem * AsAudioSystem(void);
static CCECAudioSystem * AsAudioSystem(CCECBusDevice *device);
CCECPlaybackDevice * AsPlaybackDevice(void);
Expand Down Expand Up @@ -243,5 +246,6 @@ namespace CEC
bool m_bVendorIdRequested;
CWaitForResponse *m_waitForResponse;
bool m_bImageViewOnSent;
bool m_bActiveSourceSent;
};
};
6 changes: 6 additions & 0 deletions src/libcec/devices/CECDeviceMap.cpp
Expand Up @@ -212,6 +212,12 @@ CCECBusDevice *CCECDeviceMap::GetActiveSource(void) const
return NULL;
}

void CCECDeviceMap::ResetActiveSourceSent(void)
{
for (CECDEVICEMAP::iterator it = m_busDevices.begin(); it != m_busDevices.end(); it++)
it->second->SetActiveSourceSent(false);
}

void CCECDeviceMap::FilterLibCECControlled(CECDEVICEVEC &devices)
{
CECDEVICEVEC newDevices;
Expand Down
1 change: 1 addition & 0 deletions src/libcec/devices/CECDeviceMap.h
Expand Up @@ -71,6 +71,7 @@ namespace CEC
void GetWakeDevices(const libcec_configuration &configuration, CECDEVICEVEC &devices) const;

CCECBusDevice *GetActiveSource(void) const;
void ResetActiveSourceSent(void);

static void FilterLibCECControlled(CECDEVICEVEC &devices);
static void FilterActive(CECDEVICEVEC &devices);
Expand Down

3 comments on commit 67d444d

@nuwonda
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can it be that this commit is causing CEC issues as described here? #342 and here #343

@VimesUK
Copy link

@VimesUK VimesUK commented on 67d444d May 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that this commit, along with this one....

d1a708b

...is causing an issue with our Panasonic TV as it will not switch "source to this device on startup".

This was determined when using the working build 314 of the LibreELEC Testbuilds stopped functioning after build 315 was installed.....

http://forum.kodi.tv/showthread.php?tid=298461&pid=2549210#pid2549210

Milhouse was able to produce a new test build with this and the other commit noted being reverted......

http://forum.kodi.tv/showthread.php?tid=298461&pid=2591306#pid2591306

....and now it works fine with the TV switching to the correct HDMI input which the Pi 3 is connected to when the Pi3 is powered up.

Following the advice here....

http://forum.kodi.tv/showthread.php?tid=298461&pid=2591393#pid2591393

I am reporting this issue and the cause being these commits in the hope that this can be fixed.

Thanks

@opdenkamp
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It indeed was a typo in this commit, which has been fixed in af50b29

Please sign in to comment.