PlayerCaptureDialog.h
资源名称:bfyy.rar [点击查看]
上传用户:tangyu_668
上传日期:2014-02-27
资源大小:678k
文件大小:5k
源码类别:
多媒体编程
开发平台:
Visual C++
- /*
- * Copyright (C) 2003-2006 Gabest
- * http://www.gabest.org
- *
- * This Program 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 2, or (at your option)
- * any later version.
- *
- * This Program 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 GNU Make; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
- */
- #pragma once
- #include "afxwin.h"
- #include "afxcmn.h"
- #include "....filterstransformbufferfilterbufferfilter.h"
- #include "FloatEdit.h"
- //
- template<class T>
- class CFormatElem
- {
- public:
- CMediaType mt;
- T caps;
- };
- template<class T>
- class CFormat : public CAutoPtrArray<CFormatElem<T> >
- {
- public:
- CString name;
- CFormat(CString name = _T("")) {this->name = name;}
- virtual ~CFormat() {}
- };
- template<class T>
- class CFormatArray : public CAutoPtrArray<CFormat<T> >
- {
- public:
- virtual ~CFormatArray() {}
- CFormat<T>* Find(CString name, bool fCreate = false)
- {
- for(int i = 0; i < (int)GetCount(); i++)
- {
- if(GetAt(i)->name == name)
- return(GetAt(i));
- }
- if(fCreate)
- {
- CAutoPtr<CFormat<T> > pf(new CFormat<T>(name));
- CFormat<T>* tmp = pf;
- Add(pf);
- return(tmp);
- }
- return(NULL);
- }
- bool FindFormat(AM_MEDIA_TYPE* pmt, CFormat<T>** ppf)
- {
- if(!pmt) return(false);
- for(int i = 0; i < (int)GetCount(); i++)
- {
- CFormat<T>* pf = GetAt(i);
- for(int j = 0; j < (int)pf->GetCount(); j++)
- {
- CFormatElem<T>* pfe = pf->GetAt(j);
- if(!pmt || (pfe->mt.majortype == pmt->majortype && pfe->mt.subtype == pmt->subtype))
- {
- if(ppf) *ppf = pf;
- return(true);
- }
- }
- }
- return(false);
- }
- bool FindFormat(AM_MEDIA_TYPE* pmt, T* pcaps, CFormat<T>** ppf, CFormatElem<T>** ppfe)
- {
- if(!pmt && !pcaps) return(false);
- for(int i = 0; i < (int)GetCount(); i++)
- {
- CFormat<T>* pf = GetAt(i);
- for(int j = 0; j < (int)pf->GetCount(); j++)
- {
- CFormatElem<T>* pfe = pf->GetAt(j);
- if((!pmt || pfe->mt == *pmt) && (!pcaps || !memcmp(pcaps, &pfe->caps, sizeof(T))))
- {
- if(ppf) *ppf = pf;
- if(ppfe) *ppfe = pfe;
- return(true);
- }
- }
- }
- return(false);
- }
- bool AddFormat(AM_MEDIA_TYPE* pmt, T caps)
- {
- if(!pmt) return(false);
- if(FindFormat(pmt, NULL, NULL, NULL)) {DeleteMediaType(pmt); return(false);}
- // if(pmt->formattype == FORMAT_VideoInfo2) {DeleteMediaType(pmt); return(false);} // TODO
- CFormat<T>* pf = Find(MakeFormatName(pmt), true);
- if(!pf) {DeleteMediaType(pmt); return(false);}
- CAutoPtr<CFormatElem<T> > pfe(new CFormatElem<T>());
- pfe->mt = *pmt;
- pfe->caps = caps;
- pf->Add(pfe);
- return(true);
- }
- bool AddFormat(AM_MEDIA_TYPE* pmt, void* pcaps, int size)
- {
- if(!pcaps) return false;
- ASSERT(size == sizeof(T));
- return AddFormat(pmt, *(T*)pcaps);
- }
- virtual CString MakeFormatName(AM_MEDIA_TYPE* pmt) = 0;
- virtual CString MakeDimensionName(CFormatElem<T>* pfe) = 0;
- };
- typedef CFormatElem<VIDEO_STREAM_CONFIG_CAPS> CVidFormatElem;
- typedef CFormat<VIDEO_STREAM_CONFIG_CAPS> CVidFormat;
- class CVidFormatArray : public CFormatArray<VIDEO_STREAM_CONFIG_CAPS>
- {
- public:
- CString MakeFormatName(AM_MEDIA_TYPE* pmt)
- {
- CString str(_T("Default"));
- if(!pmt) return(str);
- BITMAPINFOHEADER* bih = (pmt->formattype == FORMAT_VideoInfo)
- ? &((VIDEOINFOHEADER*)pmt->pbFormat)->bmiHeader
- : (pmt->formattype == FORMAT_VideoInfo2)
- ? &((VIDEOINFOHEADER2*)pmt->pbFormat)->bmiHeader
- : NULL;
- if(!bih)
- {
- // it may have a fourcc in the mediasubtype, let's check that
- WCHAR guid[100];
- memset(guid, 0, 100*sizeof(WCHAR));
- StringFromGUID2(pmt->subtype, guid, 100);
- if(CStringW(guid).MakeUpper().Find(L"0000-0010-8000-00AA00389B71") >= 0)
- {
- str.Format(_T("%c%c%c%c"),
- (TCHAR)((pmt->subtype.Data1>>0)&0xff), (TCHAR)((pmt->subtype.Data1>>8)&0xff),
- (TCHAR)((pmt->subtype.Data1>>16)&0xff), (TCHAR)((pmt->subtype.Data1>>24)&0xff));
- }
- return(str);
- }
- switch(bih->biCompression)
- {
- case BI_RGB: str.Format(_T("RGB%d"), bih->biBitCount); break;
- case BI_RLE8: str = _T("RLE8"); break;
- case BI_RLE4: str = _T("RLE4"); break;
- case BI_BITFIELDS: str.Format(_T("BITF%d"), bih->biBitCount); break;
- case BI_JPEG: str = _T("JPEG"); break;
- case BI_PNG: str = _T("PNG"); break;
- default:
- str.Format(_T("%c%c%c%c"),
- (TCHAR)((bih->biCompression>>0)&0xff), (TCHAR)((bih->biCompression>>8)&0xff),
- (TCHAR)((bih->biCompression>>16)&0xff), (TCHAR)((bih->biCompression>>24)&0xff));
- break;
- }
- return(str);
- }
- CString MakeDimensionName(CVidFormatElem* pfe)
- {
- CString str(_T("Default"));
- if(!pfe) return(str);
- BITMAPINFOHEADER* bih = (pfe->mt.formattype == FORMAT_VideoInfo)
- ? &((VIDEOINFOHEADER*)pfe->mt.pbFormat)->bmiHeader
- : (pfe->mt.formattype == FORMAT_VideoInfo2)
- ? &((VIDEOINFOHEADER2*)pfe->mt.pbFormat)->bmiHeader
- : NULL;
- if(bih == NULL) return(str);
- str.Format(_T("%dx%d %.2f"), bih->biWidth, bih->biHeight, (float)10000000/((VIDEOINFOHEADER*)pfe->mt.pbFormat)->AvgTimePerFrame);
- if(pfe->mt.formattype == FORMAT_Vide