From 93c1252af04724ab925a31b3d89d6d883fbeb8d9 Mon Sep 17 00:00:00 2001 From: shinyoshiaki Date: Thu, 30 May 2024 19:17:02 +0900 Subject: [PATCH] add vp8 test --- tests/large/loopback.test.ts | 56 +++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/tests/large/loopback.test.ts b/tests/large/loopback.test.ts index 924a921..d7eb157 100644 --- a/tests/large/loopback.test.ts +++ b/tests/large/loopback.test.ts @@ -84,7 +84,7 @@ describe('loopback', () => { }); })); - it('video', () => + it('video_h264', () => new Promise(async (done) => { const context = await SkyWayContext.Create(testTokenString, { rtcConfig: { turnPolicy: 'disable' }, @@ -142,4 +142,58 @@ describe('loopback', () => { } }); })); + + it('video_vp8', () => + new Promise(async (done) => { + const context = await SkyWayContext.Create(testTokenString, { + rtcConfig: { turnPolicy: 'disable' }, + }); + const room = await SkyWayRoom.Create(context, { + type: 'sfu', + }); + console.log('roomId', room.id); + const sender = await room.join(); + + const video = await randomPort(); + const onVideo = new Event(); + createSocket('udp4') + .on('message', (buf) => { + onVideo.emit(buf); + }) + .bind(video); + + const launch = gst.parseLaunch( + `videotestsrc ! video/x-raw,width=640,height=480,format=I420 ! vp8enc ! rtpvp8pay picture-id-mode=1 ! udpsink host=127.0.0.1 port=${video}` + ); + launch.setState(gst.State.PLAYING); + + const track = new MediaStreamTrack({ kind: 'video' }); + onVideo.add((data) => { + track.writeRtp(data); + }); + + const publication = await sender.publish(new LocalVideoStream(track), { + codecCapabilities: [ + { + mimeType: 'video/vp8', + }, + ], + }); + + const receiver = await ( + await SkyWayRoom.Find(context, room, 'sfu') + ).join(); + const { stream: remoteStream } = + await receiver.subscribe(publication); + remoteStream.track.onReceiveRtp.subscribe(async (rtp) => { + const codec = dePacketizeRtpPackets('vp8', [rtp]); + if (codec.isKeyframe) { + console.log('receive keyframe'); + await room.close(); + context.dispose(); + launch.setState(gst.State.NULL); + done(); + } + }); + })); });