This site is for P2P development and test software ONLY!

Manual Chunk Selection

Here's the code for the Manual Chunk Selection.

//BG Manual Chunk Selection
//BG Specify a string of chunks... every number must be followed by a comma
//BG Examples: 1, or 3,4,5, etc...

CString strManualChunks = thePrefs.GetCommunityName();
strManualChunks = strManualChunks.MakeReverse(); // 1,2,3, = ,3,2,1
int pos;

while (strManualChunks != _T("")) {

pos = strManualChunks.Find(_T(","));

CString strChunk = strManualChunks.Mid(pos+1,1);
uint32 iChunk = _wtoi(strChunk)-1;

if (sender->IsPartAvailable(iChunk) && GetNextEmptyBlockInPart(iChunk, 0))
chunk_list.AddHead(iChunk);

strManualChunks = strManualChunks.Right(strManualChunks.GetLength()-2);
}
//BG End


Put near the end of bool CPartFile::GetNextRequestedBlock(CUpDownClient* sender, Requested_Block_Struct** newblocks, uint16* count)


Here's the Left to Right code:

/*
Get Chunks Left to Right.
If the file is an AVI/ASF/WMV, get the last chunk after the first chunk.
Version 2 of this will try and just get the last 180KB for AVI files instead of the whole chunk for previewing
Need to rip apart the GetNextEmptyBlockInPart function.
*/
//BG
bool CPartFile::GetNextRequestedBlock_BGVideoPreview(CUpDownClient* sender, Requested_Block_Struct** newblocks, uint16* count) {

uint16 LastPartAsked;
const uint16 partCount = GetPartCount();

//Find File Extension
CString ext = GetFileName();
ext.MakeLower();
int pos = ext.ReverseFind(_T('.'));
if (pos > -1)
ext = ext.Mid(pos);

//Get First Chunk
if (sender->IsPartAvailable(0) && GetNextEmptyBlockInPart(0, NULL) ) {
LastPartAsked = 0;
}
//If AVI/ASF/WMV Get Last Chunk
else if ((ext == _T(".avi") || ext == _T(".asf") || ext == _T(".wmv")) &&
sender->IsPartAvailable(partCount - 1) && GetNextEmptyBlockInPart(partCount - 1, NULL) ) {
LastPartAsked = partCount - 1;
}
//Get All other chunks Left to Right
else {
for (uint16 i = 1; i < partCount; i++) if (sender->IsPartAvailable(i) && GetNextEmptyBlockInPart(i, NULL) ) {
LastPartAsked = i;
break;
}
}


//Build Requested Block List

uint16 requestedCount = *count;
uint16 newblockcount = 0;
do{
Requested_Block_Struct* block = new Requested_Block_Struct;
if (GetNextEmptyBlockInPart(LastPartAsked,block)) {
requestedblocks_list.AddTail(block);
newblocks[newblockcount] = block;
AddDebugLogLine( false, _T("BG-VideoPreview: Block: -%u- Start: -%u- End: -%u- Trans: -%u-"),(uint16)newblockcount,block->StartOffset,block->EndOffset,block->transferred);
newblockcount++;
}
else {
delete block;
break;
}
} while (newblockcount != requestedCount);
*count = newblockcount;
sender->m_lastPartAsked = LastPartAsked;

return true;

} //BG End GetNextRequestedBlock_BGVideoPreview

0 comments:

发表评论