[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 | nalu.m_nalRefFlag = (bs.read(1) != 0 ); |
---|
| 127 | nalu.m_nalUnitType = (NalUnitType) bs.read(6); |
---|
| 128 | |
---|
[210] | 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 |
---|
[56] | 134 | nalu.m_temporalId = bs.read(3); |
---|
| 135 | // unsigned reserved_one_5bits = bs.read(5); |
---|
| 136 | // assert(reserved_one_5bits == 1); |
---|
[77] | 137 | #if VIDYO_VPS_INTEGRATION |
---|
| 138 | nalu.m_layerId = bs.read(5) - 1; |
---|
| 139 | #else |
---|
[56] | 140 | nalu.m_viewId = bs.read(4)-1; |
---|
| 141 | nalu.m_isDepth = bs.read(1); |
---|
[77] | 142 | #endif |
---|
[56] | 143 | if ( nalu.m_temporalId ) |
---|
| 144 | { |
---|
[210] | 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 |
---|
[56] | 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 ); |
---|
[210] | 149 | #endif |
---|
[56] | 150 | } |
---|
| 151 | #endif |
---|
| 152 | } |
---|
| 153 | //! \} |
---|