Exemplo n.º 1
0
static HRESULT WINAPI IEnumMediaTypesImpl_Reset(IEnumMediaTypes * iface)
{
    ULONG i;
    AM_MEDIA_TYPE amt;
    IEnumMediaTypesImpl *This = impl_from_IEnumMediaTypes(iface);

    TRACE("(%p)->()\n", iface);

    for (i = 0; i < This->enumMediaDetails.cMediaTypes; i++)
        FreeMediaType(&This->enumMediaDetails.pMediaTypes[i]);
    CoTaskMemFree(This->enumMediaDetails.pMediaTypes);

    i = 0;
    while (This->enumMediaFunction(This->basePin, i, &amt) == S_OK) i++;

    This->enumMediaDetails.cMediaTypes = i;
    This->enumMediaDetails.pMediaTypes = CoTaskMemAlloc(sizeof(AM_MEDIA_TYPE) * i);
    for (i = 0; i < This->enumMediaDetails.cMediaTypes; i++)
    {
        This->enumMediaFunction(This->basePin, i,&amt);
        if (FAILED(CopyMediaType(&This->enumMediaDetails.pMediaTypes[i], &amt)))
        {
            while (i--)
                FreeMediaType(&This->enumMediaDetails.pMediaTypes[i]);
            CoTaskMemFree(This->enumMediaDetails.pMediaTypes);
            return E_OUTOFMEMORY;
        }
    }

    This->currentVersion = This->mediaVersionFunction(This->basePin);
    This->uIndex = 0;

    return S_OK;
}
Exemplo n.º 2
0
static HRESULT WINAPI ACMWrapper_SetMediaType(TransformFilter *tf, PIN_DIRECTION dir, const AM_MEDIA_TYPE * pmt)
{
    ACMWrapperImpl* This = impl_from_TransformFilter(tf);
    MMRESULT res;

    TRACE("(%p)->(%i %p)\n", This, dir, pmt);

    if (dir != PINDIR_INPUT)
        return S_OK;

    /* Check root (GUID w/o FOURCC) */
    if ((IsEqualIID(&pmt->majortype, &MEDIATYPE_Audio)) &&
        (!memcmp(((const char *)&pmt->subtype)+4, ((const char *)&MEDIATYPE_Audio)+4, sizeof(GUID)-4)) &&
        (IsEqualIID(&pmt->formattype, &FORMAT_WaveFormatEx)))
    {
        HACMSTREAM drv;
        WAVEFORMATEX *wfx = (WAVEFORMATEX*)pmt->pbFormat;
        AM_MEDIA_TYPE* outpmt = &This->tf.pmt;

        if (!wfx || wfx->wFormatTag == WAVE_FORMAT_PCM || wfx->wFormatTag == WAVE_FORMAT_EXTENSIBLE)
            return VFW_E_TYPE_NOT_ACCEPTED;
        FreeMediaType(outpmt);

        This->pWfIn = (LPWAVEFORMATEX)pmt->pbFormat;

	/* HACK */
	/* TRACE("ALIGN = %d\n", pACMWrapper->pWfIn->nBlockAlign); */
	/* pACMWrapper->pWfIn->nBlockAlign = 1; */

	/* Set output audio data to PCM */
        CopyMediaType(outpmt, pmt);
        outpmt->subtype.Data1 = WAVE_FORMAT_PCM;
	This->pWfOut = (WAVEFORMATEX*)outpmt->pbFormat;
	This->pWfOut->wFormatTag = WAVE_FORMAT_PCM;
	This->pWfOut->wBitsPerSample = 16;
	This->pWfOut->nBlockAlign = This->pWfOut->wBitsPerSample * This->pWfOut->nChannels / 8;
	This->pWfOut->cbSize = 0;
	This->pWfOut->nAvgBytesPerSec = This->pWfOut->nChannels * This->pWfOut->nSamplesPerSec
						* (This->pWfOut->wBitsPerSample/8);

        if (!(res = acmStreamOpen(&drv, NULL, This->pWfIn, This->pWfOut, NULL, 0, 0, 0)))
        {
            This->has = drv;

            TRACE("Connection accepted\n");
            return S_OK;
        }
	else
	    FIXME("acmStreamOpen returned %d\n", res);
        FreeMediaType(outpmt);
        TRACE("Unable to find a suitable ACM decompressor\n");
    }

    TRACE("Connection refused\n");
    return VFW_E_TYPE_NOT_ACCEPTED;
}
Exemplo n.º 3
0
CapturePin::~CapturePin()
{
#ifdef DEBUG_DSHOW
    msg_Dbg( p_input, "CapturePin::~CapturePin" );
#endif
    for( size_t c=0; c<media_type_count; c++ )
    {
        FreeMediaType(media_types[c]);
    }
    FreeMediaType(cx_media_type);
}
Exemplo n.º 4
0
static HRESULT ACMWrapper_ConnectInput(InputPin *pin, const AM_MEDIA_TYPE * pmt)
{
    ACMWrapperImpl* This = (ACMWrapperImpl *)pin->pin.pinInfo.pFilter;
    MMRESULT res;

    TRACE("(%p)->(%p)\n", This, pmt);

    /* Check root (GUID w/o FOURCC) */
    if ((IsEqualIID(&pmt->majortype, &MEDIATYPE_Audio)) &&
        (!memcmp(((const char *)&pmt->subtype)+4, ((const char *)&MEDIATYPE_Audio)+4, sizeof(GUID)-4)) &&
        (IsEqualIID(&pmt->formattype, &FORMAT_WaveFormatEx)))
    {
        HACMSTREAM drv;
        AM_MEDIA_TYPE* outpmt = &This->tf.pmt;
        FreeMediaType(outpmt);

        This->pWfIn = (LPWAVEFORMATEX)pmt->pbFormat;

	/* HACK */
	/* TRACE("ALIGN = %d\n", pACMWrapper->pWfIn->nBlockAlign); */
	/* pACMWrapper->pWfIn->nBlockAlign = 1; */

	/* Set output audio data to PCM */
        CopyMediaType(outpmt, pmt);
        outpmt->subtype.Data1 = WAVE_FORMAT_PCM;
	This->pWfOut = (WAVEFORMATEX*)outpmt->pbFormat;
	This->pWfOut->wFormatTag = WAVE_FORMAT_PCM;
	This->pWfOut->wBitsPerSample = 16;
	This->pWfOut->nBlockAlign = This->pWfOut->wBitsPerSample * This->pWfOut->nChannels / 8;
	This->pWfOut->cbSize = 0;
	This->pWfOut->nAvgBytesPerSec = This->pWfOut->nChannels * This->pWfOut->nSamplesPerSec
						* (This->pWfOut->wBitsPerSample/8);

        if (!(res = acmStreamOpen(&drv, NULL, This->pWfIn, This->pWfOut, NULL, 0, 0, 0)))
        {
            This->has = drv;

            /* Update buffer size of media samples in output */
            ((OutputPin*)This->tf.ppPins[1])->allocProps.cbBuffer = This->pWfOut->nAvgBytesPerSec / 2;
            TRACE("Connection accepted\n");
            return S_OK;
        }
	else
	    FIXME("acmStreamOpen returned %d\n", res);
        FreeMediaType(outpmt);
        TRACE("Unable to find a suitable ACM decompressor\n");
    }

    TRACE("Connection refused\n");
    return VFW_E_TYPE_NOT_ACCEPTED;
}
Exemplo n.º 5
0
SampleCapturePin::~SampleCapturePin()
{
#ifdef DEBUG_DSHOW
    ATLTRACE(  "SampleCapturePin::~SampleCapturePin" );
#endif
    for( size_t c=0; c<media_type_count; c++ )
    {
        FreeMediaType(media_types[c]);
    }
	free(media_types);
	media_types = NULL;
    FreeMediaType(cx_media_type);
	DeleteCriticalSection(&m_mylock);
}
Exemplo n.º 6
0
HRESULT __fastcall GetFrameSize(IPin* pPin, LONG* plWidth, LONG* plHeight)
{
HRESULT hr;
	if(!pPin || !plWidth || !plHeight)
		return E_POINTER;
	*plWidth = *plHeight = 0;
	AM_MEDIA_TYPE mt;
	hr = pPin->ConnectionMediaType(&mt);
	if(SUCCEEDED(hr))
	{
		if(FORMAT_VideoInfo==mt.formattype)
        {
			VIDEOINFOHEADER *pVih = reinterpret_cast<VIDEOINFOHEADER*>(mt.pbFormat);
			if(pVih)
			{
				*plWidth  = pVih->bmiHeader.biWidth;
				*plHeight = pVih->bmiHeader.biHeight;
			}
		}
		else
		{
			hr = VFW_E_UNSUPPORTED_STREAM;
		}
		FreeMediaType(mt);
	}

	return hr;
}
Exemplo n.º 7
0
void CTextInfoForm::DoPinDetails(GraphStudio::Pin *pin, int level, int offset)
{
	CString		ofs, t, f;
	for (int i=0; i<offset; i++) ofs += _T(" ");

	AM_MEDIA_TYPE	mt;
	HRESULT hr = pin->pin->ConnectionMediaType(&mt);
	if (SUCCEEDED(hr)) {
		GraphStudio::NameGuid(mt.majortype,  f);	
		t = _T("Major:   ") + f;		Echo(ofs+t);

		GraphStudio::NameGuid(mt.subtype,    f);	
		t = _T("Subtype: ") + f;		Echo(ofs+t);

		// parse one level deeper
		if (level > 1) {
			DoMediaTypeDetails(&mt, level, offset+4);
		}

		GraphStudio::NameGuid(mt.formattype, f);	
		t = _T("Format:  ") + f;		Echo(ofs+t);
		if (level > 2) {
			// parse format
			if (mt.formattype == FORMAT_WaveFormatEx) DoWaveFormatEx(&mt, level, offset); else
			if (mt.formattype == FORMAT_VideoInfo2) DoVideoInfo2(&mt, level, offset); else
			if (mt.formattype == FORMAT_VideoInfo) DoVideoInfo(&mt, level, offset); else
			if (mt.formattype == FORMAT_MPEG2_VIDEO) DoMPEG2VideoInfo(&mt, level, offset);
		}

		Echo(_T(""));
		FreeMediaType(mt);
	}
}
Exemplo n.º 8
0
HRESULT CCaptureVideo::Open(int iDeviceID,int iPress)
{
	HRESULT hr;
	hr = InitCaptureGraphBuilder();
	if (FAILED(hr)){
		return hr;
	}
	// Bind Device Filter. We know the device because the id was passed in
	if(!BindVideoFilter(iDeviceID, &m_pBF))
		return S_FALSE;
	
	hr = m_pGB->AddFilter(m_pBF, L"Capture Filter");
	
	// create a sample grabber
	hr = CoCreateInstance( CLSID_SampleGrabber, NULL, CLSCTX_INPROC_SERVER, IID_ISampleGrabber, (void**)&m_pGrabber );
	if(FAILED(hr)){
		return hr;
	   }
	CComQIPtr< IBaseFilter, &IID_IBaseFilter > pGrabBase( m_pGrabber );//设置视频格式
	AM_MEDIA_TYPE mt; 
	ZeroMemory(&mt, sizeof(AM_MEDIA_TYPE));
	mt.majortype = MEDIATYPE_Video;
	mt.subtype = MEDIASUBTYPE_RGB24; // MEDIASUBTYPE_RGB24 ; 
	hr = m_pGrabber->SetMediaType(&mt);
			 if( FAILED( hr ) ){
				 return hr;
			 }
			 hr = m_pGB->AddFilter( pGrabBase, L"Grabber" );
             if( FAILED( hr ) ){
				 return hr;
			 }// try to render preview/capture pin
			 hr = m_pCapture->RenderStream(&PIN_CATEGORY_PREVIEW, &MEDIATYPE_Video,m_pBF,pGrabBase,NULL);
			 if( FAILED( hr ) )
				 hr = m_pCapture->RenderStream(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video,m_pBF,pGrabBase,NULL);    
			 if( FAILED( hr ) ){
				 return hr;
			 }
			 hr = m_pGrabber->GetConnectedMediaType( &mt );
			 if ( FAILED( hr) ){
				 return hr;
			 }VIDEOINFOHEADER * vih = (VIDEOINFOHEADER*) mt.pbFormat;
			 mCB.lWidth = vih->bmiHeader.biWidth;
			 mCB.lHeight = vih->bmiHeader.biHeight;
			 mCB.bGrabVideo = FALSE ; 
			 //mCB.frame_handler = NULL ; 
			 FreeMediaType(mt);
			 hr = m_pGrabber->SetBufferSamples( FALSE );
			 hr = m_pGrabber->SetOneShot( FALSE );
			 //设置视频捕获回调函数 也就是如果有视频数据时就会调用这个类的BufferCB函数
			 //返回OnTimer
			 hr = m_pGrabber->SetCallback( &mCB, 1 ); 
			 //设置视频捕捉窗口
			 m_hWnd = CreateWindow("#32770", /* Dialog */ "", WS_POPUP, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
			 SetupVideoWindow();
			 hr = m_pMC->Run();//开始视频捕捉
			 if(FAILED(hr)){
				 //AfxMessageBox("Couldn’t run the graph!");return hr;
			 }
			 return S_OK;
}
Exemplo n.º 9
0
HRESULT VideoCapture::GetMediaType()
{
        AM_MEDIA_TYPE mt;
        HRESULT hr = m_pGrabber->GetConnectedMediaType(&mt);
        if (FAILED(hr)) {
                FreeMediaType(mt);
                return hr;
        }
        
        memcpy(&m_BmiHeader, &((VIDEOINFOHEADER *)mt.pbFormat)->bmiHeader, sizeof(BITMAPINFOHEADER));
        if (m_pFrameData != 0) delete[] m_pFrameData;
        m_pFrameData = new BYTE[m_BmiHeader.biSizeImage];

        FreeMediaType(mt);
        return hr;
}
Exemplo n.º 10
0
static HRESULT WINAPI DSoundRender_PrepareReceive(BaseRenderer *iface, IMediaSample *pSample)
{
    DSoundRenderImpl *This = impl_from_BaseRenderer(iface);
    HRESULT hr;
    AM_MEDIA_TYPE *amt;

    if (IMediaSample_GetMediaType(pSample, &amt) == S_OK)
    {
        AM_MEDIA_TYPE *orig = &This->renderer.pInputPin->pin.mtCurrent;
        WAVEFORMATEX *origfmt = (WAVEFORMATEX *)orig->pbFormat;
        WAVEFORMATEX *newfmt = (WAVEFORMATEX *)amt->pbFormat;

        if (origfmt->wFormatTag == newfmt->wFormatTag &&
            origfmt->nChannels == newfmt->nChannels &&
            origfmt->nBlockAlign == newfmt->nBlockAlign &&
            origfmt->wBitsPerSample == newfmt->wBitsPerSample &&
            origfmt->cbSize ==  newfmt->cbSize)
        {
            if (origfmt->nSamplesPerSec != newfmt->nSamplesPerSec)
            {
                hr = IDirectSoundBuffer_SetFrequency(This->dsbuffer,
                                                     newfmt->nSamplesPerSec);
                if (FAILED(hr))
                    return VFW_E_TYPE_NOT_ACCEPTED;
                FreeMediaType(orig);
                CopyMediaType(orig, amt);
                IMediaSample_SetMediaType(pSample, NULL);
            }
        }
        else
            return VFW_E_TYPE_NOT_ACCEPTED;
    }
    return S_OK;
}
Exemplo n.º 11
0
bool Misc::SetStreamConfigData(AM_MEDIA_TYPE *pMT,
                               BYTE *pMediaHex, int inMediaSize,
                               BYTE *pVideoHeaderHex, int inVideoHeaderSize)
{
   int mediaSize = inMediaSize / 2;
   int videoHeaderSize = inVideoHeaderSize / 2;

   if (mediaSize != sizeof AM_MEDIA_TYPE)
      return false;

   LPVOID pNewVideoHeader = NULL;
   if (videoHeaderSize > 0)
   {
      pNewVideoHeader = CoTaskMemAlloc(videoHeaderSize);
      if (pNewVideoHeader)
      {
         Make8Bit((char *) pVideoHeaderHex, (char *) pNewVideoHeader, inVideoHeaderSize);
      }
      else
         return false;
   }
   // Release any previously allocated format tag
   FreeMediaType(*pMT);
   Make8Bit((char *) pMediaHex, (char *) pMT, inMediaSize);
   pMT->pbFormat = (BYTE *) pNewVideoHeader; // may be NULL under certain circumstances

   return true;
}
Exemplo n.º 12
0
static ULONG WINAPI Parser_OutputPin_Release(IPin * iface)
{
    Parser_OutputPin *This = (Parser_OutputPin *)iface;
    ULONG refCount = InterlockedDecrement(&This->pin.pin.refCount);
    
    TRACE("(%p)->() Release from %d\n", iface, refCount + 1);

    if (!refCount)
    {
        FreeMediaType(This->pmt);
        CoTaskMemFree(This->pmt);
        FreeMediaType(&This->pin.pin.mtCurrent);
        CoTaskMemFree(This);
        return 0;
    }
    return refCount;
}
Exemplo n.º 13
0
CaptureEnumMediaTypes::~CaptureEnumMediaTypes()
{
#ifdef DEBUG_DSHOW_L1
    msg_Dbg( p_input, "CaptureEnumMediaTypes::~CaptureEnumMediaTypes" );
#endif
    FreeMediaType(cx_media_type);
    p_pin->Release();
}
Exemplo n.º 14
0
/**
 * \brief COutputPin destructor
 *
 * \param[in]  This pointer to COutputPin class
 *
 */
static void COutputPin_Destroy(COutputPin* This)
{
    free(This->mempin->vt);
    free(This->mempin);
    free(This->vt);
    FreeMediaType(&(This->type));
    free(This);
}
Exemplo n.º 15
0
SampleCaptureEnumMediaTypes::~SampleCaptureEnumMediaTypes()
{
#ifdef DEBUG_DSHOW_L1
    ATLTRACE(  "SampleCaptureEnumMediaTypes::~SampleCaptureEnumMediaTypes" );
#endif
    FreeMediaType(cx_media_type);
    p_pin->Release();
}
Exemplo n.º 16
0
	inline void Clear()
	{
		if (ptr) {
			FreeMediaType(*ptr);
			CoTaskMemFree(ptr);
			ptr = nullptr;
		}
	}
Exemplo n.º 17
0
void DeleteMediaType(AM_MEDIA_TYPE *pmt)
{
	if (pmt)
	{
		FreeMediaType(*pmt);
		CoTaskMemFree(pmt);
	}
}
Exemplo n.º 18
0
HRESULT RtspSourcePin::GetMediaType(CMediaType* pMediaType)
{
    // We only support one MediaType - the one that is streamed
    CheckPointer(pMediaType, E_POINTER);
    CAutoLock cAutoLock(m_pFilter->pStateLock());
    FreeMediaType(*pMediaType);
    return CopyMediaType(pMediaType, &_mediaType);
}
Exemplo n.º 19
0
CMediaType&
CMediaType::operator=(const AM_MEDIA_TYPE& rt)
{
    if (&rt != this) {
        FreeMediaType(*this);
        CopyMediaType(this, &rt);
    }
    return *this;
}
Exemplo n.º 20
0
static HRESULT ACMWrapper_ConnectInput(TransformFilterImpl* pTransformFilter, const AM_MEDIA_TYPE * pmt)
{
    ACMWrapperImpl* This = (ACMWrapperImpl*)pTransformFilter;
    MMRESULT res;

    TRACE("(%p)->(%p)\n", This, pmt);

    if ((IsEqualIID(&pmt->majortype, &MEDIATYPE_Audio)) &&
        (!memcmp(((char*)&pmt->subtype)+4, ((char*)&MEDIATYPE_Audio)+4, sizeof(GUID)-4)) && /* Check root (GUID w/o FOURCC) */
        (IsEqualIID(&pmt->formattype, &FORMAT_WaveFormatEx)))
    {
        HACMSTREAM drv;
        AM_MEDIA_TYPE* outpmt = &((OutputPin*)This->tf.ppPins[1])->pin.mtCurrent;
        This->pWfIn = (LPWAVEFORMATEX)pmt->pbFormat;

	/* HACK */
	/* TRACE("ALIGN = %d\n", pACMWrapper->pWfIn->nBlockAlign); */
	/* pACMWrapper->pWfIn->nBlockAlign = 1; */

	/* Set output audio data to PCM */
        CopyMediaType(outpmt, pmt);
        outpmt->subtype.Data1 = WAVE_FORMAT_PCM;
	This->pWfOut = (WAVEFORMATEX*)outpmt->pbFormat;
	This->pWfOut->wFormatTag = WAVE_FORMAT_PCM;
	This->pWfOut->wBitsPerSample = 16;
	This->pWfOut->nBlockAlign = 4;
	This->pWfOut->cbSize = 0;
	This->pWfOut->nAvgBytesPerSec = This->pWfOut->nChannels * This->pWfOut->nSamplesPerSec
						* (This->pWfOut->wBitsPerSample/8);

        if (!(res = acmStreamOpen(&drv, NULL, This->pWfIn, This->pWfOut, NULL, 0, 0, 0)))
        {
            This->has = drv;

	    if ((res = acmStreamSize(drv, OUTPUT_BUFFER_SIZE, &This->max_size, ACM_STREAMSIZEF_DESTINATION))) {
		ERR("Cannot retrieve input buffer size error %d!\n", res);
		This->max_size = INPUT_BUFFER_SIZE;
	    }

	    TRACE("input buffer size %ld\n", This->max_size);

            /* Update buffer size of media samples in output */
            ((OutputPin*)This->tf.ppPins[1])->allocProps.cbBuffer = OUTPUT_BUFFER_SIZE;
	    
            TRACE("Connection accepted\n");
            return S_OK;
        }
	else
	    FIXME("acmStreamOpen returned %d\n", res);
        FreeMediaType(outpmt);
        TRACE("Unable to find a suitable ACM decompressor\n");
    }

    TRACE("Connection refused\n");
    return S_FALSE;
}
Exemplo n.º 21
0
/**
 * \brief CMediaSample destructor
 *
 * \param[in] This pointer to CMediaSample object
 *
 */
void CMediaSample_Destroy(CMediaSample* This)
{

    Debug printf("CMediaSample_Destroy(%p) called (ref:%d)\n", This, This->refcount);
    free(This->vt);
    free(This->own_block);
    if(((CMediaSample*)This)->type_valid)
	FreeMediaType(&(This->media_type));
    free(This);
}
Exemplo n.º 22
0
BOOL SetInputMediaType(ASF_FILE_INFO* pInfo)
{
	WAVEFORMATEX* pwf;
	DMO_MEDIA_TYPE mt ={0};
	if (InitMediaType(&mt, pInfo->dwFormat) != S_OK)
		return FALSE;

	pwf = (WAVEFORMATEX*)pInfo->pbFormat;
	memcpy(mt.pbFormat, pInfo->pbFormat, pInfo->dwFormat);
	mt.majortype = MEDIATYPE_Audio;
	mt.subtype = MEDIASUBTYPE_AudioBase;
	mt.subtype.Data1 = pwf->wFormatTag;
	mt.formattype = FORMAT_WaveFormatEx;
	mt.bTemporalCompression = 0;
	mt.bFixedSizeSamples = 1;
	mt.lSampleSize = 0;

	if (pInfo->pMediaObject->SetInputType(0, &mt, 0) != S_OK) {
#ifdef _WIN32_WCE
		// from TCPMP
		if (pwf->wFormatTag == WAVE_FORMAT_WMA8 && pwf->cbSize == 10) {
			LPBYTE pb = mt.pbFormat + sizeof(WAVEFORMATEX);
			memset(pb, 0, pwf->cbSize);
			memcpy(pb + 2, pwf + 1, 6);
			if (pInfo->pMediaObject->SetInputType(0, &mt, 0) != S_OK) {
				FreeMediaType(&mt);
				return FALSE;
			}
		}
		else {
			FreeMediaType(&mt);
			return FALSE;
		}
#else
		FreeMediaType(&mt);
		return FALSE;
#endif
	}

	FreeMediaType(&mt);
	return TRUE;
}
Exemplo n.º 23
0
STDMETHODIMP CaptureEnumMediaTypes::Reset()
{
#ifdef DEBUG_DSHOW_L1
    msg_Dbg( p_input, "CaptureEnumMediaTypes::Reset" );
#endif

    FreeMediaType(cx_media_type);
    CopyMediaType(&cx_media_type, &p_pin->cx_media_type);
    i_position = 0;
    return S_OK;
};
Exemplo n.º 24
0
void WINAPI DeleteMediaType(AM_MEDIA_TYPE *pmt)
{
    // allow NULL pointers for coding simplicity

    if (pmt == NULL) {
        return;
    }

    FreeMediaType(*pmt);
    CoTaskMemFree((PVOID)pmt);
}
Exemplo n.º 25
0
STDMETHODIMP SampleCaptureEnumMediaTypes::Reset()
{
#ifdef DEBUG_DSHOW_L1
    ATLTRACE(  "SampleCaptureEnumMediaTypes::Reset" );
#endif

    FreeMediaType(cx_media_type);
    CopyMediaType(&cx_media_type, &p_pin->cx_media_type); 
    i_position = 0;
    return S_OK;
};
Exemplo n.º 26
0
BOOL SetOutputMediaType(ASF_FILE_INFO* pInfo)
{
	WAVEFORMATEX* pwfIn;
	WAVEFORMATEX* pwfOut;
	DMO_MEDIA_TYPE mt;
	if (InitMediaType(&mt, sizeof(WAVEFORMATEX)) != S_OK)
		return FALSE;

	pwfIn = (WAVEFORMATEX*)pInfo->pbFormat;
	pwfOut = (WAVEFORMATEX*)mt.pbFormat;
	pwfOut->wFormatTag = WAVE_FORMAT_PCM;
	pwfOut->nChannels = pwfIn->nChannels;
	pwfOut->nSamplesPerSec = pwfIn->nSamplesPerSec;
	pwfOut->wBitsPerSample = pwfIn->wBitsPerSample;
	pwfOut->nAvgBytesPerSec = pwfOut->wBitsPerSample * pwfOut->nSamplesPerSec * pwfOut->nChannels / 8;
	pwfOut->nBlockAlign = pwfOut->wBitsPerSample * pwfOut->nChannels / 8;
	pwfOut->cbSize = 0;

	mt.majortype = MEDIATYPE_Audio;
	mt.subtype = MEDIASUBTYPE_PCM;
	mt.formattype = FORMAT_WaveFormatEx;
	mt.bTemporalCompression = 0;
	mt.bFixedSizeSamples = 1;
	mt.lSampleSize = 0;

	if (pInfo->pMediaObject->SetOutputType(0, &mt, 0) != S_OK) {
		FreeMediaType(&mt);
		return FALSE;
	}

	pInfo->pmbOut = new CMediaBuffer(pwfOut->nAvgBytesPerSec * 2);
	if (!pInfo->pmbOut) {
		FreeMediaType(&mt);
		return FALSE;
	}
	
	FreeMediaType(&mt);

	return TRUE;
}
Exemplo n.º 27
0
HRESULT
CMediaType::Set(const AM_MEDIA_TYPE& rt)
{
    if (&rt != this) {
        FreeMediaType(*this);
        HRESULT hr = CopyMediaType(this, &rt);
        if (FAILED(hr)) {
            return E_OUTOFMEMORY;
        }
    }

    return S_OK;    
}
Exemplo n.º 28
0
static HRESULT WINAPI StdMediaSample2_SetMediaType(IMediaSample2 * iface, AM_MEDIA_TYPE * pMediaType)
{
    StdMediaSample2 *This = (StdMediaSample2 *)iface;

    TRACE("(%p)\n", pMediaType);

    if (This->props.pMediaType)
        FreeMediaType(This->props.pMediaType);
    else if (!(This->props.pMediaType = CoTaskMemAlloc(sizeof(AM_MEDIA_TYPE))))
        return E_OUTOFMEMORY;

    return CopyMediaType(This->props.pMediaType, pMediaType);
}
Exemplo n.º 29
0
/**
 * \brief IMediaType::SetMediaType (specifies media type for sample)
 *
 * \param[in] This pointer to CMediaSample object
 * \param[in] pMediaType pointer to AM_MEDIA_TYPE specifies new media type
 *
 * \return S_OK success
 * \return E_OUTOFMEMORY insufficient memory
 *
 */
static HRESULT STDCALL CMediaSample_SetMediaType(IMediaSample * This,
						 AM_MEDIA_TYPE *pMediaType)
{
    AM_MEDIA_TYPE* t;
    Debug printf("CMediaSample_SetMediaType(%p) called\n", This);
    if (!pMediaType)
	return E_INVALIDARG;
    t = &((CMediaSample*)This)->media_type;
    if(((CMediaSample*)This)->type_valid)
	FreeMediaType(t);
    CopyMediaType(t,pMediaType);
    ((CMediaSample*) This)->type_valid=1;

    return 0;
}
STDMETHODIMP CapturePin::QueryAccept(const AM_MEDIA_TYPE *pmt)
{
    if(pmt->majortype != expectedMajorType)
        return S_FALSE;
    if(!IsValidMediaType(pmt))
        return S_FALSE;

    if(connectedPin)
    {
        FreeMediaType(connectedMediaType);
        CopyMediaType(&connectedMediaType, pmt);
    }

    return S_OK;
}