void CDXVADecoderMpeg2::CopyBitstream(BYTE* pDXVABuffer, BYTE* pBuffer, UINT& nSize) { while (*((DWORD*)pBuffer) != 0x01010000) { pBuffer++; nSize--; if (nSize <= 0) { return; } } memcpy_sse (pDXVABuffer, pBuffer, nSize); }
bool CDXVADecoderMpeg2::ShrinkBuffer() { CheckPointer(m_pMPEG2Buffer, false); int nRemaining = m_nMPEG2BufferPos-m_nMPEG2PicEnd; PopBufferTime (m_nMPEG2PicEnd); memcpy_sse (m_pMPEG2Buffer, m_pMPEG2Buffer+m_nMPEG2PicEnd, nRemaining); m_nMPEG2BufferPos = nRemaining; m_nMPEG2PicEnd = (m_pMPEG2Buffer[3] == 0x00) ? 0 : INT_MIN; return true; }
HRESULT CDXVADecoderH264_DXVA1::CopyBitstream(BYTE* pDXVABuffer, BYTE* pBuffer, UINT& nSize, UINT nDXVASize/* = UINT_MAX*/) { CH264Nalu Nalu; UINT m_nSize = nSize; int nDxvaNalLength; m_nSlices = 0; Nalu.SetBuffer(pBuffer, m_nSize, m_nNALLength); nSize = 0; while (Nalu.ReadNext()) { switch (Nalu.GetType()) { case NALU_TYPE_SLICE: case NALU_TYPE_IDR: // Skip the NALU if the data length is below 0 if ((int)Nalu.GetDataLength() < 0) { break; } // For AVC1, put startcode 0x000001 pDXVABuffer[0] = pDXVABuffer[1] = 0; pDXVABuffer[2] = 1; // Copy NALU memcpy_sse(pDXVABuffer + 3, Nalu.GetDataBuffer(), Nalu.GetDataLength()); // Update slice control buffer nDxvaNalLength = Nalu.GetDataLength() + 3; m_pSliceShort[m_nSlices].BSNALunitDataLocation = nSize; m_pSliceShort[m_nSlices].SliceBytesInBuffer = nDxvaNalLength; nSize += nDxvaNalLength; pDXVABuffer += nDxvaNalLength; m_nSlices++; break; } } // Complete bitstream buffer with zero padding (buffer size should be a multiple of 128) if (nSize % 128) { int nDummy = 128 - (nSize % 128); memset(pDXVABuffer, 0, nDummy); m_pSliceShort[m_nSlices-1].SliceBytesInBuffer += nDummy; nSize += nDummy; } return S_OK; }
bool CDXVADecoderMpeg2::AppendBuffer (BYTE* pDataIn, int nSize, REFERENCE_TIME rtStart, REFERENCE_TIME rtStop) { if (rtStart != INVALID_TIME) { PushBufferTime (m_nMPEG2BufferPos, rtStart, rtStop); } if (m_nMPEG2BufferPos+nSize > m_nMPEG2BufferSize) { m_nMPEG2BufferSize = m_nMPEG2BufferPos+nSize; m_pMPEG2Buffer = (BYTE*)av_realloc(m_pMPEG2Buffer, m_nMPEG2BufferSize); } memcpy_sse(m_pMPEG2Buffer+m_nMPEG2BufferPos, pDataIn, nSize); m_nMPEG2BufferPos += nSize; return true; }