|
58
|
1 |
/*
|
|
|
2 |
* Copyright (c) 2010 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: Engine class of the SimpleVideoPlayback MPX view plugin.
|
|
|
15 |
*
|
|
|
16 |
*/
|
|
|
17 |
|
|
50
|
18 |
#include <mpxplaybackutility.h> // MMPXPlaybackUtility
|
|
|
19 |
#include <mpxmessagegeneraldefs.h>
|
|
|
20 |
#include <mpxplaybackmessage.h>
|
|
|
21 |
#include <mpxcommandgeneraldefs.h>
|
|
|
22 |
#include <mpxvideoplaybackdefs.h>
|
|
|
23 |
#include <mpxmediageneraldefs.h>
|
|
|
24 |
#include <mpxmediageneralextdefs.h>
|
|
|
25 |
#include <mpxmediavideodefs.h>
|
|
|
26 |
|
|
|
27 |
#include "svpbengine.h"
|
|
|
28 |
#include "trace.h"
|
|
|
29 |
|
|
|
30 |
const TUid KVideoHelixPlaybackPluginUid = { 0x10282551 };
|
|
|
31 |
|
|
|
32 |
SvpbEngine::SvpbEngine(QObject *parent) :
|
|
|
33 |
QObject(parent),
|
|
|
34 |
mSurfaceContainer(0),
|
|
|
35 |
mState(Disconnected),
|
|
|
36 |
mPlaybackUtility(0),
|
|
|
37 |
mMpxPbState(EPbStateNotInitialised)
|
|
|
38 |
{
|
|
|
39 |
FUNC_LOG;
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
SvpbEngine::~SvpbEngine()
|
|
|
43 |
{
|
|
|
44 |
FUNC_LOG;
|
|
|
45 |
|
|
|
46 |
disconnectMPX();
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
void SvpbEngine::connectMPX()
|
|
|
50 |
{
|
|
|
51 |
FUNC_LOG;
|
|
|
52 |
|
|
|
53 |
if (mState == Disconnected && !mPlaybackUtility) {
|
|
|
54 |
QT_TRAP_THROWING(mPlaybackUtility =
|
|
|
55 |
MMPXPlaybackUtility::UtilityL(EMPXCategoryVideo, KPbModeDefault));
|
|
|
56 |
MMPXPlayerManager &manager = mPlaybackUtility->PlayerManager();
|
|
|
57 |
QT_TRAP_THROWING(manager.SelectPlayerL(KVideoHelixPlaybackPluginUid));
|
|
|
58 |
QT_TRAP_THROWING(mPlaybackUtility->AddObserverL(*this));
|
|
|
59 |
mState = Connected;
|
|
|
60 |
INFO("Connected");
|
|
|
61 |
}
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
void SvpbEngine::disconnectMPX()
|
|
|
65 |
{
|
|
|
66 |
FUNC_LOG;
|
|
|
67 |
|
|
|
68 |
if (mState != Disconnected && mPlaybackUtility)
|
|
|
69 |
{
|
|
|
70 |
mPlaybackUtility->RemoveObserverL(*this);
|
|
|
71 |
mPlaybackUtility->Close();
|
|
|
72 |
mPlaybackUtility = 0;
|
|
|
73 |
mState = Disconnected;
|
|
|
74 |
INFO("Disconnected");
|
|
|
75 |
}
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
/** Ownership is not transferred. */
|
|
|
79 |
void SvpbEngine::setSurfaceContainer(SvpbSurfaceContainer *surfaceContainer)
|
|
|
80 |
{
|
|
|
81 |
FUNC_LOG;
|
|
|
82 |
|
|
|
83 |
mSurfaceContainer = surfaceContainer;
|
|
|
84 |
}
|
|
|
85 |
|
|
|
86 |
void SvpbEngine::togglePause()
|
|
|
87 |
{
|
|
|
88 |
FUNC_LOG;
|
|
|
89 |
|
|
|
90 |
if (mState == PlayRequested || mState == Playing) {
|
|
|
91 |
QT_TRAP_THROWING(mPlaybackUtility->CommandL(EPbCmdPause, 0));
|
|
|
92 |
mState = PauseRequested;
|
|
|
93 |
INFO("Pause requested");
|
|
|
94 |
}
|
|
|
95 |
else if (mState == PauseRequested || mState == Paused) {
|
|
|
96 |
QT_TRAP_THROWING(mPlaybackUtility->CommandL(EPbCmdPlay, 0));
|
|
|
97 |
mState = PlayRequested;
|
|
|
98 |
INFO("Play requested");
|
|
|
99 |
}
|
|
|
100 |
}
|
|
|
101 |
|
|
|
102 |
void SvpbEngine::stop()
|
|
|
103 |
{
|
|
|
104 |
FUNC_LOG;
|
|
|
105 |
|
|
|
106 |
if (mState == PlayRequested || mState == Playing) {
|
|
|
107 |
QT_TRAP_THROWING(mPlaybackUtility->CommandL(EPbCmdStop, 0));
|
|
|
108 |
mState = StopRequested;
|
|
|
109 |
INFO("Stop requested");
|
|
|
110 |
}
|
|
|
111 |
}
|
|
|
112 |
|
|
|
113 |
void SvpbEngine::HandlePlaybackMessage(CMPXMessage *aMessage, TInt aErr)
|
|
|
114 |
{
|
|
|
115 |
FUNC_LOG;
|
|
|
116 |
|
|
|
117 |
if (aMessage) {
|
|
|
118 |
TMPXMessageId id(aMessage->ValueTObjectL<TMPXMessageId>(KMPXMessageGeneralId));
|
|
|
119 |
|
|
|
120 |
if (id == KMPXMessageGeneral) {
|
|
|
121 |
TInt msg(0), type(0);
|
|
|
122 |
QT_TRAP_THROWING(msg = aMessage->ValueTObjectL<TInt>(KMPXMessageGeneralEvent));
|
|
|
123 |
QT_TRAP_THROWING(type = aMessage->ValueTObjectL<TInt>(KMPXMessageGeneralType));
|
|
|
124 |
INFO("KMPXMessageGeneral" << msg << type);
|
|
|
125 |
|
|
|
126 |
switch(msg)
|
|
|
127 |
{
|
|
|
128 |
case TMPXPlaybackMessage::EInitializeComplete:
|
|
|
129 |
INFO("Initialize complete");
|
|
|
130 |
break;
|
|
|
131 |
case TMPXPlaybackMessage::EStateChanged:
|
|
|
132 |
mpxPbStateChanged(static_cast<TMPXPlaybackState>(type), aErr);
|
|
|
133 |
break;
|
|
|
134 |
default:
|
|
|
135 |
break;
|
|
|
136 |
}
|
|
|
137 |
}
|
|
|
138 |
else if (id == KMPXMediaIdVideoDisplayMessage) {
|
|
|
139 |
TMPXVideoDisplayCommand msg =
|
|
|
140 |
( *(aMessage->Value<TMPXVideoDisplayCommand>(KMPXMediaVideoDisplayCommand)));
|
|
|
141 |
INFO("KMPXMediaIdVideoDisplayMessage" << msg);
|
|
|
142 |
|
|
|
143 |
switch (msg)
|
|
|
144 |
{
|
|
|
145 |
case EPbMsgVideoSurfaceCreated:
|
|
|
146 |
case EPbMsgVideoSurfaceChanged:
|
|
|
147 |
if (mSurfaceContainer) {
|
|
|
148 |
TSurfaceId surfaceId;
|
|
|
149 |
TRect cropRect;
|
|
|
150 |
TVideoAspectRatio aspectRatio;
|
|
|
151 |
QT_TRAP_THROWING(surfaceId = aMessage->ValueTObjectL<TSurfaceId>(KMPXMediaVideoDisplayTSurfaceId));
|
|
|
152 |
QT_TRAP_THROWING(cropRect = aMessage->ValueTObjectL<TRect>(KMPXMediaVideoDisplayCropRect));
|
|
|
153 |
QT_TRAP_THROWING(aspectRatio = aMessage->ValueTObjectL<TVideoAspectRatio>(KMPXMediaVideoDisplayAspectRatio));
|
|
|
154 |
mSurfaceContainer->attachSurface(surfaceId, cropRect, aspectRatio);
|
|
|
155 |
}
|
|
|
156 |
break;
|
|
|
157 |
case EPbMsgVideoSurfaceRemoved:
|
|
|
158 |
if (mSurfaceContainer) {
|
|
|
159 |
mSurfaceContainer->detachSurface();
|
|
|
160 |
}
|
|
|
161 |
break;
|
|
|
162 |
}
|
|
|
163 |
}
|
|
|
164 |
}
|
|
|
165 |
}
|
|
|
166 |
|
|
|
167 |
void SvpbEngine::HandlePropertyL(TMPXPlaybackProperty aProperty, TInt aValue, TInt aError)
|
|
|
168 |
{
|
|
|
169 |
Q_UNUSED(aProperty);
|
|
|
170 |
Q_UNUSED(aValue);
|
|
|
171 |
Q_UNUSED(aError);
|
|
|
172 |
FUNC_LOG;
|
|
|
173 |
}
|
|
|
174 |
|
|
|
175 |
void SvpbEngine::HandleSubPlayerNamesL(TUid /*aPlayer*/,
|
|
|
176 |
const MDesCArray* /*aSubPlayers*/,
|
|
|
177 |
TBool /*aComplete*/,
|
|
|
178 |
TInt /*aError*/)
|
|
|
179 |
{
|
|
|
180 |
FUNC_LOG;
|
|
|
181 |
}
|
|
|
182 |
|
|
|
183 |
void SvpbEngine::HandleMediaL(const CMPXMedia& /*aProperties*/, TInt /*aError*/)
|
|
|
184 |
{
|
|
|
185 |
FUNC_LOG;
|
|
|
186 |
|
|
|
187 |
QT_TRAP_THROWING(mPlaybackUtility->CommandL(EPbCmdPlay, 0));
|
|
|
188 |
mState = PlayRequested;
|
|
|
189 |
INFO("Play requested");
|
|
|
190 |
}
|
|
|
191 |
|
|
|
192 |
void SvpbEngine::mpxPbStateChanged(TMPXPlaybackState type, int err)
|
|
|
193 |
{
|
|
|
194 |
FUNC_LOG;
|
|
|
195 |
INFO("MPX PB state:" << type << "error" << err);
|
|
|
196 |
|
|
|
197 |
if (err == 0) {
|
|
|
198 |
switch(type) {
|
|
|
199 |
case EPbStateInitialised:
|
|
|
200 |
requestMedia(); // VideoHelixPlugin uses media request to signal view activation
|
|
|
201 |
mState = MediaRequested;
|
|
|
202 |
INFO("Media requested");
|
|
|
203 |
break;
|
|
|
204 |
case EPbStatePlaying:
|
|
|
205 |
mState = Playing;
|
|
|
206 |
INFO("Playing");
|
|
|
207 |
break;
|
|
|
208 |
case EPbStatePaused:
|
|
|
209 |
mState = Paused;
|
|
|
210 |
INFO("Paused");
|
|
|
211 |
break;
|
|
|
212 |
case EPbStateStopped:
|
|
|
213 |
mState = Connected;
|
|
|
214 |
INFO("Connected");
|
|
|
215 |
emit finished();
|
|
|
216 |
break;
|
|
|
217 |
default:
|
|
|
218 |
break;
|
|
|
219 |
};
|
|
|
220 |
}
|
|
|
221 |
}
|
|
|
222 |
|
|
|
223 |
void SvpbEngine::requestMedia()
|
|
|
224 |
{
|
|
|
225 |
FUNC_LOG;
|
|
|
226 |
|
|
|
227 |
MMPXSource *source = mPlaybackUtility->Source();
|
|
|
228 |
HANDLE_ERROR_NULL(source);
|
|
|
229 |
if (source) {
|
|
|
230 |
RArray<TMPXAttribute> attrs;
|
|
|
231 |
attrs.Append(KMPXMediaGeneralUri|
|
|
|
232 |
KMPXMediaGeneralDuration|
|
|
|
233 |
KMPXMediaGeneralTitle|
|
|
|
234 |
KMPXMediaGeneralMimeType);
|
|
|
235 |
attrs.Append(KMPXMediaVideoAll);
|
|
|
236 |
|
|
|
237 |
CMPXAttributeSpecs *specs = 0;
|
|
|
238 |
TRAPD(err, specs = CMPXAttributeSpecs::NewL());
|
|
|
239 |
HANDLE_ERROR_NEG(err);
|
|
|
240 |
if (specs) {
|
|
|
241 |
// Set the attribute to always route the media call to playback plugin
|
|
|
242 |
TRAP(err, specs->SetTObjectValueL<TBool>(KMPXMediaGeneralExtMediaRedirect, ETrue));
|
|
|
243 |
HANDLE_ERROR_NEG(err);
|
|
|
244 |
if (err == KErrNone) {
|
|
|
245 |
TRAP(err, source->MediaL(attrs.Array(), *this, specs));
|
|
|
246 |
HANDLE_ERROR_NEG(err);
|
|
|
247 |
}
|
|
|
248 |
}
|
|
|
249 |
|
|
|
250 |
delete specs;
|
|
|
251 |
attrs.Close();
|
|
|
252 |
}
|
|
|
253 |
}
|