libwmvrecord.cpp 67 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166
  1. // libwmvrecord.cpp : 定义 DLL 应用程序的导出函数。
  2. //
  3. #include "libwmvrecord.h"
  4. #ifdef RVC_OS_WIN
  5. #include "io.h"
  6. #include <process.h>
  7. #include <windows.h> //包含头文件 windows.h
  8. #else
  9. #include <pthread.h>
  10. #endif
  11. #include <dirent.h>
  12. #include <stdint.h>
  13. #include <unistd.h>
  14. #include "libaudioqueue.h"
  15. #include "libvideoqueue.h"
  16. #include <stdio.h>
  17. #include <math.h>
  18. #include <exception>
  19. #include "FFmpegWriter.h"
  20. #include "videoutil.h"
  21. #include "cv.h"
  22. #include "highgui.h"
  23. #include "CvxText.h" // 用于中文字幕添加 add by ly
  24. #include <speex/speex_resampler.h>
  25. #include "iaudionsinterface.h"
  26. #include <semaphore.h>
  27. #define SLASH '/'
  28. #define BACK_SLASH '\\'
  29. #define MB_SLASH_STR "/"
  30. #define MB_BACK_SLASH_STR "\\"
  31. #define W_SLASH_STR L"/"
  32. #define W_BACK_SLASH_STR L"\\"
  33. #if defined(UNICODE) || defined(_UNICODE)
  34. #define SLASH_STR W_SLASH_STR
  35. #define BACK_SLASH_STR W_BACK_SLASH_STR
  36. #else
  37. #define SLASH_STR MB_SLASH_STR
  38. #define BACK_SLASH_STR MB_BACK_SLASH_STR
  39. #endif
  40. #ifdef _WIN32
  41. #define SPLIT_SLASH BACK_SLASH
  42. #define SPLIT_SLASH_STR BACK_SLASH_STR
  43. #define MB_SPLIT_SLASH_STR MB_BACK_SLASH_STR
  44. #define W_SPLIT_SLASH_STR W_BACK_SLASH_STR
  45. #define LINE_BREAK_STR "\r\n"
  46. #else
  47. #define SPLIT_SLASH SLASH
  48. #define SPLIT_SLASH_STR SLASH_STR
  49. #define MB_SPLIT_SLASH_STR MB_SLASH_STR
  50. #define W_SPLIT_SLASH_STR W_SLASH_STR
  51. #define LINE_BREAK_STR "\n"
  52. #endif
  53. #ifndef CAPTURE_CLOCK
  54. #define CAPTURE_CLOCK 8000
  55. #endif
  56. #ifndef CAPTURE_FRAME_TIME
  57. #define CAPTURE_FRAME_TIME 20 // 20ms per frame
  58. #endif
  59. #ifdef RVC_OS_WIN
  60. #include <DbgHelp.h>
  61. #pragma comment(lib, "dbghelp.lib")
  62. #endif
  63. #ifndef RVC_OS_WIN
  64. #include <time.h>
  65. unsigned int timeGetTime()
  66. {
  67. unsigned int uptime = 0;
  68. struct timespec on;
  69. if (clock_gettime(CLOCK_MONOTONIC, &on) == 0)
  70. uptime = on.tv_sec * 1000 + on.tv_nsec / 1000000;
  71. return uptime;
  72. }
  73. #endif
  74. void GetLocalTimeRVC(SYSTEMTIME& stTime)
  75. {
  76. #ifdef RVC_OS_WIN
  77. GetLocalTime(&stTime);
  78. #else
  79. struct tm* pst = NULL;
  80. time_t t = time(NULL);
  81. pst = localtime(&t);
  82. stTime.wYear = pst->tm_year + 1900;
  83. stTime.wMonth = pst->tm_mon + 1;//because the range of tm_mon is:0-11
  84. stTime.wDay = pst->tm_mday;
  85. stTime.wHour = pst->tm_hour;
  86. stTime.wMinute = pst->tm_min;
  87. stTime.wDayOfWeek = pst->tm_wday;
  88. stTime.wSecond = pst->tm_sec;
  89. stTime.wMilliseconds = 0;
  90. //Dbg("oiltest,time:%d,%d,%d,%d", stTime.wYear, stTime.wHour, stTime.wMinute, stTime.wDayOfWeek);
  91. #endif
  92. }
  93. class libwmvrecord_impl : public LogApi
  94. {
  95. public:
  96. libwmvrecord_impl(BOOL *pResult,CWmvHostApi *pHostAPI,LPCTSTR audioqueuename,LPCTSTR videoqueuename,LPCTSTR videoqueue2name,LPCTSTR salesaudioqueuename,LPCTSTR remotevideoqueuename,LPCTSTR remoteaudioqueuename)
  97. {
  98. m_bResult = pResult;
  99. m_pHostApi = pHostAPI;
  100. m_bStopRecord = FALSE;
  101. m_bCloseVideo = FALSE;
  102. m_eRecordType = eSingleSide;
  103. m_bIsAudioNsOn = FALSE;
  104. m_iNsPolicy = 2;
  105. m_bIsAudioTransOn = FALSE;
  106. m_bReNameVideo = FALSE;
  107. m_nFps = 0;
  108. m_bWholeSection = FALSE;
  109. m_bSessionManage = FALSE;
  110. videoframe = new videoq_frame;
  111. memset(videoframe,0,sizeof(videoq_frame));
  112. audioframe = new audio_frame;
  113. memset(audioframe,0,sizeof(audio_frame));
  114. m_nRecordthreadId = 0;
  115. sem_init(&m_semt, 0, 0);
  116. m_pAudioBufferTmp = NULL; //音频录制拼接BUFFER
  117. m_iAudioBufferSize = 0;
  118. memset(m_FileName,0,MAX_PATH);
  119. memset(m_WmvFileName,0,MAX_PATH);
  120. memset(m_PathName,0,MAX_PATH);
  121. memset(m_audioqueuename, 0, MAX_PATH);
  122. memset(m_salesaudioqueuename, 0, MAX_PATH);
  123. memset(m_videoqueuename, 0, MAX_PATH);
  124. memset(m_videoqueue2name, 0, MAX_PATH);
  125. memset(m_remotevideoqueuename, 0, MAX_PATH);
  126. memset(m_remoteaudioqueuename, 0, MAX_PATH);
  127. m_audioqueue = NULL;
  128. strncpy(m_audioqueuename, audioqueuename, (strlen(audioqueuename) > MAX_PATH) ? (MAX_PATH - 1): strlen(audioqueuename));
  129. m_salesaudioqueue = NULL;
  130. if (salesaudioqueuename){
  131. strncpy(m_salesaudioqueuename, salesaudioqueuename, (strlen(salesaudioqueuename) > MAX_PATH) ? (MAX_PATH - 1) : strlen(salesaudioqueuename));
  132. }
  133. m_videoqueue = NULL;
  134. if (videoqueuename){
  135. strncpy(m_videoqueuename, videoqueuename, (strlen(videoqueuename) > MAX_PATH) ? (MAX_PATH - 1) : strlen(videoqueuename));
  136. }
  137. m_videoqueue2 = NULL;
  138. if (videoqueue2name){
  139. strncpy(m_videoqueue2name, videoqueue2name, (strlen(videoqueue2name) > MAX_PATH) ? (MAX_PATH - 1) : strlen(videoqueue2name));
  140. }
  141. m_remotevideoqueue = NULL;
  142. if (remotevideoqueuename){
  143. strncpy(m_remotevideoqueuename, remotevideoqueuename, (strlen(remotevideoqueuename) > MAX_PATH) ? (MAX_PATH - 1) : strlen(remotevideoqueuename));
  144. }
  145. m_remoteaudioqueue = NULL;
  146. if (remoteaudioqueuename){
  147. strncpy(m_remoteaudioqueuename, remoteaudioqueuename, (strlen(remoteaudioqueuename) > MAX_PATH) ? (MAX_PATH - 1) : strlen(remoteaudioqueuename));
  148. }
  149. m_pWriter = NULL;
  150. m_pAudioNsObj = NULL;
  151. int err = 0;
  152. m_16kto8kst = speex_resampler_init_frac(1, 2*CAPTURE_CLOCK , CAPTURE_CLOCK, 2*CAPTURE_CLOCK, CAPTURE_CLOCK, 0, &err);
  153. *pResult = TRUE;
  154. }
  155. ~libwmvrecord_impl()
  156. {
  157. if (videoframe->data != NULL){
  158. delete videoframe->data;
  159. videoframe->data = NULL;
  160. }
  161. if (videoframe != NULL){
  162. delete videoframe;
  163. videoframe = NULL;
  164. }
  165. if (audioframe != NULL){
  166. delete audioframe;
  167. audioframe = NULL;
  168. }
  169. if (m_pWriter!= NULL){
  170. delete m_pWriter;
  171. m_pWriter = NULL;
  172. }
  173. if (m_localaudioqueue != NULL){
  174. delete m_localaudioqueue;
  175. m_localaudioqueue = NULL;
  176. }
  177. if (m_salesaudioqueue != NULL){
  178. delete m_salesaudioqueue;
  179. m_salesaudioqueue = NULL;
  180. }
  181. m_audioqueue = NULL;
  182. if (m_remoteaudioqueue != NULL){
  183. delete m_remoteaudioqueue;
  184. m_remoteaudioqueue = NULL;
  185. }
  186. if (m_videoqueue != NULL){
  187. delete m_videoqueue;
  188. m_videoqueue = NULL;
  189. }
  190. if (m_videoqueue2 != NULL){
  191. delete m_videoqueue2;
  192. m_videoqueue2 = NULL;
  193. }
  194. if (m_remotevideoqueue != NULL){
  195. delete m_remotevideoqueue;
  196. m_remotevideoqueue = NULL;
  197. }
  198. if (NULL != m_16kto8kst){
  199. speex_resampler_destroy(m_16kto8kst);
  200. m_16kto8kst = NULL;
  201. }
  202. if (NULL != m_pAudioNsObj){
  203. DestroyIAudioNsObj(m_pAudioNsObj);
  204. m_pAudioNsObj = NULL;
  205. }
  206. }
  207. CWmvHostApi* GetHostApi()
  208. {
  209. return m_pHostApi;
  210. }
  211. private:
  212. sem_t m_semt;
  213. BOOL m_bStopRecord;
  214. eRvcRecordType m_eRecordType; //录制双向的视频类型,0:单向录制,1:手机<->pad双录,2:坐席<->pad双录,3:坐席<->大机双录
  215. eAudioOutPutType m_eAudioType;
  216. BOOL m_bIsAudioNsOn; //是否开启音频降噪功能开关
  217. int m_iNsPolicy; //音频降噪等级
  218. BOOL m_bIsAudioTransOn; //是否开始音频传输到识别服务器开关
  219. int m_nFps;
  220. /************************************************************************/
  221. int m_videoquality;
  222. SubtitleParam m_SubtitleParam;
  223. BOOL m_bWholeSection;
  224. BOOL m_bSessionManage;
  225. /************************************************************************/
  226. videoq_frame* videoframe;
  227. audio_frame* audioframe;
  228. Clibaudioqueue*m_audioqueue;
  229. Clibvideoqueue*m_videoqueue;
  230. Clibvideoqueue*m_videoqueue2;
  231. Clibvideoqueue*m_remotevideoqueue; //远端视频,用于双向录像
  232. Clibaudioqueue*m_remoteaudioqueue; //远端音频,用于双向录像
  233. Clibaudioqueue*m_localaudioqueue; //本地音频
  234. Clibaudioqueue*m_salesaudioqueue; //现场销售音频
  235. char m_audioqueuename[MAX_PATH];
  236. char m_videoqueuename[MAX_PATH];
  237. char m_videoqueue2name[MAX_PATH];
  238. char m_salesaudioqueuename[MAX_PATH];
  239. char m_remotevideoqueuename[MAX_PATH];
  240. char m_remoteaudioqueuename[MAX_PATH];
  241. pthread_t m_nRecordthreadId;
  242. char m_FileName[MAX_PATH];
  243. char m_PathName[MAX_PATH];
  244. char m_WmvFileName[MAX_PATH];
  245. //编码器
  246. CWmvHostApi* m_pHostApi;
  247. BOOL*m_bResult;
  248. //音频录制拼接BUFFER
  249. char*m_pAudioBufferTmp;
  250. //音频拼接的缓冲区大小;
  251. int m_iAudioBufferSize;
  252. //wmv recorder
  253. FFmpegWmvWriter*m_pWriter;
  254. //audio noise suppression
  255. IAudioNs *m_pAudioNsObj;
  256. SpeexResamplerState *m_16kto8kst;
  257. BOOL EndRecord()
  258. {
  259. if (!m_pWriter->End()){
  260. return FALSE;
  261. }
  262. if (m_pWriter){
  263. delete m_pWriter;
  264. m_pWriter = NULL;
  265. }
  266. if (videoframe->data){
  267. delete videoframe->data;
  268. videoframe->data = NULL;
  269. }
  270. if (m_pAudioBufferTmp!=NULL){
  271. delete m_pAudioBufferTmp;
  272. m_pAudioBufferTmp = NULL;
  273. m_iAudioBufferSize = 0;
  274. }
  275. if (m_localaudioqueue != NULL){
  276. delete m_localaudioqueue;
  277. m_localaudioqueue = NULL;
  278. }
  279. if (m_salesaudioqueue != NULL){
  280. delete m_salesaudioqueue;
  281. m_salesaudioqueue = NULL;
  282. }
  283. m_audioqueue = NULL;
  284. if (m_remoteaudioqueue != NULL){
  285. delete m_remoteaudioqueue;
  286. m_remoteaudioqueue = NULL;
  287. }
  288. if (m_videoqueue != NULL){
  289. delete m_videoqueue;
  290. m_videoqueue = NULL;
  291. }
  292. if (m_videoqueue2 != NULL){
  293. delete m_videoqueue2;
  294. m_videoqueue2 = NULL;
  295. }
  296. if (m_remotevideoqueue != NULL){
  297. delete m_remotevideoqueue;
  298. m_remotevideoqueue = NULL;
  299. }
  300. return TRUE;
  301. }
  302. void FSleep(int ms)
  303. {
  304. struct timespec ts;
  305. clock_gettime(CLOCK_REALTIME, &ts);
  306. long unsec = ts.tv_nsec + (1000 * 1000 * ms);
  307. ts.tv_sec += (unsec / 1000000000);
  308. ts.tv_nsec = (unsec % 1000000000);
  309. if (-1 == sem_timedwait(&m_semt, &ts)) {
  310. if (ETIMEDOUT == errno) {
  311. }
  312. }
  313. else {
  314. throw std::exception();
  315. }
  316. }
  317. static void __recordlog(void* user_data, const char* fmt, va_list arg)
  318. {
  319. libwmvrecord_impl* pRecord = (libwmvrecord_impl*)user_data;
  320. if (NULL != pRecord){
  321. CWmvHostApi* pHost = pRecord->GetHostApi();
  322. if (NULL != pHost){
  323. pHost->Debug(fmt, arg);
  324. }
  325. }
  326. }
  327. //开始录制视频
  328. BOOL StartRecord()
  329. {
  330. BOOL bRet = FALSE;
  331. m_pWriter = new FFmpegWmvWriter(this);
  332. if (m_bIsAudioNsOn){
  333. audions_callback_t t_callback = { 0 };
  334. t_callback.debug = &__recordlog;
  335. t_callback.user_data = this;
  336. m_pAudioNsObj = CreateIAudioNsObj(&t_callback);
  337. }
  338. if (0 == pthread_create(&m_nRecordthreadId, NULL, VideoRecordThread, (void*)this)) {
  339. bRet = TRUE;
  340. m_pHostApi->Debug("create video record thread and thread id is %u.", m_nRecordthreadId);
  341. }
  342. else {
  343. m_pHostApi->Debug("create video record thread failed.");
  344. }
  345. return bRet;
  346. }
  347. //获取指定队列的SIZE
  348. int GetVideoFrameSize(int&nWidth,int&nHeight,Clibvideoqueue*queue) //add by chh 20170320
  349. {
  350. int size = queue->GetFrameSize(nWidth,nHeight);
  351. return size;
  352. }
  353. int GetVideoFrameSizeNew(int&nWidth,int&nHeight)
  354. {
  355. int size = 0;
  356. if (m_videoqueue == NULL)
  357. {
  358. m_pHostApi->Debug("本地视频队列未初始化,不存在!");
  359. size = 0;
  360. }
  361. if((m_videoqueue2)&&(eSingleSide == m_eRecordType)) //大机的正常计算
  362. {
  363. int width1 = 0;
  364. int height1 = 0;
  365. int width2 = 0;
  366. int height2 = 0;
  367. size = m_videoqueue->GetFrameSize(width1,height1);
  368. //m_pHostApi->Debug("eSingleSide Record, video queue size: %d, width1: %d, height1: %d.", size, width1, height1);
  369. if (size)
  370. {
  371. (width1>height1)?(nWidth=nHeight=width1):(nWidth=nHeight=height1);
  372. }
  373. else
  374. {
  375. size = m_videoqueue2->GetFrameSize(width2,height2);
  376. (width2>height2)?(nWidth=nHeight=width2):(nWidth=nHeight=height2);
  377. //m_pHostApi->Debug("eSingleSide Record, videoqueue2 size: %d, width2: %d, height2: %d.", size, width2, height2);
  378. }
  379. if (!m_SubtitleParam.bSubtitle || !m_SubtitleParam.bSubtitleSection)
  380. {
  381. size = nWidth*nHeight*3;
  382. }
  383. else
  384. {
  385. nHeight += 50;
  386. size = nWidth*nHeight*3;
  387. }
  388. //m_pHostApi->Debug("eSingleSide Record, bSubtitle: %d, size: %d, nWidth: %d, nHeight: %d.", m_SubtitleParam.bSubtitle, size, nWidth, nHeight);
  389. }
  390. else
  391. {
  392. if (m_remotevideoqueue && eSingleSide != m_eRecordType) //如果远端队列不为空,且录制双向视频
  393. {
  394. //如果PAD版下录制双向视频,视频大小由远端视频决定,如果远端为320*240,则视频大小为640*240
  395. if (ePhone2Pad == m_eRecordType || ePad2Agent == m_eRecordType) //手机到pad,坐席到pad的双向录像
  396. {
  397. int width1 = 0;
  398. int height1 = 0;
  399. size = m_remotevideoqueue->GetFrameSize(width1,height1);
  400. nWidth = width1*2;
  401. nHeight = height1;
  402. size = nWidth*nHeight*3;
  403. //m_pHostApi->Debug("ePad2Agent Record, remotevideoqueue size: %d, nWidth: %d, nHeight: %d.", size, nWidth, nHeight);
  404. }
  405. else if (eStand2Agent == m_eRecordType) //大机以终端的视频大小确定画布,终端为640*360,远端固定为320*240,则画布为640*640+320*240 = 960*640
  406. {
  407. //计算画布左边部分的分辨率,640*640
  408. int width1 = 0;
  409. int height1 = 0;
  410. int width2 = 0;
  411. int height2 = 0;
  412. size = m_videoqueue->GetFrameSize(width1,height1);
  413. //m_pHostApi->Debug("eStand2Agent Record, videoqueue size: %d, width1: %d, height1: %d.", size, width1, height1);
  414. if (size)
  415. {
  416. (width1>height1)?(nWidth=nHeight=width1):(nWidth=nHeight=height1);
  417. }
  418. else
  419. {
  420. size = m_videoqueue2->GetFrameSize(width2,height2);
  421. (width2>height2)?(nWidth=nHeight=width2):(nWidth=nHeight=height2);
  422. //m_pHostApi->Debug("eStand2Agent Record, videoqueue2 size: %d, width2: %d, height2: %d.", size, width2, height2);
  423. }
  424. //远端视频320*240
  425. nWidth =nWidth+ 480;
  426. if (!m_SubtitleParam.bSubtitle || !m_SubtitleParam.bSubtitleSection)
  427. {
  428. size = nWidth*nHeight*3;
  429. }
  430. else
  431. {
  432. nHeight += 50;
  433. size = nWidth*nHeight*3;
  434. }
  435. //m_pHostApi->Debug("eStand2Agent Record, bSubtitle: %d, size: %d, nWidth: %d, nHeight: %d.", m_SubtitleParam.bSubtitle, size, nWidth, nHeight);
  436. }
  437. }
  438. else //录制单向视频
  439. {
  440. if (!m_SubtitleParam.bSubtitle || !m_SubtitleParam.bSubtitleSection)
  441. {
  442. size = m_videoqueue->GetFrameSize(nWidth,nHeight);
  443. }
  444. else
  445. {
  446. int width1 = 0;
  447. int height1 = 0;
  448. size = m_videoqueue->GetFrameSize(width1,height1);
  449. nWidth=width1;
  450. nHeight=height1+50;
  451. size = nWidth*nHeight*3;
  452. }
  453. //m_pHostApi->Debug("eSingleSide Record No Local videoqueue2, bSubtitle: %d, size: %d, nWidth: %d, nHeight: %d.",
  454. // m_SubtitleParam.bSubtitle, size, nWidth, nHeight);
  455. }
  456. }
  457. return size;
  458. }
  459. //从指定队列读取video
  460. BOOL GetVideoFrame(video_frame* Video,int flags,Clibvideoqueue*queue) //add by chh 20170320
  461. {
  462. return queue->GetVideo2(Video,flags);
  463. }
  464. // chh@2019/10/16 获取拼接后的视频帧
  465. BOOL GetVideoFrameNew(videoq_frame* Video, int flags,const bool bSwitchCam, int iInitCam)
  466. {
  467. if (m_videoqueue2 == NULL) //如果是单摄像头pad
  468. {
  469. if (m_remotevideoqueue && eSingleSide != m_eRecordType) //如果远端队列不为空,且录制双向视频
  470. {
  471. if (ePhone2Pad == m_eRecordType || ePad2Agent == m_eRecordType)
  472. {
  473. //拼接两个方向视频的BUF
  474. if (m_videoqueue != NULL)
  475. {
  476. //合成一个图像
  477. int w = 0,h = 0;
  478. int nsize = GetVideoFrameSize(w,h,m_videoqueue); // 获取本地视频帧大小
  479. memset(Video->data,0,Video->framesize); // 初始化拼接后视频帧数据
  480. video_frame tmp_frm = {0};
  481. tmp_frm.data[0] = new unsigned char[nsize];
  482. tmp_frm.linesize[0] = w*3;
  483. tmp_frm.format = videoframe->format;
  484. tmp_frm.width = w;
  485. tmp_frm.height = h;
  486. BOOL bGetLocalvideo = FALSE;
  487. bGetLocalvideo = GetVideoFrame(&tmp_frm,1,m_videoqueue); //获取本地视频的数组形式数据
  488. //m_pHostApi->Debug("%s mode have remote video queue, local video queue format: %d, width: %d, height: %d.",
  489. // record_type_table[m_eRecordType], tmp_frm.format, tmp_frm.width, tmp_frm.height);
  490. if (bGetLocalvideo)
  491. {
  492. //本地录像需要偏移量
  493. int nOffset = 0;
  494. if (Video->height > h)
  495. {
  496. nOffset = (Video->height-h)/2*Video->width*3;
  497. }
  498. //m_pHostApi->Debug("%s mode local video queue offset: %d, Video width: %d, Video height: %d, width: %d, height: %d.",
  499. // record_type_table[m_eRecordType], nOffset, Video->width, Video->height, w, h);
  500. for (int i= 0;i<tmp_frm.height && i<Video->height;i++)
  501. {
  502. memcpy(Video->data+nOffset+i*Video->width*3,tmp_frm.data[0]+i*tmp_frm.linesize[0],tmp_frm.linesize[0]);
  503. }
  504. }
  505. delete tmp_frm.data[0];
  506. nsize = GetVideoFrameSize(w,h,m_remotevideoqueue);
  507. tmp_frm.data[0] = new unsigned char[nsize];
  508. tmp_frm.linesize[0] = w*3;
  509. tmp_frm.format = videoframe->format;
  510. tmp_frm.width = w;
  511. tmp_frm.height = h;
  512. BOOL bGetRemotevideo = FALSE;
  513. bGetRemotevideo = GetVideoFrame(&tmp_frm,1,m_remotevideoqueue);
  514. //m_pHostApi->Debug("%s mode have remote video queue, remote video queue format: %d, width: %d, height: %d.",
  515. // record_type_table[m_eRecordType], tmp_frm.format, tmp_frm.width, tmp_frm.height);
  516. if (bGetRemotevideo)
  517. {
  518. for (int i= 0;i<tmp_frm.height&&i<Video->height;i++)
  519. {
  520. memcpy(Video->data+i*Video->width*3+tmp_frm.linesize[0],tmp_frm.data[0]+i*tmp_frm.linesize[0],tmp_frm.linesize[0]);
  521. }
  522. }
  523. delete tmp_frm.data[0];
  524. if (!bGetLocalvideo&&!bGetRemotevideo)
  525. {
  526. return FALSE;
  527. }
  528. }
  529. else
  530. {
  531. return FALSE;
  532. }
  533. }
  534. else
  535. {
  536. m_pHostApi->Debug("the device type cannot record both way video");
  537. }
  538. }
  539. else //录制单向视频
  540. {
  541. if (!m_SubtitleParam.bSubtitle || !m_SubtitleParam.bSubtitleSection)
  542. {
  543. bool result = m_videoqueue->GetVideo(Video,flags);
  544. //m_pHostApi->Debug("%s mode No bSubtitle, local video queue format: %d, width: %d, height: %d.",
  545. // record_type_table[m_eRecordType], Video->format, Video->width, Video->height);
  546. return result;
  547. }
  548. else
  549. {
  550. BOOL bRslt =FALSE;
  551. int width = 0;
  552. int height = 0;
  553. m_videoqueue->GetFrameSize(width,height);
  554. memset(Video->data,0,Video->framesize);
  555. videoq_frame*tmp_frm = new videoq_frame;
  556. //下移30
  557. tmp_frm->data = Video->data+ Video->width*30*3;
  558. //m_pHostApi->Debug("%s mode local video queue offset: %d, Video width: %d, width: %d, height: %d.",
  559. // record_type_table[m_eRecordType], Video->width * 30 * 3, Video->width, width, height);
  560. bRslt = m_videoqueue->GetVideo(tmp_frm, flags);
  561. //m_pHostApi->Debug("%s mode local video queue format: %d, width: %d, height: %d.",
  562. // record_type_table[m_eRecordType], tmp_frm->format, tmp_frm->width, tmp_frm->height);
  563. if (!bRslt)
  564. {
  565. delete tmp_frm;
  566. m_pHostApi->Debug("get env video fail!");
  567. return FALSE;
  568. }
  569. delete tmp_frm;
  570. }
  571. }
  572. }
  573. else //如果是双摄像头大机
  574. {
  575. if (m_remotevideoqueue && eStand2Agent == m_eRecordType) //如果远端队列不为空,且录制双向视频
  576. {
  577. //将大机摄像头和远端视频拼接到一张画布中
  578. memset(Video->data,0,Video->framesize);
  579. BOOL bRslt = FALSE;
  580. int width = 0;
  581. int height = 0;
  582. m_videoqueue->GetFrameSize(width,height);
  583. video_frame localtmp_frm = {0};
  584. localtmp_frm.data[0] = new unsigned char[640*640*3];
  585. localtmp_frm.linesize[0] = 640*3;
  586. localtmp_frm.format = videoframe->format;
  587. localtmp_frm.width = 640;
  588. localtmp_frm.height = 640;
  589. memset(localtmp_frm.data[0],0,640*640*3);
  590. int nActiveCam = iInitCam;
  591. if (bSwitchCam)
  592. {
  593. nActiveCam = m_pHostApi->GetActiveCamera();
  594. }
  595. if (nActiveCam == 0) // get env snapshot
  596. {
  597. videoq_frame*tmp_frm = new videoq_frame;
  598. //if (!m_SubtitleParam.bSubtitle || !m_SubtitleParam.bSubtitleSection)
  599. tmp_frm->data = localtmp_frm.data[0]+ width*(width-height)/2*3; //在画布中加上偏移量
  600. //m_pHostApi->Debug("%s mode local video queue offset: %d, width: %d, height: %d.",
  601. // record_type_table[m_eRecordType], width* (width - height) / 2 * 3, width, height);
  602. //横向摄像头拼接
  603. bRslt = m_videoqueue->GetVideo(tmp_frm, flags);
  604. //m_pHostApi->Debug("%s mode local video queue format: %d, width: %d, height: %d.",
  605. // record_type_table[m_eRecordType], tmp_frm->format, tmp_frm->width, tmp_frm->height);
  606. if (!bRslt)
  607. {
  608. delete tmp_frm;
  609. m_pHostApi->Debug("stand device both way video,get env video fail!");
  610. return FALSE;
  611. }
  612. delete tmp_frm;
  613. }
  614. else if (nActiveCam == 1) // get opt snapshot
  615. {
  616. videoq_frame*tmp_frm = new videoq_frame;
  617. tmp_frm->data = localtmp_frm.data[0] + (width-height)/2*3; //在画布中加上偏移量
  618. //m_pHostApi->Debug("%s mode local videoqueue2 offset: %d, width: %d, height: %d.",
  619. // record_type_table[m_eRecordType], (width - height) / 2 * 3, width, height);
  620. //竖向摄像头图像,拼接
  621. bRslt = m_videoqueue2->GetVideo3(tmp_frm, flags);
  622. //m_pHostApi->Debug("%s mode local videoqueue2 format: %d, width: %d, height: %d.",
  623. // record_type_table[m_eRecordType], tmp_frm->format, tmp_frm->width, tmp_frm->height);
  624. if (!bRslt)
  625. {
  626. delete tmp_frm;
  627. m_pHostApi->Debug("stand device both way video,get opt video fail!");
  628. return FALSE;
  629. }
  630. delete tmp_frm;
  631. }
  632. else
  633. {
  634. return FALSE;
  635. }
  636. {
  637. //本地录像需要偏移量s
  638. int nOffset = 0;
  639. if (!m_SubtitleParam.bSubtitle || !m_SubtitleParam.bSubtitleSection)
  640. {
  641. nOffset = 0;
  642. }
  643. else
  644. {
  645. //下移25
  646. nOffset = 25*Video->width*3;
  647. }
  648. int imaxheight = localtmp_frm.height > Video->height ? Video->height : localtmp_frm.height;
  649. if (0 == nActiveCam) {
  650. for (int i = imaxheight - 1, j = 0; i >= 0 && j < imaxheight; i--, j++)
  651. {
  652. memcpy(Video->data + nOffset + j * Video->width * 3, localtmp_frm.data[0] + i * localtmp_frm.linesize[0], localtmp_frm.linesize[0]);
  653. }
  654. }
  655. else {
  656. for (int i = 0; i < imaxheight; i++)
  657. {
  658. memcpy(Video->data + nOffset + i * Video->width * 3, localtmp_frm.data[0] + i * localtmp_frm.linesize[0], localtmp_frm.linesize[0]);
  659. }
  660. }
  661. }
  662. delete localtmp_frm.data[0];
  663. //拼接远端视频
  664. //合成一个图像
  665. {
  666. int w = 0,h = 0;
  667. int nsize = GetVideoFrameSize(w,h,m_remotevideoqueue);
  668. video_frame tmp_frm = {0};
  669. tmp_frm.data[0] = new unsigned char[nsize];
  670. tmp_frm.linesize[0] = w*3;
  671. tmp_frm.format = videoframe->format;
  672. tmp_frm.width = w;
  673. tmp_frm.height = h;
  674. BOOL bGetRemotevideo = FALSE;
  675. bGetRemotevideo = GetVideoFrame(&tmp_frm,1,m_remotevideoqueue);
  676. //m_pHostApi->Debug("%s mode remote video queue format: %d, width: %d, height: %d.",
  677. // record_type_table[m_eRecordType], tmp_frm.format, tmp_frm.width, tmp_frm.height);
  678. if (bGetRemotevideo)
  679. {
  680. int imaxheight = tmp_frm.height > Video->height ? Video->height : tmp_frm.height;
  681. for (int i = imaxheight - 1, j = 0; i >= 0 && j < imaxheight; i--, j++)
  682. {
  683. memcpy(Video->data+((Video->height-tmp_frm.height)/2+j)*Video->width*3+640*3,tmp_frm.data[0]+i*tmp_frm.linesize[0],tmp_frm.linesize[0]);
  684. }
  685. }
  686. delete tmp_frm.data[0];
  687. if (!bGetRemotevideo)
  688. {
  689. return FALSE;
  690. }
  691. }
  692. }
  693. else
  694. {
  695. BOOL bRslt =FALSE;
  696. int width = 0;
  697. int height = 0;
  698. m_videoqueue->GetFrameSize(width,height);
  699. memset(Video->data,0,Video->framesize);
  700. int nActiveCam = iInitCam;
  701. if (bSwitchCam)
  702. {
  703. nActiveCam = m_pHostApi->GetActiveCamera();
  704. }
  705. if (nActiveCam == 0) // get env snapshot
  706. {
  707. videoq_frame*tmp_frm = new videoq_frame;
  708. if (!m_SubtitleParam.bSubtitle || !m_SubtitleParam.bSubtitleSection)
  709. {
  710. tmp_frm->data = Video->data+ Video->width*(width-height)/2*3;
  711. //m_pHostApi->Debug("%s mode no remote video queue, no bSubtitle offset: %d, width: %d, height: %d.",
  712. // record_type_table[m_eRecordType], Video->width* (width - height) / 2 * 3, width, height);
  713. }
  714. else
  715. {
  716. tmp_frm->data = Video->data+ Video->width*((width-height)/2+30)*3;
  717. //m_pHostApi->Debug("%s mode no remote video queue, have bSubtitle offset: %d, width: %d, height: %d.",
  718. // record_type_table[m_eRecordType], Video->width* ((width - height) / 2 + 30) * 3, width, height);
  719. }
  720. bRslt = m_videoqueue->GetVideo(tmp_frm, flags);
  721. //m_pHostApi->Debug("%s mode no remote video queue, local video queue format: %d, width: %d, height: %d.",
  722. // record_type_table[m_eRecordType], tmp_frm->format, tmp_frm->width, tmp_frm->height);
  723. if (!bRslt)
  724. {
  725. delete tmp_frm;
  726. m_pHostApi->Debug("get env video fail!");
  727. return FALSE;
  728. }
  729. delete tmp_frm;
  730. }
  731. else if (nActiveCam == 1) // get opt snapshot
  732. {
  733. videoq_frame*tmp_frm = new videoq_frame;
  734. if (!m_SubtitleParam.bSubtitle || !m_SubtitleParam.bSubtitleSection)
  735. {
  736. tmp_frm->data = Video->data + (width-height)/2*3;
  737. //m_pHostApi->Debug("%s mode no remote video queue, no bSubtitle offset: %d, width: %d, height: %d.",
  738. // record_type_table[m_eRecordType], (width - height) / 2 * 3, width, height);
  739. }
  740. else
  741. {
  742. tmp_frm->data = Video->data + (Video->width*30+(width-height)/2)*3;
  743. //m_pHostApi->Debug("%s mode no remote video queue, have bSubtitle offset: %d, width: %d, height: %d.",
  744. // record_type_table[m_eRecordType], (Video->width * 30 + (width - height) / 2) * 3, width, height);
  745. }
  746. //横向摄像头图像,拼接
  747. bRslt = m_videoqueue2->GetVideo3(tmp_frm, flags);
  748. //m_pHostApi->Debug("%s mode no remote video queue, local videoqueue2 format: %d, width: %d, height: %d.",
  749. // record_type_table[m_eRecordType], tmp_frm->format, tmp_frm->width, tmp_frm->height);
  750. if (!bRslt)
  751. {
  752. delete tmp_frm;
  753. m_pHostApi->Debug("get opt video fail!");
  754. return FALSE;
  755. }
  756. delete tmp_frm;
  757. }
  758. else
  759. {
  760. return FALSE;
  761. }
  762. }
  763. }
  764. return TRUE;
  765. }
  766. BOOL ReNameFile(const char*file,const char*newfilename)
  767. {
  768. #ifdef RVC_OS_WIN
  769. if (!_access(file, 0))
  770. #else
  771. if (!access(file, F_OK))
  772. #endif //RVC_OS_WIN
  773. {
  774. if (!rename(file,newfilename))
  775. {
  776. return TRUE;
  777. }
  778. else
  779. {
  780. return FALSE;
  781. }
  782. }
  783. else
  784. {
  785. return FALSE;
  786. }
  787. }
  788. //混音
  789. void MixtureAudio(int buflens,char*localbuf,char*remotebuf)
  790. {
  791. for (int i =0;i<buflens-2;i+=2)
  792. {
  793. *(__int16*)(localbuf+i) = *(__int16*)(localbuf+i)
  794. +*(__int16*)(remotebuf+i)-((*(__int16*)(localbuf+i))*(*(__int16*)(remotebuf+i))>>0x10);
  795. if (*(__int16*)(localbuf+i) > 32767)
  796. {
  797. *(__int16*)(localbuf+i) = 32767;
  798. }
  799. else if (*(__int16*)(localbuf+i) < -32768)
  800. {
  801. *(__int16*)(localbuf+i) = -32768;
  802. }
  803. }
  804. return;
  805. }
  806. uint32_t BindPCMAudioData(uint32_t uBufferLen, char* pLocalAudios, uint32_t uLocalAudioLen, char* pRemoteAudios, uint32_t uRemoteAudioLen, uint32_t uBitDeepth, eStereoArrayType eType)
  807. {
  808. uint32_t uRet = 0;
  809. char* pBuffer = new char[uLocalAudioLen];
  810. memset(pBuffer, 0, uLocalAudioLen);
  811. if (NULL != pLocalAudios){
  812. memcpy(pBuffer, pLocalAudios, uLocalAudioLen);
  813. memset(pLocalAudios, 0, uBufferLen);
  814. }
  815. for (int i = 0; i < uLocalAudioLen/uBitDeepth; i++){
  816. if (eLocalLeft == eType){
  817. memcpy((uint32_t*)pLocalAudios + i, ((uint16_t*)(pBuffer))+i, uBitDeepth);
  818. uint16_t *pindex = (uint16_t*)((uint32_t*)pLocalAudios + i) + 1;
  819. memcpy(pindex, ((uint16_t*)(pRemoteAudios))+i, uBitDeepth);
  820. uRet += (2*uBitDeepth);
  821. }
  822. else{
  823. memcpy((uint32_t*)pLocalAudios + i, ((uint16_t*)(pRemoteAudios))+i, uBitDeepth);
  824. uint16_t *pindex = (uint16_t*)((uint32_t*)pLocalAudios + i) + 1;
  825. memcpy(pindex, ((uint16_t*)(pBuffer))+i, uBitDeepth);
  826. uRet += (2*uBitDeepth);
  827. }
  828. }
  829. if (NULL != pBuffer){
  830. delete []pBuffer;
  831. pBuffer = NULL;
  832. }
  833. return uRet;
  834. }
  835. size_t Get8KOutPutBitRate(int iChannels, eAudioOutPutType eType)
  836. {
  837. size_t uOutBitRate = 16*8;
  838. if (1 == iChannels){
  839. if (eUltraHD == eType){
  840. uOutBitRate = 1000*8;
  841. }
  842. else if (eHighDefinition == eType){
  843. uOutBitRate = 625*8;
  844. }
  845. else if (eStandardDefinition == eType){
  846. uOutBitRate = 16*8;
  847. }
  848. else{
  849. uOutBitRate = 128*1000;
  850. }
  851. }
  852. else{
  853. if (eStandardDefinition == eType){
  854. uOutBitRate = 16*8;
  855. }
  856. else if (eLowDefinition == eType){
  857. uOutBitRate = iChannels*128*1000;
  858. }
  859. else{
  860. uOutBitRate = 1500*8;
  861. }
  862. }
  863. return uOutBitRate;
  864. }
  865. size_t Get16KOutPutBitRate(int iChannels, eAudioOutPutType eType)
  866. {
  867. size_t uOutBitRate = 1000*8;
  868. if (1 == iChannels){
  869. if (eUltraHD == eType){
  870. uOutBitRate = 2000*8;
  871. }
  872. else if (eHighDefinition == eType){
  873. uOutBitRate = 1500*8;
  874. }
  875. else if(eStandardDefinition == eType){
  876. uOutBitRate = 1000*8;
  877. }
  878. else{
  879. uOutBitRate = 1000*256;
  880. }
  881. }
  882. else{
  883. if (eStandardDefinition == eType){
  884. uOutBitRate = 2000*8;
  885. }
  886. else{
  887. uOutBitRate = 2500*8;
  888. }
  889. }
  890. return uOutBitRate;
  891. }
  892. size_t Get32KOutPutBitRate(int iChannels, eAudioOutPutType eType)
  893. {
  894. size_t uOutBitRate = 1000*8;
  895. if (1 == iChannels){
  896. if (eUltraHD == eType){
  897. uOutBitRate = 2500*8;
  898. }
  899. else{
  900. uOutBitRate = 1000*8;
  901. }
  902. }
  903. else{
  904. if (eStandardDefinition == eType){
  905. uOutBitRate = 3000*8;
  906. }
  907. else{
  908. uOutBitRate = 6000*8;
  909. }
  910. }
  911. return uOutBitRate;
  912. }
  913. size_t Get44KOutPutBitRate(int iChannels, eAudioOutPutType eType)
  914. {
  915. size_t uOutBitRate = 2000*8;
  916. if (1 == iChannels){
  917. if (eUltraHD == eType){
  918. uOutBitRate = 6000*8;
  919. }
  920. else if(eHighDefinition == eType){
  921. uOutBitRate = 4000*8;
  922. }
  923. else{
  924. uOutBitRate = 2000*8;
  925. }
  926. }
  927. else{
  928. if (eStandardDefinition == eType){
  929. uOutBitRate = 10000*8;
  930. }
  931. else if (eHighDefinition == eType){
  932. uOutBitRate = 20000*8;
  933. }
  934. else{
  935. uOutBitRate = 40000*8;
  936. }
  937. }
  938. return uOutBitRate;
  939. }
  940. size_t GetAudioOutPutBitRate(int iInPutSamperate, int iChannels, eAudioOutPutType eType)
  941. {
  942. size_t uOutBitRate = 8000;
  943. switch (iInPutSamperate)
  944. {
  945. case 8000:
  946. uOutBitRate = Get8KOutPutBitRate(iChannels, eType);
  947. break;
  948. case 16000:
  949. uOutBitRate = Get16KOutPutBitRate(iChannels, eType);
  950. break;
  951. case 32000:
  952. uOutBitRate = Get32KOutPutBitRate(iChannels, eType);
  953. break;
  954. case 44100:
  955. uOutBitRate = Get44KOutPutBitRate(iChannels, eType);
  956. break;
  957. default:
  958. m_pHostApi->Debug("not support format, input sample rate is %d, channels number is %d.", iInPutSamperate, iChannels);
  959. break;
  960. }
  961. return uOutBitRate;
  962. }
  963. int VideoRecord()
  964. {
  965. BOOL bResult;
  966. BOOL bInitWmvParam = FALSE;
  967. m_bStopRecord = FALSE;
  968. DWORD nRecordTime = 0; //本段视频持续时间
  969. DWORD nTimeExpended = 0; //录制经过的时间
  970. DWORD nVideoNum = 0; //当前时间的视频数
  971. DWORD noldvideoNum = 0; //已经录制的视频数
  972. DWORD nAudioNum = 0; //当前时间的音频数
  973. DWORD noldAudioNum = 0; //已经录制的音频数
  974. DWORD nAudioFromQueNum = 0; //从音频队列中取出的音频数量
  975. DWORD nRecordStartTime = 0; //本段录像开始时间
  976. int WmvFileSerialNum = 0; //WMV文件的序列号
  977. int nAudioBufferLens = 0; //音频录制拼接BUFFER的当前长度
  978. int nRemoteAudioBufferLens = 0; //远端音频拼接BUFFER的当前长度
  979. int nAudioFrameSize = 0; //音频帧的大小
  980. int nVideoFrameSize = 0; //视频帧的大小
  981. int nWidth = 0;
  982. int nHeight = 0;
  983. int nPerSecBufferLens = 0; //每秒音频的长度
  984. int nAudioFps = 0; //音频频率
  985. int nRemoteAudioFps = 0; //远端音频频率
  986. int nRemoteAudioNum = 0; //远端音频数量
  987. char*pRemoteAudioBufTmp = NULL; //远端音频BUFFER
  988. // 添加字幕所需变量定义 add by ly
  989. //char subTitles[3][256];
  990. wchar_t timeSubtitle[MAX_PATH];
  991. const char *weekDict[] = {"日","一","二","三","四","五","六"};
  992. SYSTEMTIME st;
  993. DWORD nSubTitleTime = 0; //本段视频添加字幕耗时
  994. #ifdef RVC_OS_WIN
  995. string TtcDir = "C:\\Windows\\Fonts\\";
  996. #else
  997. //string TtcDir = "/usr/share/fonts/";
  998. string TtcDir = "./";
  999. #endif
  1000. string fontfile = "";
  1001. CvxText *pText = NULL;
  1002. bool bSwitchCam = true;
  1003. int nInitActiveCam = 0;
  1004. m_pHostApi->Debug("FindMatchedFile");
  1005. #ifdef RVC_OS_WIN
  1006. if (FindMatchedFile(TtcDir.c_str(),"msyh.",fontfile))
  1007. #else
  1008. if (FindMatchedFile(TtcDir.c_str(), "wryh.", fontfile))
  1009. #endif
  1010. {
  1011. m_pHostApi->Debug("Fontfile:%s", fontfile.c_str());
  1012. TtcDir += fontfile;
  1013. pText = new CvxText(m_pHostApi, TtcDir.c_str());
  1014. int type = 0;
  1015. CvScalar scalar = {16, 0.3, 0.2, 0}; //字体大小/空白比例/间隔比例/旋转角度
  1016. bool underline = false;
  1017. float diaphaneity = 1.0;
  1018. pText->setFont(&type, &scalar, &underline, &diaphaneity); //字体类型/size/下滑线/透明度
  1019. }
  1020. m_pHostApi->Debug("setFont success");
  1021. if (!pText)
  1022. {
  1023. if (m_SubtitleParam.bSubtitle)
  1024. {
  1025. m_pHostApi->Debug("Font is null, subtitles cannot be added!");
  1026. m_bStopRecord = TRUE;
  1027. m_pHostApi->OnRecordFailed();
  1028. }
  1029. }
  1030. int nVideoSizeFailedTimes = 0, nAudioSizeFailedTimes = 0; // add by ly 20160713
  1031. if (m_bWholeSection || !m_bSessionManage){
  1032. sprintf_s(m_WmvFileName,MAX_PATH,"%s%s_%d.wmv",m_PathName,m_FileName,WmvFileSerialNum);
  1033. }
  1034. else{
  1035. sprintf_s(m_WmvFileName,MAX_PATH,"%s%s_%d_end.wmv",m_PathName,m_FileName,WmvFileSerialNum);
  1036. }
  1037. m_pHostApi->Debug("m_WmvFileName = %s",m_WmvFileName);
  1038. m_bCloseVideo = FALSE;
  1039. m_bReNameVideo = FALSE;
  1040. while (!m_bStopRecord)
  1041. {
  1042. try
  1043. {
  1044. if (!bInitWmvParam)
  1045. {
  1046. //获取视频帧大小
  1047. if (nVideoFrameSize <= 0)
  1048. {
  1049. if (nVideoSizeFailedTimes >= 5000)
  1050. {
  1051. m_bStopRecord = TRUE;
  1052. m_pHostApi->OnRecordFailed(true);
  1053. continue;
  1054. }
  1055. m_pHostApi->Debug("Get Video FrameSize,record type is %s.",record_type_table[m_eRecordType]);
  1056. nVideoFrameSize = GetVideoFrameSizeNew(nWidth,nHeight);
  1057. if(nVideoFrameSize <= 0)
  1058. {
  1059. ++nVideoSizeFailedTimes;
  1060. m_pHostApi->Debug("nVideoFrameSize = 0");
  1061. FSleep(5);
  1062. continue;
  1063. }
  1064. }
  1065. //获取音频帧大小
  1066. if (nAudioFrameSize <= 0)
  1067. {
  1068. if (nAudioSizeFailedTimes >= 5000)
  1069. {
  1070. m_bStopRecord = TRUE;
  1071. m_pHostApi->OnRecordFailed(true);
  1072. continue;
  1073. }
  1074. nAudioFrameSize = m_audioqueue->GetFrameSize();
  1075. if (nAudioFrameSize <=0)
  1076. {
  1077. ++nAudioSizeFailedTimes;
  1078. //m_pHostApi->Debug("nAudioFrameSize = 0");
  1079. //nAudioFrameSize = m_remoteaudioqueue->GetFrameSize();
  1080. //m_pHostApi->Debug("use m_remoteaudioqueue audio frame size init audio frame size.");
  1081. FSleep(10);
  1082. continue;
  1083. }
  1084. //m_pHostApi->Debug("Local Audio Frame Size = %d", nAudioFrameSize);
  1085. }
  1086. //初始化视频buffer
  1087. if (videoframe->data == NULL)
  1088. {
  1089. videoframe->data = new unsigned char[nVideoFrameSize];
  1090. videoframe->framesize = nVideoFrameSize;
  1091. videoframe->height = nHeight;
  1092. videoframe->width = nWidth;
  1093. videoframe->format = VIDEO_FORMAT_RGB24;
  1094. }
  1095. //初始化WMV文件
  1096. audio_frame*audio = new audio_frame;
  1097. audio->data = new char[nAudioFrameSize];
  1098. if (!m_audioqueue->GetAudio(audio))
  1099. {
  1100. delete audio->data;
  1101. delete audio;
  1102. FSleep(5);
  1103. continue;
  1104. }
  1105. m_pHostApi->Debug("audio samplespersec=%d,framesize=%d,channels=%d,format=%d,bitspersample=%d,series number=%d.",audio->samplespersec,audio->framesize,audio->nchannels,audio->format, audio->bitspersample, audio->iseriesnumber);
  1106. //计算每秒音频的长度
  1107. nPerSecBufferLens = audio->samplespersec*audio->bitspersample/8;
  1108. m_iAudioBufferSize = nPerSecBufferLens;
  1109. m_pHostApi->Debug("nPerSecBufferLens=%d", nPerSecBufferLens);
  1110. //计算音频帧的帧频,
  1111. nAudioFps = nPerSecBufferLens/audio->framesize;
  1112. m_pHostApi->Debug("音频帧的帧频 nAudioFps=%d", nAudioFps);
  1113. if((m_audioqueue != NULL)&&((m_remoteaudioqueue != NULL)&& eSingleSide != m_eRecordType))
  1114. {
  1115. //计算远端音频包的封包频率,本地50个包,远端为手机端使用1秒100个音频包分包,远端为可视柜台坐席使用1秒50个包分包 ,新增渠道时需要检查此处
  1116. if(ePhone2Pad == m_eRecordType) //手机渠道的双向录像
  1117. {
  1118. nRemoteAudioFps = 100;
  1119. }
  1120. else if(ePad2Agent == m_eRecordType || eStand2Agent == m_eRecordType) //可视柜台渠道的双向录像,本地端和坐席端声音采用左右声道方式录制
  1121. {
  1122. nRemoteAudioFps = 50;
  1123. audio->nchannels = 2;
  1124. if (CAPTURE_CLOCK*2 == audio->samplespersec){
  1125. audio->samplespersec = CAPTURE_CLOCK;
  1126. nPerSecBufferLens = CAPTURE_CLOCK*audio->bitspersample/8;
  1127. }
  1128. m_iAudioBufferSize = nPerSecBufferLens*2;
  1129. }
  1130. else
  1131. {
  1132. nRemoteAudioFps = 0;
  1133. }
  1134. m_pHostApi->Debug("calc remote audio fps = %d",nRemoteAudioFps);
  1135. }
  1136. m_pHostApi->Debug("audio fps = %d, audio buffer size = %d.",nAudioFps, m_iAudioBufferSize);
  1137. //初始化音频buffer
  1138. if (m_pAudioBufferTmp == NULL){
  1139. m_pAudioBufferTmp = new char[m_iAudioBufferSize];
  1140. memset(m_pAudioBufferTmp, 0, m_iAudioBufferSize);
  1141. }
  1142. if (pRemoteAudioBufTmp == NULL){
  1143. pRemoteAudioBufTmp = new char[nPerSecBufferLens];
  1144. memset(pRemoteAudioBufTmp,0,nPerSecBufferLens);
  1145. }
  1146. size_t uOutPutBitRate = GetAudioOutPutBitRate(audio->samplespersec,audio->nchannels,m_eAudioType);
  1147. if (m_bIsAudioNsOn && NULL != m_pAudioNsObj){
  1148. if (m_pAudioNsObj->SetNsParams(audio->samplespersec, CAPTURE_FRAME_TIME, m_iNsPolicy)){
  1149. m_pHostApi->Debug("Ns audio set params failed!");
  1150. }
  1151. }
  1152. m_pHostApi->Debug("InitWmvWriter audio param samplespersec=%d,audioOutChannels=%d,audioOutBitRate=%d bps.",audio->samplespersec,audio->nchannels,uOutPutBitRate);
  1153. m_pHostApi->Debug("InitWmvWriter video param Width=%d,Height=%d,Fps=%d.", nWidth, nHeight, m_nFps);
  1154. bResult = m_pWriter->InitWmvWriter(m_WmvFileName,nWidth,nHeight,24,m_nFps,audio->samplespersec,
  1155. audio->nchannels,audio->bitspersample,6,m_videoquality,uOutPutBitRate, (int)m_eAudioType);
  1156. delete audio->data;
  1157. delete audio;
  1158. if(!bResult)
  1159. {
  1160. m_pHostApi->Debug("WMV初始化失败!");
  1161. *m_bResult = FALSE;
  1162. // add by ly at 20160729
  1163. m_bStopRecord = TRUE;
  1164. m_pHostApi->OnRecordFailed();
  1165. break;
  1166. }
  1167. //开始录像
  1168. bResult = m_pWriter->StartWrite();
  1169. if(!bResult)
  1170. {
  1171. m_pHostApi->Debug("开始录像失败!");
  1172. *m_bResult = FALSE;
  1173. // add by ly at 20160729
  1174. m_bStopRecord = TRUE;
  1175. m_pHostApi->OnRecordFailed();
  1176. break;
  1177. }
  1178. bInitWmvParam = TRUE;
  1179. //当第一次记录时删除当前音频只剩下1帧,使音视频数据能够同步
  1180. m_audioqueue->ClearAudioQueue();
  1181. nRecordStartTime = timeGetTime();//本段录像开始时间
  1182. continue;
  1183. }
  1184. //控制音视频的同步,精确控制录制频率,确保暂停足够时间
  1185. int sleeptime = 0;
  1186. nRecordTime = timeGetTime() - nRecordStartTime - nSubTitleTime;
  1187. //m_pHostApi->Debug("nRecordStartTime=%ld, nAudioFromQueNum=%ld, nRecordTime=%ld .", nRecordStartTime, nAudioFromQueNum, nRecordTime);
  1188. if(m_nFps<nAudioFps)
  1189. {
  1190. if((m_audioqueue != NULL)&&((m_remoteaudioqueue != NULL)&& eSingleSide != m_eRecordType))//如果双向混音,则sleeptime以远端为准
  1191. {
  1192. if ((nRemoteAudioFps!=0)&&(nRemoteAudioFps>nAudioFps))
  1193. {
  1194. sleeptime = (int)((nRemoteAudioNum+1)*1000/nRemoteAudioFps-nRecordTime);
  1195. }
  1196. else
  1197. {
  1198. sleeptime = (int)((nAudioFromQueNum+1)*1000/nAudioFps-nRecordTime);
  1199. }
  1200. }
  1201. else
  1202. {
  1203. sleeptime = (int)((nAudioFromQueNum+1)*1000/nAudioFps-nRecordTime);
  1204. }
  1205. }
  1206. else
  1207. {
  1208. sleeptime = (int)((noldvideoNum+1)*1000/m_nFps-nRecordTime);
  1209. }
  1210. if(sleeptime>=0)
  1211. {
  1212. FSleep(sleeptime);
  1213. }
  1214. //计算经过的时间,计算已经经过几帧时间y
  1215. nRecordTime = timeGetTime() - nRecordStartTime - nSubTitleTime;
  1216. nVideoNum = (DWORD)(((double) nRecordTime /1000.0 ) * (double)m_nFps);
  1217. //如果是第1帧,或者又经过了1帧的时间,则录制视频,对视频进行压缩
  1218. if (((nVideoNum==0)&&(noldvideoNum == 0))||(nVideoNum>noldvideoNum))
  1219. {
  1220. BOOL bVideoLens = (m_videoqueue2 == NULL)?(m_videoqueue->GetVideoLens()>0):((m_videoqueue->GetVideoLens()>0)||(m_videoqueue2->GetVideoLens()>0));
  1221. if (bVideoLens)
  1222. {
  1223. BOOL bGetvideo = FALSE;
  1224. //bGetvideo = GetVideoFrame(videoframe,1,bSalesRecord);
  1225. //获取拼接后的视频帧数据
  1226. if (eStand2Agent == m_eRecordType && bSwitchCam){ //大机双向录像,只做一次摄像头选择 add by clp 20191025
  1227. bSwitchCam = false;
  1228. nInitActiveCam = m_pHostApi->GetActiveCamera();
  1229. m_pHostApi->Debug("Stand2S Device Double Record local use %d CAMERA_TYPE_ENV[0] CAMERA_TYPE_OPT[1] Camera.", nInitActiveCam);
  1230. }
  1231. bGetvideo = GetVideoFrameNew(videoframe,1, bSwitchCam, nInitActiveCam);
  1232. if (!bGetvideo)
  1233. {
  1234. FSleep(2);
  1235. continue;
  1236. }
  1237. // 加入字幕
  1238. if (m_SubtitleParam.bSubtitle)
  1239. {
  1240. DWORD nStartTime = timeGetTime();
  1241. IplImage *pImg = cvCreateImage(cvSize(nWidth, nHeight), IPL_DEPTH_8U, 3);
  1242. memcpy(pImg->imageData, videoframe->data, nVideoFrameSize);
  1243. //cvFlip(pImg); // 先把图像翻转
  1244. if (strlen(m_SubtitleParam.topSubtitleData) <= 0)
  1245. {
  1246. if (m_SubtitleParam.bSubtitleSection)
  1247. {
  1248. GetLocalTimeRVC(st);
  1249. swprintf(timeSubtitle, MAX_PATH, L"%4d年%02d月%02d日 星期%s %02d:%02d:%02d",st.wYear,
  1250. st.wMonth,st.wDay,weekDict[st.wDayOfWeek],st.wHour,st.wMinute, st.wSecond);
  1251. }
  1252. else
  1253. {
  1254. GetLocalTimeRVC(st);
  1255. swprintf(timeSubtitle, MAX_PATH, L"%4d/%02d/%02d %02d:%02d:%02d",st.wYear,
  1256. st.wMonth,st.wDay,st.wHour,st.wMinute, st.wSecond);
  1257. }
  1258. pText->putText(pImg, timeSubtitle, cvPoint(10, 42));
  1259. }
  1260. else
  1261. {
  1262. pText->putText(pImg, m_SubtitleParam.topSubtitleData, cvPoint(10, 42));
  1263. }
  1264. if (wcslen(m_SubtitleParam.bottomSubtitleData1) > 0)
  1265. {
  1266. pText->putText(pImg, m_SubtitleParam.bottomSubtitleData1, cvPoint(10, pImg->height - 47));
  1267. }
  1268. if (wcslen(m_SubtitleParam.bottomSubtitleData2) > 0)
  1269. {
  1270. pText->putText(pImg, m_SubtitleParam.bottomSubtitleData2, cvPoint(10, pImg->height - 23));
  1271. }
  1272. //拼接后的右侧视频添加坐席信息
  1273. if (wcslen(m_SubtitleParam.strRightAgentInfo) > 0)
  1274. {
  1275. if (eStand2Agent == m_eRecordType){
  1276. pText->putText(pImg, m_SubtitleParam.strRightAgentInfo, cvPoint(10+640, pImg->height - 47));
  1277. }
  1278. else{
  1279. pText->putText(pImg, m_SubtitleParam.strRightAgentInfo, cvPoint(10+320, pImg->height - 47));
  1280. }
  1281. }
  1282. //cvFlip(pImg); // 添完字幕再翻转
  1283. memcpy(videoframe->data, pImg->imageData, nVideoFrameSize);
  1284. cvReleaseImage(&pImg);
  1285. nSubTitleTime += (timeGetTime()- nStartTime);
  1286. }
  1287. bResult = m_pWriter->ReceiveVideoData((BYTE*)videoframe->data,nVideoFrameSize);
  1288. if (!bResult)
  1289. {
  1290. m_pHostApi->Debug("视频流写入失败!");
  1291. *m_bResult = FALSE;
  1292. // add by ly at 20160729
  1293. m_bStopRecord = TRUE;
  1294. m_pHostApi->OnRecordFailed();
  1295. break;
  1296. }
  1297. noldvideoNum++;
  1298. }
  1299. }
  1300. //本地音频不为空,远端为空或者远端不为空,但不是双向则只录制本地音频
  1301. if((m_audioqueue != NULL)&&((m_remoteaudioqueue == NULL)||((m_remoteaudioqueue != NULL) && eSingleSide == m_eRecordType)))
  1302. {
  1303. //取音频数据,合并成1S的音频
  1304. int nAudioLens = m_audioqueue->GetAudioLens();
  1305. //m_pHostApi->Debug("AudioLens: %d!", nAudioLens);
  1306. if (nAudioLens>0)
  1307. {
  1308. if (nAudioBufferLens < nPerSecBufferLens)
  1309. {
  1310. //取出音频
  1311. audioframe->data = m_pAudioBufferTmp+nAudioBufferLens;
  1312. BOOL bGetAudio = FALSE;
  1313. if (nAudioLens < MAX_AUDIOQUEUE_LENS){
  1314. bGetAudio = m_audioqueue->GetAudioAndDel(audioframe);
  1315. }
  1316. else{
  1317. bGetAudio = m_audioqueue->GetAudio(audioframe);
  1318. }
  1319. //m_pHostApi->Debug("bGetAudio: %d!", bGetAudio);
  1320. if (bGetAudio){
  1321. if (m_bIsAudioNsOn && NULL != m_pAudioNsObj){
  1322. char pOutAudio[MAX_PATH*3] = {0};
  1323. int iRet = m_pAudioNsObj->NsProcess(pOutAudio,audioframe->framesize, audioframe->data, audioframe->framesize);
  1324. if (0 == iRet){
  1325. memset(m_pAudioBufferTmp+nAudioBufferLens, 0, audioframe->framesize);
  1326. memcpy(m_pAudioBufferTmp+nAudioBufferLens, pOutAudio, audioframe->framesize);
  1327. }
  1328. }
  1329. nAudioBufferLens+=audioframe->framesize;
  1330. //m_pHostApi->Debug("audio get samplespersec=%d,framesize=%d,channels=%d,format=%d,bitspersample=%d,series number=%d.",
  1331. // audioframe->samplespersec, audioframe->framesize, audioframe->nchannels, audioframe->format, audioframe->bitspersample, audioframe->iseriesnumber);
  1332. nAudioFromQueNum++;
  1333. if ((0 == nAudioFromQueNum%100) && 0 != audioframe->iseriesnumber){
  1334. //m_pHostApi->Debug("single side record current audio queue len is %d and audio series number is: %d.",nAudioLens, audioframe->iseriesnumber);
  1335. }
  1336. }
  1337. else{
  1338. //m_pHostApi->Debug("get audio from m_audioqueue failed.");
  1339. FSleep(2); //huchen add ,避免不停获取音频数据导致cpu占用高
  1340. }
  1341. }
  1342. }
  1343. else {
  1344. //m_pHostApi->Debug("get audio length from m_audioqueue failed.");
  1345. FSleep(2); //huchen add ,避免不停获取音频数据导致cpu占用高
  1346. }
  1347. }
  1348. else if((m_audioqueue != NULL)&&((m_remoteaudioqueue != NULL)&& eSingleSide != m_eRecordType)) //客户端坐席端混音
  1349. {
  1350. //取音频数据,合并成1S的音频
  1351. int nAudioLens = m_audioqueue->GetAudioLens();
  1352. int nRemoteAudioLens = m_remoteaudioqueue->GetAudioLens();
  1353. if((nAudioLens>0)&&(nRemoteAudioLens<=0)) //远端无数据不混音
  1354. {
  1355. if (nAudioBufferLens < nPerSecBufferLens)
  1356. { //取出音频
  1357. audioframe->data = m_pAudioBufferTmp+nAudioBufferLens;
  1358. BOOL bGetAudio = FALSE;
  1359. if (nAudioLens < MAX_AUDIOQUEUE_LENS){
  1360. bGetAudio = m_audioqueue->GetAudioAndDel(audioframe);
  1361. }
  1362. else{
  1363. bGetAudio = m_audioqueue->GetAudio(audioframe);
  1364. }
  1365. if (bGetAudio){
  1366. //if (m_bIsAudioNsOn && NULL != m_pAudioNsObj){
  1367. // char pOutAudio[MAX_PATH*3] = {0};
  1368. // int iRet = m_pAudioNsObj->NsProcess(pOutAudio,audioframe->framesize, audioframe->data, audioframe->framesize);
  1369. // if (0 == iRet){
  1370. // memset(m_pAudioBufferTmp+nAudioBufferLens, 0, audioframe->framesize);
  1371. // memcpy(m_pAudioBufferTmp+nAudioBufferLens, pOutAudio, audioframe->framesize);
  1372. // }
  1373. //}
  1374. nAudioBufferLens += audioframe->framesize;
  1375. nAudioFromQueNum++;
  1376. if ((0 == nAudioFromQueNum%100) && (0 != audioframe->iseriesnumber)){
  1377. //m_pHostApi->Debug("not single side record,but no remote audio data and current local audio queue len is %d, local audio series number is: %d.", nAudioLens, audioframe->iseriesnumber);
  1378. }
  1379. }
  1380. else{
  1381. //m_pHostApi->Debug("get audio from m_audioqueue failed.");
  1382. FSleep(2);
  1383. }
  1384. }
  1385. }
  1386. else if ((nAudioLens>0)&&(nRemoteAudioLens>0))//混音
  1387. {
  1388. if(nRemoteAudioBufferLens < nPerSecBufferLens) //收到的远端音频不够1秒
  1389. {
  1390. //取远端音频
  1391. BOOL bGetRemoteAudio = FALSE;
  1392. audio_frame*RemoteAudio = new audio_frame;
  1393. RemoteAudio->data = pRemoteAudioBufTmp+nRemoteAudioBufferLens;
  1394. if (nRemoteAudioLens < MAX_AUDIOQUEUE_LENS){
  1395. bGetRemoteAudio = m_remoteaudioqueue->GetAudioAndDel(RemoteAudio);
  1396. }
  1397. else{
  1398. bGetRemoteAudio = m_remoteaudioqueue->GetAudio(RemoteAudio);
  1399. }
  1400. if (bGetRemoteAudio){
  1401. //if (m_bIsAudioNsOn && NULL != m_pAudioNsObj){
  1402. // char pOutAudio[MAX_PATH*3] = {0};
  1403. // int iRet = m_pAudioNsObj->NsProcess(pOutAudio,RemoteAudio->framesize, RemoteAudio->data, RemoteAudio->framesize);
  1404. // if (0 == iRet){
  1405. // memset(pRemoteAudioBufTmp + nRemoteAudioBufferLens, 0, RemoteAudio->framesize);
  1406. // memcpy(pRemoteAudioBufTmp + nRemoteAudioBufferLens, pOutAudio, RemoteAudio->framesize);
  1407. // }
  1408. //}
  1409. nRemoteAudioBufferLens += RemoteAudio->framesize;
  1410. nRemoteAudioNum++;
  1411. }
  1412. else {
  1413. //m_pHostApi->Debug("get audio from m_remoteaudioqueue failed.");
  1414. FSleep(2);
  1415. }
  1416. delete RemoteAudio;
  1417. }
  1418. int ncurtime = timeGetTime() - nRecordStartTime - nSubTitleTime;
  1419. if(( nAudioBufferLens< nPerSecBufferLens)&&((ncurtime-nAudioFromQueNum*1000/nAudioFps)>=(1000/nAudioFps)))
  1420. {
  1421. //本地音频
  1422. audioframe->data = m_pAudioBufferTmp+nAudioBufferLens;
  1423. BOOL bGetAudio = FALSE;
  1424. if (nAudioLens < MAX_AUDIOQUEUE_LENS){
  1425. bGetAudio = m_audioqueue->GetAudioAndDel(audioframe);
  1426. }
  1427. else{
  1428. bGetAudio = m_audioqueue->GetAudio(audioframe);
  1429. }
  1430. if (bGetAudio){
  1431. if (CAPTURE_CLOCK == audioframe->samplespersec){
  1432. //if (m_bIsAudioNsOn && NULL != m_pAudioNsObj){
  1433. // char pOutAudio[MAX_PATH*3] = {0};
  1434. // int iRet = m_pAudioNsObj->NsProcess(pOutAudio,audioframe->framesize, audioframe->data, audioframe->framesize);
  1435. // if (0 == iRet){
  1436. // memset(m_pAudioBufferTmp + nAudioBufferLens, 0, audioframe->framesize);
  1437. // memcpy(m_pAudioBufferTmp + nAudioBufferLens, pOutAudio, audioframe->framesize);
  1438. // }
  1439. //}
  1440. nAudioBufferLens += audioframe->framesize;
  1441. }
  1442. else if(CAPTURE_CLOCK*2 == audioframe->samplespersec){
  1443. spx_uint32_t uInLen = audioframe->framesize;
  1444. spx_uint32_t uOutLen = 512;
  1445. spx_int16_t pOutAudio[512] = {0};
  1446. int iRet = speex_resampler_process_int(m_16kto8kst, 0, (spx_int16_t*)audioframe->data, &uInLen, pOutAudio, &uOutLen);
  1447. if (RESAMPLER_ERR_SUCCESS == iRet){
  1448. memset(m_pAudioBufferTmp+nAudioBufferLens, 0, audioframe->framesize);
  1449. memcpy(m_pAudioBufferTmp+nAudioBufferLens, pOutAudio, uOutLen);
  1450. nAudioBufferLens += uOutLen;
  1451. }
  1452. //m_pHostApi->Debug("16kto8k inLen is %d, outLen is %d.",audioframe->framesize, uOutLen);
  1453. }
  1454. else{
  1455. m_pHostApi->Debug("not support audio sample rate.");
  1456. m_pHostApi->OnRecordFailed();
  1457. }
  1458. nAudioFromQueNum++;
  1459. if ((0 == nAudioFromQueNum%100) && (0 != audioframe->iseriesnumber)){
  1460. //m_pHostApi->Debug("not single side record,and current local audio queue len is %d audio series number is: %d.",nAudioLens, audioframe->iseriesnumber);
  1461. }
  1462. }
  1463. else{
  1464. //m_pHostApi->Debug("get audio from m_audioqueue failed.");
  1465. FSleep(2);
  1466. }
  1467. }
  1468. //混音
  1469. if ((nRemoteAudioBufferLens==nPerSecBufferLens)&&(nAudioBufferLens == nPerSecBufferLens))
  1470. {
  1471. if(ePhone2Pad == m_eRecordType){
  1472. MixtureAudio(nAudioBufferLens,m_pAudioBufferTmp,pRemoteAudioBufTmp);
  1473. }
  1474. else{//可视远程双录场景,本地和坐席端分别录制到左右声道
  1475. uint32_t uOutlen = BindPCMAudioData(m_iAudioBufferSize, m_pAudioBufferTmp, nAudioBufferLens, pRemoteAudioBufTmp, nRemoteAudioBufferLens, audioframe->bitspersample/8, eLocalLeft);
  1476. //m_pHostApi->Debug("double channel buffer length is %d, local buffer len is %d, remote buffer len is %d.",m_iAudioBufferSize, nAudioBufferLens, nRemoteAudioBufferLens);
  1477. nAudioBufferLens = uOutlen;
  1478. }
  1479. }
  1480. }
  1481. else if((nAudioLens<=0)&&(nRemoteAudioLens>0)) //本地端无数据不混音,双录语音播报场景 add by clp 20191104
  1482. {
  1483. if (nAudioBufferLens < nPerSecBufferLens)
  1484. { //取出音频
  1485. audioframe->data = m_pAudioBufferTmp+nAudioBufferLens;
  1486. BOOL bGetAudio = FALSE;
  1487. if (nAudioLens < MAX_AUDIOQUEUE_LENS)
  1488. {
  1489. bGetAudio = m_remoteaudioqueue->GetAudioAndDel(audioframe);
  1490. }
  1491. else
  1492. {
  1493. bGetAudio = m_remoteaudioqueue->GetAudio(audioframe);
  1494. }
  1495. if (bGetAudio)
  1496. {
  1497. nAudioBufferLens+=audioframe->framesize;
  1498. nAudioFromQueNum++;
  1499. }
  1500. else {
  1501. //m_pHostApi->Debug("get audio from m_remoteaudioqueue failed.");
  1502. FSleep(2);
  1503. }
  1504. }
  1505. }
  1506. else {
  1507. //m_pHostApi->Debug("get audio length from m_remoteaudioqueue and m_audioqueue failed.");
  1508. FSleep(2);
  1509. }
  1510. }
  1511. //录制音频
  1512. //计算经过的时间,计算已经经过几帧时间
  1513. nRecordTime = timeGetTime() - nRecordStartTime - nSubTitleTime;
  1514. nAudioNum = (DWORD)((double) nRecordTime /1000.0 );
  1515. if ((nAudioNum > noldAudioNum)/*&&(noldvideoNum >= (m_nFps*(noldAudioNum+1)))*/&&(nAudioBufferLens >= nPerSecBufferLens))
  1516. {
  1517. if (m_pWriter->ReceiveAudioData((BYTE*)m_pAudioBufferTmp,nAudioBufferLens))
  1518. {
  1519. noldAudioNum++;
  1520. nAudioBufferLens = 0;
  1521. nRemoteAudioBufferLens = 0;
  1522. memset(m_pAudioBufferTmp,0,m_iAudioBufferSize);
  1523. memset(pRemoteAudioBufTmp,0,nPerSecBufferLens);
  1524. }
  1525. else
  1526. {
  1527. m_pHostApi->Debug("音频流写入失败!");
  1528. *m_bResult = FALSE;
  1529. // add by ly at 20160729
  1530. m_bStopRecord = TRUE;
  1531. m_pHostApi->OnRecordFailed();
  1532. break;
  1533. }
  1534. }
  1535. //计算文件大小,如果文件大小大于10分钟则建立新文件记录
  1536. nRecordTime = timeGetTime() - nRecordStartTime - nSubTitleTime;
  1537. if (!m_bWholeSection)
  1538. {
  1539. if((nRecordTime > WMVREC_MAX_FILE)||((m_bCloseVideo||m_bReNameVideo)&&m_bSessionManage))
  1540. {
  1541. m_pWriter->End();
  1542. m_pHostApi->OnASectionFinished(m_WmvFileName); // add by ly at 2017/03/25
  1543. m_bStopRecord = FALSE;
  1544. bInitWmvParam = FALSE;
  1545. nRecordTime = 0; //本段视频持续时间
  1546. nRecordStartTime = timeGetTime(); //本段录像开始时间
  1547. nTimeExpended = 0; //录制经过的时间
  1548. nVideoNum = 0; //当前时间的视频数
  1549. noldvideoNum = 0; //已经录制的视频数
  1550. nAudioNum = 0; //当前时间的音频数
  1551. noldAudioNum = 0; //已经录制的音频数
  1552. nAudioFromQueNum = 0; //从音频队列中取出的音频数量
  1553. nAudioBufferLens = 0; //音频录制拼接BUFFER的当前长度
  1554. nRemoteAudioBufferLens = 0; //远端音频拼接BUFFER的当前长度
  1555. nRemoteAudioNum=0; //远端音频数量
  1556. nSubTitleTime = 0; //本段视频添加字幕耗时
  1557. memset(videoframe->data,0,nVideoFrameSize);
  1558. memset(m_pAudioBufferTmp,0,m_iAudioBufferSize);
  1559. memset(pRemoteAudioBufTmp,0,nPerSecBufferLens);
  1560. if (m_bSessionManage)
  1561. {
  1562. //sessionid切换,重命名录像文件
  1563. if (m_bReNameVideo)
  1564. {
  1565. if (WmvFileSerialNum>0)//如果当前文件序号大于0,说明前一个文件与当前文件是同一个SESSION,需要修改前一个文件名+END,否则直接改当前文件的文件名
  1566. {
  1567. //sessionid切换,前一个文件需要加上END
  1568. char m_NewFileName[MAX_PATH];
  1569. char m_OldFileName[MAX_PATH];
  1570. string FileName(m_WmvFileName);
  1571. string name = FileName.substr(0,FileName.find_first_of('_')+1);
  1572. //m_pHostApi->Debug("renamefile1 name = %s",name.c_str());
  1573. //前一个文件名
  1574. sprintf_s(m_OldFileName,MAX_PATH,"%s%d.wmv",name.c_str(),WmvFileSerialNum-1);
  1575. sprintf_s(m_NewFileName,MAX_PATH,"%s%d_end.wmv",name.c_str(),WmvFileSerialNum-1);
  1576. m_pHostApi->Debug("renamefile1 from %s to %s",m_OldFileName,m_NewFileName);
  1577. ReNameFile(m_OldFileName,m_NewFileName);
  1578. }
  1579. //sessionid切换,当前文件需要重命名
  1580. char m_NewFileName[MAX_PATH];
  1581. WmvFileSerialNum = 0;
  1582. sprintf_s(m_NewFileName,MAX_PATH,"%s%s_%d.wmv",m_PathName,m_FileName,WmvFileSerialNum);
  1583. m_pHostApi->Debug("renamefile2 from %s to %s",m_WmvFileName,m_NewFileName);
  1584. if (ReNameFile(m_WmvFileName,m_NewFileName))
  1585. {
  1586. WmvFileSerialNum++;
  1587. }
  1588. m_bReNameVideo = FALSE;
  1589. }
  1590. else
  1591. {
  1592. //继续录像,删除当前文件的"END"
  1593. char m_NewFileName[MAX_PATH];
  1594. sprintf_s(m_NewFileName,MAX_PATH,"%s%s_%d.wmv",m_PathName,m_FileName,WmvFileSerialNum);
  1595. m_pHostApi->Debug("renamefile3 from %s to %s",m_WmvFileName,m_NewFileName);
  1596. ReNameFile(m_WmvFileName,m_NewFileName);
  1597. //WMV文件的序列号
  1598. WmvFileSerialNum++;
  1599. }
  1600. //新文件增加END
  1601. sprintf_s(m_WmvFileName,MAX_PATH,"%s%s_%d_end.wmv",m_PathName,m_FileName,WmvFileSerialNum);
  1602. m_pHostApi->Debug("generate new file name %s",m_WmvFileName);
  1603. m_bCloseVideo = FALSE;
  1604. }
  1605. else
  1606. {
  1607. //WMV文件的序列号
  1608. WmvFileSerialNum++;
  1609. sprintf_s(m_WmvFileName,MAX_PATH,"%s%s_%d.wmv",m_PathName,m_FileName,WmvFileSerialNum);
  1610. }
  1611. }
  1612. }
  1613. }
  1614. catch (...)
  1615. {
  1616. m_pHostApi->Debug("IPP copy error or stop record.");
  1617. Sleep(50);
  1618. continue;
  1619. }
  1620. }
  1621. if (pRemoteAudioBufTmp){
  1622. delete pRemoteAudioBufTmp;
  1623. pRemoteAudioBufTmp = NULL;
  1624. }
  1625. m_pHostApi->OnRecordFinished();
  1626. EndRecord();
  1627. if (pText)
  1628. {
  1629. delete pText;
  1630. pText = NULL;
  1631. }
  1632. return 0;
  1633. }
  1634. #ifdef RVC_OS_WIN
  1635. // 寻找某目录下与通配符匹配的文件 add by ly at 20170215
  1636. BOOL FindMatchedFile(LPCSTR sFindPath, LPCSTR sFindFileName, std::string &sMatchedFile)
  1637. {
  1638. char sPath[MAX_PATH];
  1639. memset(sPath, 0, MAX_PATH);
  1640. char sFormatFileName[MAX_PATH+2] = "*";
  1641. WIN32_FIND_DATA FindFileData;
  1642. HANDLE hFind;
  1643. strcpy(sFormatFileName, sFindPath);
  1644. if(sFindPath[strlen(sFindPath)-1] != SPLIT_SLASH)
  1645. {
  1646. strcat(sFormatFileName, SPLIT_SLASH_STR);
  1647. strcat(sFormatFileName, "*");
  1648. }
  1649. else
  1650. {
  1651. strcat(sFormatFileName, "*");
  1652. }
  1653. strcat(sFormatFileName, sFindFileName);
  1654. strcat(sFormatFileName, "*");
  1655. hFind = FindFirstFile(sFormatFileName, &FindFileData);
  1656. if (hFind == INVALID_HANDLE_VALUE)
  1657. {
  1658. sMatchedFile = "";
  1659. return FALSE;
  1660. }
  1661. else
  1662. {
  1663. sMatchedFile = FindFileData.cFileName;
  1664. FindClose(hFind);
  1665. }
  1666. return TRUE;
  1667. }
  1668. #else
  1669. BOOL FindMatchedFile(LPCSTR sFindPath, LPCSTR sFindFileName, std::string& sMatchedFile)
  1670. {
  1671. DIR* pDir = NULL;
  1672. struct dirent* pFile = NULL;
  1673. BOOL result = false;
  1674. pDir = opendir(sFindPath);
  1675. if (pDir == NULL) return result;
  1676. while ((pFile = readdir(pDir)) != NULL) {
  1677. if (pFile->d_type & DT_DIR) {
  1678. //m_pHostApi->Debug("FindMatchedFile DIR name: %s.", pFile->d_name);
  1679. if (strcmp(pFile->d_name, ".") == 0
  1680. || strcmp(pFile->d_name, "..") == 0) continue;
  1681. char Path[256] = {0};
  1682. int len = strlen(sFindPath);
  1683. strncpy(Path, sFindPath, len + 1);
  1684. if (sFindPath[len - 1] != '/') strncat(Path, "/", 2);
  1685. strncat(Path, pFile->d_name, strlen(pFile->d_name) + 1);
  1686. //m_pHostApi->Debug("FindMatchedFile Path: %s.", Path);
  1687. result = FindMatchedFile(Path, sFindFileName, sMatchedFile);
  1688. if (result) {
  1689. break;
  1690. }
  1691. }
  1692. else {
  1693. //m_pHostApi->Debug("FindMatchedFile FILE name: %s.", pFile->d_name);
  1694. if (strstr(pFile->d_name, sFindFileName) != NULL) {
  1695. char Path[256];
  1696. int len = strlen(sFindPath);
  1697. strncpy(Path, sFindPath, len + 1);
  1698. if (sFindPath[len - 1] != '/') strncat(Path, "/", 2);
  1699. strncat(Path, pFile->d_name, strlen(pFile->d_name) + 1);
  1700. //m_pHostApi->Debug("FindMatchedFile Finded: %s.", Path);
  1701. sMatchedFile = Path;
  1702. result = true;
  1703. break;
  1704. }
  1705. }
  1706. }
  1707. closedir(pDir);
  1708. return result;
  1709. }
  1710. #endif
  1711. #ifdef RVC_OS_WIN
  1712. static void DeleteDumpFiles()
  1713. {
  1714. CSimpleStringA sourPath = ".\\";
  1715. if (sourPath.GetLength() > 0 && sourPath[sourPath.GetLength()-1] != '\\') {
  1716. sourPath += "\\";
  1717. }
  1718. char srcFilePath[MAX_PATH]={0};
  1719. WIN32_FIND_DATA FindFileData;
  1720. HANDLE hFind;
  1721. BOOL fFinished = FALSE;
  1722. sprintf_s(srcFilePath, MAX_PATH, "%s*.dmp", sourPath);
  1723. hFind = FindFirstFile(srcFilePath, &FindFileData);
  1724. if (INVALID_HANDLE_VALUE != hFind)
  1725. {
  1726. while (!fFinished)
  1727. {
  1728. if (FILE_ATTRIBUTE_DIRECTORY & FindFileData.dwFileAttributes)
  1729. {
  1730. continue;
  1731. }
  1732. CSimpleStringA sourFileName = CSimpleStringA::Format("%s%s", (LPCSTR)sourPath, FindFileData.cFileName);
  1733. if(!DeleteFile((LPCSTR)sourFileName)) {
  1734. Dbg("Error Code %lu while delete %s ", GetLastError(), (LPCSTR)sourFileName);
  1735. }
  1736. else{
  1737. Dbg("Delete file %s success.", (LPCSTR)sourFileName);
  1738. }
  1739. if (!FindNextFile(hFind, &FindFileData))
  1740. {
  1741. if (GetLastError() == ERROR_NO_MORE_FILES)
  1742. {
  1743. fFinished = TRUE;
  1744. }
  1745. else
  1746. {
  1747. break;
  1748. }
  1749. }
  1750. }
  1751. FindClose(hFind);
  1752. }
  1753. }
  1754. static void wmvrecorddump_exception(PEXCEPTION_POINTERS ExceptionInfo, libwmvrecord_impl* pWmvRecord)
  1755. {
  1756. if (NULL != pWmvRecord){
  1757. pWmvRecord->EndRecord();
  1758. if (NULL != pWmvRecord->m_pHostApi){
  1759. pWmvRecord->m_pHostApi->Debug("VideoRecord Thread Exception.");
  1760. pWmvRecord->m_pHostApi->OnRecordEntityExcption();
  1761. }
  1762. }
  1763. DeleteDumpFiles();
  1764. char tmp[MAX_PATH] = {0};
  1765. HANDLE hDumpFile;
  1766. sprintf(tmp, ".\\wmvrecord_%d.dmp", GetCurrentProcessId());
  1767. hDumpFile = CreateFileA( tmp, GENERIC_READ | GENERIC_WRITE,
  1768. 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
  1769. if( ( hDumpFile != NULL ) && ( hDumpFile != INVALID_HANDLE_VALUE ) )
  1770. {
  1771. MINIDUMP_EXCEPTION_INFORMATION mdei;
  1772. MINIDUMP_TYPE mdt;
  1773. mdei.ThreadId = GetCurrentThreadId();
  1774. mdei.ExceptionPointers = ExceptionInfo;
  1775. mdei.ClientPointers = FALSE;
  1776. mdt = MiniDumpWithFullMemory;
  1777. MiniDumpWriteDump( GetCurrentProcess(), GetCurrentProcessId(),
  1778. hDumpFile, mdt, (ExceptionInfo != 0) ? &mdei : 0, 0, 0 );
  1779. CloseHandle( hDumpFile );
  1780. }
  1781. }
  1782. #endif
  1783. //视频录制线程
  1784. static void* VideoRecordThread(void* pParam)
  1785. {
  1786. libwmvrecord_impl* WmvRecord = (libwmvrecord_impl*)pParam;
  1787. int iRet = -1;
  1788. #ifdef _WIN32
  1789. __try
  1790. {
  1791. iRet = WmvRecord->VideoRecord();
  1792. }
  1793. __except(wmvrecorddump_exception(GetExceptionInformation(),WmvRecord), EXCEPTION_EXECUTE_HANDLER) {
  1794. }
  1795. #else
  1796. iRet = WmvRecord->VideoRecord();
  1797. #endif
  1798. return &iRet;
  1799. }
  1800. public:
  1801. BOOL StartWmvRecord(int fps,int videoquality,const SubtitleParam *subtitleParam,BOOL bWholeSection,
  1802. BOOL bSessionManage,const char *pathname,int pathlength,const char *wmvfilename,int filenamelength, Rvc_RecordAudioParam_t* pAudioParam)//开始记录
  1803. {
  1804. m_audioqueue = NULL;
  1805. m_localaudioqueue = new Clibaudioqueue((char *)m_audioqueuename);
  1806. m_salesaudioqueue = NULL;
  1807. if (strlen(m_salesaudioqueuename) != 0){
  1808. m_salesaudioqueue = new Clibaudioqueue((char*)m_salesaudioqueuename);
  1809. }
  1810. m_videoqueue = NULL;
  1811. if (strlen(m_videoqueuename) != 0){
  1812. m_videoqueue = new Clibvideoqueue((char*)m_videoqueuename);
  1813. }
  1814. m_videoqueue2 = NULL;
  1815. if (strlen(m_videoqueue2name) != 0){
  1816. m_videoqueue2 = new Clibvideoqueue((char*)m_videoqueue2name);
  1817. }
  1818. m_remotevideoqueue = NULL;
  1819. if (strlen(m_remotevideoqueuename) != 0){
  1820. m_remotevideoqueue = new Clibvideoqueue((char*)m_remotevideoqueuename);
  1821. }
  1822. m_remoteaudioqueue = NULL;
  1823. if (strlen(m_remoteaudioqueuename) != 0){
  1824. m_remoteaudioqueue = new Clibaudioqueue((char*)m_remoteaudioqueuename);
  1825. }
  1826. memset(m_FileName,0,MAX_PATH);
  1827. memset(m_PathName,0,MAX_PATH);
  1828. if (filenamelength == 0){
  1829. SYSTEMTIME nowTime; // 系统时间结构体
  1830. GetLocalTimeRVC(nowTime);
  1831. sprintf_s(m_FileName,MAX_PATH,"%4d%02d%02d%02d%02d%02d",nowTime.wYear,nowTime.wMonth,nowTime.wDay,nowTime.wHour,nowTime.wMinute,nowTime.wSecond);
  1832. }
  1833. else{
  1834. memcpy(m_FileName,wmvfilename,filenamelength);
  1835. }
  1836. if (pathlength!=0){
  1837. memcpy(m_PathName,pathname,pathlength);
  1838. }
  1839. m_nFps = fps;
  1840. if (videoquality > 0 || videoquality <= 100){
  1841. m_videoquality = videoquality;
  1842. }
  1843. else{
  1844. m_pHostApi->Debug("warn: videoquality is illegal, will use default instead!");
  1845. m_videoquality = 75;
  1846. }
  1847. memset(&m_SubtitleParam, 0, sizeof(SubtitleParam));
  1848. if(subtitleParam != NULL) // 接收字幕信息
  1849. {
  1850. memcpy(&m_SubtitleParam, subtitleParam, sizeof(SubtitleParam));
  1851. }
  1852. m_bWholeSection = bWholeSection;
  1853. m_bSessionManage = bSessionManage;
  1854. m_eRecordType = pAudioParam->eRecordType;
  1855. m_eAudioType = pAudioParam->eOutPutType;
  1856. m_bIsAudioNsOn = pAudioParam->bIsNsOn;
  1857. m_iNsPolicy = pAudioParam->iNsPolicy;
  1858. m_bIsAudioTransOn = pAudioParam->bIsTransOn;
  1859. m_audioqueue = m_localaudioqueue;
  1860. if (m_salesaudioqueue && (eSingleSide == m_eRecordType || eStand2Agent == m_eRecordType)) //当大机进行双录拼接时使用本地音频队列会出现抢占导致取音频失败,此处选择使用销售音频队列
  1861. {
  1862. m_audioqueue = m_salesaudioqueue;
  1863. }
  1864. m_pHostApi->Debug("record output audio quality type is = %s, noise suppression flag is %s, noise suppression policy is %d, audio transfer flag is %s.", audio_quality_type_table[m_eAudioType], m_bIsAudioNsOn ? "true":"false", m_iNsPolicy, m_bIsAudioTransOn ? "true":"false");
  1865. if (0 != m_nRecordthreadId){
  1866. StopWmvRecord();
  1867. }
  1868. return StartRecord();
  1869. }
  1870. BOOL StopWmvRecord() //退出
  1871. {
  1872. m_bStopRecord = TRUE;
  1873. sem_post(&m_semt);
  1874. if (0 == pthread_join(m_nRecordthreadId, NULL)) {
  1875. m_pHostApi->Debug("thread join video record thread %u success!", m_nRecordthreadId);
  1876. m_nRecordthreadId = 0;
  1877. }
  1878. else {
  1879. m_pHostApi->Debug("thread join video record thread failed!");
  1880. }
  1881. return TRUE;
  1882. }
  1883. void ChangeFilename(const char*newfilename)
  1884. {
  1885. if (!m_bWholeSection)
  1886. {
  1887. memset(m_FileName,0,MAX_PATH);
  1888. memcpy(m_FileName,newfilename,strlen(newfilename));
  1889. m_bReNameVideo = TRUE;
  1890. }
  1891. }
  1892. BOOL setRightWaterMark(wchar_t* strWaterMark, size_t ulen)
  1893. {
  1894. BOOL bRet = FALSE;
  1895. memset(m_SubtitleParam.strRightAgentInfo,0,MAX_PATH);
  1896. if (ulen < MAX_PATH){
  1897. memcpy(m_SubtitleParam.strRightAgentInfo,strWaterMark,ulen);
  1898. bRet = TRUE;
  1899. }
  1900. return bRet;
  1901. }
  1902. BOOL StopAudioStreamEnTransQueue() //停止音频包入传输队列
  1903. {
  1904. m_bIsAudioTransOn = false;
  1905. return TRUE;
  1906. }
  1907. void Debug(const char* fmt, ...)
  1908. {
  1909. va_list arg;
  1910. va_start(arg, fmt);
  1911. char buf[512];
  1912. int n = _vscprintf(fmt, arg);
  1913. if (n+1 > 512)
  1914. n = 511;
  1915. vsnprintf(buf, n+1, fmt, arg);
  1916. m_pHostApi->Debug(buf);
  1917. va_end(arg);
  1918. }
  1919. BOOL m_bCloseVideo; //是否关闭当前录像
  1920. BOOL m_bReNameVideo; //是否重命名录像文件
  1921. };
  1922. // 这是已导出类的构造函数。
  1923. // 有关类定义的信息,请参阅 libwmvrecord.h
  1924. Clibwmvrecord::Clibwmvrecord(BOOL *pResult, CWmvHostApi *pHostAPI,LPCTSTR audioqueuename,LPCTSTR videoqueuename,LPCTSTR videoqueue2name,LPCTSTR salesaudioqueuename,LPCTSTR remotevideoqueuename,LPCTSTR remoteaudioqueuename)
  1925. {
  1926. m_pImpl = new libwmvrecord_impl(pResult,pHostAPI,audioqueuename,videoqueuename,videoqueue2name,salesaudioqueuename,remotevideoqueuename,remoteaudioqueuename);
  1927. return;
  1928. }
  1929. Clibwmvrecord::~Clibwmvrecord()
  1930. {
  1931. delete m_pImpl;
  1932. return;
  1933. }
  1934. BOOL Clibwmvrecord::StartWmvRecord(
  1935. int fps,
  1936. int videoquality,
  1937. Rvc_RecordAudioParam_t* pAudioParam,
  1938. SubtitleParam *subtitleParam /* = NULL */,
  1939. BOOL bWholeSection /* = FALSE */,
  1940. BOOL bSessionManage /* = FALSE */,
  1941. const char *pathname /* = NULL */,
  1942. int pathlength /* = 0 */,
  1943. const char *wmvfilename /* = NULL */,
  1944. int filenamelength /* = 0 */
  1945. )
  1946. {
  1947. return m_pImpl->StartWmvRecord(fps,videoquality,subtitleParam,bWholeSection,bSessionManage,pathname,pathlength,wmvfilename,filenamelength,pAudioParam);
  1948. }
  1949. BOOL Clibwmvrecord::StopWmvRecord() //退出
  1950. {
  1951. return m_pImpl->StopWmvRecord();
  1952. }
  1953. void Clibwmvrecord::CloseVideoFile() //结束当前录像
  1954. {
  1955. m_pImpl->m_bCloseVideo = TRUE;
  1956. }
  1957. BOOL Clibwmvrecord::ReNameVideoFile(const char*newfilename) //session变化,修改当前录像文件名
  1958. {
  1959. m_pImpl->ChangeFilename(newfilename);
  1960. //m_pImpl->m_bReNameVideo = TRUE;
  1961. return TRUE;
  1962. }
  1963. BOOL Clibwmvrecord::SetRightVideoWaterMark(wchar_t* strWaterMark)
  1964. {
  1965. BOOL bRet = FALSE;
  1966. if (NULL == strWaterMark){
  1967. return bRet;
  1968. }
  1969. size_t ulen = wcslen(strWaterMark);
  1970. bRet = m_pImpl->setRightWaterMark(strWaterMark, ulen*sizeof(wchar_t));
  1971. return bRet;
  1972. }
  1973. BOOL Clibwmvrecord::StopAudioEnTransQueue()
  1974. {
  1975. return m_pImpl->StopAudioStreamEnTransQueue();
  1976. }