Commit | Line | Data |
---|---|---|
abbca718 LOK |
1 | #pragma once |
2 | /* | |
3 | * This file is part of the libCEC(R) library. | |
4 | * | |
b492c10e | 5 | * libCEC(R) is Copyright (C) 2011-2012 Pulse-Eight Limited. All rights reserved. |
abbca718 LOK |
6 | * libCEC(R) is an original work, containing original code. |
7 | * | |
8 | * libCEC(R) is a trademark of Pulse-Eight Limited. | |
9 | * | |
10 | * This program is dual-licensed; you can redistribute it and/or modify | |
11 | * it under the terms of the GNU General Public License as published by | |
12 | * the Free Software Foundation; either version 2 of the License, or | |
13 | * (at your option) any later version. | |
14 | * | |
15 | * This program is distributed in the hope that it will be useful, | |
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | * GNU General Public License for more details. | |
19 | * | |
20 | * You should have received a copy of the GNU General Public License | |
21 | * along with this program; if not, write to the Free Software | |
22 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
23 | * | |
24 | * | |
25 | * Alternatively, you can license this library under a commercial license, | |
26 | * please contact Pulse-Eight Licensing for more information. | |
27 | * | |
28 | * For more information contact: | |
29 | * Pulse-Eight Licensing <license@pulse-eight.com> | |
30 | * http://www.pulse-eight.com/ | |
31 | * http://www.pulse-eight.net/ | |
32 | */ | |
33 | ||
25701fa6 | 34 | #include <string> |
4c9b9776 | 35 | #include "../../include/cectypes.h" |
7bb4ed43 | 36 | #include "platform/threads/threads.h" |
ba65909d | 37 | #include "platform/util/buffer.h" |
b1f94db1 | 38 | #include "adapter/AdapterCommunication.h" |
abbca718 | 39 | |
abbca718 LOK |
40 | namespace CEC |
41 | { | |
2abe74eb | 42 | class CLibCEC; |
7bdb5ccb | 43 | class IAdapterCommunication; |
e9de9629 | 44 | class CCECBusDevice; |
a8f0bd18 | 45 | |
a4b9f561 LOK |
46 | // a buffer that priotises the input from the TV. |
47 | // if we need more than this, we'll have to change it into a priority_queue | |
48 | class CCECInputBuffer | |
49 | { | |
50 | public: | |
51 | CCECInputBuffer(void) : m_bHasData(false) {} | |
52 | virtual ~CCECInputBuffer(void) | |
53 | { | |
54 | m_condition.Broadcast(); | |
55 | } | |
56 | ||
57 | bool Push(const cec_command &command) | |
58 | { | |
59 | bool bReturn(false); | |
60 | PLATFORM::CLockObject lock(m_mutex); | |
61 | if (command.initiator == CECDEVICE_TV) | |
62 | bReturn = m_tvInBuffer.Push(command); | |
63 | else | |
64 | bReturn = m_inBuffer.Push(command); | |
65 | ||
66 | m_bHasData |= bReturn; | |
4548e663 | 67 | if (m_bHasData) |
a4b9f561 LOK |
68 | m_condition.Signal(); |
69 | ||
70 | return bReturn; | |
71 | } | |
72 | ||
b32ffd87 | 73 | bool Pop(cec_command &command, uint16_t iTimeout) |
a4b9f561 LOK |
74 | { |
75 | bool bReturn(false); | |
76 | PLATFORM::CLockObject lock(m_mutex); | |
77 | if (m_tvInBuffer.IsEmpty() && m_inBuffer.IsEmpty() && | |
78 | !m_condition.Wait(m_mutex, m_bHasData, iTimeout)) | |
79 | return bReturn; | |
80 | ||
81 | if (m_tvInBuffer.Pop(command)) | |
82 | bReturn = true; | |
83 | else if (m_inBuffer.Pop(command)) | |
84 | bReturn = true; | |
85 | ||
86 | m_bHasData = !m_tvInBuffer.IsEmpty() || !m_inBuffer.IsEmpty(); | |
87 | return bReturn; | |
88 | } | |
89 | ||
90 | private: | |
91 | PLATFORM::CMutex m_mutex; | |
92 | PLATFORM::CCondition<volatile bool> m_condition; | |
93 | volatile bool m_bHasData; | |
94 | PLATFORM::SyncedBuffer<cec_command> m_tvInBuffer; | |
95 | PLATFORM::SyncedBuffer<cec_command> m_inBuffer; | |
96 | }; | |
97 | ||
b1f94db1 | 98 | class CCECProcessor : public PLATFORM::CThread, public IAdapterCommunicationCallback |
abbca718 LOK |
99 | { |
100 | public: | |
7bdfd76c | 101 | CCECProcessor(CLibCEC *controller, const char *strDeviceName, const cec_device_type_list &types, uint16_t iPhysicalAddress); |
3efda01a | 102 | CCECProcessor(CLibCEC *controller, libcec_configuration *configuration); |
2abe74eb LOK |
103 | virtual ~CCECProcessor(void); |
104 | ||
b32ffd87 | 105 | bool Start(const char *strPort, uint16_t iBaudRate = CEC_SERIAL_DEFAULT_BAUDRATE, uint32_t iTimeoutMs = CEC_DEFAULT_CONNECT_TIMEOUT); |
e186a843 LOK |
106 | void *Process(void); |
107 | void Close(void); | |
108 | ||
109 | bool OnCommandReceived(const cec_command &command); | |
110 | ||
111 | bool IsMonitoring(void) const { return m_bMonitor; } | |
0680dab3 | 112 | CCECBusDevice * GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress, bool bSuppressUpdate = true); |
e186a843 LOK |
113 | CCECBusDevice * GetDeviceByType(cec_device_type type) const; |
114 | CCECBusDevice * GetPrimaryDevice(void) const; | |
115 | cec_version GetDeviceCecVersion(cec_logical_address iAddress); | |
116 | bool GetDeviceMenuLanguage(cec_logical_address iAddress, cec_menu_language *language); | |
117 | CStdString GetDeviceName(void) const; | |
118 | cec_osd_name GetDeviceOSDName(cec_logical_address iAddress); | |
119 | uint64_t GetDeviceVendorId(cec_logical_address iAddress); | |
120 | cec_power_status GetDevicePowerStatus(cec_logical_address iAddress); | |
121 | cec_logical_address GetLogicalAddress(void) const { return m_configuration.logicalAddresses.primary; } | |
122 | cec_logical_addresses GetLogicalAddresses(void) const { return m_configuration.logicalAddresses; } | |
123 | cec_logical_addresses GetActiveDevices(void); | |
124 | uint16_t GetDevicePhysicalAddress(cec_logical_address iAddress); | |
125 | bool HasLogicalAddress(cec_logical_address address) const { return m_configuration.logicalAddresses.IsSet(address); } | |
126 | bool IsPresentDevice(cec_logical_address address); | |
127 | bool IsPresentDeviceType(cec_device_type type); | |
128 | uint16_t GetPhysicalAddress(void) const; | |
129 | uint64_t GetLastTransmission(void) const { return m_iLastTransmission; } | |
5734016c | 130 | cec_logical_address GetActiveSource(bool bRequestActiveSource = true); |
e186a843 LOK |
131 | bool IsActiveSource(cec_logical_address iAddress); |
132 | bool IsInitialised(void); | |
133 | bool SetStreamPath(uint16_t iPhysicalAddress); | |
134 | cec_client_version GetClientVersion(void) const { return (cec_client_version)m_configuration.clientVersion; }; | |
135 | bool StandbyDevices(cec_logical_address address = CECDEVICE_BROADCAST); | |
136 | bool PowerOnDevices(cec_logical_address address = CECDEVICE_BROADCAST); | |
137 | ||
138 | bool SetActiveView(void); | |
139 | bool SetActiveSource(cec_device_type type = CEC_DEVICE_TYPE_RESERVED); | |
140 | bool SetDeckControlMode(cec_deck_control_mode mode, bool bSendUpdate = true); | |
141 | bool SetDeckInfo(cec_deck_info info, bool bSendUpdate = true); | |
142 | bool SetHDMIPort(cec_logical_address iBaseDevice, uint8_t iPort, bool bForce = false); | |
143 | bool TransmitInactiveSource(void); | |
144 | bool SetLogicalAddress(cec_logical_address iLogicalAddress); | |
145 | bool SetMenuState(cec_menu_state state, bool bSendUpdate = true); | |
146 | bool SetPhysicalAddress(uint16_t iPhysicalAddress, bool bSendUpdate = true); | |
147 | bool SetActiveSource(uint16_t iStreamPath); | |
148 | bool SwitchMonitoring(bool bEnable); | |
149 | bool PollDevice(cec_logical_address iAddress); | |
150 | uint8_t VolumeUp(bool bSendRelease = true); | |
151 | uint8_t VolumeDown(bool bSendRelease = true); | |
152 | uint8_t MuteAudio(bool bSendRelease = true); | |
153 | bool TransmitKeypress(cec_logical_address iDestination, cec_user_control_code key, bool bWait = true); | |
154 | bool TransmitKeyRelease(cec_logical_address iDestination, bool bWait = true); | |
155 | bool EnablePhysicalAddressDetection(void); | |
dcd240b2 LOK |
156 | void SetStandardLineTimeout(uint8_t iTimeout); |
157 | void SetRetryLineTimeout(uint8_t iTimeout); | |
e186a843 LOK |
158 | bool GetCurrentConfiguration(libcec_configuration *configuration); |
159 | bool SetConfiguration(const libcec_configuration *configuration); | |
160 | bool CanPersistConfiguration(void); | |
161 | bool PersistConfiguration(libcec_configuration *configuration); | |
162 | void RescanActiveDevices(void); | |
acec5f48 | 163 | |
855a3a98 LOK |
164 | bool SetLineTimeout(uint8_t iTimeout); |
165 | ||
3e61b350 | 166 | const char *ToString(const cec_device_type type); |
03ae897d LOK |
167 | const char *ToString(const cec_menu_state state); |
168 | const char *ToString(const cec_version version); | |
169 | const char *ToString(const cec_power_status status); | |
170 | const char *ToString(const cec_logical_address address); | |
171 | const char *ToString(const cec_deck_control_mode mode); | |
172 | const char *ToString(const cec_deck_info status); | |
173 | const char *ToString(const cec_opcode opcode); | |
174 | const char *ToString(const cec_system_audio_status mode); | |
175 | const char *ToString(const cec_audio_status status); | |
176 | const char *ToString(const cec_vendor_id vendor); | |
caca2d81 | 177 | const char *ToString(const cec_client_version version); |
3efda01a | 178 | const char *ToString(const cec_server_version version); |
03ae897d | 179 | |
e186a843 LOK |
180 | bool Transmit(const cec_command &data); |
181 | void TransmitAbort(cec_logical_address address, cec_opcode opcode, cec_abort_reason reason = CEC_ABORT_REASON_UNRECOGNIZED_OPCODE); | |
e9de9629 | 182 | |
e186a843 LOK |
183 | bool ChangeDeviceType(cec_device_type from, cec_device_type to); |
184 | bool FindLogicalAddresses(void); | |
185 | bool SetAckMask(uint16_t iMask); | |
f8513317 | 186 | |
e186a843 LOK |
187 | bool StartBootloader(const char *strPort = NULL); |
188 | bool PingAdapter(void); | |
189 | void HandlePoll(cec_logical_address initiator, cec_logical_address destination); | |
190 | bool HandleReceiveFailed(cec_logical_address initiator); | |
1113cb7d | 191 | |
b32ffd87 | 192 | bool GetDeviceInformation(const char *strPort, libcec_configuration *config, uint32_t iTimeoutMs = CEC_DEFAULT_CONNECT_TIMEOUT); |
f80cd208 | 193 | |
b78b4e33 LOK |
194 | bool TransmitPendingActiveSourceCommands(void); |
195 | ||
f00ff009 | 196 | CCECBusDevice * m_busDevices[16]; |
abbca718 | 197 | |
e41b06f9 | 198 | private: |
f80cd208 | 199 | bool OpenConnection(const char *strPort, uint16_t iBaudRate, uint32_t iTimeoutMs, bool bStartListening = true); |
578c3905 | 200 | bool Initialise(void); |
2db8981f | 201 | void SetInitialised(bool bSetTo = true); |
caca2d81 | 202 | void CreateBusDevices(void); |
578c3905 | 203 | |
a3ffc068 | 204 | void ReplaceHandlers(void); |
45b97de7 | 205 | bool PhysicalAddressInUse(uint16_t iPhysicalAddress); |
b58d9277 LOK |
206 | bool TryLogicalAddress(cec_logical_address address); |
207 | bool FindLogicalAddressRecordingDevice(void); | |
208 | bool FindLogicalAddressTuner(void); | |
209 | bool FindLogicalAddressPlaybackDevice(void); | |
210 | bool FindLogicalAddressAudioSystem(void); | |
f8513317 | 211 | |
9dee1670 | 212 | void LogOutput(const cec_command &data); |
b1f94db1 | 213 | void ParseCommand(const cec_command &command); |
abbca718 | 214 | |
80726797 | 215 | bool m_bConnectionOpened; |
f00ff009 | 216 | bool m_bInitialised; |
f00ff009 | 217 | PLATFORM::CMutex m_mutex; |
7bb4ed43 | 218 | IAdapterCommunication * m_communication; |
f00ff009 LOK |
219 | CLibCEC* m_controller; |
220 | bool m_bMonitor; | |
f00ff009 LOK |
221 | cec_keypress m_previousKey; |
222 | PLATFORM::CThread * m_busScan; | |
f00ff009 LOK |
223 | uint8_t m_iStandardLineTimeout; |
224 | uint8_t m_iRetryLineTimeout; | |
225 | uint64_t m_iLastTransmission; | |
a4b9f561 | 226 | CCECInputBuffer m_inBuffer; |
30b4aac0 | 227 | libcec_configuration m_configuration; |
7c63a480 | 228 | }; |
abbca718 | 229 | }; |