diff --git a/app/demo/calcrtmpdelay/calcrtmpdelay.go b/app/demo/calcrtmpdelay/calcrtmpdelay.go index 7326a779..394547d2 100644 --- a/app/demo/calcrtmpdelay/calcrtmpdelay.go +++ b/app/demo/calcrtmpdelay/calcrtmpdelay.go @@ -92,12 +92,12 @@ func main() { switch pullType { case PullTypeHttpflv: - httpflvPullSession = httpflv.NewPullSession() - err = httpflvPullSession.Pull(pullUrl, func(tag httpflv.Tag) { + httpflvPullSession = httpflv.NewPullSession().WithOnReadFlvTag(func(tag httpflv.Tag) { handleReadPayloadFn(tag.Payload()) }) - if err != nil { + if err = httpflvPullSession.Start(pullUrl); err != nil { nazalog.Fatalf("pull flv failed. err=%+v", err) + return } nazalog.Info("pull flv succ.") defer httpflvPullSession.Dispose() diff --git a/app/demo/pullhttpflv/pullhttpflv.go b/app/demo/pullhttpflv/pullhttpflv.go index 52b296cd..b3d7908d 100644 --- a/app/demo/pullhttpflv/pullhttpflv.go +++ b/app/demo/pullhttpflv/pullhttpflv.go @@ -37,8 +37,7 @@ func main() { defer flvfile.Close() - session := httpflv.NewPullSession() - err = session.Pull(url, func(tag httpflv.Tag) { + session := httpflv.NewPullSession().WithOnReadFlvTag(func(tag httpflv.Tag) { if tag.Header.Type == httpflv.TagTypeMetadata { // TODO(chef): httpflv.PullSession支持返回flv header,可供业务方选择使用 202210 // 根据metadata填写flv头 @@ -69,6 +68,8 @@ func main() { flvfile.Write(tag.Raw) }) + + err = session.Start(url) nazalog.Assert(nil, err) err = <-session.WaitChan() nazalog.Assert(nil, err) diff --git a/pkg/httpflv/client_pull_session.go b/pkg/httpflv/client_pull_session.go index 56af37bc..87f0b2b4 100644 --- a/pkg/httpflv/client_pull_session.go +++ b/pkg/httpflv/client_pull_session.go @@ -91,7 +91,7 @@ func (session *PullSession) Start(rawUrl string) error { return session.pull(rawUrl) } -// Pull deprecated. use Start instead. +// Pull deprecated. use WithOnReadFlvTag and Start instead. func (session *PullSession) Pull(rawUrl string, onReadFlvTag OnReadFlvTag) error { return session.WithOnReadFlvTag(onReadFlvTag).Start(rawUrl) } diff --git a/pkg/innertest/innertest.go b/pkg/innertest/innertest.go index 9cd3a418..09788591 100644 --- a/pkg/innertest/innertest.go +++ b/pkg/innertest/innertest.go @@ -232,13 +232,13 @@ func entry() { var flvErr error httpflvPullSession = httpflv.NewPullSession(func(option *httpflv.PullSessionOption) { option.ReadTimeoutMs = 10000 - }) - err := httpflvPullSession.Pull(httpflvPullUrl, func(tag httpflv.Tag) { - err := httpFlvWriter.WriteTag(tag) - assert.Equal(t, nil, err) + }).WithOnReadFlvTag(func(tag httpflv.Tag) { + errWrite := httpFlvWriter.WriteTag(tag) + assert.Equal(t, nil, errWrite) httpflvPullTagCount.Increment() }) - Log.Assert(nil, err) + errStart := httpflvPullSession.Start(httpflvPullUrl) + Log.Assert(nil, errStart) flvErr = <-httpflvPullSession.WaitChan() Log.Debug(flvErr)