由于portaudio 捕获识别不到麦克风,改用ffmpeg的device来捕获音频数据

master
DESKTOP-4RNDQIC\29019 2020-06-19 17:30:29 +08:00
parent f92ca985db
commit 2ac9112f1f
7 changed files with 124 additions and 5 deletions

5
.gitignore vendored
View File

@ -26,3 +26,8 @@ client/qt_gl_render/yuvgl/third/
client/qt_gl_/yuvgl/third/ client/qt_gl_/yuvgl/third/
client/qt_gl_/build-yuvgl-Desktop_Qt_5_14_0_MinGW_32_bit-Debug/ client/qt_gl_/build-yuvgl-Desktop_Qt_5_14_0_MinGW_32_bit-Debug/
client/qt_gl_/mingw32/ client/qt_gl_/mingw32/
client/qt_gl_/yuvgl/yuvgl.pro.user.22
client/qt_gl_/yuvgl/yuvgl.pro.user.3ffb486
client/qt_gl_/yuvgl/yuvgl.pro.user.4.10-pre1
client/qt_gl_/yuvgl/yuvgl.pro.user.bccf4b5
client/qt_gl_/yuvgl/yuvgl.pro.user.ed68183.4.8-pre1

View File

@ -9,7 +9,8 @@ MainWindow::MainWindow(QWidget *parent) :
m_bRtmpPushing(false), m_bRtmpPushing(false),
mPlayerWidget(nullptr), mPlayerWidget(nullptr),
mVideoCoder(nullptr), mVideoCoder(nullptr),
mPusher(nullptr) mPusher(nullptr),
mAudioCapture(nullptr)
{ {
ui->setupUi(this); ui->setupUi(this);
std::vector<std::wstring> cameras = Camera::EnumAllCamera(); std::vector<std::wstring> cameras = Camera::EnumAllCamera();
@ -17,6 +18,16 @@ 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);
mMic = mAudioCapture->EnumSpeakers();
qDebug()<<"capture "<<mMic.size()<<"mic";
for(vector<CaptureAudio::MICInfo>::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()));
}
//mAudioCapture->SetObserver(mAudioCoder);
//mAudioCapture->InitCapture(0, 44100, 2);
//mAudioCapture->StartCapture();
mPusher = new H264RtmpPuser(); mPusher = new H264RtmpPuser();
} }
@ -96,3 +107,8 @@ void MainWindow::on_pushButton_2_clicked()
} }
} }
void MainWindow::on_pushButton_3_clicked()
{
}

View File

@ -10,6 +10,9 @@
#include "utils.h" #include "utils.h"
#include "media/RtmpPusher.h" #include "media/RtmpPusher.h"
#include "Qss/Qss.h" #include "Qss/Qss.h"
#include "media/AudioCapture.h"
#include <vector>
using namespace std;
namespace Ui { namespace Ui {
class MainWindow; class MainWindow;
@ -28,6 +31,8 @@ private slots:
void on_pushButton_2_clicked(); void on_pushButton_2_clicked();
void on_pushButton_3_clicked();
private: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;
Camera *mCamera; Camera *mCamera;
@ -37,6 +42,8 @@ private:
VideoCoder *mVideoCoder; VideoCoder *mVideoCoder;
bool m_bRtmpPushing; bool m_bRtmpPushing;
H264RtmpPuser *mPusher; H264RtmpPuser *mPusher;
CaptureAudio *mAudioCapture;
vector<CaptureAudio::MICInfo> mMic;
}; };
#endif // MAINWINDOW_H #endif // MAINWINDOW_H

View File

@ -30,7 +30,7 @@
<item row="0" column="0"> <item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout" stretch="1,9"> <layout class="QVBoxLayout" name="verticalLayout" stretch="1,9">
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout" stretch="1,2,0,0,0,13"> <layout class="QHBoxLayout" name="horizontalLayout" stretch="1,2,0,0,0,0,0,13">
<property name="leftMargin"> <property name="leftMargin">
<number>2</number> <number>2</number>
</property> </property>
@ -72,7 +72,7 @@
<widget class="QComboBox" name="comboBox"> <widget class="QComboBox" name="comboBox">
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>300</width> <width>200</width>
<height>35</height> <height>35</height>
</size> </size>
</property> </property>
@ -84,6 +84,29 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QPushButton" name="pushButton_3">
<property name="minimumSize">
<size>
<width>100</width>
<height>50</height>
</size>
</property>
<property name="text">
<string>打开麦克风</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox_2">
<property name="minimumSize">
<size>
<width>200</width>
<height>35</height>
</size>
</property>
</widget>
</item>
<item> <item>
<widget class="QLabel" name="label"> <widget class="QLabel" name="label">
<property name="text"> <property name="text">

