github.com/cnotch/ipchub@v1.1.0/av/codec/hevc/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 hevc 6 7 import ( 8 "testing" 9 ) 10 11 func TestH265RawSPS_DecodeString(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 "base64_1", 22 "QgEBAWAAAAMAkAAAAwAAAwBdoAKAgC0WWVmkkyuAQAAA+kAAF3AC", 23 1280, 24 720, 25 float64(24000) / float64(1001), 26 false, 27 }, 28 { 29 "base64_2", 30 "QgEBBAgAAAMAnQgAAAMAAF2wAoCALRZZWaSTK4BAAAADAEAAAAeC", 31 1280, 32 720, 33 30, 34 false, 35 }, 36 } 37 for _, tt := range tests { 38 t.Run(tt.name, func(t *testing.T) { 39 sps := &H265RawSPS{} 40 if err := sps.DecodeString(tt.b64); (err != nil) != tt.wantErr { 41 t.Errorf("RawSPS.Parse() error = %v, wantErr %v", err, tt.wantErr) 42 } 43 if sps.Width() != tt.wantW { 44 t.Errorf("RawSPS.Parse() Width = %v, wantWidth %v", sps.Width(), tt.wantW) 45 } 46 if sps.Height() != tt.wantH { 47 t.Errorf("RawSPS.Parse() Height = %v, wantHeight %v", sps.Height(), tt.wantH) 48 } 49 if sps.FrameRate() != tt.wantFR { 50 t.Errorf("RawSPS.Parse() FrameRate = %v, wantFrameRate %v", sps.FrameRate(), tt.wantFR) 51 } 52 }) 53 } 54 } 55 56 func Benchmark_SPSDecode(b *testing.B) { 57 spsstr := "QgEBAWAAAAMAkAAAAwAAAwBdoAKAgC0WWVmkkyuAQAAA+kAAF3ACQgEBAWAAAAMAkAAAAwAAAwBdoAKAgC0WWVmkkyuAQAAA+kAAF3AC" 58 59 b.ResetTimer() 60 b.RunParallel(func(pb *testing.PB) { 61 for pb.Next() { 62 sps := &H265RawSPS{} 63 _ = sps.DecodeString(spsstr) 64 } 65 }) 66 }