github.com/cnotch/ipchub@v1.1.0/av/codec/h264/sps_test.go (about) 1 // Copyright (c) 2019,CAOHONGJU All rights reserved. 2 // Use of this source code is governed by a MIT-style 3 // license that can be found in the LICENSE file. 4 5 package h264 6 7 import ( 8 "testing" 9 ) 10 11 func TestRawSPS_Parse(t *testing.T) { 12 tests := []struct { 13 name string 14 b64 string 15 wantW int 16 wantH int 17 wantFR float64 18 wantErr bool 19 }{ 20 { 21 "music", 22 "Z01AH6sSB4CL9wgAAAMACAAAAwGUeMGMTA==", 23 960, 24 540, 25 25, 26 false, 27 }, 28 { 29 "game", 30 "Z2QAH6zZQFAFuhAAAAMAEAAAAwPI8YMZYA==", 31 1280, 32 720, 33 30, 34 false, 35 }, 36 { 37 "4k", 38 "Z2QAM6wspADwAQ+wFSAgICgAAB9IAAdTBO0LFok=", 39 3840, 40 2160, 41 float64(60000) / float64(1001*2), 42 false, 43 }, 44 } 45 for _, tt := range tests { 46 t.Run(tt.name, func(t *testing.T) { 47 sps := &RawSPS{} 48 if err := sps.DecodeString(tt.b64); (err != nil) != tt.wantErr { 49 t.Errorf("RawSPS.Parse() error = %v, wantErr %v", err, tt.wantErr) 50 } 51 if sps.Width() != tt.wantW { 52 t.Errorf("RawSPS.Parse() Width = %v, wantWidth %v", sps.Width(), tt.wantW) 53 } 54 if sps.Height() != tt.wantH { 55 t.Errorf("RawSPS.Parse() Height = %v, wantHeight %v", sps.Height(), tt.wantH) 56 } 57 if sps.FrameRate() != tt.wantFR { 58 t.Errorf("RawSPS.Parse() FrameRate = %v, wantFrameRate %v", sps.FrameRate(), tt.wantFR) 59 } 60 }) 61 } 62 }