|
1 /* |
|
2 * Copyright (c) 2002-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: PayloadFormat plugin capable to read RTP payload containing |
|
15 * AMR audio. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 // INCLUDE FILES |
|
23 #include "amrpayloadformatter.h" |
|
24 #include "amrcommonutil.h" |
|
25 |
|
26 // CONSTANTS |
|
27 |
|
28 // ============================= LOCAL FUNCTIONS =============================== |
|
29 |
|
30 // ============================ MEMBER FUNCTIONS =============================== |
|
31 |
|
32 |
|
33 // ----------------------------------------------------------------------------- |
|
34 // CAmrPayloadFormatter::CAmrPayloadFormatter |
|
35 // C++ default constructor can NOT contain any code, that |
|
36 // might leave. |
|
37 // ----------------------------------------------------------------------------- |
|
38 // |
|
39 CAmrPayloadFormatter::CAmrPayloadFormatter( TBool aIsNb ) |
|
40 : iIsNb( aIsNb ), |
|
41 iChannelCount( 1 ), |
|
42 iFrameBlockCount( 1 ), |
|
43 iFrameCount( iChannelCount * iFrameBlockCount ), |
|
44 iModeRequest( EAmrModeReqNone ), |
|
45 iPayloadPtr( 0, 0, 0 ) |
|
46 {} |
|
47 |
|
48 // Destructor |
|
49 CAmrPayloadFormatter::~CAmrPayloadFormatter( ) |
|
50 { |
|
51 iPayload = NULL; |
|
52 iFrameDatas.ResetAndDestroy(); |
|
53 } |
|
54 |
|
55 // ----------------------------------------------------------------------------- |
|
56 // CAmrPayloadFormatter::Initialize |
|
57 // Initialize formatter. MUST be done always when starting decoding/encoding |
|
58 // possibly after pause/stop. Redundant frames collected so far are destroyed as |
|
59 // well as frames received for redundancy detection. |
|
60 // ----------------------------------------------------------------------------- |
|
61 // |
|
62 void CAmrPayloadFormatter::Initialize() |
|
63 { |
|
64 iFrameDatas.ResetAndDestroy(); |
|
65 DoInitialize(); |
|
66 } |
|
67 |
|
68 // ----------------------------------------------------------------------------- |
|
69 // CAmrPayloadFormatter::SetPayloadBuffer |
|
70 // Set payload buffer. |
|
71 // ----------------------------------------------------------------------------- |
|
72 // |
|
73 void CAmrPayloadFormatter::SetPayloadBuffer( TDes8& aBuffer ) |
|
74 { |
|
75 iPayload = const_cast<TUint8*>( aBuffer.Ptr( ) ); |
|
76 iPayloadSize = aBuffer.Length( ); |
|
77 iPayloadPtr.Set( iPayload, aBuffer.Length( ), aBuffer.MaxLength( ) ); |
|
78 } |
|
79 |
|
80 |
|
81 // ----------------------------------------------------------------------------- |
|
82 // CAmrPayloadFormatter::SetChannelCount |
|
83 // Set number of audio channels. |
|
84 // ----------------------------------------------------------------------------- |
|
85 // |
|
86 TInt CAmrPayloadFormatter::SetChannelCount( TInt aChannelCount ) |
|
87 { |
|
88 if ( KMaxChannelCount < aChannelCount || aChannelCount < 1 ) |
|
89 { |
|
90 return KErrArgument; |
|
91 } |
|
92 |
|
93 iChannelCount = aChannelCount; |
|
94 iFrameCount = iChannelCount * iFrameBlockCount; |
|
95 return KErrNone; |
|
96 } |
|
97 |
|
98 |
|
99 // ----------------------------------------------------------------------------- |
|
100 // CAmrPayloadFormatter::SetFramesBlockCount |
|
101 // Set number of AMR frame blocks included in one RTP packet. |
|
102 // ----------------------------------------------------------------------------- |
|
103 // |
|
104 TInt CAmrPayloadFormatter::SetFrameBlockCount( TInt aFrameblockCount ) |
|
105 { |
|
106 if ( KMaxFrameBlocksPerPacket < aFrameblockCount || aFrameblockCount < 1 ) |
|
107 { |
|
108 return KErrArgument; |
|
109 } |
|
110 |
|
111 iFrameBlockCount = aFrameblockCount; |
|
112 iFrameCount = iChannelCount * iFrameBlockCount; |
|
113 return KErrNone; |
|
114 } |
|
115 |
|
116 |
|
117 // ----------------------------------------------------------------------------- |
|
118 // CAmrPayloadFormatter::SpeechBitCount |
|
119 // Get number of speech bits in an AMR frame. |
|
120 // ----------------------------------------------------------------------------- |
|
121 // |
|
122 TInt CAmrPayloadFormatter::SpeechBitCount( enum TAmrFrameType aFrameType ) const |
|
123 { |
|
124 if ( iIsNb ) |
|
125 { |
|
126 if ( aFrameType > EAmrFrameSid) |
|
127 { |
|
128 return 0; |
|
129 } |
|
130 else |
|
131 { |
|
132 return KAmrNbTotalSpeechBits[TInt( aFrameType )]; |
|
133 } |
|
134 } |
|
135 else |
|
136 { |
|
137 if ( aFrameType > EAmrWbFrameSid) |
|
138 { |
|
139 return 0; |
|
140 } |
|
141 else |
|
142 { |
|
143 return KAmrWbTotalSpeechBits[TInt( aFrameType )]; |
|
144 } |
|
145 } |
|
146 } |
|
147 |
|
148 // ========================== OTHER EXPORTED FUNCTIONS ========================= |
|
149 |
|
150 // End of File |