void CWinVideoGrabber::getAudioFormat(int *r_channels, int *r_bits_per_sample, int *r_sample_rate) { if (!inited) return; WAVEFORMATEX t_wave_format; capGetAudioFormat(videowindow, &t_wave_format, sizeof(WAVEFORMATEX)); *r_channels = t_wave_format . nChannels; *r_bits_per_sample = t_wave_format . wBitsPerSample; *r_sample_rate = t_wave_format . nSamplesPerSec; }
void CWinVideoGrabber::setAudioFormat(int p_channels, int p_bits_per_sample, int p_sample_rate) { if (!inited) return; WAVEFORMATEX t_wave_format; capGetAudioFormat(videowindow, &t_wave_format, sizeof(WAVEFORMATEX)); t_wave_format . nChannels = p_channels; t_wave_format . wBitsPerSample = p_bits_per_sample; t_wave_format . nSamplesPerSec = p_sample_rate; BOOL t_result; t_result = capSetAudioFormat(videowindow, &t_wave_format, sizeof(t_wave_format)); }
void MMCapture::captureInit(UINT framesPerSecond, UINT audioBufferSize) { DWORD style = WS_CHILD; m_captureWindow = capCreateCaptureWindow(_T("my capture window"), style,0,0,640,480,m_receiver.getWindow(),1); if(m_captureWindow == NULL) { throwException(_T("%s:Cannot create CaptureWindow:%s"),__TFUNCTION__,getLastErrorText().cstr()); } try { CHECKRESULT(capSetUserData( m_captureWindow, this)); if(captureVideo()) { CHECKRESULT(capDriverConnect(m_captureWindow, 0 )); m_webCamConnected = true; } CAPTUREPARMS param; CHECKRESULT(capCaptureGetSetup(m_captureWindow,¶m,sizeof(param))); param.dwRequestMicroSecPerFrame = 1000000 / framesPerSecond; param.fYield = TRUE; param.AVStreamMaster = AVSTREAMMASTER_AUDIO; // AVSTREAMMASTER_NONE; param.dwAudioBufferSize = audioBufferSize; CHECKRESULT(capCaptureSetSetup(m_captureWindow,¶m,sizeof(param))); if(captureAudio()) { int audioFormatSize = capGetAudioFormat(m_captureWindow,&m_audioFormat, sizeof(m_audioFormat)); CHECKRESULT(capSetCallbackOnWaveStream( m_captureWindow, captureWaveStreamCallback)); } if(captureVideo()) { int videoFormatSize = capGetVideoFormat(m_captureWindow,&m_videoFormat, sizeof(m_videoFormat)); CHECKRESULT(capSetCallbackOnVideoStream(m_captureWindow, captureVideoStreamCallback)); CHECKRESULT(capSetCallbackOnFrame( m_captureWindow, captureFrameCallback)); } CHECKRESULT(capSetCallbackOnStatus( m_captureWindow, captureStatusCallback)); CHECKRESULT(capSetCallbackOnCapControl( m_captureWindow, captureControlCallback)); CHECKRESULT(capSetCallbackOnError( m_captureWindow, captureErrorCallback)); if(captureAudio() && m_playAudio) { m_audioThread = new AudioPlayerThread(*this); TRACE_NEW(m_audioThread); m_audioThread->start(); } } catch(...) { captureCleanup(); throw; } }