|
1 /* |
|
2 * Copyright (c) 2007-2009 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: Harvests metadata from rtp video file |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <e32std.h> |
|
19 #include <apgcli.h> |
|
20 |
|
21 #include "harvesterdata.h" |
|
22 #include "harvesterrtpplugin.h" |
|
23 #include "harvesterlog.h" |
|
24 #include "mdeobject.h" |
|
25 #include "mdsutils.h" |
|
26 #include "mdeobjectwrapper.h" |
|
27 #include "harvesterrtpmetadatareader.h" |
|
28 #include <mdenamespacedef.h> |
|
29 #include <mdeobjectdef.h> |
|
30 |
|
31 // Supported mime type |
|
32 _LIT( KRtpClipMimetype, "application/x-nokia-teh-rtp" ); |
|
33 |
|
34 // Enough size to recognize file and read metaheader |
|
35 const TInt KFileBufferSize( KMaxMetaHeaderLength ); |
|
36 |
|
37 CHarvesterRtpPluginPropertyDefs::CHarvesterRtpPluginPropertyDefs() : CBase() |
|
38 { |
|
39 } |
|
40 |
|
41 void CHarvesterRtpPluginPropertyDefs::ConstructL(CMdEObjectDef& aObjectDef) |
|
42 { |
|
43 CMdENamespaceDef& nsDef = aObjectDef.NamespaceDef(); |
|
44 |
|
45 // Common property definitions |
|
46 CMdEObjectDef& objectDef = nsDef.GetObjectDefL( MdeConstants::Object::KBaseObject ); |
|
47 iCreationDatePropertyDef = &objectDef.GetPropertyDefL( MdeConstants::Object::KCreationDateProperty ); |
|
48 iLastModifiedDatePropertyDef = &objectDef.GetPropertyDefL( MdeConstants::Object::KLastModifiedDateProperty ); |
|
49 iSizePropertyDef = &objectDef.GetPropertyDefL( MdeConstants::Object::KSizeProperty ); |
|
50 iItemTypePropertyDef = &objectDef.GetPropertyDefL( MdeConstants::Object::KItemTypeProperty ); |
|
51 iTitlePropertyDef = &objectDef.GetPropertyDefL( MdeConstants::Object::KTitleProperty ); |
|
52 |
|
53 CMdEObjectDef& mediaDef = nsDef.GetObjectDefL( MdeConstants::MediaObject::KMediaObject ); |
|
54 iCaptureDatePropertyDef =& mediaDef.GetPropertyDefL( MdeConstants::MediaObject::KCaptureDateProperty ); |
|
55 iDurationPropertyDef = &mediaDef.GetPropertyDefL( MdeConstants::MediaObject::KDurationProperty ); |
|
56 |
|
57 CMdEObjectDef& videoDef = nsDef.GetObjectDefL( MdeConstants::Video::KVideoObject ); |
|
58 iAgeProfilePropertyDef = &videoDef.GetPropertyDefL( MdeConstants::Video::KAgeProfileProperty ); |
|
59 iRecordingFlagsPropertyDef = &videoDef.GetPropertyDefL( MdeConstants::Video::KRecordingFlagsProperty ); |
|
60 } |
|
61 |
|
62 CHarvesterRtpPluginPropertyDefs* CHarvesterRtpPluginPropertyDefs::NewL(CMdEObjectDef& aObjectDef) |
|
63 { |
|
64 CHarvesterRtpPluginPropertyDefs* self = |
|
65 new (ELeave) CHarvesterRtpPluginPropertyDefs(); |
|
66 CleanupStack::PushL( self ); |
|
67 self->ConstructL( aObjectDef ); |
|
68 CleanupStack::Pop( self ); |
|
69 return self; |
|
70 } |
|
71 |
|
72 // ======== MEMBER FUNCTIONS ======== |
|
73 |
|
74 // --------------------------------------------------------------------------- |
|
75 // Default constructor |
|
76 // --------------------------------------------------------------------------- |
|
77 // |
|
78 CHarvesterRtpPlugin::CHarvesterRtpPlugin() : CHarvesterPlugin(), iPropDefs( NULL ) |
|
79 { |
|
80 } |
|
81 |
|
82 // --------------------------------------------------------------------------- |
|
83 // 2nd phase constructor |
|
84 // --------------------------------------------------------------------------- |
|
85 // |
|
86 void CHarvesterRtpPlugin::ConstructL() |
|
87 { |
|
88 WRITELOG( "CHarvesterRtpPlugin::ConstructL()" ); |
|
89 } |
|
90 |
|
91 // --------------------------------------------------------------------------- |
|
92 // Constructor |
|
93 // --------------------------------------------------------------------------- |
|
94 // |
|
95 CHarvesterRtpPlugin* CHarvesterRtpPlugin::NewL() |
|
96 { |
|
97 CHarvesterRtpPlugin* self = new(ELeave) CHarvesterRtpPlugin(); |
|
98 CleanupStack::PushL(self); |
|
99 self->ConstructL(); |
|
100 CleanupStack::Pop(self); |
|
101 |
|
102 return self; |
|
103 } |
|
104 |
|
105 // --------------------------------------------------------------------------- |
|
106 // Destructor |
|
107 // --------------------------------------------------------------------------- |
|
108 // |
|
109 CHarvesterRtpPlugin::~CHarvesterRtpPlugin() |
|
110 { |
|
111 WRITELOG( "CHarvesterRtpPlugin::~CHarvesterRtpPlugin()" ); |
|
112 } |
|
113 |
|
114 // --------------------------------------------------------------------------- |
|
115 // Harvest file |
|
116 // --------------------------------------------------------------------------- |
|
117 // |
|
118 void CHarvesterRtpPlugin::HarvestL( CHarvesterData* aHD ) |
|
119 { |
|
120 WRITELOG( "CHarvesterRtpPlugin::Harvest()" ); |
|
121 CMdEObject& mdeObject = aHD->MdeObject(); |
|
122 |
|
123 CHarvesterRtpClipDetails* clipDetails = CHarvesterRtpClipDetails::NewL(); |
|
124 CleanupStack::PushL( clipDetails ); |
|
125 |
|
126 TRAPD( error, GatherDataL( mdeObject, *clipDetails ) ); |
|
127 if ( error == KErrNone || error == KErrCompletion ) |
|
128 { |
|
129 TBool isNewObject( mdeObject.Id() == 0 ); |
|
130 |
|
131 if ( isNewObject || mdeObject.Placeholder() ) |
|
132 { |
|
133 TRAP( error, HandleObjectPropertiesL( *aHD, *clipDetails, ETrue ) ); |
|
134 mdeObject.SetPlaceholder( EFalse ); |
|
135 } |
|
136 else |
|
137 { |
|
138 TRAP( error, HandleObjectPropertiesL( *aHD, *clipDetails, EFalse ) ); |
|
139 } |
|
140 |
|
141 if ( error != KErrNone ) |
|
142 { |
|
143 WRITELOG1( "CHarvesterWMVPlugin::HarvestL() - Handling object failed: ", error ); |
|
144 } |
|
145 } |
|
146 else |
|
147 { |
|
148 TInt convertedError = KErrNone; |
|
149 MdsUtils::ConvertTrapError( error, convertedError ); |
|
150 aHD->SetErrorCode( convertedError ); |
|
151 } |
|
152 CleanupStack::PopAndDestroy( clipDetails ); |
|
153 } |
|
154 |
|
155 // --------------------------------------------------------------------------- |
|
156 // Gather metadata |
|
157 // --------------------------------------------------------------------------- |
|
158 // |
|
159 void CHarvesterRtpPlugin::GatherDataL( CMdEObject& aMetadataObject, CHarvesterRtpClipDetails& aClipDetails ) |
|
160 { |
|
161 WRITELOG( "CHarvesterRtpPlugin - GatherDataL()" ); |
|
162 |
|
163 const TDesC& uri = aMetadataObject.Uri(); |
|
164 |
|
165 HBufC8* buffer = HBufC8::NewLC( KFileBufferSize ); |
|
166 TPtr8 bufferPtr( buffer->Des() ); |
|
167 |
|
168 RFile64 file; |
|
169 CleanupClosePushL( file ); |
|
170 |
|
171 User::LeaveIfError( file.Open( iFs, uri, EFileShareAny ) ); |
|
172 |
|
173 TEntry* entry = new (ELeave) TEntry(); |
|
174 CleanupStack::PushL( entry ); |
|
175 User::LeaveIfError( iFs.Entry( uri, *entry ) ); |
|
176 aClipDetails.iFileSize = (TUint)entry->iSize; |
|
177 aClipDetails.iModifiedDate = entry->iModified; |
|
178 CleanupStack::PopAndDestroy( entry ); // entry |
|
179 |
|
180 User::LeaveIfError( file.Read( bufferPtr, KFileBufferSize ) ); |
|
181 User::LeaveIfError( RecognizeFile( uri, *buffer, aClipDetails ) ); |
|
182 User::LeaveIfError( CheckIfMimeSupported( aClipDetails.iMimeType ) ); |
|
183 |
|
184 CHarvesterRtpMetaDataReader* mdr = CHarvesterRtpMetaDataReader::NewL( buffer ); |
|
185 CleanupStack::PushL( mdr ); |
|
186 |
|
187 WRITELOG( "CHarvesterRtpPlugin - GatherDataL() ---> found metadata!" ); |
|
188 mdr->GetClipDetailsL( aClipDetails ); |
|
189 |
|
190 CleanupStack::PopAndDestroy( mdr ); // mdr |
|
191 CleanupStack::PopAndDestroy( &file ); // file |
|
192 CleanupStack::PopAndDestroy( buffer ); // buffer |
|
193 } |
|
194 |
|
195 // ----------------------------------------------------------------------------- |
|
196 // Runs recognizers on the given file to determine its mime type |
|
197 // ----------------------------------------------------------------------------- |
|
198 // |
|
199 TInt CHarvesterRtpPlugin::RecognizeFile( |
|
200 const TDesC& aFilePath, |
|
201 const TDesC8& aFileBuffer, |
|
202 CHarvesterRtpClipDetails& aClipDetails ) |
|
203 { |
|
204 WRITELOG( "CHarvesterRtpPlugin::RecognizeFile()" ); |
|
205 TInt err( KErrNone ); |
|
206 |
|
207 RApaLsSession apaSession; |
|
208 err = apaSession.Connect(); |
|
209 if ( err == KErrNone ) |
|
210 { |
|
211 TDataRecognitionResult result; |
|
212 err = apaSession.RecognizeData( aFilePath, aFileBuffer, result ); |
|
213 if ( result.iConfidence >= CApaDataRecognizerType::EProbable ) |
|
214 { |
|
215 aClipDetails.iMimeType = result.iDataType.Des(); |
|
216 WRITELOG1( "CHarvesterRtpPlugin - Mime type: %S", &aClipDetails.iMimeType ); |
|
217 } |
|
218 |
|
219 apaSession.Close(); |
|
220 } |
|
221 |
|
222 return err; |
|
223 } |
|
224 |
|
225 ///--------------------------------------------------------------------------- |
|
226 /// Check if mime type is supported |
|
227 ///--------------------------------------------------------------------------- |
|
228 // |
|
229 TInt CHarvesterRtpPlugin::CheckIfMimeSupported( const TDesC& aMimeBuf ) |
|
230 { |
|
231 if ( MdsUtils::Compare( KRtpClipMimetype, aMimeBuf ) == 0 ) |
|
232 { |
|
233 WRITELOG( "CHarvesterRtpPlugin - Mime type supported"); |
|
234 return KErrNone; |
|
235 } |
|
236 |
|
237 WRITELOG( "CHarvesterRtpPlugin - Mime type not supported"); |
|
238 return KErrNotSupported; |
|
239 } |
|
240 |
|
241 // --------------------------------------------------------------------------- |
|
242 // Add object properties |
|
243 // --------------------------------------------------------------------------- |
|
244 // |
|
245 void CHarvesterRtpPlugin::HandleObjectPropertiesL( |
|
246 CHarvesterData& aHD, |
|
247 CHarvesterRtpClipDetails& aClipDetails, |
|
248 TBool aIsAdd) |
|
249 { |
|
250 WRITELOG( "CHarvesterRtpPlugin::HandleObjectPropertiesL()" ); |
|
251 |
|
252 CMdEObject& mdeObject = aHD.MdeObject(); |
|
253 |
|
254 if( !iPropDefs ) |
|
255 { |
|
256 CMdEObjectDef& objectDef = mdeObject.Def(); |
|
257 iPropDefs = CHarvesterRtpPluginPropertyDefs::NewL( objectDef ); |
|
258 } |
|
259 |
|
260 TTimeIntervalSeconds timeOffset = User::UTCOffset(); |
|
261 TTime localModifiedTime = aClipDetails.iModifiedDate + timeOffset; |
|
262 |
|
263 if( ! mdeObject.Placeholder() ) |
|
264 { |
|
265 // Creation date of media file |
|
266 CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, |
|
267 *iPropDefs->iCreationDatePropertyDef, &localModifiedTime, aIsAdd ); |
|
268 // Last modified date |
|
269 CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, |
|
270 *iPropDefs->iLastModifiedDatePropertyDef, &aClipDetails.iModifiedDate, aIsAdd ); |
|
271 // File size |
|
272 CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, |
|
273 *iPropDefs->iSizePropertyDef, &aClipDetails.iFileSize, aIsAdd ); |
|
274 } |
|
275 |
|
276 // Title (is set from URI by default) |
|
277 if ( aClipDetails.iTitle.Length() > 0 ) |
|
278 { |
|
279 CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, |
|
280 *iPropDefs->iTitlePropertyDef, &aClipDetails.iTitle, EFalse ); |
|
281 } |
|
282 |
|
283 // Mime Type |
|
284 CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, |
|
285 *iPropDefs->iItemTypePropertyDef, &aClipDetails.iMimeType, aIsAdd ); |
|
286 |
|
287 // Capture date |
|
288 CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, |
|
289 *iPropDefs->iCaptureDatePropertyDef, &localModifiedTime, aIsAdd ); |
|
290 |
|
291 // Duration |
|
292 CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, |
|
293 *iPropDefs->iDurationPropertyDef, &aClipDetails.iDuration, aIsAdd ); |
|
294 |
|
295 //Save these if video center videostorage available |
|
296 //AgeProfile |
|
297 CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, |
|
298 *iPropDefs->iAgeProfilePropertyDef, &aClipDetails.iParental, aIsAdd ); |
|
299 |
|
300 //VideoFlags |
|
301 TUint32 flags = 0; |
|
302 |
|
303 //always set clip type as recording |
|
304 flags |= EIptvMyVideosVideoTypeRecording; |
|
305 |
|
306 if ( aClipDetails.iRecOngoing ) |
|
307 { |
|
308 //Recording ongoing |
|
309 //Otherwise assuming that recording has completed |
|
310 flags |= EIptvMyVideosVideoIsRecording; |
|
311 } |
|
312 |
|
313 if ( aClipDetails.iRecFailed ) |
|
314 { |
|
315 //Recording failed |
|
316 flags |= EIptvMyVideosVideoRecFailed; |
|
317 } |
|
318 |
|
319 if ( aClipDetails.iQuality <= KPartiallyFailedLimit ) |
|
320 { |
|
321 //Clip partially failed |
|
322 flags |= EIptvMyVideosVideoRecPartiallyFailed; |
|
323 } |
|
324 |
|
325 CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, |
|
326 *iPropDefs->iRecordingFlagsPropertyDef, &flags, aIsAdd ); |
|
327 } |