Browse Source

1 fix sdp parse error(atoi error)

2 delete timeout when udp pushing
pull/132/head
macbookpro 6 years ago
parent
commit
1f63dbda20
  1. 22
      rtsp/rtsp-server.go
  2. 2
      rtsp/rtsp-session.go
  3. 5
      vendor/github.com/pixelbender/go-sdp/sdp/decoder.go

22
rtsp/rtsp-server.go

@ -2,7 +2,6 @@ package rtsp
import (
"fmt"
"github.com/penggy/EasyGoLib/utils"
"log"
"net"
"os"
@ -12,6 +11,8 @@ import (
"sync"
"syscall"
"time"
"github.com/penggy/EasyGoLib/utils"
)
type Server struct {
@ -82,12 +83,15 @@ func (server *Server) Start() (err error) {
log.Printf("EnsureDir:[%s] err:%v.", dir, err)
continue
}
path := path.Join(dir, fmt.Sprintf("out.m3u8"))
m3u8path := path.Join(dir, fmt.Sprintf("out.m3u8"))
// ffmpeg -i ~/Downloads/720p.mp4 -s 640x360 -g 15 -c:a aac -hls_time 5 -hls_list_size 0 record.m3u8
cmd := exec.Command(ffmpeg, "-fflags", "genpts", "-rtsp_transport", "tcp", "-i", pusher.URL(), "-c:v", "copy", "-hls_time", strconv.Itoa(ts_duration_second), "-hls_list_size", "0", path)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd := exec.Command(ffmpeg, "-fflags", "genpts", "-rtsp_transport", "tcp", "-i", pusher.URL(), "-c:v", "copy", "-hls_time", strconv.Itoa(ts_duration_second), "-hls_list_size", "0", m3u8path)
f, err := os.OpenFile(path.Join(dir, fmt.Sprintf("log.txt")), os.O_RDWR|os.O_CREATE, 0755)
if err == nil {
cmd.Stdout = f
cmd.Stderr = f
}
err = cmd.Start()
if err != nil {
log.Printf("Start ffmpeg err:%v", err)
@ -106,7 +110,15 @@ func (server *Server) Start() (err error) {
if proc != nil {
log.Printf("prepare to SIGTERM to process:%v", proc)
proc.Signal(syscall.SIGTERM)
proc.Wait()
// proc.Kill()
// no need to close attached log file.
// see "Wait releases any resources associated with the Cmd."
// if closer, ok := cmd.Stdout.(io.Closer); ok {
// closer.Close()
// log.Printf("process:%v Stdout closed.", proc)
// }
log.Printf("process:%v terminate.", proc)
}
delete(pusher2ffmpegMap, pusher)
log.Printf("delete ffmpeg from pull stream from pusher[%v]", pusher)

2
rtsp/rtsp-session.go

@ -375,6 +375,8 @@ func (session *Session) handleRequest(req *Request) {
}
} else if udpMatchs := mudp.FindStringSubmatch(ts); udpMatchs != nil {
session.TransType = TRANS_TYPE_UDP
// no need for tcp timeout.
session.Conn.timeout = 0
if session.UDPClient == nil {
session.UDPClient = &UDPClient{
Session: session,

5
vendor/github.com/pixelbender/go-sdp/sdp/decoder.go generated vendored

@ -6,6 +6,7 @@ import (
"fmt"
"io"
"strconv"
"strings"
"time"
)
@ -199,11 +200,11 @@ func (d *Decoder) rtpmap(f *Format, v string) error {
f.Name = p[0]
var err error
if ok {
if f.Channels, err = strconv.Atoi(p[2]); err != nil {
if f.Channels, err = strconv.Atoi(strings.TrimSpace(p[2])); err != nil {
return err
}
}
if f.ClockRate, err = strconv.Atoi(p[1]); err != nil {
if f.ClockRate, err = strconv.Atoi(strings.TrimSpace(p[1])); err != nil {
return err
}
return nil

Loading…
Cancel
Save