|
@@ -2,13 +2,18 @@
|
|
|
#include "libvideorecord_impl.h"
|
|
|
#include "videoutil.h"
|
|
|
#include "io.h"
|
|
|
+//#include <windowsx.h>
|
|
|
#include <stdint.h>
|
|
|
#include <stdio.h>
|
|
|
#include <process.h>
|
|
|
#include <string.h>
|
|
|
#include <timeapi.h>
|
|
|
+//#include <windows.h> //包含头文件 windows.h
|
|
|
+//#include <MMSystem.h>
|
|
|
#pragma comment(lib, "winmm.lib")
|
|
|
-
|
|
|
+//#include <DbgHelp.h>
|
|
|
+//#pragma comment(lib, "dbghelp.lib")
|
|
|
+//#pragma comment(lib, "WMVCORE.lib")
|
|
|
#ifndef RECORD_SAFE_DELETE
|
|
|
#define RECORD_SAFE_DELETE(p) \
|
|
|
do{ \
|
|
@@ -29,20 +34,15 @@
|
|
|
|
|
|
static bool ReNameFile(const char* file, const char* newfilename)
|
|
|
{
|
|
|
-#ifdef _WIN32
|
|
|
- if (!_access(file, 0))
|
|
|
-#else
|
|
|
- if (!access(file, F_OK))
|
|
|
-#endif //_WIN32
|
|
|
- {
|
|
|
- if (!rename(file, newfilename)){
|
|
|
+ if (!_access(file, 0)) {
|
|
|
+ if (!rename(file, newfilename)) {
|
|
|
return true;
|
|
|
}
|
|
|
- else{
|
|
|
+ else {
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
- else{
|
|
|
+ else {
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
@@ -62,7 +62,7 @@ static uint32_t BindPCMAudioData(uint32_t uBufferLen, char* pLocalAudios, uint32
|
|
|
memset(pLocalAudios, 0, uBufferLen);
|
|
|
}
|
|
|
|
|
|
- for (uint32_t i = 0; i < uLocalAudioLen / uBitDeepth; i++) {
|
|
|
+ for (int i = 0; i < uLocalAudioLen / uBitDeepth; i++) {
|
|
|
if (eLocalLeft == eType) {
|
|
|
memcpy((uint32_t*)pLocalAudios + i, ((uint16_t*)(pBuffer)) + i, uBitDeepth);
|
|
|
uint16_t* pindex = (uint16_t*)((uint32_t*)pLocalAudios + i) + 1;
|
|
@@ -353,6 +353,41 @@ static void DeleteDumpFiles()
|
|
|
}
|
|
|
|
|
|
|
|
|
+//static void videorecorddump_exception(PEXCEPTION_POINTERS ExceptionInfo, libvideorecord_impl* pVideoRecord)
|
|
|
+//{
|
|
|
+// if (NULL != pVideoRecord) {
|
|
|
+// pVideoRecord->EndRecord();
|
|
|
+// if (NULL != pVideoRecord->m_pHostApi) {
|
|
|
+// pVideoRecord->m_pHostApi->Debug(RECORD_LOG_ERROR, "VideoRecord Thread Exception.");
|
|
|
+// pVideoRecord->m_pHostApi->OnRecordEntityExcption();
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// DeleteDumpFiles();
|
|
|
+//
|
|
|
+// char tmp[MAX_PATH] = { 0 };
|
|
|
+// HANDLE hDumpFile;
|
|
|
+// sprintf_s(tmp, MAX_PATH, ".\\videorecord_%d.dmp", GetCurrentProcessId());
|
|
|
+// hDumpFile = CreateFileA(tmp, GENERIC_READ | GENERIC_WRITE,
|
|
|
+// 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
+// if ((hDumpFile != NULL) && (hDumpFile != INVALID_HANDLE_VALUE))
|
|
|
+// {
|
|
|
+// MINIDUMP_EXCEPTION_INFORMATION mdei;
|
|
|
+// MINIDUMP_TYPE mdt;
|
|
|
+//
|
|
|
+// mdei.ThreadId = GetCurrentThreadId();
|
|
|
+// mdei.ExceptionPointers = ExceptionInfo;
|
|
|
+// mdei.ClientPointers = false;
|
|
|
+//
|
|
|
+// mdt = MiniDumpWithFullMemory;
|
|
|
+//
|
|
|
+// MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(),
|
|
|
+// hDumpFile, mdt, (ExceptionInfo != 0) ? &mdei : 0, 0, 0);
|
|
|
+//
|
|
|
+// CloseHandle(hDumpFile);
|
|
|
+// }
|
|
|
+//}
|
|
|
+
|
|
|
|
|
|
static void __recordlog(void* user_data, const char* fmt, va_list arg)
|
|
|
{
|
|
@@ -369,11 +404,16 @@ static void __recordlog(void* user_data, const char* fmt, va_list arg)
|
|
|
//视频录制线程
|
|
|
static unsigned int __stdcall VideoRecordThread(LPVOID n)
|
|
|
{
|
|
|
- int iRet = -1;
|
|
|
-
|
|
|
libvideorecord_impl* Record = (libvideorecord_impl*)n;
|
|
|
+ int iRet = -1;
|
|
|
|
|
|
+ //__try
|
|
|
+ //{
|
|
|
iRet = Record->VideoRecord();
|
|
|
+ //}
|
|
|
+ //__except (videorecorddump_exception(GetExceptionInformation(), Record), EXCEPTION_EXECUTE_HANDLER) {
|
|
|
+
|
|
|
+ //}
|
|
|
|
|
|
return iRet;
|
|
|
}
|
|
@@ -1019,7 +1059,7 @@ int libvideorecord_impl::GetStand2SVideoFrameData(videoq_frame* Video, int flags
|
|
|
delete tmp_frm;
|
|
|
}
|
|
|
else{
|
|
|
- m_pHostApi->Debug(RECORD_LOG_ERROR, "nActiveCam value is not valid, and it's value is %d.", nActiveCam);
|
|
|
+ m_pHostApi->Debug(RECORD_LOG_DEBUG, "nActiveCam value is not valid, and it's value is %d.", nActiveCam);
|
|
|
return -4;
|
|
|
}
|
|
|
|
|
@@ -1802,7 +1842,6 @@ bool libvideorecord_impl::GetLocalAudioFrame(int iAudioLens)
|
|
|
bRet = true;
|
|
|
}
|
|
|
else {
|
|
|
- m_pHostApi->Debug(RECORD_LOG_ERROR, "not support audio sample rate, and audio samplespersec=%d,framesize=%d,channels=%d,format=%d,bitspersample=%d,series number=%d.", m_audioframe->samplespersec, m_audioframe->framesize, m_audioframe->nchannels, m_audioframe->format, m_audioframe->bitspersample, m_audioframe->iseriesnumber);
|
|
|
LogFailedEvent(eSampNotSupport, "not support audio sample rate.");
|
|
|
}
|
|
|
}
|
|
@@ -1838,32 +1877,6 @@ bool libvideorecord_impl::GetSingleSideAudioFrame()
|
|
|
}
|
|
|
|
|
|
|
|
|
-bool libvideorecord_impl::AddMuteAudioFrame(bool bLocal, int iAudioFrameSize)
|
|
|
-{
|
|
|
- bool bRet = false;
|
|
|
-
|
|
|
- if (0 == iAudioFrameSize) {
|
|
|
- return bRet;
|
|
|
- }
|
|
|
-
|
|
|
- if (bLocal) {
|
|
|
- memset(m_pRecordAudioBuffer + m_iAudioBufferLen, 0, iAudioFrameSize);
|
|
|
- m_iAudioBufferLen += iAudioFrameSize;
|
|
|
- m_iAudioFromQueNum++;
|
|
|
- m_pHostApi->Debug(RECORD_LOG_INFO, "m_iAudioFromQueNum is %d(Mute AudioFrame).", m_iAudioFromQueNum);
|
|
|
- bRet = true;
|
|
|
- }
|
|
|
- else {
|
|
|
- memset(m_pRemoteAudioBuffer + m_iRemoteAudioBufLen, 0, iAudioFrameSize);
|
|
|
- m_iRemoteAudioBufLen += iAudioFrameSize;
|
|
|
- m_iRemoteAudioNum++;
|
|
|
- m_pHostApi->Debug(RECORD_LOG_INFO, "m_iRemoteAudioNum is %d(Mute Audio Frame).", m_iRemoteAudioNum);
|
|
|
- bRet = true;
|
|
|
- }
|
|
|
-
|
|
|
- return bRet;
|
|
|
-}
|
|
|
-
|
|
|
bool libvideorecord_impl::GetRecordAudioFrame()
|
|
|
{
|
|
|
bool bRet = false;
|
|
@@ -1876,32 +1889,44 @@ bool libvideorecord_impl::GetRecordAudioFrame()
|
|
|
int nAudioLens = m_audioqueue->GetAudioLens();
|
|
|
int nRemoteAudioLens = m_remote_audioqueue->GetAudioLens();
|
|
|
m_pHostApi->Debug(RECORD_LOG_DEBUG,"current local audio length is %d, and remote audio length is %d.", nAudioLens, nRemoteAudioLens);
|
|
|
- //1. 取本地音频
|
|
|
- if (m_iAudioBufferLen < m_iAudioPerSecBufLen) {
|
|
|
- if (nAudioLens > 0) {//取到本地音频
|
|
|
+ if ((nAudioLens > 0) && (nRemoteAudioLens <= 0)) {
|
|
|
+ if (m_iAudioBufferLen < m_iAudioPerSecBufLen) { //取出音频
|
|
|
bRet = GetLocalAudioFrame(nAudioLens);
|
|
|
}
|
|
|
- else {//本地音频队列为空,用静音填充
|
|
|
- bRet = AddMuteAudioFrame(true, m_iAudioPerSecBufLen/50);
|
|
|
- }
|
|
|
}
|
|
|
-
|
|
|
- //2. 取远端音频
|
|
|
- if (m_iRemoteAudioBufLen < m_iAudioPerSecBufLen) {
|
|
|
- if (nRemoteAudioLens > 0) {
|
|
|
+ else if ((nAudioLens > 0) && (nRemoteAudioLens > 0)) {
|
|
|
+ if (m_iRemoteAudioBufLen < m_iAudioPerSecBufLen) { //收到的远端音频不够1秒
|
|
|
bRet = GetRemoteAudioFrame(nRemoteAudioLens); //取远端音频
|
|
|
}
|
|
|
- else{
|
|
|
- bRet = AddMuteAudioFrame(false, m_iAudioPerSecBufLen / 50);
|
|
|
+
|
|
|
+ if (m_iAudioBufferLen < m_iAudioPerSecBufLen) {
|
|
|
+ bRet = GetLocalAudioFrame(nAudioLens); //本地音频
|
|
|
+ }
|
|
|
+ if ((m_iRemoteAudioBufLen == m_iAudioPerSecBufLen) && (m_iAudioBufferLen == m_iAudioPerSecBufLen)) {
|
|
|
+ //可视远程双录场景,本地和坐席端分别录制到左右声道
|
|
|
+ uint32_t uOutlen = BindPCMAudioData(m_iRecordAudioBufSize, m_pRecordAudioBuffer, m_iAudioBufferLen, m_pRemoteAudioBuffer, m_iRemoteAudioBufLen, m_audioframe->bitspersample / 8, eLocalLeft);
|
|
|
+ m_pHostApi->Debug(RECORD_LOG_DEBUG, "double channel buffer length is %d, local buffer len is %d, remote buffer len is %d.", m_iRecordAudioBufSize, m_iAudioBufferLen, m_iRemoteAudioBufLen);
|
|
|
+ m_iAudioBufferLen = uOutlen;
|
|
|
}
|
|
|
}
|
|
|
+ else if ((nAudioLens <= 0) && (nRemoteAudioLens > 0)) { //本地端无数据不混音,双录语音播报场景
|
|
|
+ if (m_iAudioBufferLen < m_iAudioPerSecBufLen) { //取出音频
|
|
|
+ m_audioframe->data = m_pRecordAudioBuffer + m_iAudioBufferLen;
|
|
|
+ bool bGetAudio = false;
|
|
|
+ if (nRemoteAudioLens <= MAX_AUDIOQUEUE_LENS && nRemoteAudioLens > 1) {
|
|
|
+ bGetAudio = m_remote_audioqueue->GetAudioAndDel(m_audioframe);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ bGetAudio = m_remote_audioqueue->GetAudio(m_audioframe);
|
|
|
+ }
|
|
|
|
|
|
- //3. 可视远程双录场景,本地和坐席端分别录制到左右声道
|
|
|
- if ((m_iRemoteAudioBufLen == m_iAudioPerSecBufLen) && (m_iAudioBufferLen == m_iAudioPerSecBufLen)) {
|
|
|
-
|
|
|
- uint32_t uOutlen = BindPCMAudioData(m_iRecordAudioBufSize, m_pRecordAudioBuffer, m_iAudioBufferLen, m_pRemoteAudioBuffer, m_iRemoteAudioBufLen, m_audioframe->bitspersample / 8, eLocalLeft);
|
|
|
- m_pHostApi->Debug(RECORD_LOG_DEBUG, "double channel buffer length is %d, local buffer len is %d, remote buffer len is %d.", m_iRecordAudioBufSize, m_iAudioBufferLen, m_iRemoteAudioBufLen);
|
|
|
- m_iAudioBufferLen = uOutlen;
|
|
|
+ if (bGetAudio) {
|
|
|
+ m_pHostApi->Debug(RECORD_LOG_DEBUG,"remote audio series number is %d, channels is %d, samplespersec is %d.", m_audioframe->iseriesnumber, m_audioframe->nchannels, m_audioframe->samplespersec);
|
|
|
+ m_iAudioBufferLen += m_audioframe->framesize;
|
|
|
+ m_iAudioFromQueNum++;
|
|
|
+ m_pHostApi->Debug(RECORD_LOG_DEBUG,"m_iAudioFromQueNum is %d.", m_iAudioFromQueNum);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
m_pHostApi->Debug(RECORD_LOG_DEBUG, "current m_iAudioBufferLen = %d, m_iAudioPerSecBufLen = %d.", m_iAudioBufferLen, m_iAudioPerSecBufLen);
|
|
@@ -1943,17 +1968,13 @@ bool libvideorecord_impl::InitVideoRecordParams()
|
|
|
|
|
|
//获取视频帧大小
|
|
|
if (!GetRecordVideoFrameSize()) {
|
|
|
- if (false == m_bStopRecord) {
|
|
|
- LogFailedEvent(eVideoGetFailed, "Get Video Frame Failed Max Times.", true);
|
|
|
- }
|
|
|
+ LogFailedEvent(eVideoGetFailed, "Get Video Frame Failed Max Times.", true);
|
|
|
return bRet;
|
|
|
}
|
|
|
|
|
|
//获取音频帧大小
|
|
|
if (!GetRecordAudioFrameSize()) {
|
|
|
- if (false == m_bStopRecord) {
|
|
|
- LogFailedEvent(eLocalAudioGetFailed, "Get Audio Frame Failed Max Times.", true);
|
|
|
- }
|
|
|
+ LogFailedEvent(eLocalAudioGetFailed, "Get Audio Frame Failed Max Times.", true);
|
|
|
return bRet;
|
|
|
}
|
|
|
|