mirror of
https://github.com/pion/mediadevices.git
synced 2025-10-04 08:16:33 +08:00
Compare commits
3 Commits
renovate/g
...
vpx-improv
Author | SHA1 | Date | |
---|---|---|---|
![]() |
5d95b80d78 | ||
![]() |
76a5f96ae8 | ||
![]() |
ccbb78bd00 |
2
go.mod
2
go.mod
@@ -4,7 +4,7 @@ go 1.21
|
||||
|
||||
require (
|
||||
github.com/blackjack/webcam v0.6.1
|
||||
github.com/gen2brain/malgo v0.11.24
|
||||
github.com/gen2brain/malgo v0.11.23
|
||||
github.com/google/uuid v1.6.0
|
||||
github.com/kbinani/screenshot v0.0.0-20250624051815-089614a94018
|
||||
github.com/pion/interceptor v0.1.40
|
||||
|
4
go.sum
4
go.sum
@@ -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.24 h1:hHcIJVfzWcEDHFdPl5Dl/CUSOjzOleY0zzAV8Kx+imE=
|
||||
github.com/gen2brain/malgo v0.11.24/go.mod h1:f9TtuN7DVrXMiV/yIceMeWpvanyVzJQMlBecJFVMxww=
|
||||
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/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=
|
||||
|
40
pkg/codec/vpx/vpx_image.go
Normal file
40
pkg/codec/vpx/vpx_image.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package vpx
|
||||
|
||||
/*
|
||||
#cgo pkg-config: vpx
|
||||
#include <vpx/vpx_image.h>
|
||||
*/
|
||||
import "C"
|
||||
import "unsafe"
|
||||
|
||||
type VpxImage struct {
|
||||
img *C.vpx_image_t
|
||||
}
|
||||
|
||||
func NewImageFromPtr(ptr *C.vpx_image_t) *VpxImage {
|
||||
return &VpxImage{img: ptr}
|
||||
}
|
||||
|
||||
func (i *VpxImage) Width() int {
|
||||
return int(i.img.d_w)
|
||||
}
|
||||
|
||||
func (i *VpxImage) Height() int {
|
||||
return int(i.img.d_h)
|
||||
}
|
||||
|
||||
func (i *VpxImage) YStride() int {
|
||||
return int(i.img.stride[0])
|
||||
}
|
||||
|
||||
func (i *VpxImage) UStride() int {
|
||||
return int(i.img.stride[1])
|
||||
}
|
||||
|
||||
func (i *VpxImage) VStride() int {
|
||||
return int(i.img.stride[2])
|
||||
}
|
||||
|
||||
func (i *VpxImage) Plane(n int) unsafe.Pointer {
|
||||
return unsafe.Pointer(i.img.planes[n])
|
||||
}
|
94
pkg/codec/vpx/vpx_image_test.go
Normal file
94
pkg/codec/vpx/vpx_image_test.go
Normal file
@@ -0,0 +1,94 @@
|
||||
package vpx
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// TestVpxImageStructure tests the VpxImage struct methods
|
||||
// Note: These tests verify the interface and structure without requiring actual VPX images
|
||||
func TestVpxImageStructure(t *testing.T) {
|
||||
// Test that VpxImage can be created (interface test)
|
||||
// We can't easily test with real C structures in unit tests due to CGO limitations
|
||||
// but we can test the structure and interface
|
||||
|
||||
t.Run("VpxImageInterface", func(t *testing.T) {
|
||||
// This test ensures the VpxImage type exists and has the expected methods
|
||||
// We use a type assertion to verify the interface
|
||||
var _ interface {
|
||||
Width() int
|
||||
Height() int
|
||||
YStride() int
|
||||
UStride() int
|
||||
VStride() int
|
||||
Plane(int) unsafe.Pointer
|
||||
} = (*VpxImage)(nil)
|
||||
})
|
||||
}
|
||||
|
||||
// TestNewImageFromPtr tests the constructor
|
||||
func TestNewImageFromPtr(t *testing.T) {
|
||||
// Test with nil pointer
|
||||
vpxImg := NewImageFromPtr(nil)
|
||||
if vpxImg == nil {
|
||||
t.Error("NewImageFromPtr should not return nil even with nil input")
|
||||
}
|
||||
if vpxImg != nil && vpxImg.img != nil {
|
||||
t.Error("VpxImage should contain nil pointer when created with nil")
|
||||
}
|
||||
}
|
||||
|
||||
// TestVpxImageMethodsWithNil tests that methods panic appropriately with nil pointer
|
||||
// This documents the expected behavior - methods will panic if called with nil C pointer
|
||||
func TestVpxImageMethodsWithNil(t *testing.T) {
|
||||
vpxImg := NewImageFromPtr(nil)
|
||||
|
||||
// These methods should panic with nil img (this is expected behavior)
|
||||
testCases := []struct {
|
||||
name string
|
||||
fn func()
|
||||
}{
|
||||
{"Width", func() { vpxImg.Width() }},
|
||||
{"Height", func() { vpxImg.Height() }},
|
||||
{"YStride", func() { vpxImg.YStride() }},
|
||||
{"UStride", func() { vpxImg.UStride() }},
|
||||
{"VStride", func() { vpxImg.VStride() }},
|
||||
{"Plane0", func() { vpxImg.Plane(0) }},
|
||||
{"Plane1", func() { vpxImg.Plane(1) }},
|
||||
{"Plane2", func() { vpxImg.Plane(2) }},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
defer func() {
|
||||
if r := recover(); r == nil {
|
||||
t.Errorf("Method %s should panic with nil image but didn't", tc.name)
|
||||
}
|
||||
}()
|
||||
tc.fn()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestVpxImageConstants tests expected behavior with common video formats
|
||||
func TestVpxImageConstants(t *testing.T) {
|
||||
// Test that the VpxImage type can be used in common video processing scenarios
|
||||
testCases := []struct {
|
||||
name string
|
||||
planeIndex int
|
||||
description string
|
||||
}{
|
||||
{"Y Plane", 0, "Luma plane"},
|
||||
{"U Plane", 1, "Chroma U plane"},
|
||||
{"V Plane", 2, "Chroma V plane"},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
// Verify plane indices are within expected range
|
||||
if tc.planeIndex < 0 || tc.planeIndex > 2 {
|
||||
t.Errorf("Plane index %d is out of expected range [0-2]", tc.planeIndex)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user