diff --git a/client/qt_gl_/yuvgl/mainwindow.cpp b/client/qt_gl_/yuvgl/mainwindow.cpp index b58db34..87210dd 100644 --- a/client/qt_gl_/yuvgl/mainwindow.cpp +++ b/client/qt_gl_/yuvgl/mainwindow.cpp @@ -18,10 +18,10 @@ MainWindow::MainWindow(QWidget *parent) : ui->comboBox->addItem(QString::fromWCharArray(x.c_str(),x.size()), QString::fromWCharArray(x.c_str(),x.size())); } - mAudioCapture = new CaptureAudio(44100, 2); + mAudioCapture = new CaptureAudioFfmpeg(44100, 2); mMic = mAudioCapture->EnumSpeakers(); qDebug()<<"capture "<::iterator itr = mMic.begin();itr != mMic.end();itr++){ + for(vector::iterator itr = mMic.begin();itr != mMic.end();itr++){ ui->comboBox_2->addItem(QString::fromLocal8Bit(itr->name.c_str(),itr->name.size()), QString::fromLocal8Bit(itr->name.c_str(),itr->name.size())); } diff --git a/client/qt_gl_/yuvgl/mainwindow.h b/client/qt_gl_/yuvgl/mainwindow.h index 7bb5602..170db42 100644 --- a/client/qt_gl_/yuvgl/mainwindow.h +++ b/client/qt_gl_/yuvgl/mainwindow.h @@ -42,8 +42,8 @@ private: VideoCoder *mVideoCoder; bool m_bRtmpPushing; H264RtmpPuser *mPusher; - CaptureAudio *mAudioCapture; - vector mMic; + CaptureAudioFfmpeg *mAudioCapture; + vector mMic; }; #endif // MAINWINDOW_H diff --git a/client/qt_gl_/yuvgl/media/AudioCapture.cpp b/client/qt_gl_/yuvgl/media/AudioCapture.cpp index de7b93b..86f7189 100644 --- a/client/qt_gl_/yuvgl/media/AudioCapture.cpp +++ b/client/qt_gl_/yuvgl/media/AudioCapture.cpp @@ -124,17 +124,85 @@ void CaptureAudio::StopCapture() this->mStatus = STOP; } } +std::string WString2String(const std::wstring& ws) +{ + std::string strLocale = setlocale(LC_ALL, ""); + const wchar_t* wchSrc = ws.c_str(); + size_t nDestSize = wcstombs(NULL, wchSrc, 0) + 1; + char *chDest = new char[nDestSize]; + memset(chDest, 0, nDestSize); + wcstombs(chDest, wchSrc, nDestSize); + std::string strResult = chDest; + delete[]chDest; + setlocale(LC_ALL, strLocale.c_str()); + return strResult; +} +vector CaptureAudioFfmpeg::EnumSpeakers() +{ + vector ret; + std::vector names; + IEnumMoniker *pEnum = nullptr; + // Create the System Device Enumerator. + ICreateDevEnum *pDevEnum; + HRESULT hr = CoCreateInstance(CLSID_SystemDeviceEnum, nullptr, + CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pDevEnum)); -vector CaptureAudioFfmpeg::EnumSpeakers() + if (SUCCEEDED(hr)) + { + // Create an enumerator for the category. + hr = pDevEnum->CreateClassEnumerator(CLSID_AudioInputDeviceCategory, &pEnum, 0); + if (hr == S_FALSE) + { + hr = VFW_E_NOT_FOUND; // The category is empty. Treat as an error. + } + pDevEnum->Release(); + } + + if (!SUCCEEDED(hr)) + return ret; + + IMoniker *pMoniker = nullptr; + while (pEnum->Next(1, &pMoniker, nullptr) == S_OK) + { + IPropertyBag *pPropBag; + IBindCtx* bindCtx = nullptr; + LPOLESTR str = nullptr; + VARIANT var; + VariantInit(&var); + + HRESULT hr = pMoniker->BindToStorage(0, 0, IID_PPV_ARGS(&pPropBag)); + if (FAILED(hr)) + { + pMoniker->Release(); + continue; + } + + // Get description or friendly name. + hr = pPropBag->Read(L"Description", &var, 0); + if (FAILED(hr)) + { + hr = pPropBag->Read(L"FriendlyName", &var, 0); + } + if (SUCCEEDED(hr)) + { + names.push_back(var.bstrVal); + std::string x = WString2String(var.bstrVal); + CaptureAudioFfmpeg::MICInfo ele; + ele.name = x; + ret.push_back(ele); + VariantClear(&var); + } + + pPropBag->Release(); + pMoniker->Release(); + } + + pEnum->Release(); + + return ret; +} + +CaptureAudioFfmpeg::CaptureAudioFfmpeg(uint16_t rate, uint8_t channel) { - av_register_all(); - avdevice_register_all(); - AVFormatContext *pFmtCtx = avformat_alloc_context(); - AVDictionary* options = NULL; - av_dict_set(&options, "list_devices", "true", 0); - AVInputFormat *iformat = av_find_input_format("dshow"); - //printf("Device Info=============\n"); - avformat_open_input(&pFmtCtx, "video=dummy", iformat, &options); - } diff --git a/client/qt_gl_/yuvgl/media/AudioCapture.h b/client/qt_gl_/yuvgl/media/AudioCapture.h index 8daa656..c025208 100644 --- a/client/qt_gl_/yuvgl/media/AudioCapture.h +++ b/client/qt_gl_/yuvgl/media/AudioCapture.h @@ -16,7 +16,13 @@ extern "C" #include "libavdevice/avdevice.h" }; - +#include +#include +#include +#include "qedit.h" +#include +#include +#include "guiddef.h" using namespace std; typedef int (CbAudio)(const void* input, void* output, unsigned long frameCount, @@ -28,7 +34,7 @@ public: public: virtual void OnAudioData(const void *frameaddress, uint32_t framelen) {}; }; - typedef struct _T_MicInfo + typedef struct MICInfo { string name; int index; @@ -78,9 +84,10 @@ public: FAIL = 4, }; - vector EnumSpeakers(); + vector EnumSpeakers(); + CaptureAudioFfmpeg(uint16_t rate, uint8_t channel); + /* - CaptureAudio(uint16_t rate, uint8_t channel); ~CaptureAudio(); int StartCapture(); int InitCapture(int index,uint16_t rate,uint8_t channel);