关于filter动态重连后如何获取新的media type

class CMyPin : public CTransInPlaceInputPin
{
public:
 CMyPin::CMyPin(TCHAR *pObjectName,CTransInPlaceFilter *pFilter,HRESULT *phr,
  LPCWSTR pName);

 ~CMyPin() { };
 STDMETHODIMP QueryAccept(const AM_MEDIA_TYPE *pmt);

 int m_nWidth;
 int m_nHeight;
};

CMyPin::CMyPin(TCHAR *pObjectName,CTransInPlaceFilter *pFilter,HRESULT *phr,
      LPCWSTR pName) : CTransInPlaceInputPin(pObjectName,pFilter,phr,pName)
      ,m_nWidth(0)
      ,m_nHeight(0)
{ };

STDMETHODIMP CMyPin::QueryAccept(const AM_MEDIA_TYPE *pmt)
{
 VIDEOINFOHEADER *pvih = (VIDEOINFOHEADER*)(pmt->pbFormat);
    if(pvih)
 {
  m_nWidth = pvih->bmiHeader.biWidth;
  m_nHeight = pvih->bmiHeader.biHeight;

  /*TCHAR szBuf[32];
  wsprintf(szBuf,L"%d,%d",m_nWidth,m_nHeight);
  MessageBox(NULL,(LPCWSTR)szBuf,(LPCWSTR)szBuf,MB_OK);*/
 }

 return CTransInPlaceInputPin::QueryAccept(pmt);
}

注意:我们的filter是DSHOW中CNullNull改写的

CBasePin * CNullNull::GetPin(int n)
{
 HRESULT hr = S_OK;
 
 if(m_pInput == NULL)
 {
  //CBasePin *pPin = NULL;
  m_pInput = new CMyPin(NULL,this,&hr,NULL);
  ASSERT(SUCCEEDED(hr));
 }

 if (m_pInput!=NULL && m_pOutput == NULL) {

  m_pOutput = new CTransInPlaceOutputPin( NAME("TransInPlace output pin")
   , this       // Owner filter
   , &hr        // Result code
   , L"Output"  // Pin name
   );

  // a failed return code should delete the object

  ASSERT(SUCCEEDED(hr));
  if (m_pOutput == NULL) {
   delete m_pInput;
   m_pInput = NULL;
  }
 }

 // Return the appropriate pin

 ASSERT (n>=0 && n<=1);
 if (n == 0) {
  return m_pInput;
 } else if (n==1) {
  return m_pOutput;
 } else {
  return NULL;
 }

}

