Compare commits

..

12 Commits

Author SHA1 Message Date
renovate[bot]
dc3668a627 fix(deps): update module github.com/gen2brain/malgo to v0.11.24
Generated by Renovate Bot
2025-09-22 02:00:39 +00:00
Lei Kang
cb394eb4c5 resolve comment 2025-09-17 16:50:52 -07:00
Atsushi Watanabe
e9f3dc20b6 Fix reading multiple decoded frames 2025-09-17 16:50:52 -07:00
Lei Kang
0710906fc7 fix the test 2025-09-17 16:50:52 -07:00
Lei Kang
7fdafa9598 add codec decoder interface 2025-09-17 16:50:52 -07:00
Lei Kang
5a19127623 add return error code 2025-09-17 16:50:52 -07:00
Lei Kang
8ca6903676 add null pointer from C 2025-09-17 16:50:52 -07:00
Lei Kang
de517d790b wrap vpx_image into a struct 2025-09-17 16:50:52 -07:00
Lei Kang
81cfc047d5 add vpx decoder 2025-09-17 16:50:52 -07:00
renovate[bot]
1406108fb2 fix(deps): update module github.com/stretchr/testify to v1.11.1
Generated by Renovate Bot
2025-09-14 22:46:53 -04:00
renovate[bot]
a2a211857c chore(deps): update actions/setup-go action to v6
Generated by Renovate Bot
2025-09-14 22:41:32 -04:00
philipch07
c0721738c4 Apply go modernize (#650) 2025-09-14 21:55:37 -04:00
19 changed files with 60 additions and 71 deletions

View File

@@ -22,7 +22,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
uses: actions/setup-go@v6
with:
go-version: ${{ matrix.go }}
- name: Install dependencies
@@ -53,7 +53,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
uses: actions/setup-go@v6
with:
go-version: ${{ matrix.go }}
- name: Install dependencies
@@ -76,7 +76,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
uses: actions/setup-go@v6
with:
go-version: stable
- name: Installing go-licenses

4
go.mod
View File

@@ -4,7 +4,7 @@ go 1.21
require (
github.com/blackjack/webcam v0.6.1
github.com/gen2brain/malgo v0.11.23
github.com/gen2brain/malgo v0.11.24
github.com/google/uuid v1.6.0
github.com/kbinani/screenshot v0.0.0-20250624051815-089614a94018
github.com/pion/interceptor v0.1.40
@@ -12,7 +12,7 @@ require (
github.com/pion/rtcp v1.2.15
github.com/pion/rtp v1.8.19
github.com/pion/webrtc/v4 v4.1.2
github.com/stretchr/testify v1.10.0
github.com/stretchr/testify v1.11.1
golang.org/x/image v0.23.0
)

8
go.sum
View File

@@ -2,8 +2,8 @@ github.com/blackjack/webcam v0.6.1 h1:K0T6Q0zto23U99gNAa5q/hFoye6uGcKr2aE6hFoxVo
github.com/blackjack/webcam v0.6.1/go.mod h1:zs+RkUZzqpFPHPiwBZ6U5B34ZXXe9i+SiHLKnnukJuI=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gen2brain/malgo v0.11.23 h1:3/VAI8DP9/Wyx1CUDNlUQJVdWUvGErhjHDqYcHVk9ME=
github.com/gen2brain/malgo v0.11.23/go.mod h1:f9TtuN7DVrXMiV/yIceMeWpvanyVzJQMlBecJFVMxww=
github.com/gen2brain/malgo v0.11.24 h1:hHcIJVfzWcEDHFdPl5Dl/CUSOjzOleY0zzAV8Kx+imE=
github.com/gen2brain/malgo v0.11.24/go.mod h1:f9TtuN7DVrXMiV/yIceMeWpvanyVzJQMlBecJFVMxww=
github.com/gen2brain/shm v0.1.0 h1:MwPeg+zJQXN0RM9o+HqaSFypNoNEcNpeoGp0BTSx2YY=
github.com/gen2brain/shm v0.1.0/go.mod h1:UgIcVtvmOu+aCJpqJX7GOtiN7X2ct+TKLg4RTxwPIUA=
github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk=
@@ -56,8 +56,8 @@ github.com/pion/webrtc/v4 v4.1.2 h1:mpuUo/EJ1zMNKGE79fAdYNFZBX790KE7kQQpLMjjR54=
github.com/pion/webrtc/v4 v4.1.2/go.mod h1:xsCXiNAmMEjIdFxAYU0MbB3RwRieJsegSB2JZsGN+8U=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/wlynxg/anet v0.0.5 h1:J3VJGi1gvo0JwZ/P1/Yc/8p63SoW98B5dHkYDmpgvvU=
github.com/wlynxg/anet v0.0.5/go.mod h1:eay5PRQr7fIVAMbTbchTnO9gG65Hg/uYGdc7mguHxoA=
golang.org/x/crypto v0.33.0 h1:IOBPskki6Lysi0lo9qQvbxiQ+FvsCC/YWOecCHAixus=

View File

@@ -2,6 +2,7 @@ package mediadevices
import (
"io"
"slices"
"testing"
"github.com/pion/mediadevices/pkg/codec"
@@ -93,13 +94,7 @@ func TestMediaStreamFilters(t *testing.T) {
}
for _, a := range actual {
found := false
for _, e := range expected {
if e == a {
found = true
break
}
}
found := slices.Contains(expected, a)
if !found {
t.Fatalf("%s: Expected to find %p in the query results", t.Name(), a)

View File

@@ -167,7 +167,7 @@ type VideoDecoder interface {
// EncoderController is the interface allowing to control the encoder behaviour after it's initialisation.
// It will possibly have common control method in the future.
// A controller can have optional methods represented by *Controller interfaces
type EncoderController interface{}
type EncoderController any
// Controllable is a interface representing a encoder which can be controlled
// after it's initialisation with an EncoderController

View File

@@ -512,9 +512,7 @@ func TestVP8EncodeDecode(t *testing.T) {
}
}
writer.Close()
// ✅ wait until decoder goroutine is done
wg.Wait()
assert.Equal(t, counter, totalFrames)
assert.Equal(t, totalFrames, counter)
})
}

View File

@@ -1,7 +1,8 @@
// Package vnc implements a VNC client.
//
// References:
// [PROTOCOL]: http://tools.ietf.org/html/rfc6143
//
// [PROTOCOL]: http://tools.ietf.org/html/rfc6143
package vnc
import (
@@ -96,7 +97,7 @@ func (c *ClientConn) CutText(text string) error {
var buf bytes.Buffer
// This is the fixed size data we'll send
fixedData := []interface{}{
fixedData := []any{
uint8(6),
uint8(0),
uint8(0),
@@ -141,7 +142,7 @@ func (c *ClientConn) FramebufferUpdateRequest(incremental bool, x, y, width, hei
incrementalByte = 1
}
data := []interface{}{
data := []any{
uint8(3),
incrementalByte,
x, y, width, height,
@@ -172,7 +173,7 @@ func (c *ClientConn) KeyEvent(keysym uint32, down bool) error {
downFlag = 1
}
data := []interface{}{
data := []any{
uint8(4),
downFlag,
uint8(0),
@@ -199,7 +200,7 @@ func (c *ClientConn) KeyEvent(keysym uint32, down bool) error {
func (c *ClientConn) PointerEvent(mask ButtonMask, x, y uint16) error {
var buf bytes.Buffer
data := []interface{}{
data := []any{
uint8(5),
uint8(mask),
x,
@@ -225,7 +226,7 @@ func (c *ClientConn) PointerEvent(mask ButtonMask, x, y uint16) error {
//
// See RFC 6143 Section 7.5.2
func (c *ClientConn) SetEncodings(encs []Encoding) error {
data := make([]interface{}, 3+len(encs))
data := make([]any, 3+len(encs))
data[0] = uint8(2)
data[1] = uint8(0)
data[2] = uint16(len(encs))
@@ -319,7 +320,7 @@ func (c *ClientConn) handshake() error {
}
// Respond with the version we will support
if maxMinor<8 {
if maxMinor < 8 {
if _, err = c.c.Write([]byte("RFB 003.003\n")); err != nil {
return err
}
@@ -331,7 +332,7 @@ func (c *ClientConn) handshake() error {
if numSecurityTypes == 0 {
return fmt.Errorf("no security types: %s", c.readErrorReason())
}
}else{
} else {
if _, err = c.c.Write([]byte("RFB 003.008\n")); err != nil {
return err
}

View File

@@ -63,7 +63,7 @@ func (*FramebufferUpdateMessage) Read(c *ClientConn, r io.Reader) (ServerMessage
var encodingType int32
rect := &rects[i]
data := []interface{}{
data := []any{
&rect.X,
&rect.Y,
&rect.Width,
@@ -128,7 +128,7 @@ func (*SetColorMapEntriesMessage) Read(c *ClientConn, r io.Reader) (ServerMessag
for i := uint16(0); i < numColors; i++ {
color := &result.Colors[i]
data := []interface{}{
data := []any{
&color.R,
&color.G,
&color.B,

View File

@@ -27,7 +27,7 @@ func NewBroadcaster(source Reader, config *BroadcasterConfig) *Broadcaster {
coreConfig = config.Core
}
broadcaster := io.NewBroadcaster(io.ReaderFunc(func() (interface{}, func(), error) {
broadcaster := io.NewBroadcaster(io.ReaderFunc(func() (any, func(), error) {
return source.Read()
}), coreConfig)
@@ -39,11 +39,11 @@ func NewBroadcaster(source Reader, config *BroadcasterConfig) *Broadcaster {
// buffer, this means that slow readers might miss some data if they're really late and the data is no longer
// in the ring buffer.
func (broadcaster *Broadcaster) NewReader(copyChunk bool) Reader {
copyFn := func(src interface{}) interface{} { return src }
copyFn := func(src any) any { return src }
if copyChunk {
buffer := wave.NewBuffer()
copyFn = func(src interface{}) interface{} {
copyFn = func(src any) any {
realSrc, _ := src.(wave.Audio)
buffer.StoreCopy(realSrc)
return buffer.Load()
@@ -60,7 +60,7 @@ func (broadcaster *Broadcaster) NewReader(copyChunk bool) Reader {
// ReplaceSource replaces the underlying source. This operation is thread safe.
func (broadcaster *Broadcaster) ReplaceSource(source Reader) error {
return broadcaster.ioBroadcaster.ReplaceSource(io.ReaderFunc(func() (interface{}, func(), error) {
return broadcaster.ioBroadcaster.ReplaceSource(io.ReaderFunc(func() (any, func(), error) {
return source.Read()
}))
}

View File

@@ -17,7 +17,7 @@ const (
var errEmptySource = fmt.Errorf("Source can't be nil")
type broadcasterData struct {
data interface{}
data any
count uint32
err error
}
@@ -124,10 +124,10 @@ func NewBroadcaster(source Reader, config *BroadcasterConfig) *Broadcaster {
// copyFn is used to copy the data from the source to individual readers. Broadcaster uses a small ring
// buffer, this means that slow readers might miss some data if they're really late and the data is no longer
// in the ring buffer.
func (broadcaster *Broadcaster) NewReader(copyFn func(interface{}) interface{}) Reader {
func (broadcaster *Broadcaster) NewReader(copyFn func(any) any) Reader {
currentCount := broadcaster.buffer.lastCount()
return ReaderFunc(func() (data interface{}, release func(), err error) {
return ReaderFunc(func() (data any, release func(), err error) {
currentCount++
if push := broadcaster.buffer.acquire(currentCount); push != nil {
data, _, err = broadcaster.source.Load().(Reader).Read()

View File

@@ -57,7 +57,7 @@ func TestBroadcast(t *testing.T) {
frameCount := 0
frameSent := 0
lastSend := time.Now()
src = ReaderFunc(func() (interface{}, func(), error) {
src = ReaderFunc(func() (any, func(), error) {
if pauseCond.src && frameSent == 30 {
time.Sleep(time.Second)
}
@@ -85,7 +85,7 @@ func TestBroadcast(t *testing.T) {
wg.Add(n)
for i := 0; i < n; i++ {
go func() {
reader := broadcaster.NewReader(func(src interface{}) interface{} { return src })
reader := broadcaster.NewReader(func(src any) any { return src })
count := 0
lastFrameCount := -1
droppedFrames := 0

View File

@@ -11,13 +11,13 @@ type Reader interface {
// there will be new allocations during streaming, and old unused memory will become garbage. As a consequence,
// these garbage will put a lot of pressure to the garbage collector and makes it to run more often and finish
// slower as the heap memory usage increases and more garbage to collect.
Read() (data interface{}, release func(), err error)
Read() (data any, release func(), err error)
}
// ReaderFunc is a proxy type for Reader
type ReaderFunc func() (data interface{}, release func(), err error)
type ReaderFunc func() (data any, release func(), err error)
func (f ReaderFunc) Read() (data interface{}, release func(), err error) {
func (f ReaderFunc) Read() (data any, release func(), err error) {
data, release, err = f()
return
}

View File

@@ -27,7 +27,7 @@ func NewBroadcaster(source Reader, config *BroadcasterConfig) *Broadcaster {
coreConfig = config.Core
}
broadcaster := io.NewBroadcaster(io.ReaderFunc(func() (interface{}, func(), error) {
broadcaster := io.NewBroadcaster(io.ReaderFunc(func() (any, func(), error) {
return source.Read()
}), coreConfig)
@@ -39,11 +39,11 @@ func NewBroadcaster(source Reader, config *BroadcasterConfig) *Broadcaster {
// buffer, this means that slow readers might miss some data if they're really late and the data is no longer
// in the ring buffer.
func (broadcaster *Broadcaster) NewReader(copyFrame bool) Reader {
copyFn := func(src interface{}) interface{} { return src }
copyFn := func(src any) any { return src }
if copyFrame {
buffer := NewFrameBuffer(0)
copyFn = func(src interface{}) interface{} {
copyFn = func(src any) any {
realSrc, _ := src.(image.Image)
buffer.StoreCopy(realSrc)
return buffer.Load()
@@ -60,7 +60,7 @@ func (broadcaster *Broadcaster) NewReader(copyFrame bool) Reader {
// ReplaceSource replaces the underlying source. This operation is thread safe.
func (broadcaster *Broadcaster) ReplaceSource(source Reader) error {
return broadcaster.ioBroadcaster.ReplaceSource(io.ReaderFunc(func() (interface{}, func(), error) {
return broadcaster.ioBroadcaster.ReplaceSource(io.ReaderFunc(func() (any, func(), error) {
return source.Read()
}))
}

View File

@@ -3,6 +3,7 @@ package prop
import (
"fmt"
"math"
"slices"
"strings"
"time"
)
@@ -54,10 +55,8 @@ type DurationOneOf []time.Duration
// Compare implements DurationConstraint.
func (d DurationOneOf) Compare(a time.Duration) (float64, bool) {
for _, ii := range d {
if ii == a {
return 0.0, true
}
if slices.Contains(d, a) {
return 0.0, true
}
return 1.0, false
}

View File

@@ -3,6 +3,7 @@ package prop
import (
"fmt"
"math"
"slices"
"strings"
)
@@ -53,10 +54,8 @@ type FloatOneOf []float32
// Compare implements FloatConstraint.
func (f FloatOneOf) Compare(a float32) (float64, bool) {
for _, ff := range f {
if ff == a {
return 0.0, true
}
if slices.Contains(f, a) {
return 0.0, true
}
return 1.0, false
}

View File

@@ -3,6 +3,7 @@ package prop
import (
"fmt"
"github.com/pion/mediadevices/pkg/frame"
"slices"
"strings"
)
@@ -56,10 +57,8 @@ type FrameFormatOneOf []frame.Format
// Compare implements FrameFormatConstraint.
func (f FrameFormatOneOf) Compare(a frame.Format) (float64, bool) {
for _, ff := range f {
if ff == a {
return 0.0, true
}
if slices.Contains(f, a) {
return 0.0, true
}
return 1.0, false
}

View File

@@ -3,6 +3,7 @@ package prop
import (
"fmt"
"math"
"slices"
"strings"
)
@@ -53,10 +54,8 @@ type IntOneOf []int
// Compare implements IntConstraint.
func (i IntOneOf) Compare(a int) (float64, bool) {
for _, ii := range i {
if ii == a {
return 0.0, true
}
if slices.Contains(i, a) {
return 0.0, true
}
return 1.0, false
}

View File

@@ -32,7 +32,7 @@ func (m *Media) String() string {
return prettifyStruct(m)
}
func prettifyStruct(i interface{}) string {
func prettifyStruct(i any) string {
var rows []string
var addRows func(int, reflect.Value)
addRows = func(level int, obj reflect.Value) {
@@ -67,7 +67,7 @@ type setterFn func(fieldA, fieldB reflect.Value)
// merge merges all the field values from o to p, except zero values. It's guaranteed that setterFn will be called
// when fieldA and fieldB are not struct.
func (p *Media) merge(o interface{}, set setterFn) {
func (p *Media) merge(o any, set setterFn) {
rp := reflect.ValueOf(p).Elem()
ro := reflect.ValueOf(o)
@@ -159,13 +159,13 @@ func (p *MediaConstraints) FitnessDistance(o Media) (float64, bool) {
}
type comparisons []struct {
desired, actual interface{}
desired, actual any
}
func (c *comparisons) add(desired, actual interface{}) {
func (c *comparisons) add(desired, actual any) {
if desired != nil {
*c = append(*c,
struct{ desired, actual interface{} }{
struct{ desired, actual any }{
desired, actual,
},
)

View File

@@ -2,6 +2,7 @@ package prop
import (
"fmt"
"slices"
"strings"
)
@@ -55,10 +56,8 @@ type StringOneOf []string
// Compare implements StringConstraint.
func (f StringOneOf) Compare(a string) (float64, bool) {
for _, ff := range f {
if ff == a {
return 0.0, true
}
if slices.Contains(f, a) {
return 0.0, true
}
return 1.0, false
}