|
1 /* |
|
2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: This class observes the accessory framework. |
|
15 * |
|
16 */ |
|
17 |
|
18 // Version : %version: 6 % |
|
19 |
|
20 // |
|
21 // INCLUDE FILES |
|
22 // |
|
23 #include <e32svr.h> |
|
24 #include <AccPolSubblockNameArray.h> |
|
25 |
|
26 #include "mpxvideoaccessoryobserver.h" |
|
27 #include "mpxvideoplaybackcontroller.h" |
|
28 #include "mpxvideo_debug.h" |
|
29 |
|
30 // |
|
31 // ============================ MEMBER FUNCTIONS =================================================== |
|
32 // |
|
33 |
|
34 // ------------------------------------------------------------------------------------------------- |
|
35 // CMPXVideoAccessoryObserver::NewL |
|
36 // Two-phased constructor. |
|
37 // ------------------------------------------------------------------------------------------------- |
|
38 // |
|
39 CMPXVideoAccessoryObserver* |
|
40 CMPXVideoAccessoryObserver::NewL( CMPXVideoPlaybackController* aController ) |
|
41 { |
|
42 MPX_ENTER_EXIT(_L("CMPXVideoAccessoryObserver::NewL()")); |
|
43 |
|
44 CMPXVideoAccessoryObserver* self = new (ELeave) CMPXVideoAccessoryObserver( aController ); |
|
45 CleanupStack::PushL( self ); |
|
46 self->ConstructL(); |
|
47 CleanupStack::Pop( self ); |
|
48 return self; |
|
49 } |
|
50 |
|
51 // ------------------------------------------------------------------------------------------------- |
|
52 // CMPXVideoAccessoryObserver::ConstructL |
|
53 // Symbian 2nd phase constructor can leave |
|
54 // ------------------------------------------------------------------------------------------------- |
|
55 // |
|
56 void CMPXVideoAccessoryObserver::ConstructL() |
|
57 { |
|
58 MPX_ENTER_EXIT(_L("CMPXVideoAccessoryObserver::ConstructL()")); |
|
59 |
|
60 #ifdef __ACCESSORY_FW |
|
61 User::LeaveIfError( iServer.Connect() ); |
|
62 User::LeaveIfError( iConnection.CreateSubSession( iServer ) ); |
|
63 |
|
64 // |
|
65 // Get initial accessory status synchronously |
|
66 // |
|
67 iConnection.GetAccessoryConnectionStatus( iGenericIdArray ); |
|
68 #endif |
|
69 |
|
70 // |
|
71 // This will set check if a TV-Out accessory has been connected |
|
72 // and initialize the member variable |
|
73 // |
|
74 UpdateTvOutStatusL(); |
|
75 |
|
76 StartMonitoringL(); |
|
77 } |
|
78 |
|
79 // ------------------------------------------------------------------------------------------------- |
|
80 // CMPXVideoAccessoryObserver::CMPXVideoAccessoryObserver |
|
81 // ------------------------------------------------------------------------------------------------- |
|
82 // |
|
83 CMPXVideoAccessoryObserver::CMPXVideoAccessoryObserver( CMPXVideoPlaybackController* aController ) |
|
84 : CActive( CActive::EPriorityStandard ) |
|
85 , iController( aController ) |
|
86 , iTvOutConnected( EFalse ) |
|
87 , iTvOutPlaybackAllowed( ETrue ) |
|
88 { |
|
89 CActiveScheduler::Add( this ); |
|
90 } |
|
91 |
|
92 // ------------------------------------------------------------------------------------------------- |
|
93 // CMPXVideoAccessoryObserver::~CMPXVideoAccessoryObserver |
|
94 // Destructor, close and release the handles. |
|
95 // ------------------------------------------------------------------------------------------------- |
|
96 // |
|
97 CMPXVideoAccessoryObserver::~CMPXVideoAccessoryObserver() |
|
98 { |
|
99 MPX_ENTER_EXIT(_L("CMPXVideoAccessoryObserver::~CMPXVideoAccessoryObserver()")); |
|
100 |
|
101 Cancel(); |
|
102 |
|
103 #ifdef __ACCESSORY_FW |
|
104 iConnection.CloseSubSession(); |
|
105 iServer.Disconnect(); |
|
106 #endif |
|
107 } |
|
108 |
|
109 // ------------------------------------------------------------------------------------------------- |
|
110 // CMPXVideoAccessoryObserver::StartMonitoringL |
|
111 // ------------------------------------------------------------------------------------------------- |
|
112 // |
|
113 void CMPXVideoAccessoryObserver::StartMonitoringL() |
|
114 { |
|
115 MPX_ENTER_EXIT(_L("CMPXVideoAccessoryObserver::StartMonitoringL()")); |
|
116 |
|
117 if ( ! IsActive() ) |
|
118 { |
|
119 #ifdef __ACCESSORY_FW |
|
120 iConnection.NotifyAccessoryConnectionStatusChanged( iStatus, iGenericIdArray ); |
|
121 #endif |
|
122 |
|
123 SetActive(); |
|
124 } |
|
125 } |
|
126 |
|
127 // ------------------------------------------------------------------------------------------------- |
|
128 // CMPXVideoAccessoryObserver::UpdateTvOutStatusL |
|
129 // ------------------------------------------------------------------------------------------------- |
|
130 // |
|
131 TBool CMPXVideoAccessoryObserver::UpdateTvOutStatusL() |
|
132 { |
|
133 MPX_DEBUG(_L("CMPXVideoAccessoryObserver::UpdateTvOutStatusL()")); |
|
134 |
|
135 TBool statusChanged = EFalse; |
|
136 |
|
137 // |
|
138 // Initialize TV-Out value to EFalse before checking if |
|
139 // accessories support TV-Out |
|
140 // |
|
141 TBool tvOutConnected = EFalse; |
|
142 |
|
143 #ifdef __ACCESSORY_FW |
|
144 CAccPolSubblockNameArray* nameArray = CAccPolSubblockNameArray::NewL(); |
|
145 CleanupStack::PushL( nameArray ); |
|
146 |
|
147 // |
|
148 // Get the number of currently connected accessories |
|
149 // Loop through each connected accessory looking for |
|
150 // the desired capabilities |
|
151 // |
|
152 const TInt count = iGenericIdArray.Count(); |
|
153 |
|
154 for ( TInt index = 0 ; index < count ; index++ ) |
|
155 { |
|
156 // |
|
157 // Get all supported capabilities for this connected accessory. |
|
158 // |
|
159 iConnection.GetSubblockNameArrayL( iGenericIdArray.GetGenericIDL( index ), *nameArray ); |
|
160 |
|
161 // |
|
162 // Check if this connected accessory supports TV-Out |
|
163 // |
|
164 if ( nameArray->HasName( KAccVideoOut ) ) |
|
165 { |
|
166 MPX_DEBUG(_L(" TV-Out Capabilities Exist")); |
|
167 |
|
168 tvOutConnected = ETrue; |
|
169 break; |
|
170 } |
|
171 } |
|
172 |
|
173 CleanupStack::PopAndDestroy( nameArray ); |
|
174 #endif |
|
175 |
|
176 // |
|
177 // Check if the TV-Out status has changed |
|
178 // |
|
179 if ( iTvOutConnected != tvOutConnected ) |
|
180 { |
|
181 iTvOutConnected = tvOutConnected; |
|
182 |
|
183 if ( iTvOutConnected ) |
|
184 { |
|
185 // |
|
186 // Check the playablility of the clip |
|
187 // |
|
188 iTvOutPlaybackAllowed = iController->iPlaybackMode->IsTvOutAllowedL(); |
|
189 } |
|
190 else |
|
191 { |
|
192 iTvOutPlaybackAllowed = ETrue; |
|
193 } |
|
194 |
|
195 statusChanged = ETrue; |
|
196 } |
|
197 |
|
198 MPX_DEBUG(_L(" iTvOutConnected = %d"), iTvOutConnected); |
|
199 |
|
200 MPX_DEBUG(_L("CMPXVideoAccessoryObserver::UpdateTvOutStatusL() ret = %d"), statusChanged); |
|
201 |
|
202 return statusChanged; |
|
203 } |
|
204 |
|
205 // ----------------------------------------------------------------------------- |
|
206 // CMPXVideoAccessoryObserver::RunL |
|
207 // ----------------------------------------------------------------------------- |
|
208 // |
|
209 void CMPXVideoAccessoryObserver::RunL() |
|
210 { |
|
211 MPX_ENTER_EXIT(_L("CMPXVideoAccessoryObserver::RunL()"), |
|
212 _L("iStatus = %d"), iStatus.Int()); |
|
213 |
|
214 #ifdef __ACCESSORY_FW |
|
215 if ( KErrNone == iStatus.Int() ) |
|
216 { |
|
217 // |
|
218 // Check for TV-Out status change |
|
219 // If a changed, issue notice to the observer |
|
220 // |
|
221 if ( UpdateTvOutStatusL() ) |
|
222 { |
|
223 iController->HandleTvOutEventL( iTvOutConnected ); |
|
224 } |
|
225 } |
|
226 #endif |
|
227 |
|
228 // |
|
229 // Renew request for accessory events |
|
230 // |
|
231 StartMonitoringL(); |
|
232 } |
|
233 |
|
234 // ----------------------------------------------------------------------------- |
|
235 // CMPXVideoAccessoryObserver::DoCancel |
|
236 // ----------------------------------------------------------------------------- |
|
237 // |
|
238 void CMPXVideoAccessoryObserver::DoCancel() |
|
239 { |
|
240 MPX_ENTER_EXIT(_L("CMPXVideoAccessoryObserver::DoCancel()")); |
|
241 |
|
242 #ifdef __ACCESSORY_FW |
|
243 iConnection.CancelNotifyAccessoryConnectionStatusChanged(); |
|
244 #endif |
|
245 } |
|
246 |
|
247 // ----------------------------------------------------------------------------- |
|
248 // CMPXVideoAccessoryObserver::RunError |
|
249 // ----------------------------------------------------------------------------- |
|
250 // |
|
251 TInt CMPXVideoAccessoryObserver::RunError( TInt aError ) |
|
252 { |
|
253 MPX_ENTER_EXIT(_L("CMPXVideoAccessoryObserver::RunError()"), |
|
254 _L("aError = %d"), aError); |
|
255 |
|
256 #ifdef __ACCESSORY_FW |
|
257 // |
|
258 // Error occurred, issue new request for accessory status |
|
259 // |
|
260 iConnection.NotifyAccessoryConnectionStatusChanged( iStatus, iGenericIdArray ); |
|
261 #endif |
|
262 |
|
263 return KErrNone; |
|
264 } |
|
265 |
|
266 // ------------------------------------------------------------------------------------------------- |
|
267 // CMPXVideoAccessoryObserver::IsTvOutConnected |
|
268 // ------------------------------------------------------------------------------------------------- |
|
269 // |
|
270 TBool CMPXVideoAccessoryObserver::IsTvOutConnected() |
|
271 { |
|
272 MPX_DEBUG(_L("CMPXVideoAccessoryObserver::IsTvOutConnected(%d)"), iTvOutConnected); |
|
273 |
|
274 return iTvOutConnected; |
|
275 } |
|
276 |
|
277 // ------------------------------------------------------------------------------------------------- |
|
278 // CMPXVideoAccessoryObserver::IsTvOutPlaybackAllowed |
|
279 // ------------------------------------------------------------------------------------------------- |
|
280 // |
|
281 TBool CMPXVideoAccessoryObserver::IsTvOutPlaybackAllowed() |
|
282 { |
|
283 TBool playAllowed = ( ! iTvOutConnected || iTvOutPlaybackAllowed ); |
|
284 MPX_DEBUG(_L("CMPXVideoAccessoryObserver::IsTvOutPlaybackAllowed(%d)"), playAllowed); |
|
285 |
|
286 return playAllowed; |
|
287 } |
|
288 |
|
289 // End of File |