当前位置:网站首页>[Shanda conference] software performance optimization and bug repair
[Shanda conference] software performance optimization and bug repair
2022-06-22 16:04:00 【What does Xiao Li Mao eat today】
List of articles
preface
This article is mainly used to record the client code in several projects performance optimization as well as Malignant bug Repair of .
modify WebRTC Encoder
2022 year 5 month 30 Japan
It was found in the test that , When the software makes a video call ,CPU High load , After testing, it was found that it was due to WebRTC By default VP8 The encoder 、 decoder . In order to reduce CPU load , I allow users to choose to use CPU or GPU Rendering . When using GPU When video rendering , Will use H264 The encoder of .
// NOTE: Supported encoders
const senderCodecs = RTCRtpSender.getCapabilities('video')?.codecs as RTCRtpCodecCapability[];
const receiverCodecs = RTCRtpReceiver.getCapabilities('video')?.codecs as RTCRtpCodecCapability[];
(() => {
const senderH264Index = senderCodecs?.findIndex(
(c) =>
c.mimeType === 'video/H264' &&
c.sdpFmtpLine ===
'level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42e01f'
);
const senderH264 = (senderCodecs as Array<RTCRtpCodecCapability>)[
senderH264Index ? senderH264Index : 0
];
senderCodecs?.splice(senderH264Index ? senderH264Index : 0, 1);
senderCodecs?.unshift(senderH264);
const receiverH264Index = receiverCodecs?.findIndex(
(c) =>
c.mimeType === 'video/H264' &&
c.sdpFmtpLine ===
'level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42e01f'
);
const receiverH264 = (receiverCodecs as Array<RTCRtpCodecCapability>)[
receiverH264Index ? receiverH264Index : 0
];
receiverCodecs?.splice(receiverH264Index ? receiverH264Index : 0, 1);
receiverCodecs?.unshift(receiverH264);
})();
export {
senderCodecs, receiverCodecs };
Save the encoder , Use if necessary H264 The encoder / decoder .
The user is missing some multimedia devices
2022 year 6 month 2 Japan
Because of our WebRTC The default user transmits audio and video on two tracks , Once the user does not have certain equipment, the whole process may not go on . In order to alleviate this situation , I will get the media stream failure try...catch operation , And will return a default media stream .
let defaultVideoWidget: HTMLVideoElement | undefined;
function getDefaultStream(): Promise<MediaStream> {
return new Promise((resolve) => {
if (defaultVideoWidget) {
resolve((defaultVideoWidget as any).captureStream(1) as MediaStream);
} else {
defaultVideoWidget = document.createElement('video');
defaultVideoWidget.autoplay = true;
defaultVideoWidget.src = '../electronAssets/null.mp4';
defaultVideoWidget.loop = true;
defaultVideoWidget.onloadedmetadata = () => {
resolve((defaultVideoWidget as any).captureStream(1) as MediaStream);
};
}
});
}
Message tone Bug Repair
2022 year 6 month 4 Japan
Because our message tone uses AudioContext Realization , Which has a large number of Asynchronous operations . In the initial development, I didn't realize the problems caused by such asynchronous operations , In subsequent tests, it was found that the asynchronous operation led to Stop playing It's hard to work properly . therefore , For asynchronous operations , I will modify the code of the message tone to the following version :
// Prompt.ts
export const AUDIO_TYPE = {
MESSAGE_RECEIVED: 'info',
WEBRTC_CALLING: 'call',
WEBRTC_ANSWERING: 'answer',
};
export const buildPropmt = function (audioType: string, loop = false) {
const audioContext = new AudioContext();
let source = audioContext.createBufferSource();
const audio = require(`./audios/${
audioType}.aac`);
let abortController = new AbortController();
let abortSignal = abortController.signal;
const startAudioPropmt = () => {
if (source.buffer) {
source.stop();
source = audioContext.createBufferSource();
}
fetch(audio.default, {
signal: abortSignal,
})
.then((res) => {
return res.arrayBuffer();
})
.then((arrayBuffer) => {
return audioContext.decodeAudioData(arrayBuffer, (decodeData) => {
return decodeData;
});
})
.then((audioBuffer) => {
stopAudioPropmt();
source.buffer = audioBuffer;
source.loop = loop;
source.connect(audioContext.destination);
source.start(0);
})
.catch((message) => {
console.log(message);
});
};
const stopAudioPropmt = () => {
if (source.buffer) {
source.stop();
source = audioContext.createBufferSource();
} else {
abortController.abort();
abortController = new AbortController();
abortSignal = abortController.signal;
}
};
return [startAudioPropmt, stopAudioPropmt];
};
The asynchronous operation will now be terminated first , Prevent operation failure from causing irreparable problems in the subsequent use of the program bug .
边栏推荐
- jmeter关联登录302类型的接口
- Be an we media video blogger, and share the necessary 32 material websites
- C语言学习-17-函数作为参数传入函数
- 【山大会议】应用设置模块
- 推進兼容適配,使能協同發展 GBase 5月適配速遞
- ORB_ VI ideological framework
- Merge sort of sorting
- Huawei cloud hcdez special session and Distributed Technology Summit: Huawei cloud distributed cloud native technology and Practice
- Luogu p2466 [sdoi2008] Sue's small ball solution
- ORB_VI思想框架
猜你喜欢
![[译文] 弥合开源数据库和数据库业务之间的鸿沟](/img/e5/f89a8f3e2e9034f557ea3e76f37f81.jpg)
[译文] 弥合开源数据库和数据库业务之间的鸿沟

Research on ICT: domestic databases focus on the ICT market, and Huawei Gauss is expected to become the strongest

Gbase "library" special training of innovation and application Committee of Beijing fintech Industry Alliance

Development status of full color LED display
![[single chip microcomputer] [make buzzer sound] know the buzzer and let it make the sound you want](/img/cb/826b3591bafa62cc71826732eb32ef.png)
[single chip microcomputer] [make buzzer sound] know the buzzer and let it make the sound you want

ArcGIS JS之 4.23之IIS本地部署与问题解决

84. (cesium chapter) movement of cesium model on terrain

Process address space

On the routing tree of gin

微信小程序头像挂件制作
随机推荐
[译文] 弥合开源数据库和数据库业务之间的鸿沟
GBASE现身说 “库” 北京金融科技产业联盟创新应用专委会专题培训
Research on ICT: domestic databases focus on the ICT market, and Huawei Gauss is expected to become the strongest
Promouvoir l'adaptation compatible et permettre le développement collaboratif du Service Express adaptatif gbase en mai
Bridging the gap between open source databases and database services
推進兼容適配,使能協同發展 GBase 5月適配速遞
High precision calculation
Promoting compatibility and adaptation, enabling coordinated development of gbase may adaptation Express
【山大会议】私人聊天频道 WebRTC 工具类
Application of mongodb in Tencent retail premium code
uni开发微信小程序自定义相机自动检测(人像+身份证)
坚持更新博客的动力是什么
推进兼容适配,使能协同发展 GBase 5月适配速递
【山大会议】注册页的编写
Be an we media video blogger, and share the necessary 32 material websites
Meet webassembly again
C language learning -17- function is passed in as a parameter
New design of databend SQL planner
webDriver以及Selenium使用总结
Quickly play ci/cd graphical choreography