summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/phonon/mmf/audioplayer.cpp
blob: f49e89892326b63da535075d9d07c18efd4a652c (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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
/*  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 <QUrl>

#include "audioplayer.h"
#include "utils.h"

QT_BEGIN_NAMESPACE

using namespace Phonon;
using namespace Phonon::MMF;

/*! \class MMF::AudioPlayer
  \internal
*/

//-----------------------------------------------------------------------------
// Constructor / destructor
//-----------------------------------------------------------------------------

MMF::AudioPlayer::AudioPlayer(MediaObject *parent, const AbstractPlayer *player)
        :   AbstractMediaPlayer(parent, player)
        ,   m_totalTime(0)
{
    construct();
}

void MMF::AudioPlayer::construct()
{
    TRACE_CONTEXT(AudioPlayer::AudioPlayer, EAudioApi);
    TRACE_ENTRY_0();

    NativePlayer *player = 0;
    QT_TRAP_THROWING(player = NativePlayer::NewL(*this, 0, EMdaPriorityPreferenceNone));
    m_player.reset(player);
    m_player->RegisterForAudioLoadingNotification(*this);

    TRACE_EXIT_0();
}

MMF::AudioPlayer::~AudioPlayer()
{
    TRACE_CONTEXT(AudioPlayer::~AudioPlayer, EAudioApi);
    TRACE_ENTRY_0();

    TRACE_EXIT_0();
}

MMF::AudioPlayer::NativePlayer *MMF::AudioPlayer::nativePlayer() const
{
    return m_player.data();
}

//-----------------------------------------------------------------------------
// Public API
//-----------------------------------------------------------------------------

void MMF::AudioPlayer::doPlay()
{
    m_player->Play();
}

void MMF::AudioPlayer::doPause()
{
    m_player->Pause();
}

void MMF::AudioPlayer::doStop()
{
    m_player->Stop();
}

void MMF::AudioPlayer::doSeek(qint64 ms)
{
    m_player->SetPosition(TTimeIntervalMicroSeconds(ms * 1000));
}

int MMF::AudioPlayer::setDeviceVolume(int mmfVolume)
{
    /* In SDK 3.1, SetVolume() returns void. If we're compiling against
     * 3.1, we handle it with ifdefs. However, if we compile against a later
     * SDK but are _running_ against 3.1, we avoid returning from an undefined
     * stack by doing a runtime check of the SDK version. */
#if !defined(__SERIES60_31__)
    const int err = m_player->SetVolume(mmfVolume);
    if (QSysInfo::s60Version() >= QSysInfo::SV_S60_3_2)
        return err;
    else
        return KErrNone;
 #else
     m_player->SetVolume(mmfVolume);
     return KErrNone;
#endif
}

int MMF::AudioPlayer::openFile(RFile& file)
{
    TRAPD(err, m_player->OpenFileL(file));

#ifdef QT_PHONON_MMF_AUDIO_DRM
    if (KErrNone == err) {
        // There appears to be a bug in the CDrmPlayerUtility implementation (at least
        // in S60 5.x) whereby the player does not check whether the loading observer
        // pointer is null before dereferencing it.  Therefore we must register for
        // loading notification, even though we do nothing in the callback functions.
        m_player->RegisterForAudioLoadingNotification(*this);
    }
#endif

    return err;
}

int MMF::AudioPlayer::openUrl(const QString& /*url*/)
{
    // Streaming playback is generally not supported by the implementation
    // of the audio player API, so we use CVideoPlayerUtility for both
    // audio and video streaming.
    Utils::panic(AudioUtilityUrlNotSupported);

    // Silence warning
    return 0;
}

int MMF::AudioPlayer::bufferStatus() const
{
    int result = 0;
    TRAP_IGNORE(m_player->GetAudioLoadingProgressL(result));
    return result;
}

void MMF::AudioPlayer::close()
{
    m_player->Close();
}

bool MMF::AudioPlayer::hasVideo() const
{
    return false;
}

qint64 MMF::AudioPlayer::currentTime() const
{
    TRACE_CONTEXT(AudioPlayer::currentTime, EAudioApi);

    TTimeIntervalMicroSeconds us;
    const TInt err = m_player->GetPosition(us);

    qint64 result = 0;

    if (KErrNone == err) {
        result = toMilliSeconds(us);
    } else {
        TRACE("GetPosition err %d", err);

        // If we don't cast away constness here, we simply have to ignore
        // the error.
        const_cast<AudioPlayer*>(this)->setError(tr("Getting position failed"), err);
    }

    return result;
}

qint64 MMF::AudioPlayer::totalTime() const
{
    return m_totalTime;
}


//-----------------------------------------------------------------------------
// Symbian multimedia client observer callbacks
//-----------------------------------------------------------------------------

#ifdef QT_PHONON_MMF_AUDIO_DRM
void MMF::AudioPlayer::MdapcInitComplete(TInt aError,
        const TTimeIntervalMicroSeconds &)
#else
void MMF::AudioPlayer::MapcInitComplete(TInt aError,
                                        const TTimeIntervalMicroSeconds &)
#endif
{
    TRACE_CONTEXT(AudioPlayer::MapcInitComplete, EAudioInternal);
    TRACE_ENTRY("state %d error %d", state(), aError);

    __ASSERT_ALWAYS(LoadingState == state(), Utils::panic(InvalidStatePanic));

    if (KErrNone == aError) {
        maxVolumeChanged(m_player->MaxVolume());
        m_totalTime = toMilliSeconds(m_player->Duration());
        emit totalTimeChanged(m_totalTime);
    }

    loadingComplete(aError);

    TRACE_EXIT_0();
}

#ifdef QT_PHONON_MMF_AUDIO_DRM
void MMF::AudioPlayer::MdapcPlayComplete(TInt aError)
#else
void MMF::AudioPlayer::MapcPlayComplete(TInt aError)
#endif
{
    TRACE_CONTEXT(AudioPlayer::MapcPlayComplete, EAudioInternal);
    TRACE_ENTRY("state %d error %d", state(), aError);

    // Call base class function which handles end of playback for both
    // audio and video clips.
    playbackComplete(aError);

    TRACE_EXIT_0();
}

#ifdef QT_PHONON_MMF_AUDIO_DRM
void MMF::AudioPlayer::MaloLoadingStarted()
{

}

void MMF::AudioPlayer::MaloLoadingComplete()
{

}
#endif // QT_PHONON_MMF_AUDIO_DRM


//-----------------------------------------------------------------------------
// MAudioLoadingObserver callbacks
//-----------------------------------------------------------------------------

void MMF::AudioPlayer::MaloLoadingStarted()
{
    bufferingStarted();
}

void MMF::AudioPlayer::MaloLoadingComplete()
{
    bufferingComplete();
}


//-----------------------------------------------------------------------------
// Private functions
//-----------------------------------------------------------------------------

int MMF::AudioPlayer::numberOfMetaDataEntries() const
{
    int numberOfEntries = 0;
    m_player->GetNumberOfMetaDataEntries(numberOfEntries); // ignoring return code
    return numberOfEntries;
}

QPair<QString, QString> MMF::AudioPlayer::metaDataEntry(int index) const
{
    CMMFMetaDataEntry *entry = 0;
    QT_TRAP_THROWING(entry = m_player->GetMetaDataEntryL(index));
    return QPair<QString, QString>(qt_TDesC2QString(entry->Name()), qt_TDesC2QString(entry->Value()));
}


QT_END_NAMESPACE