os/mm/devsoundextensions/mmfcustominterfaces/SpeechEncoderConfig/SpeechEncoderConfigProxy/src/SpeechEncoderConfigProxy.cpp
First public contribution.
2 * Copyright (c) 2002-2004 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
14 * Description: Interface proxy for speech encoder configuration.
21 #include "SpeechEncoderConfigProxy.h"
22 #include "SpeechEncoderConfigMsgs.h"
23 #include <CustomCommandUtility.h>
24 #include <CustomInterfaceUtility.h>
26 // EXTERNAL DATA STRUCTURES
28 // EXTERNAL FUNCTION PROTOTYPES
34 // LOCAL CONSTANTS AND MACROS
36 // MODULE DATA STRUCTURES
38 // LOCAL FUNCTION PROTOTYPES
40 // FORWARD DECLARATIONS
42 // ============================= LOCAL FUNCTIONS ===============================
44 // ================= MEMBER FUNCTIONS =======================
46 // -----------------------------------------------------------------------------
47 // CSpeechEncoderConfigProxy::CSpeechEncoderConfigProxy
48 // C++ default constructor can NOT contain any code, that
50 // -----------------------------------------------------------------------------
52 CSpeechEncoderConfigProxy::CSpeechEncoderConfigProxy(
53 TMMFMessageDestinationPckg aMessageHandler,
54 MCustomCommand& aCustomCommand,
55 CCustomInterfaceUtility* aCustomInterfaceUtility) :
56 iCustomCommand(aCustomCommand),
57 iMessageHandler(aMessageHandler),
58 iCustomInterfaceUtility(aCustomInterfaceUtility)
63 // -----------------------------------------------------------------------------
64 // CSpeechEncoderConfigProxy::ConstructL
65 // Symbian 2nd phase constructor can leave.
66 // -----------------------------------------------------------------------------
68 void CSpeechEncoderConfigProxy::ConstructL()
72 // -----------------------------------------------------------------------------
73 // CSpeechEncoderConfigProxy::NewL
74 // Two-phased constructor.
75 // -----------------------------------------------------------------------------
77 EXPORT_C CSpeechEncoderConfigProxy* CSpeechEncoderConfigProxy::NewL(
78 TMMFMessageDestinationPckg aMessageHandler,
79 MCustomCommand& aCustomCommand,
80 CCustomInterfaceUtility* aCustomInterfaceUtility)
82 CSpeechEncoderConfigProxy* self = new(ELeave) CSpeechEncoderConfigProxy(
85 aCustomInterfaceUtility);
86 CleanupStack::PushL( self );
88 CleanupStack::Pop( self );
93 EXPORT_C CSpeechEncoderConfigProxy::~CSpeechEncoderConfigProxy()
95 iCustomInterfaceUtility->RemoveCustomInterface(iMessageHandler);
96 delete iCustomInterfaceUtility;
99 // ---------------------------------------------------------
100 // CSpeechEncoderConfigProxy::GetSupportedBitrates
101 // Calls a subfunction which sends the appropriate custom command for this
102 // function to its message handler. A subfunction is used
103 // to contain multiple leaving functions for a single trap.
104 // (other items were commented in a header).
105 // ---------------------------------------------------------
107 EXPORT_C TInt CSpeechEncoderConfigProxy::GetSupportedBitrates(
108 RArray<TUint>& aSupportedBitrates)
111 TRAP(status, GetSupportedBitratesL(aSupportedBitrates));
115 // ---------------------------------------------------------
116 // CSpeechEncoderConfigProxy::GetSupportedBitratesL
117 // Sends the custom command for this function to its message handler.
118 // This requires two commands. The first is a request for the number of
119 // supported bitrates. A buffer is allocated locally to hold this number of
120 // bitrates that will be returned. A pointer to this buffer is sent with the
121 // next command which is a request for the bitrates. This buffer will be filled
122 // with the bitrate values. These bitrates are then copied into the array
123 // provided to this function and the local buffer is deleted.
124 // (other items were commented in a header).
125 // ---------------------------------------------------------
127 void CSpeechEncoderConfigProxy::GetSupportedBitratesL(
128 RArray<TUint>& aSupportedBitrates)
130 aSupportedBitrates.Reset();
132 TPckgBuf<TUint> numberOfBitratesPckg;
133 User::LeaveIfError(iCustomCommand.CustomCommandSync(
135 ESecmGetNumOfSupportedBitrates,
138 numberOfBitratesPckg));
139 HBufC8* buf = HBufC8::NewLC(numberOfBitratesPckg()*sizeof(TUint));
140 // buf is left on cleanup
141 TPtr8 ptr = buf->Des();
143 User::LeaveIfError(iCustomCommand.CustomCommandSync(
145 ESecmGetSupportedBitrates,
149 RDesReadStream stream(ptr);
150 CleanupClosePushL(stream); // stream on cleanup
151 for (TInt i=0; i<numberOfBitratesPckg(); i++)
153 aSupportedBitrates.AppendL(stream.ReadUint32L());
155 CleanupStack::PopAndDestroy(&stream);
156 CleanupStack::PopAndDestroy(buf);
159 // ---------------------------------------------------------
160 // CSpeechEncoderConfigProxy::SetBitrate
161 // Sends the custom command for this function to its message handler.
162 // (other items were commented in a header).
163 // ---------------------------------------------------------
165 EXPORT_C TInt CSpeechEncoderConfigProxy::SetBitrate(TUint aBitrate)
167 TPckgBuf<TInt> bitratePckg(aBitrate);
168 TInt status = iCustomCommand.CustomCommandSync(iMessageHandler,
175 // ---------------------------------------------------------
176 // CSpeechEncoderConfigProxy::GetBitrate
177 // Sends the custom command for this function to its message handler.
178 // (other items were commented in a header).
179 // ---------------------------------------------------------
181 EXPORT_C TInt CSpeechEncoderConfigProxy::GetBitrate(TUint& aBitrate)
184 TPckgBuf<TInt> bitratePckg(bitrate);
185 TInt status = iCustomCommand.CustomCommandSync(iMessageHandler,
190 if (status == KErrNone)
191 aBitrate = bitratePckg();
195 // ---------------------------------------------------------
196 // CSpeechEncoderConfigProxy::SetVadMode
197 // Sends the custom command for this function to its message handler.
198 // (other items were commented in a header).
199 // ---------------------------------------------------------
201 EXPORT_C TInt CSpeechEncoderConfigProxy::SetVadMode(TBool aVadMode)
203 TPckgBuf<TBool> pckgBuf(aVadMode);
204 TInt status = iCustomCommand.CustomCommandSync(iMessageHandler,
211 // ---------------------------------------------------------
212 // CSpeechEncoderConfigProxy::GetVadMode
213 // Sends the custom command for this function to its message handler.
214 // (other items were commented in a header).
215 // ---------------------------------------------------------
217 EXPORT_C TInt CSpeechEncoderConfigProxy::GetVadMode(TBool& aVadMode)
219 TInt vadMode = EFalse;
220 TPckgBuf<TBool> pckgBuf(vadMode);
221 TInt status = iCustomCommand.CustomCommandSync(iMessageHandler,
226 if (status == KErrNone)
227 aVadMode = pckgBuf();