From: Lars Op den Kamp Date: Tue, 22 Nov 2011 23:50:57 +0000 (+0100) Subject: cec: make SetStreamPath() thread safe. bugzid: 19 X-Git-Tag: upstream/2.2.0~1^2~44^2~116 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=7856411b6ce25b2e47b4c70038124fd7666066a3;p=deb_libcec.git cec: make SetStreamPath() thread safe. bugzid: 19 --- diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index a51abc7..a7ff64c 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -360,12 +360,7 @@ bool CCECProcessor::SetStreamPath(uint16_t iStreamPath) CCECBusDevice *device = GetDeviceByPhysicalAddress(iStreamPath); if (device) { - for (unsigned int iPtr = 0; iPtr < 16; iPtr++) - m_busDevices[iPtr]->m_bActiveSource = false; - - device->m_bActiveSource = true; - device->m_powerStatus = CEC_POWER_STATUS_ON; - + device->SetActiveDevice(); bReturn = true; } diff --git a/src/lib/devices/CECBusDevice.cpp b/src/lib/devices/CECBusDevice.cpp index 1fca4a5..e46e82d 100644 --- a/src/lib/devices/CECBusDevice.cpp +++ b/src/lib/devices/CECBusDevice.cpp @@ -216,7 +216,7 @@ cec_power_status CCECBusDevice::GetPowerStatus(void) return m_powerStatus; } -const cec_vendor_id CCECBusDevice::GetVendorId(void) +cec_vendor_id CCECBusDevice::GetVendorId(void) { if (m_vendor == CEC_VENDOR_UNKNOWN) { @@ -283,6 +283,24 @@ void CCECBusDevice::SetMenuState(const cec_menu_state state) } } +void CCECBusDevice::SetInactiveDevice(void) +{ + CLockObject lock(&m_mutex); + m_bActiveSource = false; +} + +void CCECBusDevice::SetActiveDevice(void) +{ + CLockObject lock(&m_mutex); + + for (int iPtr = 0; iPtr < 16; iPtr++) + if (iPtr != m_iLogicalAddress) + m_processor->m_busDevices[iPtr]->SetInactiveDevice(); + + m_bActiveSource = true; + m_powerStatus = CEC_POWER_STATUS_ON; +} + void CCECBusDevice::SetPhysicalAddress(uint16_t iNewAddress) { if (iNewAddress > 0) diff --git a/src/lib/devices/CECBusDevice.h b/src/lib/devices/CECBusDevice.h index 245f829..6b0ddb9 100644 --- a/src/lib/devices/CECBusDevice.h +++ b/src/lib/devices/CECBusDevice.h @@ -67,10 +67,13 @@ namespace CEC virtual cec_power_status GetPowerStatus(void); virtual CCECProcessor * GetProcessor(void) const { return m_processor; } virtual cec_device_type GetType(void) const { return m_type; } - virtual const cec_vendor_id GetVendorId(void); + virtual cec_vendor_id GetVendorId(void); virtual const char * GetVendorName(void); virtual bool MyLogicalAddressContains(cec_logical_address address) const; + virtual void SetInactiveDevice(void); + virtual void SetActiveDevice(void); + virtual void SetPhysicalAddress(uint16_t iNewAddress); virtual void SetStreamPath(uint16_t iNewAddress, uint16_t iOldAddress = 0); virtual void SetCecVersion(const cec_version newVersion);