|
|
@@ -1,54 +1,48 @@
|
|
|
-
|
|
|
+#include <locale.h>
|
|
|
#include <stdio.h>
|
|
|
#include <stdlib.h>
|
|
|
-
|
|
|
+#include <WinSock2.h>
|
|
|
+#ifndef WIN32_LEAN_AND_MEAN
|
|
|
+#define WIN32_LEAN_AND_MEAN
|
|
|
+#endif //
|
|
|
+#include <windows.h>
|
|
|
+
|
|
|
+#include <audioframework.h>
|
|
|
+#include <videoframework.h>
|
|
|
#include <portaudio.h>
|
|
|
+#include <pa_debugprint.h>
|
|
|
|
|
|
-//#include <pa_debugprint.h>
|
|
|
+#include <MMDeviceApi.h>
|
|
|
+#include <AudioEngineEndPoint.h>
|
|
|
+#include <DeviceTopology.h>
|
|
|
+#include <EndpointVolume.h>
|
|
|
+#include <functiondiscoverykeys.h>
|
|
|
+
|
|
|
+#include <md5.h>
|
|
|
|
|
|
-#include <errno.h>
|
|
|
-#include <fcntl.h>
|
|
|
-#include <stdio.h>
|
|
|
-#include <stdlib.h>
|
|
|
-#include <sys/ioctl.h>
|
|
|
-#include <sys/stat.h>
|
|
|
-#include <unistd.h>
|
|
|
-#include <sys/types.h>
|
|
|
-#include <sys/stat.h>
|
|
|
-#include <fcntl.h>
|
|
|
-#include <sys/mman.h>
|
|
|
-#include <poll.h>
|
|
|
-#include <sys/ioctl.h>
|
|
|
-#include <string.h>
|
|
|
-#include <unistd.h>
|
|
|
-//v4l includes
|
|
|
-#include <linux/videodev2.h>
|
|
|
-#include <dlfcn.h>
|
|
|
-#include <alsa/asoundlib.h>
|
|
|
-
|
|
|
-#include "../libmediadeviceinfo/imediadeviceinfo.h"
|
|
|
-
|
|
|
-
|
|
|
-#ifndef MAX_STR_LEN
|
|
|
#define MAX_STR_LEN 512
|
|
|
-#endif // !MAX_STR_LEN
|
|
|
|
|
|
+static char* utf8togb2312(const char* utf8)
|
|
|
+{
|
|
|
+ int len = MultiByteToWideChar(CP_UTF8, 0, utf8, -1, NULL, 0);
|
|
|
+
|
|
|
+ wchar_t* wstr = new wchar_t[len + 1];
|
|
|
+ memset(wstr, 0, len + 1);
|
|
|
|
|
|
-#ifndef MAX_PATH
|
|
|
-#define MAX_PATH 260
|
|
|
-#endif // !MAX_PATH
|
|
|
+ MultiByteToWideChar(CP_UTF8, 0, utf8, -1, wstr, len);
|
|
|
+ len = WideCharToMultiByte(CP_ACP, 0, wstr, -1, NULL, 0, NULL, NULL);
|
|
|
|
|
|
+ char* str = new char[len + 1];
|
|
|
+ memset(str, 0, len + 1);
|
|
|
|
|
|
-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);
|
|
|
+ WideCharToMultiByte(CP_ACP, 0, wstr, -1, str, len, NULL, NULL);
|
|
|
|
|
|
-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;
|
|
|
+ if (wstr) {
|
|
|
+ delete[]wstr;
|
|
|
+ wstr = NULL;
|
|
|
+ }
|
|
|
+ return str;
|
|
|
+}
|
|
|
|
|
|
|
|
|
static int audio_translate_id(int in_direction, int idx)
|
|
|
@@ -85,7 +79,6 @@ 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)
|
|
|
@@ -100,7 +93,7 @@ int audio_get_dev_count(int *in_cnt, int *out_cnt)
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-static char *audio_get_dev_name(char *buf, bool in_direction, int idx)
|
|
|
+static char *audio_get_dev_name(char *buf, BOOL in_direction, int idx)
|
|
|
{
|
|
|
int cnt = Pa_GetDeviceCount();
|
|
|
int ii, i;
|
|
|
@@ -133,22 +126,153 @@ static void show_audio_dev()
|
|
|
int rc = audio_get_dev_count(&icnt, &ocnt);
|
|
|
if (rc == 0) {
|
|
|
int i;
|
|
|
- char tmp[128];
|
|
|
+ char tmp[128] = {0};
|
|
|
printf("audio input devices(%d):\n", icnt);
|
|
|
for (i = 0; i < icnt; ++i) {
|
|
|
- audio_get_dev_name(tmp, true, i);
|
|
|
+ audio_get_dev_name(tmp, TRUE, i);
|
|
|
+#if _MSC_VER < 1929 //VS2010
|
|
|
+ char* straudioin = utf8togb2312(tmp);
|
|
|
+ printf("%d = %s\n", i, straudioin);
|
|
|
+ delete straudioin;
|
|
|
+#else
|
|
|
printf("%d = %s\n", i, tmp);
|
|
|
+#endif
|
|
|
}
|
|
|
printf("audio output devices(%d):\n", ocnt);
|
|
|
for (i = 0; i < ocnt; ++i) {
|
|
|
- audio_get_dev_name(tmp, false, i);
|
|
|
+ audio_get_dev_name(tmp, FALSE, i);
|
|
|
+#if _MSC_VER < 1929 //VS2010
|
|
|
+ char* straudioout = utf8togb2312(tmp);
|
|
|
+ printf("%d = %s\n", i, straudioout);
|
|
|
+ delete straudioout;
|
|
|
+#else
|
|
|
printf("%d = %s\n", i, tmp);
|
|
|
+#endif
|
|
|
}
|
|
|
printf("\n");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+typedef struct tagAUDIO_DEVICE_INFO
|
|
|
+{
|
|
|
+ char szDeviceName[MAX_STR_LEN];
|
|
|
+ char szDeviceID[MAX_STR_LEN];
|
|
|
+} AUDIO_DEVICE_INFO, *PAUDIO_DEVICE_INFO;
|
|
|
+
|
|
|
+static HRESULT GetDeviceNum(EDataFlow eDataFlow, UINT *uDevCount)
|
|
|
+{
|
|
|
+ IMMDeviceEnumerator *pEnumerator = NULL;
|
|
|
+ IMMDeviceCollection *pEndpoints = NULL;
|
|
|
+ HRESULT hr;
|
|
|
+
|
|
|
+ hr = CoCreateInstance(CLSID_MMDeviceEnumerator, NULL, CLSCTX_INPROC_SERVER, IID_IMMDeviceEnumerator, (void**)&pEnumerator);
|
|
|
+ if (FAILED(hr))
|
|
|
+ goto on_error;
|
|
|
+ hr = pEnumerator->EnumAudioEndpoints(eDataFlow, DEVICE_STATE_ACTIVE, (IMMDeviceCollection**)&pEndpoints);
|
|
|
+ if (FAILED(hr))
|
|
|
+ goto on_error;
|
|
|
+ hr = pEndpoints->GetCount(uDevCount);
|
|
|
+ if (FAILED(hr))
|
|
|
+ goto on_error;
|
|
|
+
|
|
|
+on_error:
|
|
|
+ if (pEndpoints)
|
|
|
+ pEndpoints->Release();
|
|
|
+ if (pEnumerator)
|
|
|
+ pEnumerator->Release();
|
|
|
+ return hr;
|
|
|
+}
|
|
|
+
|
|
|
+static HRESULT EnumDevice(EDataFlow eDataFlow, UINT uNumElements, AUDIO_DEVICE_INFO *pDevicInfo)
|
|
|
+{
|
|
|
+ IMMDeviceEnumerator *pEnumerator = NULL;
|
|
|
+ IMMDeviceCollection *pEndpoints = NULL;
|
|
|
+ HRESULT hr;
|
|
|
+ UINT uCount;
|
|
|
+ UINT uIdx;
|
|
|
+
|
|
|
+ hr = CoCreateInstance(CLSID_MMDeviceEnumerator, NULL, CLSCTX_INPROC_SERVER, IID_IMMDeviceEnumerator, (void**)&pEnumerator);
|
|
|
+ if (FAILED(hr))
|
|
|
+ goto on_error;
|
|
|
+ hr = pEnumerator->EnumAudioEndpoints(eDataFlow, DEVICE_STATE_ACTIVE, (IMMDeviceCollection**)&pEndpoints);
|
|
|
+ if (FAILED(hr))
|
|
|
+ goto on_error;
|
|
|
+ hr = pEndpoints->GetCount(&uCount);
|
|
|
+ if (FAILED(hr))
|
|
|
+ goto on_error;
|
|
|
+
|
|
|
+ ZeroMemory(pDevicInfo, sizeof(AUDIO_DEVICE_INFO)*uNumElements);
|
|
|
+
|
|
|
+ for (uIdx = 0; uIdx < uCount && uIdx < uNumElements; ++uIdx) {
|
|
|
+ IMMDevice *pDevice = NULL;
|
|
|
+ IPropertyStore *pPS = NULL;
|
|
|
+ WCHAR* pszDeviceId = NULL;
|
|
|
+ PROPVARIANT value;
|
|
|
+ PropVariantInit(&value);
|
|
|
+ pEndpoints->Item(uIdx, &pDevice);
|
|
|
+ pDevice->GetId(&pszDeviceId);
|
|
|
+ pDevice->OpenPropertyStore(STGM_READ, &pPS);
|
|
|
+ pPS->GetValue(PKEY_Device_FriendlyName, &value);
|
|
|
+ WideCharToMultiByte(CP_ACP, 0, pszDeviceId, -1, pDevicInfo[uIdx].szDeviceID, MAX_STR_LEN-1, NULL, NULL);
|
|
|
+ WideCharToMultiByte(CP_ACP, 0, value.pwszVal, -1, pDevicInfo[uIdx].szDeviceName, MAX_STR_LEN-1, NULL, NULL);
|
|
|
+ PropVariantClear(&value);
|
|
|
+ CoTaskMemFree(pszDeviceId);
|
|
|
+ pPS->Release();
|
|
|
+ pDevice->Release();
|
|
|
+ }
|
|
|
+
|
|
|
+on_error:
|
|
|
+ if (pEndpoints)
|
|
|
+ pEndpoints->Release();
|
|
|
+ if (pEnumerator)
|
|
|
+ pEnumerator->Release();
|
|
|
+ return hr;
|
|
|
+}
|
|
|
+
|
|
|
+static int get_device_index(int indev, const char *key)
|
|
|
+{
|
|
|
+ EDataFlow df = indev ? eCapture : eRender;
|
|
|
+ UINT i;
|
|
|
+ UINT n;
|
|
|
+ AUDIO_DEVICE_INFO *pInfo = NULL;
|
|
|
+ GetDeviceNum(df, &n);
|
|
|
+ pInfo = (AUDIO_DEVICE_INFO*)malloc(sizeof(AUDIO_DEVICE_INFO) * n);
|
|
|
+ EnumDevice(df, n, pInfo);
|
|
|
+ for (i = 0; i < n; ++i) {
|
|
|
+ if (strstr(pInfo[i].szDeviceName, key)) {
|
|
|
+ free(pInfo);
|
|
|
+ return i;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ free(pInfo);
|
|
|
+ return -1;
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
+static void show_audio_dev2()
|
|
|
+{
|
|
|
+ UINT i;
|
|
|
+ UINT n;
|
|
|
+ AUDIO_DEVICE_INFO *pInfo = NULL;
|
|
|
+
|
|
|
+ GetDeviceNum(eCapture, &n);
|
|
|
+ pInfo = (AUDIO_DEVICE_INFO*)malloc(sizeof(AUDIO_DEVICE_INFO) * n);
|
|
|
+ EnumDevice(eCapture, n, pInfo);
|
|
|
+ printf("audio input devices -- win7 (%d):\n", n);
|
|
|
+ for (i = 0; i < n; ++i) {
|
|
|
+ printf("%d = %s\n", i, pInfo[i].szDeviceName);
|
|
|
+ }
|
|
|
+ free(pInfo);
|
|
|
+
|
|
|
+ GetDeviceNum(eRender, &n);
|
|
|
+ pInfo = (AUDIO_DEVICE_INFO*)malloc(sizeof(AUDIO_DEVICE_INFO) * n);
|
|
|
+ EnumDevice(eRender, n, pInfo);
|
|
|
+ printf("audio output devices -- win7 (%d):\n", n);
|
|
|
+ for (i = 0; i < n; ++i) {
|
|
|
+ printf("%d = %s\n", i, pInfo[i].szDeviceName);
|
|
|
+ }
|
|
|
+ free(pInfo);
|
|
|
+}
|
|
|
|
|
|
static int Bin2Str(unsigned char *x, int xlen, char *str, int str_size)
|
|
|
{
|
|
|
@@ -167,285 +291,77 @@ static int Bin2Str(unsigned char *x, int xlen, char *str, int str_size)
|
|
|
}
|
|
|
|
|
|
|
|
|
-//static int isSupportThisFormat(int iPixelFormat)
|
|
|
-//{
|
|
|
-// unsigned int i;
|
|
|
-// for (i = 0; i < sizeof(g_aiSupportedFormats) / sizeof(g_aiSupportedFormats[0]); i++)
|
|
|
-// {
|
|
|
-// if (g_aiSupportedFormats[i] == iPixelFormat)
|
|
|
-// return 1;
|
|
|
-// }
|
|
|
-// return 0;
|
|
|
-//}
|
|
|
-
|
|
|
static void show_video_dev()
|
|
|
{
|
|
|
-
|
|
|
- //uint32_t count = 0;
|
|
|
- //char device[20];
|
|
|
- //int fd = -1;
|
|
|
- //bool found = false;
|
|
|
- //int n = 0;
|
|
|
- //for (; n < 64; n++)
|
|
|
- //{
|
|
|
- // sprintf(device, "/dev/video%d", n);
|
|
|
- // if ((fd = open(device, O_RDONLY)) != -1)
|
|
|
- // {
|
|
|
- // count++;
|
|
|
- // // query device capabilities
|
|
|
- // struct v4l2_capability cap;
|
|
|
- // struct v4l2_fmtdesc tFmtDesc;
|
|
|
- // struct v4l2_format tV4l2Fmt;
|
|
|
- // int iPixelFormat = 0;
|
|
|
- // if (ioctl(fd, VIDIOC_QUERYCAP, &cap) < 0)
|
|
|
- // {
|
|
|
- // printf("error in querying the device capability for device %s. errno = %d.\n",device, errno);
|
|
|
- // close(fd);
|
|
|
- // continue;
|
|
|
- // }
|
|
|
- // //printf("device[%s] Name UTF8 is: %s\n", device, cap.card);
|
|
|
- // if (cap.bus_info[0] != 0) // may not available in all drivers
|
|
|
- // {
|
|
|
- // //printf("device[%s] UniqueId UTF8 is: %s\n", device, cap.bus_info);
|
|
|
- // }
|
|
|
-
|
|
|
- // if (cap.driver[0] != 0) // may not available in all drivers
|
|
|
- // {
|
|
|
- // //printf("device[%s] driver UTF8 is: %s\n", device, cap.driver);
|
|
|
- // }
|
|
|
-
|
|
|
- // //printf("capabilities is 0x%x\n", cap.capabilities);
|
|
|
-
|
|
|
- // if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE))
|
|
|
- // {
|
|
|
- // //printf("%s is not a video capture device\n", device);
|
|
|
- // continue;
|
|
|
- // }
|
|
|
- // /* ------------------------------------------------------------------ */
|
|
|
-
|
|
|
- // if (cap.capabilities & V4L2_CAP_STREAMING) {
|
|
|
- // //printf("%s supports streaming i/o\n", device);
|
|
|
- // }
|
|
|
-
|
|
|
- // if (cap.capabilities & V4L2_CAP_READWRITE) {
|
|
|
- // //printf("%s supports read i/o\n", device);
|
|
|
- // }
|
|
|
-
|
|
|
- // /* 查询支持的格式 */
|
|
|
- // memset(&tFmtDesc, 0, sizeof(tFmtDesc));
|
|
|
- // tFmtDesc.index = 0;
|
|
|
- // tFmtDesc.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
|
|
- // while ((ioctl(fd, VIDIOC_ENUM_FMT, &tFmtDesc)) == 0) {
|
|
|
- // //if (isSupportThisFormat(tFmtDesc.pixelformat))
|
|
|
- // //printf("tFmtDesc.pixelformat == 0x:%x\n", tFmtDesc.pixelformat);
|
|
|
- // if(V4L2_PIX_FMT_YUYV == tFmtDesc.pixelformat || V4L2_PIX_FMT_RGB565 == tFmtDesc.pixelformat)
|
|
|
- // {
|
|
|
- // //printf("Support this format!\n");
|
|
|
- // iPixelFormat = tFmtDesc.pixelformat;
|
|
|
- // break;
|
|
|
- // }
|
|
|
- // //printf("Support this format +++!\n");
|
|
|
- // tFmtDesc.index++;
|
|
|
- // }
|
|
|
-
|
|
|
- // if (0 != iPixelFormat)
|
|
|
- // {
|
|
|
- // char strCameraName[MAX_PATH] = { 0 };
|
|
|
- // snprintf(strCameraName, MAX_PATH, "%s%s%s", cap.card,";",cap.bus_info);
|
|
|
- // printf("%s\n\n", strCameraName);
|
|
|
- // }
|
|
|
- // else {
|
|
|
- // //printf("can not support the format of this device[%s]\n\n", device);
|
|
|
- // continue;
|
|
|
- // }
|
|
|
-
|
|
|
-
|
|
|
- // /* 获取当前显示设备支持的分辨率 */
|
|
|
- // memset(&tV4l2Fmt, 0, sizeof(struct v4l2_format));
|
|
|
- // tV4l2Fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
|
|
- // tV4l2Fmt.fmt.pix.pixelformat = iPixelFormat;
|
|
|
- // tV4l2Fmt.fmt.pix.width = 1920;
|
|
|
- // tV4l2Fmt.fmt.pix.height = 1080;
|
|
|
- // tV4l2Fmt.fmt.pix.field = V4L2_FIELD_ANY;
|
|
|
-
|
|
|
- // /* 如果驱动程序发现无法某些参数(比如分辨率),
|
|
|
- // * 它会调整这些参数, 并且返回给应用程序
|
|
|
- // */
|
|
|
- // if (ioctl(fd, VIDIOC_S_FMT, &tV4l2Fmt))
|
|
|
- // {
|
|
|
- // //printf("Unable to set format\n\n");
|
|
|
- // continue;
|
|
|
- // }
|
|
|
- // {
|
|
|
- // int iWidth = tV4l2Fmt.fmt.pix.width;
|
|
|
- // int iHeight = tV4l2Fmt.fmt.pix.height;
|
|
|
-
|
|
|
- // //printf("width is %d\nheight is %d\nformat is %d\n\n", iWidth, iHeight, iPixelFormat);
|
|
|
- // }
|
|
|
-
|
|
|
- // close(fd);
|
|
|
- // }
|
|
|
- //}
|
|
|
-
|
|
|
- int icount = get_cameracount();
|
|
|
- printf("video devices(%d):\n", icount);
|
|
|
-
|
|
|
- int inumber = 0;
|
|
|
- for (int i = 0; i < 64 && inumber < icount; ++i) {
|
|
|
- char strcamera[2*MAX_PATH] = { 0 };
|
|
|
- char strpath[MAX_PATH] = { 0 };
|
|
|
-
|
|
|
- if(0 == get_device_fullpathname(i, strcamera, 2*MAX_PATH))
|
|
|
+ int i, n;
|
|
|
+
|
|
|
+ n = videocap_get_device_count();
|
|
|
+ printf("video devices(%d):\n", n);
|
|
|
+ for (i = 0; i < n; ++i) {
|
|
|
+ WCHAR tmp[256];
|
|
|
+ char t[256];
|
|
|
+ videocap_get_device_name(i, tmp, ARRAYSIZE(tmp));
|
|
|
+ WideCharToMultiByte(CP_ACP, 0, tmp, -1, t, sizeof(t), 0, NULL);
|
|
|
+ printf("%d = %s;", i, t);
|
|
|
+ videocap_get_device_path(i, tmp, ARRAYSIZE(tmp));
|
|
|
+ WideCharToMultiByte(CP_ACP, 0, tmp, -1, t, sizeof(t), 0, NULL);
|
|
|
{
|
|
|
- printf("%d = %s\n", inumber++, strcamera);
|
|
|
+ unsigned char x[MD5_DIGESTSIZE];
|
|
|
+ md5_ctx_t ctx;
|
|
|
+ md5_init(&ctx);
|
|
|
+ md5(x, t, strlen(t));
|
|
|
+ Bin2Str(x, sizeof(x), t, sizeof(t));
|
|
|
}
|
|
|
+ printf("%s\n", t);
|
|
|
+
|
|
|
}
|
|
|
+ printf("\n");
|
|
|
}
|
|
|
|
|
|
-
|
|
|
static void __dummy_log_callback(const char *log)
|
|
|
{
|
|
|
-
|
|
|
}
|
|
|
|
|
|
-static int load_dll_functions()
|
|
|
+static int app_init()
|
|
|
{
|
|
|
- int iret = -1;
|
|
|
+ CoInitialize(NULL);
|
|
|
|
|
|
- void* handle = NULL;
|
|
|
- char* error = NULL;
|
|
|
- handle = dlopen("./libmediadeviceinfo.so", RTLD_LAZY);
|
|
|
- if (NULL == handle)
|
|
|
- {
|
|
|
- printf("dlopen failed %s.\n", dlerror());
|
|
|
- return iret;
|
|
|
- }
|
|
|
-
|
|
|
- get_cameracount = (lpfn_get_cameracountfun)dlsym(handle, "rvc_videocap_get_device_count");
|
|
|
- if ((error = dlerror()) != NULL) {
|
|
|
- printf("%s\n", error);
|
|
|
- return iret;
|
|
|
- }
|
|
|
-
|
|
|
- get_videodevice_name = (lpfn_get_videodevice_namefun)dlsym(handle, "rvc_videocap_get_device_name");
|
|
|
- if ((error = dlerror()) != NULL) {
|
|
|
- printf("%s\n", error);
|
|
|
- return iret;
|
|
|
- }
|
|
|
-
|
|
|
- get_videodevice_info = (lpfn_get_videodevice_infofun)dlsym(handle, "rvc_videocap_get_device_info");
|
|
|
- if ((error = dlerror()) != NULL) {
|
|
|
- printf("%s\n", error);
|
|
|
- return iret;
|
|
|
- }
|
|
|
-
|
|
|
- get_device_fullpathname = (lpfn_get_videodevice_namefun)dlsym(handle, "rvc_videocap_get_device_fullpathname");
|
|
|
- if ((error = dlerror()) != NULL) {
|
|
|
- printf("%s\n", error);
|
|
|
- return iret;
|
|
|
- }
|
|
|
-
|
|
|
- get_videodeviceid = (lpfn_get_videodeviceid)dlsym(handle, "rvc_videocap_get_video_device_id");
|
|
|
- if ((error = dlerror()) != NULL) {
|
|
|
- printf("%s\n", error);
|
|
|
- return iret;
|
|
|
- }
|
|
|
+ Pa_Initialize();
|
|
|
+ PaUtil_SetDebugPrintFunction(&__dummy_log_callback);
|
|
|
|
|
|
- iret = 0;
|
|
|
+ audioframework_init();
|
|
|
+ videoframework_init();
|
|
|
|
|
|
- return iret;
|
|
|
-}
|
|
|
+ audio_log_set_func(NULL);
|
|
|
|
|
|
-static int app_init()
|
|
|
-{
|
|
|
- Pa_Initialize();
|
|
|
- //PaUtil_SetDebugPrintFunction(&__dummy_log_callback);
|
|
|
- int iret = load_dll_functions();
|
|
|
-
|
|
|
- return iret;
|
|
|
+ return 0;
|
|
|
}
|
|
|
|
|
|
static void app_term()
|
|
|
{
|
|
|
+ videoframework_term();
|
|
|
+ audioframework_term();
|
|
|
Pa_Terminate();
|
|
|
+ CoUninitialize();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-static void device_list(bool in_direction)
|
|
|
+int main()
|
|
|
{
|
|
|
- snd_ctl_t* handle = NULL;
|
|
|
- int card = 0, err = 0, dev = 0, idx = 0;
|
|
|
- snd_ctl_card_info_t* info = NULL;
|
|
|
- snd_pcm_info_t* pcminfo = NULL;
|
|
|
- snd_ctl_card_info_alloca(&info);
|
|
|
- snd_pcm_info_alloca(&pcminfo);
|
|
|
- snd_pcm_stream_t instream = SND_PCM_STREAM_CAPTURE;
|
|
|
- if (!in_direction){
|
|
|
- instream = SND_PCM_STREAM_PLAYBACK;
|
|
|
- }
|
|
|
+ printf("%s\n", setlocale(LC_ALL, "chs"));
|
|
|
|
|
|
- card = -1;
|
|
|
- if (snd_card_next(&card) < 0 || card < 0) {
|
|
|
- printf("no soundcards found...\n");
|
|
|
- return;
|
|
|
- }
|
|
|
- printf("**** List of %s Hardware Devices ****\n",snd_pcm_stream_name(instream));
|
|
|
- while (card >= 0) {
|
|
|
- char name[32] = {0};
|
|
|
- sprintf(name, "hw:%d", card);
|
|
|
- if ((err = snd_ctl_open(&handle, name, 0)) < 0) {
|
|
|
- printf("control open (%i): %s\n", card, snd_strerror(err));
|
|
|
- goto next_card;
|
|
|
- }
|
|
|
- if ((err = snd_ctl_card_info(handle, info)) < 0) {
|
|
|
- printf("control hardware info (%i): %s\n", card, snd_strerror(err));
|
|
|
- snd_ctl_close(handle);
|
|
|
- goto next_card;
|
|
|
- }
|
|
|
- dev = -1;
|
|
|
- while (1) {
|
|
|
- unsigned int count = 0;
|
|
|
- if (snd_ctl_pcm_next_device(handle, &dev) < 0)
|
|
|
- printf("snd_ctl_pcm_next_device\n");
|
|
|
- if (dev < 0)
|
|
|
- break;
|
|
|
- snd_pcm_info_set_device(pcminfo, dev);
|
|
|
- snd_pcm_info_set_subdevice(pcminfo, 0);
|
|
|
- snd_pcm_info_set_stream(pcminfo, instream);
|
|
|
- if ((err = snd_ctl_pcm_info(handle, pcminfo)) < 0) {
|
|
|
- if (err != -ENOENT)
|
|
|
- printf("control digital audio info (%i): %s\n", card, snd_strerror(err));
|
|
|
- continue;
|
|
|
- }
|
|
|
- printf("card %i: %s [%s], device %i: %s [%s]\n",
|
|
|
- card, snd_ctl_card_info_get_id(info), snd_ctl_card_info_get_name(info),
|
|
|
- dev,
|
|
|
- snd_pcm_info_get_id(pcminfo),
|
|
|
- snd_pcm_info_get_name(pcminfo));
|
|
|
- //printf("%s\n",snd_ctl_card_info_get_name(info));
|
|
|
- count = snd_pcm_info_get_subdevices_count(pcminfo);
|
|
|
- //printf(" Subdevices: %i/%i\n",snd_pcm_info_get_subdevices_avail(pcminfo), count);
|
|
|
- for (idx = 0; idx < (int)count; idx++) {
|
|
|
- snd_pcm_info_set_subdevice(pcminfo, idx);
|
|
|
- if ((err = snd_ctl_pcm_info(handle, pcminfo)) < 0) {
|
|
|
- printf("control digital audio playback info (%i): %s\n", card, snd_strerror(err));
|
|
|
- }
|
|
|
- else {
|
|
|
- //printf(" Subdevice #%i: %s\n",idx, snd_pcm_info_get_subdevice_name(pcminfo));
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- snd_ctl_close(handle);
|
|
|
- next_card:
|
|
|
- if (snd_card_next(&card) < 0) {
|
|
|
- printf("snd_card_next\n");
|
|
|
- break;
|
|
|
+ if(0)
|
|
|
+ {
|
|
|
+ HMODULE hModule = GetModuleHandleA("MSVCR100.dll");
|
|
|
+ if (hModule) {
|
|
|
+ typedef char *(*f_setlocale)(int, const char*);
|
|
|
+ f_setlocale f = (f_setlocale)GetProcAddress(hModule, "setlocale");
|
|
|
+ (*f)(LC_ALL, "chs");
|
|
|
}
|
|
|
}
|
|
|
-}
|
|
|
+ //setlocale(LC_ALL, setlocale(LC_ALL, NULL));
|
|
|
+
|
|
|
+ //getchar();
|
|
|
|
|
|
-int main()
|
|
|
-{
|
|
|
if (app_init() != 0) {
|
|
|
printf("app init failed!\n");
|
|
|
return -1;
|
|
|
@@ -454,17 +370,14 @@ int main()
|
|
|
show_audio_dev();
|
|
|
show_video_dev();
|
|
|
|
|
|
+ //MessageBoxA(0,0,0,0);
|
|
|
+ //show_audio_dev2();
|
|
|
+
|
|
|
//getchar();
|
|
|
|
|
|
app_term();
|
|
|
|
|
|
- printf("\n--------------------------------------------------------------\n");
|
|
|
- printf(" get audio device info from alsa. \n");
|
|
|
- printf("--------------------------------------------------------------\n");
|
|
|
-
|
|
|
- device_list(true);
|
|
|
- printf("--------------------------------------------------------------\n");
|
|
|
- device_list(false);
|
|
|
+ system("pause");
|
|
|
|
|
|
return 0;
|
|
|
}
|