123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628 |
- #ifdef RVC_OS_WIN
- #include "stdafx.h"
- #include <ipp.h>
- #include <objbase.h>
- #include <intrin.h>
- #include "../../Other/libvideohorflip/videohorflip.h"
- #include "../../Other/libvideoframework/video_common/ffmpeg_api_cpp_adapter.h"
- #else
- #endif // RVC_OS_WIN
- #include <locale.h>
- #include <memutil.h>
- #include <md5.h>
- #include "y2k_time.h"
- #include "../../Other/rvcmediacommon/rvc_media_common.h"
- #include "Event.h"
- #include "capture.h"
- using namespace MediaController;
- #ifndef av_always_inline
- #define av_always_inline __inline
- #endif // !av_always_inline
- #ifndef inline
- #define inline __inline
- #endif // !inline
- #ifndef RVC_AUDIO_BUFFER_LEN
- #define RVC_AUDIO_BUFFER_LEN 320
- #endif
- static int Bin2Str(unsigned char *x, int xlen, char *str, int str_size)
- {
- static const char *hex2char = "0123456789ABCDEF";
- int i, k = 0;
- if (str_size <= xlen * 2)
- return -1;
- for (i = 0; i < xlen; ++i) {
- int h = x[i] >> 4;
- int l = x[i] & 0xf;
- str[k++] = hex2char[h];
- str[k++] = hex2char[l];
- }
- str[k] = 0;
- return k;
- }
- static void __audiomgrlog(void* user_data, const char* fmt, va_list arg)
- {
- vDbg(fmt, arg);
- }
- #ifdef RVC_OS_WIN
- static int audio_get_dev_count(int* in_cnt, int* out_cnt)
- {
- int icnt = 0, ocnt = 0;
- int cnt = Pa_GetDeviceCount();
- for (int i = 0; i < cnt; ++i) {
- const PaDeviceInfo* info = Pa_GetDeviceInfo(i);
- if (info->maxInputChannels)
- icnt++;
- if (info->maxOutputChannels)
- ocnt++;
- }
- if (in_cnt)
- * in_cnt = icnt;
- if (out_cnt)
- * out_cnt = ocnt;
- return 0;
- }
- static CSimpleStringA audio_get_dev_name(bool in_direction, int idx)
- {
- int cnt = Pa_GetDeviceCount();
- int ii, i;
- for (i = 0, ii = 0; i < cnt; ++i) {
- const PaDeviceInfo* info = Pa_GetDeviceInfo(i);
- if (in_direction) {
- if (info->maxInputChannels) {
- if (idx == ii) {
- return CSimpleStringA(info->name);
- }
- ii++;
- }
- }
- else {
- if (info->maxOutputChannels) {
- if (idx == ii) {
- return CSimpleStringA(info->name);
- }
- ii++;
- }
- }
- }
- return CSimpleStringA();
- }
- static int translate_id(int in_direction, int idx)
- {
- int i, n, ii;
- n = Pa_GetDeviceCount();
- for (i = 0, ii = 0; i < n; ++i) {
- const PaDeviceInfo* info = Pa_GetDeviceInfo(i);
- if (in_direction) {
- if (info->maxInputChannels) {
- if (ii == idx) {
- return i;
- }
- ii++;
- }
- }
- else {
- if (info->maxOutputChannels) {
- if (ii == idx) {
- return i;
- }
- ii++;
- }
- }
- }
- return -1;
- }
- int capture_get_audio_device_id(bool in_direction, const char* dev_name)
- {
- int cnt = Pa_GetDeviceCount();
- int ii, i;
- for (i = 0, ii = 0; i < cnt; ++i) {
- const PaDeviceInfo* info = Pa_GetDeviceInfo(i);
- if (in_direction) {
- if (info->maxInputChannels) {
- if (strstr(info->name, dev_name) != NULL) {
- return ii;
- }
- ii++;
- }
- }
- else {
- if (info->maxOutputChannels) {
- if (strstr(info->name, dev_name) != NULL) {
- return ii;
- }
- ii++;
- }
- }
- }
- return -1;
- }
- static int StreamCallback(const void* input,
- void* output,
- unsigned long frameCount,
- const PaStreamCallbackTimeInfo* timeInfo,
- PaStreamCallbackFlags statusFlags,
- void* userData)
- {
- audio_capture_t* audio_cap = (audio_capture_t*)userData;
- if (input) {
- audio_frame frm;
- audio_frame dst_frm;
- frm.bitspersample = audio_cap->dev_bitspersample;
- frm.format = 1;
- frm.data = (char*)const_cast<void*>(input);
- frm.framesize = frameCount * (audio_cap->dev_bitspersample / 8);
- frm.nchannels = audio_cap->dev_channels;
- frm.samplespersec = audio_cap->dev_samplespersec;
- frm.iseriesnumber = 0;
- //Dbg("[StreamCallback] frameCount :%d and framesize :%d, nchannels :%d, bitspersample :%d.", frameCount, frm.framesize, frm.nchannels, frm.bitspersample);
- if (audio_cap->dev_bitspersample == 32) {
- dst_frm.bitspersample = 16;
- dst_frm.format = 1;
- dst_frm.data = (char*)malloc(frameCount * 16 / 8);
- dst_frm.framesize = frameCount * 16 / 8;
- dst_frm.nchannels = audio_cap->dev_channels;
- dst_frm.samplespersec = audio_cap->dev_samplespersec;
- dst_frm.iseriesnumber = 0;
- From32To16Bit(&frm, &dst_frm);
- //Dbg("[StreamCallback] From32To16Bit frameCount :%d and framesize :%d, nchannels :%d, bitspersample :%d.", frameCount, dst_frm.framesize, dst_frm.nchannels, dst_frm.bitspersample);
- if (!audio_cap->shm_queue->InsertAudio(&dst_frm)) {
- Dbg("[StreamCallback] InsertAudio to shm_queue failed! frameCount:%d", frameCount);
- }
- //else {
- // Dbg("[StreamCallback] InsertAudio to shm_queue success! frameCount:%d and framesize is :%d, and shm_queue length is %d.", frameCount, frm.framesize, audio_cap->shm_queue->GetAudioLens());
- //}
- //if (!audio_cap->salesol_shm_queue->InsertAudio(&dst_frm)) {
- // Dbg("[StreamCallback] InsertAudio to salesol_shm_queue failed! frameCount:%d", frameCount);
- //}
- //else {
- // Dbg("[StreamCallback] InsertAudio to salesol_shm_queue success! and framesize is :%d, and salesol_shm_queue length is %d.", frm.framesize, audio_cap->salesol_shm_queue->GetAudioLens());
- //}
- free(dst_frm.data);
- }
- else {
- if (!audio_cap->shm_queue->InsertAudio(&frm)) {
- Dbg("[StreamCallback] InsertAudio to shm_queue failed! frameCount:%d", frameCount);
- }
- //else {
- // Dbg("[StreamCallback] InsertAudio to shm_queue success! frameCount:%d and framesize is :%d, and shm_queue length is %d.", frameCount, frm.framesize, audio_cap->shm_queue->GetAudioLens());
- //}
- //if (!audio_cap->salesol_shm_queue->InsertAudio(&frm)) {
- // Dbg("[StreamCallback] InsertAudio to salesol_shm_queue failed! frameCount:%d", frameCount);
- //}
- //else {
- // Dbg("[StreamCallback] InsertAudio to salesol_shm_queue success! and framesize is :%d, and salesol_shm_queue length is %d.", frm.framesize, audio_cap->salesol_shm_queue->GetAudioLens());
- //}
- }
- }
- if (output) {
- memset(output, 0, frameCount << 1);
- }
- return paContinue;
- }
- static int Sales_StreamCallback(const void* input,
- void* output,
- unsigned long frameCount,
- const PaStreamCallbackTimeInfo* timeInfo,
- PaStreamCallbackFlags statusFlags,
- void* userData)
- {
- rvc_audio_capture_t* audio_cap = (rvc_audio_capture_t*)userData;
- if ((NULL != audio_cap) && (NULL != audio_cap->audio_shm_queue) && (NULL != input)) {
- audio_frame frm;
- audio_frame dst_frm;
- frm.bitspersample = audio_cap->dev_bitspersample;
- frm.format = 1;
- frm.data = (char*)const_cast<void*>(input);
- frm.framesize = frameCount * (audio_cap->dev_bitspersample / 8);
- frm.nchannels = audio_cap->dev_channels;
- frm.samplespersec = audio_cap->dev_samplespersec;
- frm.iseriesnumber = audio_cap->iseriesnumber++;
- //Dbg("[Sales_StreamCallback] frameCount :%d and framesize :%d, nchannels :%d, bitspersample :%d.", frameCount, frm.framesize, frm.nchannels, frm.bitspersample);
- if (audio_cap->dev_bitspersample == 32) {
- dst_frm.bitspersample = 16;
- dst_frm.format = 1;
- dst_frm.data = (char*)malloc(frameCount * 16 / 8);
- dst_frm.framesize = frameCount * 16 / 8;
- dst_frm.nchannels = audio_cap->dev_channels;
- dst_frm.samplespersec = audio_cap->dev_samplespersec;
- dst_frm.iseriesnumber = frm.iseriesnumber;
- From32To16Bit(&frm, &dst_frm);
- //Dbg("[Sales_StreamCallback] From32To16Bit frameCount :%d and framesize :%d, nchannels :%d, bitspersample :%d.", frameCount, dst_frm.framesize, dst_frm.nchannels, dst_frm.bitspersample);
- if (!audio_cap->audio_shm_queue->InsertAudio(&dst_frm)) {
- Dbg("[Sales_StreamCallback] InsertAudio failed! frameCount:%d", frameCount);
- }
- else {
- if ((audio_cap->iaudio_capture_peroid) > 0 && (0 == dst_frm.iseriesnumber % audio_cap->iaudio_capture_peroid)) {
- if (audio_cap->iseriesnumber > INT_MAX) {
- audio_cap->iseriesnumber = 0;
- }
- //Dbg("current audio frame series number is %d.", frm.iseriesnumber);
- }
- }
- free(dst_frm.data);
- }
- else {
- if (!audio_cap->audio_shm_queue->InsertAudio(&frm)) {
- Dbg("[Sales_StreamCallback] InsertAudio failed! frameCount:%d", frameCount);
- }
- else {
- if ((audio_cap->iaudio_capture_peroid) > 0 && (0 == frm.iseriesnumber % audio_cap->iaudio_capture_peroid)) {
- if (audio_cap->iseriesnumber > INT_MAX) {
- audio_cap->iseriesnumber = 0;
- }
- //Dbg("current audio frame series number is %d.", frm.iseriesnumber);
- }
- }
- }
- if (eSingleWriteLocal == audio_cap->eType) {
- fwrite(frm.data, frm.framesize, 1, (FILE*)(audio_cap->pdata));
- }
- }
- if (output) {
- memset(output, 0, frameCount << 1);
- }
- return paContinue;
- }
- static int portaudio_capture_start(audio_capture_t* audio_cap)
- {
- capture_t* cap = audio_cap->parent;
- PaStreamParameters outParam = { 0 };
- PaStreamParameters inParam = { 0 };
- PaStreamParameters salesInParam = { 0 };
- PaError paError = paNoError;
- int nId = capture_get_audio_device_id(true, cap->config.strAudioIn);
- if (nId == -1)
- {
- //需要立即处理的告警使用Severity_High
- LogError(Severity_High, Error_DevMedia, ERROR_MOD_MEDIACONTROLLER_HANDFREEIN_INITFAIL, "hand free in device config error,please check");
- return Error_AudioIN;
- }
- int in_dev_id = translate_id(TRUE, nId);
- if (in_dev_id < 0) {
- Dbg("audio in device translate failed!");
- return Error_AudioIN;
- }
- const PaDeviceInfo* in_info = Pa_GetDeviceInfo(in_dev_id);
- if (!in_info) {
- Dbg("get device info failed!");
- return Error_AudioIN;
- }
- else
- {
- Dbg("[%d] in dev name is %s, defaultSampleRate = %f", in_dev_id, in_info->name, in_info->defaultSampleRate);
- }
- inParam.channelCount = 1;
- audio_cap->dev_channels = 1;
- inParam.device = in_dev_id;
- inParam.suggestedLatency = in_info->defaultLowInputLatency;
- inParam.sampleFormat = paInt16;
- audio_cap->dev_bitspersample = 16;
- inParam.hostApiSpecificStreamInfo = NULL;
- audio_cap->dev_samplespersec = in_info->defaultSampleRate;
- double inSampleRate = in_info->defaultSampleRate;
- Dbg("audio input device name is %s.", in_info->name);
- paError = Pa_IsFormatSupported(&inParam, NULL, inSampleRate);
- if (paNoError != paError) {
- Dbg("[%d] in dev %s audio capture create error[%d], cannot open audio input device", in_dev_id, in_info->name, paError);
- return Error_AudioIN;
- }
- else
- {
- Dbg("[%d] in dev %s audio capture create success, sampleFormat = %d,inSampleRate = %f.", in_dev_id, in_info->name, inParam.sampleFormat, inSampleRate);
- }
- nId = capture_get_audio_device_id(false, cap->config.strAudioOut);
- if (nId == -1)
- {
- //需要立即处理的告警使用Severity_High
- LogError(Severity_High, Error_DevMedia, ERROR_MOD_MEDIACONTROLLER_HANDFREEOUT_INITFAIL, "hand free out device config error,please check");
- return Error_AudioOut;
- }
- int out_dev_id = translate_id(FALSE, nId);
- if (out_dev_id < 0) {
- Dbg("audio out device translate failed!");
- return Error_AudioOut;
- }
- const PaDeviceInfo* out_info = Pa_GetDeviceInfo(out_dev_id);
- if (!out_info) {
- Dbg("get output device info failed!");
- return Error_AudioOut;
- }
- outParam.channelCount = 1;
- outParam.device = out_dev_id;
- outParam.suggestedLatency = out_info->defaultLowOutputLatency;
- outParam.sampleFormat = paInt16;
- outParam.hostApiSpecificStreamInfo = NULL;
- Dbg("audio output device name is %s.", in_info->name);
- if (Pa_IsFormatSupported(NULL, &outParam, out_info->defaultSampleRate) != paNoError) {
- Dbg("audio capture create error, cannot open output audio device.");
- return Error_AudioOut;
- }
- //打开流设备,可以用以下代码替换paError = Pa_OpenStream(&audio_cap->stream, &inParam, &outParam, CAPTURE_CLOCK,
- //CAPTURE_FRAME_TIME * CAPTURE_CLOCK/1000, paClipOff|paDitherOff, &StreamCallback, audio_cap);
- paError = Pa_OpenStream(&audio_cap->stream, &inParam, NULL, inSampleRate,
- CAPTURE_FRAME_TIME * inSampleRate / 1000, paClipOff | paDitherOff, &StreamCallback, audio_cap);
- if (paNoError != paError) {
- Dbg("[%d] in dev %s port audio open stream failed! paError = %d", in_dev_id, in_info->name, paError);
- return Error_AudioIN;
- }
- else
- {
- Dbg("[%d] in dev %s port audio open stream success, sampleFormat = %d,inSampleRate = %f.", in_dev_id, in_info->name, inParam.sampleFormat, inSampleRate);
- }
- paError = Pa_StartStream(audio_cap->stream);
- if (paNoError != paError) {
- Dbg("[%d] in dev %s port audio start stream failed! paError = %d", in_dev_id, in_info->name, paError);
- return Error_AudioIN;
- }
- else
- {
- Dbg("[%d] in dev %s port audio start stream success, sampleFormat = %d,inSampleRate = %f.", in_dev_id, in_info->name, inParam.sampleFormat, inSampleRate);
- }
- return Error_Succeed;
- }
- static void portaudio_capture_stop(audio_capture_t* audio_cap)
- {
- if (audio_cap->stream) {
- Pa_AbortStream(audio_cap->stream);
- Pa_CloseStream(audio_cap->stream);
- audio_cap->stream = NULL;
- }
- }
- static int record_portaudio_capture_start(rvc_audio_capture_t* audio_cap)
- {
- rvc_sales_audio_capture_t* cap = audio_cap->parent;
- PaStreamParameters salesInParam = { 0 };
- PaError paError;
- const PaDeviceInfo* info;
- int nId = capture_get_audio_device_id(true, cap->rvc_audio_config.strAudioIn);
- if (nId == -1)
- {
- //需要立即处理的告警使用Severity_High
- LogError(Severity_High, Error_DevMedia, ERROR_MOD_MEDIACONTROLLER_HANDFREEIN_INITFAIL, "hand free in device config error,please check");
- return Error_AudioIN;
- }
- int in_dev_id = translate_id(TRUE, nId);
- if (in_dev_id < 0) {
- Dbg("sales audio in device translate failed!");
- return Error_AudioIN;
- }
- info = Pa_GetDeviceInfo(in_dev_id);
- if (!info) {
- Dbg("get device info failed!");
- return Error_AudioIN;
- }
- else
- {
- Dbg("[%d] in dev name is %s, defaultSampleRate = %f", in_dev_id, info->name, info->defaultSampleRate);
- }
- salesInParam.channelCount = 1;
- audio_cap->dev_channels = 1;
- salesInParam.device = in_dev_id;
- salesInParam.suggestedLatency = info->defaultLowInputLatency;
- salesInParam.sampleFormat = paInt16;
- audio_cap->dev_bitspersample = 16;
- salesInParam.hostApiSpecificStreamInfo = NULL;
- audio_cap->dev_samplespersec = info->defaultSampleRate;
- if (Pa_IsFormatSupported(&salesInParam, NULL, info->defaultSampleRate) != paNoError) {
- Dbg("sales audio capture create error, cannot open audio input device, and current capture sample rate is %d.", info->defaultSampleRate);
- return Error_AudioIN;
- }
- paError = Pa_OpenStream(&audio_cap->stream, &salesInParam, NULL, info->defaultSampleRate,
- audio_cap->iaudio_capture_peroid * info->defaultSampleRate / 1000, paClipOff | paDitherOff, &Sales_StreamCallback, audio_cap);
- if (paError != paNoError) {
- Dbg("port audio open sales stream failed! paError = %d", paError);
- return Error_AudioIN;
- }
- paError = Pa_StartStream(audio_cap->stream);
- if (paError != paNoError) {
- Dbg("port audio start sales stream failed! paError = %d", paError);
- return Error_AudioIN;
- }
- return Error_Succeed;
- }
- static void record_portaudio_capture_stop(rvc_audio_capture_t* audio_cap)
- {
- if (NULL != audio_cap) {
- if (audio_cap->stream) {
- PaError Error = Pa_AbortStream(audio_cap->stream);
- if (paNoError == Error) {
- Dbg("Pa_AbortStream no error.");
- }
- Error = Pa_CloseStream(audio_cap->stream);
- if (paNoError == Error) {
- Dbg("Pa_CloseStream no error.");
- }
- audio_cap->stream = NULL;
- }
- audio_cap->iseriesnumber = 0;
- }
- }
- #else
- static void audio_data_callback(const void* input, unsigned long audiolen, void* userdata)
- {
- audio_capture_t* audio_cap = (audio_capture_t*)userdata;
- if (input) {
- int ileft = audiolen;
- int index = 0;
- while (audio_cap->uaudiolen + ileft >= RVC_AUDIO_BUFFER_LEN)
- {
- int ineed = RVC_AUDIO_BUFFER_LEN - audio_cap->uaudiolen;
- memcpy(audio_cap->paudio_buffer + audio_cap->uaudiolen, input + index, ineed);
- ileft -= ineed;
- audio_cap->uaudiolen += ineed;
- index += ineed;
- audio_frame frm;
- frm.bitspersample = 16;
- frm.format = 1;
- frm.data = audio_cap->paudio_buffer;
- frm.framesize = RVC_AUDIO_BUFFER_LEN;
- frm.nchannels = 1;
- frm.samplespersec = 8000;
- frm.iseriesnumber = audio_cap->iseriesnumber++;
- if (audio_cap->iseriesnumber >= INT_MAX) {
- audio_cap->iseriesnumber = 0;
- }
- if (!audio_cap->shm_queue->InsertAudio(&frm)) {
- Dbg("%s:%d InsertAudio to shm_queue failed!", __FUNCTION__, __LINE__);
- }
- else {
- //Dbg("%s:%d InsertAudio to shm_queue success! and framesize is :%d, and shm_queue length is %d, frm.iseriesnumber = %d.", __FUNCTION__, __LINE__, frm.framesize, audio_cap->shm_queue->GetAudioLens(), frm.iseriesnumber);
- }
- audio_cap->uaudiolen -= RVC_AUDIO_BUFFER_LEN;
- }
- if (ileft > 0){
- memcpy(audio_cap->paudio_buffer + audio_cap->uaudiolen, input + index, ileft);
- audio_cap->uaudiolen += ileft;
- }
- }
- return;
- }
- static int pulseaudio_capture_start(audio_capture_t* audio_cap)
- {
- int iret = -1;
- capture_t* cap = audio_cap->parent;
-
- if (NULL != audio_cap->paudiocap){
- audiocap_param_t param = { 0 };
- int nId = audio_cap->paudiocap->audio_get_device_id(cap->config.strAudioIn.GetData(), true);
- if (nId == -1)
- {
- //需要立即处理的告警使用Severity_High
- LogError(Severity_High, Error_DevMedia, ERROR_MOD_MEDIACONTROLLER_HANDFREEIN_INITFAIL, "hand free in device config error,please check");
- return Error_AudioIN;
- }
- param.ideviceid = nId;
- param.ichannels = 1;
- param.isampleformat = 3 /*PA_SAMPLE_S16LE*/;
- param.isamprate = 8000;
- param.flatency = 0.02;
- param.on_audio_callback = &audio_data_callback;
- param.user_data = audio_cap;
- audio_cap->paudiocap->set_audio_capture_params(¶m);
- iret = audio_cap->paudiocap->start_audio_capture();
- }
- return iret;
- }
- static void pulseaudio_capture_stop(audio_capture_t* audio_cap)
- {
- if (audio_cap->paudiocap) {
- audio_cap->paudiocap->stop_audio_capture();
- }
- }
- static void record_audio_data_callback(const void* input, unsigned long audiolen, void* userdata)
- {
- rvc_audio_capture_t* audio_cap = (rvc_audio_capture_t*)userdata;
- if (input) {
- int ileft = audiolen;
- int index = 0;
- while (audio_cap->uaudiolen + ileft >= RVC_AUDIO_BUFFER_LEN)
- {
- int ineed = RVC_AUDIO_BUFFER_LEN - audio_cap->uaudiolen;
- memcpy(audio_cap->paudio_buffer + audio_cap->uaudiolen, input + index, ineed);
- ileft -= ineed;
- audio_cap->uaudiolen += ineed;
- index += ineed;
- audio_frame frm;
- frm.bitspersample = 16;
- frm.format = 1;
- frm.data = audio_cap->paudio_buffer;
- frm.framesize = RVC_AUDIO_BUFFER_LEN;
- frm.nchannels = 1;
- frm.samplespersec = 8000;
- frm.iseriesnumber = audio_cap->iseriesnumber++;
- if (audio_cap->iseriesnumber >= INT_MAX) {
- audio_cap->iseriesnumber = 0;
- }
- if (!audio_cap->audio_shm_queue->InsertAudio(&frm)) {
- Dbg("%s:%d InsertAudio to audio_shm_queue failed!", __FUNCTION__, __LINE__);
- }
- audio_cap->uaudiolen -= RVC_AUDIO_BUFFER_LEN;
- }
- if (ileft > 0) {
- memcpy(audio_cap->paudio_buffer + audio_cap->uaudiolen, input + index, ileft);
- audio_cap->uaudiolen += ileft;
- }
- }
- return;
- }
- static int record_pulseaudio_capture_start(rvc_audio_capture_t* audio_cap)
- {
- LOG_FUNCTION();
-
- int iret = -1;
- rvc_sales_audio_capture_t* cap = audio_cap->parent;
- if (NULL != audio_cap->paudiocap) {
- Dbg("%s:%d.", __FUNCTION__, __LINE__);
- audiocap_param_t param = { 0 };
- int nId = audio_cap->paudiocap->audio_get_device_id(cap->rvc_audio_config.strAudioIn.GetData(), true);
- if (nId == -1)
- {
- //需要立即处理的告警使用Severity_High
- LogError(Severity_High, Error_DevMedia, ERROR_MOD_MEDIACONTROLLER_HANDFREEIN_INITFAIL, "hand free in device config error,please check");
- return Error_AudioIN;
- }
- param.ideviceid = nId;
- param.ichannels = 1;
- param.isampleformat = 3 /*PA_SAMPLE_S16LE*/;
- param.isamprate = 8000;
- param.flatency = 0.02;
- param.on_audio_callback = &record_audio_data_callback;
- param.user_data = audio_cap;
- Dbg("%s:%d.", __FUNCTION__, __LINE__);
- audio_cap->paudiocap->set_audio_capture_params(¶m);
- Dbg("%s:%d.", __FUNCTION__, __LINE__);
- iret = audio_cap->paudiocap->start_audio_capture();
- Dbg("%s:%d.", __FUNCTION__, __LINE__);
- }
- return iret;
- }
- static void record_pulseaudio_capture_stop(rvc_audio_capture_t* audio_cap)
- {
- if (audio_cap->paudiocap) {
- audio_cap->paudiocap->stop_audio_capture();
- }
- }
- #endif
- static rvc_audio_capture_t *salesrecord_audio_capture_create(rvc_sales_audio_capture_t *cap)
- {
- rvc_audio_capture_t *audio_cap = ZALLOC_T(rvc_audio_capture_t);
- if (audio_cap) {
- audio_cap->parent = cap;
- audio_cap->audio_shm_queue = new Clibaudioqueue(REC_COMMON_REMOTEAUDIO_SHM_QUEUE);
- audio_cap->iseriesnumber = 0;
- audio_cap->eType = eUnKnown;
- audio_cap->pdata = NULL;
- }
- #ifdef RVC_OS_LINUX
- audio_cap->paudio_buffer = new char[RVC_AUDIO_BUFFER_LEN];
- audio_cap->uaudiolen = 0;
- #endif
- return audio_cap;
- }
- static void salesrecord_audio_capture_destroy(rvc_audio_capture_t *audio_cap)
- {
- if (NULL != audio_cap){
- if (NULL != audio_cap->audio_shm_queue){
- delete audio_cap->audio_shm_queue;
- audio_cap->audio_shm_queue = NULL;
- Dbg("set audio_cap audio_shm_queue null");
- }
- free(audio_cap);
- #ifdef RVC_OS_LINUX
- delete audio_cap->paudio_buffer;
- audio_cap->paudio_buffer = NULL;
- audio_cap->uaudiolen = 0;
- #endif
- }
- }
- static audio_capture_t *audio_capture_create(capture_t *cap)
- {
- audio_capture_t *audio_cap = ZALLOC_T(audio_capture_t);
- if (audio_cap) {
- audio_cap->parent = cap;
- audio_cap->shm_queue = new Clibaudioqueue(REC_COMMON_AUDIO_SHM_QUEUE);
- audio_cap->salesol_shm_queue = new Clibaudioqueue(REC_COMMON_AUDIO_SALESOL_SHM_QUEUE);
- #ifdef RVC_OS_LINUX
- audio_cap->paudio_buffer = new char[RVC_AUDIO_BUFFER_LEN];
- audio_cap->uaudiolen = 0;
- #endif
- }
- return audio_cap;
- }
- static void audio_capture_destroy(audio_capture_t *audio_cap)
- {
- delete audio_cap->shm_queue;
- delete audio_cap->salesol_shm_queue;
- free(audio_cap);
- #ifdef RVC_OS_LINUX
- delete audio_cap->paudio_buffer;
- audio_cap->paudio_buffer = NULL;
- audio_cap->uaudiolen = 0;
- #endif
- }
- static int audio_capture_start(audio_capture_t* audio_cap)
- {
- #ifdef RVC_OS_WIN
- return portaudio_capture_start(audio_cap);
- #else
- return pulseaudio_capture_start(audio_cap);
- #endif
- }
- static void audio_capture_stop(audio_capture_t* audio_cap)
- {
- #ifdef RVC_OS_WIN
- return portaudio_capture_stop(audio_cap);
- #else
- return pulseaudio_capture_stop(audio_cap);
- #endif
- }
- static int record_audio_capture_start(rvc_audio_capture_t* audio_cap)
- {
- #ifdef RVC_OS_WIN
- return record_portaudio_capture_start(audio_cap);
- #else
- return record_pulseaudio_capture_start(audio_cap);
- #endif
- }
- static void record_audio_capture_stop(rvc_audio_capture_t* audio_cap)
- {
- #ifdef RVC_OS_WIN
- return record_portaudio_capture_stop(audio_cap);
- #else
- return record_pulseaudio_capture_stop(audio_cap);
- #endif
- }
- static int calc_capture_mode(int width, int height, int *mode)
- {
- const struct {
- int mode;
- int width;
- int height;
- } modes [] = {
- {VIDEOCAP_FRAME_SQCIF, VIDEOCAP_SQCIF_WIDTH, VIDEOCAP_SQCIF_HEIGHT},
- {VIDEOCAP_FRAME_QQVGA, VIDEOCAP_QQVGA_WIDTH, VIDEOCAP_QQVGA_HEIGHT},
- {VIDEOCAP_FRAME_QCIF, VIDEOCAP_QCIF_WIDTH, VIDEOCAP_QCIF_HEIGHT},
- {VIDEOCAP_FRAME_QVGA, VIDEOCAP_QVGA_WIDTH, VIDEOCAP_QVGA_HEIGHT},
- {VIDEOCAP_FRAME_CIF, VIDEOCAP_CIF_WIDTH, VIDEOCAP_CIF_HEIGHT},
- {VIDEOCAP_FRAME_VGA, VIDEOCAP_VGA_WIDTH, VIDEOCAP_VGA_HEIGHT},
- {VIDEOCAP_FRAME_4CIF, VIDEOCAP_4CIF_WIDTH, VIDEOCAP_4CIF_HEIGHT},
- {VIDEOCAP_FRAME_SVGA, VIDEOCAP_SVGA_WIDTH, VIDEOCAP_SVGA_HEIGHT},
- {VIDEOCAP_FRAME_NHD, VIDEOCAP_NHD_WIDTH, VIDEOCAP_NHD_HEIGHT},
- {VIDEOCAP_FRAME_SXGA, VIDEOCAP_SXGA_WIDTH, VIDEOCAP_SXGA_HEIGHT},
- {VIDEOCAP_FRAME_720P, VIDEOCAP_720P_WIDTH, VIDEOCAP_720P_HEIGHT},
- {VIDEOCAP_FRAME_1080P, VIDEOCAP_1080P_WIDTH, VIDEOCAP_1080P_HEIGHT},
- };
- int i;
- for (i = 0; i < array_size(modes); ++i) {
- if (modes[i].width == width && modes[i].height == height) {
- *mode = modes[i].mode;
- return 0;
- }
- }
- return Error_NotExist;
- }
- static int video_shm_enqueue(Clibvideoqueue *shm_queue, video_frame *frame, int flags)
- {
- videoq_frame tmp_frm;
- tmp_frm.data = frame->data[0];
- if (VIDEO_FORMAT_RGB24 == frame->format){
- tmp_frm.framesize = frame->width * frame->height * 3;
- tmp_frm.format = VIDEOQ_FORMAT_RGB24;
- }
- else {
- tmp_frm.framesize = frame->width * frame->height * 3/2;
- tmp_frm.format = VIDEOQ_FORMAT_I420;
- }
- tmp_frm.width = frame->width;
- tmp_frm.height = frame->height;
- unsigned int nowtime = y2k_time_now();
- if (!shm_queue->InsertVideo(&tmp_frm, flags,nowtime)) {
- Dbg("caution: insert shm video failed!");
- return Error_Unexpect;
- } else {
- //Dbg("insert shm video ok!");
- return Error_Succeed;
- }
- }
- //static int env_cap_on_frame_i420(void* user_data, video_frame* frame)
- //{
- // video_capture_t* video_cap = (video_capture_t*)user_data;
- // capture_t* cap = video_cap->parent;
- // return video_shm_enqueue(video_cap->render_shm_queue, frame, VIDEOQUEUE_FLAG_VERTICAL_FLIP);
- //}
- //
- //
- //static int opt_cap_on_frame_i420(void* user_data, video_frame* frame)
- //{
- // video_capture_t* video_cap = (video_capture_t*)user_data;
- // capture_t* cap = video_cap->parent;
- // return video_shm_enqueue(video_cap->opt_render_shm_queue, frame, VIDEOQUEUE_FLAG_VERTICAL_FLIP);
- //}
- static void env_cap_on_frame(void *user_data, video_frame *frame)
- {
- video_capture_t *video_cap = (video_capture_t *)user_data;
- capture_t *cap = video_cap->parent;
- int rc;
- video_cap->frame_id++;
- //Dbg("start env on frame, id=%d, tick=%d", video_cap->frame_id, GetTickCount());;
- //IplImage* img = NULL;
- //img = cvCreateImage(cvSize(frame->width, frame->height), IPL_DEPTH_8U, 3);
- //img->imageData = (char*)frame->data[0];
- //cvSaveImage("./env.jpg", img, 0);
- //cvReleaseImageHeader(&img);
- rc = video_shm_enqueue(video_cap->snapshot_shm_queue, frame, VIDEOQUEUE_FLAG_VERTICAL_FLIP);
- //static int isnapshot_shm_queue = 0;
- //if (isnapshot_shm_queue == 0) {
- // video_frame_save_bmpfile("snapshot_shm_queue_1.bmp", frame);
- // isnapshot_shm_queue++;
- //}
- if (rc != Error_Succeed)
- {
- Dbg("env snapshot queue enqueue failed! Error = %d, camera_type=%d", rc, video_cap->camera_type);
- }
- //else {
- // Dbg("env snapshot queue enqueue success! camera_type=%d", video_cap->camera_type);
- //}
- // snapshot
- if (rc==Error_Succeed)
- {
- if (*cap->config.ref_env_capture_count)
- {
- Dbg("env camera ref_env_capture_count=%d", *cap->config.ref_env_capture_count);
- #ifdef RVC_OS_WIN
- InterlockedDecrement(cap->config.ref_env_capture_count);
- #else
- //__sync_fetch_and_sub(cap->config.ref_env_capture_count, 1);
- pthread_mutex_lock(cap->config.env_mutex);
- *(cap->config.ref_env_capture_count) -= 1;
- pthread_mutex_unlock(cap->config.env_mutex);
- #endif
- LogEvent(Severity_Middle, MOD_EVENT_MEDIACONTROLLER_FINISHED_CAPTURE_ENV, "agent capture env ok, and capture env finished!");
- }
- else if (*cap->config.ref_envopt_capture_count & 2)
- {
- Dbg("env camera ref_envopt_capture_count=%d", *cap->config.ref_envopt_capture_count);
- #ifdef RVC_OS_WIN
- _InterlockedAnd(cap->config.ref_envopt_capture_count, 0xfffffffD);
- #else
- //__sync_fetch_and_add(cap->config.ref_env_capture_count, 0xfffffffD);
- pthread_mutex_lock(cap->config.envopt_mutex);
- LONG lcount = *(cap->config.ref_envopt_capture_count);
- *(cap->config.ref_envopt_capture_count) = (lcount & 0xfffffffD);
- pthread_mutex_unlock(cap->config.envopt_mutex);
- #endif // RVC_OS_WIN
- if (*cap->config.ref_envopt_capture_count == 0)
- {
- LogEvent(Severity_Middle, MOD_EVENT_MEDIACONTROLLER_FINISHED_CAPTURE_ENVOPT, "agent capture env ok, and capture env opt finished!");
- }
- }
- }
- // preview
- {
- video_frame preview_frame;
-
- video_frame_alloc(REC_COMMON_VIDEO_PREVIEW_WIDTH, REC_COMMON_VIDEO_PREVIEW_HEIGHT, VIDEO_FORMAT_RGB24, &preview_frame);
- uint8_t *src_data[4] = {frame->data[0] + 80*3, 0, 0, 0};
- sws_scale(video_cap->preview_sws_ctx, src_data, frame->linesize, 0, frame->height, preview_frame.data, preview_frame.linesize);
- rc= video_shm_enqueue(video_cap->preview_shm_queue, &preview_frame, 0);
-
- if (rc != Error_Succeed){
- Dbg("preview_shm_queue enqueue failed, error = %d", rc);
- }
- else {
- //if (0 == video_cap->frame_id%10){
- // Dbg("preview_shm_queue enqueue[%d] success, and current video queue len is %d.", video_cap->frame_id, video_cap->preview_shm_queue->GetVideoLens());
- //}
- }
- video_frame_free(&preview_frame);
- //static int ipreview_shm_queue = 0;
- //if (ipreview_shm_queue == 0) {
- // video_frame_save_bmpfile("preview_shm_queue_1.bmp", frame);
- // ipreview_shm_queue++;
- //}
- }
- // rtp
- {
- video_frame rtp_frame;
- video_frame_alloc(REC_COMMON_VIDEO_RTP_ENV_WIDTH, REC_COMMON_VIDEO_RTP_ENV_HEIGHT, VIDEO_FORMAT_RGB24, &rtp_frame);
- uint8_t *src_data[4] = {frame->data[0] + (frame->height-1) * frame->linesize[0], 0, 0, 0};
- int src_linesize[4] = {-frame->linesize[0], 0, 0, 0};
- sws_scale(video_cap->rtp_sws_ctx, src_data, src_linesize, 0, frame->height, rtp_frame.data, rtp_frame.linesize);
- rc = video_shm_enqueue(video_cap->rtp_shm_queue, &rtp_frame, 0);
- if (rc != Error_Succeed) {
- Dbg("rtp_shm_queue enqueue failed! Error = %d", rc);
- }
- //else {
- // Dbg("rtp_shm_queue enqueue success!");
- //}
- //static int irtp_frame = 0;
- //if (irtp_frame == 0){
- // video_frame_save_bmpfile("rtp_shm_queue.bmp", &rtp_frame);
- // irtp_frame++;
- //}
-
- #if 0
- static int i = 0;
- if (i == 0) {
- video_frame tmp_frame;
- video_frame_alloc(REC_COMMON_VIDEO_RTP_ENV_WIDTH, REC_COMMON_VIDEO_RTP_ENV_HEIGHT, VIDEO_FORMAT_RGB24, &tmp_frame);
- video_frame_fill_black(&tmp_frame);
- videoq_frame frm;
- frm.data = tmp_frame.data[0];
- video_cap->rtp_shm_queue->GetVideo(&frm, 0);
- video_frame_save_bmpfile("rtp_videoqueue_abc.bmp", &tmp_frame);
- video_frame_free(&tmp_frame);
- //video_frame_save_bmpfile("d:\\ab.bmp", &rtp_frame);
- i++;
- }
- #endif
- video_frame_free(&rtp_frame);
- }
- //Dbg("end env on frame, id=%d, tick=%d", video_cap->frame_id, GetTickCount());;
- }
- static void opt_cap_on_frame(void *user_data, video_frame *frame)
- {
- video_capture_t *video_cap = (video_capture_t *)user_data;
- capture_t *cap = video_cap->parent;
- int rc;
-
- int rotate = 0;
- //Dbg("opt on frame!");
- if (cap->config.video_opt_rotate == 90) {
- rotate = 1;
- } else if (cap->config.video_opt_rotate == 270) {
- rotate = -1;
- } else {
- Dbg("video_opt_rotate is not 90 or 270 return.");
- return;
- }
- video_cap->frame_id++;
- #ifdef RVC_OS_WIN // use IPP, it's fast
- // prepare for rotation
- video_frame rframe;
- video_frame_alloc(frame->height, frame->width, frame->format, &rframe);
- {
- IppiSize srcSize;
- srcSize.width = frame->width;
- srcSize.height = frame->height;
- IppiRect srcROI;
- srcROI.width = frame->width;
- srcROI.height = frame->height;
- srcROI.x = 0;
- srcROI.y = 0;
- IppiRect dstROI;
- dstROI.width = frame->height;
- dstROI.height = frame->width;
- dstROI.x = 0;
- dstROI.y = 0;
- ippiTranspose_8u_C3R(frame->data[0], frame->linesize[0], rframe.data[0], rframe.linesize[0], srcSize);
- IppiAxis flip;
- if (rotate == 1)
- {
- flip = ippAxsVertical;
- ippiMirror_8u_C3IR(rframe.data[0], rframe.linesize[0], srcSize, flip);
- }
- else
- {
- IppiSize Size;
- Size.width = rframe.width;
- Size.height = rframe.height;
- //flip = ippAxsHorizontal;
- flip = ippAxsBoth;
- ippiMirror_8u_C3IR(rframe.data[0], rframe.linesize[0], Size, flip);
- }
- }
- rc = video_shm_enqueue(video_cap->snapshot_shm_queue, &rframe, 0);
- #else
- rc = video_shm_enqueue(video_cap->snapshot_shm_queue, frame, 0);
- #endif
- if (rc != Error_Succeed)
- {
- Dbg("opt snapshot queue enqueue shm failed! Error = %d, camera_type=%d", rc, video_cap->camera_type);
- }
- else {
- //Dbg("opt snapshot queue enqueue[%d] success, and current video queue len is %d.", video_cap->frame_id, video_cap->snapshot_shm_queue->GetVideoLens());
- }
- //static int isnapshot_shm_queue = 0;
- //if (isnapshot_shm_queue == 0) {
- // video_frame_save_bmpfile("opt_snapshot_shm_queue.bmp", &rframe);
- // isnapshot_shm_queue++;
- //}
- // snapshot
- if (rc==Error_Succeed)
- {
- if (*cap->config.ref_opt_capture_count)
- {
- Dbg("opt camera ref_opt_capture_count=%d",*cap->config.ref_opt_capture_count);
- #ifdef RVC_OS_WIN
- InterlockedDecrement(cap->config.ref_opt_capture_count);
- #else
- //__sync_fetch_and_sub(cap->config.ref_opt_capture_count, 1);
- pthread_mutex_lock(cap->config.opt_mutex);
- *(cap->config.ref_opt_capture_count) -= 1;
- pthread_mutex_unlock(cap->config.opt_mutex);
- #endif
- LogEvent(Severity_Middle, MOD_EVENT_MEDIACONTROLLER_FINISHED_CAPTURE_OPT, "agent capture opt ok, and capture opt finished!");
- }
- else if (*cap->config.ref_envopt_capture_count&1)
- {
- Dbg("opt camera ref_envopt_capture_count=%d", *cap->config.ref_envopt_capture_count);
- #ifdef RVC_OS_WIN
- if (InterlockedDecrement(cap->config.ref_envopt_capture_count) == 0)
- #else
- //__sync_fetch_and_sub(cap->config.ref_envopt_capture_count,1);
- pthread_mutex_lock(cap->config.envopt_mutex);
- *(cap->config.ref_envopt_capture_count) -= 1;
- pthread_mutex_unlock(cap->config.envopt_mutex);
- if (0 == *cap->config.ref_envopt_capture_count)
- #endif
- {
- LogEvent(Severity_Middle, MOD_EVENT_MEDIACONTROLLER_FINISHED_CAPTURE_ENVOPT, "agent capture opt ok, and capture envopt finished!");
- }
- }
- }
- // rtp
- {
- video_frame rtp_frame = {0};
- video_frame_alloc(REC_COMMON_VIDEO_RTP_OPT_WIDTH, REC_COMMON_VIDEO_RTP_OPT_HEIGHT, VIDEO_FORMAT_RGB24, &rtp_frame);
- #ifdef RVC_OS_WIN
- sws_scale(video_cap->rtp_sws_ctx, rframe.data, rframe.linesize, 0, rframe.height, rtp_frame.data, rtp_frame.linesize);
- #else
- sws_scale(video_cap->rtp_sws_ctx, frame->data, frame->linesize, 0, frame->height, rtp_frame.data, rtp_frame.linesize);
- #endif
-
- rc = video_shm_enqueue(video_cap->rtp_shm_queue, &rtp_frame, 0);
- if (rc != Error_Succeed)
- {
- Dbg("rtp_shm_queue enqueue shm failed! Error = %d, camera_type=%d", rc, video_cap->camera_type);
- }
- else {
- //Dbg("opt rtp_shm_queue enqueue[%d] success, and current video queue len is %d.", video_cap->frame_id, video_cap->rtp_shm_queue->GetVideoLens());
- }
- //static int irtp_frame = 0;
- //if (irtp_frame == 0){
- // video_frame_save_bmpfile("opt_rtp_shm_queue.bmp", &rtp_frame);
- // irtp_frame++;
- //}
- video_frame_free(&rtp_frame);
- }
- #ifdef RVC_OS_WIN
- video_frame_free(&rframe);
- #endif
- }
- static video_capture_t *video_capture_create(capture_t *cap, int camera_type)
- {
- video_capture_t *video_cap = ZALLOC_T(video_capture_t);
- if (video_cap) {
- video_cap->parent = cap;
- video_cap->camera_type = camera_type;
- video_cap->frame_id = 0;
-
- if (camera_type == CAMERA_TYPE_ENV) {
- //video_cap->render_shm_queue = new Clibvideoqueue(REC_COMMON_VIDEO_ENV_SHM_RENDER_QUEUE);
- //video_cap->opt_render_shm_queue = new Clibvideoqueue(REC_COMMON_VIDEO_OPT_SHM_RENDER_QUEUE);
- video_cap->snapshot_shm_queue = new Clibvideoqueue(REC_COMMON_VIDEO_ENV_SHM_SNAPSHOT_QUEUE);
- video_cap->rtp_shm_queue = new Clibvideoqueue(REC_COMMON_VIDEO_ENV_SHM_RTP_QUEUE);
- video_cap->rtp_sws_ctx = sws_getContext(REC_COMMON_VIDEO_SNAPSHOT_WIDTH,
- REC_COMMON_VIDEO_SNAPSHOT_HEIGHT,
- AV_PIX_FMT_BGR24,
- REC_COMMON_VIDEO_RTP_ENV_WIDTH,
- REC_COMMON_VIDEO_RTP_ENV_HEIGHT,
- AV_PIX_FMT_BGR24,
- SWS_POINT, NULL, NULL, NULL);
- video_cap->preview_shm_queue = new Clibvideoqueue(REC_COMMON_VIDEO_ENV_SHM_PREVIEW_QUEUE);
- video_cap->preview_sws_ctx = sws_getContext(REC_COMMON_VIDEO_SNAPSHOT_PREVIEW_WIDTH,
- REC_COMMON_VIDEO_SNAPSHOT_PREVIEW_HEIGHT,
- AV_PIX_FMT_BGR24,
- REC_COMMON_VIDEO_PREVIEW_WIDTH,
- REC_COMMON_VIDEO_PREVIEW_HEIGHT,
- AV_PIX_FMT_BGR24,
- SWS_FAST_BILINEAR, NULL, NULL, NULL);
- } else {
- //video_cap->render_shm_queue = new Clibvideoqueue(REC_COMMON_VIDEO_ENV_SHM_RENDER_QUEUE);
- //video_cap->opt_render_shm_queue = new Clibvideoqueue(REC_COMMON_VIDEO_OPT_SHM_RENDER_QUEUE);
- video_cap->snapshot_shm_queue = new Clibvideoqueue(REC_COMMON_VIDEO_OPT_SHM_SNAPSHOT_QUEUE);
- video_cap->rtp_shm_queue = new Clibvideoqueue(REC_COMMON_VIDEO_OPT_SHM_RTP_QUEUE);
- video_cap->rtp_sws_ctx = sws_getContext(REC_COMMON_VIDEO_SNAPSHOT_HEIGHT,
- REC_COMMON_VIDEO_SNAPSHOT_WIDTH,
- AV_PIX_FMT_BGR24,
- REC_COMMON_VIDEO_RTP_OPT_WIDTH,
- REC_COMMON_VIDEO_RTP_OPT_HEIGHT,
- AV_PIX_FMT_BGR24,
- SWS_POINT, NULL, NULL, NULL);
- //video_cap->preview_shm_queue = NULL;
- //video_cap->preview_sws_ctx = NULL;
- }
- }
- return video_cap;
- }
- static void video_capture_destroy(video_capture_t *video_cap)
- {
- if (video_cap) {
- if (video_cap->preview_sws_ctx) {
- sws_freeContext(video_cap->preview_sws_ctx);
- video_cap->preview_sws_ctx = NULL;
- }
- if (video_cap->rtp_sws_ctx) {
- sws_freeContext(video_cap->rtp_sws_ctx);
- video_cap->rtp_sws_ctx = NULL;
- }
- if (video_cap->snapshot_shm_queue) {
- delete video_cap->snapshot_shm_queue;
- video_cap->snapshot_shm_queue = NULL;
- }
- if (video_cap->rtp_shm_queue) {
- delete video_cap->rtp_shm_queue;
- video_cap->rtp_shm_queue = NULL;
- }
- if (video_cap->preview_shm_queue) {
- delete video_cap->preview_shm_queue;
- video_cap->preview_shm_queue = NULL;
- }
- //if (video_cap->render_shm_queue) {
- // delete video_cap->render_shm_queue;
- // video_cap->render_shm_queue = NULL;
- //}
- //if (video_cap->opt_render_shm_queue) {
- // delete video_cap->opt_render_shm_queue;
- // video_cap->opt_render_shm_queue = NULL;
- //}
- free(video_cap);
- }
- }
- static int get_video_capture_fps(int icapfps)
- {
- int ifps = REC_COMMON_VIDEO_PADRAW_FPS;
- if ((ePadtype == g_eDeviceType) || (eMobilePadType == g_eDeviceType) || (eDesk2SType == g_eDeviceType)
- || (eDesk1SType == g_eDeviceType) || (eDesk2SIntegratedType == g_eDeviceType)){
- ifps = REC_COMMON_VIDEO_PADRAW_FPS;
- }
- else{
- ifps = REC_COMMON_VIDEO_RAW_FPS;
- }
- if (icapfps <=30 && icapfps >=5){
- ifps = icapfps;
- }
- return ifps;
- }
- #ifdef RVC_OS_WIN
- static int video_capture_start_win(video_capture_t* video_cap)
- {
- capture_config_t* conf = &video_cap->parent->config;
- int dev_id;
- if (video_cap->camera_type == CAMERA_TYPE_ENV)
- {
- dev_id = capture_get_video_device_id(conf->strVideoEnv);
- if (dev_id == -1)
- {
- Dbg("No environment camera,please check config file or device!");
- return -1;
- }
- }
- else
- {
- dev_id = capture_get_video_device_id(conf->strVideoOpt);
- if (dev_id == -1)
- {
- Dbg("No operation camera,please check config file or device!");
- return -1;
- }
- }
- videocap_param param = { 0 };
- int cap_mode;
- int rc = -1;
- rc = calc_capture_mode(REC_COMMON_VIDEO_SNAPSHOT_WIDTH, REC_COMMON_VIDEO_SNAPSHOT_HEIGHT, &cap_mode);
- if (rc != 0)
- {
- Dbg("calc cap_mode failed!");
- return rc;
- }
- param.cap_mode = cap_mode;
- param.dev_id = dev_id;
- param.frame_fmt = VIDEO_FORMAT_RGB24;
- if ((ePadtype == g_eDeviceType) || (eMobilePadType == g_eDeviceType) || (eDesk2SType == g_eDeviceType) || (eDesk1SType == g_eDeviceType) || (eDesk2SIntegratedType == g_eDeviceType))
- {
- param.fps = REC_COMMON_VIDEO_PADRAW_FPS;
- }
- else
- {
- param.fps = REC_COMMON_VIDEO_RAW_FPS;
- }
- param.on_frame = (video_cap->camera_type == CAMERA_TYPE_ENV ? &env_cap_on_frame : &opt_cap_on_frame);
- param.user_data = video_cap;
- param.option = 0;
- rc = videocap_create(&video_cap->cap, ¶m);
- if (rc != 0)
- {
- Dbg("videocap create failed!");
- return rc;
- }
- rc = videocap_start(video_cap->cap);
- if (rc != 0)
- {
- Dbg("videocap start failed!");
- videocap_destroy(video_cap->cap);
- video_cap->cap = NULL;
- return rc;
- }
- else {
- Dbg("videocap start success!");
- }
- return 0;
- }
- #else
- static void __videocaplog(void* user_data, const char* fmt, va_list arg)
- {
- vDbg(fmt, arg);
- }
- static void __logevent(int itype, const char* strmessage)
- {
- if (0 == itype) {
- LogWarn(Severity_Middle, Error_Debug, LOG_EVT_MEDIACONTROLLER_CAMERA_MATCHED_FORMAT, strmessage);
- }
- else if (1 == itype) {
- LogWarn(Severity_Middle, Error_Debug, LOG_EVT_MEDIACONTROLLER_CAMERA_OUTPUT_FORMAT, strmessage);
- }
- else {
- Dbg("unknown type event.");
- }
- }
- static int video_capture_start_linux(video_capture_t* video_cap)
- {
- LOG_FUNCTION();
- int iret = -1;
- capture_config_t* conf = &video_cap->parent->config;
- int dev_id = -1;
- if (video_cap->camera_type == CAMERA_TYPE_ENV){
- dev_id = rvc_videocap_get_video_device_id(conf->strVideoEnv.GetData());
- if (-1 == dev_id){
- Dbg("No environment camera[%s], please check config file or device!", conf->strVideoEnv.GetData());
- return iret;
- }
- }
- else{
- dev_id = rvc_videocap_get_video_device_id(conf->strVideoOpt.GetData());
- if (-1 == dev_id){
- Dbg("No operation camera[%s], please check config file or device!", conf->strVideoOpt.GetData());
- return iret;
- }
- }
- Dbg("video dev_id is %d", dev_id);
- videocap_param_t t_param = { 0 };
- int cap_mode;
- int rc = calc_capture_mode(REC_COMMON_VIDEO_SNAPSHOT_WIDTH, REC_COMMON_VIDEO_SNAPSHOT_HEIGHT, &cap_mode);
- if (rc != 0){
- Dbg("calc cap_mode failed!");
- return iret;
- }
- else{
- Dbg("cap_mode == %d.",cap_mode);
- }
- t_param.cap_mode = cap_mode;
- t_param.dev_id = dev_id;
- t_param.frame_fmt = VIDEO_FORMAT_RGB24;
- t_param.fps = get_video_capture_fps(video_cap->camera_type == CAMERA_TYPE_ENV ? conf->video_env_fps : conf->video_opt_fps);
- t_param.irotate = (video_cap->camera_type == CAMERA_TYPE_ENV ? conf->video_env_rotate : conf->video_opt_rotate);
- t_param.on_frame = (video_cap->camera_type == CAMERA_TYPE_ENV ? &env_cap_on_frame : &opt_cap_on_frame);
- //t_param.on_frame_i420 = (video_cap->camera_type == CAMERA_TYPE_ENV ? &env_cap_on_frame_i420 : &opt_cap_on_frame_i420);
- t_param.user_data = video_cap;
- t_param.option = 0;
- videocap_callback_t t_callback = { 0 };
- t_callback.debug = &__videocaplog;
- t_callback.logevent = &__logevent;
- video_cap->pVideoCap = CreateVideoCaptureObj(&t_callback);
- if (NULL != video_cap->pVideoCap){
- if (0 == video_cap->pVideoCap->VideoCaptureSetParam(&t_param)) {
- Dbg("VideoCap SetVideoCaptureParam success!");
- if (0 == video_cap->pVideoCap->StartVideoCapture()) {
- Dbg("VideoCap StartVideoCapture success!");
- iret = 0;
- }
- else {
- Dbg("VideoCap StartVideoCapture failed!");
- DestroyVideoCaptureObj(video_cap->pVideoCap);
- }
- }
- else {
- Dbg("VideoCap SetVideoCaptureParam failed!");
- DestroyVideoCaptureObj(video_cap->pVideoCap);
- }
- }
- else{
- Dbg(" CreateVideoCaptureObj failed!");
- }
- return iret;
- }
- #endif // RVC_OS_WIN
- static int video_capture_start(video_capture_t *video_cap)
- {
- #ifdef RVC_OS_WIN
- return video_capture_start_win(video_cap);
- #else
- return video_capture_start_linux(video_cap);
- #endif
- }
- static void video_capture_stop(video_capture_t *video_cap)
- {
- #ifdef RVC_OS_WIN
- if (video_cap->cap) {
- videocap_stop(video_cap->cap);
- videocap_destroy(video_cap->cap);
- video_cap->cap = NULL;
- }
- #else
- if (video_cap->pVideoCap) {
- video_cap->pVideoCap->StopVideoCapture();
- DestroyVideoCaptureObj(video_cap->pVideoCap);
- video_cap->pVideoCap = NULL;
- }
- #endif // RVC_OS_WIN
- }
- namespace MediaController {
- DeviceTypeEnum g_eDeviceType;
- int capture_create(const capture_config_t *config, capture_t **p_cap)
- {
- capture_t *cap = ZALLOC_T(capture_t);
- cap->audio = NULL;
- cap->env_video = NULL;
- cap->opt_video = NULL;
- memcpy(&cap->config, config, sizeof(capture_config_t));
- cap->audio = audio_capture_create(cap);
- if (!cap->audio) {
- Dbg("create audio capture object failed!");
- return Error_Unexpect;
- }
- int dev_id_env = capture_get_video_device_id(config->strVideoEnv);
- if (dev_id_env != -1) {
- cap->env_video = video_capture_create(cap, CAMERA_TYPE_ENV);
- if (!cap->env_video) {
- Dbg("create env video object failed!");
- return Error_Unexpect;
- }
- }
- int dev_id_opt = -1;
- if (eStand2sType == g_eDeviceType){
- dev_id_opt = capture_get_video_device_id(config->strVideoOpt);
- }
- if (dev_id_opt != -1){
- cap->opt_video = video_capture_create(cap, CAMERA_TYPE_OPT);
- if (!cap->opt_video) {
- Dbg("create opt video object failed!");
- return Error_Unexpect;
- }
- }
- if((dev_id_env == -1)&&(dev_id_opt == -1)){
- Dbg("all camera device id error!");
- capture_destroy(cap);
- return Error_Unexpect;
- }
- else{
- *p_cap = cap;
- return 0;
- }
- }
- ErrorCodeEnum capture_create(const capture_config_t *config,capture_t *cap,int nCamera)
- {
- int dev_id1 = capture_get_video_device_id(config->strVideoEnv);
- int dev_id2 = capture_get_video_device_id(config->strVideoOpt);
- if((dev_id1 != -1)&&(nCamera==ENVCAMERA)&&(cap->env_video == NULL))
- {
- cap->env_video = video_capture_create(cap, CAMERA_TYPE_ENV);
- if (!cap->env_video)
- {
- Dbg("create env video object failed!");
- return Error_Unexpect;
- }
- }
- else if((dev_id2 != -1)&&(nCamera == OPTCAMERA)&&(cap->opt_video == NULL))
- {
- cap->opt_video = video_capture_create(cap, CAMERA_TYPE_OPT);
- if (!cap->opt_video)
- {
- Dbg("create opt video object failed!");
- return Error_Unexpect;
- }
- }
- else
- {
- return Error_Unexpect;
- }
- return Error_Succeed;
- }
- int salesaudio_capture_create(rvc_audio_capture_config_t *config, rvc_sales_audio_capture_t **p_cap)
- {
- rvc_sales_audio_capture_t *cap = ZALLOC_T(rvc_sales_audio_capture_t);
- cap->rvc_audio = NULL;
- memcpy(&cap->rvc_audio_config, config, sizeof(rvc_audio_capture_config_t));
- cap->rvc_audio = salesrecord_audio_capture_create(cap);
- if (!cap->rvc_audio) {
- Dbg("create sales record audio capture object failed!");
- salesaudio_capture_destroy(cap);
- cap = NULL;
- return Error_Unexpect;
- }
- else
- {
- cap->rvc_audio->iaudio_capture_peroid = config->audio_capture_period;
- cap->rvc_audio->iaudio_capture_samplerate = config->audio_capture_samplerate;
- *p_cap = cap;
- Dbg("create sales record audio capture object(0x%08x) success, capture sample rate is %d, and rvc audio(0x%08x) in device is %s.",
- cap, cap->rvc_audio->iaudio_capture_samplerate, cap->rvc_audio, cap->rvc_audio_config.strAudioIn.GetData());
- return 0;
- }
- }
- void salesaudio_capture_destroy(rvc_sales_audio_capture_t *cap)
- {
- if (NULL != cap){
- Dbg("sales audio capture destroy, and cap addr is 0x%08x.", cap);
- if (cap->rvc_audio) {
- Dbg("sales audio capture rvc_audio destroy, and rvc_audio addr is 0x%08x.", cap->rvc_audio);
- salesrecord_audio_capture_destroy(cap->rvc_audio);
- cap->rvc_audio = NULL;
- Dbg("set rvc_audio to null.");
- }
- free(cap);
- }
- }
- void capture_destroy(capture_t *cap)
- {
- if (cap) {
- if (cap->env_video) {
- video_capture_destroy(cap->env_video);
- cap->env_video = NULL;
- }
- if (cap->opt_video) {
- video_capture_destroy(cap->opt_video);
- cap->opt_video = NULL;
- }
- if (cap->audio) {
- audio_capture_destroy(cap->audio);
- cap->audio = NULL;
- }
- free(cap);
- }
- }
- void capture_destroy(capture_t *cap,int nCamera)
- {
- if (cap)
- {
- if((cap->env_video)&&(nCamera == ENVCAMERA))
- {
- video_capture_destroy(cap->env_video);
- cap->env_video = NULL;
- }
- else if((cap->opt_video)&&(nCamera==OPTCAMERA))
- {
- video_capture_destroy(cap->opt_video);
- cap->opt_video = NULL;
- }
- }
- }
- ErrorCodeEnum start_audio_capture(audio_capture_t *paudio)
- {
- ErrorCodeEnum rslt = Error_Succeed;
- int rc = 0;
- if (NULL != paudio) {
- rc = audio_capture_start(paudio);
- if (rc != Error_Succeed) {
- rslt = (ErrorCodeEnum)rc;
- if (rslt == Error_AudioIN){
- Dbg("start audio In object failed! rc:%d", rc);
- LogError(Severity_High,Error_NotInit,ERROR_MOD_MEDIACONTROLLER_HANDFREE_OPENFAIL,"open audioIn device fail,please check device");
- }
- else{
- Dbg("start audio Out object failed! rc:%d", rc);
- LogError(Severity_High,Error_NotInit,ERROR_MOD_MEDIACONTROLLER_HANDFREE_OPENFAIL,"open audioOut device fail,please check device");
- }
- }
- else{
- Dbg("audio capture start success.");
- }
- }
- else{
- Dbg("audio_capture_t is null.");
- rslt = Error_AudioIN;
- }
- return rslt;
- }
- ErrorCodeEnum capture_start(capture_t *cap)
- {
- int rc = 0;
- ErrorCodeEnum rslt = start_audio_capture(cap->audio);
- if (Error_Succeed != rslt) {
- return rslt;
- }
- if (cap->env_video)
- {
- rc = video_capture_start(cap->env_video);
- if (rc != Error_Succeed)
- {
- Dbg("start env video capture object failed! rc:%d", rc);
- char strMessage[MAX_PATH*2] = {0};
- get_camera_exception_message(strMessage, MAX_PATH*2, cap->config.strVideoEnv, "open environ camera fail,please check device.");
- LogWarn(Severity_Middle,Error_NotInit,ERROR_MOD_MEDIACONTROLLER_ENVCAM_OPEN,strMessage);
- if (cap->opt_video)
- {
- if (cap->env_video)
- {
- ::Sleep(3000);
- }
- rc = video_capture_start(cap->opt_video);
- if (rc != Error_Succeed)
- {
- Dbg("start opt video capture object failed! rc:%d", rc);
- char strMessage[MAX_PATH*2] = {0};
- get_camera_exception_message(strMessage, MAX_PATH*2, cap->config.strVideoOpt, "open operate camera fail,please check device.");
- LogWarn(Severity_Middle,Error_NotInit,ERROR_MOD_MEDIACONTROLLER_OPTCAM_OPEN, strMessage);
- return Error_AllCamera;
- }
- else
- {
- Dbg("start env video capture object failed!");
- return Error_EnvCamera;
- }
- }
- else
- {
- Dbg("start all video capture object failed!");
- return Error_AllCamera;
- }
- }
- else
- {
- if (cap->opt_video)
- {
- if (cap->env_video)
- {
- ::Sleep(3000);
- }
- rc = video_capture_start(cap->opt_video);
- if (rc != Error_Succeed)
- {
- Dbg("start opt video capture object failed! rc:%d", rc);
- char strMessage[MAX_PATH*2] = {0};
- get_camera_exception_message(strMessage, MAX_PATH*2, cap->config.strVideoOpt, "open operate camera fail,please check device.");
- LogWarn(Severity_Middle,Error_NotInit,ERROR_MOD_MEDIACONTROLLER_OPTCAM_OPEN,strMessage);
- return Error_OptCamera;
- }
- else
- {
- return Error_Succeed;
- }
- }
- else
- {
- Dbg("opt_video = Null");
- return Error_OptCamera;
- }
- }
- }
- else
- {
- if (cap->opt_video)
- {
- if (cap->env_video)
- {
- ::Sleep(3000);
- }
- rc = video_capture_start(cap->opt_video);
- if (rc != Error_Succeed)
- {
- Dbg("start opt video capture object failed! rc:%d", rc);
- char strMessage[MAX_PATH*2] = {0};
- get_camera_exception_message(strMessage, MAX_PATH*2, cap->config.strVideoOpt, "open operate camera fail,please check device.");
- LogWarn(Severity_Middle,Error_NotInit,ERROR_MOD_MEDIACONTROLLER_OPTCAM_OPEN,strMessage);
- return Error_AllCamera;
- }
- else
- {
- Dbg("start env video capture object failed!");
- return Error_EnvCamera;
- }
- }
- else
- {
- Dbg("start env video Error_AllCamera");
- return Error_AllCamera;
- }
- }
- }
- ErrorCodeEnum capture_start(capture_t *cap,int nCamera)
- {
- int rc = 0;
- if (cap->env_video&&(nCamera==ENVCAMERA))
- {
- rc = video_capture_start(cap->env_video);
- if (rc != Error_Succeed)
- {
- return Error_Hardware;
- }
- else
- {
- return Error_Succeed;
- }
- }
- else if(cap->opt_video&&(nCamera==OPTCAMERA))
- {
- rc = video_capture_start(cap->opt_video);
- if (rc != Error_Succeed)
- {
- return Error_Hardware;
- }
- else
- {
- return Error_Succeed;
- }
- }
- else
- {
- return Error_Unexpect;
- }
- }
- ErrorCodeEnum salesrecord_audio_capture_start(rvc_sales_audio_capture_t *cap)
- {
- auto rc = Error_Param;
- if (NULL == cap){
- return rc;
- }
- if (cap->rvc_audio) {
- audiomgr_callback_t t_callback = { 0 };
- t_callback.debug = &__audiomgrlog;
- cap->rvc_audio->paudiocap = CreateAudioMgrObj(&t_callback);
- if (0 == cap->rvc_audio->paudiocap->audio_mgr_initialize()) {
- Dbg("audio manager initialize success!");
- }
- else {
- Dbg("audio manager initialize failed!");
- return Error_Null;
- }
- int rslt = record_audio_capture_start(cap->rvc_audio);
- if (rslt != Error_Succeed) {
- if (Error_AudioIN == rslt){
- Dbg("start audio In object failed! rc:%d", rc);
- LogError(Severity_High,Error_NotInit,ERROR_MOD_MEDIACONTROLLER_HANDFREE_OPENFAIL,"open audioIn device fail,please check device");
- }
- rc = (ErrorCodeEnum)rslt;
- }
- else{
- rc = Error_Succeed;
- }
- }
- return rc;
- }
- void salesrecord_audio_capture_stop(rvc_sales_audio_capture_t *cap)
- {
- if (NULL != cap){
- if (cap->rvc_audio){
- if (cap->rvc_audio->pdata){
- if (eSingleWriteLocal == cap->rvc_audio->eType){
- fclose((FILE*)cap->rvc_audio->pdata);
- cap->rvc_audio->pdata = NULL;
- }
- }
- record_audio_capture_stop(cap->rvc_audio);
- }
- }
- else{
- Dbg("sales record audio capture stop failed for param error.");
- }
- }
- void capture_stop(capture_t *cap)
- {
- if (cap->audio) {
- audio_capture_stop(cap->audio);
- }
- if (cap->env_video) {
- video_capture_stop(cap->env_video);
- }
- if (cap->opt_video) {
- video_capture_stop(cap->opt_video);
- }
- }
- int capture_detect_camera_bug(capture_t *cap, int *env_n, int *opt_n,BOOL IsPad)
- {
- *env_n = 0;
- *opt_n = 0;
- if (cap->env_video)
- {
- if (cap->env_video->rtp_shm_queue)
- {
- *env_n = cap->env_video->rtp_shm_queue->GetVideoLens();
- }
- }
- else
- {
- *env_n = -1;
- }
- if (cap->opt_video)
- {
- if (cap->opt_video->rtp_shm_queue)
- {
- *opt_n = cap->opt_video->rtp_shm_queue->GetVideoLens();
- }
- }
- else
- {
- if (!IsPad)
- {
- *opt_n = -1;
- }
- else
- {
- *opt_n = 1;
- }
- }
- return 0;
- }
- int capture_get_last_frametime(capture_t *cap, DWORD *env_n, DWORD *opt_n,BOOL IsPad)
- {
- *env_n = 0;
- *opt_n = 0;
- if (cap->env_video)
- {
- if (cap->env_video->rtp_shm_queue)
- {
- *env_n = cap->env_video->rtp_shm_queue->GetLastFrameTime();
- }
- }
- else
- {
- *env_n = 0;
- }
- if (cap->opt_video)
- {
- if (cap->opt_video->rtp_shm_queue)
- {
- *opt_n = cap->opt_video->rtp_shm_queue->GetLastFrameTime();
- }
- }
- else
- {
- *opt_n = 0;
- }
- return 0;
- }
- int capture_get_video_device_id(const char *dev_name)
- {
- #ifdef RVC_OS_WIN
- int n = videocap_get_device_count();
- for (int i = 0; i < n; ++i) {
- WCHAR tmp[256];
- char t[256];
- WCHAR tmp1[256];
- char t1[256];
- videocap_get_device_name(i, tmp, ARRAYSIZE(tmp));
- WideCharToMultiByte(CP_ACP, 0, tmp, -1, t, sizeof(t), 0, NULL);
- videocap_get_device_path(i, tmp1, ARRAYSIZE(tmp1));
- WideCharToMultiByte(CP_ACP, 0, tmp1, -1, t1, sizeof(t1), 0, NULL);
- // save DevicePath (add by ly at 20160725)
- char t2[256];
- strcpy(t2,t1);
- for (int j = 0; j < strlen(t2); ++j)
- {
- t2[j] = toupper(t2[j]);
- if (t2[j] == '#') t2[j] = '\\';
- }
- {
- unsigned char x[MD5_DIGESTSIZE];
- md5_ctx_t ctx;
- md5_init(&ctx);
- md5(x, t1, strlen(t1));
- Bin2Str(x, sizeof(x), t1, sizeof(t1));
- }
-
- if (dev_name != NULL && strlen(dev_name) > 1 &&
- strstr(dev_name, ";") == NULL) // 外接摄像头 add by ly at 20160531
- {
- /*if (strstr(t, dev_name) != NULL)
- {
- Dbg("[dbg] %s founded in %d cameras.", dev_name, n);
- return i;
- }*/
- Dbg("[dbg] device_path: %s",t2);
- if (strstr(t2,dev_name) != NULL) // 判断外接摄像头DeviceLocationPaths是否是DevicePath的子串
- {
- Dbg("[dbg] %s founded in %d cameras.", dev_name, n);
- return i;
- }
- if (strcmp(dev_name, t) == 0) // 如果是直接用友好名称查询(适用于高拍仪) add by ly 2017/11/08
- return i;
- }
- else
- {
- strcat(t, ";");
- strcat(t, t1);
- if (strcmp(dev_name, t) == 0)
- return i;
- }
- }
- return -1; // not found
- #else
- return rvc_videocap_get_video_device_id(dev_name);
- #endif // RVC_OS_WIN
-
- }
- int capture_lib_init() // edit by ly at 20160401
- {
- #ifdef RVC_OS_WIN
- HRESULT hr = CoInitialize(NULL);
- int rc;
- {
- 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");
- }
- }
- if (SUCCEEDED(hr)) {
- PaError Error;
- Error = Pa_Initialize();
- if (Error == paNoError) {
- rc = videoframework_init();
- if (rc != 0) {
- Dbg("videoframework_init failed, rc=%d", rc);
- return Error_Resource;
- }
- }
- else {
- Dbg("PaInitialize failed, rc=%d", Error);
- return Error_Resource;
- }
- }
- else {
- Dbg("coinitialze failed! hr:%d", hr);
- return Error_Resource;
- }
- {
- int i, n;
- n = videocap_get_device_count();
- for (i = 0; i < n; ++i) {
- WCHAR tmp[256];
- char t[256];
- WCHAR tmp1[256];
- char t1[256];
- videocap_get_device_name(i, tmp, ARRAYSIZE(tmp));
- WideCharToMultiByte(CP_ACP, 0, tmp, -1, t, sizeof(t), 0, NULL);
- videocap_get_device_path(i, tmp1, ARRAYSIZE(tmp1));
- WideCharToMultiByte(CP_ACP, 0, tmp1, -1, t1, sizeof(t1), 0, NULL);
- {
- unsigned char x[MD5_DIGESTSIZE];
- md5_ctx_t ctx;
- md5_init(&ctx);
- md5(x, t1, strlen(t1));
- Bin2Str(x, sizeof(x), t1, sizeof(t1));
- }
- Dbg("%d = %s;%s", i, t, t1);
- }
- }
- {
- int icnt, ocnt;
- int rc = audio_get_dev_count(&icnt, &ocnt);
- if (rc == 0) {
- int i;
- Dbg("audio input devices(%d):", icnt);
- for (i = 0; i < icnt; ++i) {
- CSimpleStringA str = audio_get_dev_name(true, i);
- Dbg("%d = %s", i, (LPCSTR)str);
- }
- Dbg("audio output devices(%d):", ocnt);
- for (i = 0; i < ocnt; ++i) {
- CSimpleStringA str = audio_get_dev_name(false, i);
- Dbg("%d = %s", i, (LPCSTR)str);
- }
- }
- }
- #else
- {
- int inumber = 0;
- int icount = rvc_videocap_get_device_count();
- for (int i = 0; i < 64 && inumber < icount; ++i) {
- char strcamera[2 * MAX_PATH] = { 0 };
- char strpath[MAX_PATH] = { 0 };
- if (0 == rvc_videocap_get_device_fullpathname(i, strcamera, 2 * MAX_PATH)){
- Dbg("%d = %s", inumber++, strcamera);
- }
- }
- }
- #endif // RVC_OS_WIN
- return Error_Succeed;
- }
- int videocap_innerdev_fetch(CSimpleStringA&frontcam,CSimpleStringA&rearcam) // edit by ly at 20160401
- {
- int i = 0, n = 0;
- #ifdef RVC_OS_WIN
- frontcam = "$", rearcam = "$";
- n = videocap_get_device_count();
- if (n == 2) // 未插入外接时
- {
- for (i = 0; i < n; ++i) {
- WCHAR tmp[256];
- char t[256];
- WCHAR tmp1[256];
- char t1[256];
- videocap_get_device_name(i, tmp, ARRAYSIZE(tmp));
- WideCharToMultiByte(CP_ACP, 0, tmp, -1, t, sizeof(t), 0, NULL);
- videocap_get_device_path(i, tmp1, ARRAYSIZE(tmp1));
- WideCharToMultiByte(CP_ACP, 0, tmp1, -1, t1, sizeof(t1), 0, NULL);
- {
- unsigned char x[MD5_DIGESTSIZE];
- md5_ctx_t ctx;
- md5_init(&ctx);
- md5(x, t1, strlen(t1));
- Bin2Str(x, sizeof(x), t1, sizeof(t1));
- }
- strcat(t, ";");
- strcat(t, t1);
- if (i == 0)
- {
- frontcam = t;
- }
- else if (i == 1)
- {
- rearcam = t;
- }
- }
- }
- else
- {
- Dbg("[dbg] detect %d cameras.", n);
- }
- #else
- #endif // RVC_OS_WIN
- return n;
- }
- int videocap_outerdev_fetch( CSimpleStringA envcam,CSimpleStringA optcam,CSimpleStringA ewscam,CAutoArray<CSimpleStringA> &hspcams,CSimpleStringA &outercam )
- {
- int i = 0, n = 0;
- #ifdef RVC_OS_WIN
- outercam = "$";
- n = videocap_get_device_count();
- int m = hspcams.GetCount(); // 高拍仪的个数 add by ly 2017/11/07
- if (ewscam.GetLength() <= 1) // 如果外部广角摄像头未配置
- {
- if (n <= m || n > 3+m)
- {
- Dbg("[dbg] [videocap_outerdev_fetch] detect %d cameras.", n);
- }
- else
- {
- int cnt = 0;
- for (i = 0; i < n; ++i) {
- WCHAR tmp[256];
- char t[256];
- WCHAR tmp1[256];
- char t1[256];
- videocap_get_device_name(i, tmp, ARRAYSIZE(tmp));
- WideCharToMultiByte(CP_ACP, 0, tmp, -1, t, sizeof(t), 0, NULL);
- videocap_get_device_path(i, tmp1, ARRAYSIZE(tmp1));
- WideCharToMultiByte(CP_ACP, 0, tmp1, -1, t1, sizeof(t1), 0, NULL);
- // save DevicePath (add by ly at 20160725)
- char t2[256];
- strcpy(t2,t1);
- for (int j = 0; j < strlen(t2); ++j)
- {
- t2[j] = toupper(t2[j]);
- if (t2[j] == '#') t2[j] = '\\';
- }
- {
- unsigned char x[MD5_DIGESTSIZE];
- md5_ctx_t ctx;
- md5_init(&ctx);
- md5(x, t1, strlen(t1));
- Bin2Str(x, sizeof(x), t1, sizeof(t1));
- }
- // 检查是否为高拍仪摄像头,若是则直接枚举下一个摄像头
- bool isHspCam = false;
- for (int k = 0; k < m; ++k) {
- if (!strcmp((LPCTSTR)hspcams[k],t)) {
- isHspCam = true;
- break;
- }
- }
- if (isHspCam) {
- continue;
- }
- strcat(t, ";");
- strcat(t, t1);
- if(strcmp(t,(LPCTSTR)envcam) && strcmp(t,(LPCTSTR)optcam))
- {
- if (0 == cnt)
- {
- outercam = t2;
- }
- ++cnt;
- }
- }
- if(cnt != 1)
- {
- outercam = "$";
- }
- }
- }
- else // 如果外部广角摄像头已配置
- {
- if (n <= m || n > 4+m)
- {
- Dbg("[dbg] [videocap_outerdev_fetch] detect %d cameras.", n);
- }
- else
- {
- int cnt = 0;
- for (i = 0; i < n; ++i) {
- WCHAR tmp[256];
- char t[256];
- WCHAR tmp1[256];
- char t1[256];
- videocap_get_device_name(i, tmp, ARRAYSIZE(tmp));
- WideCharToMultiByte(CP_ACP, 0, tmp, -1, t, sizeof(t), 0, NULL);
- videocap_get_device_path(i, tmp1, ARRAYSIZE(tmp1));
- WideCharToMultiByte(CP_ACP, 0, tmp1, -1, t1, sizeof(t1), 0, NULL);
- // save DevicePath (add by ly at 20160725)
- char t2[256];
- strcpy(t2,t1);
- for (int j = 0; j < strlen(t2); ++j)
- {
- t2[j] = toupper(t2[j]);
- if (t2[j] == '#') t2[j] = '\\';
- }
- {
- unsigned char x[MD5_DIGESTSIZE];
- md5_ctx_t ctx;
- md5_init(&ctx);
- md5(x, t1, strlen(t1));
- Bin2Str(x, sizeof(x), t1, sizeof(t1));
- }
- // 检查是否为高拍仪摄像头,若是则直接枚举下一个摄像头
- bool isHspCam = false;
- for (int k = 0; k < m; ++k) {
- if (!strcmp((LPCTSTR)hspcams[k],t)) {
- isHspCam = true;
- break;
- }
- }
- if (isHspCam) {
- continue;
- }
- strcat(t, ";");
- strcat(t, t1);
- if(strcmp(t,(LPCTSTR)envcam) && strcmp(t,(LPCTSTR)optcam) && !strstr(t2,(LPCTSTR)ewscam))
- {
- if (0 == cnt)
- {
- outercam = t2;
- }
- ++cnt;
- }
- }
- if(cnt != 1)
- {
- outercam = "$";
- }
- }
- }
- #else
- #endif // RVC_OS_WIN
- return n;
- }
- void capture_enum_cameras(CAutoArray<CSimpleStringA>& cams)
- {
- #if defined(RVC_OS_LINUX)
- cams.Clear();
- CAutoArray<CSimpleStringA> tmp;
- int inumber = 0;
- int icount = rvc_videocap_get_device_count();
- if (icount >= 64) icount = 64;
- tmp.Init(icount);
- for (int i = 0; inumber < icount; ++i) {
- char strcamera[2 * MAX_PATH] = { 0 };
- char strpath[MAX_PATH] = { 0 };
- if (0 == rvc_videocap_get_device_fullpathname(i, strcamera, 2 * MAX_PATH)) {
- tmp[inumber] = strcamera;
- Dbg("%d = %s", inumber++, strcamera);
- }
- }
- cams.Copy(tmp, 0, inumber);
- #endif //RVC_OS_LINUX
- }
- void capture_lib_term()
- {
- #ifdef RVC_OS_WIN
- Pa_Terminate();
- videoframework_term();
- CoUninitialize();
- #else
- #endif // RVC_OS_WIN
- }
- bool capture_adj_brightness(capture_t *cap,int nvalue,ErrorCodeEnum nCode)
- {
- #ifdef RVC_OS_WIN
- HRESULT rst = S_OK;
- if (cap->env_video&&(nCode!=Error_EnvCamera)&&(nCode!=Error_AllCamera))
- {
- rst = videocap_adj_brightness(cap->env_video->cap,nvalue);
- }
- HRESULT rst2 = S_OK;
- if (cap->opt_video->cap&&(nCode!=Error_OptCamera)&&(nCode!=Error_AllCamera))
- {
- rst2 = videocap_adj_brightness(cap->opt_video->cap,nvalue);
- }
- if (SUCCEEDED(rst)&&SUCCEEDED(rst2))
- return true;
- else
- return false;
- #else
- int ienv = -1;
- if (cap->env_video && cap->env_video->pVideoCap && (nCode != Error_EnvCamera) && (nCode != Error_AllCamera)){
- ienv = cap->env_video->pVideoCap->SetCamBrightness(nvalue);
- }
- int iopt = -1;
- if (cap->opt_video && cap->opt_video->pVideoCap && (nCode != Error_OptCamera) && (nCode != Error_AllCamera)){
- iopt = cap->opt_video->pVideoCap->SetCamBrightness(nvalue);
- }
- if (0 == ienv && 0 == iopt){
- return true;
- }
- else{
- return false;
- }
- #endif // RVC_OS_WIN
- }
- bool capture_set_autobrightness(capture_t *cap,ErrorCodeEnum nCode)
- {
- #ifdef RVC_OS_WIN
- HRESULT rst = S_OK;
- HRESULT rst2 = S_OK;
- if (cap->env_video && (nCode != Error_EnvCamera) && (nCode != Error_AllCamera))
- {
- rst = videocap_set_autobrightness(cap->env_video->cap);
- }
- if (cap->opt_video && (nCode != Error_OptCamera) && (nCode != Error_AllCamera))
- {
- rst2 = videocap_set_autobrightness(cap->opt_video->cap);
- }
- if (SUCCEEDED(rst) && SUCCEEDED(rst2))
- return true;
- else
- return false;
- #else
- int ienv = -1;
- int iopt = -1;
- if (cap->env_video && cap->env_video->pVideoCap && (nCode != Error_EnvCamera) && (nCode != Error_AllCamera))
- {
- ienv = cap->env_video->pVideoCap->SetCamAutoBrightness();
- }
- if (cap->opt_video && cap->opt_video->pVideoCap && (nCode != Error_OptCamera) && (nCode != Error_AllCamera))
- {
- iopt = cap->opt_video->pVideoCap->SetCamAutoBrightness();
- }
- if (0 == ienv && 0 == iopt) {
- return true;
- }
- else {
- return false;
- }
-
- #endif // RVC_OS_WIN
- }
- int capture_get_brightness(capture_t *cap,ErrorCodeEnum nCode)
- {
- #ifdef RVC_OS_WIN
- int nValue1 = 0;
- int nValue2 = 0;
- HRESULT rst = S_OK;
- if (cap->env_video && (nCode != Error_EnvCamera) && (nCode != Error_AllCamera))
- {
- HRESULT rst = videocap_get_brightness(cap->env_video->cap, &nValue1);
- }
- HRESULT rst2 = S_OK;
- if (cap->opt_video && (nCode != Error_OptCamera) && (nCode != Error_AllCamera))
- {
- rst2 = videocap_get_brightness(cap->opt_video->cap, &nValue2);
- }
- else
- {
- return -1;
- }
- if ((cap->opt_video == NULL) && cap->env_video)
- {
- return nValue1;
- }
- else if ((cap->env_video == NULL) && cap->opt_video)
- {
- return nValue2;
- }
- else
- {
- if (SUCCEEDED(rst) && SUCCEEDED(rst2))
- return (nValue1 <= nValue2) ? nValue1 : nValue2;
- else
- return -1;
- }
- #else
- int nValue1 = 0;
- int nValue2 = 0;
- int ienv = -1;
- if (cap->env_video && cap->env_video->pVideoCap && (nCode != Error_EnvCamera) && (nCode != Error_AllCamera)){
- ienv = cap->env_video->pVideoCap->GetCamBrightness(&nValue1);
- }
- int iopt = -1;
- if (cap->opt_video && cap->opt_video->pVideoCap && (nCode != Error_OptCamera) && (nCode != Error_AllCamera)){
- iopt = cap->opt_video->pVideoCap->GetCamBrightness(&nValue2);
- }
- else{
- return -1;
- }
- if ((cap->opt_video == NULL) && cap->env_video)
- {
- return nValue1;
- }
- else if ((cap->env_video == NULL) && cap->opt_video)
- {
- return nValue2;
- }
- else
- {
- if (0 == ienv && 0 == iopt) {
- return (nValue1 <= nValue2) ? nValue1 : nValue2;
- }
- else
- {
- return -1;
- }
- }
- #endif // RVC_OS_WIN
- }
- int StopCamera(capture_t *cap,int nCamera)
- {
- if((nCamera == ENVCAMERA)&&cap->env_video)
- {
- video_capture_stop(cap->env_video);
- video_capture_destroy(cap->env_video);
- cap->env_video = NULL;
- return 0;
- }
- else if((nCamera == OPTCAMERA)&&cap->opt_video)
- {
- video_capture_stop(cap->opt_video);
- video_capture_destroy(cap->opt_video);
- cap->opt_video = NULL;
- return 0;
- }
- else
- {
- return -1;
- }
- }
- //根据frontcam完整名(包含设备名+逗号+设备路径MD5)、ewscam设备路径、hspcams设备名,找到rearcam的完整名
- //排除以上设备后的唯一设备即为rearcam
- int videocap_optdev_fetch( CSimpleStringA frontcam,CSimpleStringA ewscam,CAutoArray<CSimpleStringA> &hspcams,CSimpleStringA &rearcam )
- {
- int i = 0, n = 0;
- #ifdef RVC_OS_WIN
- rearcam = "$";
- n = videocap_get_device_count();
- int m = hspcams.GetCount(); // 高拍仪的个数 add by ly 2017/11/07
- if (ewscam.GetLength() <= 1) // 如果外部广角摄像头未配置
- {
- if (n <= 2+m)
- {
- int cnt = 0;
- for (i = 0; i < n; ++i) {
- WCHAR tmp[256];
- char t[256];
- WCHAR tmp1[256];
- char t1[256];
- videocap_get_device_name(i, tmp, ARRAYSIZE(tmp));
- WideCharToMultiByte(CP_ACP, 0, tmp, -1, t, sizeof(t), 0, NULL);
- videocap_get_device_path(i, tmp1, ARRAYSIZE(tmp1));
- WideCharToMultiByte(CP_ACP, 0, tmp1, -1, t1, sizeof(t1), 0, NULL);
- {
- unsigned char x[MD5_DIGESTSIZE];
- md5_ctx_t ctx;
- md5_init(&ctx);
- md5(x, t1, strlen(t1));
- Bin2Str(x, sizeof(x), t1, sizeof(t1));
- }
- // 检查是否为高拍仪摄像头,若是则直接枚举下一个摄像头
- bool isHspCam = false;
- for (int k = 0; k < m; ++k) {
- if (!strcmp((LPCTSTR)hspcams[k],t)) {
- isHspCam = true;
- break;
- }
- }
- if (isHspCam) {
- continue;
- }
- strcat(t, ";");
- strcat(t, t1);
- if (strcmp((LPCTSTR)frontcam, t))
- {
- if (0 == cnt)
- {
- rearcam = t;
- }
- cnt++;
- }
- }
- if (1 != cnt) // 未找到或无法识别内置后摄像头
- {
- rearcam = "$";
- }
- }
- else
- {
- Dbg("[dbg] [videocap_optdev_fetch] detect %d cameras.", n);
- }
- }
- else // 如果外部广角摄像头已配置
- {
- if (n <= 3+m)
- {
- int cnt = 0;
- for (i = 0; i < n; ++i) {
- WCHAR tmp[256];
- char t[256];
- WCHAR tmp1[256];
- char t1[256];
- videocap_get_device_name(i, tmp, ARRAYSIZE(tmp));
- WideCharToMultiByte(CP_ACP, 0, tmp, -1, t, sizeof(t), 0, NULL);
- videocap_get_device_path(i, tmp1, ARRAYSIZE(tmp1));
- WideCharToMultiByte(CP_ACP, 0, tmp1, -1, t1, sizeof(t1), 0, NULL);
- // 检查是否为高拍仪摄像头,若是则直接枚举下一个摄像头
- bool isHspCam = false;
- for (int k = 0; k < m; ++k) {
- if (!strcmp((LPCTSTR)hspcams[k],t)) {
- isHspCam = true;
- break;
- }
- }
- if (isHspCam) {
- continue;
- }
- // save DevicePath (add by ly at 20160725)
- char t2[256];
- strcpy(t2,t1);
- for (int j = 0; j < strlen(t2); ++j)
- {
- t2[j] = toupper(t2[j]);
- if (t2[j] == '#') t2[j] = '\\';
- }
- {
- unsigned char x[MD5_DIGESTSIZE];
- md5_ctx_t ctx;
- md5_init(&ctx);
- md5(x, t1, strlen(t1));
- Bin2Str(x, sizeof(x), t1, sizeof(t1));
- }
- strcat(t, ";");
- strcat(t, t1);
- if (strcmp((LPCTSTR)frontcam, t) && !strstr(t2,(LPCTSTR)ewscam))
- {
- if (0 == cnt)
- {
- rearcam = t;
- }
- cnt++;
- }
- }
- if (1 != cnt) // 未找到或无法识别内置后摄像头
- {
- rearcam = "$";
- }
- }
- else
- {
- Dbg("[dbg] [videocap_optdev_fetch] detect %d cameras.", n);
- }
- }
- #else
- #endif // RVC_OS_WIN
- return n;
- }
- void capture_clearsnapshotvideo(capture_t *cap,int nCamera)
- {
- if((nCamera == ENVCAMERA)&&cap->env_video)
- {
- Dbg("clear ENV snapshot video!");
- cap->env_video->snapshot_shm_queue->ClearVideoQueue();
- return;
- }
- else if((nCamera == OPTCAMERA)&&cap->opt_video)
- {
- Dbg("clear OPT snapshot video!");
- cap->opt_video->snapshot_shm_queue->ClearVideoQueue();
- return;
- }
- else if(nCamera == AlLCAMERA)
- {
- if (cap->env_video)
- {
- Dbg("clear ENV snapshot video!");
- cap->env_video->snapshot_shm_queue->ClearVideoQueue();
- }
- if (cap->opt_video)
- {
- Dbg("clear OPT snapshot video!");
- cap->opt_video->snapshot_shm_queue->ClearVideoQueue();
- }
- return;
- }
- else
- {
- return ;
- }
- }
- int get_camera_exception_message(char* pBuffer, size_t uLen, CSimpleStringA strDeviceName, const char* strErrorMessage)
- {
- int iRet = 0;
- if (strDeviceName.GetLength() > 0){
- const char* strCameraName = strDeviceName.GetData();
- char strBuffer[MAX_PATH] = {0};
- if (sprintf_s(strBuffer, MAX_PATH, "%s", strCameraName) > 0){
- char *pIndex = NULL;
- if (pIndex = (char*)strstr(strBuffer, ";")){
- *pIndex = '\0';
- }
- }
-
- if (NULL != strErrorMessage){
- size_t uDataLen = strlen(strBuffer);
- size_t uErrorLen = strlen(strErrorMessage);
- if (uLen > uDataLen + uErrorLen + 10){
- iRet = sprintf_s(pBuffer, uLen, "[%s] %s", strBuffer, strErrorMessage);
- }
- }
- }
- if (0 == iRet){
- if (NULL != strErrorMessage){
- iRet = sprintf_s(pBuffer, uLen, "%s", strErrorMessage);
- }
- }
- return iRet;
- }
- }
|