Ticket #994: entry_point_offset_wpp_hm-9.1.patch
File entry_point_offset_wpp_hm-9.1.patch, 9.5 KB (added by kiranmisra, 11 years ago) |
---|
-
Lib/TLibCommon/TComBitStream.h
162 162 class TComInputBitstream 163 163 { 164 164 std::vector<uint8_t> *m_fifo; /// FIFO for storage of complete bytes 165 std::vector<UInt> m_emulationPreventionByteLocation; 165 166 166 167 protected: 167 168 UInt m_fifo_idx; /// Read index into m_fifo … … 205 206 Void deleteFifo(); // Delete internal fifo of bitstream. 206 207 UInt getNumBitsRead() { return m_numBitsRead; } 207 208 Void readByteAlignment(); 209 210 Void pushEmulationPreventionByteLocation ( UInt pos ) { m_emulationPreventionByteLocation.push_back( pos ); } 211 UInt numEmulationPreventionBytesRead () { return m_emulationPreventionByteLocation.size(); } 212 std::vector<UInt> getEmulationPreventionByteLocation () { return m_emulationPreventionByteLocation; } 213 UInt getEmulationPreventionByteLocation ( UInt idx ) { return m_emulationPreventionByteLocation[ idx ]; } 214 Void clearEmulationPreventionByteLocation() { m_emulationPreventionByteLocation.clear(); } 215 Void setEmulationPreventionByteLocation ( std::vector<UInt> vec ) { m_emulationPreventionByteLocation = vec; } 208 216 }; 209 217 210 218 //! \} -
Lib/TLibDecoder/NALread.cpp
58 58 UInt zeroCount = 0; 59 59 vector<uint8_t>::iterator it_read, it_write; 60 60 61 for (it_read = it_write = nalUnitBuf.begin(); it_read != nalUnitBuf.end(); it_read++, it_write++) 61 UInt pos = 0; 62 pcBitstream->clearEmulationPreventionByteLocation(); 63 for (it_read = it_write = nalUnitBuf.begin(); it_read != nalUnitBuf.end(); it_read++, it_write++, pos++) 62 64 { 63 65 assert(zeroCount < 2 || *it_read >= 0x03); 64 66 if (zeroCount == 2 && *it_read == 0x03) 65 67 { 68 pcBitstream->pushEmulationPreventionByteLocation( pos ); 69 pos++; 66 70 it_read++; 67 71 zeroCount = 0; 68 72 if (it_read == nalUnitBuf.end()) … … 144 148 #endif 145 149 146 150 nalu.m_Bitstream = new TComInputBitstream(&nalUnitBuf); 151 nalu.m_Bitstream->setEmulationPreventionByteLocation(pcBitstream->getEmulationPreventionByteLocation()); 147 152 delete pcBitstream; 148 153 readNalUnitHeader(nalu); 149 154 } -
Lib/TLibDecoder/TDecCAVLC.cpp
1337 1337 rpcSlice->setLFCrossSliceBoundaryFlag( (uiCode==1)?true:false); 1338 1338 1339 1339 } 1340 if( pps->getTilesEnabledFlag() || pps->getEntropyCodingSyncEnabledFlag() ) 1340 1341 UInt *entryPointOffset = NULL; 1342 UInt numEntryPointOffsets, offsetLenMinus1; 1343 if( pps->getTilesEnabledFlag() || pps->getEntropyCodingSyncEnabledFlag() ) 1344 { 1345 READ_UVLC(numEntryPointOffsets, "num_entry_point_offsets"); rpcSlice->setNumEntryPointOffsets ( numEntryPointOffsets ); 1346 if (numEntryPointOffsets>0) 1341 1347 { 1342 UInt *entryPointOffset = NULL; 1343 UInt numEntryPointOffsets, offsetLenMinus1; 1348 READ_UVLC(offsetLenMinus1, "offset_len_minus1"); 1349 } 1350 entryPointOffset = new UInt[numEntryPointOffsets]; 1351 for (UInt idx=0; idx<numEntryPointOffsets; idx++) 1352 { 1353 READ_CODE(offsetLenMinus1+1, uiCode, "entry_point_offset"); 1354 entryPointOffset[ idx ] = uiCode; 1355 } 1356 } 1357 else 1358 { 1359 rpcSlice->setNumEntryPointOffsets ( 0 ); 1360 } 1344 1361 1345 READ_UVLC(numEntryPointOffsets, "num_entry_point_offsets"); rpcSlice->setNumEntryPointOffsets ( numEntryPointOffsets ); 1346 if (numEntryPointOffsets>0) 1347 { 1348 READ_UVLC(offsetLenMinus1, "offset_len_minus1"); 1349 } 1350 entryPointOffset = new UInt[numEntryPointOffsets]; 1351 for (UInt idx=0; idx<numEntryPointOffsets; idx++) 1352 { 1353 READ_CODE(offsetLenMinus1+1, uiCode, "entry_point_offset"); 1354 entryPointOffset[ idx ] = uiCode; 1355 } 1362 if(pps->getSliceHeaderExtensionPresentFlag()) 1363 { 1364 READ_UVLC(uiCode,"slice_header_extension_length"); 1365 for(Int i=0; i<uiCode; i++) 1366 { 1367 UInt ignore; 1368 READ_CODE(8,ignore,"slice_header_extension_data_byte"); 1369 } 1370 } 1371 m_pcBitstream->readByteAlignment(); 1356 1372 1357 if ( pps->getTilesEnabledFlag() ) 1358 { 1359 rpcSlice->setTileLocationCount( numEntryPointOffsets ); 1373 if( pps->getTilesEnabledFlag() || pps->getEntropyCodingSyncEnabledFlag() ) 1374 { 1375 Int endOfSliceHeaderLocation = m_pcBitstream->getByteLocation(); 1376 Int curEntryPointOffset = 0; 1377 Int prevEntryPointOffset = 0; 1378 for (UInt idx=0; idx<numEntryPointOffsets; idx++) 1379 { 1380 curEntryPointOffset += entryPointOffset[ idx ]; 1360 1381 1361 UInt prevPos = 0; 1362 for (Int idx=0; idx<rpcSlice->getTileLocationCount(); idx++) 1363 { 1364 rpcSlice->setTileLocation( idx, prevPos + entryPointOffset [ idx ] ); 1365 prevPos += entryPointOffset[ idx ]; 1366 } 1367 } 1368 else if ( pps->getEntropyCodingSyncEnabledFlag() ) 1382 Int emulationPreventionByteCount = 0; 1383 for ( UInt curByteIdx = 0; curByteIdx<m_pcBitstream->numEmulationPreventionBytesRead(); curByteIdx++ ) 1369 1384 { 1370 Int numSubstreams = rpcSlice->getNumEntryPointOffsets()+1; 1371 rpcSlice->allocSubstreamSizes(numSubstreams); 1372 UInt *pSubstreamSizes = rpcSlice->getSubstreamSizes(); 1373 for (Int idx=0; idx<numSubstreams-1; idx++) 1385 if ( m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) >= ( prevEntryPointOffset + endOfSliceHeaderLocation ) && 1386 m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) < ( curEntryPointOffset + endOfSliceHeaderLocation ) ) 1374 1387 { 1375 if ( idx < numEntryPointOffsets ) 1376 { 1377 pSubstreamSizes[ idx ] = ( entryPointOffset[ idx ] << 3 ) ; 1378 } 1379 else 1380 { 1381 pSubstreamSizes[ idx ] = 0; 1382 } 1388 emulationPreventionByteCount++; 1383 1389 } 1384 1390 } 1385 1391 1386 if (entryPointOffset) 1392 entryPointOffset[ idx ] -= emulationPreventionByteCount; 1393 prevEntryPointOffset = curEntryPointOffset; 1394 } 1395 1396 if ( pps->getTilesEnabledFlag() ) 1397 { 1398 rpcSlice->setTileLocationCount( numEntryPointOffsets ); 1399 1400 UInt prevPos = 0; 1401 for (Int idx=0; idx<rpcSlice->getTileLocationCount(); idx++) 1387 1402 { 1388 delete [] entryPointOffset; 1403 rpcSlice->setTileLocation( idx, prevPos + entryPointOffset [ idx ] ); 1404 prevPos += entryPointOffset[ idx ]; 1389 1405 } 1390 1406 } 1391 else 1407 else if ( pps->getEntropyCodingSyncEnabledFlag() ) 1392 1408 { 1393 rpcSlice->setNumEntryPointOffsets ( 0 ); 1409 Int numSubstreams = rpcSlice->getNumEntryPointOffsets()+1; 1410 rpcSlice->allocSubstreamSizes(numSubstreams); 1411 UInt *pSubstreamSizes = rpcSlice->getSubstreamSizes(); 1412 for (Int idx=0; idx<numSubstreams-1; idx++) 1413 { 1414 if ( idx < numEntryPointOffsets ) 1415 { 1416 pSubstreamSizes[ idx ] = ( entryPointOffset[ idx ] << 3 ) ; 1417 } 1418 else 1419 { 1420 pSubstreamSizes[ idx ] = 0; 1421 } 1422 } 1394 1423 } 1395 1424 1396 if(pps->getSliceHeaderExtensionPresentFlag()) 1397 { 1398 READ_UVLC(uiCode,"slice_header_extension_length"); 1399 for(Int i=0; i<uiCode; i++) 1425 if (entryPointOffset) 1400 1426 { 1401 UInt ignore; 1402 READ_CODE(8,ignore,"slice_header_extension_data_byte"); 1427 delete [] entryPointOffset; 1403 1428 } 1404 1429 } 1405 m_pcBitstream->readByteAlignment(); 1430 1406 1431 return; 1407 1432 } 1408 1433 -
Lib/TLibEncoder/TEncGOP.cpp
1158 1158 } 1159 1159 if (ui+1 < pcSlice->getPPS()->getNumSubstreams()) 1160 1160 { 1161 puiSubstreamSizes[ui] = pcSubstreamsOut[ui].getNumberOfWrittenBits(); 1161 1162 UInt uiCounter = 0; 1163 vector<uint8_t>& rbsp = pcSubstreamsOut[ui].getFIFO(); 1164 for (vector<uint8_t>::iterator it = rbsp.begin(); it != rbsp.end();) 1165 { 1166 /* 1) find the next emulated 00 00 {00,01,02,03} 1167 * 2a) if not found, write all remaining bytes out, stop. 1168 * 2b) otherwise, write all non-emulated bytes out 1169 * 3) insert emulation_prevention_three_byte 1170 */ 1171 vector<uint8_t>::iterator found = it; 1172 do 1173 { 1174 /* NB, end()-1, prevents finding a trailing two byte sequence */ 1175 found = search_n(found, rbsp.end()-1, 2, 0); 1176 found++; 1177 /* if not found, found == end, otherwise found = second zero byte */ 1178 if (found == rbsp.end()) 1179 { 1180 break; 1181 } 1182 if (*(++found) <= 3) 1183 { 1184 break; 1185 } 1186 } while (true); 1187 it = found; 1188 if (found != rbsp.end()) 1189 { 1190 it++; 1191 uiCounter++; 1192 } 1193 } 1194 puiSubstreamSizes[ui] = pcSubstreamsOut[ui].getNumberOfWrittenBits() + (uiCounter<<3); 1162 1195 } 1163 1196 } 1164 1197