Changeset 608 in 3DVCSoftware for trunk/source/Lib/TLibDecoder/NALread.cpp
- Timestamp:
- 1 Sep 2013, 22:47:26 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/source/Lib/TLibDecoder/NALread.cpp
r296 r608 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-201 2, ITU/ISO/IEC6 * Copyright (c) 2010-2013, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 32 32 */ 33 33 34 /** 35 \file NALread.cpp 36 \brief reading funtionality for NAL units 37 */ 38 39 34 40 #include <vector> 35 41 #include <algorithm> … … 44 50 //! \ingroup TLibDecoder 45 51 //! \{ 46 static void convertPayloadToRBSP(vector<uint8_t>& nalUnitBuf, TComInputBitstream * pcBitstream)52 static void convertPayloadToRBSP(vector<uint8_t>& nalUnitBuf, TComInputBitstream *bitstream, Bool isVclNalUnit) 47 53 { 48 unsignedzeroCount = 0;54 UInt zeroCount = 0; 49 55 vector<uint8_t>::iterator it_read, it_write; 50 56 51 UInt *auiStoredTileMarkerLocation = new UInt[MAX_MARKER_PER_NALU];52 // Remove tile markers and note the bitstream location53 for (it_read = it_write = nalUnitBuf.begin(); it_read != nalUnitBuf.end(); it_read++ 57 UInt pos = 0; 58 bitstream->clearEmulationPreventionByteLocation(); 59 for (it_read = it_write = nalUnitBuf.begin(); it_read != nalUnitBuf.end(); it_read++, it_write++, pos++) 54 60 { 55 Bool bTileMarkerFound = false; 56 if ( ( it_read - nalUnitBuf.begin() ) < ( nalUnitBuf.size() - 2 ) ) 57 { 58 if ( (*(it_read) == 0x00) && (*(it_read+1) == 0x00) && (*(it_read+2) == 0x02) ) // tile marker detected 59 { 60 it_read += 2; 61 UInt uiDistance = (UInt) (it_write - nalUnitBuf.begin()); 62 UInt uiCount = pcBitstream->getTileMarkerLocationCount(); 63 bTileMarkerFound = true; 64 pcBitstream->setTileMarkerLocation( uiCount, uiDistance ); 65 auiStoredTileMarkerLocation[uiCount] = uiDistance; 66 pcBitstream->setTileMarkerLocationCount( uiCount + 1 ); 67 68 } 69 } 70 71 if (!bTileMarkerFound) 72 { 73 *it_write = *it_read; 74 it_write++; 75 } 76 } 77 nalUnitBuf.resize(it_write - nalUnitBuf.begin()); 78 79 for (it_read = it_write = nalUnitBuf.begin(); it_read != nalUnitBuf.end(); it_read++, it_write++) 80 { 61 assert(zeroCount < 2 || *it_read >= 0x03); 81 62 if (zeroCount == 2 && *it_read == 0x03) 82 63 { 83 // update tile marker location 84 UInt uiDistance = (UInt) (it_read - nalUnitBuf.begin()); 85 for (UInt uiIdx=0; uiIdx<pcBitstream->getTileMarkerLocationCount(); uiIdx++) 86 { 87 if (auiStoredTileMarkerLocation[ uiIdx ] >= uiDistance) 88 { 89 pcBitstream->setTileMarkerLocation( uiIdx, pcBitstream->getTileMarkerLocation( uiIdx )-1 ); 90 } 91 } 64 bitstream->pushEmulationPreventionByteLocation( pos ); 65 pos++; 92 66 it_read++; 93 67 zeroCount = 0; 68 if (it_read == nalUnitBuf.end()) 69 { 70 break; 71 } 94 72 } 95 73 zeroCount = (*it_read == 0x00) ? zeroCount+1 : 0; 96 74 *it_write = *it_read; 97 75 } 76 assert(zeroCount == 0); 77 78 if (isVclNalUnit) 79 { 80 // Remove cabac_zero_word from payload if present 81 Int n = 0; 82 83 while (it_write[-1] == 0x00) 84 { 85 it_write--; 86 n++; 87 } 88 89 if (n > 0) 90 { 91 printf("\nDetected %d instances of cabac_zero_word", n/2); 92 } 93 } 98 94 99 95 nalUnitBuf.resize(it_write - nalUnitBuf.begin()); 100 delete [] auiStoredTileMarkerLocation;101 96 } 102 97 98 Void readNalUnitHeader(InputNALUnit& nalu) 99 { 100 TComInputBitstream& bs = *nalu.m_Bitstream; 101 102 Bool forbidden_zero_bit = bs.read(1); // forbidden_zero_bit 103 assert(forbidden_zero_bit == 0); 104 nalu.m_nalUnitType = (NalUnitType) bs.read(6); // nal_unit_type 105 #if H_MV 106 nalu.m_layerId = bs.read(6); // layerId 107 #else 108 nalu.m_reservedZero6Bits = bs.read(6); // nuh_reserved_zero_6bits 109 assert(nalu.m_reservedZero6Bits == 0); 110 #endif 111 nalu.m_temporalId = bs.read(3) - 1; // nuh_temporal_id_plus1 112 113 if ( nalu.m_temporalId ) 114 { 115 assert( nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_BLA_W_LP 116 && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_BLA_W_RADL 117 && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_BLA_N_LP 118 && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_IDR_W_RADL 119 && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_IDR_N_LP 120 && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_CRA 121 && nalu.m_nalUnitType != NAL_UNIT_VPS 122 && nalu.m_nalUnitType != NAL_UNIT_SPS 123 && nalu.m_nalUnitType != NAL_UNIT_EOS 124 && nalu.m_nalUnitType != NAL_UNIT_EOB ); 125 } 126 else 127 { 128 assert( nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_TLA_R 129 && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_TSA_N 130 && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_STSA_R 131 && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_STSA_N ); 132 } 133 } 103 134 /** 104 135 * create a NALunit structure with given header values and storage for … … 109 140 /* perform anti-emulation prevention */ 110 141 TComInputBitstream *pcBitstream = new TComInputBitstream(NULL); 111 convertPayloadToRBSP(nalUnitBuf, pcBitstream );112 142 convertPayloadToRBSP(nalUnitBuf, pcBitstream, (nalUnitBuf[0] & 64) == 0); 143 113 144 nalu.m_Bitstream = new TComInputBitstream(&nalUnitBuf); 114 // copy the tile marker location information 115 nalu.m_Bitstream->setTileMarkerLocationCount( pcBitstream->getTileMarkerLocationCount() ); 116 for (UInt uiIdx=0; uiIdx < nalu.m_Bitstream->getTileMarkerLocationCount(); uiIdx++) 117 { 118 nalu.m_Bitstream->setTileMarkerLocation( uiIdx, pcBitstream->getTileMarkerLocation(uiIdx) ); 119 } 145 nalu.m_Bitstream->setEmulationPreventionByteLocation(pcBitstream->getEmulationPreventionByteLocation()); 120 146 delete pcBitstream; 121 TComInputBitstream& bs = *nalu.m_Bitstream; 122 123 bool forbidden_zero_bit = bs.read(1); 124 assert(forbidden_zero_bit == 0); 125 126 nalu.m_nalRefFlag = (bs.read(1) != 0 ); 127 nalu.m_nalUnitType = (NalUnitType) bs.read(6); 128 129 #if QC_MVHEVC_B0046 130 //nalu.m_layerId = bs.read(6); 131 nalu.m_layerId = bs.read(5); 132 nalu.m_temporalId = bs.read(3) - 1; 133 #else 134 nalu.m_temporalId = bs.read(3); 135 // unsigned reserved_one_5bits = bs.read(5); 136 // assert(reserved_one_5bits == 1); 137 #if VIDYO_VPS_INTEGRATION 138 nalu.m_layerId = bs.read(5) - 1; 139 #else 140 nalu.m_viewId = bs.read(4)-1; 141 nalu.m_isDepth = bs.read(1); 142 #endif 143 if ( nalu.m_temporalId ) 144 { 145 #if QC_REM_IDV_B0046 146 assert( nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_CRA && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_IDR); 147 #else 148 assert( nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_CRA && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_IDR && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_IDV ); 149 #endif 150 } 151 #endif 147 readNalUnitHeader(nalu); 152 148 } 153 149 //! \}
Note: See TracChangeset for help on using the changeset viewer.