1 // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
2 // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
3 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
6 // Copyright (c) Microsoft Corporation. All rights reserved
12 //////////////////////////////////////////////////////////////////////////
16 // Locks a video buffer that might or might not support IMF2DBuffer.
18 //////////////////////////////////////////////////////////////////////////
23 VideoBufferLock(IMFMediaBuffer *pBuffer) : m_p2DBuffer(NULL)
28 // Query for the 2-D buffer interface. OK if this fails.
29 m_pBuffer->QueryInterface(IID_PPV_ARGS(&m_p2DBuffer));
35 SafeRelease(&m_pBuffer);
36 SafeRelease(&m_p2DBuffer);
40 // Locks the buffer. Returns a pointer to scan line 0 and returns the stride.
42 // The caller must provide the default stride as an input parameter, in case
43 // the buffer does not expose IMF2DBuffer. You can calculate the default stride
44 // from the media type.
47 LONG lDefaultStride, // Minimum stride (with no padding).
48 DWORD dwHeightInPixels, // Height of the image, in pixels.
49 BYTE **ppbScanLine0, // Receives a pointer to the start of scan line 0.
50 LONG *plStride // Receives the actual stride.
55 // Use the 2-D version if available.
58 hr = m_p2DBuffer->Lock2D(ppbScanLine0, plStride);
62 // Use non-2D version.
65 hr = m_pBuffer->Lock(&pData, NULL, NULL);
68 *plStride = lDefaultStride;
69 if (lDefaultStride < 0)
71 // Bottom-up orientation. Return a pointer to the start of the
72 // last row *in memory* which is the top row of the image.
73 *ppbScanLine0 = pData + abs(lDefaultStride) * (dwHeightInPixels - 1);
77 // Top-down orientation. Return a pointer to the start of the
79 *ppbScanLine0 = pData;
86 HRESULT UnlockBuffer()
90 return m_p2DBuffer->Unlock2D();
94 return m_pBuffer->Unlock();
99 IMFMediaBuffer *m_pBuffer;
100 IMF2DBuffer *m_p2DBuffer;