bluetoothengine/btsac/src/btsacStreamerController.cpp
branchRCL_3
changeset 16 b23265fb36da
parent 1 6a1fe72036e3
equal deleted inserted replaced
14:f7fbeaeb166a 16:b23265fb36da
   938 //
   938 //
   939 void CBTSACStreamerController::SetBitpoolValues(TSBCCodecCapabilities& aCap)
   939 void CBTSACStreamerController::SetBitpoolValues(TSBCCodecCapabilities& aCap)
   940 	{
   940 	{
   941 	// Define max bitpool
   941 	// Define max bitpool
   942 	TInt MaxBP = 0;
   942 	TInt MaxBP = 0;
       
   943 	TInt minBitpool = aCap.MinBitpoolValue();
       
   944 	TInt maxBitpool = aCap.MaxBitpoolValue();	
   943 	TBool ProperMaxBitpoolFound = EFalse;
   945 	TBool ProperMaxBitpoolFound = EFalse;
       
   946 	
       
   947 	if( minBitpool == maxBitpool )
       
   948 	    {
       
   949         // Remote supports only one bitpool value
       
   950         iRemoteSupportsOnlyOneValue = ETrue;
       
   951         TRACE_INFO((_L("CBTSACStreamerController::SetBitpoolValues(), remote supports only one bitpool value")))
       
   952         TRACE_INFO((_L("CBTSACStreamerController::SetBitpoolValues(), Max Bitpool: %d"), maxBitpool))
       
   953         TRACE_INFO((_L("CBTSACStreamerController::SetBitpoolValues(), Min Bitpool: %d"), minBitpool))
       
   954         return;
       
   955 	    }
       
   956 	
   944 	for(TInt i = 0 ; i < KNumOfBitpoolValues ; i++)
   957 	for(TInt i = 0 ; i < KNumOfBitpoolValues ; i++)
   945 		{
   958 		{
   946 		if(aCap.MaxBitpoolValue() >= KMaxBitpoolValues[i])
   959 		if(maxBitpool >= KMaxBitpoolValues[i])
   947 			{
   960 			{
   948 			MaxBP = KMaxBitpoolValues[i];
   961 			MaxBP = KMaxBitpoolValues[i];
   949 			ProperMaxBitpoolFound = ETrue;
   962 			ProperMaxBitpoolFound = ETrue;
   950 			break;
   963 			break;
   951 			}
   964 			}
   952 		}
   965 		}
   953 	if(!ProperMaxBitpoolFound)
   966 	if(!ProperMaxBitpoolFound)
   954 		{
   967 		{
   955 		// None of our proposed max bitpool values weren't suitable for accessory.
   968 		// None of our proposed max bitpool values weren't suitable for accessory.
   956 		// Let's use the one which was proposed by the accessory.
   969 		// Let's use the one which was proposed by the accessory.
   957 		MaxBP = aCap.MaxBitpoolValue();
   970 		MaxBP = maxBitpool;
   958 		}
   971 		}
   959 	
   972 	
   960 	// Define min bitpool. This bitpool value is negotiated with sink.
   973 	// Define min bitpool. This bitpool value is negotiated with sink.
   961 	TInt MinBP = (iLocalCap.MinBitpoolValue() < aCap.MinBitpoolValue()) ? aCap.MinBitpoolValue() : iLocalCap.MinBitpoolValue();
   974 	TInt MinBP = (iLocalCap.MinBitpoolValue() < minBitpool) ? minBitpool : iLocalCap.MinBitpoolValue();
   962 	
   975 	
   963 	// Define bitpool which is used for medium quality streaming (when streaming is interfered for some reason).
   976 	// Define bitpool which is used for medium quality streaming (when streaming is interfered for some reason).
   964 	// This is real lowest bitpool value which is used for streaming.
   977 	// This is real lowest bitpool value which is used for streaming.
   965 	
   978 	
   966 	// Check if selected max bitpool value is smaller than our default min bitpool value, if it is, set
   979 	// Check if selected max bitpool value is smaller than our default min bitpool value, if it is, set
   973 	else if(MAXBITPOOLVALUEMIN < MinBP) // Check also that minimum max bitpool value is not smaller than bitpool which is negotiated for the link.
   986 	else if(MAXBITPOOLVALUEMIN < MinBP) // Check also that minimum max bitpool value is not smaller than bitpool which is negotiated for the link.
   974 		{
   987 		{
   975 		iBitpoolData[iBitpoolData.Count()-1].iMaxBitpoolValue = MinBP;
   988 		iBitpoolData[iBitpoolData.Count()-1].iMaxBitpoolValue = MinBP;
   976 		}
   989 		}
   977 	
   990 	
   978 	TRACE_INFO((_L("CBTSACStreamerController::SetBitpoolValues(), Remote Max Bitpool: %d"), aCap.MaxBitpoolValue()))
   991 	TRACE_INFO((_L("CBTSACStreamerController::SetBitpoolValues(), Remote Max Bitpool: %d"), maxBitpool))
   979 	TRACE_INFO((_L("CBTSACStreamerController::SetBitpoolValues(), Remote Min Bitpool: %d"), aCap.MinBitpoolValue()))
   992 	TRACE_INFO((_L("CBTSACStreamerController::SetBitpoolValues(), Remote Min Bitpool: %d"), minBitpool))
   980 	
   993 	
   981 	aCap.SetMaxBitpoolValue(MaxBP);
   994 	aCap.SetMaxBitpoolValue(MaxBP);
   982 	TRACE_INFO((_L("CBTSACStreamerController::SetBitpoolValues(), Max Bitpool: %d"), MaxBP))
   995 	TRACE_INFO((_L("CBTSACStreamerController::SetBitpoolValues(), Max Bitpool: %d"), MaxBP))
   983 	aCap.SetMinBitpoolValue(MinBP);
   996 	aCap.SetMinBitpoolValue(MinBP);
   984 	TRACE_INFO((_L("CBTSACStreamerController::SetBitpoolValues(), Min Bitpool: %d"), MinBP))
   997 	TRACE_INFO((_L("CBTSACStreamerController::SetBitpoolValues(), Min Bitpool: %d"), MinBP))
  1261 // -----------------------------------------------------------------------------
  1274 // -----------------------------------------------------------------------------
  1262 //
  1275 //
  1263 void CBTSACStreamerController::InitializeBitpoolDataL()
  1276 void CBTSACStreamerController::InitializeBitpoolDataL()
  1264 	{
  1277 	{
  1265 	TRACE_FUNC
  1278 	TRACE_FUNC
       
  1279 	iRemoteSupportsOnlyOneValue = EFalse;
  1266 	TBitpoolData data;
  1280 	TBitpoolData data;
  1267 	iBitpoolData.Reset();
  1281 	iBitpoolData.Reset();
  1268 	for(TInt i = 0 ; i < KNumOfBitpoolValues ; i++)
  1282 	for(TInt i = 0 ; i < KNumOfBitpoolValues ; i++)
  1269 		{
  1283 		{
  1270 		data.iMaxBitpoolValue = KMaxBitpoolValues[i];
  1284 		data.iMaxBitpoolValue = KMaxBitpoolValues[i];
  1292 // -----------------------------------------------------------------------------
  1306 // -----------------------------------------------------------------------------
  1293 // CBTSACStreamerController::ReorganizeBitpoolTable
  1307 // CBTSACStreamerController::ReorganizeBitpoolTable
  1294 // -----------------------------------------------------------------------------
  1308 // -----------------------------------------------------------------------------
  1295 //
  1309 //
  1296 void CBTSACStreamerController::ReorganizeBitpoolTable(TInt aNegotiatedMaxBitpool)
  1310 void CBTSACStreamerController::ReorganizeBitpoolTable(TInt aNegotiatedMaxBitpool)
  1297 	{
  1311     {
  1298 	TRACE_INFO((_L("CBTSACStreamerController::ReorganizeBitpoolTable(), Negotiated Max Bitpool %d"), aNegotiatedMaxBitpool))
  1312     TRACE_INFO((_L("CBTSACStreamerController::ReorganizeBitpoolTable(), Negotiated Max Bitpool %d"), aNegotiatedMaxBitpool))
  1299 	// Start checking from the lowest possible bitpool value	
  1313             
  1300 	for(TInt i = (KNumOfBitpoolValues - 1) ; i > 0 ; i--)
  1314     TInt tablesToBeRemoved;
  1301 		{
  1315     if( iRemoteSupportsOnlyOneValue )
  1302 		if(aNegotiatedMaxBitpool <= KMaxBitpoolValues[i])
  1316         {
  1303 			{
  1317         // Remote supports only one bitpool value, so we need only one table, remove rest. 
  1304 			TInt ii;
  1318         tablesToBeRemoved = KNumOfBitpoolValues - 1;
  1305 			for(ii = 0 ; ii < i ; ii++)
  1319         }
  1306 				{
  1320     else
  1307 				iBitpoolData.Remove(0);				
  1321         {
  1308 				}
  1322         // Find proper bitpool value, start checking from the lowest possible bitpool value
  1309 			TRACE_INFO((_L("CBTSACStreamerController::ReorganizeBitpoolTable(), Tables removed: %d"), ii))
  1323         for(tablesToBeRemoved = (KNumOfBitpoolValues - 1) ; tablesToBeRemoved > 0 ; tablesToBeRemoved--)
  1310 			for(TInt j = 0 ; j < iBitpoolData.Count() ; j++)
  1324             {
  1311 				{
  1325             if(aNegotiatedMaxBitpool <= KMaxBitpoolValues[tablesToBeRemoved])
  1312 				if(j == 0)
  1326                 {            
  1313 					{
  1327                 break;
  1314 					iBitpoolData[j].iMaxBitpoolValue = aNegotiatedMaxBitpool;
  1328                 }
  1315 					}
  1329             }
  1316 				iBitpoolData[j].iIndex = j;
  1330         }
  1317 				iBitpoolData[j].iUpBitpoolIndex = (j == 0) ? j : j - 1;
  1331     if( tablesToBeRemoved >= iBitpoolData.Count() )
  1318 				iBitpoolData[j].iDownBitpoolIndex = (j == iBitpoolData.Count() - 1) ? j : j + 1;
  1332         {
  1319 				}
  1333         // This should never happen.
  1320 			break;
  1334         TRACE_INFO((_L("CBTSACStreamerController::ReorganizeBitpoolTable(), Index error!")))
  1321 			}
  1335         tablesToBeRemoved = 0;
  1322 		}
  1336         TRAPD(err, InitializeBitpoolDataL())
  1323 	TRACE_INFO((_L("CBTSACStreamerController::ReorganizeBitpoolTable(), Tables left: %d"), iBitpoolData.Count()))
  1337         if(err)
  1324 	for(TInt k = 0 ; k < iBitpoolData.Count() ; k++)
  1338             {
  1325 		{
  1339             return;
  1326 		TRACE_INFO((_L("CBTSACStreamerController::ReorganizeBitpoolTable(), Table[%d] MaxBP: %d"), k, iBitpoolData[k].iMaxBitpoolValue))
  1340             }
  1327 		}
  1341         }
  1328 	}
  1342     
       
  1343     // Remove tables we don't need
       
  1344     TInt idx;
       
  1345     for( idx = 0 ; idx < tablesToBeRemoved ; idx++)
       
  1346         {
       
  1347         iBitpoolData.Remove(0);             
       
  1348         }    
       
  1349     TRACE_INFO((_L("CBTSACStreamerController::ReorganizeBitpoolTable(), Tables removed: %d"), tablesToBeRemoved))
       
  1350     
       
  1351     if( tablesToBeRemoved )
       
  1352         {
       
  1353         for( idx = 0 ; idx < iBitpoolData.Count() ; idx++)
       
  1354             {
       
  1355             if( idx == 0 )
       
  1356                 {
       
  1357                 // Index zero has the highest matching/negotiated bitpool value, update it.
       
  1358                 // Rest values remains to be according to default table.
       
  1359                 iBitpoolData[idx].iMaxBitpoolValue = aNegotiatedMaxBitpool;
       
  1360                 }
       
  1361             // Update indexing.
       
  1362             iBitpoolData[idx].iIndex = idx;
       
  1363             iBitpoolData[idx].iUpBitpoolIndex = (idx == 0) ? idx : idx - 1;
       
  1364             iBitpoolData[idx].iDownBitpoolIndex = (idx == iBitpoolData.Count() - 1) ? idx : idx + 1;
       
  1365             iBitpoolData[idx].iMinimumMaxBitpool = (idx == iBitpoolData.Count() - 1) ? ETrue : EFalse;
       
  1366             }
       
  1367         }
       
  1368     
       
  1369     TRACE_INFO((_L("CBTSACStreamerController::ReorganizeBitpoolTable(), Tables left: %d"), iBitpoolData.Count()))
       
  1370     for( idx = 0 ; idx < iBitpoolData.Count() ; idx++)
       
  1371         {
       
  1372         TRACE_INFO((_L("CBTSACStreamerController::ReorganizeBitpoolTable(), Table[%d] MaxBP: %d"), idx, iBitpoolData[idx].iMaxBitpoolValue))
       
  1373         }
       
  1374     }
  1329 
  1375 
  1330 // -----------------------------------------------------------------------------
  1376 // -----------------------------------------------------------------------------
  1331 // CBTSACStreamerController::DoSelfComplete
  1377 // CBTSACStreamerController::DoSelfComplete
  1332 // -----------------------------------------------------------------------------
  1378 // -----------------------------------------------------------------------------
  1333 //
  1379 //