Skip to content

Commit

Permalink
chore: optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
guoxianzhe committed Dec 17, 2024
1 parent 479aa76 commit 0a45342
Showing 1 changed file with 19 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import {
VideoSourceType,
createAgoraRtcEngine,
} from 'agora-electron-sdk';
import { Checkbox, List } from 'antd';
import { CheckboxValueType } from 'antd/lib/checkbox/Group';
import React, { ReactElement } from 'react';
import { SketchPicker } from 'react-color';

Expand All @@ -35,7 +33,6 @@ interface State extends BaseVideoComponentState {
blur_degree: BackgroundBlurDegree;
encodeAlpha: boolean;
video_module_position: VideoModulePosition;
checked_video_module_position_list: CheckboxValueType[];
enableVirtualBackground?: boolean;
}

Expand All @@ -55,9 +52,6 @@ export default class VirtualBackground
startPreview: false,
encodeAlpha: true,
video_module_position: VideoModulePosition.PositionPreEncoder,
checked_video_module_position_list: [
VideoModulePosition.PositionPostCapturer,
],
background_source_type: BackgroundSourceType.BackgroundNone,
color: 0xffffff,
source: getResourcePath('agora-logo.png'),
Expand Down Expand Up @@ -90,6 +84,8 @@ export default class VirtualBackground
// If you only call `enableAudio`, only relay the audio stream to the target channel
this.engine.enableVideo();

// if you want to use the alpha channel, you need to set the following parameters to let remoteView support alpha channel
this.engine?.setParameters('{"rtc.video.dec_split_alpha":true}');
this.engine?.setVideoEncoderConfiguration({
advanceOptions: {
encodeAlpha: true,
Expand All @@ -100,9 +96,6 @@ export default class VirtualBackground
handleStartPreview = () => {
this.engine?.startPreview();
this.setState({ startPreview: true });
console.log(
`startPreview with position:${this.state.video_module_position}`
);
};

handleStopPreview = () => {
Expand Down Expand Up @@ -222,44 +215,12 @@ export default class VirtualBackground
source,
blur_degree,
encodeAlpha,
checked_video_module_position_list,
startPreview,
joinChannelSuccess,
video_module_position,
} = this.state;
return (
<>
<>
<p>local video module position</p>
<Checkbox.Group
style={{ width: '100%' }}
value={checked_video_module_position_list}
disabled={startPreview}
onChange={(checkedValues) => {
let result = 0;
checkedValues.forEach((value: CheckboxValueType) => {
result |= value as number;
});
this.setState({
checked_video_module_position_list: checkedValues,
video_module_position: result,
});
}}
>
<List
itemLayout="horizontal"
dataSource={enumToItems(VideoModulePosition)}
renderItem={(item) =>
item.value !== VideoModulePosition.PositionPreRenderer ? (
<List.Item>
<List.Item.Meta
avatar={<Checkbox value={item.value} />}
title={item.label}
/>
</List.Item>
) : undefined
}
/>
</Checkbox.Group>
</>
<AgoraDropdown
title={'backgroundSourceType'}
items={enumToItems(BackgroundSourceType)}
Expand Down Expand Up @@ -299,10 +260,24 @@ export default class VirtualBackground
}}
/>
) : null}
<AgoraSwitch
title={'PositionPostCapturer'}
disabled={startPreview || joinChannelSuccess}
value={
video_module_position === VideoModulePosition.PositionPostCapturer
}
onValueChange={(value) => {
this.setState({
video_module_position: value
? VideoModulePosition.PositionPostCapturer
: VideoModulePosition.PositionPreEncoder,
});
}}
/>
<AgoraSwitch
title={'encodeAlpha'}
//attention: encodeAlpha can only change before rendering, when rendering, you can't change it, otherwise, it will cause rendering error and crash
disabled={startPreview}
disabled={startPreview || joinChannelSuccess}
value={encodeAlpha}
onValueChange={(value) => {
this.setState({ encodeAlpha: value });
Expand Down

0 comments on commit 0a45342

Please sign in to comment.