Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mpegts: readd PCR to outgoing packets #74

Merged
merged 1 commit into from
Sep 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 58 additions & 48 deletions pkg/formats/mpegts/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,17 @@ var casesReadWriter = []struct {
},
[]sample{
{
0,
0,
30 * 90000,
30 * 90000,
[][]byte{
testH265SPS, // SPS
testH265PPS, // PPS
{byte(h265.NALUType_CRA_NUT) << 1},
},
},
{
2 * 90000,
1 * 90000,
30*90000 + 2*90000,
30*90000 + 1*90000,
[][]byte{
{byte(h265.NALUType_TRAIL_N) << 1},
},
Expand Down Expand Up @@ -98,8 +98,10 @@ var casesReadWriter = []struct {
{ // PES
AdaptationField: &astits.PacketAdaptationField{
Length: 88,
StuffingLength: 87,
StuffingLength: 81,
RandomAccessIndicator: true,
HasPCR: true,
PCR: &astits.ClockReference{Base: 2691000},
},
Header: astits.PacketHeader{
HasAdaptationField: true,
Expand All @@ -109,7 +111,7 @@ var casesReadWriter = []struct {
},
Payload: []byte{
0x00, 0x00, 0x01, 0xe0, 0x00, 0x00, 0x80, 0x80,
0x05, 0x21, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00,
0x05, 0x21, 0x00, 0xa5, 0x65, 0xc1, 0x00, 0x00,
0x00, 0x01, 0x42, 0x01, 0x01, 0x02, 0x20, 0x00,
0x00, 0x03, 0x00, 0xb0, 0x00, 0x00, 0x03, 0x00,
0x00, 0x03, 0x00, 0x7b, 0xa0, 0x07, 0x82, 0x00,
Expand All @@ -136,8 +138,8 @@ var casesReadWriter = []struct {
},
Payload: []byte{
0x00, 0x00, 0x01, 0xe0, 0x00, 0x00, 0x80, 0xc0,
0x0a, 0x31, 0x00, 0x0b, 0x7e, 0x41, 0x11, 0x00,
0x05, 0xbf, 0x21, 0x00, 0x00, 0x00, 0x01, 0x00,
0x0a, 0x31, 0x00, 0xaf, 0xe4, 0x01, 0x11, 0x00,
0xab, 0x24, 0xe1, 0x00, 0x00, 0x00, 0x01, 0x00,
},
},
},
Expand All @@ -150,17 +152,17 @@ var casesReadWriter = []struct {
},
[]sample{
{
0,
0,
30 * 90000,
30 * 90000,
[][]byte{
testH264SPS, // SPS
{8}, // PPS
{5}, // IDR
},
},
{
2 * 90000,
1 * 90000,
30*90000 + 2*90000,
30*90000 + 1*90000,
[][]byte{
{1}, // non-IDR
},
Expand Down Expand Up @@ -194,8 +196,10 @@ var casesReadWriter = []struct {
{ // PES
AdaptationField: &astits.PacketAdaptationField{
Length: 130,
StuffingLength: 129,
StuffingLength: 123,
RandomAccessIndicator: true,
HasPCR: true,
PCR: &astits.ClockReference{Base: 2691000},
},
Header: astits.PacketHeader{
HasAdaptationField: true,
Expand All @@ -205,7 +209,7 @@ var casesReadWriter = []struct {
},
Payload: []byte{
0x00, 0x00, 0x01, 0xe0, 0x00, 0x00, 0x80, 0x80,
0x05, 0x21, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00,
0x05, 0x21, 0x00, 0xa5, 0x65, 0xc1, 0x00, 0x00,
0x00, 0x01, 0x67, 0x42, 0xc0, 0x28, 0xd9, 0x00,
0x78, 0x02, 0x27, 0xe5, 0x84, 0x00, 0x00, 0x03,
0x00, 0x04, 0x00, 0x00, 0x03, 0x00, 0xf0, 0x3c,
Expand All @@ -227,8 +231,8 @@ var casesReadWriter = []struct {
},
Payload: []byte{
0x00, 0x00, 0x01, 0xe0, 0x00, 0x00, 0x80, 0xc0,
0x0a, 0x31, 0x00, 0x0b, 0x7e, 0x41, 0x11, 0x00,
0x05, 0xbf, 0x21, 0x00, 0x00, 0x00, 0x01, 0x01,
0x0a, 0x31, 0x00, 0xaf, 0xe4, 0x01, 0x11, 0x00,
0xab, 0x24, 0xe1, 0x00, 0x00, 0x00, 0x01, 0x01,
},
},
},
Expand All @@ -241,8 +245,8 @@ var casesReadWriter = []struct {
},
[]sample{
{
0,
0,
30 * 90000,
30 * 90000,
[][]byte{{0, 0, 1, 0xb3}},
},
},
Expand Down Expand Up @@ -274,8 +278,10 @@ var casesReadWriter = []struct {
{ // PES
AdaptationField: &astits.PacketAdaptationField{
Length: 165,
StuffingLength: 164,
StuffingLength: 158,
RandomAccessIndicator: true,
HasPCR: true,
PCR: &astits.ClockReference{Base: 2691000},
},
Header: astits.PacketHeader{
HasAdaptationField: true,
Expand All @@ -285,7 +291,7 @@ var casesReadWriter = []struct {
},
Payload: []byte{
0x00, 0x00, 0x01, 0xe0, 0x00, 0x00, 0x80, 0x80,
0x05, 0x21, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00,
0x05, 0x21, 0x00, 0xa5, 0x65, 0xc1, 0x00, 0x00,
0x01, 0xb3,
},
},
Expand All @@ -301,13 +307,13 @@ var casesReadWriter = []struct {
},
[]sample{
{
0,
0,
30 * 90000,
30 * 90000,
[][]byte{{3}, {2}},
},
{
2 * 90000,
0,
30*90000 + 2*90000,
30 * 90000,
[][]byte{{1}},
},
},
Expand Down Expand Up @@ -340,7 +346,9 @@ var casesReadWriter = []struct {
{ // PES
AdaptationField: &astits.PacketAdaptationField{
Length: 161,
StuffingLength: 160,
StuffingLength: 154,
HasPCR: true,
PCR: &astits.ClockReference{Base: 2691000},
RandomAccessIndicator: true,
},
Header: astits.PacketHeader{
Expand All @@ -351,7 +359,7 @@ var casesReadWriter = []struct {
},
Payload: []byte{
0x00, 0x00, 0x01, 0xc0, 0x00, 0x10, 0x80, 0x80,
0x05, 0x21, 0x00, 0x01, 0x00, 0x01, 0x7f, 0xe0,
0x05, 0x21, 0x00, 0xa5, 0x65, 0xc1, 0x7f, 0xe0,
0x01, 0x03, 0x7f, 0xe0, 0x01, 0x02,
},
},
Expand Down Expand Up @@ -397,7 +405,7 @@ var casesReadWriter = []struct {
},
Payload: []byte{
0x00, 0x00, 0x01, 0xc0, 0x00, 0x0c, 0x80, 0x80,
0x05, 0x21, 0x00, 0x0b, 0x7e, 0x41, 0x7f, 0xe0,
0x05, 0x21, 0x00, 0xaf, 0xe4, 0x01, 0x7f, 0xe0,
0x01, 0x01,
},
},
Expand All @@ -417,13 +425,13 @@ var casesReadWriter = []struct {
},
[]sample{
{
0,
0,
30 * 90000,
30 * 90000,
[][]byte{{3}, {2}},
},
{
2 * 90000,
0,
30*90000 + 2*90000,
30 * 90000,
[][]byte{{1}},
},
},
Expand Down Expand Up @@ -455,7 +463,9 @@ var casesReadWriter = []struct {
{ // PES
AdaptationField: &astits.PacketAdaptationField{
Length: 153,
StuffingLength: 152,
StuffingLength: 146,
HasPCR: true,
PCR: &astits.ClockReference{Base: 2691000},
RandomAccessIndicator: true,
},
Header: astits.PacketHeader{
Expand All @@ -466,7 +476,7 @@ var casesReadWriter = []struct {
},
Payload: []byte{
0x00, 0x00, 0x01, 0xc0, 0x00, 0x18, 0x80, 0x80,
0x05, 0x21, 0x00, 0x01, 0x00, 0x01, 0xff, 0xf1,
0x05, 0x21, 0x00, 0xa5, 0x65, 0xc1, 0xff, 0xf1,
0x4c, 0x80, 0x01, 0x1f, 0xfc, 0x03, 0xff, 0xf1,
0x4c, 0x80, 0x01, 0x1f, 0xfc, 0x02,
},
Expand Down Expand Up @@ -512,7 +522,7 @@ var casesReadWriter = []struct {
},
Payload: []byte{
0x00, 0x00, 0x01, 0xc0, 0x00, 0x10, 0x80, 0x80,
0x05, 0x21, 0x00, 0x0b, 0x7e, 0x41, 0xff, 0xf1,
0x05, 0x21, 0x00, 0xaf, 0xe4, 0x01, 0xff, 0xf1,
0x4c, 0x80, 0x01, 0x1f, 0xfc, 0x01,
},
},
Expand All @@ -526,8 +536,8 @@ var casesReadWriter = []struct {
},
[]sample{
{
0,
0,
30 * 90000,
30 * 90000,
[][]byte{{
0xff, 0xfa, 0x52, 0x04, 0xa9, 0xbe, 0xe4, 0x8f,
0xf0, 0xfd, 0x02, 0xdc, 0x80, 0x00, 0x30, 0x00,
Expand Down Expand Up @@ -586,8 +596,9 @@ var casesReadWriter = []struct {
},
{ // PES
AdaptationField: &astits.PacketAdaptationField{
Length: 1,
StuffingLength: 0,
Length: 7,
HasPCR: true,
PCR: &astits.ClockReference{Base: 2691000},
RandomAccessIndicator: true,
},
Header: astits.PacketHeader{
Expand All @@ -598,7 +609,7 @@ var casesReadWriter = []struct {
},
Payload: []byte{
0x00, 0x00, 0x01, 0xc0, 0x00, 0xd9, 0x80, 0x80,
0x05, 0x21, 0x00, 0x01, 0x00, 0x01, 0xff, 0xfa,
0x05, 0x21, 0x00, 0xa5, 0x65, 0xc1, 0xff, 0xfa,
0x52, 0x04, 0xa9, 0xbe, 0xe4, 0x8f, 0xf0, 0xfd,
0x02, 0xdc, 0x80, 0x00, 0x30, 0x00, 0x22, 0xc1,
0x5b, 0x90, 0x14, 0x23, 0x24, 0x05, 0x58, 0x3f,
Expand All @@ -619,13 +630,12 @@ var casesReadWriter = []struct {
0x28, 0x2c, 0x08, 0x06, 0xc0, 0xe0, 0x3c, 0x0a,
0xfa, 0x1a, 0x6f, 0x43, 0x55, 0xbe, 0x05, 0x5a,
0x53, 0xae, 0xcb, 0x74, 0xa9, 0xe8, 0x7e, 0x9f,
0x2f, 0x53, 0xde, 0x8b, 0xd6, 0x20,
},
},
{ // PES
AdaptationField: &astits.PacketAdaptationField{
Length: 142,
StuffingLength: 141,
Length: 136,
StuffingLength: 135,
},
Header: astits.PacketHeader{
ContinuityCounter: 1,
Expand All @@ -635,12 +645,12 @@ var casesReadWriter = []struct {
PID: 257,
},
Payload: []byte{
0x36, 0xce, 0xcb, 0xcd, 0x95, 0x15, 0x08, 0xaa,
0x82, 0x13, 0x51, 0x48, 0xc1, 0x09, 0x28, 0x46,
0x11, 0x0b, 0x3b, 0x41, 0x34, 0x50, 0x24, 0x18,
0xa7, 0x72, 0x88, 0x99, 0x49, 0x17, 0x63, 0xac,
0xa7, 0x98, 0x7e, 0x81, 0x7b, 0x13, 0x9d, 0x7f,
0xd3,
0x2f, 0x53, 0xde, 0x8b, 0xd6, 0x20, 0x36, 0xce,
0xcb, 0xcd, 0x95, 0x15, 0x08, 0xaa, 0x82, 0x13,
0x51, 0x48, 0xc1, 0x09, 0x28, 0x46, 0x11, 0x0b,
0x3b, 0x41, 0x34, 0x50, 0x24, 0x18, 0xa7, 0x72,
0x88, 0x99, 0x49, 0x17, 0x63, 0xac, 0xa7, 0x98,
0x7e, 0x81, 0x7b, 0x13, 0x9d, 0x7f, 0xd3,
},
},
},
Expand Down
1 change: 1 addition & 0 deletions pkg/formats/mpegts/track.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ type Track struct {
PID uint16
Codec Codec

isLeading bool // Writer-only
mp3Checked bool // Writer-only
}

Expand Down
Loading
Loading