Changeset 1313 in 3DVCSoftware for trunk/source/Lib/TLibEncoder/NALwrite.cpp
- Timestamp:
- 13 Aug 2015, 17:38:13 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/source/Lib/TLibEncoder/NALwrite.cpp
r1179 r1313 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2015, ITU/ISO/IEC6 * Copyright (c) 2010-2015, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 53 53 bsNALUHeader.write(0,1); // forbidden_zero_bit 54 54 bsNALUHeader.write(nalu.m_nalUnitType, 6); // nal_unit_type 55 #if H_MV56 bsNALUHeader.write(nalu.m_ layerId, 6); // layerId55 #if NH_MV 56 bsNALUHeader.write(nalu.m_nuhLayerId, 6); // layerId 57 57 #else 58 bsNALUHeader.write(nalu.m_ reservedZero6Bits, 6); // nuh_reserved_zero_6bits58 bsNALUHeader.write(nalu.m_nuhLayerId, 6); // nuh_layer_id 59 59 #endif 60 60 bsNALUHeader.write(nalu.m_temporalId+1, 3); // nuh_temporal_id_plus1 … … 66 66 * emulation as required. nalu.m_RBSPayload must be byte aligned. 67 67 */ 68 void write(ostream& out, OutputNALUnit& nalu)68 Void write(ostream& out, OutputNALUnit& nalu) 69 69 { 70 70 writeNalUnitHeader(out, nalu); … … 91 91 vector<uint8_t>& rbsp = nalu.m_Bitstream.getFIFO(); 92 92 93 if (rbsp.size() == 0) 93 vector<uint8_t> outputBuffer; 94 outputBuffer.resize(rbsp.size()*2+1); //there can never be enough emulation_prevention_three_bytes to require this much space 95 std::size_t outputAmount = 0; 96 Int zeroCount = 0; 97 for (vector<uint8_t>::iterator it = rbsp.begin(); it != rbsp.end(); it++) 94 98 { 95 return; 99 const uint8_t v=(*it); 100 if (zeroCount==2 && v<=3) 101 { 102 outputBuffer[outputAmount++]=emulation_prevention_three_byte[0]; 103 zeroCount=0; 104 } 105 106 if (v==0) 107 { 108 zeroCount++; 109 } 110 else 111 { 112 zeroCount=0; 113 } 114 outputBuffer[outputAmount++]=v; 96 115 } 97 98 for (vector<uint8_t>::iterator it = rbsp.begin(); it != rbsp.end();)99 {100 /* 1) find the next emulated 00 00 {00,01,02,03}101 * 2a) if not found, write all remaining bytes out, stop.102 * 2b) otherwise, write all non-emulated bytes out103 * 3) insert emulation_prevention_three_byte104 */105 vector<uint8_t>::iterator found = it;106 do107 {108 /* NB, end()-1, prevents finding a trailing two byte sequence */109 found = search_n(found, rbsp.end()-1, 2, 0);110 found++;111 /* if not found, found == end, otherwise found = second zero byte */112 if (found == rbsp.end())113 break;114 if (*(++found) <= 3)115 break;116 } while (true);117 118 it = found;119 if (found != rbsp.end())120 {121 it = rbsp.insert(found, emulation_prevention_three_byte[0]);122 }123 }124 125 out.write((Char*)&(*rbsp.begin()), rbsp.end() - rbsp.begin());126 116 127 117 /* 7.4.1.1 … … 130 120 * to 0x03 is appended to the end of the data. 131 121 */ 132 if ( rbsp.back() == 0x00)122 if (zeroCount>0) 133 123 { 134 out .write(emulation_prevention_three_byte, 1);124 outputBuffer[outputAmount++]=emulation_prevention_three_byte[0]; 135 125 } 136 } 137 138 /** 139 * Write rbsp_trailing_bits to bs causing it to become byte-aligned 140 */ 141 void writeRBSPTrailingBits(TComOutputBitstream& bs) 142 { 143 bs.write( 1, 1 ); 144 bs.writeAlignZero(); 145 } 146 147 /** 148 * Copy NALU from naluSrc to naluDest 149 */ 150 void copyNaluData(OutputNALUnit& naluDest, const OutputNALUnit& naluSrc) 151 { 152 naluDest.m_nalUnitType = naluSrc.m_nalUnitType; 153 #if H_MV 154 naluDest.m_layerId = naluSrc.m_layerId; 155 #else 156 naluDest.m_reservedZero6Bits = naluSrc.m_reservedZero6Bits; 157 #endif 158 naluDest.m_temporalId = naluSrc.m_temporalId; 159 naluDest.m_Bitstream = naluSrc.m_Bitstream; 126 out.write((Char*)&(*outputBuffer.begin()), outputAmount); 160 127 } 161 128
Note: See TracChangeset for help on using the changeset viewer.