From 2ac9112f1f7f0683264b52e409a9c7170baca2ad Mon Sep 17 00:00:00 2001 From: "DESKTOP-4RNDQIC\\29019" <290198252@qq.com> Date: Fri, 19 Jun 2020 17:30:29 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=B1=E4=BA=8Eportaudio=20=E6=8D=95?= =?UTF-8?q?=E8=8E=B7=E8=AF=86=E5=88=AB=E4=B8=8D=E5=88=B0=E9=BA=A6=E5=85=8B?= =?UTF-8?q?=E9=A3=8E=EF=BC=8C=E6=94=B9=E7=94=A8ffmpeg=E7=9A=84device?= =?UTF-8?q?=E6=9D=A5=E6=8D=95=E8=8E=B7=E9=9F=B3=E9=A2=91=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 5 +++ client/qt_gl_/yuvgl/mainwindow.cpp | 18 +++++++- client/qt_gl_/yuvgl/mainwindow.h | 7 +++ client/qt_gl_/yuvgl/mainwindow.ui | 27 ++++++++++- client/qt_gl_/yuvgl/media/AudioCapture.cpp | 14 ++++++ client/qt_gl_/yuvgl/media/AudioCapture.h | 52 ++++++++++++++++++++++ client/qt_gl_/yuvgl/yuvgl.pro | 6 ++- 7 files changed, 124 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index baa2e35..59f4bba 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,8 @@ client/qt_gl_render/yuvgl/third/ client/qt_gl_/yuvgl/third/ client/qt_gl_/build-yuvgl-Desktop_Qt_5_14_0_MinGW_32_bit-Debug/ 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 diff --git a/client/qt_gl_/yuvgl/mainwindow.cpp b/client/qt_gl_/yuvgl/mainwindow.cpp index 17afe03..b58db34 100644 --- a/client/qt_gl_/yuvgl/mainwindow.cpp +++ b/client/qt_gl_/yuvgl/mainwindow.cpp @@ -9,7 +9,8 @@ MainWindow::MainWindow(QWidget *parent) : m_bRtmpPushing(false), mPlayerWidget(nullptr), mVideoCoder(nullptr), - mPusher(nullptr) + mPusher(nullptr), + mAudioCapture(nullptr) { ui->setupUi(this); std::vector cameras = Camera::EnumAllCamera(); @@ -17,6 +18,16 @@ 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); + mMic = mAudioCapture->EnumSpeakers(); + qDebug()<<"capture "<::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(); } @@ -96,3 +107,8 @@ void MainWindow::on_pushButton_2_clicked() } } + +void MainWindow::on_pushButton_3_clicked() +{ + +} diff --git a/client/qt_gl_/yuvgl/mainwindow.h b/client/qt_gl_/yuvgl/mainwindow.h index 6e5d355..7bb5602 100644 --- a/client/qt_gl_/yuvgl/mainwindow.h +++ b/client/qt_gl_/yuvgl/mainwindow.h @@ -10,6 +10,9 @@ #include "utils.h" #include "media/RtmpPusher.h" #include "Qss/Qss.h" +#include "media/AudioCapture.h" +#include +using namespace std; namespace Ui { class MainWindow; @@ -28,6 +31,8 @@ private slots: void on_pushButton_2_clicked(); + void on_pushButton_3_clicked(); + private: Ui::MainWindow *ui; Camera *mCamera; @@ -37,6 +42,8 @@ private: VideoCoder *mVideoCoder; bool m_bRtmpPushing; H264RtmpPuser *mPusher; + CaptureAudio *mAudioCapture; + vector mMic; }; #endif // MAINWINDOW_H diff --git a/client/qt_gl_/yuvgl/mainwindow.ui b/client/qt_gl_/yuvgl/mainwindow.ui index d9b5ad4..150ac3e 100644 --- a/client/qt_gl_/yuvgl/mainwindow.ui +++ b/client/qt_gl_/yuvgl/mainwindow.ui @@ -30,7 +30,7 @@ - + 2 @@ -72,7 +72,7 @@ - 300 + 200 35 @@ -84,6 +84,29 @@ + + + + + 100 + 50 + + + + 打开麦克风 + + + + + + + + 200 + 35 + + + + diff --git a/client/qt_gl_/yuvgl/media/AudioCapture.cpp b/client/qt_gl_/yuvgl/media/AudioCapture.cpp index 9d18d4a..de7b93b 100644 --- a/client/qt_gl_/yuvgl/media/AudioCapture.cpp +++ b/client/qt_gl_/yuvgl/media/AudioCapture.cpp @@ -124,3 +124,17 @@ void CaptureAudio::StopCapture() this->mStatus = STOP; } } + +vector 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); + +} diff --git a/client/qt_gl_/yuvgl/media/AudioCapture.h b/client/qt_gl_/yuvgl/media/AudioCapture.h index a8cac19..8daa656 100644 --- a/client/qt_gl_/yuvgl/media/AudioCapture.h +++ b/client/qt_gl_/yuvgl/media/AudioCapture.h @@ -4,6 +4,19 @@ #include "../third/portaudio/portaudio.h" #include #include +//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; typedef int (CbAudio)(const void* input, void* output, unsigned long frameCount, @@ -46,4 +59,43 @@ private: 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 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__ diff --git a/client/qt_gl_/yuvgl/yuvgl.pro b/client/qt_gl_/yuvgl/yuvgl.pro index 89deb2c..8604f34 100644 --- a/client/qt_gl_/yuvgl/yuvgl.pro +++ b/client/qt_gl_/yuvgl/yuvgl.pro @@ -18,6 +18,8 @@ DEFINES += QT_DEPRECATED_WARNINGS # 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. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 +QMAKE_CXXFLAGS += -std=c++11 + CONFIG += c++11 SOURCES += \ @@ -52,8 +54,8 @@ FORMS += \ INCLUDEPATH += media/ third/ffmpeg/include/ inc/ third/ LIBS += -L$$PWD/third/libs/ -LIBS += -lm -lavformat -lavdevice -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 += -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 -lshlwapi -lvfw32 -lpostproc -luuid # Default rules for deployment. QMAKE_CXXFLAGS_RELEASE += -Zi QMAKE_LFLAGS_RELEASE += /DEBUG /OPT:REF