Skip to content

Commit

Permalink
Added missing format context tests
Browse files Browse the repository at this point in the history
  • Loading branch information
asticode committed Sep 6, 2024
1 parent cbbdcd4 commit f30e2eb
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 10 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
.DS_STORE
coverage.out
tmp
coverage.out
62 changes: 54 additions & 8 deletions format_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestFormatContext(t *testing.T) {
require.NoError(t, err)
require.Equal(t, "v=0\r\no=- 0 0 IN IP4 127.0.0.1\r\ns=Big Buck Bunny\r\nt=0 0\r\na=tool:libavformat 61.1.100\r\nm=video 0 RTP/AVP 96\r\nb=AS:441\r\na=rtpmap:96 H264/90000\r\na=fmtp:96 packetization-mode=1; sprop-parameter-sets=Z0LADasgKDPz4CIAAAMAAgAAAwBhHihUkA==,aM48gA==; profile-level-id=42C00D\r\na=control:streamid=0\r\nm=audio 0 RTP/AVP 97\r\nb=AS:161\r\na=rtpmap:97 MPEG4-GENERIC/48000/2\r\na=fmtp:97 profile-level-id=1;mode=AAC-hbr;sizelength=13;indexlength=3;indexdeltalength=3; config=1190\r\na=control:streamid=1\r\n", sdp)

fc2, err := AllocOutputFormatContext(nil, "", "/tmp/test.mp4")
fc2, err := AllocOutputFormatContext(nil, "mp4", "")
require.NoError(t, err)
defer fc2.Free()
require.True(t, fc2.OutputFormat().Flags().Has(IOFormatFlagGlobalheader))
Expand Down Expand Up @@ -83,11 +83,57 @@ func TestFormatContext(t *testing.T) {
require.Equal(t, 1, len(ps))
require.Equal(t, 1, ps[0].ID())

// TODO Test ReadFrame
// TODO Test SeekFrame
// TODO Test Flush
// TODO Test WriteHeader
// TODO Test WriteFrame
// TODO Test WriteInterleavedFrame
// TODO Test WriteTrailer
fc6 := AllocFormatContext()
require.NotNil(t, fc6)
defer fc6.Free()
require.NoError(t, fc6.OpenInput("testdata/video.mp4", nil, nil))
require.NoError(t, fc6.FindStreamInfo(nil))
require.Equal(t, 2, fc6.NbStreams())
pkt1 := AllocPacket()
require.NotNil(t, pkt1)
defer pkt1.Free()
require.NoError(t, fc6.ReadFrame(pkt1))
require.Equal(t, int64(48), pkt1.Pos())
pkt2 := AllocPacket()
require.NotNil(t, pkt2)
defer pkt2.Free()
require.NoError(t, fc6.ReadFrame(pkt2))
require.Equal(t, int64(261), pkt2.Pos())
require.NoError(t, fc6.SeekFrame(0, 0, NewSeekFlags().Add(SeekFlagBackward)))
require.NoError(t, fc6.ReadFrame(pkt1))
require.Equal(t, int64(48), pkt1.Pos())

const outputPath = "tmp/test-format-context-output.mp4"
fc7, err := AllocOutputFormatContext(nil, "", outputPath)
require.NoError(t, err)
defer fc7.Free()
for _, is := range fc6.Streams() {
os := fc7.NewStream(nil)
require.NotNil(t, os)
require.NoError(t, is.CodecParameters().Copy(os.CodecParameters()))
}
ic, err := OpenIOContext(outputPath, NewIOContextFlags(IOContextFlagWrite))
require.NoError(t, err)
fc7.SetPb(ic)
require.NoError(t, fc7.WriteHeader(nil))
require.NoError(t, fc7.WriteFrame(pkt1))
require.NoError(t, fc7.WriteInterleavedFrame(pkt2))
require.NoError(t, fc7.WriteTrailer())
require.NoError(t, fc7.Flush())
fc8 := AllocFormatContext()
require.NotNil(t, fc8)
defer fc8.Free()
require.NoError(t, fc8.OpenInput(outputPath, nil, nil))
require.NoError(t, fc8.FindStreamInfo(nil))
require.Equal(t, 2, fc8.NbStreams())
pkt3 := AllocPacket()
require.NotNil(t, pkt3)
defer pkt3.Free()
require.NoError(t, fc8.ReadFrame(pkt3))
require.Equal(t, int64(48), pkt3.Pos())
pkt4 := AllocPacket()
require.NotNil(t, pkt4)
defer pkt4.Free()
require.NoError(t, fc8.ReadFrame(pkt4))
require.Equal(t, int64(261), pkt4.Pos())
}
1 change: 1 addition & 0 deletions internal/benchmarks/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tmp
1 change: 1 addition & 0 deletions internal/test/arm/7/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tmp
2 changes: 2 additions & 0 deletions tmp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore

0 comments on commit f30e2eb

Please sign in to comment.