View File

@ -124,3 +124,17 @@ void CaptureAudio::StopCapture()
this->mStatus = STOP; this->mStatus = STOP;
} }
} }
vector<CaptureAudio::MICInfo> CaptureAudioFfmpeg::EnumSpeakers()
{
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);
}

View File

@ -4,6 +4,19 @@
#include "../third/portaudio/portaudio.h" #include "../third/portaudio/portaudio.h"
#include <vector> #include <vector>
#include <string> #include <string>
//Windows
extern "C"
{
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libavutil/avutil.h"
#include "libswscale/swscale.h"
#include "libavutil/opt.h"
#include "libavutil/imgutils.h"
#include "libavdevice/avdevice.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,
@ -46,4 +59,43 @@ private:
CaptureAudioObserver *observer; CaptureAudioObserver *observer;
}; };
class CaptureAudioFfmpeg {
public:
class CaptureAudioObserver {
public:
virtual void OnAudioData(const void *frameaddress, uint32_t framelen) {};
};
typedef struct _T_MicInfo
{
string name;
int index;
}MICInfo;
enum CAP_STATUS {
RUNNING = 1,
STOP = 2,
PAUSE = 3,
FAIL = 4,
};
vector<CaptureAudio::MICInfo> EnumSpeakers();
/*
CaptureAudio(uint16_t rate, uint8_t channel);
~CaptureAudio();
int StartCapture();
int InitCapture(int index,uint16_t rate,uint8_t channel);
void StopCapture();
int SetObserver(CaptureAudioObserver*);
int OnCallBack(const void* input, void* output, unsigned long frameCount);
void AddCnt(unsigned int x) {this->mSize += x;};
*/
private:
uint16_t mSampleRate; //²ÉÑùÂÊ
uint16_t mChanel; //ͨµÀºÅ
unsigned long mSize;
CAP_STATUS mStatus;
CaptureAudioObserver *observer;
};
#endif //__CAPTUREAUDIO_H__ #endif //__CAPTUREAUDIO_H__

View File

@ -18,6 +18,8 @@ DEFINES += QT_DEPRECATED_WARNINGS
# In order to do so, uncomment the following line. # In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt. # You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
QMAKE_CXXFLAGS += -std=c++11
CONFIG += c++11 CONFIG += c++11
SOURCES += \ SOURCES += \
@ -52,8 +54,8 @@ FORMS += \
INCLUDEPATH += media/ third/ffmpeg/include/ inc/ third/ INCLUDEPATH += media/ third/ffmpeg/include/ inc/ third/
LIBS += -L$$PWD/third/libs/ LIBS += -L$$PWD/third/libs/
LIBS += -lm -lavformat -lavdevice -lavcodec -lavutil -lswresample -lswscale -lpthread -lm -lfdk-aac -lx264 -liconv -lucrtbase -lstrmiids LIBS += -lm -lavformat -lavdevice -lavfilter -lavcodec -lavutil -lswresample -lswscale -lpthread -lm -lfdk-aac -lx264 -liconv -lucrtbase -lstrmiids
LIBS += -lole32 -loleAut32 -lquartz -ldxguid -ldxapi -lwinmm -lbcrypt -lssl -lcrypto -lGdi32 -lws2_32 -lbz2 -lz -lportaudio LIBS += -lole32 -loleAut32 -lquartz -ldxguid -ldxapi -lwinmm -lbcrypt -lssl -lcrypto -lGdi32 -lws2_32 -lbz2 -lz -lportaudio -lshlwapi -lvfw32 -lpostproc -luuid
# Default rules for deployment. # Default rules for deployment.
QMAKE_CXXFLAGS_RELEASE += -Zi QMAKE_CXXFLAGS_RELEASE += -Zi
QMAKE_LFLAGS_RELEASE += /DEBUG /OPT:REF QMAKE_LFLAGS_RELEASE += /DEBUG /OPT:REF