@@ -125,6 +125,7 @@ bool CAgoraCaptureAduioDlg::InitAgora()
125125 context.eventHandler = &m_eventHandler;
126126 // initialize the Agora RTC engine context.
127127 int ret = m_rtcEngine->initialize (context);
128+ mediaEngine.queryInterface (m_rtcEngine, agora::AGORA_IID_MEDIA_ENGINE);
128129 if (ret != 0 ) {
129130 m_initialize = false ;
130131 CString strInfo;
@@ -166,6 +167,8 @@ void CAgoraCaptureAduioDlg::UnInitAgora()
166167 // disable video in the engine.
167168 m_rtcEngine->disableVideo ();
168169 m_lstInfo.InsertString (m_lstInfo.GetCount (), _T (" disableVideo" ));
170+ m_agAudioCaptureDevice.Stop ();
171+ mediaEngine->release ();
169172 // release engine.
170173 m_rtcEngine->release (true );
171174 m_lstInfo.InsertString (m_lstInfo.GetCount (), _T (" release rtc engine" ));
@@ -297,6 +300,15 @@ void CAgoraCaptureAduioDlg::EnableCaputre(BOOL bEnable) {
297300 m_extenalCaptureAudio = !m_extenalCaptureAudio;
298301}
299302
303+ void CAgoraCaptureAduioDlg::PushAudioFrame (uint8_t * data, int size, uint64_t ts)
304+ {
305+ if (m_extenalCaptureAudio && mediaEngine) {
306+ memcpy (m_audioFrame.buffer , data, size);
307+ m_audioFrame.renderTimeMs = ts;
308+ mediaEngine->pushAudioFrame (&m_audioFrame);
309+ }
310+ }
311+
300312void CAgoraCaptureAduioDlg::PushAudioFrameThread (CAgoraCaptureAduioDlg * self)
301313{
302314 agora::util::AutoPtr<agora::media::IMediaEngine> mediaEngine;
@@ -308,8 +320,7 @@ void CAgoraCaptureAduioDlg::PushAudioFrameThread(CAgoraCaptureAduioDlg * self)
308320 SIZE_T nSize = self->m_audioFrame .samples * self->m_audioFrame .channels * self->m_audioFrame .bytesPerSample ;
309321 unsigned int readByte = 0 ;
310322 int timestamp = 0 ;
311- if (!CircleBuffer::GetInstance ()->readBuffer (self->m_audioFrame .buffer , nSize, &readByte, timestamp))
312- {
323+ if (!CircleBuffer::GetInstance ()->readBuffer (self->m_audioFrame .buffer , nSize, &readByte, timestamp)){
313324 Sleep (1 );
314325 continue ;
315326 }
@@ -364,8 +375,9 @@ void CAgoraCaptureAduioDlg::OnBnClickedButtonStartCaputre()
364375 EnableExtendAudioCapture (TRUE );
365376 // start capture
366377 EnableCaputre (TRUE );
367- CreateThread (NULL , 0 , (LPTHREAD_START_ROUTINE)PushAudioFrameThread, this , 0 , NULL );
378+ // CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)PushAudioFrameThread, this, 0, NULL);
368379 m_lstInfo.InsertString (m_lstInfo.GetCount (), _T (" use external audio source" ));
380+ m_agAudioCaptureDevice.SetCaptureDlg (this );
369381 }
370382 else {
371383 m_btnSetAudioCtx.SetWindowText (customAudioCaptureCtrlSetExternlCapture);
@@ -374,6 +386,7 @@ void CAgoraCaptureAduioDlg::OnBnClickedButtonStartCaputre()
374386 // stop capture.
375387 EnableCaputre (FALSE );
376388 m_lstInfo.InsertString (m_lstInfo.GetCount (), _T (" use inner audio source" ));
389+ m_agAudioCaptureDevice.SetCaptureDlg (nullptr );
377390 }
378391
379392}
0 commit comments