From 631fffee8a28b1bec5ed1f1d26a20e0135967f99 Mon Sep 17 00:00:00 2001 From: Mamadou DIOP Date: Mon, 17 Aug 2015 01:56:35 +0200 Subject: - --- .../internals/wince/CPropertyBag.cxx | 108 +++++++++++ .../internals/wince/CPropertyBag.h | 43 +++++ .../internals/wince/DSISampleGrabberCB.h | 30 ++++ .../internals/wince/DSNullFilter.cxx | 56 ++++++ .../internals/wince/DSNullFilter.h | 40 +++++ .../internals/wince/DSSampleGrabber.cxx | 197 +++++++++++++++++++++ .../internals/wince/DSSampleGrabber.h | 73 ++++++++ .../internals/wince/DSSampleGrabberUtils.h | 38 ++++ 8 files changed, 585 insertions(+) create mode 100644 plugins/pluginDirectShow/internals/wince/CPropertyBag.cxx create mode 100644 plugins/pluginDirectShow/internals/wince/CPropertyBag.h create mode 100644 plugins/pluginDirectShow/internals/wince/DSISampleGrabberCB.h create mode 100644 plugins/pluginDirectShow/internals/wince/DSNullFilter.cxx create mode 100644 plugins/pluginDirectShow/internals/wince/DSNullFilter.h create mode 100644 plugins/pluginDirectShow/internals/wince/DSSampleGrabber.cxx create mode 100644 plugins/pluginDirectShow/internals/wince/DSSampleGrabber.h create mode 100644 plugins/pluginDirectShow/internals/wince/DSSampleGrabberUtils.h (limited to 'plugins/pluginDirectShow/internals/wince') diff --git a/plugins/pluginDirectShow/internals/wince/CPropertyBag.cxx b/plugins/pluginDirectShow/internals/wince/CPropertyBag.cxx new file mode 100644 index 0000000..a6b436a --- /dev/null +++ b/plugins/pluginDirectShow/internals/wince/CPropertyBag.cxx @@ -0,0 +1,108 @@ +#if defined(_WIN32_WCE) +// +// Copyright (c) Microsoft Corporation.  All rights reserved. +// +// +// Use of this source code is subject to the terms of the Microsoft end-user +// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT. +// If you did not accept the terms of the EULA, you are not authorized to use +// this source code. For a copy of the EULA, please see the LICENSE.RTF on your +// install media. +// +#include +#include +#include + +#include "internals/wince/CPropertyBag.h" + +CPropertyBag::CPropertyBag() : _refCount(1), pVar(0) +{ +} + +CPropertyBag::~CPropertyBag() +{ + VAR_LIST *pTemp = pVar; + HRESULT hr = S_OK; + + while(pTemp) { + VAR_LIST *pDel = pTemp; + VariantClear(&pTemp->var); + SysFreeString(pTemp->pBSTRName); + pTemp = pTemp->pNext; + delete pDel; + } + +} + +HRESULT STDMETHODCALLTYPE +CPropertyBag::Read(LPCOLESTR pszPropName, + VARIANT *_pVar, + IErrorLog *pErrorLog) +{ + VAR_LIST *pTemp = pVar; + HRESULT hr = S_OK; + + while (pTemp) { + if (0 == wcscmp(pszPropName, pTemp->pBSTRName)) { + hr = VariantCopy(_pVar, &pTemp->var); + break; + } + pTemp = pTemp->pNext; + } + return hr; +} + + +HRESULT STDMETHODCALLTYPE +CPropertyBag::Write(LPCOLESTR pszPropName, + VARIANT *_pVar) +{ + HRESULT hr = S_OK; + VAR_LIST *pTemp = new VAR_LIST(); + ASSERT(pTemp); + + if ( !pTemp ) { + return E_OUTOFMEMORY; + } + + VariantInit(&pTemp->var); + pTemp->pBSTRName = SysAllocString(pszPropName); + pTemp->pNext = pVar; + pVar = pTemp; + return VariantCopy(&pTemp->var, _pVar); +} + +ULONG STDMETHODCALLTYPE +CPropertyBag::AddRef() +{ + return InterlockedIncrement((LONG *)&_refCount); +} + +ULONG STDMETHODCALLTYPE +CPropertyBag::Release() +{ + ASSERT(_refCount != 0xFFFFFFFF); + ULONG ret = InterlockedDecrement((LONG *)&_refCount); + if (!ret) { + delete this; + } + return ret; +} + +HRESULT STDMETHODCALLTYPE +CPropertyBag::QueryInterface(REFIID riid, void** ppv) +{ + if (!ppv) { + return E_POINTER; + } + if (riid == IID_IPropertyBag) { + *ppv = static_cast(this); + } + else { + return *ppv = 0, E_NOINTERFACE; + } + + return AddRef(), S_OK; +} + +#endif /* _WIN32_WCE */ diff --git a/plugins/pluginDirectShow/internals/wince/CPropertyBag.h b/plugins/pluginDirectShow/internals/wince/CPropertyBag.h new file mode 100644 index 0000000..20ce779 --- /dev/null +++ b/plugins/pluginDirectShow/internals/wince/CPropertyBag.h @@ -0,0 +1,43 @@ +#pragma once + +#if defined(_WIN32_WCE) + +#include "plugin_dshow_config.h" + +struct VAR_LIST +{ + VARIANT var; + VAR_LIST *pNext; + BSTR pBSTRName; +}; + +class CPropertyBag : public IPropertyBag +{ +public: + CPropertyBag(); + ~CPropertyBag(); + + HRESULT STDMETHODCALLTYPE + Read( + LPCOLESTR pszPropName, + VARIANT *pVar, + IErrorLog *pErrorLog + ); + + + HRESULT STDMETHODCALLTYPE + Write( + LPCOLESTR pszPropName, + VARIANT *pVar + ); + + ULONG STDMETHODCALLTYPE AddRef(); + ULONG STDMETHODCALLTYPE Release(); + HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppv); + +private: + ULONG _refCount; + VAR_LIST *pVar; +}; + +#endif /* _WIN32_WCE */ diff --git a/plugins/pluginDirectShow/internals/wince/DSISampleGrabberCB.h b/plugins/pluginDirectShow/internals/wince/DSISampleGrabberCB.h new file mode 100644 index 0000000..89d8909 --- /dev/null +++ b/plugins/pluginDirectShow/internals/wince/DSISampleGrabberCB.h @@ -0,0 +1,30 @@ +/* Copyright (C) 2014-2015 Mamadou DIOP +* +* This file is part of Open Source Doubango Framework. +* +* DOUBANGO is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* DOUBANGO is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with DOUBANGO. +*/ +#pragma once + +#if defined(_WIN32_WCE) + +#include "plugin_dshow_config.h" + +interface DSISampleGrabberCB +{ + virtual HRESULT STDMETHODCALLTYPE SampleCB(double SampleTime, IMediaSample *pSample) = 0; + virtual HRESULT STDMETHODCALLTYPE BufferCB(double SampleTime, BYTE *pBuffer, long BufferLen) = 0; +}; + +#endif /* _WIN32_WCE */ \ No newline at end of file diff --git a/plugins/pluginDirectShow/internals/wince/DSNullFilter.cxx b/plugins/pluginDirectShow/internals/wince/DSNullFilter.cxx new file mode 100644 index 0000000..76d713c --- /dev/null +++ b/plugins/pluginDirectShow/internals/wince/DSNullFilter.cxx @@ -0,0 +1,56 @@ +#if defined(_WIN32_WCE) + +/* Copyright (C) 2014-2015 Mamadou DIOP +* +* This file is part of Open Source Doubango Framework. +* +* DOUBANGO is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* DOUBANGO is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with DOUBANGO. +*/ + +#include "internals/wince/DSNullFilter.h" + +// {7F9F08CF-139F-40b2-A283-01C4EC26A452} +TDSHOW_DEFINE_GUID(CLSID_DSNullFilter, +0x7f9f08cf, 0x139f, 0x40b2, 0xa2, 0x83, 0x1, 0xc4, 0xec, 0x26, 0xa4, 0x52); + +DSNullFilter::DSNullFilter(LPUNKNOWN punk,HRESULT *phr) + : CTransInPlaceFilter(TEXT("NullRenderer"), punk, CLSID_DSNullFilter, phr) +{ +} + +HRESULT DSNullFilter::CheckInputType(const CMediaType *mtIn) +{ + CheckPointer(mtIn,E_POINTER); + + if (*mtIn->FormatType() != FORMAT_VideoInfo) { + return E_INVALIDARG; + } + + if ( *mtIn->Type( ) != MEDIATYPE_Video ) { + return E_INVALIDARG; + } + + if ( *mtIn->Subtype( ) != MEDIASUBTYPE_RGB24 ) { + return E_INVALIDARG; + } + + return NOERROR; +} + +HRESULT DSNullFilter::Transform(IMediaSample *pSample) +{ + return NOERROR; +} + +#endif /* _WIN32_WCE */ diff --git a/plugins/pluginDirectShow/internals/wince/DSNullFilter.h b/plugins/pluginDirectShow/internals/wince/DSNullFilter.h new file mode 100644 index 0000000..fc9b76a --- /dev/null +++ b/plugins/pluginDirectShow/internals/wince/DSNullFilter.h @@ -0,0 +1,40 @@ +/* Copyright (C) 2014-2015 Mamadou DIOP +* +* This file is part of Open Source Doubango Framework. +* +* DOUBANGO is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* DOUBANGO is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with DOUBANGO. +*/ +#pragma once + +#if defined(_WIN32_WCE) + +#include "plugin_dshow_config.h" + +#include +#include + +class DSNullFilter : public CTransInPlaceFilter +{ +public: + + DECLARE_IUNKNOWN; + + HRESULT Transform(IMediaSample *pSample); + HRESULT CheckInputType(const CMediaType *mtIn); + + // Constructor + DSNullFilter( LPUNKNOWN punk, HRESULT *phr ); +}; + +#endif /* _WIN32_WCE */ diff --git a/plugins/pluginDirectShow/internals/wince/DSSampleGrabber.cxx b/plugins/pluginDirectShow/internals/wince/DSSampleGrabber.cxx new file mode 100644 index 0000000..d33d105 --- /dev/null +++ b/plugins/pluginDirectShow/internals/wince/DSSampleGrabber.cxx @@ -0,0 +1,197 @@ +#if defined(_WIN32_WCE) + +#include +#include +#include + + +// {38589364-71FD-4641-B426-E443DB023568} +TDSHOW_DEFINE_GUID(CLSID_SampleGrabber, +0x38589364, 0x71fd, 0x4641, 0xb4, 0x26, 0xe4, 0x43, 0xdb, 0x2, 0x35, 0x68); + +#define RGB565_MASK_RED 0xF800 +#define RGB565_MASK_GREEN 0x07E0 +#define RGB565_MASK_BLUE 0x001F + +DSSampleGrabber::DSSampleGrabber(TCHAR *tszName, LPUNKNOWN punk, HRESULT *phr) +:CTransInPlaceFilter (tszName, punk, CLSID_SampleGrabber, phr) +{ +#define FPS_INPUT 30 +#define FPS_OUTPUT 5 + + this->m_rtFrameLength = (10000000)/FPS_OUTPUT; + + this->m_inputFps = FPS_INPUT; + this->m_outputFps = FPS_OUTPUT; + + this->m_iFrameNumber = 0; + this->m_progress = 0; + this->m_bProcessFrame = true; + + this->callback = NULL; + this->m_rgb24 = NULL; + + m_cRef = 0; +} + +DSSampleGrabber::~DSSampleGrabber() { + this->callback = NULL; + if(this->m_rgb24) + { + delete[]this->m_rgb24; + this->m_rgb24 = NULL; + } +} + +HRESULT DSSampleGrabber::SetFps(int inputFps, int outputFps) +{ + if (inputFps <= 0 || outputFps <= 0) { + return E_FAIL; + } + + // Stop prcessing + this->m_bProcessFrame = false; + + if (inputFps < outputFps) { + this->m_inputFps = this->m_outputFps = inputFps; + } + else { + this->m_outputFps = outputFps; + this->m_inputFps = inputFps; + } + + // Restart processing + this->m_iFrameNumber = 0; + this->m_progress = 0; + this->m_bProcessFrame = true; + + return S_OK; +} + +HRESULT DSSampleGrabber::Transform(IMediaSample *pSample) +{ + BYTE *pData = NULL; + HRESULT hr = S_OK; + HRESULT ret = S_FALSE; + + if (!this->m_bProcessFrame) { + return S_FALSE; + } + + // Get pointer to the video buffer data + if ( FAILED(pSample->GetPointer(&pData)) ) { + ret = E_FAIL; + goto bail; + } + + pSample->SetTime(NULL, NULL); + + // Drop frame? + if (this->m_iFrameNumber == 0) { + ret = S_OK; + } + else if (this->m_progress >= this->m_inputFps) { + this->m_progress -= this->m_inputFps; + ret = S_OK; + } + + // Mark frame as accepted + if (ret == S_OK) { + // Set TRUE on every sample for uncompressed frames + pSample->SetSyncPoint(TRUE); + + long Size = pSample->GetSize(); + if ( this->callback ) { + LONGLONG start, end; + WORD *rgb565 = (WORD*)pData; + + for(int i = 0, i24 = 0, i565 = 0; i< (Size/2); i++, i24+=3, i565+=1) { + BYTE *p24 = (this->m_rgb24+i24); + WORD val565 = *(rgb565 + i565); + + // extract RGB + p24[2] = (val565 & RGB565_MASK_RED) >> 11; + p24[1] = (val565 & RGB565_MASK_GREEN) >> 5; + p24[0] = (val565 & RGB565_MASK_BLUE); + + // amplify the image + p24[2] <<= 3; + p24[1] <<= 2; + p24[0] <<= 3; + } + + pSample->GetMediaTime(&start, &end); + this->callback->BufferCB( (double)start, this->m_rgb24, ((Size >> 1) * 3)); + } + } + + this->m_progress += this->m_outputFps; + this->m_iFrameNumber++; + +bail: + SAFE_DELETE_ARRAY( pData ); + SAFE_RELEASE(pSample); + + return ret; +} + +HRESULT DSSampleGrabber::CheckInputType(const CMediaType* mtIn) +{ + VIDEOINFO *video; + if ( !IsEqualGUID( *mtIn->Subtype(), MEDIASUBTYPE_RGB565 ) || !(video=(VIDEOINFO *)mtIn->Format()) ) { + return E_FAIL; + } + + return S_OK; +} + +STDMETHODIMP DSSampleGrabber::SetCallback( DSISampleGrabberCB* callback_ ) +{ + if (!callback_) { + return E_FAIL; + } + + this->callback = callback_; + return S_OK; +} + +HRESULT DSSampleGrabber::SetSize(int width, int height) +{ + ZeroMemory(&this->mt, sizeof(CMediaType)); + + VIDEOINFO *pvi = (VIDEOINFO *)this->mt.AllocFormatBuffer(sizeof(VIDEOINFO)); + if (NULL == pvi) + { + return E_OUTOFMEMORY; + } + + ZeroMemory(pvi, sizeof(VIDEOINFO)); + + pvi->bmiHeader.biCompression = BI_RGB; + pvi->bmiHeader.biBitCount = 24; + pvi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); + pvi->bmiHeader.biWidth = width; + pvi->bmiHeader.biHeight = height; + pvi->bmiHeader.biPlanes = 1; + pvi->bmiHeader.biSizeImage = GetBitmapSize(&pvi->bmiHeader); + pvi->bmiHeader.biClrImportant = 0; + + // Frame rate + pvi->AvgTimePerFrame = 10000000/this->m_outputFps; + + SetRectEmpty(&(pvi->rcSource)); // we want the whole image area rendered. + SetRectEmpty(&(pvi->rcTarget)); // no particular destination rectangle + + this->mt.SetType(&MEDIATYPE_Video); + this->mt.SetFormatType(&FORMAT_VideoInfo); + this->mt.SetTemporalCompression(FALSE); + + this->mt.SetSubtype(&MEDIASUBTYPE_RGB24); + this->mt.SetSampleSize(pvi->bmiHeader.biSizeImage); + + this->m_rgb24 = new BYTE[pvi->bmiHeader.biSizeImage]; + + return S_OK; +} + +#endif /* _WIN32_WCE */ diff --git a/plugins/pluginDirectShow/internals/wince/DSSampleGrabber.h b/plugins/pluginDirectShow/internals/wince/DSSampleGrabber.h new file mode 100644 index 0000000..39ee5c6 --- /dev/null +++ b/plugins/pluginDirectShow/internals/wince/DSSampleGrabber.h @@ -0,0 +1,73 @@ +/* Copyright (C) 2014-2015 Mamadou DIOP +* +* This file is part of Open Source Doubango Framework. +* +* DOUBANGO is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* DOUBANGO is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with DOUBANGO. +*/ + +#pragma once + +#if defined(_WIN32_WCE) + +#include "plugin_dshow_config.h" + +#include +#include + +#include +#include +#include "DSSampleGrabberUtils.h" + +class DSSampleGrabber : public CTransInPlaceFilter +{ +public: + // instantiation + DSSampleGrabber( TCHAR *tszName, LPUNKNOWN punk, HRESULT *phr ); + ~DSSampleGrabber(void); + +public: + HRESULT Transform(IMediaSample *pSample); + HRESULT CheckInputType(const CMediaType* mtIn); + + HRESULT SetFps(int inputFps, int outputFps); + + // DECLARE_IUNKNOWN; + STDMETHODIMP QueryInterface(REFIID riid, void **ppv) { + return GetOwner()->QueryInterface(riid,ppv); + }; + STDMETHODIMP_(ULONG) AddRef() { + return InterlockedIncrement(&m_cRef); + }; + STDMETHODIMP_(ULONG) Release() { + return GetOwner()->Release(); + }; + + STDMETHODIMP SetCallback(DSISampleGrabberCB* callback_); + HRESULT SetSize(int width, int height); + + inline AM_MEDIA_TYPE GetMediaType() { return (AM_MEDIA_TYPE)this->mt; } + +private: + int m_progress; + int m_inputFps, m_outputFps; + bool m_bProcessFrame; + REFERENCE_TIME m_rtFrameLength; // UNITS/fps + LONGLONG m_iFrameNumber; + + DSISampleGrabberCB* callback; + CMediaType mt; + BYTE *m_rgb24; +}; + +#endif /* _WIN32_WCE */ diff --git a/plugins/pluginDirectShow/internals/wince/DSSampleGrabberUtils.h b/plugins/pluginDirectShow/internals/wince/DSSampleGrabberUtils.h new file mode 100644 index 0000000..01e1728 --- /dev/null +++ b/plugins/pluginDirectShow/internals/wince/DSSampleGrabberUtils.h @@ -0,0 +1,38 @@ +/* Copyright (C) 2014-2015 Mamadou DIOP +* +* This file is part of Open Source Doubango Framework. +* +* DOUBANGO is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* DOUBANGO is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with DOUBANGO. +*/ +#pragma once + +#if defined(_WIN32_WCE) + +// callback definition +typedef void (CALLBACK *MANAGEDCALLBACKPROC)(BYTE* pdata, long len); + +// ISampleGrabber interface definition + +// {04951BFF-696A-4ade-828D-42A5F1EDB631} +DEFINE_GUID(IID_ISampleGrabber, + 0x4951bff, 0x696a, 0x4ade, 0x82, 0x8d, 0x42, 0xa5, 0xf1, 0xed, 0xb6, 0x31); + +DECLARE_INTERFACE_(ISampleGrabber, IUnknown) { + STDMETHOD(SetCallback)(MANAGEDCALLBACKPROC callback) PURE;}; + + // {D11DFE19-8864-4a60-B26C-552F9AA472E1} +DEFINE_GUID(CLSID_NullRenderer, + 0xd11dfe19, 0x8864, 0x4a60, 0xb2, 0x6c, 0x55, 0x2f, 0x9a, 0xa4, 0x72, 0xe1); + +#endif /* _WIN32_WCE */ -- cgit v1.1