|
1 /* |
|
2 * Copyright (c) 2008-2009 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 /** |
|
20 @file |
|
21 @internalComponent |
|
22 */ |
|
23 |
|
24 #ifndef OMXILPCMRENDERERPROCESSINGFUNCTION_H |
|
25 #define OMXILPCMRENDERERPROCESSINGFUNCTION_H |
|
26 |
|
27 #include <mmf/server/mmfdatabuffer.h> |
|
28 #include "omxilpcmrendererconst.h" |
|
29 #include <openmax/il/common/omxilprocessingfunction.h> |
|
30 #include <e32msgqueue.h> |
|
31 |
|
32 // Forward declarations |
|
33 class MOmxILClockComponentCmdsIf; |
|
34 |
|
35 NONSHARABLE_CLASS(COmxILPcmRendererProcessingFunction) : |
|
36 public COmxILProcessingFunction |
|
37 { |
|
38 |
|
39 public: |
|
40 static COmxILPcmRendererProcessingFunction* NewL( |
|
41 MOmxILCallbackNotificationIf& aCallbacks, |
|
42 MOmxILClockComponentCmdsIf& aClientClockPort); |
|
43 |
|
44 ~COmxILPcmRendererProcessingFunction(); |
|
45 |
|
46 OMX_ERRORTYPE StateTransitionIndication(TStateIndex aNewState); |
|
47 |
|
48 OMX_ERRORTYPE BufferFlushingIndication(TUint32 aPortIndex, |
|
49 OMX_DIRTYPE aDirection); |
|
50 |
|
51 OMX_ERRORTYPE ParamIndication(OMX_INDEXTYPE aParamIndex, |
|
52 const TAny* apComponentParameterStructure); |
|
53 |
|
54 OMX_ERRORTYPE ConfigIndication(OMX_INDEXTYPE aConfigIndex, |
|
55 const TAny* apComponentConfigStructure); |
|
56 |
|
57 OMX_ERRORTYPE BufferIndication( |
|
58 OMX_BUFFERHEADERTYPE* apBufferHeader, |
|
59 OMX_DIRTYPE aDirection); |
|
60 |
|
61 OMX_ERRORTYPE MediaTimeIndication(const OMX_TIME_MEDIATIMETYPE& aMediaTimeType); |
|
62 |
|
63 OMX_BOOL BufferRemovalIndication( |
|
64 OMX_BUFFERHEADERTYPE* apBufferHeader, |
|
65 OMX_DIRTYPE aDirection); |
|
66 |
|
67 TInt GetBytesPlayed() const; |
|
68 |
|
69 private: |
|
70 |
|
71 COmxILPcmRendererProcessingFunction(MOmxILCallbackNotificationIf& aCallbacks, |
|
72 MOmxILClockComponentCmdsIf& aClientClockPort); |
|
73 |
|
74 void ConstructL(); |
|
75 |
|
76 void FlushBufferList(RPointerArray<OMX_BUFFERHEADERTYPE>& aBufferList); |
|
77 |
|
78 private: |
|
79 RPointerArray<OMX_BUFFERHEADERTYPE> iBuffersToEmpty; |
|
80 RPointerArray<OMX_BUFFERHEADERTYPE> iBuffersEmptied; |
|
81 OMX_STATETYPE iState; |
|
82 MOmxILClockComponentCmdsIf* iClientClockPortPtr; |
|
83 OMX_TICKS iStartMediaTime; |
|
84 |
|
85 class CAudioDevice : public CActive |
|
86 { |
|
87 public: |
|
88 static CAudioDevice* NewL(COmxILPcmRendererProcessingFunction& aParent); |
|
89 ~CAudioDevice(); |
|
90 |
|
91 // from CActive |
|
92 void RunL(); |
|
93 void DoCancel(); |
|
94 |
|
95 OMX_ERRORTYPE OpenDevice(); |
|
96 OMX_ERRORTYPE CloseDevice(); |
|
97 OMX_ERRORTYPE Execute(); |
|
98 OMX_ERRORTYPE MoveToPausedState(); |
|
99 OMX_ERRORTYPE Stop(); |
|
100 |
|
101 OMX_ERRORTYPE SetChannels(TUint aChannels); |
|
102 OMX_ERRORTYPE SetSampleRate(TUint aSampleRate); |
|
103 OMX_ERRORTYPE SetVolume(TInt aVolume); |
|
104 OMX_ERRORTYPE SetVolumeRamp(const TTimeIntervalMicroSeconds& aRampDuration); |
|
105 OMX_ERRORTYPE SetMuted(TBool aMuted); |
|
106 OMX_BUFFERHEADERTYPE* GetCurrentBuffer(); |
|
107 TInt GetBytesPlayed(); |
|
108 void ConfigAudioRamper(TInt64 aRampTime); |
|
109 TBool RampAudio(CMMFDataBuffer* aBuffer); |
|
110 TBool ConstructAndStartUpdateTimer(); |
|
111 void ProcessNextBuffer(); |
|
112 void PlayData(); |
|
113 void ProcessMediaTimeIndication(OMX_TIME_MEDIATIMETYPE& aMediaTimeType); |
|
114 void ProcessParamIndication(const OMX_AUDIO_PARAM_PCMMODETYPE& aPcmModeType); |
|
115 |
|
116 private: |
|
117 CAudioDevice(COmxILPcmRendererProcessingFunction& aParent); |
|
118 void ConstructL(); |
|
119 OMX_ERRORTYPE SetPlayFormat(); |
|
120 void SignalBufferCompletion(OMX_BUFFERHEADERTYPE* apCurrentBuffer); |
|
121 TBool IsBufferLengthSufficient(TInt aBufferLength) const; |
|
122 TInt GetMinBufferLength() const; |
|
123 void SendBufferToSoundDevice(TDes8& aBuffer); |
|
124 void StartUpdateTimer(); |
|
125 void HandleClockStateChanged(const OMX_TIME_MEDIATIMETYPE& aMediaTimeType); |
|
126 TBool CanPlayNow(); |
|
127 void HandleClockScaleChanged(const OMX_TIME_MEDIATIMETYPE& aMediaTimeType); |
|
128 void PauseAudio(); |
|
129 |
|
130 // From MGenericTimerClient |
|
131 static TInt UpdateClockMediaTime(TAny* aPtr ); |
|
132 |
|
133 private: |
|
134 RMdaDevSound iSoundDevice; |
|
135 OMX_BUFFERHEADERTYPE* iCurrentBuffer; |
|
136 COmxILPcmRendererProcessingFunction& iParent; |
|
137 TInt iSampleRate; |
|
138 TInt iChannels; |
|
139 RMdaDevSound::TMdaSoundEncoding iEncoding; |
|
140 TUint iVolume; |
|
141 TBool iMuted; |
|
142 TUint iBufferSize; |
|
143 TTimeIntervalMicroSeconds iVolumeRamp; |
|
144 TBool iRampAudioSample; |
|
145 TInt iRampSamples; |
|
146 TInt iRampSamplesLeft; |
|
147 TInt iRampIncr; |
|
148 TBool iSkip; |
|
149 TBool iClockStateRunning; |
|
150 TBool iPausedClockViaScale; |
|
151 TBool iIsStartTimeFlagSet; |
|
152 OMX_TICKS iClockMediaTime; |
|
153 TBool iPlayData; // To indicate whether it can start rendering audio or not |
|
154 |
|
155 /// If the component is in a state other than OMX_StateExecuting, this |
|
156 /// internal variable is used to store the last value of bytes played by |
|
157 /// the Sound Device. |
|
158 TInt iLastBytesPlayedValue; |
|
159 |
|
160 /// This is used to send a media time update to the clock component |
|
161 CPeriodic* iPeriodic; |
|
162 |
|
163 // This variable is used to optionally allocate a memory segment to cache OMX buffers if the tunnelled component does not utilise them well |
|
164 // If the tunnelled components don't fill in sufficient data in the buffers, this can create underflows in the renderer, as the driver won't have enough data to play |
|
165 RBuf8 iCachedPlayBuffer; |
|
166 TBool iResumeAfterNextPlay; |
|
167 |
|
168 } *iAudioDevice; |
|
169 |
|
170 class CPFHelper : public CActive |
|
171 { |
|
172 public: |
|
173 static CPFHelper* NewL(CAudioDevice& aAudioDevice); |
|
174 ~CPFHelper(); |
|
175 |
|
176 // from CActive |
|
177 void RunL(); |
|
178 void DoCancel(); |
|
179 |
|
180 TInt OpenDevice(); |
|
181 TInt CloseDevice(); |
|
182 TInt CloseDeviceOnError(); |
|
183 TInt Execute(); |
|
184 TInt Stop(); |
|
185 TInt CancelDevice(); |
|
186 TInt BufferIndication(); |
|
187 TInt MediaTimeIndication(const OMX_TIME_MEDIATIMETYPE& aMediaTimeType); |
|
188 TInt ParamIndication(const OMX_AUDIO_PARAM_PCMMODETYPE* aPcmModeType); |
|
189 TInt SetVolumeRamp(const OMX_U64 aRampDuration); |
|
190 TInt SetVolume(const OMX_S32 aVolumeValue); |
|
191 TInt SetMuted(const OMX_BOOL aVolumeValue); |
|
192 |
|
193 enum TMessageType |
|
194 { |
|
195 EOpenDevice, |
|
196 ECloseDevice, |
|
197 ECloseDeviceOnError, |
|
198 EExecuteCommand, |
|
199 EStopCommand, |
|
200 ECancelCommand, |
|
201 EBufferIndication, |
|
202 EMediaTimeIndication, |
|
203 EParamIndication, |
|
204 ESetVolumeRamp, |
|
205 ESetVolume, |
|
206 ESetMuted |
|
207 }; |
|
208 |
|
209 class TProcMessage |
|
210 { |
|
211 public: |
|
212 TMessageType iType; |
|
213 OMX_TIME_MEDIATIMETYPE iMediaTimeType; |
|
214 OMX_AUDIO_PARAM_PCMMODETYPE iPcmModeType; |
|
215 OMX_U64 iRampDuration; |
|
216 OMX_S32 iVolumeValue; |
|
217 OMX_BOOL iMuted; |
|
218 }; |
|
219 |
|
220 RMsgQueue<TProcMessage> iMsgQueue; |
|
221 |
|
222 private: |
|
223 CPFHelper(CAudioDevice& aAudioDevice); |
|
224 void ConstructL(); |
|
225 |
|
226 private: |
|
227 |
|
228 static const TInt KMaxMsgQueueEntries = 150; |
|
229 |
|
230 CAudioDevice& iAudioDevice; |
|
231 TThreadId iHelperThreadId; |
|
232 RSemaphore iCallerSemaphore; |
|
233 |
|
234 } *iPFHelper; |
|
235 |
|
236 }; |
|
237 |
|
238 #endif // OMXILPCMRENDERERPROCESSINGFUNCTION_H |