github.com/bluenviron/mediacommon@v1.9.3/pkg/codecs/vp9/header_test.go (about)

     1  package vp9
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/require"
     7  )
     8  
     9  func TestHeaderUnmarshal(t *testing.T) {
    10  	for _, ca := range []struct {
    11  		name   string
    12  		byts   []byte
    13  		sh     Header
    14  		width  int
    15  		height int
    16  	}{
    17  		{
    18  			"chrome webrtc",
    19  			[]byte{
    20  				0x82, 0x49, 0x83, 0x42, 0x00, 0x77, 0xf0, 0x32,
    21  				0x34, 0x30, 0x38, 0x24, 0x1c, 0x19, 0x40, 0x18,
    22  				0x03, 0x40, 0x5f, 0xb4,
    23  			},
    24  			Header{
    25  				ShowFrame: true,
    26  				ColorConfig: &Header_ColorConfig{
    27  					BitDepth:     8,
    28  					SubsamplingX: true,
    29  					SubsamplingY: true,
    30  				},
    31  				FrameSize: &Header_FrameSize{
    32  					FrameWidthMinus1:  1919,
    33  					FrameHeightMinus1: 803,
    34  				},
    35  			},
    36  			1920,
    37  			804,
    38  		},
    39  		{
    40  			"vp9 sample",
    41  			[]byte{
    42  				0x82, 0x49, 0x83, 0x42, 0x40, 0xef, 0xf0, 0x86,
    43  				0xf4, 0x04, 0x21, 0xa0, 0xe0, 0x00, 0x30, 0x70,
    44  				0x00, 0x00, 0x00, 0x01,
    45  			},
    46  			Header{
    47  				ShowFrame: true,
    48  				ColorConfig: &Header_ColorConfig{
    49  					BitDepth:     8,
    50  					ColorSpace:   2,
    51  					SubsamplingX: true,
    52  					SubsamplingY: true,
    53  				},
    54  				FrameSize: &Header_FrameSize{
    55  					FrameWidthMinus1:  3839,
    56  					FrameHeightMinus1: 2159,
    57  				},
    58  			},
    59  			3840,
    60  			2160,
    61  		},
    62  	} {
    63  		t.Run(ca.name, func(t *testing.T) {
    64  			var sh Header
    65  			err := sh.Unmarshal(ca.byts)
    66  			require.NoError(t, err)
    67  			require.Equal(t, ca.sh, sh)
    68  			require.Equal(t, ca.width, sh.Width())
    69  			require.Equal(t, ca.height, sh.Height())
    70  		})
    71  	}
    72  }
    73  
    74  func FuzzHeaderUnmarshal(f *testing.F) {
    75  	f.Fuzz(func(_ *testing.T, b []byte) {
    76  		var sh Header
    77  		sh.Unmarshal(b) //nolint:errcheck
    78  	})
    79  }