-
Notifications
You must be signed in to change notification settings - Fork 192
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
RTPListener doesn't work #136
Labels
question
Further information is requested
Comments
Hello, first of all, why did you do this? // i wanna set Setup(false, t, baseURL, 0, 0) , so i didn't use SetupAndPlay Func
fmt.Println("Setup")
for _, t := range tracks {
_, err := c.Setup(true, t, baseURL, 0, 0) // i don't know why i can't set (forPlay == false) in Setup Function.
if err != nil {
fmt.Println("hihi", err)
}
}
|
thanks for your response.
first i refered your example code in gortsplib/examples/client-read-h264
and during to study rtsp, i get to know that 'Setup' Request is Define the way how to send media stream. (like client port, server port)
and in my question '// i wanna set Setup(false, t, baseURL, 0, 0) , so i didn't use SetupAndPlay Func', i misunderstand first pamameters (forPay) mean it is forPlay with streaming(pulbish)
so i used that method with parameter 'true'
/*
_, err := c.Setup(true, t, baseURL, 0, 0) // i don't know why i can't set (forPlay == false) in Setup Function.
*/
and i tried to unuse Setup Method in your answer 'If you're using Describe() and Play() you're definitely reading a stream from a camera.'
in this case the function doPlay in Client.go, it returns the error cauze Preplay
Error Message [ Play must be in state [prePlay], while is in state initial ]
in server.go error function (67~71 line)
// Error implements the error interface.
func (e ErrServerInvalidState) Error() string {
return fmt.Sprintf("must be in state %v, while is in state %v",
e.AllowedList, e.State)
}
i understand separate Setup & Play function is unnecessary
so i change my code like
err = c.SetupAndPlay(tracks, baseURL)
if err != nil {
fmt.Println("Setup And Play!")
}
but it doesn't work without sleep (in previous question)
thanks for your attention.
…-----Original Message-----
From: "Alessandro ***@***.***>
To: ***@***.***>;
Cc: ***@***.***>; ***@***.***>;
Sent: 2022-08-23 (화) 19:46:39 (GMT+09:00)
Subject: Re: [aler9/gortsplib] RTPListener doesn't work (Issue #136)
Hello, first of all, why did you do this?
// i wanna set Setup(false, t, baseURL, 0, 0) , so i didn't use SetupAndPlay Func fmt.Println("Setup") for _, t := range tracks { _, err := c.Setup(true, t, baseURL, 0, 0) // i don't know why i can't set (forPlay == false) in Setup Function. if err != nil { fmt.Println("hihi", err) } }
Setup(true) can be called only when you're publishing a stream to a RTSP server, not when you're reading one. If you're using Describe() and Play() you're definitely reading a stream from a camera.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for your lib before writing issue.
i tried to make sample in window with this library and it make a successful.
so i saw your reference main.go
and i setup ffmpeg in window in order to use h264decoder.go
this link is ffmpeg library (it's good with window)
ffmpeg-master-latest-win64-gpl.zip
and i change the cgo flag like this
// #cgo CFLAGS: -I D:/Camera/ffmpeg-master-latest-win64-gpl-shared/include
// #cgo LDFLAGS: -Ld D:/Camera/ffmpeg-master-latest-win64-gpl-shared/lib/libavcodec.dll.a
// #cgo LDFLAGS: -Ld D:/Camera/ffmpeg-master-latest-win64-gpl-shared/lib/libavutil.dll.a
// #cgo LDFLAGS: -Ld D:/Camera/ffmpeg-master-latest-win64-gpl-shared/lib/libswscale.dll.a
// #include <libavcodec/avcodec.h>
// #include <libavutil/imgutils.h>
// #include <libswscale/swscale.h>
import "C"
until that, it is my development environment. and from down here, i think it is issue.
with your sample, it should have worked normally.
but, in my environment, RTCP callback function work well but RTP callback function doesn't called. :(
so i debuged with goland, i found the expected part.
in client.go with 713 - 716 Line, it call function start (clientudpl.go)
[client.go 713-716]
for _, ct := range c.tracks {
ct.udpRTPListener.start(true)
ct.udpRTCPListener.start(true)
}
[clientudpl.go start]
func (u *clientUDPListener) start(forPlay bool) {
u.running = true
u.pc.SetReadDeadline(time.Time{})
u.readerDone = make(chan struct{})
go u.runReader(forPlay)
}
in this start function, it called goroutine u.runReader.
I don't know the internal movement of goroutine, but it wasn't called. (only udpRTPListener.start)
so i set delay in client.go, it works well
[client.go 713-716]
for _, ct := range c.tracks {
ct.udpRTPListener.start(true)
++ time.Sleep(time.Second * time.Duration(3)) // at least 3 second. not worked in 2 second
ct.udpRTCPListener.start(true)
}
The exact cause was not found, but symptoms were found so i think it seemed to be reported.
i attach my sample code and i hope it helps to resolve that Symptom.
thank you.
package main
import (
"fmt"
"github.com/aler9/gortsplib"
"github.com/aler9/gortsplib/pkg/base"
"github.com/aler9/gortsplib/pkg/url"
"image"
"image/jpeg"
"os"
"runtime"
"strconv"
"time"
)
func saveToFile(img image.Image) error {
fname := "D://"+strconv.FormatInt(time.Now().UnixNano()/int64(time.Millisecond), 10) + ".jpg" //
}
func main() {
runtime.GOMAXPROCS(8)
c := gortsplib.Client{}
}
//[decoder.go]
// https://github.com/aler9/gortsplib/blob/main/examples/client-read-h264/h264decoder.go
package main
import (
"fmt"
"image"
"unsafe"
)
// #cgo CFLAGS: -I D:/Camera/ffmpeg-master-latest-win64-gpl-shared/include
// #cgo LDFLAGS: -Ld D:/Camera/ffmpeg-master-latest-win64-gpl-shared/lib/libavcodec.dll.a
// #cgo LDFLAGS: -Ld D:/Camera/ffmpeg-master-latest-win64-gpl-shared/lib/libavutil.dll.a
// #cgo LDFLAGS: -Ld D:/Camera/ffmpeg-master-latest-win64-gpl-shared/lib/libswscale.dll.a
// #include <libavcodec/avcodec.h>
// #include <libavutil/imgutils.h>
// #include <libswscale/swscale.h>
import "C"
func frameData(frame *C.AVFrame) **C.uint8_t {
return (**C.uint8_t)(unsafe.Pointer(&frame.data[0]))
}
func frameLineSize(frame *C.AVFrame) *C.int {
return (*C.int)(unsafe.Pointer(&frame.linesize[0]))
}
// h264Decoder is a wrapper around ffmpeg's H264 decoder.
type h264Decoder struct {
codecCtx *C.AVCodecContext
srcFrame *C.AVFrame
swsCtx *C.struct_SwsContext
dstFrame *C.AVFrame
dstFramePtr []uint8
}
// newH264Decoder allocates a new h264Decoder.
func newH264Decoder() (*h264Decoder, error) {
codec := C.avcodec_find_decoder(C.AV_CODEC_ID_H264)
if codec == nil {
return nil, fmt.Errorf("avcodec_find_decoder() failed")
}
}
// close closes the decoder.
func (d *h264Decoder) close() {
if d.dstFrame != nil {
C.av_frame_free(&d.dstFrame)
}
}
func (d *h264Decoder) decode(nalu []byte) (image.Image, error) {
nalu = append([]uint8{0x00, 0x00, 0x00, 0x01}, []uint8(nalu)...)
}
The text was updated successfully, but these errors were encountered: