multimediacommsengine/mmceshared/inc/mcecommediastream.h
changeset 0 1bce908db942
child 9 5d1d815214a5
child 49 64c62431ac08
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2005 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:    
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #ifndef CMCECOMMEDIASTREAM_H
       
    22 #define CMCECOMMEDIASTREAM_H
       
    23 
       
    24 #include <e32std.h>  	
       
    25 #include <e32base.h>
       
    26 #include <s32strm.h>
       
    27 #include <in_sock.h>
       
    28 #include "mcemediastream.h"
       
    29 #include "mcedefs.h"
       
    30 #include "mceclientserver.h"
       
    31 #include "mcecomserializable.h"
       
    32 
       
    33 
       
    34 #ifdef MCE_COMMON_SERVER_SIDE
       
    35 
       
    36 #include <mmccinterfacedef.h>
       
    37 #include <mmccsecureinterface.h>
       
    38 
       
    39 class TMceMccComEvent;
       
    40 class CMceMediaManager;
       
    41 
       
    42 #endif//MCE_COMMON_SERVER_SIDE
       
    43 
       
    44 
       
    45 class TMceComFactory;
       
    46 class TMceComMediaStreamFactory;
       
    47 class TMceComEvent;
       
    48 class CMceComSession;
       
    49 class TMceMccComEvent;
       
    50 class CMceComCodec;
       
    51 class CMceComMediaSource;
       
    52 class CMceComMediaSink;
       
    53 class MMceComSerializationContext;
       
    54 class TMcePreconditions;
       
    55 class CSdpMediaField;
       
    56 
       
    57 #define IS_SENDSTREAM( stream )\
       
    58     ( ( stream )->iStreamType == CMceComMediaStream::ESendStream ||\
       
    59       ( stream )->iStreamType == CMceComMediaStream::ESendOnlyStream )
       
    60 
       
    61 #define IS_RECEIVESTREAM( stream )\
       
    62     ( ( stream )->iStreamType == CMceComMediaStream::EReceiveStream ||\
       
    63       ( stream )->iStreamType == CMceComMediaStream::EReceiveOnlyStream )
       
    64 
       
    65 
       
    66 const TBool KMceNoEndpointAdjustment = EFalse;
       
    67 const TBool KMceEndpointAdjustment = ETrue;
       
    68 const TBool KMceRoleAnswerer = ETrue;
       
    69 const TBool KMceRoleOfferer = EFalse;
       
    70 
       
    71 
       
    72 /**
       
    73  * 
       
    74  *
       
    75  * @lib 
       
    76  */
       
    77 class CMceComMediaStream: public CBase,
       
    78                           public MMceComSerializable
       
    79 
       
    80 	{
       
    81 
       
    82 
       
    83 public: // Destructor
       
    84 
       
    85     enum TStreamType
       
    86         {
       
    87         ELocalStream,
       
    88         ESendOnlyStream,
       
    89         EReceiveOnlyStream,
       
    90         ESendStream,
       
    91         EReceiveStream
       
    92         };
       
    93     
       
    94 public: // Destructor
       
    95 
       
    96 
       
    97     /**
       
    98     * Destructor.
       
    99     */
       
   100 	~CMceComMediaStream();
       
   101 	
       
   102 public: // Source and sink functions
       
   103 
       
   104     /**
       
   105     * Adds source to the stream.
       
   106     * @param aSource source to be added to the stream.
       
   107     */
       
   108 	void SetSourceL( CMceComMediaSource* aSource );
       
   109 
       
   110     /**
       
   111     * Adds sink to the stream.
       
   112     * @param aSink sink to be added to the stream.
       
   113     */
       
   114 	void AddSinkL( CMceComMediaSink* aSink );
       
   115 
       
   116     /**
       
   117     * Deletes sink
       
   118     * @param aIndex index of sink in the array
       
   119     */
       
   120     void DeleteSink( TInt aIndex );
       
   121 
       
   122     /**
       
   123     * Removes codec from stream
       
   124     * @param aCodec the codec
       
   125     */
       
   126     virtual void RemoveCodecL( CMceComCodec* aCodec ) = 0;
       
   127     
       
   128 	/**
       
   129 	* Clears list of codecs and deletes each codec in it.
       
   130 	*/
       
   131     virtual void DestroyCodecs() = 0;
       
   132 
       
   133     /**
       
   134     * Searches for codec matching with input codec instance or sdp name
       
   135     * @param aCodec the search term
       
   136     * @return matching codec or NULL if not found
       
   137     */
       
   138     virtual CMceComCodec* FindCodecL( CMceComCodec& aCodec ) = 0;
       
   139 
       
   140     /**
       
   141     * Adds codec to the stream.
       
   142     * @param aCodec codec to be added to the stream.
       
   143 	*	     Ownership is transferred.
       
   144     */
       
   145 	virtual void AddCodecL( CMceComCodec* aCodec ) = 0;
       
   146 
       
   147     /**
       
   148     * Gets source of the stream. Returns null is source not set.
       
   149     * @return source of the stream. Ownership is not transferred.
       
   150     */
       
   151 	CMceComMediaSource* Source();
       
   152 
       
   153     /**
       
   154     * Gets array of sinks of the stream.
       
   155     * @return array of sinks.
       
   156     */
       
   157 	RPointerArray<CMceComMediaSink>& Sinks();
       
   158 	
       
   159 	virtual void ReorderCodecs() = 0;
       
   160 
       
   161 
       
   162 public: // Binding opposite way stream
       
   163 
       
   164     /**
       
   165     * Binds opposite direction stream to this stream.
       
   166     * @param aStream another stream to be bind to the stream.
       
   167     */
       
   168 	 void BindL( CMceComMediaStream* aStream );
       
   169 
       
   170     /**
       
   171     * Gets opposite direction stream of this stream.
       
   172     * @return opposite direction stream.
       
   173     */
       
   174 	 CMceComMediaStream& BoundStreamL();
       
   175 
       
   176     /**
       
   177     * Checks if opposite direction stream is set.
       
   178     * @return ETrue if opposite direction stream is set.
       
   179     */
       
   180 	 TBool BoundStream() const;
       
   181 
       
   182     /**
       
   183     * Checks if this is binder (biding owner)
       
   184     * @return ETrue if this is binder (biding owner)
       
   185     */
       
   186 	TBool Binder() const;
       
   187 	
       
   188     /**
       
   189     * Gives 'main' stream
       
   190     * @return 'main' stream
       
   191     */
       
   192 	CMceComMediaStream& operator()();
       
   193 
       
   194     /**
       
   195     * Gives 'main' stream
       
   196     * @return 'main' stream
       
   197     */
       
   198 	const CMceComMediaStream& operator()() const;
       
   199 	
       
   200     /**
       
   201     * Gives send stream
       
   202     * @return send stream
       
   203     */
       
   204     CMceComMediaStream* SendStream();
       
   205     
       
   206     /**
       
   207     * Gives receive stream
       
   208     * @return receive stream
       
   209     */
       
   210     CMceComMediaStream* ReceiveStream();
       
   211 
       
   212     /**
       
   213     * Gives offer stream
       
   214     * @return offer stream
       
   215     */
       
   216     CMceComMediaStream* OfferStream();
       
   217 
       
   218     /**
       
   219     * Gives answer stream
       
   220     * @return answer stream
       
   221     */
       
   222     CMceComMediaStream* AnswerStream();
       
   223     
       
   224     /**
       
   225     * Gives sdp index
       
   226     * @return sdp index
       
   227     */
       
   228     TInt& SdpIndex();
       
   229     
       
   230     
       
   231 public: //from MMceComSerializable
       
   232 
       
   233     /**
       
   234     * Returns serialization id
       
   235     * @return serialization id
       
   236     */
       
   237     TUint64 SerializationId() const;
       
   238 
       
   239     /**
       
   240     * Internalizes flat data
       
   241     * @param aReadStream read stream
       
   242     */
       
   243     void InternalizeFlatL( RReadStream& aReadStream );
       
   244 
       
   245     /**
       
   246     * Externalizes flat data
       
   247     * @param aWriteStream write stream
       
   248     */
       
   249     void ExternalizeFlatL( RWriteStream& aWriteStream );
       
   250     
       
   251     /**
       
   252     * Internalizes
       
   253     * @param aSerCtx context for serialization
       
   254     */
       
   255     void InternalizeL( MMceComSerializationContext& aSerCtx );
       
   256     
       
   257     /**
       
   258     * Externalizes
       
   259     * @param aSerCtx context for serialization
       
   260     */
       
   261     void ExternalizeL( MMceComSerializationContext& aSerCtx );
       
   262     
       
   263 
       
   264 public: //serialization helpers
       
   265 
       
   266     /**
       
   267     * Factory
       
   268     * @return factory
       
   269     */
       
   270     TMceComFactory BaseFactory();
       
   271 
       
   272     /**
       
   273     * Factory
       
   274     * @return factory
       
   275     */
       
   276     static TMceComMediaStreamFactory Factory();
       
   277     
       
   278     /**
       
   279     * Adds source, during serialization, to the stream.
       
   280     * @param aSerCtx serialization context
       
   281     */
       
   282 	void SetSourceL( MMceComSerializationContext& aSerCtx );
       
   283 
       
   284     /**
       
   285     * Adds sink, during serialization, to the stream.
       
   286     * @param aSerCtx serialization context
       
   287     */
       
   288 	void AddSinkL( MMceComSerializationContext& aSerCtx );
       
   289 
       
   290     
       
   291 public:// new Functions
       
   292 
       
   293     /**
       
   294     * ID 
       
   295     * @return ID
       
   296     */
       
   297 	TMceMediaId Id() const;
       
   298 
       
   299     /**
       
   300     * Parent object
       
   301     * @return Parent object
       
   302     */
       
   303 	CMceComSession* Session() const;
       
   304 
       
   305 
       
   306     /**
       
   307     * Initializes 
       
   308     * @param aParent the parent
       
   309     */
       
   310     virtual void InitializeL( CMceComSession& aParent );
       
   311     
       
   312     /**
       
   313     * Traversal event handler
       
   314     * @param aEvent the event
       
   315     * @return status, if event was consumed or not or object needs update
       
   316     */
       
   317     virtual TInt EventReceivedL( TMceComEvent& aEvent );
       
   318 
       
   319     /**
       
   320     * Updates 
       
   321     * @param aStream new stream
       
   322     */
       
   323     virtual void UpdateL( CMceComMediaStream& aStream );
       
   324 
       
   325     /**
       
   326     * Clones whole stream object
       
   327     * @return cloned stream object
       
   328     */
       
   329     virtual CMceComMediaStream* CloneL() = 0;
       
   330 
       
   331     
       
   332 public:// new Functions
       
   333 
       
   334     /**
       
   335     * Returns ETrue, if enabled
       
   336     * @return ETrue, if enabled
       
   337     */
       
   338     virtual TBool IsEnabled();
       
   339     
       
   340     /**
       
   341     * Sets remote media port
       
   342     * @param aPort remote media port
       
   343     */
       
   344 	void SetRemoteMediaPort( TUint aPort );
       
   345 	
       
   346 	/**
       
   347     * Sets remote rtcp media address
       
   348     * @param aAddr remote rtcp media address
       
   349     */
       
   350 	void SetRemoteRtcpMediaAddrL( TDesC16& aAddr );
       
   351 	
       
   352     /**
       
   353     * Sets local media port
       
   354     * @param aPort local media port
       
   355     */
       
   356     void SetLocalMediaPort( TUint aPort );
       
   357 	
       
   358     /**
       
   359     * Gets remote media port
       
   360     * @return remote media port
       
   361     */
       
   362 	TUint RemoteMediaPort() const;
       
   363 	
       
   364     /**
       
   365     * Gets local media port
       
   366     * @return local media port
       
   367     */
       
   368 	TUint LocalMediaPort() const;
       
   369 	
       
   370     /**
       
   371     * Sets remote media port
       
   372     * @param aPort remote media port
       
   373     */
       
   374 	void SetRemoteRtcpMediaPort( TUint aPort );
       
   375 	
       
   376 	/**
       
   377 	* Checks whether remote media port has changed
       
   378 	* @return ETrue if port has changed, otherwise return EFalse
       
   379 	*/
       
   380 	TBool RemoteMediaPortChanged( TUint aNewPort );
       
   381 	
       
   382 	
       
   383 	/**
       
   384 	* Checks whether remote RTCP address, and port has changed 
       
   385 	* @return ETrue if port has changed, otherwise return EFalse
       
   386 	*/
       
   387 	TBool CMceComMediaStream::RemoteRTCPAddressChanged( TUint aNewPort, TInetAddr aAddr );
       
   388     
       
   389 		
       
   390 	/**
       
   391     * Stores remote port.
       
   392     * @param aIgnore, ETrue if remote port comparison should be ignored
       
   393     */
       
   394 	void SetIgnoreRemotePort( TBool aIgnore );
       
   395     
       
   396     TBool& DowngradedEndpoints();
       
   397     
       
   398 #ifdef MCE_COMMON_SERVER_SIDE
       
   399 
       
   400 public:// new (virtual) Functions
       
   401 
       
   402     /**
       
   403     * Called when stream has been decoded
       
   404     * @param aDecodedOffer is offer decoded
       
   405     */
       
   406     void DecodedL( TBool aRoleAnswerer );
       
   407     
       
   408     /**
       
   409     * Synchronizes stream's codecs.
       
   410     * @param aRoleAnswerer is answerer
       
   411     */
       
   412     virtual void SynchronizeL( TBool aRoleAnswerer ) = 0;
       
   413     
       
   414     /**
       
   415     * Update default codec to reflect current negotiation
       
   416     */
       
   417     virtual void UpdateDefaultCodecL() = 0;
       
   418 
       
   419     /**
       
   420     * Prepares
       
   421     */
       
   422     virtual void PrepareL() = 0;
       
   423 
       
   424     /**
       
   425     * Return mcc stream type
       
   426     * @return mcc stream type
       
   427     */
       
   428     virtual TInt MccStreamType() const = 0;
       
   429 
       
   430     /**
       
   431     * Return mcc link type
       
   432     * @return mcc link type
       
   433     */
       
   434     virtual TInt MccLinkType() const = 0;
       
   435 
       
   436     /**
       
   437     * Handles event received from mcc
       
   438     * @param aEvent the event from mcc
       
   439     */
       
   440     virtual void EventReceived( TMceMccComEvent& aEvent );
       
   441 
       
   442 public:// new Functions
       
   443         
       
   444     /**
       
   445     * Sets state 
       
   446     * @param aEvent the event from mcc
       
   447     */
       
   448     void SetState( TMceMccComEvent& aEvent );
       
   449     
       
   450     /**
       
   451     * Sets link id
       
   452     * @param aLinkId the link id
       
   453     */
       
   454     void SetLinkId( TUint32 aLinkId );
       
   455     
       
   456     /**
       
   457     * Gets direction
       
   458     * @return direction
       
   459     */
       
   460     TInt Direction();
       
   461     
       
   462     /**
       
   463     * Sets direction
       
   464     * @param aDirection direction
       
   465     * @param aEndpointAdjustment should endpoints follow
       
   466     */
       
   467     void SetDirection( TInt aDirection, TBool aEndpointAdjustment = KMceEndpointAdjustment );
       
   468     
       
   469     /**
       
   470     * Sets direction. Leaves if not allowed
       
   471     * @param aDirection direction
       
   472     */
       
   473     void SetDirectionL( TInt aDirection );
       
   474 
       
   475     /**
       
   476     * Sets stream enabled/disabled
       
   477     * @param aEnable if ETrue stream and sinks/source 
       
   478     * is set enabled
       
   479     * @param aEndpointAdjustment if endpoints follow
       
   480     */
       
   481     void Enable( TBool aEnable, TBool aEndpointAdjustment );
       
   482     
       
   483     /**
       
   484     * Gets SDP stream type
       
   485     * @return SDP stream type
       
   486     */
       
   487     TInt SdpStreamType();
       
   488     
       
   489     /**
       
   490     * Gets or creates preconditions
       
   491     * @param aModifier mce preconditon modifier
       
   492     * @param aMediaLine media line
       
   493     * @return preconditions
       
   494     */
       
   495     TMcePreconditions* PreconditionsL( TMceSessionModifier aModifier,
       
   496     									CSdpMediaField* aMediaLine = NULL );
       
   497 
       
   498     /**
       
   499     * Gets preconditions
       
   500     * @return preconditions
       
   501     */
       
   502     const RPointerArray<TMcePreconditions>& Preconditions() const ;
       
   503     
       
   504     /**
       
   505     * CopyPrecondition parameters 
       
   506     * @param aModifier mce preconditon modifier
       
   507     * @return void
       
   508     */
       
   509     void CopyPreconditionL( TMceSessionModifier aModifier );
       
   510 
       
   511     
       
   512     /**
       
   513     * Merges with stream
       
   514     */
       
   515     void Merge( CMceComMediaStream& aMergeWith );
       
   516 
       
   517 #endif//MCE_COMMON_SERVER_SIDE
       
   518 
       
   519     /**
       
   520     * Gets empty sink
       
   521     * @return empty sink
       
   522     */
       
   523     CMceComMediaSink& EmptySinkL();
       
   524     
       
   525     /**
       
   526     * Gets empty source
       
   527     * @return empty source
       
   528     */
       
   529     CMceComMediaSource& EmptySourceL();
       
   530     
       
   531 
       
   532     /**
       
   533     * Checks whether RTCP should be used.
       
   534     * return ETrue, if the source and all the sinks indicate RTCP usage,
       
   535     *        otherwise EFalse. 
       
   536     */
       
   537     TBool UseRtcp() const;
       
   538 
       
   539 protected:
       
   540 
       
   541 
       
   542     /**
       
   543      * C++ default constructor.
       
   544      * @param type of stream
       
   545      */
       
   546 	CMceComMediaStream( TMceMediaType aType );
       
   547 
       
   548     /**
       
   549     * second-phase constructor
       
   550     */
       
   551 	void ConstructL();
       
   552 	
       
   553     /**
       
   554      * second-phase copy constructor
       
   555      */
       
   556 	void ConstructL( CMceComMediaStream& aStream );
       
   557 	
       
   558 
       
   559 private: // methods
       
   560 
       
   561     /**
       
   562     * one-way bind
       
   563     * @param aStream another stream to be bind to the stream.
       
   564     */
       
   565     void DoBind( CMceComMediaStream* aStream );    
       
   566     
       
   567     /**
       
   568     * Deletes source
       
   569     */
       
   570 	void DeleteSource();
       
   571 	
       
   572 	/**
       
   573     * Checks whether RTCP should be used.
       
   574     * return ETrue, if the source and all the sinks indicate RTCP usage,
       
   575     *        otherwise EFalse. 
       
   576     */
       
   577 	TBool DoUseRtcp() const;
       
   578 
       
   579 public: // Owned serialized Data
       
   580 
       
   581     /**
       
   582      * ID
       
   583      */
       
   584     TMceMediaId iID;
       
   585 
       
   586     /**
       
   587      * type
       
   588      */
       
   589     TMceMediaType iType;
       
   590     
       
   591     /**
       
   592      * state, enabled or disabled
       
   593      */
       
   594     TBool iIsEnabled;
       
   595     
       
   596 	/**
       
   597     * Local port
       
   598     */
       
   599 	TUint iLocalMediaPort;
       
   600 
       
   601 	/**
       
   602     * Remote port
       
   603     */
       
   604 	TUint iRemoteMediaPort;
       
   605     
       
   606     /**
       
   607     * Remote RTCP IP-address (IPv4 or IPv6)
       
   608     */    
       
   609     TInetAddr iRemoteRtcpAddress;
       
   610     
       
   611     /**
       
   612     * Remote RTCP port, if 0 then use RTP port + 1
       
   613     */
       
   614 	TUint iRemoteRtcpPort;
       
   615 	
       
   616     /**
       
   617      * local sdp media lines
       
   618      */
       
   619     CDesC8Array* iLocalMediaSDPLines;
       
   620 
       
   621     /**
       
   622      * remote sdp media lines
       
   623      */
       
   624     CDesC8Array* iRemoteMediaSDPLines;
       
   625 
       
   626     /**
       
   627      * stream type
       
   628      */
       
   629     TStreamType iStreamType;
       
   630     
       
   631     /**
       
   632      * stream state
       
   633      */
       
   634     CMceMediaStream::TState iState;
       
   635     
       
   636     /**
       
   637     * ignore remote port comparison
       
   638     */
       
   639     TBool iIgnoreRemotePort;
       
   640 
       
   641     /**
       
   642      * does this owns the link
       
   643      */
       
   644     TBool iLinkOwner;
       
   645 
       
   646     /**
       
   647      * linked stream. Owned if iLinkOwner is ETrue
       
   648      */
       
   649     CMceComMediaStream* iLinkedStream;
       
   650     
       
   651     /**
       
   652      * source
       
   653      */
       
   654 	CMceComMediaSource* iSource;
       
   655 	
       
   656     /**
       
   657      * sinks
       
   658      */
       
   659 	RPointerArray<CMceComMediaSink> iSinks;
       
   660 
       
   661     /**
       
   662      * sdp index
       
   663      */
       
   664     TInt iSdpIndex;
       
   665     
       
   666     /**
       
   667      * link id
       
   668      */
       
   669     TUint32 iLinkId;
       
   670     
       
   671     /**
       
   672      * preconditions
       
   673      */
       
   674     RPointerArray <TMcePreconditions> iPreconditions;
       
   675     
       
   676     /**
       
   677      * empty source
       
   678      */
       
   679     CMceComMediaSource* iEmptySource;
       
   680     
       
   681     /**
       
   682      * empty sink
       
   683      */
       
   684     CMceComMediaSink* iEmptySink;
       
   685     
       
   686     
       
   687 protected: // NOT owned data
       
   688 	
       
   689     /**
       
   690      * session
       
   691      */
       
   692 	CMceComSession* iSession;
       
   693 
       
   694 private:
       
   695 
       
   696     TBool iDowngradedEnpoints;
       
   697 
       
   698 #ifdef EUNIT_TEST
       
   699 	friend class UT_CMceMediaSdpCodec;
       
   700     friend class UT_CMceAudioSdpCodec;
       
   701     friend class UT_CMceVideoSdpCodec;
       
   702 
       
   703 #endif    
       
   704 	};
       
   705 
       
   706 
       
   707 #endif