|
1 /* |
|
2 * Copyright (c) 2008 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: Comfort noise generator of MCC jitterbuffer |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <mmcccodecinformation.h> //codec FourCC declarations |
|
22 #include <voipjitterbufferintfc.h> |
|
23 #include "debugtracemacros.h" |
|
24 #include "InternalDef.h" |
|
25 #include "JitterBufferObserver.h" |
|
26 #include "CngGenerator.h" |
|
27 |
|
28 |
|
29 // ----------------------------------------------------------------------------- |
|
30 // CVoIPCNGenerator::NewL |
|
31 // Static constructor. |
|
32 // ----------------------------------------------------------------------------- |
|
33 // |
|
34 CVoIPCNGenerator* CVoIPCNGenerator::NewL(MJitterBufferObserver* aObserver, |
|
35 const TFourCC& aCodec) |
|
36 { |
|
37 CVoIPCNGenerator* self = new (ELeave) CVoIPCNGenerator(aObserver, aCodec); |
|
38 CleanupStack::PushL(self); |
|
39 self->ConstructL(); |
|
40 CleanupStack::Pop(self); |
|
41 return self; |
|
42 } |
|
43 |
|
44 // ----------------------------------------------------------------------------- |
|
45 // CVoIPCNGenerator::CVoIPCNGenerator |
|
46 // C++ default constructor can NOT contain any code, that might leave. |
|
47 // ----------------------------------------------------------------------------- |
|
48 // |
|
49 CVoIPCNGenerator::CVoIPCNGenerator(MJitterBufferObserver* aObserver, |
|
50 const TFourCC& aCodec) |
|
51 { |
|
52 iObserver = aObserver; |
|
53 iCodec = aCodec; |
|
54 } |
|
55 |
|
56 // ----------------------------------------------------------------------------- |
|
57 // CVoIPCNGenerator::ConstructL |
|
58 // Symbian 2nd phase constructor can leave. |
|
59 // ----------------------------------------------------------------------------- |
|
60 // |
|
61 void CVoIPCNGenerator::ConstructL() |
|
62 { |
|
63 switch (iCodec.FourCC()) |
|
64 { |
|
65 case KMccFourCCIdG711: |
|
66 case KMccFourCCIdG729: |
|
67 case KMccFourCCIdILBC: |
|
68 case KMccFourCCIdAMRNB: |
|
69 break; |
|
70 default: |
|
71 User::Leave(KErrNotSupported); |
|
72 } |
|
73 } |
|
74 |
|
75 // ----------------------------------------------------------------------------- |
|
76 // CVoIPCNGenerator::~CVoIPCNGenerator |
|
77 // Destructor |
|
78 // ----------------------------------------------------------------------------- |
|
79 // |
|
80 CVoIPCNGenerator::~CVoIPCNGenerator() |
|
81 { |
|
82 } |
|
83 |
|
84 // ----------------------------------------------------------------------------- |
|
85 // CVoIPCNGenerator::CreateSidBufferL |
|
86 // Creates codec-specific SID Buffer |
|
87 // ----------------------------------------------------------------------------- |
|
88 // |
|
89 void CVoIPCNGenerator::GenerateSidPacket(TDes8& aPayload, TInt aRequestSize) |
|
90 { |
|
91 // TRACE_PRN_FN_ENT; |
|
92 |
|
93 if (aRequestSize > aPayload.MaxLength()) |
|
94 { |
|
95 TRACE_PRN_N(_L("CVoIPCNGenerator::GenerateSidPacket->Adjust Size")); |
|
96 aRequestSize = aPayload.MaxLength(); |
|
97 } |
|
98 |
|
99 iGeneratedCNFrames++; |
|
100 TRACE_PRN_N1(_L("JB-CNG-> Generated CN frames [%d]"), iGeneratedCNFrames); |
|
101 |
|
102 if (iCodec.FourCC() == KMccFourCCIdAMRNB) |
|
103 { |
|
104 GenerateAmrNoDataPacket(aPayload); |
|
105 |
|
106 if (iGeneratedCNFrames == KAmrNbSidUpdateInterval) |
|
107 { |
|
108 // We haven't received SID_UPDATE for the 8-th frame; |
|
109 // this means packet loss |
|
110 iDtxPeriodStarted = EFalse; |
|
111 } |
|
112 } |
|
113 else |
|
114 { |
|
115 GenerateVoIPNoDataPacket(aPayload, aRequestSize); |
|
116 } |
|
117 |
|
118 // TRACE_PRN_FN_EXT; |
|
119 } |
|
120 |
|
121 // ----------------------------------------------------------------------------- |
|
122 // CVoIPCNGenerator::GenerateAmrNoDataPacket |
|
123 // Generates AMR SID packet |
|
124 // ----------------------------------------------------------------------------- |
|
125 // |
|
126 void CVoIPCNGenerator::GenerateAmrNoDataPacket(TDes8& aPayload) const |
|
127 { |
|
128 // TRACE_PRN_FN_ENT; |
|
129 |
|
130 if (aPayload.MaxLength() >= KNoDataLength) |
|
131 { |
|
132 aPayload.Copy(&KAmrNoDataFrame, KNoDataLength); |
|
133 } |
|
134 |
|
135 // TRACE_PRN_FN_EXT; |
|
136 }; |
|
137 |
|
138 // ----------------------------------------------------------------------------- |
|
139 // CVoIPCNGenerator::GenerateVoIPNoDataPacket |
|
140 // Generates SID packet for codecs other than AMR |
|
141 // ----------------------------------------------------------------------------- |
|
142 // |
|
143 void CVoIPCNGenerator::GenerateVoIPNoDataPacket(TDes8& aPayload, |
|
144 TInt aRequestSize) const |
|
145 { |
|
146 // TRACE_PRN_FN_ENT; |
|
147 |
|
148 aPayload.FillZ(aRequestSize); |
|
149 |
|
150 if (!iDtxPeriodStarted) |
|
151 { |
|
152 ConcealErrorForNextFrame(); |
|
153 } |
|
154 |
|
155 // TRACE_PRN_FN_EXT; |
|
156 }; |
|
157 |
|
158 // ----------------------------------------------------------------------------- |
|
159 // CVoIPCNGenerator::ConcealErrorForNextFrame |
|
160 // Requests error concealment for the next frame |
|
161 // ----------------------------------------------------------------------------- |
|
162 // |
|
163 void CVoIPCNGenerator::ConcealErrorForNextFrame() const |
|
164 { |
|
165 iObserver->EventJB(MJitterBufferObserver::EConcealErrorForNextBuffer); |
|
166 } |
|
167 |
|
168 // ----------------------------------------------------------------------------- |
|
169 // CVoIPCNGenerator::DtxPeriodStatus |
|
170 // Returns DTX status |
|
171 // ----------------------------------------------------------------------------- |
|
172 // |
|
173 TBool CVoIPCNGenerator::DtxPeriodStatus() const |
|
174 { |
|
175 return iDtxPeriodStarted; |
|
176 } |
|
177 |
|
178 // ----------------------------------------------------------------------------- |
|
179 // CVoIPCNGenerator::DoDtxDecision() |
|
180 // Determine DTX period based on codec used and data in the buffer |
|
181 // ----------------------------------------------------------------------------- |
|
182 // |
|
183 void CVoIPCNGenerator::DoDtxDecision(const TDes8& aData) |
|
184 { |
|
185 // TRACE_PRN_FN_ENT; |
|
186 |
|
187 if (aData.Length() > KMinDataLenForDtx) |
|
188 { |
|
189 if (IsSidBuffer(aData)) |
|
190 { |
|
191 // DTX period started or updated |
|
192 iDtxPeriodStarted = ETrue; |
|
193 iGeneratedCNFrames = 0; |
|
194 TRACE_PRN_N(_L("JB-CNG-> DTX_START")); |
|
195 } |
|
196 else |
|
197 { |
|
198 // DTX period has ended |
|
199 iDtxPeriodStarted = EFalse; |
|
200 TRACE_PRN_N(_L("JB-CNG-> DTX_END")); |
|
201 } |
|
202 } |
|
203 |
|
204 // TRACE_PRN_FN_EXT; |
|
205 } |
|
206 |
|
207 // ----------------------------------------------------------------------------- |
|
208 // CVoIPCNGenerator::IsSidBuffer |
|
209 // Is the given buffer a SID UPDATE buffer |
|
210 // ----------------------------------------------------------------------------- |
|
211 // |
|
212 TBool CVoIPCNGenerator::IsSidBuffer(const TDes8& aData) |
|
213 { |
|
214 // TRACE_PRN_FN_ENT; |
|
215 TBool status = ETrue; |
|
216 |
|
217 switch (iCodec.FourCC()) |
|
218 { |
|
219 case KMccFourCCIdAMRNB: |
|
220 { |
|
221 // Get AMR mode by bit-masking first byte and shifting |
|
222 const TUint8 mode((aData[0] & KAmrModeMask) >> KModeShiftBits); |
|
223 if (mode == KAmrSidMode) |
|
224 { |
|
225 status = ETrue; |
|
226 TRACE_PRN_N(_L("JB-CNG-> SID AMRNB FRAME")); |
|
227 } |
|
228 else |
|
229 { |
|
230 status = EFalse; |
|
231 TRACE_PRN_N(_L("JB-CNG-> NON-SID AMRNB FRAME")); |
|
232 } |
|
233 break; |
|
234 } |
|
235 case KMccFourCCIdG711: |
|
236 case KMccFourCCIdILBC: |
|
237 case KMccFourCCIdG729: |
|
238 { |
|
239 // Check the frame type |
|
240 if (aData[0] == KVoIPCNFrame) |
|
241 { |
|
242 status = ETrue; |
|
243 TRACE_PRN_N(_L("JB-CNG-> SID FRAME")); |
|
244 } |
|
245 else |
|
246 { |
|
247 status = EFalse; |
|
248 TRACE_PRN_N(_L("JB-CNG-> NON-SID FRAME")); |
|
249 } |
|
250 break; |
|
251 } |
|
252 default: |
|
253 { |
|
254 status = EFalse; |
|
255 TRACE_PRN_N(_L("JB-CNG-> SID-UNKNOWN")); |
|
256 } |
|
257 } |
|
258 |
|
259 // TRACE_PRN_FN_EXT; |
|
260 return status; |
|
261 } |
|
262 |
|
263 // End of File |