Skip to content

Commit

Permalink
add pr suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
leandromoreira authored and asticode committed May 14, 2024
1 parent a059a72 commit ac72dc5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 121 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Test

on:
push:
branches: [ "master", "dev" ]
branches: [ "master", "dev", "leandromoreira-master" ]
pull_request:
branches: [ "master" ]

Expand Down
95 changes: 0 additions & 95 deletions astiav_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,43 +85,6 @@ func (h *helper) inputFormatContext(name string) (fc *FormatContext, err error)
return
}

func (h *helper) bitStreamFilterContext(fc *FormatContext, si int, fn string) (*BitStreamFilterContext, error) {
var cs *Stream
for _, s := range fc.Streams() {
if s.Index() != si {
continue
}
cs = s
break
}
if cs == nil {
return nil, fmt.Errorf("astiav_test: could not find a stream to the packet")
}

bsf := FindBitStreamFilterByName(fn)
if bsf == nil {
return nil, fmt.Errorf("astiav_test: cannot find the bit stream filter %s", fn)
}

var bsfc *BitStreamFilterContext
bsfc, err := AllocBitStreamFilterContext(bsf)
if err != nil {
return nil, fmt.Errorf("astiav_test: error while allocating bit stream context %w", err)
}
h.closer.Add(bsfc.Free)

bsfc.SetTimeBaseIn(cs.TimeBase())
if err := cs.CodecParameters().Copy(bsfc.CodecParametersIn()); err != nil {
return nil, fmt.Errorf("astiav_test: error while copying codec parameters for bit stream context%w", err)
}

if err := bsfc.Initialize(); err != nil {
return nil, fmt.Errorf("astiav_test: error while initiating bit stream filter context %w", err)
}

return bsfc, nil
}

func (h *helper) inputFirstPacket(name string) (pkt *Packet, err error) {
h.m.Lock()
i, ok := h.inputs[name]
Expand Down Expand Up @@ -155,64 +118,6 @@ func (h *helper) inputFirstPacket(name string) (pkt *Packet, err error) {
return
}

func (h *helper) inputFirstVideoPacketWithBitStreamFilter(name string, fn string) (pkt *Packet, err error) {
var fc *FormatContext
if fc, err = h.inputFormatContext(name); err != nil {
err = fmt.Errorf("astiav_test: getting input format context failed")
return
}

pkt = AllocPacket()
if pkt == nil {
err = errors.New("astiav_test: pkt is nil")
return
}
h.closer.Add(pkt.Free)
var foundVideo bool

for {
if err = fc.ReadFrame(pkt); err != nil {
err = fmt.Errorf("astiav_test: reading frame failed: %w", err)
return
}

for _, s := range fc.Streams() {
if s.Index() == pkt.StreamIndex() && s.CodecParameters().CodecID() == CodecIDH264 {
foundVideo = true
break
}
}
if foundVideo {
break
}
}

if !foundVideo {
err = fmt.Errorf("astiav_test: there must be an h264 stream")
pkt = nil
return
}

var bsfc *BitStreamFilterContext
bsfc, err = h.bitStreamFilterContext(fc, pkt.StreamIndex(), fn)
if err != nil {
pkt = nil
return
}

if err = bsfc.SendPacket(pkt); err != nil {
err = fmt.Errorf("astiav_test: error while sending the packet %w", err)
pkt = nil
return
}
if err = bsfc.ReceivePacket(pkt); err != nil {
pkt = nil
err = fmt.Errorf("astiav_test: error while receiving the packet %w", err)
return
}
return
}

func (h *helper) inputLastFrame(name string, mediaType MediaType) (f *Frame, err error) {
h.m.Lock()
i, ok := h.inputs[name]
Expand Down
24 changes: 8 additions & 16 deletions bit_stream_filter_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@ import (
)

func TestBitStreamFilterContext(t *testing.T) {
cp1 := AllocCodecParameters()
require.NotNil(t, cp1)
defer cp1.Free()
cp1.SetCodecID(CodecIDH264)

bsf := FindBitStreamFilterByName("null")
require.NotNil(t, bsf)

bsfc, err := AllocBitStreamFilterContext(bsf)
require.NotNil(t, bsfc)
require.Nil(t, err)
require.NoError(t, err)
defer bsfc.Free()

cl := bsfc.Class()
Expand All @@ -22,21 +27,8 @@ func TestBitStreamFilterContext(t *testing.T) {
bsfc.SetTimeBaseIn(NewRational(15, 1))
require.Equal(t, NewRational(15, 1), bsfc.TimeBaseIn())

fc, err := globalHelper.inputFormatContext("video.mp4")
require.NoError(t, err)
ss := fc.Streams()
require.Len(t, ss, 2)
s1 := ss[0]

cp1 := s1.CodecParameters()
bsfc.SetCodecParametersIn(cp1)
require.Equal(t, int64(441324), bsfc.CodecParametersIn().BitRate())

// video.mp4 bit stream h264 format is avcc
pkt1, err := globalHelper.inputFirstPacket("video.mp4")
pkt1Bsf, errBsf := globalHelper.inputFirstVideoPacketWithBitStreamFilter("video.mp4", "h264_mp4toannexb")
require.NoError(t, err)
require.NoError(t, errBsf)
require.Equal(t, CodecIDH264, bsfc.CodecParametersIn().CodecID())

require.NotEqual(t, pkt1.Data(), pkt1Bsf.Data())
// TODO: add tests for send and receive packet flows
}
18 changes: 9 additions & 9 deletions bit_stream_filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import (
)

func TestBitStreamFilter(t *testing.T) {
bitStreamFilterNames := []string{"h264_mp4toannexb", "null", "setts"}
t.Log("TestBitStreamFilter 1")
fn := "null"
f := FindBitStreamFilterByName(fn)
require.NotNil(t, f)
require.Equal(t, f.Name(), fn)
require.Equal(t, f.String(), fn)

for _, fn := range bitStreamFilterNames {
f := FindBitStreamFilterByName(fn)
require.NotNil(t, f)
require.Equal(t, f.Name(), fn)
require.Equal(t, f.String(), fn)
}

f := FindBitStreamFilterByName("foobar_non_existing_bsf")
t.Log("TestBitStreamFilter 2")
f = FindBitStreamFilterByName("foobar_non_existing_bsf")
require.Nil(t, f)
t.Log("TestBitStreamFilter 3")
}

0 comments on commit ac72dc5

Please sign in to comment.