📦 NEW: 增加rtpdump的回放功能

This commit is contained in:
dexter
2022-11-19 23:39:11 +08:00
parent fe244e5cea
commit b725fdbd59
9 changed files with 293 additions and 118 deletions

40
http.go
View File

@@ -6,6 +6,7 @@ import (
"time"
"gopkg.in/yaml.v3"
"m7s.live/engine/v4/codec"
"m7s.live/engine/v4/config"
"m7s.live/engine/v4/util"
)
@@ -193,3 +194,42 @@ func (conf *GlobalConfig) API_stopPush(w http.ResponseWriter, r *http.Request) {
http.Error(w, "no such pusher", http.StatusNotFound)
}
}
func (conf *GlobalConfig) API_replay_rtpdump(w http.ResponseWriter, r *http.Request) {
q := r.URL.Query()
streamPath := q.Get("streamPath")
if streamPath == "" {
streamPath = "dump/rtsp"
}
dumpFile := q.Get("dump")
if dumpFile == "" {
dumpFile = streamPath + ".rtpdump"
}
cv := q.Get("vcodec")
ca := q.Get("acodec")
var pub RTPDumpPublisher
switch cv {
case "h264":
pub.VCodec = codec.CodecID_H264
case "h265":
pub.VCodec = codec.CodecID_H265
default:
pub.VCodec = codec.CodecID_H264
}
switch ca {
case "aac":
pub.ACodec = codec.CodecID_AAC
case "pcma":
pub.ACodec = codec.CodecID_PCMA
case "pcmu":
pub.ACodec = codec.CodecID_PCMU
default:
pub.ACodec = codec.CodecID_AAC
}
pub.DumpFile = dumpFile
if err := Engine.Publish(streamPath, &pub); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
} else {
w.Write([]byte("ok"))
}
}