|
|
@@ -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();
|
|
|
+ }
|
|
|
}
|