baseport/syborg/soundsc/virtio_audio.h
changeset 45 01c1ffcc4fca
child 71 d00bf4f57250
equal deleted inserted replaced
44:72a7468afdd4 45:01c1ffcc4fca
       
     1 /*
       
     2 * This component and the accompanying materials are made available
       
     3 * under the terms of the License "Eclipse Public License v1.0"
       
     4 * which accompanies this distribution, and is available
       
     5 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     6 *
       
     7 * Initial Contributors:
       
     8 * Accenture Ltd
       
     9 *
       
    10 * Contributors:
       
    11 *
       
    12 * Description: This file is a part of sound driver for Syborg adaptation.
       
    13 *
       
    14 */
       
    15 
       
    16 #ifndef VIRTIO_AUDIO_H
       
    17 #define VIRTIO_AUDIO_H
       
    18 
       
    19 #include "virtio_audio_defs.h"
       
    20 #include "virtio_defs.h"
       
    21 #include "virtio.h"
       
    22 
       
    23 #include <e32def.h>
       
    24 
       
    25 namespace VirtIo
       
    26 {
       
    27 
       
    28 namespace Audio
       
    29 {
       
    30 
       
    31 /// Encapsulates routines that affect VirtIo Audio device's Stream.
       
    32 /// DControl object may share ioHandler with other DControl objects.
       
    33 /// especially Control Queue.
       
    34 class DControl : public DBase
       
    35 	{
       
    36 	static const TUint KCmdMaxBufCount = 8;
       
    37 	static const TUint KControlQueueId = 0;
       
    38 public:
       
    39 	enum Command { ERun = 5, EStop, EPause, EResume };
       
    40 	
       
    41 	DControl( VirtIo::MIoHandler& aIoHandler, TUint32 aDataQueueId )
       
    42 	: iIoHandler( aIoHandler ), iDataQueueId( aDataQueueId)
       
    43 		{}
       
    44 		
       
    45 	~DControl();
       
    46 		
       
    47 	TInt Construct();
       
    48 	
       
    49 	/// sets up stream parameters.
       
    50 	TInt Setup( StreamDirection aDirection, TInt aChannelNum, 
       
    51 		FormatId aFormat, TInt aFreq );
       
    52 		
       
    53 	/// @brief posts a data buffer. 
       
    54 	///
       
    55 	/// The virtaulAddr is going to be turned into 
       
    56 	/// a physical address scatter gather list.
       
    57 	TInt SendDataBuffer( TAny* virtaulAddr, TUint aSize, Token aToken );
       
    58 	
       
    59 	/// Sends a specific command
       
    60 	void SendCommand( Command aCmd )
       
    61 		{ AddCommand( aCmd ); ControlQueue().Sync(); }
       
    62 
       
    63 	/// Return Data Queue of the stream.
       
    64 	MQueue& DataQueue()
       
    65 		{ return iIoHandler.Queue(iDataQueueId); }
       
    66 
       
    67 	/// Returns Control Queue of the associated device.
       
    68 	MQueue& ControlQueue()
       
    69 		{ return iIoHandler.Queue(KControlQueueId); }	
       
    70 
       
    71 private:
       
    72 	// size of this struct needs to be power2 aligned
       
    73 	// we extend original TCommand with padding to ensure this
       
    74 	struct TCommandPadded: public TCommand
       
    75 		{
       
    76 		static const TUint KPaddingSize = POW2ALIGN(sizeof(TCommand))-sizeof(TCommand);
       
    77 		TUint8 iPadding[KPaddingSize];
       
    78 		};
       
    79 	
       
    80 	void AddCommand( TCommandPadded* aCmd, Token aToken );
       
    81 	
       
    82 	void AddCommand( TCommandPadded* aCmd, Token aToken, TAny* mem, TUint size );
       
    83 
       
    84 	void AddCommand( Command aCmd );
       
    85 
       
    86 	void WaitForCompletion();
       
    87 	static TBool CheckProcessing( TAny* aSelf );
       
    88 	
       
    89 	VirtIo::MIoHandler& iIoHandler;
       
    90 	TUint iDataQueueId;
       
    91 	
       
    92 	TUint8* iCmdMem; // managed
       
    93 	TCommandPadded* iCmd; // unmanaged
       
    94 	TBufferInfo* iBufferInfo; // unmanaged
       
    95 	
       
    96 	StreamDirection iDirection;
       
    97 	};
       
    98 
       
    99 } // namespace Audio
       
   100 } // namespace VirtIo
       
   101 
       
   102 
       
   103 #endif