Skip to content

Commit

Permalink
use thread safe atomic bool
Browse files Browse the repository at this point in the history
  • Loading branch information
EmrysMyrddin committed Sep 20, 2023
1 parent dd9582e commit 8eb5e86
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions 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,7 +101,7 @@ type encoderVP8 struct {

rate *framerateDetector

forceKeyFrame bool
forceKeyFrame atomic.Bool

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

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

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

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

func (e *encoderVP8) Close() error {
Expand Down

0 comments on commit 8eb5e86

Please sign in to comment.