Update contrib.
1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // @file hostisochronoustransfers.cpp
19 #include "hosttransfers.h"
25 namespace NUnitTesting_USBDI
28 CIsochTransfer::CIsochTransfer(RUsbPipe& aPipe,RUsbInterface& aInterface,TUint16 aMaxPacketSize,
29 TInt aMaxNumPackets,MTransferObserver& aObserver,TInt aTransferId)
30 : CBaseTransfer(aPipe,aInterface,aObserver,aTransferId),
31 iTransferDescriptor(aMaxPacketSize,aMaxNumPackets),
32 iMaxPacketSize(aMaxPacketSize)
34 RDebug::Printf("aMaxPacketSize = %d, aMaxNumPackets = %d",aMaxPacketSize, aMaxNumPackets);
37 CIsochTransfer::~CIsochTransfer()
41 // Cancel the transfer
46 TBool CIsochTransfer::DataPolled(TUint aPacketsToBeRead, RBuf8& aDataPolled)
49 TInt numOfPacketsReturned = 0;
51 TInt firstPacketIndex = 0;
52 TInt totalPacketsRead = 0;
53 TInt packetsToBeRead = aPacketsToBeRead;
55 TUint dataPolledBufSize = iMaxPacketSize*aPacketsToBeRead;
56 aDataPolled.CreateL(dataPolledBufSize);
59 TPtrC8 ptrRet = iTransferDescriptor.Packets(firstPacketIndex, packetsToBeRead, numOfPacketsReturned);
60 RDebug::Printf("numOfPacketsReturned = %d", numOfPacketsReturned);
61 RDebug::Printf("ptrRet.Length() = %d", ptrRet.Length());
62 firstPacketIndex = numOfPacketsReturned;
63 totalPacketsRead += numOfPacketsReturned;
64 packetsToBeRead = packetsToBeRead - numOfPacketsReturned;
65 RDebug::Printf("totalPacketsRead = %d", totalPacketsRead);
66 RDebug::Printf("packetsToBeRead = %d", packetsToBeRead);
67 aDataPolled.Append(ptrRet);
68 } while(totalPacketsRead != aPacketsToBeRead);
74 TInt CIsochTransfer::TransferInL(TInt aPacketsExpected)
78 // Activate the asynchronous transfer
79 RDebug::Printf("Activating isoch. in transfer");
81 iTransferDescriptor.Reset();
82 TPacketLengths fullLengths = iTransferDescriptor.Lengths();
84 for(TInt packet = 0; packet < fullLengths.MaxNumPackets(); packet++)
86 fullLengths[packet] = iMaxPacketSize;
89 RDebug::Printf("fullLengths.MaxNumPackets() == %d",fullLengths.MaxNumPackets());
90 iTransferDescriptor.ReceivePackets(aPacketsExpected);
92 Pipe().Transfer(iTransferDescriptor,iStatus);
97 TInt CIsochTransfer::RegisterTransferDescriptor()
101 // Register the transfer descriptor with the interface
102 TInt err(Interface().RegisterTransferDescriptor(iTransferDescriptor));
105 RDebug::Printf("<Error %d> Unable to register transfer descriptor",err);
110 TInt CIsochTransfer::PrepareTransfer(const TDesC8& aIsochData)
115 iTransferDescriptor.Reset();
116 TPacketLengths fullLengths = iTransferDescriptor.Lengths();
118 RDebug::Printf("fullLengths.MaxNumPackets() == %d",fullLengths.MaxNumPackets());
121 TInt bytesRemaining(aIsochData.Size());
122 TInt maxAvailablePacketSlots;
126 RDebug::Printf("Audio data is %d bytes",bytesRemaining);
128 // Keep saving the isoch data to transfer in each packet buffer supplied
129 // by the transfer descriptor
131 while(bytesRemaining)
133 // Request a modifiable buffer to write the isoch data to
134 TPtr8 packetBuffer = iTransferDescriptor.WritablePackets(bytesRemaining/iMaxPacketSize,maxAvailablePacketSlots);
135 TInt dataToWrite = Min(bytesRemaining,packetBuffer.MaxSize());
139 RDebug::Printf("<Warning> dropping the rest of the isoch data");
143 // Validate entire buffer as it is going to be filled
145 packetBuffer.SetMax();
146 // Calculate the number of packets to write in this buffer
147 TInt maxPacket = dataToWrite / iMaxPacketSize;
149 for(TInt packet = 0; packet < maxPacket; packet++)
151 fullLengths[startPacket + packet] = iMaxPacketSize;
154 packetBuffer.Copy(aIsochData.Mid(startOffset, maxPacket * iMaxPacketSize));
155 iTransferDescriptor.SaveMultiple(maxPacket);
156 bytesRemaining -= maxPacket * iMaxPacketSize;
157 startOffset += maxPacket * iMaxPacketSize;
158 startPacket += maxPacket;
163 TInt CIsochTransfer::TransferOut()
165 // Transfer the iscohronous data
166 RDebug::Printf("Activating isochronous out transfer");
167 Pipe().Transfer(iTransferDescriptor,iStatus);