streaming

Media streaming and broadcast systems in Go
Log | Files | Refs | README | LICENSE

pes_test.go (1043B)


      1 package mpegts
      2 
      3 import (
      4 	"fmt"
      5 	"testing"
      6 )
      7 
      8 func TestPackTimestamp(t *testing.T) {
      9 	var tests = []struct {
     10 		tstamp Timestamp
     11 		want   [5]byte
     12 	}{
     13 		{
     14 			Timestamp{true, true, maxTicks},
     15 			[5]byte{0b00111111, 0xff, 0xff, 0xff, 0xff},
     16 		}, {
     17 			Timestamp{true, true, 0},
     18 			[5]byte{0b00110001, 0, 0b00000001, 0, 0b00000001},
     19 		}, {
     20 			// from packet 10 of testdata/193039199_mp4_h264_aac_hq_7.ts
     21 			Timestamp{true, false, 900909},
     22 			[5]byte{0x21, 0x00, 0x37, 0x7e, 0x5b},
     23 		}, {
     24 			// from packet 163 of testdata/193039199_mp4_h264_aac_hq_7.ts
     25 			Timestamp{true, false, 934346},
     26 			[5]byte{0x21, 0x00, 0x39, 0x83, 0x95},
     27 		},
     28 	}
     29 	for _, tt := range tests {
     30 		name := fmt.Sprintf("%d", tt.tstamp.Ticks)
     31 		t.Run(name, func(t *testing.T) {
     32 			packed := packTimestamp(tt.tstamp)
     33 			if packed != tt.want {
     34 				t.Errorf("packTimestamp(%v) = %x, want %x", tt.tstamp, packed, tt.want)
     35 				for i := range packed {
     36 					if packed[i] != tt.want[i] {
     37 						t.Errorf("byte %d: got %08b, want %08b", i, packed[i], tt.want[i])
     38 					}
     39 				}
     40 			}
     41 		})
     42 	}
     43 }