Пример #1
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;
}
/*++
GetMediaType

Description:
    Method from CBasePin should be rewrote
    Enumerate supported input types
--*/
HRESULT CPlgPin::GetMediaType(
     OUT    CMediaType*             pmt
     )
{
    LOG((MSP_TRACE, "CPlgPin::GetMediaType - enter"));
    //
    // Validates parameters
    //

    if (!pmt)
    {
        LOG((MSP_ERROR, "CPlgPin::GetMediaType - "
            "invalid pointer, return E_POINTER"));
        return E_POINTER;
    }

    if(NULL == m_pFilter)
    {
        return E_UNEXPECTED;
    }

    CAutoLock lock((CPlgFilter*)m_pFilter);

    HRESULT hr = InitMediaType();
    if (FAILED (hr))
    {
        LOG((MSP_ERROR, "CPlgPin::GetMediaType - "
            "InitMediaType failed, return 0x%08x", hr));
        return hr;
    }

    CPlgFilter* pFilter = (CPlgFilter*)m_pFilter;

    //
    //create media type to return
    //
    hr = CreateAudioMediaType(pFilter->m_lpWaveFormatEx, pmt, TRUE);

    LOG((MSP_TRACE, "CPlgPin::GetMediaType - exit 0x%08x", hr));
    return hr;
}
Пример #3
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;
}
Пример #4
0
CMediaType::CMediaType(const GUID * type)
{
    InitMediaType();
    majortype = *type;
}
Пример #5
0
CMediaType::CMediaType()
{
    InitMediaType();
}
Пример #6
0
VideoCompressorResult VideoCompressor::OpenFile(const String &Filename, UINT Width, UINT Height, UINT BitRate, UINT FrameRate, UINT AudioDeviceIndex, Clock *Timer)
{
    VideoCompressorResult Result = VideoCompressorResultSuccess;
    _Width = Width;
    _Height = Height;
    _CapturingAudio = (AudioDeviceIndex != 0xFFFFFFFF);
    _Clock = Timer;
    HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
    //PersistentAssert(SUCCEEDED(hr), "CoInitializeEx failed");

    hr = MFStartup(MF_VERSION);
    PersistentAssert(SUCCEEDED(hr), "MFStartup failed");
    
    hr = MFCreateSinkWriterFromURL(
            UnicodeString(Filename).CString(),
            NULL,
            NULL,
            &_Writer
            );
    PersistentAssert(SUCCEEDED(hr), "MFCreateSinkWriterFromURL failed");

    const UINT RawBufferSize = Width * Height * 4;
    
    IMFMediaType *OutputMediaType;
    MFCreateMediaType(&OutputMediaType);
    InitMediaType(OutputMediaType, MFVideoFormat_H264, BitRate, Width, Height, FrameRate);

    IMFMediaType *InputMediaType;
    MFCreateMediaType(&InputMediaType);
    InitMediaType(InputMediaType, MFVideoFormat_RGB32, RawBufferSize, Width, Height, FrameRate);

    DWORD VideoStreamIndex;
    hr = _Writer->AddStream(OutputMediaType, &VideoStreamIndex);
    PersistentAssert(SUCCEEDED(hr), "AddStream failed");
    OutputMediaType->Release();
    
    /*hr = MFTRegisterLocalByCLSID(
            __uuidof(CColorConvertDMO),
            MFT_CATEGORY_VIDEO_PROCESSOR,
            L"",
            MFT_ENUM_FLAG_SYNCMFT,
            0,
            NULL,
            0,
            NULL
            );
    PersistentAssert(SUCCEEDED(hr), "MFTRegisterLocalByCLSID failed");*/

    hr = _Writer->SetInputMediaType(VideoStreamIndex, InputMediaType, NULL);
    InputMediaType->Release();
    if(FAILED(hr))
    {
        if(Width > 1920 || Height > 1080)
        {
            MessageBox(NULL, "The maximum resolution for H.264 video is 1920x1080.", "Invalid Window Dimensions", MB_OK | MB_ICONERROR);
        }
        else
        {
            MessageBox(NULL, "There was an error when attempting to initialize video capture.  The maximum resolution for H.264 video is 1920x1080.", "Invalid Window Dimensions", MB_OK | MB_ICONERROR);
        }
        _Writer->Release();
        _Writer = NULL;
        _Clock = NULL;
        return VideoCompressorResultFailure;
    }
    
    if(_CapturingAudio)
    {
        //
        // Setup the output media type
        //
        IMFMediaType *OutputAudioType;
        hr = MFCreateMediaType( &OutputAudioType );
        PersistentAssert(SUCCEEDED(hr), "MFCreateMediaType failed");

        const UINT SamplesPerSecond = 44100;
        const UINT AverageBytesPerSecond = 24000;
        const UINT ChannelCount = 2;
        const UINT BitsPerSample = 16;
        
        OutputAudioType->SetGUID( MF_MT_MAJOR_TYPE, MFMediaType_Audio ) ;  
        OutputAudioType->SetGUID( MF_MT_SUBTYPE, MFAudioFormat_AAC ) ;
        OutputAudioType->SetUINT32( MF_MT_AUDIO_SAMPLES_PER_SECOND, SamplesPerSecond ) ;
        OutputAudioType->SetUINT32( MF_MT_AUDIO_BITS_PER_SAMPLE, BitsPerSample ) ;
        OutputAudioType->SetUINT32( MF_MT_AUDIO_NUM_CHANNELS, ChannelCount ) ;
        OutputAudioType->SetUINT32( MF_MT_AUDIO_AVG_BYTES_PER_SECOND, AverageBytesPerSecond ) ;
        OutputAudioType->SetUINT32( MF_MT_AUDIO_BLOCK_ALIGNMENT, 1 ) ;
        //OutputAudioType->SetUINT32( MF_MT_AAC_AUDIO_PROFILE_LEVEL_INDICATION, 0x29 ) ;

        DWORD AudioStreamIndex;
        hr = _Writer->AddStream( OutputAudioType, &AudioStreamIndex );
        PersistentAssert(SUCCEEDED(hr), "AddStream failed");

        //
        // Setup the input media type
        //

        IMFMediaType *InputAudioType;
        MFCreateMediaType( &InputAudioType );
        InputAudioType->SetGUID( MF_MT_MAJOR_TYPE, MFMediaType_Audio );
        InputAudioType->SetGUID( MF_MT_SUBTYPE, MFAudioFormat_PCM );
        InputAudioType->SetUINT32( MF_MT_AUDIO_BITS_PER_SAMPLE, BitsPerSample );
        InputAudioType->SetUINT32( MF_MT_AUDIO_SAMPLES_PER_SECOND, SamplesPerSecond );
        InputAudioType->SetUINT32( MF_MT_AUDIO_NUM_CHANNELS, ChannelCount );

        hr = _Writer->SetInputMediaType( AudioStreamIndex, InputAudioType, NULL );
        PersistentAssert(SUCCEEDED(hr), "SetInputMediaType failed");

        _AudioCapture.StartCapture(this, AudioDeviceIndex);
    }

    hr = _Writer->BeginWriting();
    PersistentAssert(SUCCEEDED(hr), "BeginWriting failed");

    
    hr = MFCreateSample(&_Sample);
    PersistentAssert(SUCCEEDED(hr), "MFCreateSample failed");

    hr = MFCreateMemoryBuffer(RawBufferSize, &_Buffer);
    _Buffer->SetCurrentLength(RawBufferSize);
    _Sample->AddBuffer(_Buffer);

    return Result;
}