[bluray] Fix stream info/language retrieval for blurays in non-nav mode.
[vuplus_xbmc] / xbmc / peripherals / devices / PeripheralCecAdapter.h
1 #pragma once
2 /*
3  *      Copyright (C) 2005-2013 Team XBMC
4  *      http://xbmc.org
5  *
6  *  This Program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2, or (at your option)
9  *  any later version.
10  *
11  *  This Program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with XBMC; see the file COPYING.  If not, see
18  *  <http://www.gnu.org/licenses/>.
19  *
20  */
21
22 #include "system.h"
23
24 #if !defined(HAVE_LIBCEC)
25 #include "Peripheral.h"
26
27 // an empty implementation, so CPeripherals can be compiled without a bunch of #ifdef's when libCEC is not available
28 namespace PERIPHERALS
29 {
30   class CPeripheralCecAdapter : public CPeripheral
31   {
32   public:
33     bool HasAudioControl(void) { return false; }
34     void VolumeUp(void) {}
35     void VolumeDown(void) {}
36     bool IsMuted(void) { return false; }
37     void ToggleMute(void) {}
38
39     int GetButton(void) { return 0; }
40     unsigned int GetHoldTime(void) { return 0; }
41     void ResetButton(void) {}
42   };
43 }
44
45 #else
46
47 #include "PeripheralHID.h"
48 #include "interfaces/AnnouncementManager.h"
49 #include "threads/Thread.h"
50 #include "threads/CriticalSection.h"
51 #include <queue>
52
53 // undefine macro isset, it collides with function in cectypes.h
54 #ifdef isset
55 #undef isset
56 #endif
57 #include <libcec/cectypes.h>
58
59 class DllLibCEC;
60
61 namespace CEC
62 {
63   class ICECAdapter;
64 };
65
66 namespace PERIPHERALS
67 {
68   class CPeripheralCecAdapterUpdateThread;
69
70   typedef struct
71   {
72     int         iButton;
73     unsigned int iDuration;
74   } CecButtonPress;
75
76   typedef enum
77   {
78     VOLUME_CHANGE_NONE,
79     VOLUME_CHANGE_UP,
80     VOLUME_CHANGE_DOWN,
81     VOLUME_CHANGE_MUTE
82   } CecVolumeChange;
83
84   class CPeripheralCecAdapter : public CPeripheralHID, public ANNOUNCEMENT::IAnnouncer, private CThread
85   {
86     friend class CPeripheralCecAdapterUpdateThread;
87
88   public:
89     CPeripheralCecAdapter(const PeripheralScanResult& scanResult);
90     virtual ~CPeripheralCecAdapter(void);
91
92     void Announce(ANNOUNCEMENT::AnnouncementFlag flag, const char *sender, const char *message, const CVariant &data);
93
94     // audio control
95     bool HasAudioControl(void);
96     void VolumeUp(void);
97     void VolumeDown(void);
98     void ToggleMute(void);
99     bool IsMuted(void);
100
101     // CPeripheral callbacks
102     void OnSettingChanged(const CStdString &strChangedSetting);
103     void OnDeviceRemoved(void);
104
105     // input
106     int GetButton(void);
107     unsigned int GetHoldTime(void);
108     void ResetButton(void);
109
110     // public CEC methods
111     void ActivateSource(void);
112     void StandbyDevices(void);
113
114   private:
115     bool InitialiseFeature(const PeripheralFeature feature);
116     void ResetMembers(void);
117     void Process(void);
118     bool IsRunning(void) const;
119
120     bool OpenConnection(void);
121     bool ReopenConnection(void);
122
123     void SetConfigurationFromSettings(void);
124     void SetConfigurationFromLibCEC(const CEC::libcec_configuration &config);
125     void SetVersionInfo(const CEC::libcec_configuration &configuration);
126
127     static void ReadLogicalAddresses(const CStdString &strString, CEC::cec_logical_addresses &addresses);
128     static void ReadLogicalAddresses(int iLocalisedId, CEC::cec_logical_addresses &addresses);
129     bool WriteLogicalAddresses(const CEC::cec_logical_addresses& addresses, const std::string& strSettingName, const std::string& strAdvancedSettingName);
130
131     void ProcessActivateSource(void);
132     void ProcessStandbyDevices(void);
133     void ProcessVolumeChange(void);
134
135     void PushCecKeypress(const CEC::cec_keypress &key);
136     void PushCecKeypress(const CecButtonPress &key);
137     void GetNextKey(void);
138
139     void SetAudioSystemConnected(bool bSetTo);
140     void SetMenuLanguage(const char *strLanguage);
141
142     // callbacks from libCEC
143     static int CecLogMessage(void *cbParam, const CEC::cec_log_message message);
144     static int CecCommand(void *cbParam, const CEC::cec_command command);
145     static int CecConfiguration(void *cbParam, const CEC::libcec_configuration config);
146     static int CecAlert(void *cbParam, const CEC::libcec_alert alert, const CEC::libcec_parameter data);
147     static void CecSourceActivated(void *param, const CEC::cec_logical_address address, const uint8_t activated);
148     static int CecKeyPress(void *cbParam, const CEC::cec_keypress key);
149
150     DllLibCEC*                        m_dll;
151     CEC::ICECAdapter*                 m_cecAdapter;
152     bool                              m_bStarted;
153     bool                              m_bHasButton;
154     bool                              m_bIsReady;
155     bool                              m_bHasConnectedAudioSystem;
156     CStdString                        m_strMenuLanguage;
157     CDateTime                         m_screensaverLastActivated;
158     std::vector<CecButtonPress>       m_buttonQueue;
159     CecButtonPress                    m_currentButton;
160     std::queue<CecVolumeChange>       m_volumeChangeQueue;
161     unsigned int                      m_lastKeypress;
162     CecVolumeChange                   m_lastChange;
163     int                               m_iExitCode;
164     bool                              m_bIsMuted;
165     bool                              m_bGoingToStandby;
166     bool                              m_bIsRunning;
167     bool                              m_bDeviceRemoved;
168     CPeripheralCecAdapterUpdateThread*m_queryThread;
169     CEC::ICECCallbacks                m_callbacks;
170     CCriticalSection                  m_critSection;
171     CEC::libcec_configuration         m_configuration;
172     bool                              m_bActiveSourcePending;
173     bool                              m_bStandbyPending;
174     CDateTime                         m_preventActivateSourceOnPlay;
175     bool                              m_bActiveSourceBeforeStandby;
176     bool                              m_bOnPlayReceived;
177     bool                              m_bPlaybackPaused;
178     CStdString                        m_strComPort;
179   };
180
181   class CPeripheralCecAdapterUpdateThread : public CThread
182   {
183   public:
184     CPeripheralCecAdapterUpdateThread(CPeripheralCecAdapter *adapter, CEC::libcec_configuration *configuration);
185     virtual ~CPeripheralCecAdapterUpdateThread(void);
186
187     void Signal(void);
188     bool UpdateConfiguration(CEC::libcec_configuration *configuration);
189
190   protected:
191     void UpdateMenuLanguage(void);
192     CStdString UpdateAudioSystemStatus(void);
193     bool WaitReady(void);
194     bool SetInitialConfiguration(void);
195     void Process(void);
196
197     CPeripheralCecAdapter *    m_adapter;
198     CEvent                     m_event;
199     CCriticalSection           m_critSection;
200     CEC::libcec_configuration  m_configuration;
201     CEC::libcec_configuration  m_nextConfiguration;
202     bool                       m_bNextConfigurationScheduled;
203     bool                       m_bIsUpdating;
204   };
205 }
206
207 #endif