def.h
根据实际需求修改
#pragma once#define WIN_CLASSNAME TEXT("My_Widget")
#define WIN_WINDNAME TEXT("Worker")#define GET_PARAMS(params,type,index) *((type *)((void ** )params)[index])
#define THREAD_PARAMS(params,type,index) GET_PARAMS(params,type,index)#include <iostream>
#define COUT() std::cout
#define COUT_ERROR(code,msg) std::cout<<"Error("<<code<<"): at "<<__FILE__<<":"<<__LINE__<<" what:"<<msg
#define COUT_ERRORLN(code,msg) COUT_ERROR(code,msg)<<std::endl
#define COUT_MESSAGE(msg) std::cout<<"Message: at "<<__FILE__<<":"<<__LINE__<<" message:"<<msg
#define COUT_MESSAGELN(msg) COUT_MESSAGE(msg)<<std::endl
#define COUT_LN() std::endl
mian.cpp
。
#include <Windows.h>#include <time.h>#include <iostream>
#include <vector>//TX TRTC
#include <TRTC/TXLiteAVBase.h>
#include <TRTC/ITRTCCloud.h>
#include <TRTC/ITXLiteAVLocalRecord.h>#pragma comment(lib, "liteav.lib")#include <math.h>#include "def.h"LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
int main(int argc, const char** argv) {COUT_MESSAGELN(getLiteAvSDKVersion());HINSTANCE hInstance = GetModuleHandle(NULL);WNDCLASS wndclass;wndclass.style = CS_HREDRAW | CS_VREDRAW;wndclass.lpfnWndProc = WndProc;wndclass.cbClsExtra = 0;wndclass.cbWndExtra = 0;wndclass.hInstance = hInstance;wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);wndclass.lpszMenuName = NULL;wndclass.lpszClassName = WIN_CLASSNAME;ATOM atRet = RegisterClass(&wndclass);HWND hWndMian = CreateWindow(WIN_CLASSNAME, L"显示远端的窗口", WS_OVERLAPPEDWINDOW | WS_POPUP,10, 10, 800, 600,NULL, NULL, hInstance, NULL);ShowWindow(hWndMian, SW_SHOW);UpdateWindow(hWndMian);HWND hwndChildMy = CreateWindow(WIN_CLASSNAME, L"显示自己的窗口", WS_VISIBLE | WS_CHILD,30, 30, 200, 180,hWndMian, NULL, hInstance, NULL);int iAppid = 0; //这里填充在腾讯云控制台创建的应用IDstd::string strUserId = "";std::cout << "请输入UserId:" << std::endl;std::cin >> strUserId;/*{//向服务器获取签名HttpClient stHttpClient(L"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:86.0) Gecko/20100101 Firefox/86.0");WCHAR wcstrBuf[1024];wsprintf(wcstrBuf, L"127.0.0.1:8081/trtc/userssig?uid=%s", strUserId.c_str());std::string strResText = "";std::vector<std::wstring> headers;headers.push_back(L"Host:127.0.0.1");stHttpClient.http_get(wcstrBuf, headers, strResText);}*/std::cout << "输入签名:" << std::endl;std::cin >> strResText;//打印签名std::cout << strResText << std::endl;MyColudCallback stCallBack;ITRTCCloud* pstCould = getTRTCShareInstance();void* callbackParams[3] = { &pstCould,&hwndChildMy,&hWndMian};stCallBack._params = callbackParams;pstCould->addCallback(&stCallBack);pstCould->startLocalPreview(hwndChildMy);TRTCParams trtcParams;trtcParams.sdkAppId = iAppid;trtcParams.userId = strUserId.c_str();trtcParams.userSig = strResText.c_str();Id = 1001;pstCould->enterRoom(trtcParams, trtc::TRTCAppScene::TRTCAppSceneVideoCall);MSG msg;while (GetMessage(&msg, NULL, 0, 0)){if (ssage == WM_QUIT){break;}TranslateMessage(&msg);DispatchMessage(&msg);}pstCould->exitRoom();return 0;
}LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {switch (message){case WM_PAINT:{PAINTSTRUCT ps;HDC hdc = BeginPaint(hWnd, &ps);// TODO: 在此处添加使用 hdc 的任何绘图代码...EndPaint(hWnd, &ps);}break;case WM_CREATE:{}break;case WM_DESTROY:PostQuitMessage(0);break;default:return DefWindowProc(hWnd, message, wParam, lParam);}return 0;
}
MyColudCallback .h
TRTCCould回调,在此类中重写ITRTCCloudCallback的虚函数
#pragma once#include <TRTC/ITRTCCloud.h>
class MyColudCallback : public trtc::ITRTCCloudCallback
{
public:MyColudCallback(void* params = NULL);
public:virtual void onError(TXLiteAVError errCode, const char* errMsg, void* extraInfo) override;virtual void onWarning(TXLiteAVWarning warningCode, const char* warningMsg, void* extraInfo) override;public:virtual void onEnterRoom(int result) override;virtual void onExitRoom(int reason) override;virtual void onRemoteUserEnterRoom(const char* userId) override;virtual void onFirstVideoFrame(const char* cstrUserId, const TRTCVideoStreamType streamType, const int width, const int height) override;public:void* _params;
};
MyColudCallback.cpp
#include "MyColudCallback.h"
#include "def.h"MyColudCallback::MyColudCallback(void * params) {_params = params;
}void MyColudCallback::onError(TXLiteAVError errCode, const char* errMsg, void* extraInfo)
{COUT_ERRORLN(errCode, errMsg);
}void MyColudCallback::onWarning(TXLiteAVWarning warningCode, const char* warningMsg, void* extraInfo)
{COUT_MESSAGELN(warningMsg);
}void MyColudCallback::onEnterRoom(int result)
{if(reuslt < 0 ){//出错误了}COUT_MESSAGE("加入房间:Result = ") << result << COUT_LN();
}void MyColudCallback::onExitRoom(int reason)
{COUT_MESSAGE("退出房间:reason = ") << reason << COUT_LN();
}void MyColudCallback::onRemoteUserEnterRoom(const char* userId)
{ITRTCCloud* pstCould = GET_PARAMS(_params, ITRTCCloud*,0);HWND hwndChildMy = GET_PARAMS(_params, HWND, 1);HWND hwndMain = GET_PARAMS(_params, HWND, 2);//拉取房间内远端数据,渲染到主要窗口中pstCould->startRemoteView(userId, TRTCVideoStreamTypeBig, hwndMain);
}void MyColudCallback::onFirstVideoFrame(const char* cstrUserId, const TRTCVideoStreamType streamType, const int width, const int height)
{COUT() << "n开始渲染视频:t " << width << " x " << height << COUT_LN();
}
本文发布于:2024-01-31 14:19:42,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170668198429140.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |