//------------------------------------------------------------------- // LockBuffer // // Locks the buffer. Returns a pointer to scan line 0 and returns the stride. // // The caller must provide the default stride as an input parameter, in case // the buffer does not expose IMF2DBuffer. You can calculate the default stride // from the media type. //------------------------------------------------------------------- public int LockBuffer( int lDefaultStride, // Minimum stride (with no padding). int dwHeightInPixels, // Height of the image, in pixels. out IntPtr ppbScanLine0, // Receives a pointer to the start of scan line 0. out int plStride // Receives the actual stride. ) { int hr; ppbScanLine0 = IntPtr.Zero; plStride = 0; // Use the 2-D version if available. if (p2DBuffer != null) { hr = p2DBuffer.Lock2D(out ppbScanLine0, out plStride); } else { // Use non-2D version. IntPtr pData; int pcbMaxLength; int pcbCurrentLength; hr = pBuffer.Lock(out pData, out pcbMaxLength, out pcbCurrentLength); if (Succeeded(hr)) { plStride = lDefaultStride; if (lDefaultStride < 0) { // Bottom-up orientation. Return a pointer to the start of the // last row *in memory* which is the top row of the image. ppbScanLine0 += lDefaultStride * (dwHeightInPixels - 1); } else { // Top-down orientation. Return a pointer to the start of the // buffer. ppbScanLine0 = pData; } } } bLocked = (Succeeded(hr)); return(hr); }
private void Lockit(IMFMediaBuffer pOut, out IMF2DBuffer pOut2D, out int lDestStride, out IntPtr pDest) { MFError throwonhr; pOut2D = pOut as IMF2DBuffer; if (pOut2D != null) { throwonhr = pOut2D.Lock2D(out pDest, out lDestStride); } else { int ml; int cb; throwonhr = pOut.Lock(out pDest, out ml, out cb); lDestStride = m_lStrideIfContiguous; } }