2018-12-07 08:23:38 +03:00
|
|
|
package psi
|
|
|
|
|
|
|
|
import (
|
2018-12-11 07:22:18 +03:00
|
|
|
"bytes"
|
2018-12-07 08:23:38 +03:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2018-12-11 08:32:57 +03:00
|
|
|
const (
|
2018-12-11 09:35:40 +03:00
|
|
|
tstTime = 1235367435 // hex = 49A2360B
|
|
|
|
tstTime2 = 1735357535 // hex = 676F745F
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
errCmp = "Incorrect output, for: %v wanted: %v, got: %v"
|
2018-12-11 08:32:57 +03:00
|
|
|
)
|
|
|
|
|
2018-12-10 10:12:45 +03:00
|
|
|
var (
|
2018-12-11 08:32:57 +03:00
|
|
|
timeSlice = []byte{
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x49, 0xA2, 0x36, 0x0B,
|
|
|
|
}
|
|
|
|
patPsi1 = PSI{
|
2018-12-10 10:12:45 +03:00
|
|
|
Pf: 0x00,
|
|
|
|
Tid: 0x00,
|
|
|
|
Ssi: true,
|
|
|
|
Pb: false,
|
|
|
|
Sl: uint16(0x0d),
|
|
|
|
Tss: &TSS{
|
|
|
|
Tide: uint16(0x01),
|
|
|
|
V: 0,
|
|
|
|
Cni: true,
|
|
|
|
Sn: 0,
|
|
|
|
Lsn: 0,
|
|
|
|
Sd: &PAT{
|
|
|
|
Pn: uint16(0x01),
|
2018-12-11 07:22:18 +03:00
|
|
|
Pmpid: uint16(0x1000),
|
2018-12-10 10:12:45 +03:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2018-12-11 08:32:57 +03:00
|
|
|
pmtPsi1 = PSI{
|
2018-12-11 07:22:18 +03:00
|
|
|
Pf: 0x00,
|
2018-12-10 10:12:45 +03:00
|
|
|
Tid: 0x02,
|
|
|
|
Ssi: true,
|
2018-12-11 07:22:18 +03:00
|
|
|
Sl: uint16(0x12),
|
|
|
|
Tss: &TSS{
|
2018-12-10 10:12:45 +03:00
|
|
|
Tide: uint16(0x01),
|
2018-12-11 07:22:18 +03:00
|
|
|
V: 0,
|
|
|
|
Cni: true,
|
|
|
|
Sn: 0,
|
|
|
|
Lsn: 0,
|
2018-12-10 10:12:45 +03:00
|
|
|
Sd: &PMT{
|
2018-12-11 08:32:57 +03:00
|
|
|
Pcrpid: 0x0100, // wrong
|
2018-12-11 07:22:18 +03:00
|
|
|
Pil: 0,
|
2018-12-10 10:12:45 +03:00
|
|
|
Essd: &ESSD{
|
2018-12-11 07:22:18 +03:00
|
|
|
St: 0x1b,
|
|
|
|
Epid: 0x0100,
|
|
|
|
Esil: 0x00,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2018-12-10 10:12:45 +03:00
|
|
|
}
|
2018-12-11 08:32:57 +03:00
|
|
|
// pmt with descriptor in it
|
2018-12-11 09:35:40 +03:00
|
|
|
StdPmtTime = []byte{
|
2018-12-11 08:32:57 +03:00
|
|
|
0x00, // pointer
|
|
|
|
|
|
|
|
// ---- section included in data sent to CRC32 during check
|
|
|
|
// table header
|
|
|
|
0x02, // table id
|
|
|
|
0xb0, // section syntax indicator:1|private bit:1|reserved:2|section length:2|more bytes...:2
|
|
|
|
0x12, // more bytes...
|
|
|
|
|
|
|
|
// syntax section
|
|
|
|
0x00, 0x01, // table id extension
|
|
|
|
0xc1, // reserved bits:3|version:5|use now:1
|
|
|
|
0x00, // section number
|
|
|
|
0x00, // last section number
|
|
|
|
// table data
|
|
|
|
0xe1, 0x00, // reserved:3|PCR PID:13
|
|
|
|
0xf0, 0x0a, // reserved:4|unused:2|program info length:10
|
|
|
|
// Desriptor
|
2018-12-11 09:35:40 +03:00
|
|
|
byte(timeDescTag), // Descriptor tag
|
2018-12-11 08:32:57 +03:00
|
|
|
byte(8), // Length of bytes to follow
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x49, 0xA2, 0x36, 0x0B, // timestamp
|
|
|
|
// No program descriptors since program info length is 0.
|
|
|
|
// elementary stream info data
|
|
|
|
0x1b, // stream type
|
|
|
|
0xe1, 0x00, // reserved:3|elementary PID:13
|
|
|
|
0xf0, 0x00, // reserved:4|unused:2|ES info length:10
|
|
|
|
// No elementary stream descriptors since ES info length is 0.
|
|
|
|
|
|
|
|
// 0x15, 0xbd, 0x4d, 0x56, // CRC
|
|
|
|
// ----
|
|
|
|
}
|
2018-12-11 09:35:40 +03:00
|
|
|
pmtPsiTime = PSI{
|
2018-12-11 08:32:57 +03:00
|
|
|
Pf: 0x00,
|
|
|
|
Tid: 0x02,
|
|
|
|
Ssi: true,
|
|
|
|
Sl: uint16(0x12),
|
|
|
|
Tss: &TSS{
|
|
|
|
Tide: uint16(0x01),
|
|
|
|
V: 0,
|
|
|
|
Cni: true,
|
|
|
|
Sn: 0,
|
|
|
|
Lsn: 0,
|
|
|
|
Sd: &PMT{
|
|
|
|
Pcrpid: 0x0100, // wrong
|
|
|
|
Pil: 10,
|
|
|
|
Pd: []Desc{
|
|
|
|
Desc{
|
2018-12-11 09:35:40 +03:00
|
|
|
Dt: byte(timeDescTag),
|
2018-12-11 08:32:57 +03:00
|
|
|
Dl: byte(8),
|
2018-12-11 09:35:40 +03:00
|
|
|
Dd: TimeToBytes(tstTime),
|
2018-12-11 08:32:57 +03:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Essd: &ESSD{
|
|
|
|
St: 0x1b,
|
|
|
|
Epid: 0x0100,
|
|
|
|
Esil: 0x00,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2018-12-11 09:35:40 +03:00
|
|
|
// pmt with descriptor in it
|
|
|
|
StdPmtTime2 = []byte{
|
|
|
|
0x00, // pointer
|
|
|
|
|
|
|
|
// ---- section included in data sent to CRC32 during check
|
|
|
|
// table header
|
|
|
|
0x02, // table id
|
|
|
|
0xb0, // section syntax indicator:1|private bit:1|reserved:2|section length:2|more bytes...:2
|
|
|
|
0x12, // more bytes...
|
|
|
|
|
|
|
|
// syntax section
|
|
|
|
0x00, 0x01, // table id extension
|
|
|
|
0xc1, // reserved bits:3|version:5|use now:1
|
|
|
|
0x00, // section number
|
|
|
|
0x00, // last section number
|
|
|
|
// table data
|
|
|
|
0xe1, 0x00, // reserved:3|PCR PID:13
|
|
|
|
0xf0, 0x0a, // reserved:4|unused:2|program info length:10
|
|
|
|
// Desriptor
|
|
|
|
byte(timeDescTag), // Descriptor tag
|
|
|
|
byte(8), // Length of bytes to follow
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x67, 0x6F, 0x74, 0x5F, // timestamp
|
|
|
|
// No program descriptors since program info length is 0.
|
|
|
|
// elementary stream info data
|
|
|
|
0x1b, // stream type
|
|
|
|
0xe1, 0x00, // reserved:3|elementary PID:13
|
|
|
|
0xf0, 0x00, // reserved:4|unused:2|ES info length:10
|
|
|
|
// No elementary stream descriptors since ES info length is 0.
|
|
|
|
|
|
|
|
// 0x15, 0xbd, 0x4d, 0x56, // CRC
|
|
|
|
// ----
|
|
|
|
}
|
2018-12-10 10:12:45 +03:00
|
|
|
)
|
|
|
|
|
2018-12-11 08:32:57 +03:00
|
|
|
// Test Bytes for a standard pat
|
|
|
|
func TestBytesPAT1(t *testing.T) {
|
|
|
|
got := patPsi1.Bytes()
|
2018-12-11 07:22:18 +03:00
|
|
|
// Remove crc32
|
|
|
|
got = got[:len(got)-4]
|
2018-12-11 08:32:57 +03:00
|
|
|
if !bytes.Equal(StdPat, got) {
|
2018-12-11 09:35:40 +03:00
|
|
|
t.Errorf(errCmp, "TestBytesPAT1", StdPat, got)
|
2018-12-11 07:22:18 +03:00
|
|
|
}
|
|
|
|
}
|
2018-12-07 08:23:38 +03:00
|
|
|
|
2018-12-11 08:32:57 +03:00
|
|
|
// Test Bytes for a standard pmt
|
|
|
|
func TestBytesPMT1(t *testing.T) {
|
|
|
|
got := pmtPsi1.Bytes()
|
2018-12-11 07:22:18 +03:00
|
|
|
// Remove crc32
|
|
|
|
got = got[:len(got)-4]
|
2018-12-11 08:32:57 +03:00
|
|
|
if !bytes.Equal(StdPmt, got) {
|
2018-12-11 09:35:40 +03:00
|
|
|
t.Errorf(errCmp, "TestBytesPMT1", StdPmt, got)
|
2018-12-11 07:22:18 +03:00
|
|
|
}
|
2018-12-07 08:23:38 +03:00
|
|
|
}
|
2018-12-11 08:32:57 +03:00
|
|
|
|
|
|
|
// A quick sanity check of the int64 time to []byte func
|
|
|
|
func TestTimestampToBytes(t *testing.T) {
|
2018-12-11 09:35:40 +03:00
|
|
|
timeBytes := TimeToBytes(tstTime)
|
2018-12-11 08:32:57 +03:00
|
|
|
if !bytes.Equal(timeSlice, timeBytes) {
|
2018-12-11 09:35:40 +03:00
|
|
|
t.Errorf(errCmp, "testTimeStampToBytes", timeSlice, timeBytes)
|
2018-12-11 08:32:57 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test Bytes for a a standard PMT with a descripot containing a timestamp
|
|
|
|
func TestBytesPmt2(t *testing.T) {
|
2018-12-11 09:35:40 +03:00
|
|
|
got := pmtPsiTime.Bytes()
|
2018-12-11 08:32:57 +03:00
|
|
|
// Remove crc32
|
|
|
|
got = got[:len(got)-4]
|
2018-12-11 09:35:40 +03:00
|
|
|
if !bytes.Equal(StdPmtTime, got) {
|
|
|
|
t.Errorf(errCmp, "testBytesPmt2", StdPmtTime, got)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTimeUpdate(t *testing.T) {
|
|
|
|
cpy := make([]byte, len(StdPmtTime))
|
|
|
|
copy(cpy, StdPmtTime)
|
|
|
|
err := UpdateTime(cpy, tstTime2)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Update time returned err: %v", err)
|
|
|
|
}
|
|
|
|
if !bytes.Equal(StdPmtTime2, cpy) {
|
|
|
|
t.Errorf(errCmp, "TestTimeUpdate", StdPmtTime2, cpy)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTimeGet(t *testing.T) {
|
|
|
|
s, err := GetTime(StdPmtTime)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Getting timestamp failed with err: %v", err)
|
|
|
|
}
|
|
|
|
if s != tstTime {
|
|
|
|
t.Errorf(errCmp, "TestTimeGet", tstTime, s)
|
2018-12-11 08:32:57 +03:00
|
|
|
}
|
|
|
|
}
|