bluetoothengine/btaudiostreamer/inc/btaudiostreamer.h
changeset 0 f63038272f30
equal deleted inserted replaced
-1:000000000000 0:f63038272f30
       
     1 /*
       
     2 * Copyright (c) 2005-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:  This is an interface class that exports streamer's functions 
       
    15 *                for its clients. The functionality is implemented in 
       
    16 *                BTAudioStreamerSender, this class forwards the function 
       
    17 *                calls to it. 
       
    18 *
       
    19 */
       
    20 
       
    21 
       
    22 #ifndef __BTAUDIOSTREAMER_H__
       
    23 #define __BTAUDIOSTREAMER_H__
       
    24 
       
    25 #include <in_sock.h>
       
    26 #include <rtp.h> 
       
    27 
       
    28 #include "btaudiostreaminputbase.h" 
       
    29 
       
    30 class CBTAudioStreamSender; 
       
    31 
       
    32 /**
       
    33  *  An observer pattern. 
       
    34  *
       
    35  *  This class defines an observer interface for BT Audio Stream Sender. 
       
    36  *
       
    37  *  @lib btaudiostreamer.lib
       
    38  *  @since S60 v3.1 
       
    39  */
       
    40 NONSHARABLE_CLASS(MBTAudioStreamSenderObserver) 
       
    41     {
       
    42     public:
       
    43     virtual void NotifyBufferSent(const TDesC8& aBuffer ) = 0;         // Buffer sent. 
       
    44     virtual void NotifyErrorSending(const TDesC8& aBuffer ) = 0;    // Could not send a packet at all. 
       
    45     };
       
    46 
       
    47 /**
       
    48  *  BT Audio Streamer class. 
       
    49  *
       
    50  *  This class implements the audio streaming over A2DP. 
       
    51  *  It acts as an interface between the controller, BT Audio Adaptation and RTP API. 
       
    52  *  It uses helper class CBTAudioStreamSender to handle 
       
    53  *  the frame contruction and sending. 
       
    54  *
       
    55  *  @lib btaudiostreamer.lib
       
    56  *  @since S60 v3.1 
       
    57  */
       
    58 class CBTAudioStreamer : public CBase, public MBTAudioStreamObserver, public MBTAudioStreamSenderObserver 
       
    59     {
       
    60     public:
       
    61 
       
    62     IMPORT_C static CBTAudioStreamer* NewL(); 
       
    63     
       
    64     /**
       
    65      * A method for preparing the BT Audio Streamer for incoming data. 
       
    66      *
       
    67      * @since S60 v3.1
       
    68      * @param aSocket Bluetooth socket instance, needed for getting the RTP sending class instance. 
       
    69      * @param aFrameLength Length of a single audio data frame, needed for calculating the send packet size. 
       
    70      * @param aAudioInput The API where the data is received and where the sending of packets will be confirmed. 
       
    71      * @return void. 
       
    72      */
       
    73     IMPORT_C TInt SetNewFrameLength(const TUint aFrameLength, const TUint aTargetBitrate);
       
    74 
       
    75     /**
       
    76      * A method for preparing the BT Audio Streamer for incoming data. 
       
    77      *
       
    78      * @since S60 v3.1
       
    79      * @param aSocket Bluetooth socket instance, needed for getting the RTP sending class instance. 
       
    80      * @param aFrameLength Length of a single audio data frame, needed for calculating the send packet size. 
       
    81      * @param aAudioInput The API where the data is received and where the sending of packets will be confirmed. 
       
    82      * @return void. 
       
    83      */
       
    84     IMPORT_C void StartL(RSocket& aSocket, const TUint aFrameLength, CBTAudioStreamInputBase* aAudioInput, const TUint aTargetBitrate);
       
    85 
       
    86     /**
       
    87      * A method for cleaning up the BT Audio Streamer after streaming data. 
       
    88      *
       
    89      * @since S60 v3.1
       
    90      * @param void. 
       
    91      * @return void. 
       
    92      */
       
    93     IMPORT_C void Stop(); 
       
    94 
       
    95     virtual ~CBTAudioStreamer();
       
    96 
       
    97     /**
       
    98      * From MBTAudioStreamObserver.
       
    99      * This method receives data from the data producer. 
       
   100      *
       
   101      * @since S60 v3.1
       
   102      * @param aBuffer contains the audio data frames. 
       
   103      * @return a Symbian OS wide error code. 
       
   104      */
       
   105     TInt Receive(const TDesC8& aBuffer);
       
   106 
       
   107     /**
       
   108      * From MBTAudioStreamObserver.
       
   109      * This method receives data and timestamps from the data producer. 
       
   110      *
       
   111      * @since S60 v3.1
       
   112      * @param aBuffer contains the audio data frames. 
       
   113      * @param aTimestamp The timestamp of the audio data frames. 
       
   114      *                   34 minutes max. interval should not be a problem to us. 
       
   115      * @return a Symbian OS wide error code. 
       
   116      */
       
   117     TInt Receive(const TDesC8& aBuffer, TTimeIntervalMicroSeconds aTimestamp);
       
   118 
       
   119     /**
       
   120      * From MBTAudioStreamSenderObserver.
       
   121      * This method is used for reporting that the referred buffer has been sent. 
       
   122      * This tells the data producer that we're ready to receive more data. 
       
   123      *
       
   124      * @since S60 v3.1
       
   125      * @param aBuffer refers to the original bufffer that we received in Receive method. 
       
   126      * @return void. 
       
   127      */
       
   128     void NotifyBufferSent( const TDesC8& aBuffer );  
       
   129 
       
   130     /**
       
   131      * From MBTAudioStreamSenderObserver.
       
   132      * This method is used for reporting that the buffer wasn't sent because of an error. 
       
   133      * This method then informs the error observer class. 
       
   134      *
       
   135      * @since S60 v3.1
       
   136      * @param aBuffer refers to the original bufffer that we received in Receive method. 
       
   137      * @return void. 
       
   138      */
       
   139     void NotifyErrorSending( const TDesC8& aBuffer );  
       
   140 
       
   141     private:
       
   142     CBTAudioStreamer();
       
   143     void ConstructL();
       
   144 
       
   145     private:
       
   146     /**
       
   147      * This stores a pointer to the audio input interface. 
       
   148      * After a buffer has been processed, this interface must be informed. 
       
   149      */
       
   150     CBTAudioStreamInputBase* iAudioInput; 
       
   151 
       
   152     /**
       
   153      * This points to a helper class that handles the sending of a frame. 
       
   154      * Own.  
       
   155      */
       
   156     CBTAudioStreamSender* iSender; 
       
   157 
       
   158     /**
       
   159      * RTP session object that is needed for sending RTP frames. 
       
   160      */
       
   161     RRtpSession iRtpSession;
       
   162 
       
   163     /**
       
   164      * This stores the state of the streamer. 
       
   165      */
       
   166 		TBool iStarted;
       
   167 
       
   168     }; 
       
   169 
       
   170 #endif // __BTAUDIOSTREAMER_H__