Kaynağa Gözat

#IQRV #comment [Plugin] MediaDetect 填充 ShowDev 的代码

gifur 4 yıl önce
ebeveyn
işleme
bc6a957736

+ 27 - 2
Plugins/MediaDevDetect/CMakeLists.txt

@@ -6,6 +6,15 @@ find_package(Qt5 COMPONENTS Widgets REQUIRED
 
 find_package(Qt5UiTools HINTS ${QT5_HINT_PATH} NO_SYSTEM_ENVIRONMENT_PATH )
 
+if(WIN32)
+    conan_cmake_run(REQUIRES portaudio/v190600.20161030@LR04.02_ThirdParty/testing
+    BASIC_SETUP CMAKE_TARGETS)
+else(WIN32)
+    conan_cmake_run(REQUIRES portaudio/v19.0.6@LR04.02_ThirdParty/testing
+    alsa/1.1.6@LR04.02_ThirdParty/testing
+    BASIC_SETUP CMAKE_TARGETS)
+endif(WIN32)
+
 set(${MODULE_PREFIX}_SRCS
     mainform.cpp
     mainform.ui
@@ -14,11 +23,27 @@ set(${MODULE_PREFIX}_SRCS
 )
 
 add_library(${MODULE_NAME} SHARED ${${MODULE_PREFIX}_SRCS})
-target_include_directories(${MODULE_NAME} PRIVATE ${PLUGINS_COMM_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR})
+target_include_directories(${MODULE_NAME} PRIVATE 
+    ${RVC_OTHER_DEPENDENIES_DIR}/libmediadeviceinfo
+    ${PLUGINS_COMM_INCLUDE_DIRS}
+    ${CMAKE_CURRENT_SOURCE_DIR}
+    ${CONAN_INCLUDE_DIRS_PORTAUDIO}
+    )
+
+target_link_directories(${MODULE_NAME} PRIVATE
+    ${CONAN_LIB_DIRS_PORTAUDIO}
+    ${CONAN_LIB_DIRS_ALSA}
+    )
+
 set_target_properties(${MODULE_NAME} PROPERTIES AUTOMOC TRUE)
 
 list(APPEND ${MODULE_PREFIX}_LIBS Qt5::Widgets Qt5::Core Qt5::Gui Qt5::UiTools)
-target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS})
+set(CONAN_PKG_LIBS_ALSA asound)
+target_link_libraries(${MODULE_NAME} PUBLIC
+    ${${MODULE_PREFIX}_LIBS}
+    ${CONAN_PKG_LIBS_PORTAUDIO}
+    ${CONAN_PKG_LIBS_ALSA}
+    )
 
 install(TARGETS ${MODULE_NAME} 
     RUNTIME DESTINATION "${RVC_PLUGINS_PATH}"

+ 206 - 2
Plugins/MediaDevDetect/mainform.cpp

@@ -1,20 +1,224 @@
 #include "mainform.h"
 #include "ui_mainform.h"
+#include <portaudio.h>
 #include <QMessageBox>
+#include <QDebug>
+#include <QCoreApplication>
+
+#include "imediadeviceinfo.h"
+
+#ifndef MAX_STR_LEN
+#define MAX_STR_LEN 512
+#endif // !MAX_STR_LEN
+
+#ifndef MAX_PATH
+#define MAX_PATH 260
+#endif // !MAX_PATH
+
+typedef int (*lpfn_get_cameracountfun)();
+typedef int (*lpfn_get_videodevice_namefun)(int device_id, char* buf, int len);
+typedef int (*lpfn_get_videodevice_infofun)(int device_id, char* namebuf, int namelen, char* pathbuf, int pathlen);
+typedef int (*lpfn_get_videodeviceid)(const char* dev_name);
+
+static lpfn_get_cameracountfun get_cameracount = NULL;
+static lpfn_get_videodevice_namefun get_videodevice_name = NULL;
+static lpfn_get_videodevice_infofun get_videodevice_info = NULL;
+static lpfn_get_videodevice_namefun	get_device_fullpathname = NULL;
+static lpfn_get_videodeviceid get_videodeviceid = NULL;
+
+static int audio_translate_id(int in_direction, int idx)
+{
+    int i, n, ii;
+    //audio_log_set_func(NULL);
+    n = Pa_GetDeviceCount();
+    for (i = 0, ii = 0; i < n; ++i) {
+        const PaDeviceInfo* info = Pa_GetDeviceInfo(i);
+        if (in_direction) {
+            if (info->maxInputChannels) {
+                if (ii == idx) {
+                    //audio_log_set_func(__audio_log_func);
+                    return i;
+                }
+                ii++;
+            }
+        } else {
+            if (info->maxOutputChannels) {
+                if (ii == idx) {
+                    //audio_log_set_func(__audio_log_func);
+                    return i;
+                }
+                ii++;
+            }
+        }
+    }
+    //audio_log_set_func(__audio_log_func);
+    return -1;
+}
+
+int audio_get_dev_count(int* in_cnt, int* out_cnt)
+{
+    int i;
+    int icnt = 0, ocnt = 0;
+    int cnt = Pa_GetDeviceCount();
+    printf("\n\ndevice count is %d.\n", cnt);
+    for (i = 0; i < cnt; ++i) {
+        const PaDeviceInfo* info = Pa_GetDeviceInfo(i);
+        if (info->maxInputChannels)
+            icnt++;
+        if (info->maxOutputChannels)
+            ocnt++;
+    }
+    if (in_cnt)
+        *in_cnt = icnt;
+    if (out_cnt)
+        *out_cnt = ocnt;
+    return 0;
+}
+
+static char* audio_get_dev_name(char* buf, bool in_direction, int idx)
+{
+    int cnt = Pa_GetDeviceCount();
+    int ii, i;
+    for (i = 0, ii = 0; i < cnt; ++i) {
+        const PaDeviceInfo* info = Pa_GetDeviceInfo(i);
+        if (in_direction) {
+            if (info->maxInputChannels) {
+                if (idx == ii) {
+                    strcpy(buf, info->name);
+                    return buf;
+                }
+                ii++;
+            }
+        } else {
+            if (info->maxOutputChannels) {
+                if (idx == ii) {
+                    strcpy(buf, info->name);
+                    return buf;
+                }
+                ii++;
+            }
+        }
+    }
+    return NULL;
+}
+
+
+static void show_audio_dev()
+{
+    int icnt, ocnt;
+    int rc = audio_get_dev_count(&icnt, &ocnt);
+    if (rc == 0) {
+        int i;
+        char tmp[128];
+        printf("audio input devices(%d):\n", icnt);
+        for (i = 0; i < icnt; ++i) {
+            audio_get_dev_name(tmp, true, i);
+            printf("%d = %s\n", i, tmp);
+        }
+        printf("audio output devices(%d):\n", ocnt);
+        for (i = 0; i < ocnt; ++i) {
+            audio_get_dev_name(tmp, false, i);
+            printf("%d = %s\n", i, tmp);
+        }
+        printf("\n");
+    }
+}
+
+static void show_video_dev()
+{
+    int icount = get_cameracount();
+    printf("video devices(%d):\n", icount);
+
+    int inumber = 0;
+    for (int i = 0; i < 2 * icount; ++i) {
+        char strcamera[2 * MAX_PATH] = { 0 };
+        char strpath[MAX_PATH] = { 0 };
+
+        if (0 == get_device_fullpathname(i, strcamera, 2 * MAX_PATH)) {
+            printf("%d = %s\n", inumber++, strcamera);
+        }
+    }
+}
+
+
 
 MainForm::MainForm(QWidget *parent) :
     QWidget(parent),
-    ui(new Ui::MainForm)
+    ui(new Ui::MainForm), deviceInfoLib(nullptr)
 {
+    Pa_Initialize();
     ui->setupUi(this);
 }
 
 MainForm::~MainForm()
 {
     delete ui;
+    if (deviceInfoLib != nullptr) {
+        deviceInfoLib->unload();
+        delete deviceInfoLib;
+    }
+    Pa_Terminate();
 }
 
+bool MainForm::loadExportFunctions()
+{
+    QString appDir = QCoreApplication::applicationDirPath();
+    QString libAbsolutePath = appDir + "/libmediadeviceinfo.so";
+    qDebug() << "Enter loadExportFunctions" << " " << libAbsolutePath << endl;
+    deviceInfoLib = new QLibrary(libAbsolutePath);
+    deviceInfoLib->load();
+    if (!deviceInfoLib->isLoaded()) {
+        qDebug() << "Load libmediadeviceinfo.so failed: " << deviceInfoLib->errorString() << endl;
+        return false;
+    }
+    get_cameracount = (lpfn_get_cameracountfun)deviceInfoLib->resolve("rvc_videocap_get_device_count");
+    if (!get_cameracount) {
+        qDebug() << "Load rvc_videocap_get_device_count failed: " << deviceInfoLib->errorString() << endl;
+        deviceInfoLib->unload();
+        return false;
+    }
+    get_videodevice_name = (lpfn_get_videodevice_namefun)deviceInfoLib->resolve("rvc_videocap_get_device_name");
+    if (!get_videodevice_name) {
+        qDebug() << "Load rvc_videocap_get_device_name failed: " << deviceInfoLib->errorString() << endl;
+        deviceInfoLib->unload();
+        return false;
+    }
+
+    get_videodevice_info = (lpfn_get_videodevice_infofun)deviceInfoLib->resolve("rvc_videocap_get_device_info");
+    if (!get_videodevice_info) {
+        qDebug() << "Load rvc_videocap_get_device_info failed: " << deviceInfoLib->errorString() << endl;
+        deviceInfoLib->unload();
+        return false;
+    }
+
+    get_device_fullpathname = (lpfn_get_videodevice_namefun)deviceInfoLib->resolve("rvc_videocap_get_device_fullpathname");
+    if (!get_device_fullpathname) {
+        qDebug() << "Load rvc_videocap_get_device_fullpathname failed: " << deviceInfoLib->errorString() << endl;
+        deviceInfoLib->unload();
+        return false;
+    }
+
+    get_videodeviceid = (lpfn_get_videodeviceid)deviceInfoLib->resolve("rvc_videocap_get_video_device_id");
+    if (!get_videodeviceid) {
+        qDebug() << "Load rvc_videocap_get_video_device_id failed: " << deviceInfoLib->errorString() << endl;
+        deviceInfoLib->unload();
+        return false;
+    }
+    
+    return true;
+}
+
+
+
 void MainForm::on_pushButton_clicked()
 {
-    QMessageBox::information(this, "TSET", tst);
+    QMessageBox::information(this, "Hello", tst);
+    if (!loadExportFunctions()) {
+        qDebug() << "load library failed!" << endl;
+        return;
+    }
+    if (deviceInfoLib != nullptr) {
+        show_audio_dev();
+        show_video_dev();
+    }
 }

+ 3 - 1
Plugins/MediaDevDetect/mainform.h

@@ -2,6 +2,7 @@
 #define MAINFORM_H
 
 #include <QWidget>
+#include <QLibrary>
 
 namespace Ui {
 class MainForm;
@@ -17,9 +18,10 @@ public:
     QString tst;
 private slots:
     void on_pushButton_clicked();
-
+    bool loadExportFunctions();
 private:
     Ui::MainForm *ui;
+    QLibrary* deviceInfoLib;
 };
 
 #endif // MAINFORM_H

+ 1 - 0
Plugins/MediaDevDetect/mediadetectplugin.json

@@ -0,0 +1 @@
+{}

+ 2 - 0
Plugins/MediaDevDetect/mediadevdetect.cpp

@@ -1,5 +1,6 @@
 #include "mediadevdetect.h"
 #include "mainform.h"
+#include <QDebug>
 
 QString MediaDevDetect::getVersion()
 {
@@ -18,6 +19,7 @@ QString MediaDevDetect::getDisplayText()
 
 QWidget* MediaDevDetect::getComponent(QWidget *parent, const QStringList& param)
 {
+    qDebug() << "Enter getComponent" << endl;
     MainForm* item = new MainForm(parent);
     item->tst = param[0];
     item->setWindowTitle(item->tst);

+ 3 - 1
Plugins/MediaDevDetect/mediadevdetect.h

@@ -4,6 +4,8 @@
 #include "CustomImportInterface.h"
 #include <QtCore/qglobal.h>
 
+#define MEDIADEVDETECT_LIBRARY
+
 #if defined(MEDIADEVDETECT_LIBRARY)
 #  define MEDIADEVDETECT_EXPORT Q_DECL_EXPORT
 #else
@@ -13,7 +15,7 @@
 class MEDIADEVDETECT_EXPORT MediaDevDetect : public QObject, CustomImportInterface
 {
     Q_OBJECT
-    Q_PLUGIN_METADATA(IID "org.cmbchina.rvcterminal.CustomImportInterface/1.0")
+    Q_PLUGIN_METADATA(IID "org.cmbchina.rvcterminal.CustomImportInterface/1.0" FILE "mediadetectplugin.json")
     Q_INTERFACES(CustomImportInterface)
 
 public: