os/mm/devsoundextensions/mmfcustominterfaces/SbcEncoderIntfc/SbcEncoderIntfcProxy/src/SbcEncoderIntfcProxy.cpp
Update contrib.
2 * Copyright (c) 2006 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 BT SBC Encoder configuration CI.
21 #include <CustomCommandUtility.h>
22 #include <CustomInterfaceUtility.h>
23 #include "SbcEncoderIntfcMsgs.h"
24 #include "SbcEncoderIntfcProxy.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 ==============================
47 * CSbcEncoderIntfcProxy::CSbcEncoderIntfcProxy
48 * C++ default constructor can NOT contain any code, that might leave.
50 CSbcEncoderIntfcProxy::CSbcEncoderIntfcProxy(
51 TMMFMessageDestinationPckg aMessageHandler,
52 MCustomCommand& aCustomCommand,
53 CCustomInterfaceUtility* aCustomInterfaceUtility) :
54 iCustomCommand(aCustomCommand),
55 iMessageHandler(aMessageHandler),
56 iCustomInterfaceUtility(aCustomInterfaceUtility)
61 * CSbcEncoderIntfcProxy::ConstructL
62 * Symbian 2nd phase constructor can leave.
64 void CSbcEncoderIntfcProxy::ConstructL()
66 iHasBeenApplied = EFalse;
70 * CSbcEncoderIntfcProxy::NewL
71 * Two-phased constructor.
73 EXPORT_C CSbcEncoderIntfcProxy* CSbcEncoderIntfcProxy::NewL(
74 TMMFMessageDestinationPckg aMessageHandler,
75 MCustomCommand& aCustomCommand,
76 CCustomInterfaceUtility* aCustomInterfaceUtility)
78 CSbcEncoderIntfcProxy* self = new(ELeave) CSbcEncoderIntfcProxy(
81 aCustomInterfaceUtility);
82 CleanupStack::PushL( self );
84 CleanupStack::Pop( self );
91 EXPORT_C CSbcEncoderIntfcProxy::~CSbcEncoderIntfcProxy()
93 iCustomInterfaceUtility->RemoveCustomInterface(iMessageHandler);
94 delete iCustomInterfaceUtility;
98 * CSbcEncoderIntfcProxy::GetSupportedSamplingFrequencies
99 * Returns an array of supported sampling frequencies.
100 * Calls a subfunction, which sends the appropriate custom command
101 * to its message handler. A subfunction is used to contain multiple
102 * leaving functions in a single trap.
103 * (other items were commented in a header).
105 EXPORT_C TInt CSbcEncoderIntfcProxy::GetSupportedSamplingFrequencies(
107 aSupportedSamplingFrequencies)
110 GetSupportedSamplingFrequenciesL(aSupportedSamplingFrequencies));
115 * CSbcEncoderIntfcProxy::GetSupportedSamplingFrequenciesL
116 * Returns an array of supported sampling frequencies.
117 * Sends the custom command for this function to its message handler. This
118 * requires two commands. The first is a request for the number of supported
119 * sampling frequencies. A buffer is allocated locally to hold this number of
120 * frequencies that will be returned. A pointer to this buffer is sent with the
121 * next command, which is a request for the frequencies. This buffer will be
122 * filled with the frequency values. These values are then copied into the
123 * array provided to this function and the local buffer is deleted.
124 * (other items were commented in a header).
126 void CSbcEncoderIntfcProxy::GetSupportedSamplingFrequenciesL(
127 RArray<TUint>& aSupportedSamplingFrequencies)
129 aSupportedSamplingFrequencies.Reset();
131 TPckgBuf<TUint> pckgBuf;
132 User::LeaveIfError(iCustomCommand.CustomCommandSync(
134 ESbceimGetNumOfSupportedSamplingFrequencies,
139 HBufC8* buf = HBufC8::NewLC(pckgBuf() * sizeof(TUint));
140 TPtr8 ptr = buf->Des();
142 User::LeaveIfError(iCustomCommand.CustomCommandSync(
144 ESbceimGetSupportedSamplingFrequencies,
149 PopulateArrayL(aSupportedSamplingFrequencies, ptr, pckgBuf());
150 CleanupStack::PopAndDestroy(buf);
154 * CSbcEncoderIntfcProxy::GetSupportedChannelModes
155 * Returns an array of supported channel modes.
156 * Calls a subfunction which sends the appropriate custom command to its
157 * message handler. A subfunction is used to contain multiple leaving
158 * functions for a single trap.
159 * (other items were commented in a header).
161 EXPORT_C TInt CSbcEncoderIntfcProxy::GetSupportedChannelModes(
162 RArray<TSbcChannelMode>&
163 aSupportedChannelModes)
165 TRAPD(status, GetSupportedChannelModesL(aSupportedChannelModes));
170 * CSbcEncoderIntfcProxy::GetSupportedChannelModesL
171 * Returns an array of supported channel modes.
172 * Sends the custom command for this function to its message handler. This
173 * requires two commands. The first is a request for the number of supported
174 * channel modes. A buffer is allocated locally to hold this number of channel
175 * modes that will be returned. A pointer to this buffer is sent with the next
176 * command, which is a request for the channel modes. This buffer will be
177 * filled with the frequency values. These values are then copied into the array
178 * provided to this function and the local buffer is deleted.
179 * (other items were commented in a header).
181 void CSbcEncoderIntfcProxy::GetSupportedChannelModesL(
182 RArray<TSbcChannelMode>& aSupportedChannelModes)
184 aSupportedChannelModes.Reset();
186 TPckgBuf<TSbcChannelMode> pckgBuf;
187 User::LeaveIfError(iCustomCommand.CustomCommandSync(
189 ESbceimGetNumOfSupportedChannelModes,
194 HBufC8* buf = HBufC8::NewLC(pckgBuf() * sizeof(TUint));
195 TPtr8 ptr = buf->Des();
196 User::LeaveIfError(iCustomCommand.CustomCommandSync(
198 ESbceimGetSupportedChannelModes,
203 RDesReadStream stream(ptr);
204 CleanupClosePushL(stream);
206 for (TInt i = 0; i < pckgBuf(); i++)
208 aSupportedChannelModes.AppendL(
209 static_cast<TSbcChannelMode>(stream.ReadUint32L()));
212 CleanupStack::PopAndDestroy(&stream);
213 CleanupStack::PopAndDestroy(buf);
217 * CSbcEncoderIntfcProxy::GetSupportedNumOfBlocks
218 * Returns an array of supported blocks.
219 * Calls a subfunction, which sends the appropriate custom command to its
220 * message handler. A subfunction is used to contain multiple leaving functions
222 * (other items were commented in a header).
224 EXPORT_C TInt CSbcEncoderIntfcProxy::GetSupportedNumOfBlocks(
225 RArray<TUint>& aSupportedNumOfBlocks)
227 TRAPD(status, GetSupportedNumOfBlocksL(aSupportedNumOfBlocks));
232 * CSbcEncoderIntfcProxy::GetSupportedNumOfBlocks
233 * Returns an array of supported blocks.
234 * Sends the custom command for this function to its message handler. This
235 * requires two commands. The first is a request for the number of supported
236 * blocks. A buffer is allocated locally to hold this number of blocks that
237 * will be returned. A pointer to this buffer is then sent with the next
238 * command, which is a request for the blocks. This buffer will be filled
239 * with the block values. These values are then copied into the array provided
240 * to this function and the local buffer is deleted.
241 * (other items were commented in a header).
243 void CSbcEncoderIntfcProxy::GetSupportedNumOfBlocksL(
244 RArray<TUint>& aSupportedNumOfBlocks)
246 aSupportedNumOfBlocks.Reset();
248 TPckgBuf<TUint> pckgBuf;
249 User::LeaveIfError(iCustomCommand.CustomCommandSync(
251 ESbceimGetNumOfSupportedBlocks,
256 HBufC8* buf = HBufC8::NewLC(pckgBuf() * sizeof(TUint));
257 TPtr8 ptr = buf->Des();
258 User::LeaveIfError(iCustomCommand.CustomCommandSync(
260 ESbceimGetSupportedBlocks,
265 PopulateArrayL(aSupportedNumOfBlocks, ptr, pckgBuf());
266 CleanupStack::PopAndDestroy(buf);
270 * CSbcEncoderIntfcProxy::GetSupportedNumOfSubbands
271 * Returns an array of supported subbands.
272 * Calls a subfunction which sends the appropriate custom command to its
273 * message handler. A subfunction is used to contain multiple leaving functions
275 * (other items were commented in a header).
277 EXPORT_C TInt CSbcEncoderIntfcProxy::GetSupportedNumOfSubbands(
278 RArray<TUint>& aSupportedNumOfSubbands)
280 TRAPD(status, GetSupportedNumOfSubbandsL(aSupportedNumOfSubbands));
285 * CSbcEncoderIntfcProxy::GetSupportedNumOfSubbandsL
286 * Returns an array of supported subbands.
287 * Sends the custom command for this function to its message handler. This
288 * requires two commands. The first is a request for the number of supported
289 * subbands. A buffer is allocated locally to hold this number of subbands that
290 * will be returned. A pointer to this buffer is sent with the next command,
291 * which is a request for the subbands. This buffer will be filled with the
292 * subband values. These values are then copied into the array provided to this
293 * function and the local buffer is deleted.
294 * (other items were commented in a header).
296 void CSbcEncoderIntfcProxy::GetSupportedNumOfSubbandsL(
297 RArray<TUint>& aSupportedNumOfSubbands)
299 aSupportedNumOfSubbands.Reset();
301 TPckgBuf<TUint> pckgBuf;
302 User::LeaveIfError(iCustomCommand.CustomCommandSync(
304 ESbceimGetNumOfSupportedNumOfSubbands,
309 HBufC8* buf = HBufC8::NewLC(pckgBuf() * sizeof(TUint));
310 TPtr8 ptr = buf->Des();
311 User::LeaveIfError(iCustomCommand.CustomCommandSync(
313 ESbceimGetSupportedNumOfSubbands,
318 PopulateArrayL(aSupportedNumOfSubbands, ptr, pckgBuf());
319 CleanupStack::PopAndDestroy(buf);
323 * CSbcEncoderIntfcProxy::GetSupportedAllocationMethods
324 * Returns an array of supported allocation methods.
325 * Calls a subfunction which sends the appropriate custom command to its
326 * message handler. A subfunction is used to contain multiple leaving
327 * functions for a single trap.
328 * (other items were commented in a header).
330 EXPORT_C TInt CSbcEncoderIntfcProxy::GetSupportedAllocationMethods(
331 RArray<TSbcAllocationMethod>&
332 aSupportedAllocationMethods)
334 TRAPD(status, GetSupportedAllocationMethodsL(aSupportedAllocationMethods));
339 * CSbcEncoderIntfcProxy::GetSupportedAllocationMethodsL
340 * Returns an array of supported allocation methods.
341 * Sends the custom command for this function to its message handler. This
342 * requires two commands. The first is a request for the number of supported
343 * allocation methods. A buffer is allocated locally to hold this number of
344 * allocation methods that will be returned. A pointer to this buffer is sent
345 * with the next command which is a request for the allocation methods. This
346 * buffer will be filled with the allocation method values. These values are
347 * then copied into the array provided to this function and the local buffer
349 * (other items were commented in a header).
351 void CSbcEncoderIntfcProxy::GetSupportedAllocationMethodsL(
352 RArray<TSbcAllocationMethod>&
353 aSupportedAllocationMethods)
355 aSupportedAllocationMethods.Reset();
357 TPckgBuf<TSbcAllocationMethod> pckgBuf;
358 User::LeaveIfError(iCustomCommand.CustomCommandSync(
360 ESbceimGetNumOfSupportedAllocationMethods,
365 HBufC8* buf = HBufC8::NewLC(pckgBuf() * sizeof(TUint));
366 TPtr8 ptr = buf->Des();
367 User::LeaveIfError(iCustomCommand.CustomCommandSync(
369 ESbceimGetSupportedAllocationMethods,
374 RDesReadStream stream(ptr);
375 CleanupClosePushL(stream);
377 for (TInt i = 0; i < pckgBuf(); i++)
379 aSupportedAllocationMethods.AppendL(
380 static_cast<TSbcAllocationMethod>(stream.ReadUint32L()));
383 CleanupStack::PopAndDestroy(&stream);
384 CleanupStack::PopAndDestroy(buf);
388 * CSbcEncoderIntfcProxy::GetSupportedBitpoolRange
389 * Returns supported bitpool range.
390 * Calls a subfunction which sends the appropriate custom command to its
391 * message handler. A subfunction is used to contain multiple leaving
392 * functions for a single trap.
393 * (other items were commented in a header).
395 EXPORT_C TInt CSbcEncoderIntfcProxy::GetSupportedBitpoolRange(
396 TUint& aMinSupportedBitpoolSize,
397 TUint& aMaxSupportedBitpoolSize)
399 TRAPD(status, GetSupportedBitpoolRangeL(aMinSupportedBitpoolSize,
400 aMaxSupportedBitpoolSize));
405 * CSbcEncoderIntfcProxy::GetSupportedBitpoolRangeL
406 * Returns an array of supported bitpool range.
407 * Sends the custom command for this function to its message handler with TUint
408 * type arguments that will be filled with the bitpool min and max values.
409 * (other items were commented in a header).
411 void CSbcEncoderIntfcProxy::GetSupportedBitpoolRangeL(
412 TUint& aMinSupportedBitpoolSize,
413 TUint& aMaxSupportedBitpoolSize)
415 TSbcEncoderBitpoolRange bitPoolRange;
416 bitPoolRange.iMinSupportedBitpoolSize = 0;
417 bitPoolRange.iMaxSupportedBitpoolSize = 0;
419 TPckgBuf<TSbcEncoderBitpoolRange> pckgBuf(bitPoolRange);
420 User::LeaveIfError(iCustomCommand.CustomCommandSync(
422 ESbceimGetSupportedBitpoolRange,
427 aMinSupportedBitpoolSize = pckgBuf().iMinSupportedBitpoolSize;
428 aMaxSupportedBitpoolSize = pckgBuf().iMaxSupportedBitpoolSize;
432 * CSbcEncoderIntfcProxy::ApplyConfig
433 * Commits encoder configuration settings configured by callas to Set() APIs.
434 * Sends the custom command for this function to its message handler.
435 * New settings will not take effect until ApplyConfig() is called.
436 * (other items were commented in a header).
438 EXPORT_C TInt CSbcEncoderIntfcProxy::ApplyConfig()
440 TInt status = KErrNone;
442 if (!iHasBeenApplied)
444 if (!iSbcEncConf.iSamplingFrequencySet ||
445 !iSbcEncConf.iChannelModeSet ||
446 !iSbcEncConf.iNumOfSubbandsSet ||
447 !iSbcEncConf.iNumOfBlocksSet ||
448 !iSbcEncConf.iAllocationMethodSet ||
449 !iSbcEncConf.iBitpoolSizeSet)
451 status = KErrArgument;
455 if (status == KErrNone)
457 TSbcEncoderConfig sbcEncoderConfig;
459 sbcEncoderConfig.iSamplingFrequency = iSbcEncConf.iSamplingFrequency;
460 sbcEncoderConfig.iChannelMode = iSbcEncConf.iChannelMode;
461 sbcEncoderConfig.iNumOfSubbands = iSbcEncConf.iNumOfSubbands;
462 sbcEncoderConfig.iNumOfBlocks = iSbcEncConf.iNumOfBlocks;
463 sbcEncoderConfig.iAllocationMethod = iSbcEncConf.iAllocationMethod;
464 sbcEncoderConfig.iBitpoolSize = iSbcEncConf.iBitpoolSize;
466 TPckgBuf<TSbcEncoderConfig> pckgBuf(sbcEncoderConfig);
467 status = iCustomCommand.CustomCommandSync(iMessageHandler,
471 if (status == KErrNone)
473 iSbcEncConfCurrent = iSbcEncConf;
474 iHasBeenApplied = ETrue;
482 * CSbcEncoderIntfcProxy::SetSamplingFrequency
483 * Saves locally requested sampling frequency.
484 * Change does not apply to the encoder until ApplyConfig() is called.
485 * (other items were commented in a header).
487 EXPORT_C void CSbcEncoderIntfcProxy::SetSamplingFrequency(
488 TUint aSamplingFrequency)
490 iSbcEncConf.iSamplingFrequency = aSamplingFrequency;
491 iSbcEncConf.iSamplingFrequencySet = ETrue;
495 * CSbcEncoderIntfcProxy::GetSamplingFrequency
496 * Returns current sampling frequency commited by call to ApplyConfig().
497 * (other items were commented in a header).
499 EXPORT_C TInt CSbcEncoderIntfcProxy::GetSamplingFrequency(
500 TUint& aSamplingFrequency)
502 TInt status = KErrNone;
506 aSamplingFrequency = iSbcEncConfCurrent.iSamplingFrequency;
510 status = KErrArgument;
517 * CSbcEncoderIntfcProxy::SetChannelMode
518 * Saves locally requested channel mode.
519 * Change does not apply to the encoder until ApplyConfig() is called.
520 * (other items were commented in a header).
522 EXPORT_C void CSbcEncoderIntfcProxy::SetChannelMode(
523 TSbcChannelMode aChannelMode)
525 iSbcEncConf.iChannelMode = aChannelMode;
526 iSbcEncConf.iChannelModeSet = ETrue;
530 * CSbcEncoderIntfcProxy::GetChannelMode
531 * Returns current channel mode commited by call to ApplyConfig().
532 * (other items were commented in a header).
534 EXPORT_C TInt CSbcEncoderIntfcProxy::GetChannelMode(
535 TSbcChannelMode& aChannelMode)
537 TInt status = KErrNone;
541 aChannelMode = iSbcEncConfCurrent.iChannelMode;
545 status = KErrArgument;
552 * CSbcEncoderIntfcProxy::SetNumOfSubbands
553 * Saves locally requested number of subbands.
554 * Change does not apply to the encoder until ApplyConfig() is called.
555 * (other items were commented in a header).
557 EXPORT_C void CSbcEncoderIntfcProxy::SetNumOfSubbands(TUint aNumOfSubbands)
559 iSbcEncConf.iNumOfSubbands = aNumOfSubbands;
560 iSbcEncConf.iNumOfSubbandsSet = ETrue;
564 * CSbcEncoderIntfcProxy::GetNumOfSubbands
565 * Returns current number of subbands commited by call to ApplyConfig().
566 * (other items were commented in a header).
568 EXPORT_C TInt CSbcEncoderIntfcProxy::GetNumOfSubbands(TUint& aNumOfSubbands)
570 TInt status = KErrNone;
574 aNumOfSubbands = iSbcEncConfCurrent.iNumOfSubbands;
578 status = KErrArgument;
585 * CSbcEncoderIntfcProxy::SetNumOfBlocks
586 * Saves locally requested number of blocks.
587 * Change does not apply to the encoder until ApplyConfig() is called.
588 * (other items were commented in a header).
590 EXPORT_C void CSbcEncoderIntfcProxy::SetNumOfBlocks(TUint aNumOfBlocks)
592 iSbcEncConf.iNumOfBlocks = aNumOfBlocks;
593 iSbcEncConf.iNumOfBlocksSet = ETrue;
597 * CSbcEncoderIntfcProxy::GetNumOfBlocks
598 * Returns current number of blocks commited by call to ApplyConfig().
599 * (other items were commented in a header).
601 EXPORT_C TInt CSbcEncoderIntfcProxy::GetNumOfBlocks(TUint& aNumOfBlocks)
603 TInt status = KErrNone;
607 aNumOfBlocks = iSbcEncConfCurrent.iNumOfBlocks;
611 status = KErrArgument;
618 * CSbcEncoderIntfcProxy::SetAllocationMethod
619 * Saves locally requested allocation method.
620 * Change does not apply to the encoder until ApplyConfig() is called.
621 * (other items were commented in a header).
623 EXPORT_C void CSbcEncoderIntfcProxy::SetAllocationMethod(
624 TSbcAllocationMethod aAllocationMethod)
626 iSbcEncConf.iAllocationMethod = aAllocationMethod;
627 iSbcEncConf.iAllocationMethodSet = ETrue;
631 * CSbcEncoderIntfcProxy::GetAllocationMethod
632 * Returns current allocation method commited by call to ApplyConfig().
633 * (other items were commented in a header).
635 EXPORT_C TInt CSbcEncoderIntfcProxy::GetAllocationMethod(
636 TSbcAllocationMethod& aAllocationMethod)
638 TInt status = KErrNone;
642 aAllocationMethod = iSbcEncConfCurrent.iAllocationMethod;
646 status = KErrArgument;
653 * CSbcEncoderIntfcProxy::SetBitpoolSize
654 * Saves locally requested bitpool range.
655 * Change does not apply to the encoder until ApplyConfig() is called.
656 * (other items were commented in a header).
658 EXPORT_C void CSbcEncoderIntfcProxy::SetBitpoolSize(TUint aBitpoolSize)
660 iSbcEncConf.iBitpoolSize = aBitpoolSize;
661 iSbcEncConf.iBitpoolSizeSet = ETrue;
665 * CSbcEncoderIntfcProxy::GetBitpoolSize
666 * Returns current bitpool range commited by call to ApplyConfig().
667 * (other items were commented in a header).
669 EXPORT_C TInt CSbcEncoderIntfcProxy::GetBitpoolSize(TUint& aBitpoolSize)
671 TInt status = KErrNone;
675 aBitpoolSize = iSbcEncConfCurrent.iBitpoolSize;
679 status = KErrArgument;
686 * CSbcEncoderIntfcProxy::PopulateArrayL
687 * Utility method that reads stream from 8-bit descriptor, converts it
688 * to TUint data items and then copies them to the aArray.
689 * (other items were commented in a header).
691 void CSbcEncoderIntfcProxy::PopulateArrayL(RArray<TUint>& aArray,
695 RDesReadStream stream(aPtr);
696 CleanupClosePushL(stream);
698 for (TInt i = 0; i < aCount; i++)
700 aArray.AppendL(stream.ReadUint32L());
703 CleanupStack::PopAndDestroy(&stream);
706 // ========================== OTHER EXPORTED FUNCTIONS =========================