简体   繁体   English

为这个directshow系统创建一个自定义类,无法弄清楚如何

[英]Create a custom class for this directshow system, cant figure out how

I'm trying to learn directshow, and computer vision with opencv. 我正在尝试用opencv学习directshow和计算机视觉。 But to keep the code cleaner I want to "put away" (create a class) the directshow code that I've borrowed from the internet. 但为了保持代码清洁,我想“收起”(创建一个类)我从互联网上借来的directshow代码。 The code is: http://alax.info/trac/public/browser/trunk/Utilities/SetLifeCamStudioResolutionSample/SetLifeCamStudioResolutionSample.cpp 代码是: http//alax.info/trac/public/browser/trunk/Utilities/SetLifeCamStudioResolutionSample/SetLifeCamStudioResolutionSample.cpp

Okay. 好的。 so in my vc++ project, I create a new class. 所以在我的vc ++项目中,我创建了一个新类。 I call it "directshowclass", I have directshowclass.h & .cpp. 我称之为“directshowclass”,我有directshowclass.h和.cpp。

The problem I have is that I cant figure out how to take care of all parts in the code. 我遇到的问题是我无法弄清楚如何处理代码中的所有部分。

Everything in _tmain() I put in one function. _tmain()中的所有内容我都放入了一个函数。 that one is okay. 那个没问题。

But what do I do with: 但我该怎么做:

CComPtr<IPin> GetPin(IBaseFilter* pBaseFilter, SIZE_T nIndex = 0)
{
    ....
}

And: 和:

#pragma region Formerly located in qedit.h in Windows SDK, now obsoleted and defined within project

struct __declspec(uuid("0579154a-2b53-4994-b0d0-e773148eff85"))
ISampleGrabberCB : IUnknown
{
    //
    // Raw methods provided by interface
    //

      virtual HRESULT __stdcall SampleCB (double SampleTime,struct IMediaSample * pSample ) = 0;
      virtual HRESULT __stdcall BufferCB double SampleTime,unsigned char * pBuffer, long BufferLen ) = 0;
};

struct __declspec(uuid("6b652fff-11fe-4fce-92ad-0266b5d7c78f"))
ISampleGrabber : IUnknown
{
    //
    // Raw methods provided by interface
    //

      virtual HRESULT __stdcall SetOneShot (
        long OneShot ) = 0;
      virtual HRESULT __stdcall SetMediaType (
        struct _AMMediaType * pType ) = 0;
      virtual HRESULT __stdcall GetConnectedMediaType (
        struct _AMMediaType * pType ) = 0;
      virtual HRESULT __stdcall SetBufferSamples (
        long BufferThem ) = 0;
      virtual HRESULT __stdcall GetCurrentBuffer (
        /*[in,out]*/ long * pBufferSize,
        /*[out]*/ long * pBuffer ) = 0;
      virtual HRESULT __stdcall GetCurrentSample (
        /*[out,retval]*/ struct IMediaSample * * ppSample ) = 0;
      virtual HRESULT __stdcall SetCallback (
        struct ISampleGrabberCB * pCallback,
        long WhichMethodToCallback ) = 0;
};

struct __declspec(uuid("c1f400a0-3f08-11d3-9f0b-006008039e37"))
SampleGrabber;
    // [ default ] interface ISampleGrabber

#pragma endregion

#undef ATLENSURE_SUCCEEDED
#define ATLENSURE_SUCCEEDED(x) { HRESULT __a = (x); if(FAILED(__a)) { _tprintf(_T("Error 0x%08x in line %d\n"), __a, __LINE__); AtlThrow(__a); } }

How do I declare them in the .h file? 如何在.h文件中声明它们? and also .cpp file. 还有.cpp文件。

You can use following qedit.h in your code. 您可以在代码中使用以下qedit.h。 Implement ISampleGrabberCB interface, you can make use of SampleCB or BufferCB to grab the sample. 实现ISampleGrabberCB接口,您可以使用SampleCB或BufferCB来获取样本。

#ifndef __qedit_h__
#define __qedit_h__

///////////////////////////////////////////////////////////////////////////////////

#pragma once

///////////////////////////////////////////////////////////////////////////////////

