|
|
@ -73,11 +73,12 @@ func TestAgent(t *testing.T) { |
|
|
|
}, |
|
|
|
}, |
|
|
|
}} |
|
|
|
}} |
|
|
|
|
|
|
|
|
|
|
|
writeToStream := func(stream *stream.Stream) { |
|
|
|
writeToStream := func(stream *stream.Stream, ntp time.Time) { |
|
|
|
for i := 0; i < 3; i++ { |
|
|
|
for i := 0; i < 3; i++ { |
|
|
|
stream.WriteUnit(desc.Medias[0], desc.Medias[0].Formats[0], &unit.H265{ |
|
|
|
stream.WriteUnit(desc.Medias[0], desc.Medias[0].Formats[0], &unit.H265{ |
|
|
|
Base: unit.Base{ |
|
|
|
Base: unit.Base{ |
|
|
|
PTS: (50 + time.Duration(i)) * time.Second, |
|
|
|
PTS: (50 + time.Duration(i)) * time.Second, |
|
|
|
|
|
|
|
NTP: ntp.Add(time.Duration(i) * 60 * time.Second), |
|
|
|
}, |
|
|
|
}, |
|
|
|
AU: [][]byte{ |
|
|
|
AU: [][]byte{ |
|
|
|
{ // VPS
|
|
|
|
{ // VPS
|
|
|
@ -144,24 +145,6 @@ func TestAgent(t *testing.T) { |
|
|
|
|
|
|
|
|
|
|
|
for _, ca := range []string{"fmp4", "mpegts"} { |
|
|
|
for _, ca := range []string{"fmp4", "mpegts"} { |
|
|
|
t.Run(ca, func(t *testing.T) { |
|
|
|
t.Run(ca, func(t *testing.T) { |
|
|
|
n := 0 |
|
|
|
|
|
|
|
timeNow = func() time.Time { |
|
|
|
|
|
|
|
n++ |
|
|
|
|
|
|
|
switch n { |
|
|
|
|
|
|
|
case 1: |
|
|
|
|
|
|
|
return time.Date(2008, 0o5, 20, 22, 15, 25, 0, time.UTC) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 2: |
|
|
|
|
|
|
|
return time.Date(2009, 0o5, 20, 22, 15, 25, 0, time.UTC) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 3: |
|
|
|
|
|
|
|
return time.Date(2010, 0o5, 20, 22, 15, 25, 0, time.UTC) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
return time.Date(2011, 0o5, 20, 22, 15, 25, 0, time.UTC) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stream, err := stream.New( |
|
|
|
stream, err := stream.New( |
|
|
|
1460, |
|
|
|
1460, |
|
|
|
desc, |
|
|
|
desc, |
|
|
@ -206,7 +189,7 @@ func TestAgent(t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
w.Initialize() |
|
|
|
w.Initialize() |
|
|
|
|
|
|
|
|
|
|
|
writeToStream(stream) |
|
|
|
writeToStream(stream, time.Date(2008, 0o5, 20, 22, 15, 25, 0, time.UTC)) |
|
|
|
|
|
|
|
|
|
|
|
// simulate a write error
|
|
|
|
// simulate a write error
|
|
|
|
stream.WriteUnit(desc.Medias[1], desc.Medias[1].Formats[0], &unit.H264{ |
|
|
|
stream.WriteUnit(desc.Medias[1], desc.Medias[1].Formats[0], &unit.H264{ |
|
|
@ -233,12 +216,12 @@ func TestAgent(t *testing.T) { |
|
|
|
_, err = os.Stat(filepath.Join(dir, "mypath", "2008-05-20_22-15-25-000000."+ext)) |
|
|
|
_, err = os.Stat(filepath.Join(dir, "mypath", "2008-05-20_22-15-25-000000."+ext)) |
|
|
|
require.NoError(t, err) |
|
|
|
require.NoError(t, err) |
|
|
|
|
|
|
|
|
|
|
|
_, err = os.Stat(filepath.Join(dir, "mypath", "2009-05-20_22-15-25-000000."+ext)) |
|
|
|
_, err = os.Stat(filepath.Join(dir, "mypath", "2008-05-20_22-16-25-000000."+ext)) |
|
|
|
require.NoError(t, err) |
|
|
|
require.NoError(t, err) |
|
|
|
|
|
|
|
|
|
|
|
time.Sleep(50 * time.Millisecond) |
|
|
|
time.Sleep(50 * time.Millisecond) |
|
|
|
|
|
|
|
|
|
|
|
writeToStream(stream) |
|
|
|
writeToStream(stream, time.Date(2010, 0o5, 20, 22, 15, 25, 0, time.UTC)) |
|
|
|
|
|
|
|
|
|
|
|
time.Sleep(50 * time.Millisecond) |
|
|
|
time.Sleep(50 * time.Millisecond) |
|
|
|
|
|
|
|
|
|
|
@ -247,7 +230,7 @@ func TestAgent(t *testing.T) { |
|
|
|
_, err = os.Stat(filepath.Join(dir, "mypath", "2010-05-20_22-15-25-000000."+ext)) |
|
|
|
_, err = os.Stat(filepath.Join(dir, "mypath", "2010-05-20_22-15-25-000000."+ext)) |
|
|
|
require.NoError(t, err) |
|
|
|
require.NoError(t, err) |
|
|
|
|
|
|
|
|
|
|
|
_, err = os.Stat(filepath.Join(dir, "mypath", "2011-05-20_22-15-25-000000."+ext)) |
|
|
|
_, err = os.Stat(filepath.Join(dir, "mypath", "2010-05-20_22-16-25-000000."+ext)) |
|
|
|
require.NoError(t, err) |
|
|
|
require.NoError(t, err) |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
@ -278,10 +261,6 @@ func TestAgentFMP4NegativeDTS(t *testing.T) { |
|
|
|
}, |
|
|
|
}, |
|
|
|
}} |
|
|
|
}} |
|
|
|
|
|
|
|
|
|
|
|
timeNow = func() time.Time { |
|
|
|
|
|
|
|
return time.Date(2008, 0o5, 20, 22, 15, 25, 0, time.UTC) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stream, err := stream.New( |
|
|
|
stream, err := stream.New( |
|
|
|
1460, |
|
|
|
1460, |
|
|
|
desc, |
|
|
|
desc, |
|
|
@ -313,6 +292,7 @@ func TestAgentFMP4NegativeDTS(t *testing.T) { |
|
|
|
stream.WriteUnit(desc.Medias[0], desc.Medias[0].Formats[0], &unit.H264{ |
|
|
|
stream.WriteUnit(desc.Medias[0], desc.Medias[0].Formats[0], &unit.H264{ |
|
|
|
Base: unit.Base{ |
|
|
|
Base: unit.Base{ |
|
|
|
PTS: -50*time.Millisecond + (time.Duration(i) * 200 * time.Millisecond), |
|
|
|
PTS: -50*time.Millisecond + (time.Duration(i) * 200 * time.Millisecond), |
|
|
|
|
|
|
|
NTP: time.Date(2008, 0o5, 20, 22, 15, 25, 0, time.UTC), |
|
|
|
}, |
|
|
|
}, |
|
|
|
AU: [][]byte{ |
|
|
|
AU: [][]byte{ |
|
|
|
{ // SPS
|
|
|
|
{ // SPS
|
|
|
|