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

demo中的pullrtmp2hls无法工作 #101

Closed
joyhope opened this issue Jul 23, 2021 · 5 comments
Closed

demo中的pullrtmp2hls无法工作 #101

joyhope opened this issue Jul 23, 2021 · 5 comments

Comments

@joyhope
Copy link

joyhope commented Jul 23, 2021

pullrtmp2hls 和 -i rtsp 做连接 直接crash。

2021/07/23 23:05:19.665373 �[22;36m INFO�[0m [RTMPPULL1] < R _result(). - client_session.go:479
2021/07/23 23:05:19.665373 �[22;36m INFO�[0m [RTMPPULL1] > W play('mystream'). - client_session.go:482
2021/07/23 23:05:19.665891 �[22;33m WARN�[0m [RTMPPULL1] read user control message, ignore. buf=00000000 00 04 00 00 00 01 |......|

  • client_session.go:350
    2021/07/23 23:05:19.666407 �[22;33m WARN�[0m [RTMPPULL1] read user control message, ignore. buf=00000000 00 00 00 00 00 01 |......|
  • client_session.go:350
    2021/07/23 23:05:19.666925 �[22;36m INFO�[0m [RTMPPULL1] < R onStatus('NetStream.Play.Start'). - client_session.go:435
    panic: runtime error: invalid memory address or nil pointer dereference
    [signal 0xc0000005 code=0x0 addr=0x18 pc=0xdb73a8]

比较容易重现的。 lalserver做服务,pullrtmp2hls 和lalserver连接。

@joyhope
Copy link
Author

joyhope commented Jul 24, 2021

触发的这个函数 observer是nil

func (m *Muxer) OnPatPmt(b []byte) {
	m.patpmt = b
	m.observer.OnPatPmt(b)
}

修改,

func (m *Muxer) OnPatPmt(b []byte) {
	m.patpmt = b
	if m.observer != nil {
		m.observer.OnPatPmt(b)
	}
}

demo注册时候就是nil , 这个修改后, lal 做server 提供rtmp, 这个demo 做rtmp 的pull 可以工作。 能保存。

但是如果和其他的rtmp 的服务(rtsp-simple-server) 连接会出现 stream 没有打开的问题。 (估计是rtmp 协议实现上有点差异)

@joyhope
Copy link
Author

joyhope commented Jul 24, 2021

和 rtsp-simple-server的日志是

2021/07/24 17:08:14.049472 �[22;33m WARN�[0m [RTMPPULL1] read on status message but code field unknown. code=NetStream.Play.Reset - client_session.go:438
2021/07/24 17:08:14.049472 �[22;36m INFO�[0m [RTMPPULL1] < R onStatus('NetStream.Play.Start'). - client_session.go:435
2021/07/24 17:08:14.050464 �[22;33m WARN�[0m [RTMPPULL1] read on status message but code field unknown. code=NetStream.Data.Start - client_session.go:438
2021/07/24 17:08:14.050464 �[22;33m WARN�[0m [RTMPPULL1] read on status message but code field unknown. code=NetStream.Play.PublishNotify - client_session.go:438
2021/07/24 17:08:14.097888 �[22;33m WARN�[0m [HLSMUXER1] OnFrame V not opened. boundary=false, key=false - muxer.go:182
2021/07/24 17:08:14.160401 �[22;33m WARN�[0m [HLSMUXER1] OnFrame V not opened. boundary=false, key=false - muxer.go:182
2021/07/24 17:08:14.207824 �[22;33m WARN�[0m [HLSMUXER1] OnFrame A not opened. boundary=false - muxer.go:163
2021/07/24 17:08:14.223283 �[22;34mDEBUG�[0m reserve. newLen=12288(0, 0), need=(6201 -> 8192), cap=(4096 -> 12288) - stream.go:75
2021/07/24 17:08:14.223855 �[22;33m WARN�[0m [HLSMUXER1] OnFrame V not opened. boundary=false, key=false - muxer.go:182
2021/07/24 17:08:14.301390 �[22;33m WARN�[0m [HLSMUXER1] OnFrame V not opened. boundary=false, key=false - muxer.go:182

2个 code field unknown. 不确定是否对流程有影响。

@zengqingfa
Copy link

zengqingfa commented Sep 17, 2021

我跑这个demo也没成功
我的代码是这样的:

//test2.go
// Copyright 2020, Chef.  All rights reserved.
// https://github.com/q191201771/lal
//
// Use of this source code is governed by a MIT-style license
// that can be found in the License file.
//
// Author: Chef ([email protected])

package main

import (
	"flag"
	"fmt"
	"os"
	"time"

	"github.com/q191201771/lal/pkg/base"
	"github.com/q191201771/lal/pkg/httpflv"
	"github.com/q191201771/lal/pkg/remux"
	"github.com/q191201771/lal/pkg/rtsp"
	"github.com/q191201771/naza/pkg/nazalog"
)

func main() {
	_ = nazalog.Init(func(option *nazalog.Option) {
		option.AssertBehavior = nazalog.AssertFatal
	})
	defer nazalog.Sync()

	inUrl, outFilename, overTcp := parseFlag()

	var fileWriter httpflv.FlvFileWriter
	err := fileWriter.Open(outFilename)
	nazalog.Assert(nil, err)
	defer fileWriter.Dispose()
	err = fileWriter.WriteRaw(httpflv.FlvHeader)
	nazalog.Assert(nil, err)

	remuxer := remux.NewAvPacket2RtmpRemuxer(func(msg base.RtmpMsg) {
		err = fileWriter.WriteTag(*remux.RtmpMsg2FlvTag(msg))
		nazalog.Assert(nil, err)
	})
	pullSession := rtsp.NewPullSession(remuxer, func(option *rtsp.PullSessionOption) {
		option.PullTimeoutMs = 5000
		option.OverTcp = overTcp != 0
	})

	err = pullSession.Pull(inUrl)
	nazalog.Assert(nil, err)

	go func() {
		for {
			pullSession.UpdateStat(1)
			nazalog.Debugf("stat. pull=%+v", pullSession.GetStat())
			time.Sleep(1 * time.Second)
		}
	}()

	// 临时测试一下主动关闭client session
	//go func() {
	//	time.Sleep(5 * time.Second)
	//	err := pullSession.Dispose()
	//	nazalog.Debugf("< session Dispose. err=%+v", err)
	//}()

	err = <-pullSession.WaitChan()
	nazalog.Infof("< pullSession.Wait(). err=%+v", err)
}

func parseFlag() (inUrl string, outFilename string, overTcp int) {
	i := flag.String("i", "rtsp://admin:[email protected]:8554/profile0", "specify pull rtsp url")
	o := flag.String("o", "/tmp/test1.flv", "specify ouput flv file")
	t := flag.Int("t", 0, "specify interleaved mode(rtp/rtcp over tcp)")
	flag.Parse()
	if *i == "" || *o == "" {
		flag.Usage()
		_, _ = fmt.Fprintf(os.Stderr, `Example:
  %s -i rtsp://localhost:5544/live/test110 -o out.flv -t 0
  %s -i rtsp://localhost:5544/live/test110 -o out.flv -t 1
`, os.Args[0], os.Args[0])
		base.OsExitAndWaitPressIfWindows(1)
	}
	return *i, *o, *t
}

输出日志是这样的:

GOROOT=/usr/local/go #gosetup
GOPATH=/root/go #gosetup
/usr/local/go/bin/go build -o /tmp/___1go_build_rtspTest__1_ -gcflags all=-N -l rtspTest #gosetup
/opt/GoLand-2021.1.3/plugins/go/lib/dlv/linux/dlv --listen=0.0.0.0:36237 --headless=true --api-version=2 --check-go-version=false --only-same-user=false exec /tmp/___1go_build_rtspTest__1_ --
API server listening at: [::]:36237
2021/09/17 17:36:01.485335  INFO [RTSPPULL1] lifecycle new rtsp ClientCommandSession. session=0xc0000aeb00 - client_command_session.go:101
2021/09/17 17:36:01.485481  INFO [RTSPPULL1] lifecycle new rtsp BaseInSession. session=0xc0000ca240 - base_in_session.go:101
2021/09/17 17:36:01.485490  INFO [RTSPPULL1] lifecycle new rtsp PullSession. session=0xc0000d4280 - client_pull_session.go:66
2021/09/17 17:36:06.402857 DEBUG [RTSPPULL1] pull. url=rtsp://admin:[email protected]:8554/profile0 - client_pull_session.go:73
2021/09/17 17:36:28.746675 DEBUG [RTSPPULL1] > tcp connect. - client_command_session.go:334
2021/09/17 17:36:32.663949 DEBUG [NAZACONN1] lifecycle new connection. net.Conn=0xc000010010, naza.Connection=0xc000072000 - connection.go:164
2021/09/17 17:36:32.664215 DEBUG [RTSPPULL1] < tcp connect. laddr=192.168.108.145:54674, raddr=192.168.108.132:8554 - client_command_session.go:344
2021/09/17 17:36:32.664279 DEBUG [RTSPPULL1] > write OPTIONS. - client_command_session.go:539
2021/09/17 17:36:34.388407 DEBUG [RTSPPULL1] < read response. version=RTSP/1.0, code=200, reason=OK, headers=map[Cseq:[1] Date:[Fri Sep 17 09:36:32 2021] Public:[DESCRIBE, SETUP, PLAY, PAUSE, OPTIONS, TEARDOWN,GET_PARAMETER,SET_PARAMETER] Server:[YGTek RTSP Server 2.0]], body= - client_command_session.go:557
2021/09/17 17:36:34.388518 DEBUG [RTSPPULL1] > write DESCRIBE. - client_command_session.go:539
2021/09/17 17:36:48.404116 DEBUG [RTSPPULL1] < read response. version=RTSP/1.0, code=401, reason=Unauthorized, headers=map[Cseq:[2] Date:[Fri Sep 17 09:36:33 2021] Server:[YGTek RTSP Server 2.0] Www-Authenticate:[Basic realm="ygtechnologyshanghai"]], body= - client_command_session.go:557
2021/09/17 17:37:28.454772 DEBUG [RTSPPULL1] > write DESCRIBE. - client_command_session.go:539
2021/09/17 17:37:28.454923 DEBUG [NAZACONN1] close once. err=EOF - connection.go:428
2021/09/17 17:37:36.597262  INFO [RTSPPULL1] lifecycle dispose rtsp ClientCommandSession. session=0xc0000aeb00 - client_command_session.go:574
2021/09/17 17:37:36.618531 DEBUG [NAZACONN1] Close. - connection.go:322
2021/09/17 17:37:45.126282 FATAL assert failed. excepted=<nil>, but actual=context deadline exceeded - test2.go:49

rtsp流密码放错地方了吗?
i := flag.String("i", "rtsp://admin:[email protected]:8554/profile0", "specify pull rtsp url")

@zengqingfa
Copy link

调试了下,发现它获取到了密码
image

@q191201771
Copy link
Owner

超时移入 #37 管理。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants