|
1 /* |
|
2 * Copyright (c) 2004-2006 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: Formatter classes for decoding of RTP payload format |
|
15 * for AMR ( narrow band ) and AMR-WB ( wide band ) audio codecs. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 #ifndef AMRPAYLOADENCODER_H |
|
23 #define AMRPAYLOADENCODER_H |
|
24 |
|
25 // INCLUDES |
|
26 #include <e32std.h> |
|
27 #include "amrpayloadformatter.h" |
|
28 #include "amrpayloadheader.h" |
|
29 #include "amrtocentry.h" |
|
30 #include "streamformatter.h" |
|
31 |
|
32 // CONSTANTS |
|
33 |
|
34 // MACROS |
|
35 |
|
36 // DATA TYPES |
|
37 |
|
38 // FUNCTION PROTOTYPES |
|
39 |
|
40 // FORWARD DECLARATIONS |
|
41 class TStreamEncoder; |
|
42 |
|
43 // CLASS DECLARATION |
|
44 |
|
45 /** |
|
46 * The AMR payload encoder for bandwidth efficient mode. |
|
47 * |
|
48 * @lib <TBD> |
|
49 * @since Series-60 2.1 |
|
50 */ |
|
51 class CAmrPayloadEncoder : public CAmrPayloadFormatter |
|
52 { |
|
53 public: // Constructors and destructor |
|
54 |
|
55 /** |
|
56 * Two-phased constructor. |
|
57 */ |
|
58 static CAmrPayloadEncoder* NewL( TBool aIsNb ); |
|
59 |
|
60 |
|
61 /** |
|
62 * Destructor. |
|
63 */ |
|
64 virtual ~CAmrPayloadEncoder( ); |
|
65 |
|
66 |
|
67 public: // Functions |
|
68 |
|
69 /** |
|
70 * Set AMR codec mode request ( CMR ). |
|
71 * @since Series-60 2.1 |
|
72 * @param aRequest - [input] AMR codec mode request ( CMR ) |
|
73 * @return void |
|
74 */ |
|
75 void SetModeRequest( TAmrModeRequest aRequest ); |
|
76 |
|
77 /** |
|
78 * Encode a received AMR frame into the payload buffer. |
|
79 * @since Series-60 2.1 |
|
80 * @param aChannel - [input] Channel number that the frame belongs to |
|
81 * @param aFrameType - [input] Frame type |
|
82 * @param aFrameQualityInd - [input] Frame quality indicator bit; 1 if frame OK; 0 if frame damaged |
|
83 * @param aFrameData - [input] Frame data; its length depends on frame type |
|
84 * @return ETrue if payload formatting is completed; otherwise EFalse |
|
85 */ |
|
86 virtual TBool EncodeFrame( TInt aChannel, |
|
87 TAmrFrameType aFrameType, |
|
88 TUint8 aFrameQualityInd, |
|
89 const TDes8& aFrameData ); |
|
90 |
|
91 /** |
|
92 * Reset the payload buffer. |
|
93 * @since Series-60 2.1 |
|
94 * @param None |
|
95 * @return void |
|
96 */ |
|
97 void ResetPayloadBuffer( ); |
|
98 |
|
99 /** |
|
100 * Do bit shifting when AmrPayloadFormatPlugin is doing buffer flushing. |
|
101 * @since Series-60 2.1 |
|
102 * @param None |
|
103 * @return ETrue if payload formatting is completed; otherwise EFalse |
|
104 */ |
|
105 TBool ReEncodeFrameL( ); |
|
106 |
|
107 /** |
|
108 * Do bit shifting when AmrPayloadFormatPlugin is doing buffer flushing |
|
109 * @since Series-60 2.1 |
|
110 * @param aBuffer Buffer containing frame data |
|
111 * @return ETrue if payload formatting is completed; otherwise EFalse |
|
112 */ |
|
113 TBool ReEncodeFrameL( TUint8* aBuffer ); |
|
114 |
|
115 /** |
|
116 * Returns ETrue if next frame will start new packetization period. |
|
117 * @since Series 60 3.1 |
|
118 * @return ETrue if next frame starts new period |
|
119 */ |
|
120 TBool IsStartOfPeriod(); |
|
121 |
|
122 public: // Functions from CAmrPayloadFormatter |
|
123 |
|
124 /** |
|
125 * Set number of audio channels. |
|
126 * @since Series-60 2.1 |
|
127 * @param aChannelCount - [input] Number of audio channels |
|
128 * @return KErrNone if successful; system wide error code otherwise |
|
129 */ |
|
130 virtual TInt SetChannelCount( TInt aChannelCount ); |
|
131 |
|
132 /** |
|
133 * Set number of AMR frame blocks included in one RTP packet. |
|
134 * Each frame block contains frames for all audio channels. |
|
135 * @since Series-60 2.1 |
|
136 * @param aFrameblockCount - [input] Number of AMR frame blocks included |
|
137 * in one RTP packet |
|
138 * @return KErrNone if successful; system wide error code otherwise |
|
139 */ |
|
140 virtual TInt SetFrameBlockCount( TInt aFrameblockCount ); |
|
141 |
|
142 /** |
|
143 * Set number of redundant frame blocks included in one RTP packet. |
|
144 * Each frame block contains frames for all audio channels. |
|
145 * @since Series 60 3.0 |
|
146 * @param aRedBlockCount Number of redundant AMR frame blocks to be |
|
147 * included in one RTP packet |
|
148 * @return KErrNone if successful; system wide error code otherwise |
|
149 */ |
|
150 virtual TInt SetRedFrameBlockCount( TInt aRedBlockCount ); |
|
151 |
|
152 /** |
|
153 * Initialize frame encoder ( Stream Encoder ). |
|
154 * Information to initialize are obtained from iPayload, calculation |
|
155 * using iChannelCount and iFrameBlockCount. |
|
156 * Initialization should be done whenever a payload is finished. |
|
157 * @since Series-60 2.1 |
|
158 * @param None |
|
159 * @return void |
|
160 */ |
|
161 virtual void InitializeFrameEncoder( ); |
|
162 |
|
163 protected: // Functions |
|
164 |
|
165 /** |
|
166 * Constructor. |
|
167 */ |
|
168 CAmrPayloadEncoder( TBool aIsNb ); |
|
169 |
|
170 /** |
|
171 * By default Symbian 2nd phase constructor is private. |
|
172 */ |
|
173 void ConstructL( ); |
|
174 |
|
175 /** |
|
176 * Encode the AMR payload ( for one RTP packet ) into a given buffer. |
|
177 * Values to encode are obtained from `iFrames' array. |
|
178 * @since Series-60 2.1 |
|
179 * @param aBuffer - [output] Buffer to store encoded data |
|
180 * @return Total number of bytes encoded in the buffer |
|
181 */ |
|
182 TInt Encode( TUint8* aBuffer ); |
|
183 |
|
184 /** |
|
185 * Encode 'Table of Contents' into a given buffer at the given position. |
|
186 * Information to encode are obtained from `iFrames' array. |
|
187 * Byte and bit positions are updated after encoding is done. |
|
188 * @since Series-60 2.1 |
|
189 * @param aBuffer - [output] Buffer to store encoded data. |
|
190 * @param aByteIndex - [input] Starting byte index ( starts from zero ). |
|
191 * [output] Byte index updated after encoding. |
|
192 * @param aBitIndex - [input] Starting bit index ( starts from zero ). |
|
193 * [output] Bit index updated after encoding. |
|
194 * @return void |
|
195 */ |
|
196 void EncodeTableOfContents( TUint8* aBuffer, |
|
197 TInt& aByteIndex, |
|
198 TInt& aBitIndex ); |
|
199 |
|
200 /** |
|
201 * Rips off unwanted NO_DATA frames from payload according to |
|
202 * RFC3267: 4.3.2. |
|
203 * |
|
204 * @since Series 60 3.0 |
|
205 * @param None |
|
206 * @return Number of frames discarded from a payload |
|
207 */ |
|
208 virtual TInt DiscardExtraNoDataFrames(); |
|
209 |
|
210 /** |
|
211 * Saves frame so it can be sent as redundancy later. |
|
212 * |
|
213 * @since Series 60 3.0 |
|
214 * @param aFrameData Frame data to save |
|
215 * @return void |
|
216 */ |
|
217 virtual void SaveRedundantFrame( const TDes8& aFrameData ); |
|
218 |
|
219 protected: // From CAmrPayloadFormatter |
|
220 |
|
221 /** |
|
222 * Initializes encoder. Encoder should be initialized when starting |
|
223 * playing. |
|
224 * |
|
225 * @since Series 60 3.0 |
|
226 * @param None |
|
227 * @return void |
|
228 */ |
|
229 virtual void DoInitialize(); |
|
230 |
|
231 protected: // Data |
|
232 |
|
233 // Encoder for payload header |
|
234 CAmrPayloadHeader* iHeaderEncoder; |
|
235 |
|
236 // Encoder for TOC entry |
|
237 CAmrTocEntry* iTocEntryEncoder; |
|
238 |
|
239 // Encoder for frame data |
|
240 TStreamEncoder iFrameEncoder; |
|
241 |
|
242 // Total speech bits in current payload |
|
243 TInt iTotalSpeechBits; |
|
244 |
|
245 // Number of redundant frames to be sent |
|
246 TInt iRedCount; |
|
247 |
|
248 // Indicates is redundancy count of sent frames collected |
|
249 TBool iRedIntervalCollected; |
|
250 |
|
251 // Indicates how many NO_DATA frames is discarded at this round |
|
252 TInt iFramesDiscarded; |
|
253 private: |
|
254 |
|
255 #ifdef TEST_EUNIT |
|
256 friend class UT_CAmrPayloadEncoder; |
|
257 friend class UT_CAmrPayloadFormatWrite; |
|
258 #endif |
|
259 |
|
260 }; |
|
261 |
|
262 #endif // __AMRPAYLOADENCODER_H |