interface
ISampleGrabberCB
:
    public IUnknown
{
    virtual STDMETHODIMP SampleCB( double SampleTime, IMediaSample *pSample ) = 0;
    virtual STDMETHODIMP BufferCB( double SampleTime, BYTE *pBuffer, long BufferLen ) = 0;
};

///////////////////////////////////////////////////////////////////////////////////

static
const
IID IID_ISampleGrabberCB = { 0x0579154A, 0x2B53, 0x4994, { 0xB0, 0xD0, 0xE7, 0x73, 0x14, 0x8E, 0xFF, 0x85 } };

///////////////////////////////////////////////////////////////////////////////////

interface
ISampleGrabber
:
    public IUnknown
{
    virtual HRESULT STDMETHODCALLTYPE SetOneShot( BOOL OneShot ) = 0;
    virtual HRESULT STDMETHODCALLTYPE SetMediaType( const AM_MEDIA_TYPE *pType ) = 0;
    virtual HRESULT STDMETHODCALLTYPE GetConnectedMediaType( AM_MEDIA_TYPE *pType ) = 0;
    virtual HRESULT STDMETHODCALLTYPE SetBufferSamples( BOOL BufferThem ) = 0;
    virtual HRESULT STDMETHODCALLTYPE GetCurrentBuffer( long *pBufferSize, long *pBuffer ) = 0;
    virtual HRESULT STDMETHODCALLTYPE GetCurrentSample( IMediaSample **ppSample ) = 0;
    virtual HRESULT STDMETHODCALLTYPE SetCallback( ISampleGrabberCB *pCallback, long WhichMethodToCallback ) = 0;
};

///////////////////////////////////////////////////////////////////////////////////

static
const
IID IID_ISampleGrabber = { 0x6B652FFF, 0x11FE, 0x4fce, { 0x92, 0xAD, 0x02, 0x66, 0xB5, 0xD7, 0xC7, 0x8F } };

///////////////////////////////////////////////////////////////////////////////////

static
const
CLSID CLSID_SampleGrabber = { 0xC1F400A0, 0x3F08, 0x11d3, { 0x9F, 0x0B, 0x00, 0x60, 0x08, 0x03, 0x9E, 0x37 } };

///////////////////////////////////////////////////////////////////////////////////

static
const
CLSID CLSID_NullRenderer = { 0xC1F400A4, 0x3F08, 0x11d3, { 0x9F, 0x0B, 0x00, 0x60, 0x08, 0x03, 0x9E, 0x37 } };

///////////////////////////////////////////////////////////////////////////////////

static
const
CLSID CLSID_VideoEffects1Category = { 0xcc7bfb42, 0xf175, 0x11d1, { 0xa3, 0x92, 0x0, 0xe0, 0x29, 0x1f, 0x39, 0x59 } };

///////////////////////////////////////////////////////////////////////////////////

static
const
CLSID CLSID_VideoEffects2Category = { 0xcc7bfb43, 0xf175, 0x11d1, { 0xa3, 0x92, 0x0, 0xe0, 0x29, 0x1f, 0x39, 0x59 } };

///////////////////////////////////////////////////////////////////////////////////

static
const
CLSID CLSID_AudioEffects1Category = { 0xcc7bfb44, 0xf175, 0x11d1, { 0xa3, 0x92, 0x0, 0xe0, 0x29, 0x1f, 0x39, 0x59 } };

///////////////////////////////////////////////////////////////////////////////////

static
const
CLSID CLSID_AudioEffects2Category = { 0xcc7bfb45, 0xf175, 0x11d1, { 0xa3, 0x92, 0x0, 0xe0, 0x29, 0x1f, 0x39, 0x59 } };

///////////////////////////////////////////////////////////////////////////////////

#endif

The second fragment (#pragma region/endregion) is OK to be included on any .h in your project, visible to code that needs it. 第二个片段(#pragma region / endregion)可以包含在项目中的任何.h中,对于需要它的代码是可见的。

The first fragment is a static function. 第一个片段是静态函数。 You can copy it into some of your classes, or you can add "inline" specifier right before "CComPtr GetPin..." on the first line and again leave it on an .h file. 您可以将它复制到您的某些类中,或者您可以在第一行的“CComPtr GetPin ...”之前添加“inline”说明符,并再次将其保留在.h文件中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM