Commit | Line | Data |
---|---|---|
bb5b4874 LOK |
1 | /* |
2 | * This file is part of the libCEC(R) library. | |
3 | * | |
b492c10e | 4 | * libCEC(R) is Copyright (C) 2011-2012 Pulse-Eight Limited. All rights reserved. |
bb5b4874 LOK |
5 | * libCEC(R) is an original work, containing original code. |
6 | * | |
7 | * libCEC(R) is a trademark of Pulse-Eight Limited. | |
8 | * | |
9 | * This program is dual-licensed; you can redistribute it and/or modify | |
10 | * it under the terms of the GNU General Public License as published by | |
11 | * the Free Software Foundation; either version 2 of the License, or | |
12 | * (at your option) any later version. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful, | |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | * GNU General Public License for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License | |
20 | * along with this program; if not, write to the Free Software | |
21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
22 | * | |
23 | * | |
24 | * Alternatively, you can license this library under a commercial license, | |
25 | * please contact Pulse-Eight Licensing for more information. | |
26 | * | |
27 | * For more information contact: | |
28 | * Pulse-Eight Licensing <license@pulse-eight.com> | |
29 | * http://www.pulse-eight.com/ | |
30 | * http://www.pulse-eight.net/ | |
31 | */ | |
32 | ||
33 | #include "VLCommandHandler.h" | |
34 | #include "../devices/CECBusDevice.h" | |
3e61b350 | 35 | #include "../CECProcessor.h" |
b78b4e33 LOK |
36 | #include "../LibCEC.h" |
37 | ||
38 | #define VL_POWER_CHANGE 0x20 | |
39 | #define VL_POWERED_UP 0x00 | |
40 | #define VL_POWERED_DOWN 0x01 | |
bb5b4874 LOK |
41 | |
42 | using namespace CEC; | |
b78b4e33 | 43 | using namespace PLATFORM; |
bb5b4874 LOK |
44 | |
45 | CVLCommandHandler::CVLCommandHandler(CCECBusDevice *busDevice) : | |
b78b4e33 LOK |
46 | CCECCommandHandler(busDevice), |
47 | m_bActiveSourcePending(false), | |
48 | m_bPowerUpEventReceived(false) | |
bb5b4874 | 49 | { |
cf4931be | 50 | m_vendorId = CEC_VENDOR_PANASONIC; |
bb5b4874 | 51 | } |
3e61b350 LOK |
52 | |
53 | bool CVLCommandHandler::InitHandler(void) | |
54 | { | |
55 | CCECBusDevice *primary = m_processor->GetPrimaryDevice(); | |
56 | if (primary->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE) | |
3e61b350 | 57 | return m_processor->ChangeDeviceType(CEC_DEVICE_TYPE_RECORDING_DEVICE, CEC_DEVICE_TYPE_PLAYBACK_DEVICE); |
b78b4e33 | 58 | |
3e61b350 LOK |
59 | return CCECCommandHandler::InitHandler(); |
60 | } | |
b78b4e33 LOK |
61 | |
62 | bool CVLCommandHandler::HandleDeviceVendorCommandWithId(const cec_command &command) | |
63 | { | |
64 | if (command.initiator == CECDEVICE_TV && | |
65 | command.destination == CECDEVICE_BROADCAST && | |
66 | command.parameters.At(3) == VL_POWER_CHANGE) | |
67 | { | |
68 | if (command.parameters.At(4) == VL_POWERED_UP) | |
69 | { | |
70 | CLibCEC::AddLog(CEC_LOG_DEBUG, "TV powered up"); | |
71 | { | |
72 | CLockObject lock(m_mutex); | |
73 | m_bPowerUpEventReceived = true; | |
74 | } | |
75 | m_processor->TransmitPendingActiveSourceCommands(); | |
76 | } | |
77 | else if (command.parameters.At(4) == VL_POWERED_DOWN) | |
78 | CLibCEC::AddLog(CEC_LOG_DEBUG, "TV powered down"); | |
79 | else if (command.parameters.At(4) == VL_POWERED_DOWN) | |
80 | CLibCEC::AddLog(CEC_LOG_DEBUG, "unknown vendor command"); | |
81 | ||
82 | return true; | |
83 | } | |
84 | ||
85 | return CCECCommandHandler::HandleDeviceVendorCommandWithId(command); | |
86 | } | |
87 | ||
88 | bool CVLCommandHandler::TransmitActiveSource(const cec_logical_address iInitiator, uint16_t iPhysicalAddress) | |
89 | { | |
90 | bool bPowerUpEventReceived(false); | |
91 | ||
92 | { | |
93 | CLockObject lock(m_mutex); | |
94 | if (!m_bPowerUpEventReceived) | |
95 | { | |
96 | // just assume it's been sent when the tv is powered on | |
97 | cec_power_status powerStatus = m_processor->m_busDevices[CECDEVICE_TV]->GetPowerStatus(); | |
98 | m_bPowerUpEventReceived = (powerStatus == CEC_POWER_STATUS_ON); | |
99 | } | |
100 | bPowerUpEventReceived = m_bPowerUpEventReceived; | |
101 | } | |
102 | ||
103 | if (!bPowerUpEventReceived) | |
104 | { | |
105 | CLockObject lock(m_mutex); | |
106 | // wait until we received the event | |
107 | m_bActiveSourcePending = true; | |
108 | return true; | |
109 | } | |
110 | else | |
111 | { | |
112 | // transmit standard active source message | |
113 | return CCECCommandHandler::TransmitActiveSource(iInitiator, iPhysicalAddress); | |
114 | } | |
115 | } | |
116 | ||
117 | bool CVLCommandHandler::TransmitPendingActiveSourceCommands(void) | |
118 | { | |
119 | bool bTransmitCommand(false); | |
120 | { | |
121 | CLockObject lock(m_mutex); | |
122 | bTransmitCommand = m_bActiveSourcePending; | |
123 | m_bActiveSourcePending = false; | |
124 | } | |
125 | ||
126 | if (bTransmitCommand) | |
127 | { | |
128 | CLibCEC::AddLog(CEC_LOG_DEBUG, "transmitting delayed activate source command"); | |
129 | return CCECCommandHandler::TransmitActiveSource(m_busDevice->GetLogicalAddress(), m_busDevice->GetPhysicalAddress(false, true)); | |
130 | } | |
131 | return true; | |
132 | } |