|
1 /* |
|
2 * Copyright (c) 2010 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: Media Video harvester plugin implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 // Include Files |
|
19 #include "videoplugin.h" //CVideoPlugin |
|
20 #include <e32base.h> |
|
21 #include "harvesterserverlogger.h" |
|
22 #include "common.h" |
|
23 #include "csearchdocument.h" |
|
24 #include "ccpixindexer.h" |
|
25 #include "mdeharvester.h" |
|
26 #include "mdeobjectqueuemanager.h" |
|
27 #include "mdsmediamonitor.h" |
|
28 #include "mdssessionobjectutils.h" |
|
29 #include "cpixmediavideodoc.h" |
|
30 #include "cpixindexerutils.h" |
|
31 #include "mmcmonitor.h" |
|
32 #include "cpixmdedbmanager.h" |
|
33 #include "mdsitementity.h" |
|
34 |
|
35 //Constants |
|
36 _LIT(KPathTrailer, "\\root\\media\\video"); |
|
37 #define MEDIA_QBASEAPPCLASS "@0:root media video" |
|
38 #define LMEDIA_QBASEAPPCLASS L"@0:root media video" |
|
39 #define MEDIAAPPCLASS "root media video" |
|
40 #define LMEDIAAPPCLASS L"root media video" |
|
41 |
|
42 #define MEDIAGENERICAPPCLASS ":root media video" |
|
43 #define LMEDIAGENERICAPPCLASS L":root media video" |
|
44 #define DATABASEPATH "\\root\\media\\video" |
|
45 #define LDATABASEPATH "\\root\\media\\video" |
|
46 |
|
47 //Member Functions |
|
48 |
|
49 |
|
50 CVideoPlugin* CVideoPlugin::NewL() |
|
51 { |
|
52 CVideoPlugin* self = new (ELeave) CVideoPlugin; |
|
53 return self; |
|
54 } |
|
55 |
|
56 CVideoPlugin::CVideoPlugin() |
|
57 { |
|
58 #ifdef __PERFORMANCE_DATA |
|
59 count = 0; |
|
60 #endif |
|
61 //No implementation required. |
|
62 } |
|
63 |
|
64 CVideoPlugin::~CVideoPlugin() |
|
65 { |
|
66 delete iMdeHarvester; |
|
67 delete iMdsMonitor; |
|
68 delete iObjectJobQueueManager; |
|
69 delete iMdsUtils; |
|
70 delete iVideoDocument; |
|
71 delete iIndexerUtil; |
|
72 delete iMMcMonitor; |
|
73 delete iDBManager; |
|
74 delete iMdsItem; |
|
75 } |
|
76 |
|
77 void CVideoPlugin::StartPluginL() |
|
78 { |
|
79 //Define the basic application class |
|
80 CPIXLOGSTRING("CVideoPlugin::StartPluginL"); |
|
81 iIndexerUtil = CCPixIndexerUtils::NewL( iSearchSession ); |
|
82 TBuf<KMaxFileName> databasePathTemp; |
|
83 databasePathTemp.Append( KPathTrailer ); |
|
84 iIndexerUtil->MountAllAvailableDriveL( _L(MEDIAGENERICAPPCLASS), databasePathTemp ); |
|
85 // Instansiate harvesting and monitering |
|
86 iMdsUtils = CMdsSessionObjectUtils::NewL(); |
|
87 iMdsUtils->InitializeL(); |
|
88 iObjectJobQueueManager = CMdeObjectQueueManager::NewL( this ); |
|
89 iMdeHarvester = CMdeHarvester::NewL( iMdsUtils->GetSession(), this, |
|
90 iObjectJobQueueManager ); |
|
91 iMdsMonitor = CMdsMediaMonitor::NewL( iMdsUtils->GetSession(), iObjectJobQueueManager ); |
|
92 iMMcMonitor = CMMCMonitorUtil::NewL( this );//Observer is self |
|
93 iMMcMonitor->StartMonitoring(); |
|
94 //start monitoring video items |
|
95 iMdsMonitor->StartMonitoringL( MdeConstants::Video::KVideoObject ); |
|
96 iVideoDocument = CCPIXMediaVideoDoc::NewL(); //Doc fetcher |
|
97 // Start harvester for this plugin |
|
98 iObserver->AddHarvestingQueue(this, _L(MEDIA_QBASEAPPCLASS) ); |
|
99 TUid uidOfPlugin = {0x20029ABA}; |
|
100 iDBManager = CCPIXMDEDbManager::NewL(uidOfPlugin); |
|
101 iMdsItem = CMDSEntity::NewL(); |
|
102 } |
|
103 |
|
104 void CVideoPlugin::StartHarvestingL( const TDesC& /*aMedia*/ ) |
|
105 { |
|
106 CPIXLOGSTRING("CVideoPlugin::StartHarvestingL"); |
|
107 iDBManager->ResetL(); |
|
108 iIndexerUtil->ResetAllL(); |
|
109 //start video harvesting |
|
110 #ifdef __PERFORMANCE_DATA |
|
111 iStartTime.UniversalTime(); |
|
112 #endif |
|
113 iMdeHarvester->DoHarvesetL( MdeConstants::Video::KVideoObject ); |
|
114 } |
|
115 |
|
116 void CVideoPlugin::HarvestingCompletedL() |
|
117 { |
|
118 CPIXLOGSTRING("CVideoPlugin::HarvestingCompletedL"); |
|
119 #ifdef __PERFORMANCE_DATA |
|
120 UpdatePerformaceDataL(); |
|
121 #endif |
|
122 iObserver->HarvestingCompleted(this, _L(MEDIA_QBASEAPPCLASS), KErrNone); |
|
123 } |
|
124 |
|
125 //handle MMC event for the Drive |
|
126 void CVideoPlugin::HandleMMCEventL(const TDriveNumber aDrive,const TBool aMMCInsertRemoval) |
|
127 { |
|
128 TBuf<KMaxFileName> databasePathTemp; |
|
129 databasePathTemp.Append(KPathTrailer); |
|
130 if(aMMCInsertRemoval) //MMC inserted |
|
131 { |
|
132 iIndexerUtil->MountDriveL(aDrive,_L(MEDIAGENERICAPPCLASS),databasePathTemp); |
|
133 //iIndexerUtil->GetIndexerFromDrive(aDrive)->ResetL(); |
|
134 } |
|
135 else |
|
136 { |
|
137 //MMC is removed but we can not reset index here as Media physically not avilable so |
|
138 // we have to do at the time of insertion only |
|
139 //Unmount drive and also reset the index as we anyhow has to reindex on insertion back |
|
140 iIndexerUtil->UnMountDriveL(aDrive,_L(MEDIAGENERICAPPCLASS),ETrue); |
|
141 } |
|
142 } |
|
143 |
|
144 void CVideoPlugin::HandleMdeItemL( TItemId aObjId, TCPixActionType aActionType) |
|
145 { |
|
146 //Get the object from object utils and get the CPIX document and add delete or update |
|
147 CPIXLOGSTRING2("CVideoPlugin::HandleMdeItemL(): aObjId = %d ", aObjId ); |
|
148 // creating CSearchDocument object with unique ID for this application |
|
149 TBuf<KMaxFileName> docid_str; |
|
150 if (aActionType == ECPixAddAction || aActionType == ECPixUpdateAction ) |
|
151 { |
|
152 //To Improve performance check here only before Getobject if it is Add event |
|
153 //and we already have in our database just return in case of update move forward |
|
154 if(iDBManager->IsAlreadyExistL(aObjId) && aActionType == ECPixAddAction)//Avoid reharvesting |
|
155 { |
|
156 CPIXLOGSTRING("CVideoPlugin::HandleMdeItemL(): Already harvested returning"); |
|
157 return; |
|
158 } |
|
159 CMdEObject& object= iMdsUtils->GetObjectL( aObjId,MdeConstants::Video::KVideoObject ); |
|
160 CMdENamespaceDef& defaultNamespaceDef = iMdsUtils->GetSession()->GetDefaultNamespaceDefL(); |
|
161 CMdEObjectDef& videoObjDef = defaultNamespaceDef.GetObjectDefL( MdeConstants::Video::KVideoObject ); |
|
162 CSearchDocument* index_item = iVideoDocument->GetCpixDocumentL(object,_L(MEDIAAPPCLASS),videoObjDef); |
|
163 iIndexer = iIndexerUtil->GetIndexerFromMediaId(object.MediaId()); |
|
164 |
|
165 if (!iIndexer) |
|
166 { |
|
167 delete index_item; |
|
168 CPIXLOGSTRING("CVideoPlugin::HandleMdeItemL(): Indexer not found"); |
|
169 return; |
|
170 } |
|
171 // Send for indexing |
|
172 if (aActionType == ECPixAddAction) |
|
173 { |
|
174 #ifdef __PERFORMANCE_DATA |
|
175 ++count; |
|
176 #endif |
|
177 CPIXLOGSTRING("CVideoPlugin::HandleMdeItemL(): Indexer found calling AddL"); |
|
178 //First check if it already exist in database |
|
179 TRAPD(err, iIndexer->UpdateL(*index_item)); //Always Update to avoid reharvesting |
|
180 if (err == KErrNone) |
|
181 { |
|
182 //Add entity to database for later use |
|
183 iMdsItem->Reset();//reset existing values |
|
184 iMdsItem->Setkey(aObjId); |
|
185 iMdsItem->SetUri(iVideoDocument->GetUri());//Use the Absolute URI |
|
186 TDriveNumber drive; |
|
187 iIndexerUtil->GetDriveFromMediaId(object.MediaId(),drive); |
|
188 iMdsItem->SetDrive(drive); |
|
189 iDBManager->AddL(aObjId,*iMdsItem);//Add to SyncDB |
|
190 CPIXLOGSTRING("CVideoPlugin::HandleMdeItemL(): Added."); |
|
191 } |
|
192 else |
|
193 { |
|
194 CPIXLOGSTRING2("CVideoPlugin::HandleMdeItemL(): Error %d in adding.", err); |
|
195 } |
|
196 } |
|
197 else if (aActionType == ECPixUpdateAction) |
|
198 { |
|
199 //If DocID for e.g \video\something.3gpp itself changes the we have to compare |
|
200 //existing URI with new one and Remove that first and Update to avoid |
|
201 //Duplicate entries |
|
202 iMdsItem->Reset();//reset existing values |
|
203 TRAPD(err, iDBManager->GetItemL(aObjId,*iMdsItem)); |
|
204 if(err == KErrNone) |
|
205 { |
|
206 //Get the drivenumber from the syncDB to delete the appropriate docId |
|
207 //in case an item is moved to different drive, delete from the old drive first and later update. |
|
208 //comparing the absolute paths along with the root drives |
|
209 if(iMdsItem->GetPath().Compare(object.Uri()) != 0) |
|
210 { |
|
211 CCPixIndexer *tempIndexer; |
|
212 tempIndexer = iIndexerUtil->GetIndexerFromDrive(iMdsItem->DriveNumber()); |
|
213 tempIndexer->DeleteL(iMdsItem->Uri()); |
|
214 CPIXLOGSTRING("CVideoPlugin::HandleMdeItemL(): Deleted existing URI for update"); |
|
215 } |
|
216 TRAPD(error, iIndexer->UpdateL(*index_item)); |
|
217 if (error == KErrNone) |
|
218 { |
|
219 //Add as new |
|
220 iMdsItem->Reset();//reset existing values |
|
221 TDriveNumber drive; |
|
222 iIndexerUtil->GetDriveFromMediaId(object.MediaId(),drive); |
|
223 iMdsItem->Set(aObjId,iVideoDocument->GetUri(),drive); |
|
224 iDBManager->UpdateL(aObjId,*iMdsItem);//Add to SyncDB |
|
225 CPIXLOGSTRING("CVideoPlugin::HandleMdeItemL(): Updated."); |
|
226 } |
|
227 else |
|
228 { |
|
229 CPIXLOGSTRING2("CVideoPlugin::HandleMdeItemL(): Error %d in updating.", error); |
|
230 } |
|
231 } |
|
232 //If a media item is added when downloading or streaming begins, add event is surpassed |
|
233 //by update or delete event because of delay introduced on monitered object by objectqueue manager |
|
234 //So add the Item first, when GetItemL() leaves with item not found |
|
235 else if(err == KErrNotFound) |
|
236 { |
|
237 TRAPD(error, iIndexer->UpdateL(*index_item)); |
|
238 if (error == KErrNone) |
|
239 { |
|
240 //Add entity to database for later use |
|
241 iMdsItem->Reset();//reset existing values |
|
242 iMdsItem->Setkey(aObjId); |
|
243 iMdsItem->SetUri(iVideoDocument->GetUri());//Use the Absolute URI |
|
244 TDriveNumber drive; |
|
245 iIndexerUtil->GetDriveFromMediaId(object.MediaId(),drive); |
|
246 iMdsItem->SetDrive(drive); |
|
247 iDBManager->AddL(aObjId,*iMdsItem);//Add to SyncDB |
|
248 CPIXLOGSTRING("CVideoPlugin::HandleMdeItemL(): Added Item before Update."); |
|
249 } |
|
250 } |
|
251 } |
|
252 delete index_item; |
|
253 iIndexer = NULL; |
|
254 } |
|
255 else if (aActionType == ECPixRemoveAction) |
|
256 { |
|
257 // Remove the document |
|
258 //Get the Item from SyncDB for removed Item |
|
259 iMdsItem->Reset();//reset existing values |
|
260 TRAPD(error, iDBManager->GetItemL(aObjId,*iMdsItem)); |
|
261 if (error == KErrNone) |
|
262 { |
|
263 iIndexer = iIndexerUtil->GetIndexerFromDrive(iMdsItem->DriveNumber());//Get Indexer from drive |
|
264 if(iIndexer) //If indexer found delete |
|
265 { |
|
266 docid_str.Copy(iMdsItem->Uri()); |
|
267 TRAPD(err, iIndexer->DeleteL(docid_str));//Delete it |
|
268 if (err == KErrNone) |
|
269 { |
|
270 CPIXLOGSTRING("CVideoPlugin::HandleMdeItemL(): Deleted."); |
|
271 } |
|
272 else |
|
273 { |
|
274 CPIXLOGSTRING2("CVideoPlugin::HandleMdeItemL(): Error %d in deleting.", err); |
|
275 } |
|
276 } |
|
277 //delete entry from database |
|
278 iDBManager->RemoveL(iMdsItem->Key()); |
|
279 } |
|
280 iIndexer = NULL;//Assign to null not pointing to any memory |
|
281 } |
|
282 } |
|
283 |
|
284 #ifdef __PERFORMANCE_DATA |
|
285 void CVideoPlugin::UpdateLogL() |
|
286 { |
|
287 UpdatePerformaceDataL(); |
|
288 } |
|
289 |
|
290 void CVideoPlugin::UpdatePerformaceDataL() |
|
291 { |
|
292 TTime now; |
|
293 |
|
294 iCompleteTime.UniversalTime(); |
|
295 TTimeIntervalMicroSeconds timeDiff = iCompleteTime.MicroSecondsFrom(iStartTime); |
|
296 |
|
297 RFs fileSession; |
|
298 RFile perfFile; |
|
299 User::LeaveIfError( fileSession.Connect () ); |
|
300 |
|
301 |
|
302 /* Open file if it exists, otherwise create it and write content in it */ |
|
303 |
|
304 if(perfFile.Open(fileSession, _L("c:\\data\\VideoPerf.txt"), EFileWrite)) |
|
305 User::LeaveIfError(perfFile.Create (fileSession, _L("c:\\data\\VideoPerf.txt"), EFileWrite)); |
|
306 |
|
307 HBufC8 *heap = HBufC8::NewL(100); |
|
308 TPtr8 ptr = heap->Des(); |
|
309 now.HomeTime(); |
|
310 TBuf<50> timeString; |
|
311 |
|
312 _LIT(KOwnTimeFormat,"%:0%H%:1%T%:2%S"); |
|
313 now.FormatL(timeString,KOwnTimeFormat); |
|
314 ptr.AppendNum(now.DateTime().Day()); |
|
315 ptr.Append(_L("/")); |
|
316 ptr.AppendNum(now.DateTime().Month()); |
|
317 ptr.Append(_L("/")); |
|
318 ptr.AppendNum(now.DateTime().Year()); |
|
319 ptr.Append(_L(":")); |
|
320 ptr.Append(timeString); |
|
321 ptr.Append(_L("--")); |
|
322 ptr.AppendNum(count); |
|
323 ptr.Append( _L(" :Time took for Harvesting Video is : ")); |
|
324 ptr.AppendNum(timeDiff.Int64()/1000) ; |
|
325 ptr.Append(_L(" MilliSeonds \n")); |
|
326 TInt myInt = 0; |
|
327 perfFile.Seek(ESeekEnd,myInt); |
|
328 perfFile.Write (ptr); |
|
329 perfFile.Close (); |
|
330 fileSession.Close (); |
|
331 delete heap; |
|
332 } |
|
333 #endif |