|
1 /* |
|
2 * Copyright (c) 2002-2007 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: Player delegate to handle RTSP live streaming |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <jdebug.h> |
|
21 |
|
22 #include "cmmavideourlplayer.h" |
|
23 |
|
24 CMMAVideoUrlPlayer::CMMAVideoUrlPlayerLiveStreamDelegate* |
|
25 CMMAVideoUrlPlayer::CMMAVideoUrlPlayerLiveStreamDelegate::NewL(CMMAVideoUrlPlayer& aPlayer) |
|
26 { |
|
27 CMMAVideoUrlPlayerLiveStreamDelegate* self = |
|
28 new(ELeave) CMMAVideoUrlPlayerLiveStreamDelegate(aPlayer); |
|
29 CleanupStack::PushL(self); |
|
30 self->ConstructL(); |
|
31 CleanupStack::Pop(); |
|
32 return self; |
|
33 } |
|
34 |
|
35 CMMAVideoUrlPlayer::CMMAVideoUrlPlayerLiveStreamDelegate:: |
|
36 CMMAVideoUrlPlayerLiveStreamDelegate(CMMAVideoUrlPlayer& aPlayer) : |
|
37 CMMAVideoUrlPlayerDelegate(aPlayer), iMediaStartTime(0), |
|
38 iStoppedAtTime(0) |
|
39 { |
|
40 } |
|
41 |
|
42 void CMMAVideoUrlPlayer::CMMAVideoUrlPlayerLiveStreamDelegate::ConstructL() |
|
43 { |
|
44 iActiveSchedulerWait = new(ELeave)CActiveSchedulerWait; |
|
45 } |
|
46 |
|
47 CMMAVideoUrlPlayer::CMMAVideoUrlPlayerLiveStreamDelegate::~CMMAVideoUrlPlayerLiveStreamDelegate() |
|
48 { |
|
49 delete iActiveSchedulerWait; |
|
50 } |
|
51 |
|
52 void CMMAVideoUrlPlayer::CMMAVideoUrlPlayerLiveStreamDelegate::StartL() |
|
53 { |
|
54 // start can't be called to not ready player |
|
55 ASSERT(iPlayer.iState == EPrefetched); |
|
56 |
|
57 |
|
58 iPlayer.PrefetchL(); |
|
59 |
|
60 // Refresh all controls again after second prefetch |
|
61 iPlayer.RefreshControls(); |
|
62 |
|
63 // Completed in VideoPrepareComplete-event |
|
64 if (!iActiveSchedulerWait->IsStarted()) |
|
65 { |
|
66 DEBUG("MMA:CMMAVideoUrlPlayer: Live stream: StartL() ASW Start1"); |
|
67 iActiveSchedulerWait->Start(); |
|
68 } |
|
69 |
|
70 // Prime() is called sometimes twice since it's needed also when |
|
71 // restarting the playing |
|
72 User::LeaveIfError(iPlayer.iController.Prime()); |
|
73 User::LeaveIfError(iPlayer.iController.Play()); |
|
74 |
|
75 // Completed in VideoLoadingComplete-event |
|
76 if (!iActiveSchedulerWait->IsStarted()) |
|
77 { |
|
78 DEBUG("MMA:CMMAVideoUrlPlayer: Live stream: StartL() ASW Start2"); |
|
79 iActiveSchedulerWait->Start(); |
|
80 } |
|
81 iPlayer.PostActionCompleted(KErrNone); // java start return |
|
82 } |
|
83 |
|
84 void CMMAVideoUrlPlayer::CMMAVideoUrlPlayerLiveStreamDelegate::StopL(TBool aPostEvent) |
|
85 { |
|
86 DEBUG("MMA:CMMAVideoUrlPlayer: Live stream: StopL"); |
|
87 if (iPlayer.iState == EStarted) |
|
88 { |
|
89 DEBUG("MMA:CMMAVideoUrlPlayer: Live stream: StopL : Started "); |
|
90 GetMediaTime(&iStoppedAtTime); |
|
91 if (aPostEvent) |
|
92 { |
|
93 DEBUG("MMA:CMMAVideoUrlPlayer: Live stream: StopL : Postevent "); |
|
94 iPlayer.PostLongEvent(CMMAPlayerEvent::EStopped, iStoppedAtTime); |
|
95 } |
|
96 // go back to prefetched state |
|
97 iPlayer.ChangeState(EPrefetched); |
|
98 |
|
99 // Call stop instead of Pause as per the suggestions from helix |
|
100 // Pause has no meaning for live streaming |
|
101 iPlayer.iController.Stop(); |
|
102 } |
|
103 DEBUG("MMA:CMMAVideoUrlPlayer: Live stream: StopL - "); |
|
104 } |
|
105 |
|
106 void CMMAVideoUrlPlayer::CMMAVideoUrlPlayerLiveStreamDelegate::GetMediaTime(TInt64* aMediaTime) |
|
107 { |
|
108 DEBUG("MMA:CMMAVideoUrlPlayer::CMMAVideoUrlPlayerLiveStreamDelegate::GetMediaTime +"); |
|
109 if (iPlayer.iState == EStarted) |
|
110 { |
|
111 DEBUG("MMA:CMMAVideoUrlPlayer::CMMAVideoUrlPlayerLiveStreamDelegate::GetMediaTime Started Playerbase call"); |
|
112 iPlayer.CMMAMMFPlayerBase::GetMediaTime(aMediaTime); |
|
113 *aMediaTime -= iMediaStartTime; |
|
114 } |
|
115 else |
|
116 { |
|
117 DEBUG("MMA:CMMAVideoUrlPlayer::CMMAVideoUrlPlayerLiveStreamDelegate::GetMediaTime Stopped"); |
|
118 *aMediaTime = iStoppedAtTime; |
|
119 } |
|
120 DEBUG("MMA:CMMAVideoUrlPlayer::CMMAVideoUrlPlayerLiveStreamDelegate::GetMediaTime -"); |
|
121 } |
|
122 |
|
123 void CMMAVideoUrlPlayer::CMMAVideoUrlPlayerLiveStreamDelegate::HandleEvent(const TMMFEvent& aEvent) |
|
124 { |
|
125 DEBUG_INT("MMA:CMMAVideoUrlPlayer: Live stream: HandleEvent %d", aEvent.iEventType.iUid); |
|
126 DEBUG_INT("MMA:CMMAVideoUrlPlayer: Live stream: HandleEvent error code: %d", aEvent.iErrorCode); |
|
127 |
|
128 TInt err = aEvent.iErrorCode; |
|
129 |
|
130 if ((aEvent.iEventType == KMMFEventCategoryVideoLoadingComplete) && |
|
131 (iPlayer.iState == EPrefetched)) |
|
132 { |
|
133 DEBUG("MMA:CMMAVideoUrlPlayer: Live stream: KMMFEventCategoryVideoLoadingComplete +"); |
|
134 if (err == KErrNone) |
|
135 { |
|
136 TTimeIntervalMicroSeconds position(0); |
|
137 TInt error(iPlayer.iController.GetPosition(position)); |
|
138 if (error == KErrNone) |
|
139 { |
|
140 iMediaStartTime = position.Int64(); |
|
141 } |
|
142 |
|
143 // inform java side. Always start playback from zero for |
|
144 // live stream. |
|
145 iPlayer.PostLongEvent(CMMAPlayerEvent::EStarted, 0); |
|
146 |
|
147 // Buffering takes a long time, so player state is not changed |
|
148 // until playback really starts. |
|
149 iPlayer.ChangeState(EStarted); |
|
150 } |
|
151 if (iActiveSchedulerWait->IsStarted()) |
|
152 { |
|
153 DEBUG("MMA:CMMAVideoUrlPlayer: Live stream: KMMFEventCategoryVideoLoadingComplete ASW Stop"); |
|
154 iActiveSchedulerWait->AsyncStop(); |
|
155 } |
|
156 if (err != KErrNone) |
|
157 { |
|
158 DEBUG("MMA:CMMAVideoUrlPlayer: Live stream: KMMFEventCategoryVideoLoadingComplete Error Inform Parent"); |
|
159 iPlayer.HandleEventToParent(aEvent); |
|
160 } |
|
161 DEBUG("MMA:CMMAVideoUrlPlayer: Live stream: KMMFEventCategoryVideoLoadingComplete -"); |
|
162 } |
|
163 else if (aEvent.iEventType == KMMFEventCategoryVideoPrepareComplete) |
|
164 { |
|
165 DEBUG("MMA:CMMAVideoUrlPlayer: Live stream: KMMFEventCategoryVideoPrepareComplete +"); |
|
166 // going to prefetch state, after Play |
|
167 // KMMFEventCategoryVideoLoadingComplete event will be received |
|
168 |
|
169 if (err == KErrNone) |
|
170 { |
|
171 iPlayer.PrepareDisplay(); |
|
172 } |
|
173 |
|
174 // For live streams: complete prefetch. |
|
175 // if activeschedulerwait is started, then |
|
176 // do not complete prefetch as we are here |
|
177 // as a result of calling StartL and not for |
|
178 // PrefetchL. |
|
179 if (!(iActiveSchedulerWait->IsStarted())) |
|
180 { |
|
181 iPlayer.CompletePrefetch(err); |
|
182 } |
|
183 |
|
184 if (iActiveSchedulerWait->IsStarted()) |
|
185 { |
|
186 DEBUG("MMA:CMMAVideoUrlPlayer: Live stream: KMMFEventCategoryVideoPrepareComplete ASW Stop"); |
|
187 iActiveSchedulerWait->AsyncStop(); |
|
188 } |
|
189 DEBUG("MMA:CMMAVideoUrlPlayer: Live stream: KMMFEventCategoryVideoPrepareComplete -"); |
|
190 } |
|
191 else if (aEvent.iEventType == KMMFEventCategoryVideoPlayerGeneralError) |
|
192 { |
|
193 DEBUG("MMA:CMMAVideoUrlPlayer: Live stream: KMMFEventCategoryVideoPlayerGeneralError +"); |
|
194 // For live streams: KMMFEventCategoryVideoPlayerGeneralError means helix is closed |
|
195 // side if player is in prefetched state. |
|
196 if (iActiveSchedulerWait->IsStarted()) |
|
197 { |
|
198 DEBUG("MMA:CMMAVideoUrlPlayer: Live stream: KMMFEventCategoryVideoPlayerGeneralError ASW Stop"); |
|
199 iActiveSchedulerWait->AsyncStop(); |
|
200 } |
|
201 |
|
202 // usually error condition -45 (KErrSessionClosed) or -33 (KErrTimedOut) |
|
203 if (err != KErrNone) |
|
204 { |
|
205 DEBUG("MMA:CMMAVideoUrlPlayer: Live stream: KMMFEventCategoryVideoPlayerGeneralError Inform Parent"); |
|
206 iPlayer.HandleEventToParent(aEvent); |
|
207 } |
|
208 DEBUG("MMA:CMMAVideoUrlPlayer: Live stream: KMMFEventCategoryVideoPlayerGeneralError -"); |
|
209 } |
|
210 else |
|
211 { |
|
212 DEBUG_INT("MMA:CMMAVideoUrlPlayer: Live stream: + 0x%X", aEvent.iEventType.iUid); |
|
213 // For live streams: KErrSessionClosed is not posted to Java |
|
214 // side if player is in prefetched state. |
|
215 if ((iPlayer.iState != EPrefetched) || |
|
216 (aEvent.iErrorCode != KErrSessionClosed)) |
|
217 { |
|
218 DEBUG("MMA:CMMAVideoUrlPlayer: Live stream: Error Inform Parent"); |
|
219 // All other events. |
|
220 iPlayer.HandleEventToParent(aEvent); |
|
221 } |
|
222 DEBUG_INT("MMA:CMMAVideoUrlPlayer: Live stream: - 0x%X", aEvent.iEventType.iUid); |
|
223 } |
|
224 |
|
225 } |
|
226 |
|
227 // END OF FILE |