| 234 | } |
| 235 | |
| 236 | func (conf *GlobalConfig) API_replay_rtpdump(w http.ResponseWriter, r *http.Request) { |
| 237 | q := r.URL.Query() |
| 238 | streamPath := q.Get("streamPath") |
| 239 | if streamPath == "" { |
| 240 | streamPath = "dump/rtsp" |
| 241 | } |
| 242 | dumpFile := q.Get("dump") |
| 243 | if dumpFile == "" { |
| 244 | dumpFile = streamPath + ".rtpdump" |
| 245 | } |
| 246 | cv := q.Get("vcodec") |
| 247 | ca := q.Get("acodec") |
| 248 | cvp := q.Get("vpayload") |
| 249 | cap := q.Get("apayload") |
| 250 | var pub RTPDumpPublisher |
| 251 | i, _ := strconv.ParseInt(cvp, 10, 64) |
| 252 | pub.VPayloadType = byte(i) |
| 253 | i, _ = strconv.ParseInt(cap, 10, 64) |
| 254 | pub.APayloadType = byte(i) |
| 255 | switch cv { |
| 256 | case "h264": |
| 257 | pub.VCodec = codec.CodecID_H264 |
| 258 | case "h265": |
| 259 | pub.VCodec = codec.CodecID_H265 |
| 260 | } |
| 261 | switch ca { |
| 262 | case "aac": |
| 263 | pub.ACodec = codec.CodecID_AAC |
| 264 | case "pcma": |
| 265 | pub.ACodec = codec.CodecID_PCMA |
| 266 | case "pcmu": |
| 267 | pub.ACodec = codec.CodecID_PCMU |
| 268 | } |
| 269 | ss := strings.Split(dumpFile, ",") |
| 270 | if len(ss) > 1 { |
| 271 | if err := Engine.Publish(streamPath, &pub); err != nil { |
| 272 | util.ReturnError(util.APIErrorPublish, err.Error(), w, r) |
| 273 | } else { |
| 274 | for _, s := range ss { |
| 275 | f, err := os.Open(s) |
| 276 | if err != nil { |
| 277 | util.ReturnError(util.APIErrorOpen, err.Error(), w, r) |
| 278 | return |
| 279 | } |
| 280 | go pub.Feed(f) |
| 281 | } |
| 282 | util.ReturnOK(w, r) |
| 283 | } |
| 284 | } else { |
| 285 | f, err := os.Open(dumpFile) |
| 286 | if err != nil { |
| 287 | util.ReturnError(util.APIErrorOpen, err.Error(), w, r) |
| 288 | return |
| 289 | } |
| 290 | if err := Engine.Publish(streamPath, &pub); err != nil { |
| 291 | util.ReturnError(util.APIErrorPublish, err.Error(), w, r) |
| 292 | } else { |
| 293 | pub.SetIO(f) |