|
@@ -1,663 +0,0 @@
|
|
|
-#include "stdafx.h"
|
|
|
-#include <io.h>
|
|
|
-#include "SpBase.h"
|
|
|
-#include "libvideoecho.h"
|
|
|
-#include "videoframework.h"
|
|
|
-#include "memutil.h"
|
|
|
-#include "libvideoqueue.h"
|
|
|
-
|
|
|
-#include "../rvcmediacommon/rvc_media_common.h"
|
|
|
-
|
|
|
-#include <videocommon.h>
|
|
|
-#include <videoutil.h>
|
|
|
-#include <videoplayer.h>
|
|
|
-#include <videocap.h>
|
|
|
-#include <videortp.h>
|
|
|
-#include <videoclock.h>
|
|
|
-
|
|
|
-//#include <ipp.h>
|
|
|
-//#include "videohorflip.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>
|
|
|
-}
|
|
|
-
|
|
|
-//#define WNDCLS_NAME "rvc_echo_video"
|
|
|
-#define MAX_PATH_SIZE 256
|
|
|
-//#define FPS_KEEP_TIME 3
|
|
|
-
|
|
|
-using namespace LibVideoEcho;
|
|
|
-
|
|
|
-namespace LibVideoEcho {
|
|
|
- struct videoplay_session_t
|
|
|
- {
|
|
|
- videoplay_session_conf_t conf;
|
|
|
-
|
|
|
- Clibvideoqueue *video_preview_queue0; // preview queue0
|
|
|
- Clibvideoqueue *video_preview_queue1; // preview queue1
|
|
|
- videoq_frame*video_error;
|
|
|
- videoplayer_t *local_player;
|
|
|
- videoclock_t local_clock;
|
|
|
-
|
|
|
- HANDLE ui_thread;
|
|
|
- HANDLE ui_event;
|
|
|
-
|
|
|
- HWND local_hwnd; // preview window
|
|
|
- TCHAR wndname[256];
|
|
|
- int frame_width[2];
|
|
|
- int frame_height[2];
|
|
|
- };
|
|
|
-}
|
|
|
-
|
|
|
-//static void av_log_cb(void*ptr, int level, const char*fmt, va_list list)
|
|
|
-//{
|
|
|
-// //vDbg(fmt, list);
|
|
|
-//}
|
|
|
-
|
|
|
-//static void __dbg(void *user_data, const char *fmt, va_list arg)
|
|
|
-//{
|
|
|
-// vDbg(fmt, arg);
|
|
|
-//}
|
|
|
-
|
|
|
-//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 void __delete_frame(videoplayer_t *player, void *user_data, video_frame *frame)
|
|
|
-//{
|
|
|
-// video_frame_delete(frame);
|
|
|
-//}
|
|
|
-
|
|
|
-//static inline Clibvideoqueue *get_active_videoqueue(videoplay_session_t *session)
|
|
|
-//{
|
|
|
-// int camera_state = *session->conf.ref_camera_state;
|
|
|
-// Clibvideoqueue *active = NULL;
|
|
|
-// if((camera_state!=CAMERA_TYPE_EWS)&&(camera_state!=CAMERA_TYPE_AUTO))
|
|
|
-// {
|
|
|
-// active = NULL;
|
|
|
-// }
|
|
|
-// else
|
|
|
-// {
|
|
|
-// active = session->video_shm_q_rtp;
|
|
|
-// }
|
|
|
-//
|
|
|
-// return active;
|
|
|
-//}
|
|
|
-
|
|
|
-
|
|
|
-//static void local_get_frame(void *user_data, video_frame *frame)
|
|
|
-//{
|
|
|
-// videoplay_session_t *session = (videoplay_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);
|
|
|
-// //Ìùͼ
|
|
|
-// Dbg("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
|
|
|
-// {
|
|
|
-// Dbg("video error img is null");
|
|
|
-// }
|
|
|
-// }
|
|
|
-//}
|
|
|
-
|
|
|
-//static void local_put_frame(void *user_data, video_frame *frame)
|
|
|
-//{
|
|
|
-// videoplay_session_t *session = (videoplay_session_t*)user_data;
|
|
|
-// video_frame *tmp_frame_encode = NULL;
|
|
|
-// int rc;
|
|
|
-//
|
|
|
-// // 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) {
|
|
|
-// 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, frame->data, frame->linesize, 0, frame->height, dst_data, tmp_frame_encode->linesize);
|
|
|
-// }
|
|
|
-// videortp_send_frame(session->rtp, tmp_frame_encode);
|
|
|
-// }
|
|
|
-//
|
|
|
-//on_error:
|
|
|
-// if (tmp_frame_encode) {
|
|
|
-// video_frame_delete(tmp_frame_encode);
|
|
|
-// }
|
|
|
-//}
|
|
|
-
|
|
|
-
|
|
|
-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_pull(videoplayer_t *player, void *user_data, video_frame **frame)
|
|
|
-{
|
|
|
- videoplay_session_t *session = (videoplay_session_t *)user_data;
|
|
|
- CVideoEchoHostApi *pHostApi = session->conf.pHostApi;
|
|
|
-
|
|
|
- video_frame *tmp_frame_preview;
|
|
|
- videoq_frame frm;
|
|
|
- int nActiveCam = pHostApi->GetActiveCamera();
|
|
|
- //pHostApi->Debug("[dbg] nActiveCam=%d",nActiveCam);
|
|
|
- if (nActiveCam == 0)
|
|
|
- {
|
|
|
- tmp_frame_preview = video_frame_new(session->frame_width[0], session->frame_height[0], VIDEO_FORMAT_RGB24);
|
|
|
- frm.data = tmp_frame_preview->data[0];
|
|
|
- session->video_preview_queue0->GetVideo(&frm, VIDEOQUEUE_FLAG_HORIZONTAL_FLIP);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- tmp_frame_preview = video_frame_new(session->frame_width[1], session->frame_height[1], VIDEO_FORMAT_RGB24);
|
|
|
- frm.data = tmp_frame_preview->data[0];
|
|
|
- session->video_preview_queue1->GetVideo(&frm, VIDEOQUEUE_FLAG_HORIZONTAL_FLIP);
|
|
|
- }
|
|
|
-
|
|
|
- *frame = tmp_frame_preview;
|
|
|
- return 0;
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-static void free_frame(videoplayer_t *player, void *user_data, video_frame *frame)
|
|
|
-{
|
|
|
- video_frame_delete(frame);
|
|
|
-}
|
|
|
-
|
|
|
-static int start_video(videoplay_session_t *session)
|
|
|
-{
|
|
|
- int rc;
|
|
|
-
|
|
|
- CVideoEchoHostApi *pHostApi = session->conf.pHostApi;
|
|
|
-
|
|
|
- if (!session->video_preview_queue0) {
|
|
|
- Dbg("video_preview_queue0 cannot be NULL!");
|
|
|
- return -1;
|
|
|
- }
|
|
|
-
|
|
|
- {
|
|
|
- pHostApi->Debug("begin to get framesize of queue0");
|
|
|
- int failedtimes = 0;
|
|
|
- int &width0 = session->frame_width[0];
|
|
|
- int &height0 = session->frame_height[0];
|
|
|
- while (true) {
|
|
|
- session->video_preview_queue0->GetFrameSize(width0, height0);
|
|
|
- if (width0 != 0 && height0 != 0) {
|
|
|
- pHostApi->Debug("width0:%d,height0:%d",width0,height0);
|
|
|
- break;
|
|
|
- }
|
|
|
- ::Sleep(1);
|
|
|
- if (++failedtimes >= 10000) {
|
|
|
- pHostApi->Debug("failed to get framesize of queue0");
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- if (width0 == 0 || height0 == 0) return -1;
|
|
|
- }
|
|
|
-
|
|
|
- if (session->video_preview_queue1) {
|
|
|
- pHostApi->Debug("begin to get framesize of queue1");
|
|
|
- int failedtimes = 0;
|
|
|
- int &width1 = session->frame_width[1];
|
|
|
- int &height1 = session->frame_height[1];
|
|
|
- while (true) {
|
|
|
- session->video_preview_queue1->GetFrameSize(width1, height1);
|
|
|
- if (width1 != 0 && height1 != 0) {
|
|
|
- pHostApi->Debug("width1:%d,height1:%d",width1,height1);
|
|
|
- break;
|
|
|
- }
|
|
|
- ::Sleep(1);
|
|
|
- if (++failedtimes >= 10000) {
|
|
|
- pHostApi->Debug("failed to get framesize of queue1");
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- if (width1 == 0 || height1 == 0) return -1;
|
|
|
- }
|
|
|
-
|
|
|
- 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->wndname,
|
|
|
- on_pull, free_frame, session,
|
|
|
- &session->local_player);
|
|
|
- if (rc != 0)
|
|
|
- {
|
|
|
- pHostApi->Debug("create local video player failed!");
|
|
|
- goto on_error;
|
|
|
- }
|
|
|
-
|
|
|
-on_error:
|
|
|
-
|
|
|
- return rc;
|
|
|
-}
|
|
|
-
|
|
|
-static void stop_video(videoplay_session_t *session)
|
|
|
-{
|
|
|
- if (session->local_player) {
|
|
|
- videoplayer_destroy(session->local_player);
|
|
|
- session->local_player = NULL;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-static LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|
|
-{
|
|
|
- videoplay_session_t *session = (videoplay_session_t*)GetWindowLongPtrA(hWnd, GWLP_USERDATA);
|
|
|
-
|
|
|
- switch (msg) {
|
|
|
- case WM_DESTROY:
|
|
|
- if (session->local_hwnd == hWnd) {
|
|
|
- session->local_hwnd = 0;
|
|
|
- }
|
|
|
- if (session->local_hwnd == 0) {
|
|
|
- PostQuitMessage(0);
|
|
|
- }
|
|
|
- return 0;
|
|
|
- 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:
|
|
|
- stop_video(session);
|
|
|
- DestroyWindow(session->local_hwnd);
|
|
|
- return 0;
|
|
|
- default:
|
|
|
- return DefWindowProc(hWnd, msg, wParam, lParam);
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-static unsigned int __stdcall ui_proc(void *arg)
|
|
|
-{
|
|
|
- videoplay_session_t *session = (videoplay_session_t *)arg;
|
|
|
- CVideoEchoHostApi *pHostApi = session->conf.pHostApi;
|
|
|
-
|
|
|
- WNDCLASSA wc = {0};
|
|
|
- ATOM a = 0;
|
|
|
- HWND hWnd = NULL;
|
|
|
- MSG msg;
|
|
|
- HINSTANCE hInst = pHostApi->GetEntityHinstance();
|
|
|
-
|
|
|
- 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 = session->wndname;
|
|
|
- wc.style = CS_HREDRAW | CS_OWNDC | CS_VREDRAW;
|
|
|
-
|
|
|
- a = RegisterClassA(&wc);
|
|
|
- if (a == 0)
|
|
|
- return 0;
|
|
|
-
|
|
|
- session->local_hwnd = CreateWindowExA(WS_EX_TOOLWINDOW | WS_EX_TOPMOST | WS_EX_NOACTIVATE,
|
|
|
- session->wndname, 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);
|
|
|
- SetWindowPos(session->local_hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
|
|
|
- }
|
|
|
-
|
|
|
- if (session->local_hwnd)
|
|
|
- {
|
|
|
- int rc = 0;
|
|
|
-
|
|
|
- ShowCursor(FALSE);
|
|
|
-
|
|
|
- SetEvent(session->ui_event);
|
|
|
-
|
|
|
- rc = start_video(session);
|
|
|
- if (rc != 0)
|
|
|
- {
|
|
|
- pHostApi->Debug("start video failed!");
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- pHostApi->Debug("start video ok!");
|
|
|
- }
|
|
|
-
|
|
|
- while (GetMessageA(&msg, NULL, NULL, NULL))
|
|
|
- {
|
|
|
- if (msg.message == WM_CLOSE) {
|
|
|
- pHostApi->Debug("rx WM_CLOSE");
|
|
|
- }
|
|
|
- TranslateMessage(&msg);
|
|
|
- DispatchMessageA(&msg);
|
|
|
- }
|
|
|
-
|
|
|
- SetEvent(session->ui_event);
|
|
|
- }
|
|
|
-
|
|
|
- if (a)
|
|
|
- UnregisterClassA(session->wndname, hInst);
|
|
|
-
|
|
|
- CoUninitialize();
|
|
|
-
|
|
|
- return 0;
|
|
|
-}
|
|
|
-
|
|
|
-static int start_ui(videoplay_session_t *session)
|
|
|
-{
|
|
|
- CVideoEchoHostApi *pHostApi = session->conf.pHostApi;
|
|
|
- session->ui_event = CreateEventA(NULL, FALSE, FALSE, NULL);
|
|
|
- if (!session->ui_event) {
|
|
|
- pHostApi->Debug("libvideoecho_start create ui event failed!");
|
|
|
- return Error_Resource;
|
|
|
- }
|
|
|
-
|
|
|
- session->ui_thread = (HANDLE)_beginthreadex(NULL, 0, &ui_proc, session, 0, NULL);
|
|
|
- if (!session->ui_thread) {
|
|
|
- pHostApi->Debug("videoecho_start create ui thread failed!");
|
|
|
- CloseHandle(session->ui_event);
|
|
|
- session->ui_event = NULL;
|
|
|
- return Error_Resource;
|
|
|
- }
|
|
|
- pHostApi->Debug("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) { //
|
|
|
- pHostApi->Debug("wait for ui ready event ok!");
|
|
|
- } else if (dwRet == WAIT_OBJECT_0 + 1) { // thread exit
|
|
|
- pHostApi->Debug("ui thread aborted unexpected!");
|
|
|
- CloseHandle(session->ui_thread);
|
|
|
- session->ui_thread = NULL;
|
|
|
- CloseHandle(session->ui_event);
|
|
|
- session->ui_event = NULL;
|
|
|
- return Error_Resource;
|
|
|
- }
|
|
|
- }
|
|
|
- return 0;
|
|
|
-}
|
|
|
-
|
|
|
-static void stop_ui(videoplay_session_t *session)
|
|
|
-{
|
|
|
- if (session->local_hwnd) {
|
|
|
- BOOL bRet = PostMessageA(session->local_hwnd, WM_CLOSE, 0, 0);
|
|
|
- WaitForSingleObject(session->ui_thread, INFINITE);
|
|
|
- CloseHandle(session->ui_thread);
|
|
|
- session->ui_thread = NULL;
|
|
|
- CloseHandle(session->ui_event);
|
|
|
- session->ui_event = NULL;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-namespace LibVideoEcho {
|
|
|
-
|
|
|
- int Local_videoplay_session_create( const videoplay_session_conf_t *conf, videoplay_session_t **p_session )
|
|
|
- {
|
|
|
- if (!conf) {
|
|
|
- Dbg("conf cannot be NULL!");
|
|
|
- return -1;
|
|
|
- }
|
|
|
-
|
|
|
- if (strlen(conf->local_video_preview_queue0)<=0) {
|
|
|
- Dbg("queue0 must be offered!");
|
|
|
- return -2;
|
|
|
- }
|
|
|
-
|
|
|
- if (!conf->pHostApi) {
|
|
|
- Dbg("pHostApi cannot be NULL!");
|
|
|
- return -3;
|
|
|
- }
|
|
|
-
|
|
|
- videoplay_session_t *session = ZALLOC_T(videoplay_session_t);
|
|
|
- session->video_error = NULL;
|
|
|
- if (session)
|
|
|
- {
|
|
|
- memcpy(&session->conf, conf, sizeof(videoplay_session_conf_t));
|
|
|
- strncpy_s(session->wndname, "ve", 2);
|
|
|
- SYSTEMTIME st;
|
|
|
- GetLocalTime(&st);
|
|
|
- srand(GetTickCount());
|
|
|
- sprintf_s(session->wndname+2, 250, "%d%d%d%d%d%d", rand(), rand(),
|
|
|
- st.wMinute, st.wSecond, st.wMilliseconds, GetTickCount());
|
|
|
- session->conf.pHostApi->Debug("[dbg] param.wndname: %s.", session->wndname);
|
|
|
-
|
|
|
- session->video_preview_queue0 = new Clibvideoqueue(conf->local_video_preview_queue0);
|
|
|
- if (strlen(conf->local_video_preview_queue1)>0)
|
|
|
- {
|
|
|
- session->video_preview_queue1 = new Clibvideoqueue(conf->local_video_preview_queue1);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- session->video_preview_queue1 = NULL;
|
|
|
- }
|
|
|
-
|
|
|
- *p_session = session;
|
|
|
- }
|
|
|
- return 0;
|
|
|
- }
|
|
|
-
|
|
|
- //int videoplay_session_create( const videoplay_session_conf_t *conf, videoplay_session_t **p_session )
|
|
|
- //{
|
|
|
- // videoplay_session_t *session = ZALLOC_T(videoplay_session_t);
|
|
|
- // if (session)
|
|
|
- // {
|
|
|
- // memcpy(&session->conf, conf, sizeof(videoplay_session_conf_t));
|
|
|
- // session->video_shm_q_rtp = new Clibvideoqueue(REC_COMMON_VIDEO_ENV_SHM_RTP_QUEUE);
|
|
|
- // session->video_shm_q_preview = new Clibvideoqueue(REC_COMMON_VIDEO_ENV_SHM_PREVIEW_QUEUE);
|
|
|
- // char strPath[MAX_PATH_SIZE];
|
|
|
- // GetCurrentRunPath(strPath);
|
|
|
- // sprintf(strPath,"%s\\bin\\error.jpg",strPath);
|
|
|
- // if (_access(strPath,0)!=-1)
|
|
|
- // {
|
|
|
- // IplImage*img = cvLoadImage(strPath,1);
|
|
|
- // if (img != NULL)
|
|
|
- // {
|
|
|
- // Dbg("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
|
|
|
- // {
|
|
|
- // Dbg("error img is null");
|
|
|
- // session->video_error = 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_rtp->GetVideo(&frm, 0);
|
|
|
- // video_frame_save_bmpfile("d:\\a.bmp", &frame);
|
|
|
- //#endif
|
|
|
- //
|
|
|
- // *p_session = session;
|
|
|
- // }
|
|
|
- // return 0;
|
|
|
- //}
|
|
|
-
|
|
|
- int Local_videoplay_session_start( videoplay_session_t *session)
|
|
|
- {
|
|
|
- int rc = start_ui(session);
|
|
|
- return rc;
|
|
|
- }
|
|
|
-
|
|
|
- void Local_videoplay_session_stop( videoplay_session_t *session )
|
|
|
- {
|
|
|
- stop_ui(session);
|
|
|
- }
|
|
|
-
|
|
|
- void Local_videoplay_session_destroy( videoplay_session_t *session )
|
|
|
- {
|
|
|
- if (session->video_preview_queue0) {
|
|
|
- delete session->video_preview_queue0;
|
|
|
- session->video_preview_queue0 = NULL;
|
|
|
- }
|
|
|
- if (session->video_preview_queue1) {
|
|
|
- delete session->video_preview_queue1;
|
|
|
- session->video_preview_queue1 = NULL;
|
|
|
- }
|
|
|
- if (session->video_error)
|
|
|
- {
|
|
|
- delete session->video_error->data;
|
|
|
- delete session->video_error;
|
|
|
- }
|
|
|
- free(session);
|
|
|
- }
|
|
|
-
|
|
|
- //int video_lib_init()
|
|
|
- //{
|
|
|
- // 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);
|
|
|
- // Dbg("%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);
|
|
|
- //
|
|
|
- // return 0;
|
|
|
- //}
|
|
|
-
|
|
|
- //void video_lib_uninit()
|
|
|
- //{
|
|
|
- // CoUninitialize();
|
|
|
- // videoframework_term();
|
|
|
- //}
|
|
|
-}
|