Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rewriter: add vp8 keyframe detection function #140

Merged
merged 1 commit into from
Mar 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions pkg/conference/subscription/rewriter/vp8.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package rewriter

import (
"github.com/pion/rtp"
"github.com/pion/rtp/codecs"
)

// Determines if a given packet contains a VP8 keyframe.
func IsVP8Keyframe(packet rtp.Packet) bool {
// First try to parse the packet as a VP8 packet.
vp8Packet := codecs.VP8Packet{}

payload, err := vp8Packet.Unmarshal(packet.Payload)
if err != nil {
return false
}

// At this point we know that we're dealing with a VP8 packet
// and we have a so-called "VP8 Payload Descriptor" that Pion
// parses into the `vp8Packet` structure. This is not to be
// confused with the "VP8 Payload Header", one bit of which
// we're parsing here. The P bit is set to 0 for the key frames.
Pbit := (payload[0] & 0x01)

// We also must check that the S bit from the VP8 Payload Descriptor
// is set to 1 as S denotes a start of a new VP8 partition. Typically
// key frames have it set to 1.
return vp8Packet.S == 1 && Pbit == 0
}