[56] | 1 | /* The copyright in this software is being made available under the BSD |
---|
| 2 | * License, included below. This software may be subject to other third party |
---|
| 3 | * and contributor rights, including patent rights, and no such rights are |
---|
| 4 | * granted under this license. |
---|
| 5 | * |
---|
| 6 | * Copyright (c) 2010-2012, ITU/ISO/IEC |
---|
| 7 | * All rights reserved. |
---|
| 8 | * |
---|
| 9 | * Redistribution and use in source and binary forms, with or without |
---|
| 10 | * modification, are permitted provided that the following conditions are met: |
---|
| 11 | * |
---|
| 12 | * * Redistributions of source code must retain the above copyright notice, |
---|
| 13 | * this list of conditions and the following disclaimer. |
---|
| 14 | * * Redistributions in binary form must reproduce the above copyright notice, |
---|
| 15 | * this list of conditions and the following disclaimer in the documentation |
---|
| 16 | * and/or other materials provided with the distribution. |
---|
| 17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
| 18 | * be used to endorse or promote products derived from this software without |
---|
| 19 | * specific prior written permission. |
---|
| 20 | * |
---|
| 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
| 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
| 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
| 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS |
---|
| 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
| 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
| 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
| 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
| 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
| 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
---|
| 31 | * THE POSSIBILITY OF SUCH DAMAGE. |
---|
| 32 | */ |
---|
| 33 | |
---|
| 34 | #include <vector> |
---|
| 35 | #include <algorithm> |
---|
| 36 | #include <ostream> |
---|
| 37 | |
---|
| 38 | #include "NALread.h" |
---|
| 39 | #include "TLibCommon/NAL.h" |
---|
| 40 | #include "TLibCommon/TComBitStream.h" |
---|
| 41 | |
---|
| 42 | using namespace std; |
---|
| 43 | |
---|
| 44 | //! \ingroup TLibDecoder |
---|
| 45 | //! \{ |
---|
| 46 | static void convertPayloadToRBSP(vector<uint8_t>& nalUnitBuf, TComInputBitstream *pcBitstream) |
---|
| 47 | { |
---|
| 48 | unsigned zeroCount = 0; |
---|
| 49 | vector<uint8_t>::iterator it_read, it_write; |
---|
| 50 | |
---|
| 51 | UInt *auiStoredTileMarkerLocation = new UInt[MAX_MARKER_PER_NALU]; |
---|
| 52 | // Remove tile markers and note the bitstream location |
---|
| 53 | for (it_read = it_write = nalUnitBuf.begin(); it_read != nalUnitBuf.end(); it_read++ ) |
---|
| 54 | { |
---|
| 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 | { |
---|
| 81 | if (zeroCount == 2 && *it_read == 0x03) |
---|
| 82 | { |
---|
| 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 | } |
---|
| 92 | it_read++; |
---|
| 93 | zeroCount = 0; |
---|
| 94 | } |
---|
| 95 | zeroCount = (*it_read == 0x00) ? zeroCount+1 : 0; |
---|
| 96 | *it_write = *it_read; |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | nalUnitBuf.resize(it_write - nalUnitBuf.begin()); |
---|
| 100 | delete [] auiStoredTileMarkerLocation; |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | /** |
---|
| 104 | * create a NALunit structure with given header values and storage for |
---|
| 105 | * a bitstream |
---|
| 106 | */ |
---|
| 107 | void read(InputNALUnit& nalu, vector<uint8_t>& nalUnitBuf) |
---|
| 108 | { |
---|
| 109 | /* perform anti-emulation prevention */ |
---|
| 110 | TComInputBitstream *pcBitstream = new TComInputBitstream(NULL); |
---|
| 111 | convertPayloadToRBSP(nalUnitBuf, pcBitstream); |
---|
| 112 | |
---|
| 113 | 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 | } |
---|
| 120 | 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 | #if NAL_REF_FLAG |
---|
| 127 | nalu.m_nalRefFlag = (bs.read(1) != 0 ); |
---|
| 128 | nalu.m_nalUnitType = (NalUnitType) bs.read(6); |
---|
| 129 | #else |
---|
| 130 | nalu.m_nalRefIDC = (NalRefIdc) bs.read(2); |
---|
| 131 | nalu.m_nalUnitType = (NalUnitType) bs.read(5); |
---|
| 132 | #endif |
---|
| 133 | |
---|
[210] | 134 | #if QC_MVHEVC_B0046 |
---|
| 135 | //nalu.m_layerId = bs.read(6); |
---|
| 136 | nalu.m_layerId = bs.read(5); |
---|
| 137 | nalu.m_temporalId = bs.read(3) - 1; |
---|
| 138 | #else |
---|
[56] | 139 | #if H0388 |
---|
| 140 | nalu.m_temporalId = bs.read(3); |
---|
| 141 | // unsigned reserved_one_5bits = bs.read(5); |
---|
| 142 | // assert(reserved_one_5bits == 1); |
---|
[77] | 143 | #if VIDYO_VPS_INTEGRATION |
---|
| 144 | nalu.m_layerId = bs.read(5) - 1; |
---|
| 145 | #else |
---|
[56] | 146 | nalu.m_viewId = bs.read(4)-1; |
---|
| 147 | nalu.m_isDepth = bs.read(1); |
---|
[77] | 148 | #endif |
---|
[56] | 149 | #if H0566_TLA |
---|
| 150 | if ( nalu.m_temporalId ) |
---|
| 151 | { |
---|
[210] | 152 | #if QC_REM_IDV_B0046 |
---|
| 153 | assert( nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_CRA && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_IDR); |
---|
| 154 | #else |
---|
[56] | 155 | 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 ); |
---|
[210] | 156 | #endif |
---|
[56] | 157 | } |
---|
| 158 | #endif |
---|
| 159 | #else |
---|
| 160 | switch (nalu.m_nalUnitType) |
---|
| 161 | { |
---|
| 162 | case NAL_UNIT_CODED_SLICE: |
---|
| 163 | case NAL_UNIT_CODED_SLICE_IDR: |
---|
| 164 | #if H0566_TLA |
---|
[210] | 165 | #if !QC_REM_IDV_B0046 |
---|
[56] | 166 | case NAL_UNIT_CODED_SLICE_IDV: |
---|
[210] | 167 | #endif |
---|
[56] | 168 | case NAL_UNIT_CODED_SLICE_CRA: |
---|
| 169 | case NAL_UNIT_CODED_SLICE_TLA: |
---|
| 170 | #else |
---|
| 171 | case NAL_UNIT_CODED_SLICE_CDR: |
---|
| 172 | #endif |
---|
| 173 | { |
---|
| 174 | nalu.m_temporalId = bs.read(3); |
---|
[77] | 175 | #if VIDYO_VPS_INTEGRATION |
---|
| 176 | nalu.m_layerId = bs.read(5) - 1; |
---|
| 177 | #else |
---|
[56] | 178 | nalu.m_OutputFlag = bs.read(1); |
---|
| 179 | // unsigned reserved_one_4bits = bs.read(4); |
---|
| 180 | // assert(reserved_one_4bits == 1); |
---|
| 181 | nalu.m_viewId = bs.read(3)-1; |
---|
| 182 | nalu.m_isDepth = bs.read(1); |
---|
[77] | 183 | #endif |
---|
[56] | 184 | |
---|
| 185 | #if H0566_TLA |
---|
| 186 | if (nalu.m_temporalId == 0) |
---|
| 187 | { |
---|
[210] | 188 | #if QC_REM_IDV_B0046 |
---|
| 189 | assert(nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_CRA || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR); |
---|
| 190 | #else |
---|
[56] | 191 | assert(nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_CRA || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDV ); |
---|
[210] | 192 | #endif |
---|
[56] | 193 | } |
---|
| 194 | else |
---|
| 195 | { |
---|
| 196 | assert(nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TLA); |
---|
| 197 | } |
---|
| 198 | #endif |
---|
| 199 | } |
---|
| 200 | break; |
---|
| 201 | default: |
---|
| 202 | nalu.m_temporalId = 0; |
---|
| 203 | nalu.m_OutputFlag = true; |
---|
| 204 | break; |
---|
| 205 | } |
---|
| 206 | #endif |
---|
[210] | 207 | #endif |
---|
[56] | 208 | } |
---|
| 209 | //! \} |
---|