1 | /* This file is part of the KDE project.
|
---|
2 |
|
---|
3 | Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 |
|
---|
5 | This library is free software: you can redistribute it and/or modify
|
---|
6 | it under the terms of the GNU Lesser General Public License as published by
|
---|
7 | the Free Software Foundation, either version 2.1 or 3 of the License.
|
---|
8 |
|
---|
9 | This library is distributed in the hope that it will be useful,
|
---|
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
12 | GNU Lesser General Public License for more details.
|
---|
13 |
|
---|
14 | You should have received a copy of the GNU Lesser General Public License
|
---|
15 | along with this library. If not, see <http://www.gnu.org/licenses/>.
|
---|
16 |
|
---|
17 | */
|
---|
18 |
|
---|
19 | #include "utils.h"
|
---|
20 | #include <e32std.h>
|
---|
21 | #include <mmf/common/mmferrors.h>
|
---|
22 |
|
---|
23 | QT_BEGIN_NAMESPACE
|
---|
24 |
|
---|
25 | using namespace Phonon;
|
---|
26 | using namespace Phonon::MMF;
|
---|
27 |
|
---|
28 | /*! \namespace Phonon::MMF::Utils
|
---|
29 | \internal
|
---|
30 | */
|
---|
31 |
|
---|
32 | /*! \class Phonon::MMF::TTraceContext
|
---|
33 | \internal
|
---|
34 | */
|
---|
35 |
|
---|
36 | /*! \enum Phonon::MMF::PanicCode
|
---|
37 | \internal
|
---|
38 | */
|
---|
39 |
|
---|
40 | /*! \enum Phonon::MMF::TTraceCategory
|
---|
41 | \internal
|
---|
42 | */
|
---|
43 |
|
---|
44 | /*! \enum Phonon::MMF::MediaType
|
---|
45 | \internal
|
---|
46 | */
|
---|
47 |
|
---|
48 | _LIT(PanicCategory, "Phonon::MMF");
|
---|
49 |
|
---|
50 | void MMF::Utils::panic(PanicCode code)
|
---|
51 | {
|
---|
52 | User::Panic(PanicCategory, code);
|
---|
53 | }
|
---|
54 |
|
---|
55 | _LIT(KMimePrefixAudio, "audio/");
|
---|
56 | _LIT(KMimePrefixVideo, "video/");
|
---|
57 | _LIT(KMimeSDP, "application/sdp");
|
---|
58 |
|
---|
59 | enum ConstantStringLengths {
|
---|
60 | KMimePrefixLength = 6, // either "audio/" or "video/",
|
---|
61 | KMimeSDPLength = 15 // "application/sdp"
|
---|
62 | };
|
---|
63 |
|
---|
64 | MMF::MediaType MMF::Utils::mimeTypeToMediaType(const TDesC& mimeType)
|
---|
65 | {
|
---|
66 | if (mimeType.Left(KMimePrefixLength).Compare(KMimePrefixAudio) == 0) {
|
---|
67 | return MediaTypeAudio;
|
---|
68 | } else if (mimeType.Left(KMimePrefixLength).Compare(KMimePrefixVideo) == 0 ||
|
---|
69 | mimeType.Left(KMimeSDPLength).Compare(KMimeSDP) == 0) {
|
---|
70 | return MediaTypeVideo;
|
---|
71 | } else
|
---|
72 | return MediaTypeUnknown;
|
---|
73 | }
|
---|
74 |
|
---|
75 | QString MMF::Utils::symbianErrorToString(int errorCode)
|
---|
76 | {
|
---|
77 | /**
|
---|
78 | * Here we translate only the error codes which are likely to be
|
---|
79 | * meaningful to the user. For example, when an error occurs
|
---|
80 | * during opening of a media file, displaying "not found" or
|
---|
81 | * "permission denied" is informative. On the other hand,
|
---|
82 | * differentiating between KErrGeneral and KErrArgument at the UI
|
---|
83 | * level does not make sense.
|
---|
84 | */
|
---|
85 | switch (errorCode)
|
---|
86 | {
|
---|
87 | // System-wide errors
|
---|
88 | case KErrNone:
|
---|
89 | return tr("No error");
|
---|
90 | case KErrNotFound:
|
---|
91 | return tr("Not found");
|
---|
92 | case KErrNoMemory:
|
---|
93 | return tr("Out of memory");
|
---|
94 | case KErrNotSupported:
|
---|
95 | return tr("Not supported");
|
---|
96 | case KErrOverflow:
|
---|
97 | return tr("Overflow");
|
---|
98 | case KErrUnderflow:
|
---|
99 | return tr("Underflow");
|
---|
100 | case KErrAlreadyExists:
|
---|
101 | return tr("Already exists");
|
---|
102 | case KErrPathNotFound:
|
---|
103 | return tr("Path not found");
|
---|
104 | case KErrInUse:
|
---|
105 | return tr("In use");
|
---|
106 | case KErrNotReady:
|
---|
107 | return tr("Not ready");
|
---|
108 | case KErrAccessDenied:
|
---|
109 | return tr("Access denied");
|
---|
110 | case KErrCouldNotConnect:
|
---|
111 | return tr("Could not connect");
|
---|
112 | case KErrDisconnected:
|
---|
113 | return tr("Disconnected");
|
---|
114 | case KErrPermissionDenied:
|
---|
115 | return tr("Permission denied");
|
---|
116 |
|
---|
117 | // Multimedia framework errors
|
---|
118 | case KErrMMNotEnoughBandwidth:
|
---|
119 | return tr("Insufficient bandwidth");
|
---|
120 | case KErrMMSocketServiceNotFound:
|
---|
121 | case KErrMMServerSocket:
|
---|
122 | return tr("Network unavailable");
|
---|
123 | case KErrMMNetworkRead:
|
---|
124 | case KErrMMNetworkWrite:
|
---|
125 | case KErrMMUDPReceive:
|
---|
126 | return tr("Network communication error");
|
---|
127 | case KErrMMServerNotSupported:
|
---|
128 | return tr("Streaming not supported");
|
---|
129 | case KErrMMServerAlert:
|
---|
130 | return tr("Server alert");
|
---|
131 | case KErrMMInvalidProtocol:
|
---|
132 | return tr("Invalid protocol");
|
---|
133 | case KErrMMInvalidURL:
|
---|
134 | return tr("Invalid URL");
|
---|
135 | case KErrMMMulticast:
|
---|
136 | return tr("Multicast error");
|
---|
137 | case KErrMMProxyServer:
|
---|
138 | case KErrMMProxyServerConnect:
|
---|
139 | return tr("Proxy server error");
|
---|
140 | case KErrMMProxyServerNotSupported:
|
---|
141 | return tr("Proxy server not supported");
|
---|
142 | case KErrMMAudioDevice:
|
---|
143 | return tr("Audio output error");
|
---|
144 | case KErrMMVideoDevice:
|
---|
145 | return tr("Video output error");
|
---|
146 | case KErrMMDecoder:
|
---|
147 | return tr("Decoder error");
|
---|
148 | case KErrMMPartialPlayback:
|
---|
149 | return tr("Audio or video components could not be played");
|
---|
150 | case KErrMMDRMNotAuthorized:
|
---|
151 | return tr("DRM error");
|
---|
152 |
|
---|
153 | /*
|
---|
154 | // We don't use QoS settings
|
---|
155 | case KErrMMQosLowBandwidth:
|
---|
156 | case KErrMMQosUnsupportedTrafficClass:
|
---|
157 | case KErrMMQosPoorTrafficClass:
|
---|
158 | case KErrMMQosUnsupportedParameters:
|
---|
159 | case KErrMMQosPoorParameters:
|
---|
160 | case KErrMMQosNotSupported:
|
---|
161 | */
|
---|
162 |
|
---|
163 | // Catch-all for errors other than those above
|
---|
164 | default:
|
---|
165 | {
|
---|
166 | return tr("Unknown error (%1)").arg(errorCode);
|
---|
167 | }
|
---|
168 | }
|
---|
169 | }
|
---|
170 |
|
---|
171 | #ifndef QT_NO_DEBUG
|
---|
172 |
|
---|
173 | #include <hal.h>
|
---|
174 | #include <hal_data.h>
|
---|
175 | #include <gdi.h>
|
---|
176 | #include <eikenv.h>
|
---|
177 |
|
---|
178 | struct TScreenInfo
|
---|
179 | {
|
---|
180 | int width;
|
---|
181 | int height;
|
---|
182 | int bpp;
|
---|
183 | const char* address;
|
---|
184 | int initialOffset;
|
---|
185 | int lineOffset;
|
---|
186 | TDisplayMode displayMode;
|
---|
187 | };
|
---|
188 |
|
---|
189 | static void getScreenInfoL(TScreenInfo& info)
|
---|
190 | {
|
---|
191 | info.displayMode = CEikonEnv::Static()->ScreenDevice()->DisplayMode();
|
---|
192 |
|
---|
193 | // Then we must set these as the input parameter
|
---|
194 | info.width = info.displayMode;
|
---|
195 | info.height = info.displayMode;
|
---|
196 | info.initialOffset = info.displayMode;
|
---|
197 | info.lineOffset = info.displayMode;
|
---|
198 | info.bpp = info.displayMode;
|
---|
199 |
|
---|
200 | User::LeaveIfError( HAL::Get(HALData::EDisplayXPixels, info.width) );
|
---|
201 | User::LeaveIfError( HAL::Get(HALData::EDisplayYPixels, info.width) );
|
---|
202 |
|
---|
203 | int address;
|
---|
204 | User::LeaveIfError( HAL::Get(HALData::EDisplayMemoryAddress, address) );
|
---|
205 | info.address = reinterpret_cast<const char*>(address);
|
---|
206 |
|
---|
207 | User::LeaveIfError( HAL::Get(HALData::EDisplayOffsetToFirstPixel, info.initialOffset) );
|
---|
208 |
|
---|
209 | User::LeaveIfError( HAL::Get(HALData::EDisplayOffsetBetweenLines, info.lineOffset) );
|
---|
210 |
|
---|
211 | User::LeaveIfError( HAL::Get(HALData::EDisplayBitsPerPixel, info.bpp) );
|
---|
212 | }
|
---|
213 |
|
---|
214 |
|
---|
215 | QColor MMF::Utils::getScreenPixel(const QPoint& pos)
|
---|
216 | {
|
---|
217 | TScreenInfo info;
|
---|
218 | TRAPD(err, getScreenInfoL(info));
|
---|
219 | QColor pixel;
|
---|
220 | if (err == KErrNone and pos.x() < info.width and pos.y() < info.height)
|
---|
221 | {
|
---|
222 | const int bytesPerPixel = info.bpp / 8;
|
---|
223 | Q_ASSERT(bytesPerPixel >= 3);
|
---|
224 |
|
---|
225 | const int stride = (info.width * bytesPerPixel) + info.lineOffset;
|
---|
226 |
|
---|
227 | const char* ptr =
|
---|
228 | info.address
|
---|
229 | + info.initialOffset
|
---|
230 | + pos.y() * stride
|
---|
231 | + pos.x() * bytesPerPixel;
|
---|
232 |
|
---|
233 | // BGRA
|
---|
234 | pixel.setBlue(*ptr++);
|
---|
235 | pixel.setGreen(*ptr++);
|
---|
236 | pixel.setRed(*ptr++);
|
---|
237 |
|
---|
238 | if (bytesPerPixel == 4)
|
---|
239 | pixel.setAlpha(*ptr++);
|
---|
240 | }
|
---|
241 | return pixel;
|
---|
242 | }
|
---|
243 |
|
---|
244 | // Debugging: for debugging video visibility
|
---|
245 | void MMF::Utils::dumpScreenPixelSample()
|
---|
246 | {
|
---|
247 | for (int i=0; i<20; ++i) {
|
---|
248 | const QPoint pos(i*10, i*10);
|
---|
249 | const QColor pixel = Utils::getScreenPixel(pos);
|
---|
250 | RDebug::Printf(
|
---|
251 | "Phonon::MMF::Utils::dumpScreenPixelSample %d %d = %d %d %d %d",
|
---|
252 | pos.x(), pos.y(), pixel.red(), pixel.green(), pixel.blue(), pixel.alpha()
|
---|
253 | );
|
---|
254 | }
|
---|
255 | }
|
---|
256 |
|
---|
257 | #endif // _DEBUG
|
---|
258 |
|
---|
259 | QT_END_NAMESPACE
|
---|
260 |
|
---|