public override int Write(IH264EntropyOutputStream outStream) { var len = 0; len += StartSlice(outStream); foreach (var mb in macroblocks) mb.Write(outStream); TerminateSlice(outStream); return len; }
protected int WriteRBSP(RBSP rbspObj, IH264EntropyOutputStream output) { var rbspSize = rbspObj.Write(output); if (rbspSize < RBSP.Maxrbspsize) { // TODO throw an exception. PayloadOverloadedException? } return 1 + PreventEmulationOfStartCode(output, 0); }
protected int PreventEmulationOfStartCode(IH264EntropyOutputStream output, int beginBytePos) { var endBytePos = output.Length / 8; var j = beginBytePos; for (var i = beginBytePos; i < endBytePos; i++) { // TODO must implement, but I didn't find any file that need this // emulation byte j++; } return j; }
public int Write(IH264EntropyOutputStream stream) { var len = 0; len += stream.WriteUeV(firstMbInSlice); len += stream.WriteUeV((int)sliceType); len += stream.WriteUeV(picParameterSetId); len += stream.WriteUv( log2MaxFrameNumMinus4 + 4, slice.Picture.FrameNum); if (nalUnitType.Equals(NaluType.NaluTypeIdr)) { // idr_pic_id len += stream.WriteUeV(slice.Picture.Number%2); } if (picOrderCntType == 0) { if (frameMbsOnlyFlag) { const int frameSkip = 0; var baseMul = slice.Picture.FrameNum; var toppoc = baseMul*(2*(frameSkip + 1)); var maxLength = ~((-1) << (log2MaxPicOrderCntLsbMinus4 + 4)); picOrderCntLsb = toppoc & maxLength; } else { // TODO Unreachable } len += stream.WriteUv( log2MaxPicOrderCntLsbMinus4 + 4, picOrderCntLsb); } len += RefPicListReordering(stream); if (((int)nalRefIdc) != 0) len += DecRefPicMarking(stream); len += stream.WriteSeV(sliceQpDelta); return len; }
protected override int DoWrite(IH264EntropyOutputStream output) { if(forbiddenZeroBit == 0) throw new Exception(); if(startcodeprefixLen == 3 || startcodeprefixLen == 4) throw new Exception(); if (startcodeprefixLen > 3) output.WriteUv(8, 0); output.WriteUv(8, 0); output.WriteUv(8, 0); output.WriteUv(8, 1); output.WriteUv(8, (forbiddenZeroBit << 7) | (((int)nalRefIdc) << 5) | ((int)nalUnitType)); WriteRBSP(rbsp, output); return (int)output.Length; }
protected abstract int DoWrite(IH264EntropyOutputStream output);
public int Write(IH264EntropyOutputStream output) { output.Nalu = this; return DoWrite(output); }
private static int RefPicListReordering(IH264EntropyOutputStream stream) { return 0; // TODO Unreachable }
public override int Write(IH264EntropyOutputStream stream) { stream.WriteUeV(picParameterSetId); stream.WriteUeV(seqParameterSetId); stream.WriteU1(entropyCodingModeFlag); stream.WriteU1(picOrderPresentFlag); stream.WriteUeV(numSliceGroupsMinus1); // FMO stuff if (numSliceGroupsMinus1 > 0) { // TODO Unreachable } // End of FMO stuff stream.WriteUeV(numRefIdxL0ActiveMinus1); stream.WriteUeV(numRefIdxL1ActiveMinus1); stream.WriteU1(weightedPredFlag); stream.WriteUv(2, weightedBipredIdc); stream.WriteSeV(picInitQpMinus26); stream.WriteSeV(picInitQsMinus26); stream.WriteSeV(chromaQpIndexOffset); stream.WriteU1(deblockingFilterControlPresentFlag); stream.WriteU1(constrainedIntraPredFlag); stream.WriteU1(redundantPicCntPresentFlag); // copies the last couple of bits into the byte Buffer stream.Close(); return (int)(stream.Length / 8); }
public void Write(IH264EntropyOutputStream outStream, int codedBlockPattern) { const int maxNumDcCoeff = 16; const int maxNumAcCoeff = 15; var coeffLevel = new int[maxNumDcCoeff]; var coeffRun = new int[maxNumDcCoeff]; var blockInfo = info.LumaDcBlockInfo; scanner.Reorder4X4(mDc, coeffLevel, coeffRun, 0, maxNumDcCoeff, 0, 0); outStream.WriteResidualBlock(coeffLevel, coeffRun, blockInfo); if ((codedBlockPattern & 15) == 0) return; for (var i8X8 = 0; i8X8 < 4; i8X8++) { for (var i4X4 = 0; i4X4 < 4; i4X4++) { var blockY = 4*(2*(i8X8 >> 1) + (i4X4 >> 1)); var blockX = 4*(2*(i8X8 & 0x01) + (i4X4 & 0x01)); Array.Clear(coeffLevel, 0, coeffLevel.Length); Array.Clear(coeffRun, 0, coeffRun.Length); scanner.Reorder4X4(mResd, coeffLevel, coeffRun, 1, maxNumAcCoeff, blockY, blockX); blockInfo = info.GetLumaAcBlockInfo(blockX >> 2, blockY >> 2); outStream.WriteResidualBlock(coeffLevel, coeffRun, blockInfo); } } }
public void Write(IH264EntropyOutputStream outStream) { DoWrite(outStream); }
public override int Write(IH264EntropyOutputStream stream) { stream.WriteUv(8, profileIdc); stream.WriteU1(constrainedSet0Flag); stream.WriteU1(constrainedSet1Flag); stream.WriteU1(constrainedSet2Flag); stream.WriteU1(constrainedSet3Flag); stream.WriteUv(4, 0); stream.WriteUv(8, levelIdc); stream.WriteUeV(seqParameterSetId); stream.WriteUeV(log2MaxFrameNumMinus4); stream.WriteUeV(picOrderCntType); if (picOrderCntType == 0) { stream.WriteUeV(log2MaxPicOrderCntLsbMinus4); } else if (picOrderCntType == 1) { // TODO Unreachable } stream.WriteUeV(numRefFrames); stream.WriteU1(gapsInFrameNumValueAllowedFlag); stream.WriteUeV(picWidthInMbsMinus1); stream.WriteUeV(picHeightInMapUnitsMinus1); stream.WriteU1(frameMbsOnlyFlag); if (!frameMbsOnlyFlag) { // TODO Unreachable } stream.WriteU1(direct_8X8InferenceFlag); stream.WriteU1(frameCroppingFlag); if (frameCroppingFlag) { // TODO Unreachable } stream.WriteU1(vuiParametersPresentFlag); if (vuiParametersPresentFlag) { // TODO Unreachable } stream.Close(); return (int)(stream.Length/8); }
private static void TerminateSlice(IH264EntropyOutputStream outStream) { outStream.Close(); }
private int StartSlice(IH264EntropyOutputStream bitstream) { header = new SliceHeader(this,bitstream.Nalu,bitstream.Sps,bitstream.Pps); return header.Write(bitstream); }
protected override void DoWrite(IH264EntropyOutputStream outStream) { const int bitDepth = 8; if (macroblock.Slice.SliceType.Equals(SliceType.Slice)) outStream.WriteMbType(25); else outStream.WriteMbType(31); outStream.Flush(); for (var j = 0; j < Macroblock.MbHeight; j++) for (var i = 0; i < Macroblock.MbWidth; i++) outStream.WriteUv(bitDepth, bufferY[i][j]); for (var j = 0; j < Macroblock.MbChromaHeight; j++) for (var i = 0; i < Macroblock.MbChromaWidth; i++) outStream.WriteUv(bitDepth, bufferU[i][j]); for (var j = 0; j < Macroblock.MbChromaHeight; j++) for (var i = 0; i < Macroblock.MbChromaWidth; i++) outStream.WriteUv(bitDepth, bufferV[i][j]); }
protected abstract void DoWrite(IH264EntropyOutputStream outStream);
public void Write(IH264EntropyOutputStream outStream) { bestMode.Write(outStream); }