HRESULT CNullNull::Transform(IMediaSample *pSample)
{
 CheckPointer(pSample,E_POINTER);
 BYTE *pSrc = NULL;
 HRESULT hr = pSample->GetPointer(&pSrc);

 ///

 VIDEOINFO* pVI = (VIDEOINFO*) m_pInput->CurrentMediaType().Format();
 if(pVI==NULL)
 {
  return E_FAIL;
 }

 long len = pSample->GetActualDataLength();
 int iw = pVI->bmiHeader.biWidth, ih = pVI->bmiHeader.biHeight;

 CMyPin *pPin = (CMyPin*)m_pInput;
 
 if( pPin->m_nWidth != 0 && pPin->m_nHeight != 0 )
 {
  iw = pPin->m_nWidth;
  ih = pPin->m_nHeight;
 }

 if(iw==0 || ih==0)
 {
  return E_FAIL;
 }

 if(iw==320 && ih==240)
 {
  CopyMemory(m_pbDataSend,pSrc,320*240*2);
        return S_OK;
 }

 long nSize = iw*ih*2;
 BYTE *pBuf = new BYTE[nSize];
 if(pBuf)
 {
  int iStepW = iw/320, iStepH = ih/240;
  int iws = iw-320, ihs = ih-240;
  int iwr = 0, ihr = 0;
  if(iws>0)
   iwr = iw/iws;
  if(ihs>0)
   ihr = ih/ihs;

  if(iStepW==1)
  {
   for(int y=0; y<ih; ++y)
   {
    int k=0;
    for(int x=0,n=0; x<iw/2; ++x,++n)
    {
     if(iwr!=0)
     {
      if(x%iwr==0 && k<iws/2)
      {
       ++x;
       ++k;
      }
     }
     *(pBuf+y*320*2+n*4+0) = *(pSrc+y*iw*2+x*4+0);
     *(pBuf+y*320*2+n*4+1) = *(pSrc+y*iw*2+x*4+1);
     *(pBuf+y*320*2+n*4+2) = *(pSrc+y*iw*2+x*4+2);
     *(pBuf+y*320*2+n*4+3) = *(pSrc+y*iw*2+x*4+3);
    }
   }

   memset(pSrc,0,len);
   CopyMemory(pSrc,pBuf,ih*320*2);
  }
  else if(iStepW==2)
  { 
   if(iw>640)
   {
    int iStep640 = iw/(iw-640);
    for(int y=0; y<ih; ++y)
    {
     for(int xSrc=0,xDst=0; xSrc<iw/2; ++xSrc,++xDst)
     {
      if(xSrc%iStep640==0)
       ++xSrc;
      *(pBuf+y*640*2+xDst*4+0) = *(pSrc+y*iw*2+xSrc*4+0);
      *(pBuf+y*640*2+xDst*4+1) = *(pSrc+y*iw*2+xSrc*4+1);
      *(pBuf+y*640*2+xDst*4+2) = *(pSrc+y*iw*2+xSrc*4+2);
      *(pBuf+y*640*2+xDst*4+3) = *(pSrc+y*iw*2+xSrc*4+3);
     }
    }
   }
   else
   {
    CopyMemory(pBuf,pSrc,640*ih*2);
   }

   memset(pSrc,0,len);
   for(int y=0; y<ih; ++y)
   {
    for(int x=0,n=0; x<640/2; x=x+2,++n)
    {
     *(pSrc+y*320*2+n*4+0) = *(pBuf+y*640*2+x*4+0);
     *(pSrc+y*320*2+n*4+1) = *(pBuf+y*640*2+x*4+1);
     *(pSrc+y*320*2+n*4+2) = *(pBuf+y*640*2+x*4+2);
     *(pSrc+y*320*2+n*4+3) = *(pBuf+y*640*2+x*4+3);
    }
   }
  }

        if(iStepH==1)
  {
   int j=0;
   for(int y=0,m=0; y<ih; ++y,++m)
   {  
    if(ihr!=0)
    {
     if(y%ihr==0 && j<ihs)
     {
      ++y;
      ++j;
     }
    }
    for(int x=0; x<160; ++x)
    {
     *(pBuf+m*320*2+x*4+0) = *(pSrc+y*320*2+x*4+0);
     *(pBuf+m*320*2+x*4+1) = *(pSrc+y*320*2+x*4+1);
     *(pBuf+m*320*2+x*4+2) = *(pSrc+y*320*2+x*4+2);
     *(pBuf+m*320*2+x*4+3) = *(pSrc+y*320*2+x*4+3);
    }
   }

   memset(pSrc,0,len);
   CopyMemory(pSrc,pBuf,240*320*2);
  }
  else if(iStepH==2)
  {
   if(ih>480)
   {
    int iStep480 = ih/(ih-480);
    for(int ySrc=0,yDst=0; ySrc<ih; ++ySrc,++yDst)
    {
     if(ySrc%iStep480==0)
      ++ySrc;
     for(int x=0; x<160; ++x)
     {
      *(pBuf+yDst*320*2+x*4+0) = *(pSrc+ySrc*320*2+x*4+0);
      *(pBuf+yDst*320*2+x*4+1) = *(pSrc+ySrc*320*2+x*4+1);
      *(pBuf+yDst*320*2+x*4+2) = *(pSrc+ySrc*320*2+x*4+2);
      *(pBuf+yDst*320*2+x*4+3) = *(pSrc+ySrc*320*2+x*4+3);
     }
    }
   }
   else
   {
    CopyMemory(pBuf,pSrc,480*320*2);
   }

   memset(pSrc,0,len);
   for(int y=0,m=0; y<480; y=y+2,++m)
   {
    for(int x=0; x<160; ++x)
    {
     *(pSrc+m*320*2+x*4+0) = *(pBuf+y*320*2+x*4+0);
     *(pSrc+m*320*2+x*4+1) = *(pBuf+y*320*2+x*4+1);
     *(pSrc+m*320*2+x*4+2) = *(pBuf+y*320*2+x*4+2);
     *(pSrc+m*320*2+x*4+3) = *(pBuf+y*320*2+x*4+3);
    }
   }
  }

  CopyMemory(m_pbDataSend,pSrc,320*240*2);
  delete [] pBuf;
  pBuf = NULL;
 }

 Sleep(1);
 return NOERROR;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值