|
1 /* |
|
2 * Copyright (c) 2006 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: Recognizer for playlist files. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDES |
|
21 #include <f32file.h> |
|
22 #include <barsread.h> |
|
23 #include <ecom/implementationproxy.h> |
|
24 #include <mpxplaylistenginedefs.h> |
|
25 #include <mpxplaylistenginedefs.hrh> |
|
26 #include <mpxlog.h> |
|
27 #include <mpxpluginhandlerbase.h> |
|
28 #include <mpxpluginhandlerobserver.h> |
|
29 #include "mpxplaylistrecognizer.h" |
|
30 |
|
31 |
|
32 // LOCAL CONSTANTS AND MACROS |
|
33 const TInt KExtLength = 4; |
|
34 |
|
35 // MIME type of the playlist. |
|
36 _LIT8(KPlaylistMimeType, "playlist/mpegurl"); |
|
37 |
|
38 // ============================ MEMBER FUNCTIONS =============================== |
|
39 |
|
40 // ----------------------------------------------------------------------------- |
|
41 // CMPXPlaylistRecognizer::CMPXPlaylistRecognizer() |
|
42 // C++ default constructor can NOT contain any code, that |
|
43 // might leave. |
|
44 // Call base constructor with the recognizer's UID and confidence level |
|
45 // ----------------------------------------------------------------------------- |
|
46 CMPXPlaylistRecognizer::CMPXPlaylistRecognizer() |
|
47 : CApaDataRecognizerType(TUid::Uid(KMPXPlaylistRecognizerDllUid), |
|
48 CApaDataRecognizerType::EHigh) |
|
49 { |
|
50 } |
|
51 |
|
52 // ----------------------------------------------------------------------------- |
|
53 // CMPXPlaylistRecognizer::ConstructL() |
|
54 // Symbian 2nd phase constructor can leave. |
|
55 // ----------------------------------------------------------------------------- |
|
56 void CMPXPlaylistRecognizer::ConstructL() |
|
57 { |
|
58 // Set the number of data (MIME) types supported by this recognizer. |
|
59 iCountDataTypes = 1; |
|
60 |
|
61 // instantiate a plugin hanlder that manages playlist plugins. |
|
62 iPluginHandler = new(ELeave)CMPXPluginHandlerBase( |
|
63 TUid::Uid(KMPXPlaylistInterfaceUid), |
|
64 CMPXPluginHandlerBase::ESelectionType, EMPXPlaylistTypeM3U, |
|
65 *this); |
|
66 } |
|
67 |
|
68 // ----------------------------------------------------------------------------- |
|
69 // CMPXPlaylistRecognizer::NewL() |
|
70 // Two-phased constructor. |
|
71 // ----------------------------------------------------------------------------- |
|
72 CMPXPlaylistRecognizer* CMPXPlaylistRecognizer::NewL() |
|
73 { |
|
74 MPX_DEBUG1("CMPXPlaylistRecognizer::NewL"); |
|
75 CMPXPlaylistRecognizer* self = new (ELeave) CMPXPlaylistRecognizer(); |
|
76 CleanupStack::PushL(self); |
|
77 self->ConstructL(); |
|
78 CleanupStack::Pop(self); |
|
79 return self; |
|
80 } |
|
81 |
|
82 // ----------------------------------------------------------------------------- |
|
83 // Destructor |
|
84 // ----------------------------------------------------------------------------- |
|
85 CMPXPlaylistRecognizer::~CMPXPlaylistRecognizer() |
|
86 { |
|
87 delete iPluginHandler; |
|
88 } |
|
89 |
|
90 // ----------------------------------------------------------------------------- |
|
91 // CMPXPlaylistRecognizer::SupportedDataTypeL |
|
92 // Return the MimeType of the DataType depending on |
|
93 // mime type of the file |
|
94 // ----------------------------------------------------------------------------- |
|
95 TDataType CMPXPlaylistRecognizer::SupportedDataTypeL(TInt aIndex ) const |
|
96 { |
|
97 MPX_DEBUG2("CMPXPlaylistRecognizer::SupportedDataTypeL [%d]", aIndex); |
|
98 |
|
99 TDataType dataType; |
|
100 switch ( aIndex ) |
|
101 { |
|
102 case 0: |
|
103 dataType = TDataType(KPlaylistMimeType); |
|
104 break; |
|
105 default: |
|
106 User::Leave(KErrArgument); |
|
107 break; |
|
108 } |
|
109 return dataType; |
|
110 } |
|
111 |
|
112 // ----------------------------------------------------------------------------- |
|
113 // CMPXPlaylistRecognizer::PreferredBufSize() |
|
114 // Return the supposed minimum buffer size we need to |
|
115 // successfully recognize the data |
|
116 // ----------------------------------------------------------------------------- |
|
117 TUint CMPXPlaylistRecognizer::PreferredBufSize() |
|
118 { |
|
119 return 0; |
|
120 } |
|
121 |
|
122 // ----------------------------------------------------------------------------- |
|
123 // CMPXPlaylistRecognizer::DoRecognizeL |
|
124 // Attempt to recognize the data |
|
125 // this recognizer only attempts to match the data and/or file extension |
|
126 // |
|
127 // NB if the file is not recognized, this function should NOT leave : |
|
128 // it should instead set iConfidence = ENotRecognized and return |
|
129 // the function should only leave if there is an out-of-memory condition |
|
130 // ----------------------------------------------------------------------------- |
|
131 void CMPXPlaylistRecognizer::DoRecognizeL( |
|
132 const TDesC& aName, |
|
133 const TDesC8& /*aBuffer*/ ) |
|
134 { |
|
135 MPX_DEBUG2("CMPXPlaylistRecognizer::DoRecognizeL: aName = %S", &aName); |
|
136 |
|
137 // assume match will fail |
|
138 iConfidence = CApaDataRecognizerType::ENotRecognized; |
|
139 if ( aName.Length() < KExtLength ) |
|
140 { |
|
141 MPX_DEBUG1("CMPXPlaylistRecognizer::DoRecognizeL - Ext not present"); |
|
142 return; |
|
143 } |
|
144 |
|
145 // get a list of supported extension from playlist plugin handler |
|
146 iPluginHandler->CreatePluginListL(); |
|
147 CDesCArray* supportedExtensions = |
|
148 iPluginHandler->SupportedExtensionsL(); |
|
149 |
|
150 // |
|
151 // determine if the given filename contains an extension that's listed |
|
152 // as supported |
|
153 // |
|
154 TInt count = supportedExtensions->Count(); |
|
155 for ( TInt i = 0; i < count; i++ ) |
|
156 { |
|
157 TPtrC extension = (*supportedExtensions)[i]; |
|
158 |
|
159 if ( aName.Right( extension.Length() ).CompareF(extension) == 0 ) |
|
160 { |
|
161 MPX_DEBUG1("CMPXPlaylistRecognizer::DoRecognizeL - Possible match"); |
|
162 iDataType = TDataType(KPlaylistMimeType); |
|
163 iConfidence = ECertain; |
|
164 break; |
|
165 } |
|
166 } |
|
167 |
|
168 delete supportedExtensions; |
|
169 } |
|
170 |
|
171 // ----------------------------------------------------------------------------- |
|
172 // CMPXPlaylistRecognizer::HandlePluginHandlerEvent |
|
173 // ----------------------------------------------------------------------------- |
|
174 // |
|
175 void CMPXPlaylistRecognizer::HandlePluginHandlerEvent( |
|
176 TPluginHandlerEvents /* aEvent */, |
|
177 const TUid& /* aPluginUid */, |
|
178 TBool /* aLoaded */, |
|
179 TInt /* aData */) |
|
180 { |
|
181 // Do nothing |
|
182 } |
|
183 |
|
184 // ========================== OTHER EXPORTED FUNCTIONS ========================= |
|
185 // ----------------------------------------------------------------------------- |
|
186 // provides an array that maps a UID for each implementation to its respective |
|
187 // creation function |
|
188 // ----------------------------------------------------------------------------- |
|
189 const TImplementationProxy ImplementationTable[] = |
|
190 { |
|
191 IMPLEMENTATION_PROXY_ENTRY(KMPXPlaylistRecognizerImplUid, CMPXPlaylistRecognizer::NewL) |
|
192 }; |
|
193 |
|
194 // ----------------------------------------------------------------------------- |
|
195 // returns the proxy of implementations |
|
196 // ----------------------------------------------------------------------------- |
|
197 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount) |
|
198 { |
|
199 aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy); |
|
200 return ImplementationTable; |
|
201 } |
|
202 |
|
203 // End of file |
|
204 |
|
205 |