From 6a41369760dd82ee2bf2dd8b9ad9e2c6d100ca92 Mon Sep 17 00:00:00 2001 From: gxz Date: Fri, 25 Oct 2024 10:56:49 +0800 Subject: [PATCH] chore: remove encodedVideoFrame case --- example/README.md | 1 - .../EncodedVideoFrame/EncodedVideoFrame.tsx | 237 ------------------ example/src/examples/advanced/index.ts | 5 - 3 files changed, 243 deletions(-) delete mode 100644 example/src/examples/advanced/EncodedVideoFrame/EncodedVideoFrame.tsx diff --git a/example/README.md b/example/README.md index 3a048059..50876d99 100644 --- a/example/README.md +++ b/example/README.md @@ -31,7 +31,6 @@ Any scene of this project can run successfully alone. | [ChannelMediaRelay](./src/examples/advanced/ChannelMediaRelay) | Starts relaying media streams across channels. This method can be used to implement scenarios such as co-host across channels | | [ContentInspect](./src/examples/advanced/ContentInspect) | Content inspect | | [DirectCdnStreaming](./src/examples/advanced/DirectCdnStreaming) | Direct CDN streaming | -| [EncodedVideoFrame](./src/examples/advanced/EncodedVideoFrame) | Encoded video frame | | [Encryption](./src/examples/advanced/Encryption) | Enables/Disables the built-in encryption | | [Extension](./src/examples/advanced/Extension) | Enables/Disables extensions | | [JoinMultipleChannel](./src/examples/advanced/JoinMultipleChannel) | Joins a channel with the connection ID | diff --git a/example/src/examples/advanced/EncodedVideoFrame/EncodedVideoFrame.tsx b/example/src/examples/advanced/EncodedVideoFrame/EncodedVideoFrame.tsx deleted file mode 100644 index c46ff1ff..00000000 --- a/example/src/examples/advanced/EncodedVideoFrame/EncodedVideoFrame.tsx +++ /dev/null @@ -1,237 +0,0 @@ -import { Buffer } from 'buffer'; - -import React, { ReactElement } from 'react'; -import { - ChannelProfileType, - ClientRoleType, - EncodedVideoFrameInfo, - ExternalVideoSourceType, - IRtcEngineEventHandler, - IRtcEngineEx, - IVideoEncodedFrameObserver, - RtcConnection, - VideoCodecType, - VideoFrameType, - createAgoraRtcEngine, -} from 'react-native-agora'; - -import { - BaseComponent, - BaseVideoComponentState, -} from '../../../components/BaseComponent'; -import { AgoraButton, AgoraTextInput } from '../../../components/ui'; -import Config from '../../../config/agora.config'; -import { askMediaAccess } from '../../../utils/permissions'; - -interface State extends BaseVideoComponentState { - imageBuffer: string; -} - -export default class EncodedVideoFrame - extends BaseComponent<{}, State> - implements IRtcEngineEventHandler, IVideoEncodedFrameObserver -{ - // @ts-ignore - protected engine?: IRtcEngineEx; - - protected createState(): State { - return { - appId: Config.appId, - enableVideo: true, - channelId: Config.channelId, - token: Config.token, - uid: Config.uid, - joinChannelSuccess: false, - remoteUsers: [], - startPreview: false, - imageBuffer: '', - }; - } - - /** - * Step 1: initRtcEngine - */ - protected async initRtcEngine() { - const { appId } = this.state; - if (!appId) { - this.error(`appId is invalid`); - } - - this.engine = createAgoraRtcEngine() as IRtcEngineEx; - this.engine.initialize({ - appId, - logConfig: { filePath: Config.logFilePath }, - // Should use ChannelProfileLiveBroadcasting on most of cases - channelProfile: ChannelProfileType.ChannelProfileLiveBroadcasting, - }); - this.engine.registerEventHandler(this); - - // Need granted the microphone and camera permission - await askMediaAccess([ - 'android.permission.RECORD_AUDIO', - 'android.permission.CAMERA', - ]); - - // Need to enable video on this case - // If you only call `enableAudio`, only relay the audio stream to the target channel - this.engine.enableVideo(); - - this.registerVideoEncodedFrameObserver(); - this.setExternalVideoSource(); - } - - /** - * Step 2: joinChannel - */ - protected joinChannel() { - const { channelId, token, uid } = this.state; - if (!channelId) { - this.error('channelId is invalid'); - return; - } - if (uid < 0) { - this.error('uid is invalid'); - return; - } - - // start joining channel - // 1. Users can only see each other after they join the - // same channel successfully using the same app id. - // 2. If app certificate is turned on at dashboard, token is needed - // when joining channel. The channel name and uid used to calculate - // the token has to match the ones used for channel join - this.engine?.joinChannel(token, channelId, uid, { - // Make myself as the broadcaster to send stream to remote - clientRoleType: ClientRoleType.ClientRoleBroadcaster, - publishCameraTrack: false, - publishEncodedVideoTrack: true, - }); - } - - /** - * Step 3-1: registerVideoEncodedFrameObserver - */ - registerVideoEncodedFrameObserver = () => { - this.engine?.getMediaEngine().registerVideoEncodedFrameObserver(this); - }; - - /** - * Step 3-2: setExternalVideoSource - */ - setExternalVideoSource = () => { - this.engine - ?.getMediaEngine() - .setExternalVideoSource( - true, - false, - ExternalVideoSourceType.EncodedVideoFrame, - { - codecType: VideoCodecType.VideoCodecGeneric, - } - ); - }; - - /** - * Step 3-3: pushEncodedVideoImage - */ - pushEncodedVideoImage = () => { - const { imageBuffer } = this.state; - if (!imageBuffer) { - this.error('imageBuffer is invalid'); - return; - } - - const buffer = Buffer.from(imageBuffer); - this.engine?.getMediaEngine().pushEncodedVideoImage(buffer, buffer.length, { - framesPerSecond: 60, - codecType: VideoCodecType.VideoCodecGeneric, - frameType: VideoFrameType.VideoFrameTypeKeyFrame, - }); - }; - - /** - * Step 3-4: unregisterVideoEncodedFrameObserver - */ - unregisterVideoEncodedFrameObserver = () => { - this.engine?.getMediaEngine().unregisterVideoEncodedFrameObserver(this); - }; - - /** - * Step 4: leaveChannel - */ - protected leaveChannel() { - this.engine?.leaveChannel(); - } - - /** - * Step 5: releaseRtcEngine - */ - protected releaseRtcEngine() { - this.unregisterVideoEncodedFrameObserver(); - this.engine?.unregisterEventHandler(this); - this.engine?.release(); - } - - onUserJoined(connection: RtcConnection, remoteUid: number, elapsed: number) { - super.onUserJoined(connection, remoteUid, elapsed); - // ⚠️ subscribe encoded frame only - this.engine?.setRemoteVideoSubscriptionOptions(remoteUid, { - encodedFrameOnly: true, - }); - } - - onEncodedVideoFrameReceived( - uid: number, - imageBuffer: Uint8Array, - length: number, - videoEncodedFrameInfo: EncodedVideoFrameInfo - ): boolean { - this.info( - 'OnEncodedVideoFrameReceived', - 'uid', - uid, - 'imageBuffer', - imageBuffer, - 'length', - length, - 'videoEncodedFrameInfo', - videoEncodedFrameInfo - ); - if (videoEncodedFrameInfo.codecType === VideoCodecType.VideoCodecGeneric) { - this.alert(`Receive from uid:${uid}`, `${imageBuffer.toString()}`); - } - return true; - } - - protected renderConfiguration(): ReactElement | undefined { - const { imageBuffer } = this.state; - return ( - <> - { - this.setState({ imageBuffer: text }); - }} - placeholder={`imageBuffer`} - value={imageBuffer} - /> - - ); - } - - protected override renderUser(): undefined { - return undefined; - } - - protected renderAction(): ReactElement | undefined { - const { joinChannelSuccess } = this.state; - return ( - <> - - - ); - } -} diff --git a/example/src/examples/advanced/index.ts b/example/src/examples/advanced/index.ts index a3036180..11a5b021 100644 --- a/example/src/examples/advanced/index.ts +++ b/example/src/examples/advanced/index.ts @@ -5,7 +5,6 @@ import BeautyEffect from './BeautyEffect/BeautyEffect'; import ChannelMediaRelay from './ChannelMediaRelay/ChannelMediaRelay'; import ContentInspect from './ContentInspect/ContentInspect'; import DirectCdnStreaming from './DirectCdnStreaming/DirectCdnStreaming'; -import EncodedVideoFrame from './EncodedVideoFrame/EncodedVideoFrame'; import Encryption from './Encryption/Encryption'; import Extension from './Extension/Extension'; import JoinMultipleChannel from './JoinMultipleChannel/JoinMultipleChannel'; @@ -60,10 +59,6 @@ const Advanced = { name: 'DirectCdnStreaming', component: DirectCdnStreaming, }, - { - name: 'EncodedVideoFrame', - component: EncodedVideoFrame, - }, { name: 'Encryption', component: Encryption,