2019-08-04 07:15:28 +03:00
|
|
|
/*
|
|
|
|
DESCRIPTION
|
|
|
|
slice_test.go provides testing for parsing utilities found in slice.go.
|
|
|
|
|
|
|
|
AUTHORS
|
|
|
|
Saxon Nelson-Milton <saxon@ausocean.org>, The Australian Ocean Laboratory (AusOcean)
|
|
|
|
Shawn Smith <shawn@ausocean.org>, The Australian Ocean Laboratory (AusOcean)
|
|
|
|
*/
|
|
|
|
|
2019-07-19 08:50:39 +03:00
|
|
|
package h264dec
|
2019-07-18 07:32:42 +03:00
|
|
|
|
2019-08-04 07:10:53 +03:00
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"bitbucket.org/ausocean/av/codec/h264/h264dec/bits"
|
|
|
|
)
|
2019-07-18 07:32:42 +03:00
|
|
|
|
|
|
|
var subWidthCTests = []struct {
|
|
|
|
in SPS
|
|
|
|
want int
|
|
|
|
}{
|
|
|
|
{SPS{}, 17},
|
|
|
|
{SPS{ChromaFormat: 0}, 17},
|
|
|
|
{SPS{ChromaFormat: 1}, 2},
|
|
|
|
{SPS{ChromaFormat: 2}, 2},
|
|
|
|
{SPS{ChromaFormat: 3}, 1},
|
|
|
|
{SPS{ChromaFormat: 3, UseSeparateColorPlane: true}, 17},
|
|
|
|
{SPS{ChromaFormat: 999}, 17},
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestSubWidthC tests that the correct SubWidthC is returned given
|
|
|
|
// SPS inputs with various chroma formats.
|
|
|
|
func TestSubWidthC(t *testing.T) {
|
|
|
|
for _, tt := range subWidthCTests {
|
|
|
|
if got := SubWidthC(&tt.in); got != tt.want {
|
|
|
|
t.Errorf("SubWidthC(%#v) = %d, want %d", tt.in, got, tt.want)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var subHeightCTests = []struct {
|
|
|
|
in SPS
|
|
|
|
want int
|
|
|
|
}{
|
|
|
|
{SPS{}, 17},
|
|
|
|
{SPS{ChromaFormat: 0}, 17},
|
|
|
|
{SPS{ChromaFormat: 1}, 2},
|
|
|
|
{SPS{ChromaFormat: 2}, 1},
|
|
|
|
{SPS{ChromaFormat: 3}, 1},
|
|
|
|
{SPS{ChromaFormat: 3, UseSeparateColorPlane: true}, 17},
|
|
|
|
{SPS{ChromaFormat: 999}, 17},
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestSubHeightC tests that the correct SubHeightC is returned given
|
|
|
|
// SPS inputs with various chroma formats.
|
|
|
|
func TestSubHeightC(t *testing.T) {
|
|
|
|
for _, tt := range subHeightCTests {
|
|
|
|
if got := SubHeightC(&tt.in); got != tt.want {
|
|
|
|
t.Errorf("SubHeight(%#v) = %d, want %d", tt.in, got, tt.want)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-08-04 07:10:53 +03:00
|
|
|
|
|
|
|
func TestNewRefPicListModification(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
in string
|
|
|
|
s SliceHeader
|
|
|
|
p PPS
|
|
|
|
want RefPicListModification
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
in: "1" + // u(1) ref_pic_list_modification_flag_l0=true
|
|
|
|
// First modification for list0
|
|
|
|
"1" + // ue(v) modification_of_pic_nums_idc[0][0] = 0
|
|
|
|
"010" + // ue(v) abs_diff_pic_num_minus1[0][0] = 1
|
|
|
|
|
|
|
|
// Second modification for list0
|
|
|
|
"010" + // ue(v) modification_of_pic_nums_idc[0][1] = 1
|
|
|
|
"011" + // ue(v) abs_diff_pic_num_minus1[0][1] = 2
|
|
|
|
|
|
|
|
// Third modification for list0
|
|
|
|
"011" + // ue(v) modification_of_pic_nums_idc[0][2] = 2
|
|
|
|
"010" + // ue(v) long_term_pic_num = 1
|
|
|
|
|
|
|
|
// Fourth modification does not exist
|
|
|
|
"00100" + // ue(v) modification_of_pic_nums_idc[0][3] = 3
|
|
|
|
|
|
|
|
// Padding bits
|
|
|
|
"00",
|
|
|
|
|
|
|
|
s: SliceHeader{
|
|
|
|
SliceType: 3,
|
|
|
|
},
|
|
|
|
|
|
|
|
p: PPS{
|
|
|
|
NumRefIdxL0DefaultActiveMinus1: 2,
|
|
|
|
},
|
|
|
|
|
|
|
|
want: RefPicListModification{
|
|
|
|
RefPicListModificationFlag: [2]bool{true, false},
|
|
|
|
ModificationOfPicNums: [2][]int{{0, 1, 2, 3}, {0, 0}},
|
|
|
|
AbsDiffPicNumMinus1: [2][]int{{1, 2, 0, 0}, {0, 0}},
|
|
|
|
LongTermPicNum: [2][]int{{0, 0, 1, 0}, {0, 0}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, test := range tests {
|
|
|
|
inBytes, err := binToSlice(test.in)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error %v for binToSlice in test %d", err, i)
|
|
|
|
}
|
|
|
|
|
|
|
|
got, err := NewRefPicListModification(bits.NewBitReader(bytes.NewReader(inBytes)), &test.p, &test.s)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error %v for NewRefPicListModification in test %d", err, i)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(*got, test.want) {
|
|
|
|
t.Errorf("did not get expected result for test %d\nGot: %v\nWant: %v\n", i, got, test.want)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|