mmfenh/enhancedmediaclient/Client/src/Components/ClientDataBufferSource/ClientDataBufferSource.cpp
changeset 0 71ca22bcf22a
equal deleted inserted replaced
-1:000000000000 0:71ca22bcf22a
       
     1 /*
       
     2 * Copyright (c) 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:  Implementation of the ClientDataBufferSource class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include "ClientDataBufferSource.h"
       
    21 #include "DataBufferQueueItem.h"
       
    22 #include "DataBufferSourceCustomCommands.h"
       
    23 #include "EventNotifier.h"
       
    24 #include "DataBufferProcessedEvent.h"
       
    25 #include "DataBufferSourceUid.h"
       
    26 #include "DRMConfigIntfcImpl.h"
       
    27 
       
    28 #include <e32std.h>
       
    29 #include <MCustomCommand.h>
       
    30 #include <DataBuffer.h>
       
    31 #include <MimeTypes.h>
       
    32 #include <SourceControlObserver.h>
       
    33 #include "tracemacros.h"
       
    34 
       
    35 #define RETURN_IF_ERROR(x) if(x != KErrNone) return x
       
    36 
       
    37 using namespace multimedia;
       
    38 
       
    39 // CONSTANTS
       
    40 const TInt KMinBufferSize = 5120;
       
    41 
       
    42 
       
    43 CClientDataBufferSource::CClientDataBufferSource()
       
    44 :iDRMType(ENone)
       
    45     {
       
    46 	iFixedDurationSupport = false;
       
    47     }
       
    48 
       
    49 CClientDataBufferSource::~CClientDataBufferSource()
       
    50     {
       
    51     delete iMimeType;
       
    52     EmptyQueue();
       
    53     delete iEventNotifier;
       
    54     delete iAudioBufferQueue;
       
    55     delete iBufTypeSupportEvent;
       
    56     iAllowedOutputDeviceList.Close();
       
    57     }
       
    58 
       
    59 TInt CClientDataBufferSource::PostConstructor()
       
    60     {
       
    61     TInt status(KErrNone);
       
    62     // Make sure this doesn't get called second time around.
       
    63     if ( !iEventNotifier )
       
    64         {
       
    65         TRAP(status, iEventNotifier = CEventNotifier::NewL());
       
    66         }
       
    67     
       
    68     RETURN_IF_ERROR(status);
       
    69     
       
    70     iAudioBufferQueue = new TSglQue<CDataBufferQueueItem>(_FOFF(CDataBufferQueueItem, iLink));
       
    71     if (!iAudioBufferQueue)
       
    72         {
       
    73         status = KErrNoMemory;
       
    74         }
       
    75     RETURN_IF_ERROR(status);
       
    76     
       
    77     TRAP(status,iBufTypeSupportEvent  = CBufTypeSupEventAO::NewL(*this)); 
       
    78     
       
    79     return status;
       
    80     }
       
    81 
       
    82 TInt CClientDataBufferSource::AddObserver( MControlObserver& aObserver )
       
    83     {
       
    84     return iEventNotifier->AddObserver( aObserver );
       
    85     }
       
    86 
       
    87 TInt CClientDataBufferSource::RemoveObserver( MControlObserver& aObserver )
       
    88     {
       
    89     return iEventNotifier->RemoveObserver( aObserver );
       
    90     }
       
    91 
       
    92 TUid CClientDataBufferSource::Type()
       
    93     {
       
    94     return KDataBufferSourceControl;
       
    95     }
       
    96 
       
    97 TControlType CClientDataBufferSource::ControlType()
       
    98     {
       
    99     return ESourceControl;
       
   100     }
       
   101 
       
   102 TInt CClientDataBufferSource::GetSize( TUint& aSize )
       
   103     {
       
   104     TInt status(KErrNone);
       
   105     aSize = iSourceSize;
       
   106     return status;
       
   107     }
       
   108 
       
   109 TInt CClientDataBufferSource::GetMimeType( TDes8& aMimeType )
       
   110     {
       
   111     aMimeType.Copy(*iMimeType);
       
   112     return KErrNone;
       
   113     }
       
   114 
       
   115 TInt CClientDataBufferSource::Close()
       
   116     {
       
   117     TInt status(KErrNone);
       
   118     iBufferSeqNum = 0;
       
   119     return status;
       
   120     }
       
   121     
       
   122 TInt CClientDataBufferSource::Open( TDesC8& aMimeType , MDataBuffer& /*aHeaderData */)
       
   123     {
       
   124     TInt status(KErrNotSupported);
       
   125     // Source is already attached to controller
       
   126     if ( iServerSourceExists )
       
   127         {
       
   128         status = KErrInUse;
       
   129         }
       
   130     else
       
   131         {
       
   132         delete iMimeType;
       
   133         iMimeType = NULL;
       
   134         TRAP( status, iMimeType = aMimeType.AllocL() );
       
   135         iBufferSeqNum = 0;
       
   136         }
       
   137     return status;
       
   138     }
       
   139 
       
   140 TInt CClientDataBufferSource::GetMinimumBufferSize( TUint& aBufferSize )
       
   141     {
       
   142     TInt status(KErrNone);
       
   143     aBufferSize = KMinBufferSize;
       
   144     return status;
       
   145     }
       
   146 
       
   147 TInt CClientDataBufferSource::SetSize( TUint aSize )
       
   148     {
       
   149     TInt status(KErrNone);
       
   150     iSourceSize = aSize;
       
   151     if ( iServerSourceExists )
       
   152         {
       
   153         TPckgBuf<TInt> pckg(aSize);
       
   154         status = iCustomCommand->CustomCommandSync( iSourceHandlePckg, ESetSize, pckg, KNullDesC8 );
       
   155         }
       
   156     return status;
       
   157     }
       
   158 
       
   159 TInt CClientDataBufferSource::WriteData(MDataBuffer& aBuffer )
       
   160     {
       
   161     EMC_TRACE3(_L("CClientDataBufferSource::WriteData:size[%d]lastbuf[%d]"), \
       
   162             aBuffer.GetBufferPtr().Length(), aBuffer.IsLastBuffer());
       
   163 /*
       
   164 	TUint8* bufPtr = const_cast<TUint8*>(aBuffer.GetBufferPtr().Ptr());
       
   165 	if ( aBuffer.GetBufferPtr().Length() > 5 )
       
   166     	{
       
   167     	RDebug::Print(_L("CClientDataBufferSource::WriteData data[0x%x][0x%x][0x%x][0x%x][0x%x]"), \
       
   168     	*bufPtr,*(bufPtr+1),*(bufPtr+2),*(bufPtr+3),*(bufPtr+4));
       
   169         }
       
   170 */
       
   171 
       
   172     TInt status(KErrNotReady);
       
   173     // For now we can only write audio data only if controller is loaded
       
   174     // and source is added to controller.
       
   175     if ( iServerSourceExists )
       
   176         {
       
   177         // Append item to queue
       
   178         CDataBufferQueueItem* item(NULL);
       
   179         TRAP(status, item  = CDataBufferQueueItem::NewL( *this,
       
   180                                                          aBuffer,
       
   181                                                          aBuffer.IsLastBuffer(),
       
   182                                                          iBufferSeqNum ));
       
   183         RETURN_IF_ERROR(status);
       
   184         
       
   185         iAudioBufferQueue->AddLast(*item);
       
   186 
       
   187         // Send data to server source
       
   188         item->SetActive();
       
   189         TPckgBuf<TUint> bufSeqNum;
       
   190         bufSeqNum() = iBufferSeqNum;
       
   191         iCustomCommand->CustomCommandAsync(
       
   192             iSourceHandlePckg,
       
   193             (TInt)EProcessBuffer,
       
   194             aBuffer.GetBufferPtr(),
       
   195             item->GetDataBufferAttributesDesc(),
       
   196             item->iStatus);
       
   197         status = KErrNone;
       
   198         iBufferSeqNum++;
       
   199         }
       
   200     return status;
       
   201     }
       
   202 
       
   203 TInt CClientDataBufferSource::EmptyBuffers()
       
   204     {
       
   205     TInt status(KErrNone);
       
   206     return status;
       
   207     }
       
   208 
       
   209 TInt CClientDataBufferSource::GetBufferingConfig(TBufferingConfig& aConfig)
       
   210     {
       
   211 	TPckgBuf<TBufferingConfig> pckg;
       
   212     if(iServerSourceExists)
       
   213         {
       
   214 		iCustomCommand->CustomCommandSync( iSourceHandlePckg, EGetCurrentBufferingConfig, KNullDesC8, KNullDesC8, pckg );
       
   215 		aConfig = pckg();
       
   216 		return KErrNone;
       
   217         }
       
   218     else
       
   219         {
       
   220 		return KErrNotFound;    
       
   221         }
       
   222     }
       
   223     
       
   224 TInt CClientDataBufferSource::SetBufferingConfig(TBufferingConfig aConfig)
       
   225     {
       
   226 	TPckgBuf<TBufferingConfig> pckg(aConfig);
       
   227 	if ( iServerSourceExists)
       
   228 		{
       
   229 		iCustomCommand->CustomCommandSync( iSourceHandlePckg, ESetBufferingConfig, pckg, KNullDesC8 );              
       
   230 		return KErrNone;    
       
   231 		}
       
   232 	else
       
   233 		{
       
   234 		return KErrNotFound;    
       
   235 		}
       
   236     }
       
   237     
       
   238 TInt CClientDataBufferSource::GetBitRate(TUint& aRate)
       
   239     {
       
   240     //Source Custom Command
       
   241     TPckgBuf<TUint> pckg;
       
   242     if(iServerSourceExists)
       
   243         {
       
   244 		iCustomCommand->CustomCommandSync( iSourceHandlePckg, EGetBitRate, KNullDesC8, KNullDesC8, pckg );
       
   245 		aRate = pckg();
       
   246 		return KErrNone;
       
   247         }
       
   248     else
       
   249         {
       
   250 		aRate = 0;
       
   251 		return KErrNotFound;    
       
   252         }
       
   253     }
       
   254               
       
   255 TInt CClientDataBufferSource::GetBufferingTypesSupported(TArray<TBufferingConfig::TBufferingType>& aArray)
       
   256     {
       
   257 	RArray<TBufferingConfig::TBufferingType> temp;
       
   258 	temp.Array() = aArray;
       
   259 	temp.Append(TBufferingConfig::BUFFERINGNONE);
       
   260 	temp.Append(TBufferingConfig::FIXEDSIZE);
       
   261 	if(iFixedDurationSupport)
       
   262 		{
       
   263         temp.Append(TBufferingConfig::FIXEDDURATION);
       
   264 		}
       
   265 	aArray = temp.Array();
       
   266 	return KErrNone;
       
   267     }
       
   268 
       
   269 TInt CClientDataBufferSource::GetInterface(
       
   270                                 TUid aInterfaceId,
       
   271                                 TVersion& aVer,
       
   272                                 TAny*& aInterfaceImpl )
       
   273     {
       
   274     TInt status(KErrNotFound);
       
   275     aInterfaceImpl = NULL;
       
   276     if ( ( aInterfaceId == KDRMConfigIntfc ) &&
       
   277          ( ( aVer.iMajor == KDRMConfigIntfcMajorVer1 ) &&
       
   278            ( aVer.iMinor == KDRMConfigIntfcMinorVer1 ) &&
       
   279            ( aVer.iBuild == KDRMConfigIntfcBuildVer1 ) ) )
       
   280             {
       
   281             CDRMConfigIntcfImpl* temp(NULL);
       
   282             TRAP(status, temp = CDRMConfigIntcfImpl::NewL(*this));
       
   283             if ( status == KErrNone )
       
   284                 {
       
   285                 this->SetChild(*((CChildIntfc*)temp));
       
   286                 temp->SetParent(*(CParentIntfc*)this);
       
   287                 aInterfaceImpl = (CDRMConfigIntfc*)temp;
       
   288                 }
       
   289             }
       
   290     return status;
       
   291     }
       
   292 
       
   293 void CClientDataBufferSource::ServerSourceCreated( MCustomCommand& aCustomCommand,
       
   294                                                      TMMFMessageDestination& aSourceHandle )
       
   295     {
       
   296     iServerSourceExists = ETrue;
       
   297     iCustomCommand = &aCustomCommand;
       
   298     iSourceHandle = aSourceHandle;    
       
   299     iSourceHandlePckg() = aSourceHandle;
       
   300     
       
   301     // Send DRM Config to server side plugin
       
   302     TRAP_IGNORE( DoCommitDRMConfigL() );
       
   303     
       
   304     iBufTypeSupportEvent->SetActive();
       
   305     iCustomCommand->CustomCommandAsync(
       
   306         iSourceHandlePckg,
       
   307         (TInt)EGetBufferingConfigSupported,
       
   308         KNullDesC8,
       
   309         KNullDesC8,
       
   310         iBufTypeSupportEvent->iStatus);
       
   311     
       
   312     }
       
   313 
       
   314 void CClientDataBufferSource::ServerSourceDeleted()
       
   315     {
       
   316     iServerSourceExists = EFalse;
       
   317     iCustomCommand = NULL;
       
   318     // Do client buffer cleanup
       
   319     // It should've already been done when server side source was deleted.
       
   320     // This is just to make sure.
       
   321     }
       
   322 
       
   323 TBool CClientDataBufferSource::IsEncrypted()
       
   324     {
       
   325 	return KErrNotSupported;   
       
   326     }
       
   327     
       
   328 TUid CClientDataBufferSource::GetSourceUid()
       
   329     {
       
   330 	return KMmfDataBufferSource;
       
   331     }
       
   332     
       
   333 TInt CClientDataBufferSource::GetHeaderData(TPtr& /*aPtr*/)
       
   334     {
       
   335 	return KErrNotSupported;      
       
   336     }
       
   337 
       
   338 
       
   339 void CClientDataBufferSource::BufferProcessed( CDataBufferQueueItem* aItem )
       
   340     {
       
   341     // Create a event object
       
   342     CDataBufferProcessedEvent* event = new CDataBufferProcessedEvent(
       
   343         &(aItem->DataBuffer()),
       
   344         aItem->Error() );
       
   345     
       
   346     // Remove the item from the list and delete it.
       
   347     iAudioBufferQueue->Remove(*aItem);
       
   348     delete aItem;
       
   349     
       
   350     // Send event to client that buffer is processed
       
   351     iEventNotifier->Event( this, MSourceControlObserver::KBufferProcessedEvent, event );
       
   352     }
       
   353 
       
   354 void CClientDataBufferSource::HandleCancel( CDataBufferQueueItem& aItem )
       
   355     {
       
   356     EMC_TRACE1(_L("CClientDataBufferSource::HandleCancel:"));
       
   357     if ( iServerSourceExists )
       
   358         {
       
   359         TPckgBuf<TUint> bufSeqPckg(aItem.GetBufferSequenceNumber());
       
   360         iCustomCommand->CustomCommandSync(
       
   361                 iSourceHandlePckg,
       
   362                 (TInt)ECancel,
       
   363                 bufSeqPckg,
       
   364                 KNullDesC8
       
   365                 );
       
   366         }
       
   367     else
       
   368         {
       
   369         aItem.CompleteSelf(KErrDied);
       
   370         }
       
   371     }
       
   372 
       
   373 void CClientDataBufferSource::BufferingTypesSupportedChanged()
       
   374 	{
       
   375 	iFixedDurationSupport = true;
       
   376 	}
       
   377 
       
   378 TInt CClientDataBufferSource::SetDRMType( TDRMType aDRMType )
       
   379     {
       
   380     TInt status(KErrNone);
       
   381     switch (aDRMType)
       
   382         {
       
   383         case ENone:
       
   384         case EOMA1:
       
   385         case EOMA2:
       
   386         case EWMDRM:
       
   387             iDRMType = aDRMType;
       
   388             break;
       
   389         default:
       
   390             status = KErrArgument;
       
   391             break;
       
   392         };
       
   393     return status;
       
   394     }
       
   395 
       
   396 TInt CClientDataBufferSource::GetDRMType( TDRMType& aDRMType )
       
   397     {
       
   398     TInt status(KErrNone);
       
   399     aDRMType = iDRMType;
       
   400     return status;
       
   401     }
       
   402 
       
   403 TInt CClientDataBufferSource::AppendAllowedOutputDevice( TDRMAllowedOutputDevice aOutputDevice )
       
   404     {
       
   405     TInt status(KErrAlreadyExists);
       
   406     switch (aOutputDevice)
       
   407         {
       
   408         case EAudioAllowAll:
       
   409         case EAudioAllowAnalog:
       
   410         case EAudioAllowFMTx:
       
   411         case EAudioAllowBTA2DP:
       
   412         case EAudioAllowBTHFPHSP:
       
   413         case EAudioAllowUplink:
       
   414         case EAudioAllowUSB:
       
   415         case EAudioAllowRecording:
       
   416         case EAudioAllowVisualization:
       
   417 		/**
       
   418 		* RIM CR 417-7642: HDMI with HDCP to Resctricted Audio Output API
       
   419 		* Due to addition of new ENUMs to CRestrictedAudioOutput::TAllowedOutputPreference for HDMI and HDCP
       
   420 		* EAllowAudioHDMI and EAllowAudioHdmiHdcpRequired,the same is matched by adding
       
   421 		* EAudioAllowHDMI and EAudioAllowHdmiHdcpRequired
       
   422 		*/
       
   423 		case EAudioAllowHDMI:
       
   424 		case EAudioAllowHdmiHdcpRequired:
       
   425             if ( iAllowedOutputDeviceList.Find( aOutputDevice ) == KErrNotFound )
       
   426                 {
       
   427                 status = iAllowedOutputDeviceList.Append( aOutputDevice );
       
   428                 }
       
   429             break;
       
   430         default:
       
   431             status = KErrArgument;
       
   432             break;
       
   433         };
       
   434     return status;
       
   435     }
       
   436 
       
   437 TInt CClientDataBufferSource::RemoveAllowedOutputDevice( TDRMAllowedOutputDevice aOutputDevice )
       
   438     {
       
   439     TInt status = iAllowedOutputDeviceList.Find( aOutputDevice );
       
   440     if ( status == KErrNotFound )
       
   441         {
       
   442         iAllowedOutputDeviceList.Remove(status);
       
   443         status = KErrNone;
       
   444         }
       
   445     return status;
       
   446     }
       
   447 
       
   448 TInt CClientDataBufferSource::GetAllowedOutputDeviceCount( TInt& aCount )
       
   449     {
       
   450     TInt status(KErrNone);
       
   451     aCount = iAllowedOutputDeviceList.Count();
       
   452     return status;
       
   453     }
       
   454 
       
   455 TInt CClientDataBufferSource::GetAllowedOutputDevice( TInt aIndex, TDRMAllowedOutputDevice& aOutputDevice )
       
   456     {
       
   457     TInt status(KErrArgument);
       
   458     if ( aIndex <= iAllowedOutputDeviceList.Count() )
       
   459         {
       
   460         aOutputDevice = iAllowedOutputDeviceList[aIndex];
       
   461         status = KErrNone;
       
   462         }
       
   463     return status;
       
   464     }
       
   465 
       
   466 TInt CClientDataBufferSource::ResetDRMConfig()
       
   467     {
       
   468     iDRMType = ENone;
       
   469     iAllowedOutputDeviceList.Reset();
       
   470     return KErrNone;
       
   471     }
       
   472 
       
   473 TInt CClientDataBufferSource::CommitDRMConfig()
       
   474     {
       
   475     TInt status(KErrNone);
       
   476     TRAP(status, DoCommitDRMConfigL());
       
   477     return status;
       
   478     }
       
   479 
       
   480 void CClientDataBufferSource::EmptyQueue()
       
   481     {
       
   482     CDataBufferQueueItem* bufferItem;
       
   483     while ( !iAudioBufferQueue->IsEmpty() )
       
   484         {
       
   485         bufferItem = iAudioBufferQueue->First();
       
   486         iAudioBufferQueue->Remove(*bufferItem);
       
   487         delete bufferItem;
       
   488         }
       
   489     }
       
   490 
       
   491 void CClientDataBufferSource::DoCommitDRMConfigL()
       
   492     {
       
   493     if ( iServerSourceExists )
       
   494         {
       
   495         // Package DRM Info into a descriptor and send it to server side plugin
       
   496         TInt descSize = sizeof(TDRMType); // For iDRMType
       
   497         descSize += sizeof(TInt); // For array size
       
   498         descSize += (iAllowedOutputDeviceList.Count() * sizeof(TDRMAllowedOutputDevice)); // For array
       
   499 
       
   500         HBufC8* buf(NULL);
       
   501         buf = HBufC8::NewL(descSize);
       
   502         CleanupStack::PushL(buf);
       
   503         
       
   504     	RDesWriteStream stream;
       
   505         TPtr8 ptr = buf->Des();
       
   506     	stream.Open(ptr);
       
   507     	CleanupClosePushL(stream);
       
   508     	
       
   509     	// Write DRM Type
       
   510     	stream.WriteInt32L(iDRMType);
       
   511     	// Write Allowed Output Device Count
       
   512     	stream.WriteInt32L(iAllowedOutputDeviceList.Count());
       
   513     	// Write Allowed Output Device enumeration
       
   514     	for (TInt i=0;i<iAllowedOutputDeviceList.Count();i++)
       
   515     	    {
       
   516     		stream.WriteInt32L(iAllowedOutputDeviceList[i]);
       
   517     	    }
       
   518     	ptr.SetLength(descSize);
       
   519         User::LeaveIfError(iCustomCommand->CustomCommandSync( iSourceHandlePckg, ESetDRMConfig, ptr, KNullDesC8 ));
       
   520         
       
   521     	// Delete objects
       
   522     	CleanupStack::PopAndDestroy(&stream);//stream
       
   523     	CleanupStack::PopAndDestroy(buf);//stream
       
   524         }
       
   525     }
       
   526 
       
   527 // End of file