音频枚举还是得用原生API,WIN下使用directshow
parent
2ac9112f1f
commit
9294890502
|
@ -18,10 +18,10 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||||
ui->comboBox->addItem(QString::fromWCharArray(x.c_str(),x.size()),
|
ui->comboBox->addItem(QString::fromWCharArray(x.c_str(),x.size()),
|
||||||
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();
|
mMic = mAudioCapture->EnumSpeakers();
|
||||||
qDebug()<<"capture "<<mMic.size()<<"mic";
|
qDebug()<<"capture "<<mMic.size()<<"mic";
|
||||||
for(vector<CaptureAudio::MICInfo>::iterator itr = mMic.begin();itr != mMic.end();itr++){
|
for(vector<CaptureAudioFfmpeg::MICInfo>::iterator itr = mMic.begin();itr != mMic.end();itr++){
|
||||||
ui->comboBox_2->addItem(QString::fromLocal8Bit(itr->name.c_str(),itr->name.size()),
|
ui->comboBox_2->addItem(QString::fromLocal8Bit(itr->name.c_str(),itr->name.size()),
|
||||||
QString::fromLocal8Bit(itr->name.c_str(),itr->name.size()));
|
QString::fromLocal8Bit(itr->name.c_str(),itr->name.size()));
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,8 +42,8 @@ private:
|
||||||
VideoCoder *mVideoCoder;
|
VideoCoder *mVideoCoder;
|
||||||
bool m_bRtmpPushing;
|
bool m_bRtmpPushing;
|
||||||
H264RtmpPuser *mPusher;
|
H264RtmpPuser *mPusher;
|
||||||
CaptureAudio *mAudioCapture;
|
CaptureAudioFfmpeg *mAudioCapture;
|
||||||
vector<CaptureAudio::MICInfo> mMic;
|
vector<CaptureAudioFfmpeg::MICInfo> mMic;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
|
|
@ -124,17 +124,85 @@ void CaptureAudio::StopCapture()
|
||||||
this->mStatus = STOP;
|
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::MICInfo> CaptureAudioFfmpeg::EnumSpeakers()
|
||||||
|
{
|
||||||
|
vector<CaptureAudioFfmpeg::MICInfo> ret;
|
||||||
|
std::vector<std::wstring> 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<CaptureAudio::MICInfo> 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);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,13 @@ extern "C"
|
||||||
#include "libavdevice/avdevice.h"
|
#include "libavdevice/avdevice.h"
|
||||||
|
|
||||||
};
|
};
|
||||||
|
#include <functional>
|
||||||
|
#include <dshow.h>
|
||||||
|
#include <windows.h>
|
||||||
|
#include "qedit.h"
|
||||||
|
#include <mutex>
|
||||||
|
#include <vector>
|
||||||
|
#include "guiddef.h"
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
typedef int (CbAudio)(const void* input, void* output, unsigned long frameCount,
|
typedef int (CbAudio)(const void* input, void* output, unsigned long frameCount,
|
||||||
|
@ -28,7 +34,7 @@ public:
|
||||||
public:
|
public:
|
||||||
virtual void OnAudioData(const void *frameaddress, uint32_t framelen) {};
|
virtual void OnAudioData(const void *frameaddress, uint32_t framelen) {};
|
||||||
};
|
};
|
||||||
typedef struct _T_MicInfo
|
typedef struct MICInfo
|
||||||
{
|
{
|
||||||
string name;
|
string name;
|
||||||
int index;
|
int index;
|
||||||
|
@ -78,9 +84,10 @@ public:
|
||||||
FAIL = 4,
|
FAIL = 4,
|
||||||
};
|
};
|
||||||
|
|
||||||
vector<CaptureAudio::MICInfo> EnumSpeakers();
|
vector<CaptureAudioFfmpeg::MICInfo> EnumSpeakers();
|
||||||
|
CaptureAudioFfmpeg(uint16_t rate, uint8_t channel);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
CaptureAudio(uint16_t rate, uint8_t channel);
|
|
||||||
~CaptureAudio();
|
~CaptureAudio();
|
||||||
int StartCapture();
|
int StartCapture();
|
||||||
int InitCapture(int index,uint16_t rate,uint8_t channel);
|
int InitCapture(int index,uint16_t rate,uint8_t channel);
|
||||||
|
|
Loading…
Reference in New Issue