summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/phonon/mmf/utils.cpp
blob: 2d17bd262d6440dd195bbc2627f1dbfd3e4f81f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
/*  This file is part of the KDE project.

Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).

This library is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2.1 or 3 of the License.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with this library.  If not, see <http://www.gnu.org/licenses/>.

*/

#include "utils.h"
#include <e32std.h>
#include <mmf/common/mmferrors.h>

QT_BEGIN_NAMESPACE

using namespace Phonon;
using namespace Phonon::MMF;

/*! \namespace Phonon::MMF::Utils
  \internal
*/

/*! \class Phonon::MMF::TTraceContext
  \internal
*/

/*! \enum Phonon::MMF::PanicCode
 \internal
*/

/*! \enum Phonon::MMF::TTraceCategory
 \internal
*/

/*! \enum Phonon::MMF::MediaType
 \internal
*/

_LIT(PanicCategory, "Phonon::MMF");

void MMF::Utils::panic(PanicCode code)
{
    User::Panic(PanicCategory, code);
}


static const TInt KMimePrefixLength = 6; // either "audio/" or "video/"
_LIT(KMimePrefixAudio, "audio/");
_LIT(KMimePrefixVideo, "video/");

MMF::MediaType MMF::Utils::mimeTypeToMediaType(const TDesC& mimeType)
{
    MediaType result = MediaTypeUnknown;

    if (mimeType.Left(KMimePrefixLength).Compare(KMimePrefixAudio) == 0) {
        result = MediaTypeAudio;
    } else if (mimeType.Left(KMimePrefixLength).Compare(KMimePrefixVideo) == 0) {
        result = MediaTypeVideo;
    }

    return result;
}

QString MMF::Utils::symbianErrorToString(int errorCode)
{
    /**
     * Here we translate only the error codes which are likely to be
     * meaningful to the user.  For example, when an error occurs
     * during opening of a media file, displaying "not found" or
     * "permission denied" is informative.  On the other hand,
     * differentiating between KErrGeneral and KErrArgument at the UI
     * level does not make sense.
     */
    switch (errorCode)
    {
    // System-wide errors
    case KErrNone:
        return tr("No error");
    case KErrNotFound:
        return tr("Not found");
    case KErrNoMemory:
        return tr("Out of memory");
    case KErrNotSupported:
        return tr("Not supported");
    case KErrOverflow:
        return tr("Overflow");
    case KErrUnderflow:
        return tr("Underflow");
    case KErrAlreadyExists:
        return tr("Already exists");
    case KErrPathNotFound:
        return tr("Path not found");
    case KErrInUse:
        return tr("In use");
    case KErrNotReady:
        return tr("Not ready");
    case KErrAccessDenied:
        return tr("Access denied");
    case KErrCouldNotConnect:
        return tr("Could not connect");
    case KErrDisconnected:
        return tr("Disconnected");
    case KErrPermissionDenied:
        return tr("Permission denied");

    // Multimedia framework errors
    case KErrMMNotEnoughBandwidth:
        return tr("Insufficient bandwidth");
    case KErrMMSocketServiceNotFound:
    case KErrMMServerSocket:
        return tr("Network unavailable");
    case KErrMMNetworkRead:
    case KErrMMNetworkWrite:
    case KErrMMUDPReceive:
        return tr("Network communication error");
    case KErrMMServerNotSupported:
        return tr("Streaming not supported");
    case KErrMMServerAlert:
        return tr("Server alert");
    case KErrMMInvalidProtocol:
        return tr("Invalid protocol");
    case KErrMMInvalidURL:
        return tr("Invalid URL");
    case KErrMMMulticast:
        return tr("Multicast error");
    case KErrMMProxyServer:
    case KErrMMProxyServerConnect:
        return tr("Proxy server error");
    case KErrMMProxyServerNotSupported:
        return tr("Proxy server not supported");
    case KErrMMAudioDevice:
        return tr("Audio output error");
    case KErrMMVideoDevice:
        return tr("Video output error");
    case KErrMMDecoder:
        return tr("Decoder error");
    case KErrMMPartialPlayback:
        return tr("Audio or video components could not be played");
    case KErrMMDRMNotAuthorized:
        return tr("DRM error");

    /*
    // We don't use QoS settings
    case KErrMMQosLowBandwidth:
    case KErrMMQosUnsupportedTrafficClass:
    case KErrMMQosPoorTrafficClass:
    case KErrMMQosUnsupportedParameters:
    case KErrMMQosPoorParameters:
    case KErrMMQosNotSupported:
    */

    // Catch-all for errors other than those above
    default:
    {
        return tr("Unknown error (%1)").arg(errorCode);
    }
    }
}

#ifndef QT_NO_DEBUG

#include <hal.h>
#include <hal_data.h>
#include <gdi.h>
#include <eikenv.h>

struct TScreenInfo
{
    int width;
    int height;
    int bpp;
    const char* address;
    int initialOffset;
    int lineOffset;
    TDisplayMode displayMode;
};

static void getScreenInfoL(TScreenInfo& info)
{
    info.displayMode = CEikonEnv::Static()->ScreenDevice()->DisplayMode();

    // Then we must set these as the input parameter
    info.width = info.displayMode;
    info.height = info.displayMode;
    info.initialOffset = info.displayMode;
    info.lineOffset = info.displayMode;
    info.bpp = info.displayMode;

    User::LeaveIfError( HAL::Get(HALData::EDisplayXPixels, info.width) );
    User::LeaveIfError( HAL::Get(HALData::EDisplayYPixels, info.width) );

    int address;
    User::LeaveIfError( HAL::Get(HALData::EDisplayMemoryAddress, address) );
    info.address = reinterpret_cast<const char*>(address);

    User::LeaveIfError( HAL::Get(HALData::EDisplayOffsetToFirstPixel, info.initialOffset) );

    User::LeaveIfError( HAL::Get(HALData::EDisplayOffsetBetweenLines, info.lineOffset) );

    User::LeaveIfError( HAL::Get(HALData::EDisplayBitsPerPixel, info.bpp) );
}


QColor MMF::Utils::getScreenPixel(const QPoint& pos)
{
    TScreenInfo info;
    TRAPD(err, getScreenInfoL(info));
    QColor pixel;
    if (err == KErrNone and pos.x() < info.width and pos.y() < info.height)
    {
        const int bytesPerPixel = info.bpp / 8;
        Q_ASSERT(bytesPerPixel >= 3);

        const int stride = (info.width * bytesPerPixel) + info.lineOffset;

        const char* ptr =
                info.address
            +    info.initialOffset
            +    pos.y() * stride
            +    pos.x() * bytesPerPixel;

        // BGRA
        pixel.setBlue(*ptr++);
        pixel.setGreen(*ptr++);
        pixel.setRed(*ptr++);

        if (bytesPerPixel == 4)
            pixel.setAlpha(*ptr++);
    }
    return pixel;
}

// Debugging: for debugging video visibility
void MMF::Utils::dumpScreenPixelSample()
{
    for (int i=0; i<20; ++i) {
        const QPoint pos(i*10, i*10);
        const QColor pixel = Utils::getScreenPixel(pos);
        RDebug::Printf(
            "Phonon::MMF::Utils::dumpScreenPixelSample %d %d = %d %d %d %d",
            pos.x(), pos.y(), pixel.red(), pixel.green(), pixel.blue(), pixel.alpha()
        );
    }
}

#endif // _DEBUG

QT_END_NAMESPACE