Skip to content

Commit

Permalink
add vp8 test
Browse files Browse the repository at this point in the history
  • Loading branch information
shinyoshiaki committed May 30, 2024
1 parent 3dbbbba commit 93c1252
Showing 1 changed file with 55 additions and 1 deletion.
56 changes: 55 additions & 1 deletion tests/large/loopback.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe('loopback', () => {
});
}));

it('video', () =>
it('video_h264', () =>
new Promise<void>(async (done) => {
const context = await SkyWayContext.Create(testTokenString, {
rtcConfig: { turnPolicy: 'disable' },
Expand Down Expand Up @@ -142,4 +142,58 @@ describe('loopback', () => {
}
});
}));

it('video_vp8', () =>
new Promise<void>(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<Buffer>();
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<RemoteVideoStream>(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();
}
});
}));
});

0 comments on commit 93c1252

Please sign in to comment.