diff options
Diffstat (limited to 'plugins/pluginDirectShow/internals/DSPushSourceDesktop.cxx')
-rwxr-xr-x | plugins/pluginDirectShow/internals/DSPushSourceDesktop.cxx | 268 |
1 files changed, 134 insertions, 134 deletions
diff --git a/plugins/pluginDirectShow/internals/DSPushSourceDesktop.cxx b/plugins/pluginDirectShow/internals/DSPushSourceDesktop.cxx index 1bdee9e..3e68ee2 100755 --- a/plugins/pluginDirectShow/internals/DSPushSourceDesktop.cxx +++ b/plugins/pluginDirectShow/internals/DSPushSourceDesktop.cxx @@ -18,27 +18,27 @@ /********************************************** * * CPushPinDesktop Class - * + * * **********************************************/ CPushPinDesktop::CPushPinDesktop(HRESULT *phr, CSource *pFilter) - : CSourceStream(NAME("Push Source Desktop"), phr, pFilter, L"Out"), - m_FramesWritten(0), - m_bZeroMemory(0), - m_iFrameNumber(0), - m_rtFrameLength(FPS_5), // Capture and display desktop 5 times per second - m_nCurrentBitDepth(24), - m_hSrcHwnd(NULL) + : CSourceStream(NAME("Push Source Desktop"), phr, pFilter, L"Out"), + m_FramesWritten(0), + m_bZeroMemory(0), + m_iFrameNumber(0), + m_rtFrameLength(FPS_5), // Capture and display desktop 5 times per second + m_nCurrentBitDepth(24), + m_hSrcHwnd(NULL) { - // The main point of this sample is to demonstrate how to take a DIB - // in host memory and insert it into a video stream. + // The main point of this sample is to demonstrate how to take a DIB + // in host memory and insert it into a video stream. - // To keep this sample as simple as possible, we just read the desktop image - // from a file and copy it into every frame that we send downstream. + // To keep this sample as simple as possible, we just read the desktop image + // from a file and copy it into every frame that we send downstream. // - // In the filter graph, we connect this filter to the AVI Mux, which creates - // the AVI file with the video frames we pass to it. In this case, + // In the filter graph, we connect this filter to the AVI Mux, which creates + // the AVI file with the video frames we pass to it. In this case, // the end result is a screen capture video (GDI images only, with no // support for overlay surfaces). @@ -60,7 +60,7 @@ CPushPinDesktop::CPushPinDesktop(HRESULT *phr, CSource *pFilter) } CPushPinDesktop::~CPushPinDesktop() -{ +{ DbgLog((LOG_TRACE, 3, TEXT("Frames written %d"), m_iFrameNumber)); } @@ -84,74 +84,76 @@ HRESULT CPushPinDesktop::GetMediaType(int iPosition, CMediaType *pmt) CheckPointer(pmt,E_POINTER); CAutoLock cAutoLock(m_pFilter->pStateLock()); - if(iPosition < 0) + if(iPosition < 0) { return E_INVALIDARG; + } // Have we run off the end of types? - if(iPosition > 4) + if(iPosition > 4) { return VFW_S_NO_MORE_ITEMS; + } VIDEOINFO *pvi = (VIDEOINFO *) pmt->AllocFormatBuffer(sizeof(VIDEOINFO)); - if(NULL == pvi) + if(NULL == pvi) { return(E_OUTOFMEMORY); + } // Initialize the VideoInfo structure before configuring its members ZeroMemory(pvi, sizeof(VIDEOINFO)); - switch(iPosition) - { - case 0: - { - // Return our highest quality 32bit format - - // Since we use RGB888 (the default for 32 bit), there is - // no reason to use BI_BITFIELDS to specify the RGB - // masks. Also, not everything supports BI_BITFIELDS - pvi->bmiHeader.biCompression = BI_RGB; - pvi->bmiHeader.biBitCount = 32; - break; - } + switch(iPosition) { + case 0: { + // Return our highest quality 32bit format - case 1: - { // Return our 24bit format - pvi->bmiHeader.biCompression = BI_RGB; - pvi->bmiHeader.biBitCount = 24; - break; - } + // Since we use RGB888 (the default for 32 bit), there is + // no reason to use BI_BITFIELDS to specify the RGB + // masks. Also, not everything supports BI_BITFIELDS + pvi->bmiHeader.biCompression = BI_RGB; + pvi->bmiHeader.biBitCount = 32; + break; + } - case 2: - { - // 16 bit per pixel RGB565 + case 1: { + // Return our 24bit format + pvi->bmiHeader.biCompression = BI_RGB; + pvi->bmiHeader.biBitCount = 24; + break; + } - // Place the RGB masks as the first 3 doublewords in the palette area - for(int i = 0; i < 3; i++) - pvi->TrueColorInfo.dwBitMasks[i] = bits565[i]; + case 2: { + // 16 bit per pixel RGB565 - pvi->bmiHeader.biCompression = BI_BITFIELDS; - pvi->bmiHeader.biBitCount = 16; - break; + // Place the RGB masks as the first 3 doublewords in the palette area + for(int i = 0; i < 3; i++) { + pvi->TrueColorInfo.dwBitMasks[i] = bits565[i]; } - case 3: - { // 16 bits per pixel RGB555 + pvi->bmiHeader.biCompression = BI_BITFIELDS; + pvi->bmiHeader.biBitCount = 16; + break; + } - // Place the RGB masks as the first 3 doublewords in the palette area - for(int i = 0; i < 3; i++) - pvi->TrueColorInfo.dwBitMasks[i] = bits555[i]; + case 3: { + // 16 bits per pixel RGB555 - pvi->bmiHeader.biCompression = BI_BITFIELDS; - pvi->bmiHeader.biBitCount = 16; - break; + // Place the RGB masks as the first 3 doublewords in the palette area + for(int i = 0; i < 3; i++) { + pvi->TrueColorInfo.dwBitMasks[i] = bits555[i]; } - case 4: - { // 8 bit palettised + pvi->bmiHeader.biCompression = BI_BITFIELDS; + pvi->bmiHeader.biBitCount = 16; + break; + } - pvi->bmiHeader.biCompression = BI_RGB; - pvi->bmiHeader.biBitCount = 8; - pvi->bmiHeader.biClrUsed = iPALETTE_COLORS; - break; - } + case 4: { + // 8 bit palettised + + pvi->bmiHeader.biCompression = BI_RGB; + pvi->bmiHeader.biBitCount = 8; + pvi->bmiHeader.biClrUsed = iPALETTE_COLORS; + break; + } } // Adjust the parameters common to all formats @@ -191,38 +193,37 @@ HRESULT CPushPinDesktop::CheckMediaType(const CMediaType *pMediaType) CheckPointer(pMediaType,E_POINTER); if((*(pMediaType->Type()) != MEDIATYPE_Video) || // we only output video - !(pMediaType->IsFixedSize())) // in fixed size samples - { + !(pMediaType->IsFixedSize())) { // in fixed size samples return E_INVALIDARG; } // Check for the subtypes we support const GUID *SubType = pMediaType->Subtype(); - if (SubType == NULL) + if (SubType == NULL) { return E_INVALIDARG; + } if( (*SubType != MEDIASUBTYPE_RGB24) #if 0 - && (*SubType != MEDIASUBTYPE_RGB565) - && (*SubType != MEDIASUBTYPE_RGB555) - && (*SubType != MEDIASUBTYPE_RGB32) - && (*SubType != MEDIASUBTYPE_RGB8) + && (*SubType != MEDIASUBTYPE_RGB565) + && (*SubType != MEDIASUBTYPE_RGB555) + && (*SubType != MEDIASUBTYPE_RGB32) + && (*SubType != MEDIASUBTYPE_RGB8) #endif - ) - { + ) { return E_INVALIDARG; } // Get the format area of the media type VIDEOINFO *pvi = (VIDEOINFO *) pMediaType->Format(); - if(pvi == NULL) + if(pvi == NULL) { return E_INVALIDARG; + } // Check if the image width & height have changed - if( pvi->bmiHeader.biWidth != m_iImageWidth || - abs(pvi->bmiHeader.biHeight) != m_iImageHeight) - { + if( pvi->bmiHeader.biWidth != m_iImageWidth || + abs(pvi->bmiHeader.biHeight) != m_iImageHeight) { // If the image width/height is changed, fail CheckMediaType() to force // the renderer to resize the image. return E_INVALIDARG; @@ -230,8 +231,9 @@ HRESULT CPushPinDesktop::CheckMediaType(const CMediaType *pMediaType) // Don't accept formats with negative height, which would cause the desktop // image to be displayed upside down. - if (pvi->bmiHeader.biHeight < 0) + if (pvi->bmiHeader.biHeight < 0) { return E_INVALIDARG; + } return S_OK; // This format is acceptable. @@ -246,7 +248,7 @@ HRESULT CPushPinDesktop::CheckMediaType(const CMediaType *pMediaType) // Then we can ask for buffers of the correct size to contain them. // HRESULT CPushPinDesktop::DecideBufferSize(IMemAllocator *pAlloc, - ALLOCATOR_PROPERTIES *pProperties) + ALLOCATOR_PROPERTIES *pProperties) { CheckPointer(pAlloc,E_POINTER); CheckPointer(pProperties,E_POINTER); @@ -265,14 +267,12 @@ HRESULT CPushPinDesktop::DecideBufferSize(IMemAllocator *pAlloc, // memory that we requested, so we must check we got whatever we wanted. ALLOCATOR_PROPERTIES Actual; hr = pAlloc->SetProperties(pProperties,&Actual); - if(FAILED(hr)) - { + if(FAILED(hr)) { return hr; } // Is this allocator unsuitable? - if(Actual.cbBuffer < pProperties->cbBuffer) - { + if(Actual.cbBuffer < pProperties->cbBuffer) { return E_FAIL; } @@ -297,31 +297,30 @@ HRESULT CPushPinDesktop::SetMediaType(const CMediaType *pMediaType) // Pass the call up to my base class HRESULT hr = CSourceStream::SetMediaType(pMediaType); - if(SUCCEEDED(hr)) - { + if(SUCCEEDED(hr)) { VIDEOINFO * pvi = (VIDEOINFO *) m_mt.Format(); - if (pvi == NULL) + if (pvi == NULL) { return E_UNEXPECTED; + } - switch(pvi->bmiHeader.biBitCount) - { - case 8: // 8-bit palettized - case 16: // RGB565, RGB555 - case 24: // RGB24 - case 32: // RGB32 - // Save the current media type and bit depth - m_MediaType = *pMediaType; - m_nCurrentBitDepth = pvi->bmiHeader.biBitCount; - hr = S_OK; - break; - - default: - // We should never agree any other media types - ASSERT(FALSE); - hr = E_INVALIDARG; - break; + switch(pvi->bmiHeader.biBitCount) { + case 8: // 8-bit palettized + case 16: // RGB565, RGB555 + case 24: // RGB24 + case 32: // RGB32 + // Save the current media type and bit depth + m_MediaType = *pMediaType; + m_nCurrentBitDepth = pvi->bmiHeader.biBitCount; + hr = S_OK; + break; + + default: + // We should never agree any other media types + ASSERT(FALSE); + hr = E_INVALIDARG; + break; } - } + } return hr; @@ -332,7 +331,7 @@ HRESULT CPushPinDesktop::SetMediaType(const CMediaType *pMediaType) // FillBuffer is called once for every sample in the stream. HRESULT CPushPinDesktop::FillBuffer(IMediaSample *pSample) { - BYTE *pData; + BYTE *pData; long cbData; CheckPointer(pSample, E_POINTER); @@ -348,18 +347,19 @@ HRESULT CPushPinDesktop::FillBuffer(IMediaSample *pSample) VIDEOINFOHEADER *pVih = (VIDEOINFOHEADER*)m_mt.pbFormat; - // Copy the DIB bits over into our filter's output buffer. + // Copy the DIB bits over into our filter's output buffer. // Since sample size may be larger than the image size, bound the copy size. int nSize = min(pVih->bmiHeader.biSizeImage, (DWORD) cbData); HDIB hDib = CopyScreenToBitmap(&m_rScreen, pData, (BITMAPINFO *) &(pVih->bmiHeader)); - if (hDib) + if (hDib) { DeleteObject(hDib); + } - // Set the timestamps that will govern playback frame rate. - // If this file is getting written out as an AVI, - // then you'll also need to configure the AVI Mux filter to - // set the Average Time Per Frame for the AVI Header. + // Set the timestamps that will govern playback frame rate. + // If this file is getting written out as an AVI, + // then you'll also need to configure the AVI Mux filter to + // set the Average Time Per Frame for the AVI Header. // The current time is the sample's start. REFERENCE_TIME rtStart = m_iFrameNumber * m_rtFrameLength; REFERENCE_TIME rtStop = rtStart + m_rtFrameLength; @@ -367,7 +367,7 @@ HRESULT CPushPinDesktop::FillBuffer(IMediaSample *pSample) pSample->SetTime(&rtStart, &rtStop); m_iFrameNumber++; - // Set TRUE on every sample for uncompressed frames + // Set TRUE on every sample for uncompressed frames pSample->SetSyncPoint(TRUE); return S_OK; @@ -382,28 +382,28 @@ HRESULT CPushPinDesktop::FillBuffer(IMediaSample *pSample) **********************************************/ CPushSourceDesktop::CPushSourceDesktop(IUnknown *pUnk, HRESULT *phr) - : CSource(NAME("PushSourceDesktop"), pUnk, CLSID_PushSourceDesktop) + : CSource(NAME("PushSourceDesktop"), pUnk, CLSID_PushSourceDesktop) { // The pin magically adds itself to our pin array. m_pPin = new CPushPinDesktop(phr, this); - if (phr) - { - if (m_pPin == NULL) - *phr = E_OUTOFMEMORY; - else - *phr = S_OK; - } + if (phr) { + if (m_pPin == NULL) { + *phr = E_OUTOFMEMORY; + } + else { + *phr = S_OK; + } + } } CPushSourceDesktop::~CPushSourceDesktop() { - if (m_pPin) - { - delete m_pPin; - m_pPin = NULL; - } + if (m_pPin) { + delete m_pPin; + m_pPin = NULL; + } } @@ -411,24 +411,24 @@ CUnknown * WINAPI CPushSourceDesktop::CreateInstance(IUnknown *pUnk, HRESULT *ph { CPushSourceDesktop *pNewFilter = new CPushSourceDesktop(pUnk, phr ); - if (phr) - { - if (pNewFilter == NULL) - *phr = E_OUTOFMEMORY; - else - *phr = S_OK; - } + if (phr) { + if (pNewFilter == NULL) { + *phr = E_OUTOFMEMORY; + } + else { + *phr = S_OK; + } + } return pNewFilter; } HRESULT CPushSourceDesktop::SetSrcHwnd(HWND hWnd) { - if (m_pPin) - { - return m_pPin->SetSrcHwnd(hWnd); - } - return E_FAIL; + if (m_pPin) { + return m_pPin->SetSrcHwnd(hWnd); + } + return E_FAIL; } #endif /* _WIN32_WCE */ |