github.com/cnotch/ipchub@v1.1.0/av/codec/aac/adtsheader_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 aac 6 7 import ( 8 "testing" 9 10 "github.com/stretchr/testify/assert" 11 ) 12 13 func TestNewADTSHeader(t *testing.T) { 14 tests := []struct { 15 name string 16 profile byte 17 sampleRateIdx byte 18 channelConfig byte 19 payloadSize int 20 }{ 21 {"case1", 1, 4, 2, 200}, 22 {"case1", 2, 3, 4, 5345}, 23 } 24 for _, tt := range tests { 25 t.Run(tt.name, func(t *testing.T) { 26 got := NewADTSHeader(tt.profile, tt.sampleRateIdx, tt.channelConfig, tt.payloadSize) 27 assert.Equal(t, tt.profile, got.Profile()) 28 assert.Equal(t, tt.sampleRateIdx, got.SamplingIndex()) 29 assert.Equal(t, tt.channelConfig, got.ChannelConfig()) 30 assert.Equal(t, tt.payloadSize, got.PayloadSize()) 31 }) 32 } 33 } 34 35 func TestADTSHeader_ToAsc(t *testing.T) { 36 tests := []struct { 37 name string 38 profile byte 39 sampleRateIdx byte 40 channelConfig byte 41 payloadSize int 42 }{ 43 {"case1", 1, 4, 2, 200}, 44 {"case1", 2, 3, 4, 5345}, 45 } 46 for _, tt := range tests { 47 t.Run(tt.name, func(t *testing.T) { 48 got := NewADTSHeader(tt.profile, tt.sampleRateIdx, tt.channelConfig, tt.payloadSize) 49 config := got.ToAsc() 50 var asc AudioSpecificConfig 51 asc.Decode(config) 52 53 assert.Equal(t, tt.profile, asc.ObjectType-1) 54 assert.Equal(t, tt.sampleRateIdx, asc.SamplingIndex) 55 assert.Equal(t, tt.channelConfig, asc.ChannelConfig) 56 }) 57 } 58 }