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

force key frame implementation for vaapi #437

Merged
merged 5 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
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
9 changes: 8 additions & 1 deletion pkg/codec/vaapi/vp8.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import (
"image"
"io"
"sync"
"sync/atomic"
"unsafe"

"github.com/pion/mediadevices/pkg/codec"
Expand Down Expand Up @@ -100,6 +101,8 @@ type encoderVP8 struct {

rate *framerateDetector

forceKeyFrame atomic.Bool
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to bump minimal supported go version to 1.19

go 1.13


mu sync.Mutex
closed bool
}
Expand Down Expand Up @@ -316,7 +319,7 @@ func (e *encoderVP8) Read() ([]byte, func(), error) {

e.frParam.data.framerate = C.uint(e.rate.Calc())

if kf {
if kf || e.forceKeyFrame.CompareAndSwap(true, false) {
// Key frame
C.setForceKFFlagVP8(&e.picParam, 1)
C.setFrameTypeFlagVP8(&e.picParam, 0)
Expand Down Expand Up @@ -546,6 +549,10 @@ func (e *encoderVP8) Controller() codec.EncoderController {
return e
}

func (e *encoderVP8) ForceKeyFrame() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand, this function method already exists and returns the encoder itself.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also don't remember what I wanted to point and old CI log is gone.
The interface seems be correct.

e.forceKeyFrame.Store(true)
}

func (e *encoderVP8) Close() error {
e.mu.Lock()
defer e.mu.Unlock()
Expand Down
2 changes: 0 additions & 2 deletions pkg/codec/vaapi/vp8_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ func TestVP8ShouldImplementBitRateControl(t *testing.T) {
}

func TestVP8ShouldImplementKeyFrameControl(t *testing.T) {
t.SkipNow() // TODO: Implement key frame control

e := &encoderVP8{}
if _, ok := e.Controller().(codec.KeyFrameController); !ok {
t.Error()
Expand Down
9 changes: 8 additions & 1 deletion pkg/codec/vaapi/vp9.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import (
"image"
"io"
"sync"
"sync/atomic"
"unsafe"

"github.com/pion/mediadevices/pkg/codec"
Expand Down Expand Up @@ -92,6 +93,8 @@ type encoderVP9 struct {

rate *framerateDetector

forceKeyFrame atomic.Bool

mu sync.Mutex
closed bool
}
Expand Down Expand Up @@ -305,7 +308,7 @@ func (e *encoderVP9) Read() ([]byte, func(), error) {

e.frParam.data.framerate = C.uint(e.rate.Calc())

if kf {
if kf || e.forceKeyFrame.CompareAndSwap(true, false) {
C.setForceKFFlag9(&e.picParam, 1)
C.setFrameTypeFlagVP9(&e.picParam, 0)
e.picParam.refresh_frame_flags = 0
Expand Down Expand Up @@ -481,6 +484,10 @@ func (e *encoderVP9) Controller() codec.EncoderController {
return e
}

func (e *encoderVP9) ForceKeyFrame() {
e.forceKeyFrame.Store(true)
}

func (e *encoderVP9) Close() error {
e.mu.Lock()
defer e.mu.Unlock()
Expand Down
2 changes: 0 additions & 2 deletions pkg/codec/vaapi/vp9_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ func TestVP9ShouldImplementBitRateControl(t *testing.T) {
}

func TestVP9ShouldImplementKeyFrameControl(t *testing.T) {
t.SkipNow() // TODO: Implement key frame control

e := &encoderVP9{}
if _, ok := e.Controller().(codec.KeyFrameController); !ok {
t.Error()
Expand Down
Loading