123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373 |
- #include "stdafx.h"
- #include "SpBase.h"
- #include "video_session.h"
- #include "../../Other/libvideoframework/videoframework.h"
- #include "memutil.h"
- #include "../../Other/libvideoqueue/libvideoqueue.h"
- #include "../../Other/rvcmediacommon/rvc_media_common.h"
- #include "../../Other/rvcmediacommon/common_video/videocommon.h"
- #include "../../Other/libvideoframework/videoutil.h"
- #include "../../Other/libvideoframework/videortp.h"
- #include "../../Other/libvideoframework/videoclock.h"
- #include "fileutil.h"
- #include "Event.h"
- #ifdef RVC_OS_WIN
- #include "../../Other/libvideoframework/videoplayer.h"
- #include "../../Other/libvideoframework/videocap.h"
- #include <ipp.h>
- #include <io.h>
- #include <DbgHelp.h>
- #pragma comment(lib, "dbghelp.lib")
- #else
- #include "../../Other/libvideorender/ivideorenderinterface.h"
- #include "../../Other/libvideocapture/ivideocaptureinterface.h"
- #include <signal.h>
- #include <semaphore.h>
- #include <time.h>
- #endif // RVC_OS_WIN
- #include "cv.h"
- #include "highgui.h"
- #include "y2k_time.h"
- #define av_always_inline __inline
- #define inline __inline
- #ifndef INT64_C
- #define INT64_C(c) (c##LL)
- #define UINT64_C(c) (c##UL)
- #endif
- #include <stdint.h>
- extern "C"
- {
- #include <libavutil/avutil.h>
- #include <libavcodec/avcodec.h>
- #include <libswscale/swscale.h>
- }
- #include "../../Other/libvideoframework/video_common/ffmpeg_api_cpp_adapter.h"
- BOOL g_bIsSalesRecord = FALSE;
- #define WNDCLS_NAME "sipmedia_video"
- #define MAX_PATH_SIZE 256
- #define DEVICE_STANDARD_TYPE 0
- #define DEVICE_PAD_TYPE 1
- #define DEVICE_MOBILEPAD_TYPE 2
- //#define FPS_KEEP_TIME 3
- //动态调整下行帧频,用于移动版,暂时不用,移动版自动将帧频降到1帧/s
- //int g_nSysFps = 0;
- //int g_nDynamicFps = 0; //当前动态帧频
- //DWORD g_nLastRecFrameTime = 0; //上一秒收到的第一帧视频的时间
- //int nRecvFrameNum = 0; //一秒钟内收到的视频帧数
- //int nFpsKeepTime = 0; //每个帧频保持时间3s,防止频繁跳动
- #ifndef RVC_DBRECORD_VIDEO_BASE
- #define RVC_DBRECORD_VIDEO_BASE 1000
- #endif // !RVC_DBRECORD_VIDEO_BASE
- struct video_session_t
- {
- video_session_conf_t conf;
- Clibvideoqueue *video_shm_q_env;// env rtp queue
- Clibvideoqueue *video_shm_q_opt;// opt rtp queue
- Clibvideoqueue *video_shm_q_preview; // preview queue
- Clibvideoqueue *video_shm_q_remote; // preview queue
- videoq_frame *video_error;
- videortp_t *rtp;
- videoclock_t local_clock;
- struct SwsContext *local_encode_sws_ctx_env;
- struct SwsContext *local_encode_sws_ctx_opt;
- IplImage*personimage;
- IplImage*personmask;
- IplImage*recordareaimage;
- IplImage*recordareamask;
- int irecv_frameid;
- #ifdef RVC_OS_WIN
- videoplayer_t* local_player;
- videoplayer_t* remote_player;
- HANDLE ui_thread;
- HANDLE ui_event;
- HWND local_hwnd; // preview window
- HWND remote_hwnd; // remote window
- picture_record_t* pic_record;
- #endif // RVC_OS_WIN
- bool bvideorecved;
- volatile bool blocalrender;
- volatile bool bremoterender;
- bool bcamera_error_posted;
- };
- static void __dbg(void *user_data, const char *fmt, va_list arg)
- {
- vDbg(fmt, arg);
- }
- static void __logevent(void* user_data, int itype, const char* strmessage)
- {
- if (0 == itype) {
- LogWarn(Severity_Low, Error_Debug, EVENT_MOD_SIP_VIDEO_RTP_CREATE, strmessage);
- }
- else {
- LogWarn(Severity_Low, Error_Debug, EVENT_MOD_SIP_VIDEO_RTP_DESTROY, strmessage);
- }
- }
- static bool __camera_error_event(bool bhaspost, int icameraid)
- {
- bool bret = false;
- if (false == bhaspost){
- if (0 == icameraid){
- LogWarn(Severity_Low, Error_Debug, ERROR_MOD_SIP_GET_ENV_VIDEO_FAILED, "get video from env queue failed!");
- }
- else{
- LogWarn(Severity_Low, Error_Debug, ERROR_MOD_SIP_GET_OPT_VIDEO_FAILED, "get video from opt queue failed!");
- }
- bret = true;
- }
- return bret;
- }
- static int translate_image_resolution(video_frame** dstframe,const int iwidth, const int iheight, const video_frame* psrcframe)
- {
- int i = -1;
- if (iwidth == psrcframe->width && iheight == psrcframe->height){
- return i;
- }
- video_frame* pframe = video_frame_new(iwidth, iheight,VIDEO_FORMAT_RGB24);
- video_frame_fill_black(pframe);
- SwsContext* sws = sws_getCachedContext(NULL, psrcframe->width, psrcframe->height,
- PIX_FMT_BGR24,
- iwidth,
- iheight,
- PIX_FMT_BGR24,
- SWS_LANCZOS,
- NULL,
- NULL,
- NULL);
- sws_scale(sws, psrcframe->data, psrcframe->linesize, 0, psrcframe->height, pframe->data, pframe->linesize);
- sws_freeContext(sws);
- *dstframe = pframe;
- i = 0;
- return i;
- }
- 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;
- }
- #ifdef RVC_OS_WIN
- static void __delete_frame(videoplayer_t *player, void *user_data, video_frame *frame)
- {
- video_frame_delete(frame);
- }
- #endif
- static int video_shm_enqueue(Clibvideoqueue *shm_queue, video_frame *frame, int flags, int iframeid)
- {
- videoq_frame tmp_frm;
- tmp_frm.data = frame->data[0];
- tmp_frm.framesize = frame->width * frame->height * 3;
- tmp_frm.format = VIDEOQ_FORMAT_RGB24;
- tmp_frm.width = frame->width;
- tmp_frm.height = frame->height;
- tmp_frm.iframeid = iframeid;
- unsigned int nowtime = y2k_time_now();
- if (!shm_queue->InsertVideo(&tmp_frm, flags,nowtime))
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("caution: shm_queue video insert shm video failed!");
- return Error_Unexpect;
- }
- else
- {
- //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("video session shm_queue video insert shm video ok, and nowtime is %d, and frame id is %d.", nowtime, iframeid);
- return Error_Succeed;
- }
- }
- static inline Clibvideoqueue *get_active_videoqueue(video_session_t *session)
- {
- int agent_option = *session->conf.ref_camera_switch;
- int facetracking_option = *session->conf.ref_active_camera;
- int camera_state = *session->conf.ref_camera_state;
- Clibvideoqueue *active = NULL;
- if (agent_option == CAMERA_TYPE_ENV)
- {
- if((camera_state!=CAMERA_TYPE_ENV)&&(camera_state!=CAMERA_TYPE_AUTO))
- {
- active = NULL;
- }
- else
- {
- active = session->video_shm_q_env;
- }
- }
- else if (agent_option == CAMERA_TYPE_OPT)
- {
- if((camera_state!=CAMERA_TYPE_OPT)&&(camera_state!=CAMERA_TYPE_AUTO))
- {
- active = NULL;
- }
- else
- {
- active = session->video_shm_q_opt;
- }
- }
- else if(agent_option == CAMERA_TYPE_ERROR)
- {
- active = NULL;
- }
- else
- { // auto
- if (camera_state == CAMERA_TYPE_AUTO)
- {
- if (facetracking_option == CAMERA_TYPE_ENV)
- {
- active = session->video_shm_q_env;
- }
- else
- { // opt
- active = session->video_shm_q_opt;
- }
- }
- else if (camera_state == CAMERA_TYPE_ENV)
- {
- active = session->video_shm_q_env;
- }
- else if (camera_state == CAMERA_TYPE_OPT)
- {
- active = session->video_shm_q_opt;
- }
- else if (camera_state == CAMERA_TYPE_ERROR)
- {
- active = NULL;
- }
- }
- return active;
- }
- static void local_get_frame(void *user_data, video_frame *frame)
- {
- video_session_t *session = (video_session_t*)user_data;
- Clibvideoqueue *q = get_active_videoqueue(session);
- if (q)
- {
- videoq_frame frm;
- frm.data = frame->data[0];
- if (q->GetVideo(&frm, 0))
- {
- //video_frame_fill_black(frame);
- frame->width = frm.width;
- frame->height = frm.height;
- frame->linesize[0] = frm.width * 3;
- }
- }
- else
- {
- //video_frame_fill_black(frame);
- //贴图
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("get active cam is null,load error img");
- if (session->video_error != NULL)
- {
- frame->width = session->video_error->width;
- frame->height = session->video_error->height;
- frame->linesize[0] = session->video_error->width * 3;
- memcpy(frame->data[0],session->video_error->data,frame->width*frame->height*3);
- }
- else
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("video error img is null");
- }
- }
- }
- static void local_put_frame(void *user_data, video_frame *frame)
- {
- //LOG_FUNCTION();
- video_session_t *session = (video_session_t*)user_data;
- video_frame *tmp_frame_encode = NULL;
- // send out
- {
- tmp_frame_encode = video_frame_new(REC_COMMON_VIDEO_RTP_WIDTH, REC_COMMON_VIDEO_RTP_HEIGHT, VIDEO_FORMAT_I420);
- video_frame_fill_black(tmp_frame_encode);
- if (frame->width == REC_COMMON_VIDEO_RTP_ENV_WIDTH && frame->height == REC_COMMON_VIDEO_RTP_ENV_HEIGHT) { // env
- int offset = (REC_COMMON_VIDEO_RTP_HEIGHT - REC_COMMON_VIDEO_RTP_ENV_HEIGHT) / 2;
- unsigned char *dst_data[4] = {tmp_frame_encode->data[0], tmp_frame_encode->data[1], tmp_frame_encode->data[2], NULL};
- dst_data[0] += offset * tmp_frame_encode->linesize[0];
- dst_data[1] += offset / 2 * tmp_frame_encode->linesize[1];
- dst_data[2] += offset / 2 * tmp_frame_encode->linesize[2];
- sws_scale(session->local_encode_sws_ctx_env, frame->data, frame->linesize, 0, frame->height, dst_data, tmp_frame_encode->linesize);
- } else if (frame->width == REC_COMMON_VIDEO_RTP_OPT_WIDTH && frame->height == REC_COMMON_VIDEO_RTP_OPT_HEIGHT) { // opt
-
- video_frame tt;
- video_frame_alloc(REC_COMMON_VIDEO_RTP_WIDTH, REC_COMMON_VIDEO_RTP_HEIGHT, VIDEO_FORMAT_RGB24, &tt);
- video_frame_fill_black(&tt);
- {
- int offset = (REC_COMMON_VIDEO_RTP_WIDTH - REC_COMMON_VIDEO_RTP_OPT_WIDTH) / 2;
- unsigned char *dst_data[4] = {tt.data[0], 0, 0, 0};
- dst_data[0] += offset * 3;
- #ifdef RVC_OS_WIN
- IppiSize size;
- size.width = frame->width;
- size.height = frame->height;
- ippiCopy_8u_C3R(frame->data[0], frame->linesize[0], tt.data[0] + offset * 3, tt.linesize[0], size);
- #else
- for (int i = 0; i < frame->height; i++){
- memcpy(dst_data[0] + i*tt.linesize[0] , frame->data[0] + i*frame->width*3, frame->width*3);
- }
- #endif // RVC_OS_WIN
- }
- sws_scale(session->local_encode_sws_ctx_opt, tt.data, tt.linesize, 0, tt.height, tmp_frame_encode->data, tmp_frame_encode->linesize);
- video_frame_free(&tt);
- }
-
- if (session->conf.local_pt == REC_COMMON_VIDEO_PT){
- videortp_send_frame(session->rtp, tmp_frame_encode);
- }
- else{
- videortp_send_yuvframe(session->rtp, tmp_frame_encode);
- }
- }
- if (tmp_frame_encode) {
- video_frame_delete(tmp_frame_encode);
- }
- }
- static int on_rx_frame(video_frame *frame, void *user_data)
- {
- //LOG_FUNCTION();
- video_session_t *session = (video_session_t *)user_data;
- session->irecv_frameid++;
- if (DOUBLERECORD_CALLTYPE == session->conf.nCallType) {
- if (false == session->bremoterender) {
- session->conf.video_render_cb.on_stop_remote_video_render(session->conf.video_render_cb.user_data);
- }
- if (eStand2sType == session->conf.eDeviceType || eStand1SPlusType == session->conf.eDeviceType) {
- //大机对远端视频进行缩放匹配
- video_frame* recordframe = NULL;
- if (0 == translate_image_resolution(&recordframe, REC_COMMON_VIDEO_SNAPSHOT_PREVIEW_WIDTH, REC_COMMON_VIDEO_SNAPSHOT_PREVIEW_HEIGHT, frame)) {
- int rc = video_shm_enqueue(session->video_shm_q_remote, recordframe, VIDEOQUEUE_FLAG_VERTICAL_FLIP, session->irecv_frameid);
- if (rc != Error_Succeed) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("eStand2sType record call mod insert remote video to queue failed.");
- }
- //else {
- // DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s:%d video frame (session->irecv_frameid = %d) video_shm_enqueue success.", __FUNCTION__, __LINE__, session->irecv_frameid);
- //}
- video_frame_delete(recordframe);
- recordframe = NULL;
- }
- }
- else {
- int rc = video_shm_enqueue(session->video_shm_q_remote, frame, VIDEOQUEUE_FLAG_VERTICAL_FLIP, session->irecv_frameid);
- if (rc != Error_Succeed) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("not eStand2sType record call mod insert remote video to queue.");
- }
- }
- }
- int used = 0;
- #ifdef RVC_OS_WIN
- if (session->remote_player)
- {
- int rc = videoplayer_queue_frame(session->remote_player, frame, &__delete_frame, NULL);
- if (rc == 0) {
- used = 1;
- }
- }
- #else
- //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s:%d session->conf.video_render_cb = 0x%08x and session->conf.video_render_cb->on_video_render = 0x%08x, session->conf.video_render_cb->user_data = 0x%08x.", __FUNCTION__, __LINE__, session->conf.video_render_cb, session->conf.video_render_cb.on_remote_video_render, session->conf.video_render_cb.user_data);
- session->conf.video_render_cb.on_remote_video_render(frame, session->conf.video_render_cb.user_data);
- //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s:%d", __FUNCTION__, __LINE__);
- used = 1;
- if (false == session->bremoterender) {
- LogWarn(Severity_Low, Error_Debug, EVENT_MOD_SIP_REMOTE_VIDEO_RENDER_STARTED, "start remote video render.");
- session->bremoterender = true;
- }
- #endif
- return used;
- }
- static void on_rx_udp(const char* buf, int size, void* user_data)
- {
- video_session_t* session = (video_session_t*)user_data;
- if (false == session->bvideorecved) {
- char strmsg[MAX_PATH] = { 0 };
- snprintf(strmsg, MAX_PATH, "received first video packet, and packet size is %d.", size);
- LogWarn(Severity_Low, Error_Debug, EVENT_MOD_SIP_VIDEO_STREAM_RECEIVED, strmsg);
- session->bvideorecved = true;
- }
- }
- #ifdef RVC_OS_WIN
- int GetCurrentRunPath(char* pPath)
- {
- char* pBuf = new char[MAX_PATH_SIZE];
- if (pBuf == NULL)
- return -1;
- ZeroMemory(pBuf, MAX_PATH_SIZE);
- GetModuleFileName(NULL, pBuf, MAX_PATH_SIZE);
- int len = strnlen_s(pBuf, MAX_PATH_SIZE);
- if (len <= 0)
- {
- delete[]pBuf;
- return -2;
- }
- char* pch;
- pch = strstr(pBuf, "bin");
- if (pch == NULL)
- return -3;
- int lenDel = strnlen_s(pch, MAX_PATH_SIZE);
- if (len <= 0)
- {
- delete[]pBuf;
- return -3;
- }
- strncpy_s(pPath, MAX_PATH_SIZE, pBuf, len - lenDel);
- delete[]pBuf; return strnlen_s(pPath, MAX_PATH_SIZE);
- }
- //远端视频窗口状态回调
- static int on_remoteWinstate(videoplayer_t *player, void *user_data, video_frame **frame)
- {
- video_session_t *session = (video_session_t*)user_data;
- //if (*session->conf.ref_window_state == 1)
- //{
- // return 1;
- //}
- //else if (*session->conf.ref_window_state == 2)
- //{
- // return 2;
- //}
- //else
- //{
- // return 0;
- //}
- return *session->conf.ref_window_state ;
- }
- //本地回显回调
- static int on_pull(videoplayer_t *player, void *user_data, video_frame **frame)
- {
- video_session_t *session = (video_session_t*)user_data;
- video_frame *tmp_frame_preview;
- //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("ref_active_img %d,ref_Is_ActiveInspect %d,ref_camera_switch %d",*session->conf.ref_active_img,*session->conf.ref_Is_ActiveInspect,*session->conf.ref_camera_switch);
- if((session->conf.ref_active_img == NULL)&&(session->conf.ref_Is_ActiveInspect == NULL))
- {
- tmp_frame_preview = video_frame_new(REC_COMMON_VIDEO_PREVIEW_WIDTH, REC_COMMON_VIDEO_PREVIEW_HEIGHT, VIDEO_FORMAT_RGB24);
- videoq_frame frm;
- frm.data = tmp_frame_preview->data[0];
- BOOL result = session->video_shm_q_preview->GetVideo(&frm, VIDEOQUEUE_FLAG_HORIZONTAL_FLIP);
- //人形框融合处理
- if (result&&session->personimage!=NULL&&session->personmask!=NULL&&*session->conf.ref_Is_showPersonArea==1)
- {
- IplImage*img = cvCreateImageHeader(cvSize(frm.width,frm.height),IPL_DEPTH_8U,3);
- img->imageData = (char*)frm.data;
- if (frm.width!=session->personimage->width)
- {
- IplImage*tmp = cvCreateImage(cvSize(frm.width,frm.height),IPL_DEPTH_8U,3);
- IplImage*tmpmask = cvCreateImage(cvSize(frm.width,frm.height),IPL_DEPTH_8U,1);
- cvResize(session->personimage,tmp);
- cvResize(session->personmask,tmpmask);
- cvAdd(img,tmp,img,tmpmask);
- cvReleaseImage(&tmp);
- cvReleaseImage(&tmpmask);
- }
- else
- {
- cvAdd(img,session->personimage,img,session->personmask);
- }
- cvReleaseImageHeader(&img);
- }
- }
- else
- {
- if (*session->conf.ref_active_img == 1)
- {
- tmp_frame_preview = video_frame_new(REC_COMMON_VIDEO_SNAPSHOT_WIDTH, REC_COMMON_VIDEO_SNAPSHOT_WIDTH, VIDEO_FORMAT_RGB24);
- video_frame_fill_black(tmp_frame_preview);
- if (session->video_error == NULL)
- {
- char strPath[MAX_PATH_SIZE] = {0};
- #ifdef RVC_OS_WIN
- GetCurrentRunPath(strPath);
- sprintf(strPath, "%s\\bin\\looklowerscreen.jpg", strPath);
- #else
- #endif // RVC_OS_WIN
- if (ExistsFile(strPath))
- {
- IplImage*img = cvLoadImage(strPath,1);
- if (img != NULL)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("load img success");
- session->video_error = new videoq_frame;
- session->video_error->format = VIDEOQ_FORMAT_RGB24;
- session->video_error->framesize = img->imageSize;
- session->video_error->height = img->width;
- session->video_error->width = img->height;
- session->video_error->data = new unsigned char[img->imageSize];
- memcpy(session->video_error->data,img->imageData,img->imageSize);
- cvReleaseImage(&img);
- }
- }
- }
- if (session->video_error != NULL)
- {
- SwsContext*sws = sws_getContext(session->video_error->width, session->video_error->height,PIX_FMT_BGR24,
- REC_COMMON_VIDEO_SNAPSHOT_WIDTH,
- REC_COMMON_VIDEO_SNAPSHOT_WIDTH,
- PIX_FMT_BGR24,
- SWS_POINT, NULL, NULL, NULL);
- uint8_t *src_data[4] = {(unsigned char*)session->video_error->data+(session->video_error->height-1)*session->video_error->width*3,NULL,NULL,NULL};
- int src_linesize[4] = {-session->video_error->width*3,0,0,0};
- unsigned char *dst[4] = {tmp_frame_preview->data[0],NULL,NULL,NULL};
- int dst_linesize[4] = {tmp_frame_preview->linesize[0],0,0,0};
- sws_scale(sws, src_data, src_linesize, 0, session->video_error->height, dst, dst_linesize);
- sws_freeContext(sws);
- }
- }
- else if (*session->conf.ref_Is_ActiveInspect == 1)
- {
- if((session->conf.eDeviceType == eMobilePadType)||(session->conf.eDeviceType == ePadtype)||(session->conf.eDeviceType == eDesk2SType)||(session->conf.eDeviceType == eDesk1SType)||(session->conf.eDeviceType == eDesk2SIntegratedType))
- {
- tmp_frame_preview = video_frame_new(REC_COMMON_VIDEO_PREVIEW_WIDTH, REC_COMMON_VIDEO_PREVIEW_HEIGHT, VIDEO_FORMAT_RGB24);
- videoq_frame frm;
- frm.data = tmp_frame_preview->data[0];
- session->video_shm_q_preview->GetVideo(&frm, VIDEOQUEUE_FLAG_HORIZONTAL_FLIP);
- }
- else
- {
- tmp_frame_preview = video_frame_new(REC_COMMON_VIDEO_SNAPSHOT_WIDTH, REC_COMMON_VIDEO_SNAPSHOT_WIDTH, VIDEO_FORMAT_RGB24);
- video_frame_fill_black(tmp_frame_preview);
- if ((*session->conf.ref_camera_switch == CAMERA_TYPE_ENV)||(*session->conf.ref_camera_switch == CAMERA_TYPE_AUTO))//显示上摄像头
- {
- if (session->video_shm_q_env)
- {
- videoq_frame frm;
- int offset = (REC_COMMON_VIDEO_SNAPSHOT_WIDTH - REC_COMMON_VIDEO_SNAPSHOT_HEIGHT) / 2;
- frm.data = tmp_frame_preview->data[0] + offset * tmp_frame_preview->linesize[0];
- session->video_shm_q_env->GetVideo(&frm, VIDEOQUEUE_FLAG_VERTICAL_FLIP);
- }
- }
- else if (*session->conf.ref_camera_switch == CAMERA_TYPE_OPT)//显示下摄像头
- {
- if (session->video_shm_q_opt)
- {
- video_frame tt = {0};
- int offset = (REC_COMMON_VIDEO_SNAPSHOT_WIDTH-REC_COMMON_VIDEO_SNAPSHOT_HEIGHT) / 2;
- tt.data[0] = tmp_frame_preview->data[0] + offset *3;
- tt.format = tmp_frame_preview->format;
- tt.linesize[0] = tmp_frame_preview->linesize[0];
- tt.width = REC_COMMON_VIDEO_SNAPSHOT_HEIGHT;
- tt.height = REC_COMMON_VIDEO_SNAPSHOT_WIDTH;
- session->video_shm_q_opt->GetVideo2(&tt, VIDEOQUEUE_FLAG_VERTICAL_FLIP);
- }
- }
- }
- }
- else
- {
- tmp_frame_preview = video_frame_new(REC_COMMON_VIDEO_PREVIEW_WIDTH, REC_COMMON_VIDEO_PREVIEW_HEIGHT, VIDEO_FORMAT_RGB24);
- videoq_frame frm;
- frm.data = tmp_frame_preview->data[0];
- BOOL result = session->video_shm_q_preview->GetVideo(&frm, VIDEOQUEUE_FLAG_HORIZONTAL_FLIP);
- //人形框融合处理
- if (result&&session->personimage!=NULL&&session->personmask!=NULL&&*session->conf.ref_Is_showPersonArea==1)
- {
- IplImage*img = cvCreateImageHeader(cvSize(frm.width,frm.height),IPL_DEPTH_8U,3);
- img->imageData = (char*)frm.data;
- if (frm.width!=session->personimage->width)
- {
- IplImage*tmp = cvCreateImage(cvSize(frm.width,frm.height),IPL_DEPTH_8U,3);
- IplImage*tmpmask = cvCreateImage(cvSize(frm.width,frm.height),IPL_DEPTH_8U,1);
- cvResize(session->personimage,tmp);
- cvResize(session->personmask,tmpmask);
- cvAdd(img,tmp,img,tmpmask);
- cvReleaseImage(&tmp);
- cvReleaseImage(&tmpmask);
- }
- else
- {
- cvAdd(img,session->personimage,img,session->personmask);
- }
- cvReleaseImageHeader(&img);
- }
- //双录人形位置框融合处理
- if (result&&session->recordareaimage!=NULL&&session->recordareamask!=NULL&&*session->conf.ref_Is_showRecordArea==1)
- {
- IplImage*img = cvCreateImageHeader(cvSize(frm.width,frm.height),IPL_DEPTH_8U,3);
- img->imageData = (char*)frm.data;
- if (frm.width!=session->recordareaimage->width)
- {
- IplImage*tmp = cvCreateImage(cvSize(frm.width,frm.height),IPL_DEPTH_8U,3);
- IplImage*tmpmask = cvCreateImage(cvSize(frm.width,frm.height),IPL_DEPTH_8U,1);
- cvResize(session->recordareaimage,tmp);
- cvResize(session->recordareamask,tmpmask);
- cvAdd(img,tmp,img,tmpmask);
- cvReleaseImage(&tmp);
- cvReleaseImage(&tmpmask);
- }
- else
- {
- cvAdd(img,session->recordareaimage,img,session->recordareamask);
- }
- cvReleaseImageHeader(&img);
- }
- }
- }
- *frame = tmp_frame_preview;
- //if (*session->conf.ref_window_state == 1)
- //{
- // return 1;
- //}
- //else if (*session->conf.ref_window_state == 2)
- //{
- // return 2;
- //}
- //else
- //{
- // return 0;
- //}
- return *session->conf.ref_window_state;
- }
- static void free_frame(videoplayer_t *player, void *user_data, video_frame *frame)
- {
- video_frame_delete(frame);
- }
- #else
- //视频窗口显示状态,0:正常大小显示,1:放大一倍显示,2:隐藏全部窗口,3:从隐藏状态恢复为全部显示,4:显示远程窗口,隐藏本地窗口, 5:缩放显示
- int set_video_windows(video_session_t* psession, int iwindowstate)
- {
- int iret = -1;
- if (NULL == psession){
- return iret;
- }
- return iret;
- }
- //本地回显回调
- static int get_local_video_frame(void* user_data, video_frame** frame)
- {
- video_session_t* session = (video_session_t*)user_data;
- video_frame* tmp_frame_preview = NULL;
- //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("ref_active_img %d,ref_Is_ActiveInspect %d,ref_camera_switch %d",*session->conf.ref_active_img,*session->conf.ref_Is_ActiveInspect,*session->conf.ref_camera_switch);
- if ((session->conf.ref_active_img == NULL) && (session->conf.ref_Is_ActiveInspect == NULL))
- {
- tmp_frame_preview = video_frame_new(REC_COMMON_VIDEO_PREVIEW_WIDTH, REC_COMMON_VIDEO_PREVIEW_HEIGHT, VIDEO_FORMAT_RGB24);
- videoq_frame frm;
- frm.data = tmp_frame_preview->data[0];
- BOOL result = session->video_shm_q_preview->GetVideo(&frm, VIDEOQUEUE_FLAG_HORIZONTAL_FLIP);
- //人形框融合处理
- if (result){
- if (session->personimage != NULL && session->personmask != NULL && *session->conf.ref_Is_showPersonArea == 1)
- {
- IplImage* img = cvCreateImageHeader(cvSize(frm.width, frm.height), IPL_DEPTH_8U, 3);
- img->imageData = (char*)frm.data;
- if (frm.width != session->personimage->width){
- IplImage* tmp = cvCreateImage(cvSize(frm.width, frm.height), IPL_DEPTH_8U, 3);
- IplImage* tmpmask = cvCreateImage(cvSize(frm.width, frm.height), IPL_DEPTH_8U, 1);
- cvResize(session->personimage, tmp);
- cvResize(session->personmask, tmpmask);
- cvAdd(img, tmp, img, tmpmask);
- cvReleaseImage(&tmp);
- cvReleaseImage(&tmpmask);
- }
- else{
- cvAdd(img, session->personimage, img, session->personmask);
- }
- cvReleaseImageHeader(&img);
- }
- }
- else {
- video_frame_fill_black(tmp_frame_preview);
- if (__camera_error_event(session->bcamera_error_posted, 0)) {
- session->bcamera_error_posted = true;
- }
- }
- }
- else
- {
- if (*session->conf.ref_active_img == 1)
- {
- tmp_frame_preview = video_frame_new(REC_COMMON_VIDEO_SNAPSHOT_WIDTH, REC_COMMON_VIDEO_SNAPSHOT_WIDTH, VIDEO_FORMAT_RGB24);
- video_frame_fill_black(tmp_frame_preview);
- if (session->video_error == NULL)
- {
- char strPath[MAX_PATH_SIZE] = { 0 };
- snprintf(strPath, MAX_PATH_SIZE, "%s", "./bin/looklowerscreen.jpg");
- if (ExistsFile(strPath))
- {
- IplImage* img = cvLoadImage(strPath, 1);
- if (img != NULL)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("load img success");
- session->video_error = new videoq_frame;
- session->video_error->format = VIDEOQ_FORMAT_RGB24;
- session->video_error->framesize = img->imageSize;
- session->video_error->height = img->width;
- session->video_error->width = img->height;
- session->video_error->data = new unsigned char[img->imageSize];
- memcpy(session->video_error->data, img->imageData, img->imageSize);
- cvReleaseImage(&img);
- }
- }
- }
- if (session->video_error != NULL)
- {
- SwsContext* sws = sws_getContext(session->video_error->width, session->video_error->height, PIX_FMT_BGR24,
- REC_COMMON_VIDEO_SNAPSHOT_WIDTH,
- REC_COMMON_VIDEO_SNAPSHOT_WIDTH,
- PIX_FMT_BGR24,
- SWS_POINT, NULL, NULL, NULL);
- uint8_t* src_data[4] = { (unsigned char*)session->video_error->data + (session->video_error->height - 1) * session->video_error->width * 3,NULL,NULL,NULL };
- int src_linesize[4] = { -session->video_error->width * 3,0,0,0 };
- unsigned char* dst[4] = { tmp_frame_preview->data[0],NULL,NULL,NULL };
- int dst_linesize[4] = { tmp_frame_preview->linesize[0],0,0,0 };
- sws_scale(sws, src_data, src_linesize, 0, session->video_error->height, dst, dst_linesize);
- sws_freeContext(sws);
- }
- }
- else if (*session->conf.ref_Is_ActiveInspect == 1)
- {
- if (session->conf.eDeviceType == eMobilePadType)
- {
- tmp_frame_preview = video_frame_new(REC_COMMON_VIDEO_PREVIEW_WIDTH, REC_COMMON_VIDEO_PREVIEW_HEIGHT, VIDEO_FORMAT_RGB24);
- videoq_frame frm;
- frm.data = tmp_frame_preview->data[0];
- if (FALSE == session->video_shm_q_preview->GetVideo(&frm, VIDEOQUEUE_FLAG_HORIZONTAL_FLIP)) {
- if (__camera_error_event(session->bcamera_error_posted, 0)) {
- session->bcamera_error_posted = true;
- }
- }
- }
- else
- {
- tmp_frame_preview = video_frame_new(REC_COMMON_VIDEO_SNAPSHOT_WIDTH, REC_COMMON_VIDEO_SNAPSHOT_WIDTH, VIDEO_FORMAT_RGB24);
- video_frame_fill_black(tmp_frame_preview);
- if ((*session->conf.ref_camera_switch == CAMERA_TYPE_ENV) || (*session->conf.ref_camera_switch == CAMERA_TYPE_AUTO))//显示上摄像头
- {
- if (session->video_shm_q_env)
- {
- videoq_frame frm;
- int offset = (REC_COMMON_VIDEO_SNAPSHOT_WIDTH - REC_COMMON_VIDEO_SNAPSHOT_HEIGHT) / 2;
- frm.data = tmp_frame_preview->data[0] + offset * tmp_frame_preview->linesize[0];
- if (FALSE == session->video_shm_q_env->GetVideo(&frm, VIDEOQUEUE_FLAG_VERTICAL_FLIP)){
- if (__camera_error_event(session->bcamera_error_posted, 0)) {
- session->bcamera_error_posted = true;
- }
- }
- }
- }
- else if (*session->conf.ref_camera_switch == CAMERA_TYPE_OPT)//显示下摄像头
- {
- if (session->video_shm_q_opt)
- {
- video_frame tt = { 0 };
- int offset = (REC_COMMON_VIDEO_SNAPSHOT_WIDTH - REC_COMMON_VIDEO_SNAPSHOT_HEIGHT) / 2;
- tt.data[0] = tmp_frame_preview->data[0] + offset * 3;
- tt.format = tmp_frame_preview->format;
- tt.linesize[0] = tmp_frame_preview->linesize[0];
- tt.width = REC_COMMON_VIDEO_SNAPSHOT_HEIGHT;
- tt.height = REC_COMMON_VIDEO_SNAPSHOT_WIDTH;
- if (FALSE == session->video_shm_q_opt->GetVideo2(&tt, VIDEOQUEUE_FLAG_VERTICAL_FLIP)) {
- if (__camera_error_event(session->bcamera_error_posted, 1)) {
- session->bcamera_error_posted = true;
- }
- }
- }
- }
- }
- }
- else
- {
- tmp_frame_preview = video_frame_new(REC_COMMON_VIDEO_PREVIEW_WIDTH, REC_COMMON_VIDEO_PREVIEW_HEIGHT, VIDEO_FORMAT_RGB24);
- videoq_frame frm;
- frm.data = tmp_frame_preview->data[0];
- BOOL result = session->video_shm_q_preview->GetVideo(&frm, VIDEOQUEUE_FLAG_HORIZONTAL_FLIP);
- if (result){
- //人形框融合处理
- if (session->personimage != NULL && session->personmask != NULL && *session->conf.ref_Is_showPersonArea == 1)
- {
- IplImage* img = cvCreateImageHeader(cvSize(frm.width, frm.height), IPL_DEPTH_8U, 3);
- img->imageData = (char*)frm.data;
- if (frm.width != session->personimage->width)
- {
- IplImage* tmp = cvCreateImage(cvSize(frm.width, frm.height), IPL_DEPTH_8U, 3);
- IplImage* tmpmask = cvCreateImage(cvSize(frm.width, frm.height), IPL_DEPTH_8U, 1);
- cvResize(session->personimage, tmp);
- cvResize(session->personmask, tmpmask);
- cvAdd(img, tmp, img, tmpmask);
- cvReleaseImage(&tmp);
- cvReleaseImage(&tmpmask);
- }
- else
- {
- cvAdd(img, session->personimage, img, session->personmask);
- }
- cvReleaseImageHeader(&img);
- }
- //双录人形位置框融合处理
- if (session->recordareaimage != NULL && session->recordareamask != NULL && *session->conf.ref_Is_showRecordArea == 1)
- {
- IplImage* img = cvCreateImageHeader(cvSize(frm.width, frm.height), IPL_DEPTH_8U, 3);
- img->imageData = (char*)frm.data;
- if (frm.width != session->recordareaimage->width)
- {
- IplImage* tmp = cvCreateImage(cvSize(frm.width, frm.height), IPL_DEPTH_8U, 3);
- IplImage* tmpmask = cvCreateImage(cvSize(frm.width, frm.height), IPL_DEPTH_8U, 1);
- cvResize(session->recordareaimage, tmp);
- cvResize(session->recordareamask, tmpmask);
- cvAdd(img, tmp, img, tmpmask);
- cvReleaseImage(&tmp);
- cvReleaseImage(&tmpmask);
- }
- else
- {
- cvAdd(img, session->recordareaimage, img, session->recordareamask);
- }
- cvReleaseImageHeader(&img);
- }
- }
- else {
- video_frame_fill_black(tmp_frame_preview);
- if (__camera_error_event(session->bcamera_error_posted, 0)) {
- session->bcamera_error_posted = true;
- }
- }
- }
- }
- *frame = tmp_frame_preview;
- return *session->conf.ref_window_state;
- }
- #endif // RVC_OS_WIN
- static int start_video_rtpsession(video_session_t* session)
- {
- int rc = -1;
- videortp_config_t config = { 0 };
- config.fps_den = REC_COMMON_VIDEO_FPS_DEN;
- if (eMobilePadType == session->conf.eDeviceType){
- config.fps_num = REC_COMMON_VIDEO_FPS_MOBILE_AGENT;
- }
- else {
- config.fps_num = REC_COMMON_VIDEO_FPS_NUM;
- }
- config.capture_height = -1; // not use
- config.capture_width = -1; // not use
- config.dir = 3;
- config.tx_width = REC_COMMON_VIDEO_RTP_WIDTH;
- config.tx_height = REC_COMMON_VIDEO_RTP_HEIGHT;
- config.rx_width = session->conf.remote_video_width;
- config.rx_height = session->conf.remote_video_height;
- config.local_ip = session->conf.local_rtp_ip;
- config.local_pt = session->conf.local_pt;
- config.remote_pt = session->conf.local_pt;
- config.local_rtp_port = session->conf.local_rtp_port;
- config.mtu = session->conf.mtu;
- config.quant = session->conf.video_quant;
- config.remote_ip = session->conf.remote_rtp_ip;
- config.remote_rtp_port = session->conf.remote_rtp_port;
- config.user_data = session;
- config.bit_rate = session->conf.bit_rate;
- config.on_rx_frame = &on_rx_frame;
- config.on_rx_udp = &on_rx_udp;
- config.dbg = &__dbg;
- config.logevent = &__logevent;
- //config.fresh_time = session->conf.irvideo_ft;
- if (0 == videortp_create(&config, &session->rtp)) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("videortp create success!");
- }
- else {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("videortp create failed!");
- }
- rc = videortp_start(session->rtp);
- if (rc != 0)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("start video rtp failed!");
- videortp_destroy(session->rtp);
- session->rtp = NULL;
- }
- else {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("videortp_start suc.");
- }
- return rc;
- }
- static int start_local_video_clock(video_session_t* session)
- {
- int rc = -1;
- if (eMobilePadType == session->conf.eDeviceType){
- rc = videoclock_create(REC_COMMON_VIDEO_FPS_MOBILE, REC_COMMON_VIDEO_FPS_DEN,
- REC_COMMON_VIDEO_RTP_WIDTH, REC_COMMON_VIDEO_RTP_HEIGHT, VIDEO_FORMAT_RGB24,
- &local_put_frame, session, &local_get_frame, session, &session->local_clock, session->conf.ref_Up_Fps, &__dbg);
- }
- else{
- rc = videoclock_create(REC_COMMON_VIDEO_FPS_NUM, REC_COMMON_VIDEO_FPS_DEN,
- REC_COMMON_VIDEO_RTP_WIDTH, REC_COMMON_VIDEO_RTP_HEIGHT, VIDEO_FORMAT_RGB24,
- &local_put_frame, session, &local_get_frame, session, &session->local_clock, session->conf.ref_Up_Fps, &__dbg);
- }
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("create session->local_clock addr is 0x%08x", session->local_clock);
- if (0 == rc) {
- rc = videoclock_start(session->local_clock);
- if (rc != 0) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("start video clock failed!");
- videoclock_destroy(session->local_clock);
- session->local_clock = NULL;
- }
- else {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("videoclock start success!");
- }
- }
- else {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("create video clock failed!");
- }
- return rc;
- }
- static int start_video(video_session_t *session)
- {
- LOG_FUNCTION();
- int rc = -1;
- if (session->video_shm_q_env)
- {
- session->local_encode_sws_ctx_env = sws_getContext(
- REC_COMMON_VIDEO_RTP_ENV_WIDTH, REC_COMMON_VIDEO_RTP_ENV_HEIGHT, PIX_FMT_BGR24,
- REC_COMMON_VIDEO_RTP_ENV_WIDTH, REC_COMMON_VIDEO_RTP_ENV_HEIGHT, PIX_FMT_YUV420P,
- SWS_POINT, NULL, NULL, NULL);
- if (!session->local_encode_sws_ctx_env)
- goto on_error;
- else{
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("get session->local_encode_sws_ctx_env succ.");
- }
- }
- else{
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("session->video_shm_q_env is NULL.");
- }
- if (session->video_shm_q_opt)
- {
- session->local_encode_sws_ctx_opt = sws_getContext(
- REC_COMMON_VIDEO_RTP_WIDTH, REC_COMMON_VIDEO_RTP_HEIGHT, PIX_FMT_BGR24,
- REC_COMMON_VIDEO_RTP_WIDTH, REC_COMMON_VIDEO_RTP_HEIGHT, PIX_FMT_YUV420P,
- SWS_POINT, NULL, NULL, NULL);
- if (!session->local_encode_sws_ctx_opt)
- goto on_error;
- else{
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("get session->local_encode_sws_ctx_opt succ.");
- }
- }
- else{
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("session->video_shm_q_opt is NULL.");
- }
- //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("session nCallType is %d, remote_video_view_cx = %d,remote_video_view_cy = %d,remote_video_width = %d,remote_video_height = %d.", session->conf.nCallType,session->conf.remote_video_view_cx,session->conf.remote_video_view_cy,session->conf.remote_video_width,session->conf.remote_video_height);
- #ifdef RVC_OS_WIN
- if (DOUBLERECORD_CALLTYPE != session->conf.nCallType){
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("create new remote video player");
- if (session->remote_hwnd)
- {
- if (session->conf.eDeviceType == eMobilePadType)
- {
- rc = videoplayer_create(session->remote_hwnd,
- 0,
- 0,
- session->conf.remote_video_view_cx,
- session->conf.remote_video_view_cy,
- REC_COMMON_VIDEO_FPS_MOBILE_AGENT,
- REC_COMMON_VIDEO_FPS_DEN,
- session->conf.remote_video_width,
- session->conf.remote_video_height,
- //*VIDEOPLAYER_FLAG_DOUBLESIZE|*/VIDEOPLAYER_FLAG_PUSH|VIDEOPLAYER_FLAG_CHECKTOP,
- session->conf.iremote_wind_flags,
- "remote",
- on_remoteWinstate,
- NULL,
- session,
- &session->remote_player);
- if (rc != 0)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("create remote video player failed!");
- goto on_error;
- }
- else{
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("create remote video player suc!");
- }
- }
- else if((session->conf.eDeviceType == ePadtype)||(session->conf.eDeviceType == eDesk2SType)||(session->conf.eDeviceType == eDesk1SType)||(session->conf.eDeviceType == eDesk2SIntegratedType))
- {
- rc = videoplayer_create(session->remote_hwnd,
- 0,
- 0,
- session->conf.remote_video_view_cx,
- session->conf.remote_video_view_cy,
- REC_COMMON_VIDEO_FPS_MOBILE,
- REC_COMMON_VIDEO_FPS_DEN,
- session->conf.remote_video_width,
- session->conf.remote_video_height,
- //*VIDEOPLAYER_FLAG_DOUBLESIZE|*/VIDEOPLAYER_FLAG_PUSH|VIDEOPLAYER_FLAG_CHECKTOP,
- session->conf.iremote_wind_flags,
- "remote",
- on_remoteWinstate,
- NULL,
- session,
- &session->remote_player);
- if (rc != 0) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("create remote video player failed!");
- goto on_error;
- }
- else{
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("create remote video player suc!");
- }
- }
- else if(session->conf.eDeviceType == eStand2sType)
- {
- rc = videoplayer_create(session->remote_hwnd,
- 0,
- 0,
- session->conf.remote_video_view_cx,
- session->conf.remote_video_view_cy,
- REC_COMMON_VIDEO_FPS_NUM,
- REC_COMMON_VIDEO_FPS_DEN,
- session->conf.remote_video_width,
- session->conf.remote_video_height,
- //*VIDEOPLAYER_FLAG_DOUBLESIZE|*/VIDEOPLAYER_FLAG_PUSH|VIDEOPLAYER_FLAG_CHECKTOP,
- session->conf.iremote_wind_flags,
- "remote",
- on_remoteWinstate,
- NULL,
- session,
- &session->remote_player);
- if (rc != 0)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("create remote video player failed!");
- goto on_error;
- }
- else{
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("create remote video player suc remote_video_width = %d,remote_video_height = %d.", session->conf.remote_video_width, session->conf.remote_video_height);
- }
- }
- }
- else
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("remote_hwnd == Null");
- }
- }
- else{
- if (NULL != pg_last_session){
- session->remote_player = pg_last_session->remote_player;
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("double record call remote_player reuse.");
- }
- else{
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("pg_last_session is NULL, and call type is %d.", session->conf.nCallType);
- }
- }
- BOOL bIsActiveInspect = FALSE;
- if (session->conf.ref_Is_ActiveInspect != NULL)
- {
- if (*session->conf.ref_Is_ActiveInspect == 1)
- {
- bIsActiveInspect = TRUE;
- }
- else
- {
- bIsActiveInspect = FALSE;
- }
- }
- else
- {
- bIsActiveInspect = FALSE;
- }
- if (DOUBLERECORD_CALLTYPE != session->conf.nCallType){
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("create new local video player");
- if (session->conf.eDeviceType == eMobilePadType)
- {
- rc = videoplayer_create(session->local_hwnd,
- 0,
- 0,
- session->conf.local_video_view_cx,
- session->conf.local_video_view_cy,
- REC_COMMON_VIDEO_FPS_MOBILE,
- REC_COMMON_VIDEO_FPS_DEN,
- REC_COMMON_VIDEO_PREVIEW_WIDTH,
- REC_COMMON_VIDEO_PREVIEW_HEIGHT,
- //*VIDEOPLAYER_FLAG_DOUBLESIZE|*/VIDEOPLAYER_FLAG_PULL|VIDEOPLAYER_FLAG_CHECKTOP,
- session->conf.ilocal_wind_flags,
- "local",
- on_pull, free_frame, session,
- &session->local_player);
- if (rc != 0)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("create local video player failed!");
- goto on_error;
- }
- else{
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("create local video player suc!");
- }
- }
- else if((session->conf.eDeviceType == ePadtype)||(session->conf.eDeviceType == eDesk2SType)||(session->conf.eDeviceType == eDesk1SType)||(session->conf.eDeviceType == eDesk2SIntegratedType))
- {
- rc = videoplayer_create(session->local_hwnd,
- 0,
- 0,
- session->conf.local_video_view_cx,
- session->conf.local_video_view_cy,
- REC_COMMON_VIDEO_FPS_MOBILE,
- REC_COMMON_VIDEO_FPS_DEN,
- REC_COMMON_VIDEO_PREVIEW_WIDTH,
- REC_COMMON_VIDEO_PREVIEW_HEIGHT,
- //*VIDEOPLAYER_FLAG_DOUBLESIZE|*/VIDEOPLAYER_FLAG_PULL|VIDEOPLAYER_FLAG_CHECKTOP,
- session->conf.ilocal_wind_flags,
- "local",
- on_pull, free_frame, session,
- &session->local_player);
-
- if (rc != 0)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("create local video player failed!");
- goto on_error;
- }
- else{
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("create local video player suc!");
- }
- }
- else if(session->conf.eDeviceType == eStand2sType)
- {
- rc = videoplayer_create(session->local_hwnd,
- 0,
- 0,
- session->conf.local_video_view_cx,
- session->conf.local_video_view_cy,
- REC_COMMON_VIDEO_FPS_NUM,
- REC_COMMON_VIDEO_FPS_DEN,
- bIsActiveInspect?REC_COMMON_VIDEO_SNAPSHOT_WIDTH:REC_COMMON_VIDEO_PREVIEW_WIDTH,
- bIsActiveInspect?REC_COMMON_VIDEO_SNAPSHOT_WIDTH:REC_COMMON_VIDEO_PREVIEW_HEIGHT,
- //*VIDEOPLAYER_FLAG_DOUBLESIZE|*/VIDEOPLAYER_FLAG_PULL|VIDEOPLAYER_FLAG_CHECKTOP,
- session->conf.ilocal_wind_flags,
- "local",
- on_pull, free_frame, session,
- &session->local_player);
- if (rc != 0)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("create local video player failed!");
- goto on_error;
- }
- else{
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("create local video player suc!");
- }
- }
- }
- else{
- if (NULL != pg_last_session){
- session->local_player = pg_last_session->local_player;
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("double record call local player reuse.");
- }
- }
- if (session->remote_hwnd)
- {
- if (0 != session->conf.remote_rtp_port)
- {
- //videortp_config_t config = {0};
- //config.fps_den = REC_COMMON_VIDEO_FPS_DEN;
- //if (session->conf.eDeviceType == eMobilePadType)
- //{
- // config.fps_num = REC_COMMON_VIDEO_FPS_MOBILE_AGENT;
- //}
- //else if((session->conf.eDeviceType == ePadtype)||(session->conf.eDeviceType == eDesk2SType)||(session->conf.eDeviceType == eDesk1SType)||(session->conf.eDeviceType == eDesk2SIntegratedType))
- //{
- // config.fps_num = REC_COMMON_VIDEO_FPS_MOBILE;
- //}
- //else if(session->conf.eDeviceType == eStand2sType)
- //{
- // config.fps_num = REC_COMMON_VIDEO_FPS_NUM;
- //}
- //config.capture_height = -1; // not use
- //config.capture_width = -1; // not use
- //config.dir = 3;
- //config.tx_width = REC_COMMON_VIDEO_RTP_WIDTH;
- //config.tx_height = REC_COMMON_VIDEO_RTP_HEIGHT;
- //config.rx_width = session->conf.remote_video_width;
- //config.rx_height = session->conf.remote_video_height;
- //config.local_ip = session->conf.local_rtp_ip;
- //config.local_pt = session->conf.local_pt;
- //config.remote_pt = session->conf.local_pt;
- //config.local_rtp_port = session->conf.local_rtp_port;
- //config.mtu = session->conf.mtu;
- //config.quant = session->conf.video_quant;
- //config.remote_ip = session->conf.remote_rtp_ip;
- //config.remote_rtp_port = session->conf.remote_rtp_port;
- //config.user_data = session;
- //config.bit_rate = session->conf.bit_rate;
- //config.on_rx_frame = &on_rx_frame;
- //config.dbg = &__dbg;
- //videortp_create(&config, &session->rtp);
- //rc = videortp_start(session->rtp);
- //if (rc != 0)
- //{
- // DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("start video rtp failed!");
- // videortp_destroy(session->rtp);
- // session->rtp = NULL;
- // goto on_error;
- //}
- //else{
- // DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("videortp_start suc.");
- //}
- if (0 != start_video_rtpsession(session)) {
- goto on_error;
- }
- if (DOUBLERECORD_CALLTYPE == session->conf.nCallType){
- if (NULL != pg_last_session){
- pg_last_session->rtp = session->rtp;
- }
- }
- //if (session->conf.eDeviceType == eMobilePadType)
- //{
- // rc = videoclock_create(REC_COMMON_VIDEO_FPS_MOBILE, REC_COMMON_VIDEO_FPS_DEN,
- // REC_COMMON_VIDEO_RTP_WIDTH, REC_COMMON_VIDEO_RTP_HEIGHT, VIDEO_FORMAT_RGB24,
- // &local_put_frame, session, &local_get_frame, session, &session->local_clock, session->conf.ref_Up_Fps);
- //}
- //else if((session->conf.eDeviceType == ePadtype)||(session->conf.eDeviceType == eDesk2SType)||(session->conf.eDeviceType == eDesk1SType)||(session->conf.eDeviceType == eDesk2SIntegratedType))
- //{
- // rc = videoclock_create(REC_COMMON_VIDEO_FPS_MOBILE, REC_COMMON_VIDEO_FPS_DEN,
- // REC_COMMON_VIDEO_RTP_WIDTH, REC_COMMON_VIDEO_RTP_HEIGHT, VIDEO_FORMAT_RGB24,
- // &local_put_frame, session, &local_get_frame, session, &session->local_clock, session->conf.ref_Up_Fps);
- //}
- //else if(session->conf.eDeviceType == eStand2sType)
- //{
- // rc = videoclock_create(REC_COMMON_VIDEO_FPS_NUM, REC_COMMON_VIDEO_FPS_DEN,
- // REC_COMMON_VIDEO_RTP_WIDTH, REC_COMMON_VIDEO_RTP_HEIGHT, VIDEO_FORMAT_RGB24,
- // &local_put_frame, session, &local_get_frame, session, &session->local_clock, session->conf.ref_Up_Fps);
- //}
- //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("create session->local_clock addr is 0x%08x", session->local_clock);
- //
- //if (rc != 0) {
- // DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("create video clock failed!");
- // goto on_error;
- //}
- //rc = videoclock_start(session->local_clock);
- //if (rc != 0) {
- // DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("start video clock failed!");
- // videoclock_destroy(session->local_clock);
- // session->local_clock = NULL;
- // goto on_error;
- //}
- if (0 != start_local_video_clock(session)) {
- goto on_error;
- }
- }
- else{
- pg_last_session = session; //保存session信息
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("begin show agent static picture.");
- show_remote_agnet_picture(session);
- }
- }
- #else
- rc = start_video_rtpsession(session);
- if (0 != rc) {
- goto on_error;
- }
- rc = start_local_video_clock(session);
- if (0 != rc) {
- goto on_error;
- }
-
- #endif // RVC_OS_WIN
- on_error:
- return rc;
- }
- static void stop_video(video_session_t *session)
- {
- LOG_FUNCTION();
- #ifdef RVC_OS_WIN
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("stop_video param video_session 0x%08x, session->local_clock is 0x%08x, session->remote_hwnd is 0x%08x.", session, session->local_clock, session->remote_hwnd);
- if (session->local_clock && session->remote_hwnd)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("videoclock_stop local_clock addr is 0x%08x", session->local_clock);
- videoclock_stop(session->local_clock);
- videoclock_destroy(session->local_clock);
- session->local_clock = NULL;
- pg_remote_hwnd = NULL;
- pg_local_hwnd = NULL;
- }
- #else
- if (session->local_clock)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("videoclock_stop local_clock addr is 0x%08x", session->local_clock);
- videoclock_stop(session->local_clock);
- videoclock_destroy(session->local_clock);
- session->local_clock = NULL;
- }
- #endif // RVC_OS_WIN
- if (session->rtp){
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("begin stop video rtp.");
- videortp_stop(session->rtp);
- videortp_destroy(session->rtp);
- session->rtp = NULL;
- }
- else {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("session->rtp == null");
- }
- #ifdef RVC_OS_WIN
- if (session->local_player) {
- videoplayer_destroy(session->local_player);
- session->local_player = NULL;
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("local video player destroy.");
- }
- if (session->remote_player && session->remote_hwnd)
- {
- videoplayer_destroy(session->remote_player);
- session->remote_player = NULL;
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("remote video player destroy.");
- }
- #else
- #endif
- if (session->local_encode_sws_ctx_env) {
- sws_freeContext(session->local_encode_sws_ctx_env);
- session->local_encode_sws_ctx_env = NULL;
- }
- if (session->local_encode_sws_ctx_opt) {
- sws_freeContext(session->local_encode_sws_ctx_opt);
- session->local_encode_sws_ctx_opt = NULL;
- }
- }
- #ifdef RVC_OS_WIN
- static bool ReMoveOutOfScreenVideoWindow(HWND hWnd, RECT rect)
- {
- bool bret = false;
- int iScreenWidth = GetSystemMetrics(SM_CXSCREEN);
- int iScreenHight = GetSystemMetrics(SM_CYSCREEN);
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("ScreenWidth = %d, ScreenHight = %d.", iScreenWidth, iScreenHight);
- int iVideoWidth = rect.right - rect.left;
- int iVideoHight = rect.bottom - rect.top;
- if (rect.left < 0) {
- if (rect.bottom <= iScreenHight) {
- MoveWindow(hWnd, 0, rect.top, iVideoWidth, iVideoHight, TRUE);
- }
- else {
- MoveWindow(hWnd, 0, iScreenHight - iVideoHight, iVideoWidth, iVideoHight, TRUE);
- }
- bret = true;
- }
- if (rect.right > iScreenWidth) {
- if (rect.bottom <= iScreenHight) {
- MoveWindow(hWnd, iScreenWidth - iVideoWidth, rect.top, iVideoWidth, iVideoHight, TRUE);
- }
- else {
- MoveWindow(hWnd, iScreenWidth - iVideoWidth, iScreenHight - iVideoHight, iVideoWidth, iVideoHight, TRUE);
- }
- bret = true;
- }
- if (rect.bottom > iScreenHight) {
- if (rect.left >= 0 && rect.right <= iScreenWidth) {
- MoveWindow(hWnd, rect.left, iScreenHight - iVideoHight, iVideoWidth, iVideoHight, TRUE);
- bret = true;
- }
- }
- return bret;
- }
- static bool ReMoveCenterOtherVideoWindow(HWND hWnd, RECT rect, RECT otherect)
- {
- bool bret = false;
- int iVideoWidth = rect.right - rect.left;
- int iVideoHight = rect.bottom - rect.top;
- int iOtherVideoWidth = otherect.right - otherect.left;
- int iOtherVideoHight = otherect.bottom - otherect.top;
- if (iVideoWidth > iOtherVideoHight || iVideoHight > iOtherVideoHight) {
- return bret;
- }
- if (rect.left > otherect.left + iVideoWidth && rect.right < otherect.right) {
- if (rect.top > otherect.top && rect.bottom < otherect.bottom) {
- if (otherect.right - rect.right <= rect.left - otherect.left) {
- MoveWindow(hWnd, otherect.right - iVideoWidth, rect.top, iVideoWidth, iVideoHight, TRUE);
- }
- else {
- MoveWindow(hWnd, otherect.left, rect.top, iVideoWidth, iVideoHight, TRUE);
- }
- bret = true;
- }
- }
- if (rect.right < otherect.right - iVideoWidth && rect.left > otherect.left) {
- if (rect.top > otherect.top && rect.bottom < otherect.bottom) {
- if (otherect.right - rect.right <= rect.left - otherect.left) {
- MoveWindow(hWnd, otherect.right - iVideoWidth, rect.top, iVideoWidth, iVideoHight, TRUE);
- }
- else {
- MoveWindow(hWnd, otherect.left, rect.top, iVideoWidth, iVideoHight, TRUE);
- }
- bret = true;
- }
- }
- return bret;
- }
- static bool ReMoveVideoWindow(HWND hWnd, RECT rect, RECT otherect)
- {
- LOG_FUNCTION();
- bool bret = false;
- bret = ReMoveOutOfScreenVideoWindow(hWnd, rect);
- bret = ReMoveCenterOtherVideoWindow(hWnd, rect, otherect);
- return bret;
- }
- static int HandleVideoMoveEvent(int iMessageType, HWND hWnd, video_session_t* pSession)
- {
- LOG_FUNCTION();
- int iRet = -1;
- if (NULL == pSession || NULL == hWnd) {
- return iRet;
- }
- HWND hOtherWnd = NULL;
- //本地和远端标识 1为本地,2为远端
- int iVideoType = 2;
- if (hWnd == pSession->local_hwnd) {
- iVideoType = 1;
- hOtherWnd = pSession->remote_hwnd;
- }
- else {
- hOtherWnd = pSession->local_hwnd;
- }
- if (NULL == hOtherWnd) {
- return iRet;
- }
- bool bMoved = false;
- RECT rect;
- GetWindowRect(hWnd, &rect);
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("MessageType = %d, VideoType = %d, rect.left = %d, rect.right = %d, rect.bottom = %d, rect.top = %d", iMessageType, iVideoType, rect.left, rect.right, rect.bottom, rect.top);
- RECT otherect;
- GetWindowRect(hOtherWnd, &otherect);
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("other video Window left = %d, right = %d, bottom = %d, top = %d", otherect.left, otherect.right, otherect.bottom, otherect.top);
- bMoved = ReMoveVideoWindow(hWnd, rect, otherect);
- if (bMoved) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("has removed video window.");
- GetWindowRect(hWnd, &rect);
- }
- if (NULL != pSession->conf.video_echo_cb && NULL != pSession->conf.video_echo_cb->on_video_box_move) {
- pSession->conf.video_echo_cb->on_video_box_move(iMessageType, iVideoType, rect.left, rect.bottom, pSession->conf.video_echo_cb->user_data);
- iRet = 0;
- }
- return iRet;
- }
- #else
- #endif // RVC_OS_WIN
- #ifdef RVC_OS_WIN
- static LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
- {
- video_session_t* session = (video_session_t*)GetWindowLongPtrA(hWnd, GWLP_USERDATA);
- switch (msg) {
- case WM_DESTROY:
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("WndProc session addr is 0x%08x, and receive WM_DESTROY.", session);
- if (session->local_hwnd == hWnd) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("session->local_hwnd = 0");
- session->local_hwnd = 0;
- }
- else if (session->remote_hwnd == hWnd) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("session->remote_hwnd = 0");
- session->remote_hwnd = 0;
- }
- if (session->local_hwnd == 0 && session->remote_hwnd == 0) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("*****PostQuitMessage****");
- PostQuitMessage(0);
- }
- return 0;
- case WM_NCHITTEST:
- if (((session->local_hwnd == hWnd) && (0 != session->conf.local_move)) || ((session->remote_hwnd == hWnd) && (0 != session->conf.remote_move))) {
- return HTCAPTION;
- }
- else {
- break;
- }
- case WM_ACTIVATE:
- case WM_TOUCH:
- case WM_GESTURE:
- ReleaseCapture();
- return 0;
- #if 1
- case WM_WINDOWPOSCHANGED:
- {
- LPWINDOWPOS pPos = (LPWINDOWPOS)lParam;
- if (pPos->hwndInsertAfter != HWND_TOPMOST && pPos->hwndInsertAfter != HWND_TOP) {
- //BringWindowToTop(hWnd);
- SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
- }
- else {
- return DefWindowProc(hWnd, msg, wParam, lParam);
- }
- }
- return 0;
- //return DefWindowProc(hWnd, msg, wParam, lParam);
- #endif
- case WM_MBUTTONDOWN:
- case WM_MBUTTONUP:
- case WM_MBUTTONDBLCLK:
- case WM_LBUTTONDBLCLK:
- case WM_LBUTTONDOWN:
- case WM_LBUTTONUP:
- OutputDebugStringA("mouse clicked!");
- if (session) {
- if (session->local_hwnd) {
- //ReleaseCapture();
- }
- }
- return 0;
- case WM_CLOSE:
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("WndProc session addr is 0x%08x, and receive WM_CLOSE", session);
- stop_video(session);
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("WndProc SetEvent session addr is 0x%08x.", session);
- //SetEvent(session->ui_thread);
- DestroyWindow(session->local_hwnd);
- DestroyWindow(session->remote_hwnd);
- return 0;
- case WM_MOVE:
- break;
- case WM_ENTERSIZEMOVE:
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("***WM_ENTERSIZEMOVE***");
- HandleVideoMoveEvent(0, hWnd, session);
- }
- break;
- case WM_EXITSIZEMOVE:
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("***WM_EXITSIZEMOVE***");
- HandleVideoMoveEvent(1, hWnd, session);
- }
- break;
- default:
- return DefWindowProc(hWnd, msg, wParam, lParam);
- }
- }
- #endif //
- #ifdef RVC_OS_WIN
- static unsigned int __stdcall ui_proc(void *arg)
- {
- video_session_t *session = (video_session_t*)arg;
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("ui_proc session addr is 0x%08x", session);
- WNDCLASSA wc = {0};
- ATOM a = 0;
- HWND hWnd = NULL;
- MSG msg;
- HINSTANCE hInst = ModuleBase::GetModuleBase()->GetInstance();
- bool breuse_local_wnd = false;
- bool breuse_remote_wnd = false;
- DWORD dLocal_style = WS_EX_TOOLWINDOW | WS_EX_TOPMOST | WS_EX_NOACTIVATE;
- DWORD dRemote_style = WS_EX_TOOLWINDOW | WS_EX_TOPMOST | WS_EX_NOACTIVATE;
- //双录两阶段视频窗口复用
- if (NULL != pg_local_hwnd){
- session->local_hwnd = pg_local_hwnd;
- //SetWindowLongPtrA(session->local_hwnd, GWLP_USERDATA, (LONG_PTR)session);
- breuse_local_wnd = true;
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("local video hwnd reuse.");
- }
- else{
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("create local video hwnd and x = %d, y = %d, width = %d, height = %d.",
- session->conf.local_video_view_x, session->conf.local_video_view_y, session->conf.local_video_view_cx, session->conf.local_video_view_cy);
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("local video move flag is %d, remote video move flag is %d.", session->conf.local_move, session->conf.remote_move);
-
- if (0 != session->conf.local_move){
- dLocal_style -= WS_EX_NOACTIVATE;
- }
- if (0 != session->conf.remote_move){
- dRemote_style -= WS_EX_NOACTIVATE;
- }
- CoInitialize(0);
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hInstance = hInst;
- wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
- wc.hCursor = NULL;
- wc.hIcon = NULL;
- wc.lpfnWndProc = &WndProc;
- wc.lpszClassName = WNDCLS_NAME;
- wc.style = CS_HREDRAW | CS_OWNDC | CS_VREDRAW;
- a = RegisterClassA(&wc);
- if (a == 0)
- return 0;
- session->local_hwnd = CreateWindowExA(dLocal_style,
- WNDCLS_NAME, NULL, WS_POPUP|WS_VISIBLE,
- session->conf.local_video_view_x, session->conf.local_video_view_y, session->conf.local_video_view_cx, session->conf.local_video_view_cy,
- NULL, NULL, hInst, NULL);
- if (session->local_hwnd) {
- SetWindowLongPtrA(session->local_hwnd, GWLP_USERDATA, (LONG_PTR)session);
- if (0 == session->conf.local_move){
- SetWindowPos(session->local_hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
- }
- pg_local_hwnd = session->local_hwnd;
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("restore local video hwnd");
- }
- }
- if(session->conf.remote_video_view_x||session->conf.remote_video_view_y||session->conf.remote_video_view_cx||session->conf.remote_video_view_cy)
- {
- if (NULL != pg_remote_hwnd){
- session->remote_hwnd = pg_remote_hwnd;
- //SetWindowLongPtrA(session->remote_hwnd, GWLP_USERDATA, (LONG_PTR)session);
- breuse_remote_wnd = true;
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("remote video hwnd reuse.");
- if (NULL != pg_last_session){
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("SetEvent pg_last_session->ui_event and ui_event addr is %8x.", pg_last_session->ui_event);
- record_agent_picture_show_session_destory(pg_last_session);
- }
- }
- else{
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("create remote video hwnd x = %d, y = %d, width = %d, height = %d.", session->conf.remote_video_view_x, session->conf.remote_video_view_y, session->conf.remote_video_view_cx, session->conf.remote_video_view_cy);
- session->remote_hwnd = CreateWindowExA(dRemote_style,
- WNDCLS_NAME, NULL, WS_POPUP|WS_VISIBLE,
- session->conf.remote_video_view_x, session->conf.remote_video_view_y, session->conf.remote_video_view_cx, session->conf.remote_video_view_cy,
- NULL, NULL, hInst, NULL);
- if (session->remote_hwnd) {
- SetWindowLongPtrA(session->remote_hwnd, GWLP_USERDATA, (LONG_PTR)session);
- if (0 == session->conf.remote_move){
- SetWindowPos(session->remote_hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
- }
- pg_remote_hwnd = session->remote_hwnd;
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("restore remote video hwnd.");
- }
- }
- }
- else
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("remote_hwnd == Null");
- session->remote_hwnd = NULL;
- }
- if (session->local_hwnd/* && session->remote_hwnd*/)
- {
- int rc = 0;
- ShowCursor(FALSE);
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("SetEvent1 session addr is 0x%08x.", session);
- SetEvent(session->ui_event);
- rc = start_video(session);
- if (rc != 0)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("start video failed!");
- }
- else
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("start video ok!");
- }
- if (!breuse_local_wnd && !breuse_remote_wnd)
- {
- while (GetMessageA(&msg, NULL, NULL, NULL))
- {
- if (msg.message == WM_CLOSE) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("session addr is 0x%08x, session->local_hwnd is 0x%08x, rx WM_CLOSE", session, session->local_hwnd);
- }
- TranslateMessage(&msg);
- DispatchMessageA(&msg);
- }
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("SetEvent2 session addr is 0x%08x.", session);
- SetEvent(session->ui_event);
- }
- }
- if (a)
- UnregisterClassA(WNDCLS_NAME, hInst);
- CoUninitialize();
- return 0;
- }
- #else
- static void __video_render_log(void* user_data, const char* fmt, va_list arg)
- {
- vDbg(fmt, arg);
- }
- //void* videorender_func(void* arg)
- //{
- // LOG_FUNCTION();
- // video_session_t* session = (video_session_t*)arg;
- // DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s:%d session addr is 0x%08x, session->plocal_render = 0x%08x", __FUNCTION__, __LINE__, session, session->plocal_render);
- // char str_local_ip[MAX_PATH_SIZE] = { 0 };
- // char str_remote_ip[MAX_PATH_SIZE] = { 0 };
- // translate_ipaddr_from_int(str_local_ip, MAX_PATH_SIZE, session->conf.local_rtp_ip);
- // translate_ipaddr_from_int(str_remote_ip, MAX_PATH_SIZE, session->conf.remote_rtp_ip);
- // int ilocal_video_fresh_time = session->conf.ilvideo_ft;
- // DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("videorender_func local_pt: %d local_ip: %s local_rtp_port: %d, local video fresh time is %dms.", session->conf.local_pt, str_local_ip, session->conf.local_rtp_port, ilocal_video_fresh_time);
- // DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("videorender_func remote_pt: %d remote_ip: %s remote_rtp_port: %d.", session->conf.remote_pt, str_remote_ip, session->conf.remote_rtp_port);
- // DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("videorender_func rx_width: %d rx_height: %d.", session->conf.remote_video_width, session->conf.remote_video_height);
- // DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s:%d local(%d,%d,%d,%d) remote(%d,%d,%d,%d).", __FUNCTION__, __LINE__, session->conf.local_video_view_x, session->conf.local_video_view_y, session->conf.local_video_view_cx, session->conf.local_video_view_cy,
- // session->conf.remote_video_view_x, session->conf.remote_video_view_y, session->conf.remote_video_view_cx, session->conf.remote_video_view_cy);
- //
- // videorender_callback_t t_callback = { 0 };
- // t_callback.debug = &__video_render_log;
- // session->plocal_render = CreateVideoRenderObj(&t_callback);
- // if (NULL != session->plocal_render){
- // videorender_param_t tparam = { 0 };
- // tparam.icx = session->conf.local_video_view_x;
- // tparam.icy = session->conf.local_video_view_y;
- // tparam.uwidth = session->conf.local_video_view_cx;
- // tparam.uheight = session->conf.local_video_view_cy;
- // tparam.ivideoformat = VIDEO_FORMAT_RGB24;
- // LogWarn(Severity_Low, Error_Debug, EVENT_MOD_SIP_LOCAL_VIDEO_RENDER_CREATE, "local video render create.");
- // if (0 == session->plocal_render->VideoRenderSetParam(&tparam)){
- // session->plocal_render->HideVideoWindow();
- // }
- // else {
- // DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s:%d set video render param failed!", __FUNCTION__, __LINE__);
- // return 0;
- // }
- // }
- //
- // if (session->conf.remote_video_view_x || session->conf.remote_video_view_y || session->conf.remote_video_view_cx || session->conf.remote_video_view_cy){
- // DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s:%d create remote video hwnd x = %d, y = %d, width = %d, height = %d.", __FUNCTION__, __LINE__, session->conf.remote_video_view_x, session->conf.remote_video_view_y, session->conf.remote_video_view_cx, session->conf.remote_video_view_cy);
- // session->premote_render = CreateVideoRenderObj(&t_callback);
- // if (session->premote_render){
- // videorender_param_t tparam_remote = { 0 };
- // tparam_remote.icx = session->conf.remote_video_view_x;
- // tparam_remote.icy = session->conf.remote_video_view_y;
- // tparam_remote.uwidth = session->conf.remote_video_view_cx;
- // tparam_remote.uheight = session->conf.remote_video_view_cy;
- // tparam_remote.ivideoformat = VIDEO_FORMAT_RGB24;
- // if (0 == session->premote_render->VideoRenderSetParam(&tparam_remote)) {
- // //session->premote_render->ShowVideoWindow();
- // }
- // LogWarn(Severity_Low, Error_Debug, EVENT_MOD_SIP_REMOTE_VIDEO_RENDER_CREATE, "remote video render create.");
- // }
- // else {
- // DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("session remote video render is null.");
- // }
- // }
- //
- // if (session->plocal_render){
- // start_video(session);
- // bool bshow_local = false;
- // bool bset = true;
- //
- // session->plocal_render->StartVideoRender();
- // for (; ; ) {
- // struct timespec ts;
- // clock_gettime(CLOCK_REALTIME, &ts);
- // long unsec = ts.tv_nsec + (1000 * 1000 * ilocal_video_fresh_time);
- // ts.tv_sec += (unsec / 1000000000);
- // ts.tv_nsec = (unsec % 1000000000);
- // if (0 != sem_timedwait(&session->ui_stop_sem, &ts) && (ETIMEDOUT == errno))
- // {
- // video_frame* local_video_frame = NULL;
- // DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s:%d", __FUNCTION__, __LINE__);
- // int iwindowstate = get_local_video_frame(session, &local_video_frame);
- // DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s:%d", __FUNCTION__, __LINE__);
- // if (iwindowstate != session->ilast_windstae){
- // set_video_windows(session, iwindowstate);
- // session->ilast_windstae = iwindowstate;
- // DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s:%d, window state is %d.", __FUNCTION__, __LINE__, iwindowstate);
- // }
- //
- // if (NULL != local_video_frame) {
- // DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s:%d, video size is (%d,%d), showPersonArea flag is %d.", __FUNCTION__, __LINE__, local_video_frame->width, local_video_frame->height, *session->conf.ref_Is_showPersonArea);
- // video_frame* localframe = NULL;
- // DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s:%d", __FUNCTION__, __LINE__);
- // if (0 == translate_image_resolution(&localframe, session->conf.local_video_view_cx, session->conf.local_video_view_cy, local_video_frame)) {
- // DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s:%d", __FUNCTION__, __LINE__);
- // session->plocal_render->RenderVideoFrame(localframe, RVC_FLIP_VERTICAL);
- // DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s:%d", __FUNCTION__, __LINE__);
- // video_frame_delete(localframe);
- // DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s:%d", __FUNCTION__, __LINE__);
- // localframe = NULL;
- // }
- // else {
- // DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s:%d", __FUNCTION__, __LINE__);
- // session->plocal_render->RenderVideoFrame(local_video_frame, RVC_FLIP_VERTICAL);
- // DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s:%d", __FUNCTION__, __LINE__);
- // }
- //
- // if (false == session->blocalrender){
- // LogWarn(Severity_Low, Error_Debug, EVENT_MOD_SIP_LOCAL_VIDEO_RENDER_STARTED, "start local video render.");
- // session->blocalrender = true;
- // }
- //
- // bshow_local = true;
- // video_frame_delete(local_video_frame);
- // local_video_frame = NULL;
- // }
- // else {
- // DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s:%d,get video from shm preview queue failed!", __FUNCTION__, __LINE__);
- // }
- // }
- // else {
- // DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s:%d videorender_func exit!", __FUNCTION__, __LINE__);
- // session->plocal_render->HideVideoWindow();
- // break;
- // }
- //
- // if (bset){
- // if (bshow_local && session->bshow_remote) {
- // session->plocal_render->ShowVideoWindow();
- // session->premote_render->ShowVideoWindow();
- // bset = false;
- // }
- // }
- // }
- // session->plocal_render->StopVideoRender();
- // }
- //
- // return 0;
- //}
- #endif // RVC_OS_WIN
- static int start_ui(video_session_t *session)
- {
- LOG_FUNCTION();
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("start ui session addr is 0x%08x", session);
- #ifdef RVC_OS_WIN
- session->ui_event = CreateEventA(NULL, FALSE, FALSE, NULL);
- if (!session->ui_event) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("phonemedia_start create ui event failed!");
- return Error_Resource;
- }
- else{
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("session->ui_event = 0x%8x", session->ui_event);
- }
- session->ui_thread = (HANDLE)_beginthreadex(NULL, 0, &ui_proc, session, 0, NULL);
- if (!session->ui_thread) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("phonemedia_start create ui thread failed!");
- CloseHandle(session->ui_event);
- session->ui_event = NULL;
- return Error_Resource;
- }
- else{
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("session %8x create session->ui_thread = %8x", session, session->ui_thread);
- }
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("ui thread created ok!");
- {
- HANDLE hs[] = {session->ui_event, session->ui_thread};
- DWORD dwRet = WaitForMultipleObjects(array_size(hs), hs, FALSE, INFINITE);
- if (dwRet == WAIT_OBJECT_0) { //
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("wait for ui ready event ok!");
- } else if (dwRet == WAIT_OBJECT_0 + 1) { // thread exit
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("ui thread aborted unexpected!");
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("CloseHandle ui_thread 0x%08x", session->ui_thread);
- CloseHandle(session->ui_thread);
- session->ui_thread = NULL;
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("CloseHandle ui_event 0x%08x", session->ui_event);
- CloseHandle(session->ui_event);
- session->ui_event = NULL;
- return Error_Resource;
- }
- }
- return 0;
- #endif // RVC_OS_WIN
- }
- static void stop_ui(video_session_t *session)
- {
- LOG_FUNCTION();
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s:%d session addr is 0x%08x.", __FUNCTION__, __LINE__, session);
- #ifdef RVC_OS_WIN
- if (DOUBLERECORD_CALLTYPE == session->conf.nCallType) {
- if (NULL != pg_last_session) {
- pg_last_session->rtp = session->rtp;
- pg_last_session->local_clock = session->local_clock;
- CloseHandle(session->ui_thread);
- session->ui_thread = NULL;
- CloseHandle(session->ui_event);
- session->ui_event = NULL;
- session = pg_last_session;
- }
- }
- if (NULL != session->pic_record) {
- if (NULL != session->pic_record->work_thread) {
- SetEvent(session->pic_record->evt);
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("CloseHandle pic_record ui_thread 0x%08x", session->pic_record->work_thread);
- CloseHandle(session->pic_record->work_thread);
- session->pic_record->work_thread = NULL;
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("CloseHandle pic_record ui_event 0x%08x", session->pic_record->evt);
- CloseHandle(session->pic_record->evt);
- session->pic_record->evt = NULL;
- }
- }
- if (session->local_hwnd) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("PostMessageA WM_CLOSE session addr is 0x%08x, session->local_hwnd = 0x%08x", session, session->local_hwnd);
- BOOL bRet = PostMessageA(session->local_hwnd, WM_CLOSE, 0, 0);
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("WaitForSingleObject session addr is %8x, and session->ui_thread is %8x.", session, session->ui_thread);
- DWORD dCode = WaitForSingleObject(session->ui_thread, INFINITE);
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("After WaitForSingleObject (session->ui_thread, INFINITE) session addr is %8x, and session->ui_thread = 0x%08x.", session, session->ui_thread);
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("CloseHandle ui_thread 0x%08x", session->ui_thread);
- CloseHandle(session->ui_thread);
- session->ui_thread = NULL;
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("CloseHandle ui_event 0x%08x", session->ui_event);
- CloseHandle(session->ui_event);
- session->ui_event = NULL;
- }
- pg_last_session = NULL;
- pg_local_hwnd = NULL;
- pg_remote_hwnd = NULL;
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("set pg_last_session to null.");
- #endif
- }
- static int load_record_area_png(video_session_t *session)
- {
- int iret = -1;
- if (NULL == session){
- return iret;
- }
- //加载双录人形背景框
- char strPath[MAX_PATH_SIZE]={0};
- char strRecordAreaPath[MAX_PATH_SIZE] = { 0 };
- #ifdef RVC_OS_WIN
- GetCurrentRunPath(strPath);
- sprintf(strRecordAreaPath, "%s\\bin\\recordarea.png", strPath);
- if (ExistsFile(strRecordAreaPath))
- {
- if (session->recordareaimage == NULL)
- {
- if((session->conf.eDeviceType == eMobilePadType)||(session->conf.eDeviceType == ePadtype)||(session->conf.eDeviceType == eDesk2SType)||(session->conf.eDeviceType == eDesk1SType)||(session->conf.eDeviceType == eDesk2SIntegratedType))
- {
- //pad版对人形区域放大处理
- session->recordareaimage = cvLoadImage(strRecordAreaPath);
- IplImage* tmp = cvCreateImage(cvSize(session->recordareaimage->width,session->recordareaimage->height),IPL_DEPTH_8U,3);
- cvResize(session->recordareaimage ,tmp);
- cvSetImageROI(tmp,cvRect(0,0,session->recordareaimage->width,session->recordareaimage->height));
- //cvSetImageROI(tmp,cvRect(0,0,session->recordareaimage->width,session->recordareaimage->height));
- cvCopy(tmp,session->recordareaimage);
- cvReleaseImage(&tmp);
- }
- else
- {
- session->recordareaimage = cvLoadImage(strRecordAreaPath);
- }
- }
- if (session->recordareamask == NULL )
- {
- if((session->conf.eDeviceType == eMobilePadType)||(session->conf.eDeviceType == ePadtype)||(session->conf.eDeviceType == eDesk2SType)||(session->conf.eDeviceType == eDesk1SType)||(session->conf.eDeviceType == eDesk2SIntegratedType))
- {
- //pad版对人形区域放大处理
- session->recordareamask = cvLoadImage(strRecordAreaPath,0);
- IplImage* tmp = cvCreateImage(cvSize(session->recordareamask->width,session->recordareamask->height),IPL_DEPTH_8U,1);
- cvResize(session->recordareamask ,tmp);
- cvSetImageROI(tmp,cvRect(0,0,session->recordareamask->width,session->recordareamask->height));
- cvCopy(tmp,session->recordareamask);
- cvReleaseImage(&tmp);
- }
- else
- {
- session->recordareamask = cvLoadImage(strRecordAreaPath,0);
- }
- }
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Load record area img Success");
- iret = 0;
- }
- else
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Load record area img Fail");
- session->recordareaimage = NULL;
- session->recordareamask = NULL;
- }
- #endif // RVC_OS_WIN
- return iret;
- }
- int video_session_create(const video_session_conf_t *conf, video_session_t **p_session)
- {
- LOG_FUNCTION();
- video_session_t *session = ZALLOC_T(video_session_t);
- if (session)
- {
- char str_local[MAX_PATH_SIZE] = {0};
- char str_remote[MAX_PATH_SIZE] = {0};
- translate_ipaddr_from_int(str_local, MAX_PATH_SIZE, conf->local_rtp_ip);
- translate_ipaddr_from_int(str_remote, MAX_PATH_SIZE, conf->remote_rtp_ip);
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("video_session_create session addr = 0x%08x,local_rtp_ip = %s,local_rtp_port = %d, local_pt = %d, remote_rtp_ip = %s,remote_rtp_port=%d, remote_pt = %d, call type = %d.",
- session, str_local, conf->local_rtp_port,conf->local_pt, str_remote, conf->remote_rtp_port, conf->remote_pt, conf->nCallType);
- memcpy(&session->conf, conf, sizeof(video_session_conf_t));
- //session->bshow_remote = false;
- //session->ilast_windstae = 0;
- session->video_shm_q_env = new Clibvideoqueue(REC_COMMON_VIDEO_ENV_SHM_RTP_QUEUE);
- session->video_shm_q_remote = new Clibvideoqueue(REC_COMMON_VIDEO_REMOTE_SHM_RTP_QUEUE);
- session->video_shm_q_preview = new Clibvideoqueue(REC_COMMON_VIDEO_ENV_SHM_PREVIEW_QUEUE);
- char strPath[MAX_PATH_SIZE]={0};
- char strImgPath[MAX_PATH_SIZE]={0};
- #ifdef RVC_OS_WIN
- GetCurrentRunPath(strPath);
- sprintf(strImgPath, "%s\\bin\\error.jpg", strPath);
- #else
- snprintf(strImgPath, MAX_PATH_SIZE, "%s", "./bin/error.jpg");
- #endif // RVC_OS_WIN
- if (ExistsFile(strImgPath))
- {
- IplImage*img = cvLoadImage(strImgPath,1);
- if (img != NULL)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("load img success");
- session->video_error = new videoq_frame;
- session->video_error->format = VIDEOQ_FORMAT_RGB24;
- session->video_error->framesize = 320*180*3;
- session->video_error->height = 180;
- session->video_error->width = 320;
- session->video_error->data = new unsigned char[320*180*3];
- memcpy(session->video_error->data,img->imageData,320*180*3);
- cvReleaseImage(&img);
- }
- }
- else
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Load error img Fail");
- session->video_error = NULL;
- }
- //加载人形背景框
- char strPersonPath[MAX_PATH_SIZE] = {0};
- #ifdef RVC_OS_WIN
- sprintf(strPersonPath, "%s\\bin\\rxk.jpg", strPath);
- #else
- snprintf(strPersonPath, MAX_PATH_SIZE, "./bin/rxk.jpg");
- #endif // RVC_OS_WIN
- if (ExistsFile(strPersonPath))
- {
- if (session->personimage == NULL)
- {
- if(eMobilePadType == session->conf.eDeviceType)
- {
- //pad版对人形区域放大处理
- session->personimage = cvLoadImage(strPersonPath);
- IplImage*tmp = cvCreateImage(cvSize(session->personimage->width*3/2,session->personimage->height*3/2),IPL_DEPTH_8U,3);
- cvResize(session->personimage ,tmp);
- cvSetImageROI(tmp,cvRect(session->personimage->width/4,50,session->personimage->width,session->personimage->height));
- cvCopy(tmp,session->personimage);
- cvReleaseImage(&tmp);
- }
- else
- {
- session->personimage = cvLoadImage(strPersonPath);
- }
- }
- if (session->personmask == NULL )
- {
- if(eMobilePadType == session->conf.eDeviceType)
- {
- //pad版对人形区域放大处理
- session->personmask = cvLoadImage(strPersonPath,0);
- IplImage*tmp = cvCreateImage(cvSize(session->personmask->width*3/2,session->personmask->height*3/2),IPL_DEPTH_8U,1);
- cvResize(session->personmask ,tmp);
- cvSetImageROI(tmp,cvRect(session->personmask->width/4,50,session->personmask->width,session->personmask->height));
- cvCopy(tmp,session->personmask);
- cvReleaseImage(&tmp);
- }
- else
- {
- session->personmask = cvLoadImage(strPersonPath,0);
- }
- }
- //IplImage*persongrey = cvLoadImage(strPersonPath,CV_LOAD_IMAGE_GRAYSCALE);
- //二值化提取人形框掩码
- //cvThreshold(persongrey,session->personmask,150, 255, CV_THRESH_BINARY);
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Load person img Success");
- }
- else
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Load person img Fail");
- session->personimage = NULL;
- session->personmask = NULL;
- }
-
- #if 0
- video_frame frame;
- video_frame_alloc(320, 180, VIDEO_FORMAT_RGB24, &frame);
- video_frame_fill_black(&frame);
- videoq_frame frm;
- frm.data = frame.data[0];
- session->video_shm_q_env->GetVideo(&frm, 0);
- video_frame_save_bmpfile("d:\\a.bmp", &frame);
- #endif
- if (conf->camera_count == 2) {
- session->video_shm_q_opt = new Clibvideoqueue(REC_COMMON_VIDEO_OPT_SHM_RTP_QUEUE);
- }
- session->bvideorecved = false;
- session->blocalrender = false;
- session->bremoterender = false;
- *p_session = session;
- }
- return 0;
- }
- int video_session_start(video_session_t *session)
- {
- LOG_FUNCTION();
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("video_session_start session addr is 0x%08x, session call type is %d.", session, session->conf.nCallType);
- int rc = -1;
- #ifdef RVC_OS_WIN
- rc = start_ui(session);
- #else
- rc = start_video(session);
- #endif // RVC_OS_WIN
- return rc;
- }
- void video_session_stop(video_session_t *session)
- {
- LOG_FUNCTION();
- #ifdef RVC_OS_WIN
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("video session stop session addr is 0x%08x", session);
- stop_ui(session);
- #else
- stop_video(session);
- #endif
- }
- void video_session_destroy(video_session_t *session)
- {
- LOG_FUNCTION();
- if (session->video_error){
- delete session->video_error->data;
- delete session->video_error;
- }
- if (session->video_shm_q_remote) {
- delete session->video_shm_q_remote;
- session->video_shm_q_remote = NULL;
- }
- if (session->personimage){
- cvReleaseImage(&session->personimage);
- }
- if (session->personmask){
- cvReleaseImage(&session->personmask);
- }
- if (session->recordareaimage){
- cvReleaseImage(&session->recordareaimage);
- }
- if (session->recordareamask){
- cvReleaseImage(&session->recordareamask);
- }
- free(session);
- }
- void av_log_cb(void*ptr, int level, const char*fmt, va_list list)
- {
- vDbg(fmt, list);
- }
- int video_lib_init()
- {
- #ifdef RVC_OS_WIN
- CoInitialize(NULL);
- {
- int i, n;
- n = videocap_get_device_count();
- for (i = 0; i < n; ++i) {
- WCHAR tmp[128];
- char t[128];
- videocap_get_device_name(i, tmp, ARRAYSIZE(tmp));
- WideCharToMultiByte(CP_ACP, 0, tmp, -1, t, sizeof(t), 0, NULL);
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%d = %s", i, t);
- }
- }
- videoframework_init();
- av_log_set_callback(&av_log_cb);
- //av_log_set_level(AV_LOG_DEBUG);
- av_log_set_level(AV_LOG_QUIET);
-
- #else
- videoframework_init();
- if (0 == VideoRender_Init()){
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("sdl init success.");
- }
- else {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("sdl init failed.");
- }
- //av_log_set_callback(&av_log_cb);
- //av_log_set_level(AV_LOG_TRACE);
- //av_log_set_level(AV_LOG_QUIET);
- #endif // RVC_OS_WIN
- return 0;
- }
- void video_lib_deinit()
- {
- #ifdef RVC_OS_WIN
- CoUninitialize();
- #else
- #endif // RVC_OS_WIN
- videoframework_term();
- VideoRender_Term();
- }
|