Esempio n. 1
0
func (this *TDecGop) DecompressSlice(pcBitstream *TLibCommon.TComInputBitstream, rpcPic *TLibCommon.TComPic, pTraceFile io.Writer) {
	pcSlice := rpcPic.GetSlice(rpcPic.GetCurrSliceIdx())
	// Table of extracted substreams.
	// These must be deallocated AND their internal fifos, too.
	//TComInputBitstream **ppcSubstreams = NULL;

	//-- For time output for each slice
	iBeforeTime := time.Now()

	uiStartCUAddr := pcSlice.GetSliceSegmentCurStartCUAddr()

	uiSliceStartCuAddr := pcSlice.GetSliceCurStartCUAddr()
	if uiSliceStartCuAddr == uiStartCUAddr {
		l := len(this.m_sliceStartCUAddress)
		this.m_sliceStartCUAddress[l] = int(uiSliceStartCuAddr)
		//this.m_sliceStartCUAddress.PushBack(uiSliceStartCuAddr);
	}

	this.m_pcSbacDecoder.Init(this.m_pcBinCABAC) //(TDecBinIf*)
	this.m_pcEntropyDecoder.SetEntropyDecoder(this.m_pcSbacDecoder)
	this.m_pcEntropyDecoder.SetTraceFile(pTraceFile)

	var uiNumSubstreams uint

	if pcSlice.GetPPS().GetEntropyCodingSyncEnabledFlag() {
		uiNumSubstreams = uint(pcSlice.GetNumEntryPointOffsets() + 1)
	} else {
		uiNumSubstreams = uint(pcSlice.GetPPS().GetNumSubstreams())
	}

	// init each couple {EntropyDecoder, Substream}
	puiSubstreamSizes := pcSlice.GetSubstreamSizes()
	ppcSubstreams := make([]*TLibCommon.TComInputBitstream, uiNumSubstreams)
	this.m_pcSbacDecoders = make([]*TDecSbac, uiNumSubstreams)
	this.m_pcBinCABACs = make([]*TDecBinCabac, uiNumSubstreams)
	for ui := uint(0); ui < uiNumSubstreams; ui++ {
		this.m_pcSbacDecoders[ui] = NewTDecSbac()
		this.m_pcBinCABACs[ui] = NewTDecBinCabac()
		this.m_pcSbacDecoders[ui].Init(this.m_pcBinCABACs[ui])
		if ui+1 < uiNumSubstreams {
			ppcSubstreams[ui] = pcBitstream.ExtractSubstream(puiSubstreamSizes[ui])
		} else {
			ppcSubstreams[ui] = pcBitstream.ExtractSubstream(pcBitstream.GetNumBitsLeft())
		}
	}

	for ui := uint(0); ui+1 < uiNumSubstreams; ui++ {
		this.m_pcEntropyDecoder.SetEntropyDecoder(this.m_pcSbacDecoders[uiNumSubstreams-1-ui])
		this.m_pcEntropyDecoder.SetTraceFile(pTraceFile)
		this.m_pcEntropyDecoder.SetBitstream(ppcSubstreams[uiNumSubstreams-1-ui])
		this.m_pcEntropyDecoder.ResetEntropy(pcSlice)
	}

	this.m_pcEntropyDecoder.SetEntropyDecoder(this.m_pcSbacDecoder)
	this.m_pcEntropyDecoder.SetTraceFile(pTraceFile)
	this.m_pcEntropyDecoder.SetBitstream(ppcSubstreams[0])
	this.m_pcEntropyDecoder.ResetEntropy(pcSlice)

	if uiSliceStartCuAddr == uiStartCUAddr {
		l := len(this.m_LFCrossSliceBoundaryFlag)
		this.m_LFCrossSliceBoundaryFlag[l] = pcSlice.GetLFCrossSliceBoundaryFlag()
		//this.m_LFCrossSliceBoundaryFlag.PushBack( pcSlice.GetLFCrossSliceBoundaryFlag());
	}
	this.m_pcSbacDecoders[0].Load(this.m_pcSbacDecoder)
	this.m_pcSliceDecoder.DecompressSlice(ppcSubstreams, rpcPic, this.m_pcSbacDecoder, this.m_pcSbacDecoders)
	this.m_pcEntropyDecoder.SetBitstream(ppcSubstreams[uiNumSubstreams-1])
	// deallocate all created substreams, including internal buffers.
	/*for ui := uint(0); ui < uiNumSubstreams; ui++ {
	    ppcSubstreams[ui]->deleteFifo();
	    delete ppcSubstreams[ui];
	  }
	  delete[] ppcSubstreams;
	  delete[] m_pcSbacDecoders;
	  delete[] m_pcBinCABACs;
	*/
	this.m_pcSbacDecoders = nil
	this.m_pcBinCABACs = nil

	lAfterTime := time.Now()
	this.m_dDecTime += lAfterTime.Sub(iBeforeTime)
}
Esempio n. 2
0
func (this *InputNALUnit) convertPayloadToRBSP(nalUnitBuf *list.List, pcBitstream *TLibCommon.TComInputBitstream, isVclNalUnit bool) *list.List {
	zeroCount := 0
	it_write := list.New()
	oldBuf := list.New()

	pos := uint(0)
	pcBitstream.ClearEmulationPreventionByteLocation()

	for e := nalUnitBuf.Front(); e != nil; e, pos = e.Next(), pos+1 {
		//assert(zeroCount < 2 || *it_read >= 0x03);
		it_read := e.Value.(byte)
		oldBuf.PushBack(it_read)
		if zeroCount == 2 && it_read == 0x03 {
			pcBitstream.PushEmulationPreventionByteLocation(pos)
			pos++

			zeroCount = 0

			e = e.Next()
			if e == nil {
				break
			} else {
				it_read = e.Value.(byte)
				oldBuf.PushBack(it_read)
			}
		}

		if it_read == 0x00 {
			zeroCount++
		} else {
			zeroCount = 0
		}
		it_write.PushBack(it_read)
	}

	//assert(zeroCount == 0);
	if isVclNalUnit {
		// Remove cabac_zero_word from payload if present
		n := 0

		e := it_write.Back()
		it_read := e.Value.(byte)
		for it_read == 0x00 {
			it_write.Remove(e)
			n++
			e = it_write.Back()
			if e != nil {
				it_read = e.Value.(byte)
			} else {
				break
			}
		}

		if n > 0 {
			fmt.Printf("\nDetected %d instances of cabac_zero_word", n/2)
		}
	}

	nalUnitBuf.Init() // = .resize(it_write - nalUnitBuf.begin());
	for e := it_write.Front(); e != nil; e = e.Next() {
		it_read := e.Value.(byte)
		nalUnitBuf.PushBack(it_read)
	}

	return oldBuf
}